package com.zhgd.xmgl.modules.basicdata.controller.government;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.util.PageUtil;
import com.zhgd.xmgl.modules.basicdata.dto.EngineeringDeviceDto;
import com.zhgd.xmgl.modules.basicdata.dto.ProjectDeviceDto;
import com.zhgd.xmgl.modules.basicdata.entity.AiMonitorQuestion;
import com.zhgd.xmgl.modules.basicdata.service.IAiMonitorAlarmService;
import com.zhgd.xmgl.modules.basicdata.service.IAiMonitorQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * @Title: Controller
 * @Description: AI预警整改记录
 * @author： pds
 * @date： 2023-02-28
 * @version： V1.0
 */
@RestController
@RequestMapping("/gov/aiMonitorQuestion")
@Slf4j
@Api(tags = "AI预警整改记录")
public class GovAiMonitorQuestionController {
    @Autowired
    private IAiMonitorQuestionService aiMonitorQuestionService;

    @Autowired
    private IAiMonitorAlarmService aiMonitorAlarmService;

    /**
     * 分页列表查询
     *
     * @return
     */
    @OperLog(operModul = "AI预警管理", operType = "分页查询", operDesc = "分页列表查询AI预警工程信息")
    @ApiOperation(value = " 分页列表查询AI预警工程信息", notes = "分页列表查询AI预警工程信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "engineeringName", value = "工程名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
    })
    @PostMapping(value = "/engineeringPage")
    public Result<IPage<EngineeringDeviceDto>> engineeringPageList(@RequestBody Map<String, Object> map) {
        return Result.success(aiMonitorAlarmService.engineeringPageList(map));
    }

    /**
     * 分页列表查询
     *
     * @return
     */
    @OperLog(operModul = "AI预警管理", operType = "分页查询", operDesc = "分页列表查询AI预警项目信息")
    @ApiOperation(value = " 分页列表查询AI预警项目信息", notes = "分页列表查询AI预警项目信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectName", value = "工程名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
    })
    @PostMapping(value = "/projectPage")
    public Result<IPage<ProjectDeviceDto>> projectPageList(@RequestBody Map<String, Object> map) {
        return Result.success(aiMonitorAlarmService.projectPageList(map));
    }

    /**
     * 分页列表查询
     *
     * @return
     */
    @OperLog(operModul = "AI预警整改管理", operType = "分页查询", operDesc = "分页列表查询AI预警整改记录信息")
    @ApiOperation(value = " 分页列表查询AI预警整改记录信息", notes = "分页列表查询AI预警整改记录信息", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "engineeringSn", value = "工程SN", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
    })
    @PostMapping(value = "/page")
    public Result<IPage<AiMonitorQuestion>> queryPageList(@RequestBody Map<String, Object> map) {
        Result<IPage<AiMonitorQuestion>> result = new Result<>();
        String projectSn = MapUtils.getString(map, "projectSn");
        String engineeringSn = MapUtils.getString(map, "engineeringSn");
        QueryWrapper<AiMonitorQuestion> wrapper = Wrappers.<AiMonitorQuestion>query();
        Page<AiMonitorQuestion> page = PageUtil.getPage(map);
        if (StringUtils.isBlank(projectSn) && StringUtils.isBlank(engineeringSn)) {
            result.setMessage("参数错误!");
            return result;
        }
        if (StringUtils.isNotBlank(projectSn)) {
            wrapper.eq("q.project_sn", projectSn).eq("q.engineering_sn", "");
        }
        if (StringUtils.isNotBlank(engineeringSn)) {
            wrapper.eq("q.engineering_sn", engineeringSn);
        }
        wrapper.orderByDesc("q.create_time");
        return Result.success(aiMonitorQuestionService.getPageList(page, wrapper));
    }

    /**
     * 通过id查询
     * @return
     */
    @OperLog(operModul = "AI预警整改管理", operType = "查询", operDesc = "通过id查询AI预警整改记录信息")
    @ApiOperation(value = "通过id查询AI预警整改记录信息", notes = "通过id查询AI预警整改记录信息", httpMethod = "POST")
    @ApiImplicitParam(name = "id", value = "AI预警整改记录ID", paramType = "query", required = true, dataType = "String")
    @PostMapping(value = "/queryById")
    public Result<AiMonitorQuestion> queryById(@RequestBody AiMonitorQuestion aiMonitorQuestion) {
        Result<AiMonitorQuestion> result = new Result<AiMonitorQuestion>();
        AiMonitorQuestion aiMonitorQuestionEntity = aiMonitorQuestionService.getById(aiMonitorQuestion.getId());
        if (aiMonitorQuestionEntity == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(aiMonitorQuestionEntity);
            result.setSuccess(true);
        }
        return result;
    }
}
