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.SysAppHomeconfigPlateList;
import com.mosty.common.core.business.entity.SysDept;
import com.mosty.common.core.business.entity.request.SysAppHomeconfigPlateListPage;
import com.mosty.common.core.business.service.SysAppHomeconfigPlateListService;
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("/sysAppHomeconfigPlatelList")
public class SysAppHomeconfigPlateListController {

    private SysAppHomeconfigPlateListService sysAppHomeconfigPlateListService;

    /**
     * 添加首页应用板块内容
     * @param plate 部门
     * @return 添加结果
     */
    @PostMapping("addPlate")
    @JwtSysUser
    @ApiOperation(value = "添加首页应用板块内容", httpMethod = "POST", response = Boolean.class)
    @Log(title = "添加首页应用板块",businessType = BusinessType.INSERT)
    public ResponseResult<Boolean> addPlate(@RequestBody SysAppHomeconfigPlateList plate,
                                            HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateListService.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<SysAppHomeconfigPlateList> plates,
                                                 HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateListService.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 SysAppHomeconfigPlateList plate,
                                               HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateListService.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<SysAppHomeconfigPlateList> plates, HttpServletRequest servletRequest) {
        String ipAddress = IpUtil.getIpAddress(servletRequest);
        sysAppHomeconfigPlateListService.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();
        sysAppHomeconfigPlateListService.delete(list, ipAddress, null);
        return ResponseResult.success(Boolean.TRUE);
    }

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

}

