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.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.xmgl.modules.basicdata.dto.ProjectDto;
import com.zhgd.xmgl.modules.basicdata.entity.Enterprise;
import com.zhgd.xmgl.modules.basicdata.entity.Project;
import com.zhgd.xmgl.modules.basicdata.service.IProjectService;
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.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 javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
* @Title: Controller
* @Description: 项目信息
* @author： pds
* @date：   2023-02-15
* @version： V1.0
*/
@RestController
@RequestMapping("/gov/project")
@Slf4j
@Api(tags = "项目信息")
public class GovProjectController {
   @Autowired
   private IProjectService projectService;

   /**
     * 分页列表查询
    * @return
    */
   @OperLog(operModul = "项目管理", operType = "分页查询", operDesc = "分页列表查询项目信息信息")
   @ApiOperation(value = " 分页列表查询项目信息信息", notes = "分页列表查询项目信息信息", httpMethod="POST")
   @ApiImplicitParams({
           @ApiImplicitParam(name = "state", value = "授权状态： 1(审批通过)；0(待审批)", paramType = "query", dataType = "Integer"),
           @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<ProjectDto>> queryPageList(@RequestBody Map<String, Object> map) {
       IPage<ProjectDto> pageList = projectService.getPageList(map);
       return Result.success(pageList);
   }

    /**
     * 列表查询
     * @param project
     * @param req
     * @return
     */
    @OperLog(operModul = "项目管理", operType = "列表查询", operDesc = "列表查询项目信息信息")
    @ApiOperation(value = " 列表查询项目信息信息", notes = "列表查询项目信息信息", httpMethod="POST")
    @PostMapping(value = "/list")
    public Result<List<Project>> queryList(@RequestBody Project project, HttpServletRequest req) {
        QueryWrapper<Project> queryWrapper = QueryGenerator.initQueryWrapper(project, req.getParameterMap());
        return Result.success(projectService.list(queryWrapper));
    }

    @OperLog(operModul = "项目管理", operType = "修改", operDesc = "项目审批")
    @ApiOperation(value = "项目审批", notes = "项目审批" , httpMethod="POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目ID", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "suggest", value = "审核结果(0:驳回;1:同意)", paramType = "query", required = true, dataType = "Integer"),
    })
    @PostMapping(value = "/examine")
    public Result<Enterprise> examine(@RequestBody Map<String,Object> map) {
        Result<Enterprise> result = new Result<Enterprise>();
        String projectId = MapUtils.getString(map, "projectId");
        Project project = projectService.getById(projectId);
        if(project==null) {
            result.error500("未找到对应实体");
        }else {
            Integer suggest = MapUtils.getInteger(map, "suggest");
            boolean ok = projectService.examine(project, suggest);
            if(ok) {
                result.success("修改成功!");
            }
        }

        return result;
    }
}
