package com.mosty.common.core.business.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.base.util.IpUtil;
import com.mosty.common.core.business.entity.SysAppHomeconfigPlate;
import com.mosty.common.core.business.entity.SysDept;
import com.mosty.common.core.business.entity.request.SysAppHomeconfigPlatePage;
import com.mosty.common.core.business.service.SysAppHomeconfigPlateService;
import com.mosty.common.token.JwtSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * app首页-板块表 前端控制器
 * </p>
 *
 * @author zengbo
 * @since 2022-08-18
 */
@Api(tags = "app首页板块接口")
@RestController
@AllArgsConstructor
@RequestMapping("/sysAppHomeconfigPlate")
public class SysAppHomeconfigPlateController {

    private SysAppHomeconfigPlateService sysAppHomeconfigPlateService;

    /**
     * 添加首页应用
     * @param plate 部门
     * @return 添加结果
     */
    @PostMapping("addPlate")
    @JwtSysUser
    @ApiOperation(value = "添加首页应用板块", httpMethod = "POST", response = Boolean.class)
    @Log(title = "添加首页应用板块",businessType = BusinessType.INSERT)
    public ResponseResult<Boolean> addPlate(@RequestBody @Valid SysAppHomeconfigPlate plate,
                                          HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateService.saveInfo(plate, ipAddress);
        return ResponseResult.success(Boolean.TRUE);
    }

    /**
     * 添加首页应用
     * @param plates 部门
     * @return 添加结果
     */
    @PostMapping("addBatch")
    @JwtSysUser
    @ApiOperation(value = "批量添加首页应用板块", httpMethod = "POST", response = Boolean.class)
    @Log(title = "批量添加首页应用板块",businessType = BusinessType.INSERT)
    public ResponseResult<Boolean> addPlateBatch(@RequestBody List<SysAppHomeconfigPlate> plates,
                                            HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateService.saveInfoBatch(plates, ipAddress);
        return ResponseResult.success(Boolean.TRUE);
    }

    /**
     * 修改首页板块
     * @param plate 首页板块信息
     * @return 修改结果
     */
    @PostMapping("updatePlate")
    @JwtSysUser
    @Log(title = "首页应用板块",businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改首页应用板块", httpMethod = "POST", response = Boolean.class)
    public ResponseResult<Boolean> updatePlate(@RequestBody @Valid SysAppHomeconfigPlate plate,
                                             HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateService.updateInfo(plate, ipAddress);
        return ResponseResult.success(Boolean.TRUE);
    }

    /**
     * 批量修改首页应用板块
     * @param plates 首页板块信息
     * @return 修改结果
     */
    @PostMapping("updateBatch")
    @JwtSysUser
    @Log(title = "批量修改首页应用板块",businessType = BusinessType.UPDATE)
    @ApiOperation(value = "批量修改首页应用板块", httpMethod = "POST", response = Boolean.class)
    public ResponseResult<Boolean> updateBatch(@RequestBody List<SysAppHomeconfigPlate> plates, HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateService.updateInfoBatch(plates, ipAddress);
        return ResponseResult.success(Boolean.TRUE);
    }

    /**
     * 删除应用板块信息
     * @param list 应用id
     * @return 删除结果
     */
    @Log(title = "删除应用板块功能",businessType = BusinessType.DELETE)
    @PostMapping("deletePlate")
    @JwtSysUser
    @ApiOperation(value = "删除应用信息", httpMethod = "POST", response = Boolean.class)
    public ResponseResult<Boolean> deletePlate(@RequestBody List<Long> list,
                                                 HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
//        UserInfo userInfo = UserInfoManager.get();
        sysAppHomeconfigPlateService.delete(list, ipAddress, null);
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("selectPage")
    @ApiOperation(value = "分页查询应用信息", httpMethod = "GET", response = SysDept.class)
    public ResponseResult<IPage<SysAppHomeconfigPlate>> selectPage(SysAppHomeconfigPlatePage deptPage) {
        IPage<SysAppHomeconfigPlate> deptIPage = sysAppHomeconfigPlateService.selectByPage(deptPage);
        return ResponseResult.success(deptIPage);
    }

}

