package com.ruoyi.postCheck.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.DeptCode;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysPostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.postCheck.domain.PostCheckedReport;
import com.ruoyi.postCheck.service.IPostCheckedReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 岗检报告管理Controller
 *
 * @author csg
 * @date 2023-12-28
 */
@Api(tags = "3.4.1-岗检报告管理")
@RestController
@RequestMapping("/postCheck/postCheckedReport")
public class PostCheckedReportController extends BaseController
{
    @Autowired
    private IPostCheckedReportService postCheckedReportService;

    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private ISysPostService sysPostService;


    /**
     * 查询岗检报告管理列表
     */
    @ApiOperation("查询岗检报告管理列表")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "reportNo", value = "编码", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "reportName", value = "岗检报告名称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "reportPreface", value = "前言", dataType = "String", dataTypeClass = String.class),
//                    @ApiImplicitParam(name = "consummationProblem", value = "废弃：完善性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "suitabilityProblem", value = "废弃：适宜性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "effectivenessProblem", value = "废弃：有效性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "liXingLiGaiQuestionNumber", value = "废弃：立行立改问题数量", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "liXingLiGaiQuestionHasRectifiedNumber", value = "废弃：立行立改问题已整改数量", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "richText", value = "废弃：富文本", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "generateTime", value = "生成时间", dataType = "Date", dataTypeClass = Date.class),
//                    @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "createUserId", value = "创建者用户ID", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "htmlOne", value = "1、（一）组织情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlTwo", value = "2、（二）岗检的时间、范围和开展形式", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlThree", value = "3、（三）岗检发现的主要问题", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlFour", value = "4、（四）原因分析", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlFive", value = "5、（五）取得成绩", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlSix", value = "6、（一）“立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlSeven", value = "7、（二）“非立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlEight", value = "8、三、下一步岗位责任提升计划", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlNine", value = "9、四、总结结论", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "status", value = "状态：1-待审核；3-通过；4-驳回；", dataType = "Integer", dataTypeClass = Integer.class),
                    @ApiImplicitParam(name = "statusByUserId", value = "审核人ID", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "statusByUserName", value = "审核人姓名", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "statusReason", value = "审核不通过原因", dataType = "String", dataTypeClass = String.class),
                @ApiImplicitParam(name = "pageNum", value = "页码从1开始", dataType = "Integer", dataTypeClass = Integer.class),
                @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "Integer", dataTypeClass = Integer.class),
                @ApiImplicitParam(name = "orderBy", value = "排序字段", dataType = "String", dataTypeClass = String.class)
    })
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostCheckedReport postCheckedReport)
    {
        startPage();
        List<PostCheckedReport> list = postCheckedReportService.selectPostCheckedReportList(postCheckedReport);
        return getDataTable(list);
    }

    /**
     * 导出岗检报告管理列表
     */
    @ApiOperation("导出岗检报告管理列表")
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:export')")
    @Log(title = "岗检报告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostCheckedReport postCheckedReport)
    {
        List<PostCheckedReport> list = postCheckedReportService.selectPostCheckedReportList(postCheckedReport);
        ExcelUtil<PostCheckedReport> util = new ExcelUtil<PostCheckedReport>(PostCheckedReport.class);
        util.exportExcel(response, list, "岗检报告管理数据");
    }

    /**
     * 获取岗检报告管理详细信息
     */
    @ApiOperation("获取岗检报告管理详细信息")
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(postCheckedReportService.selectPostCheckedReportById(id));
    }

    /**
     * 新增岗检报告管理
     */
    @ApiOperation("新增岗检报告管理")
    @ApiImplicitParams({
//        @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "reportNo", value = "编码", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "reportName", value = "岗检报告名称", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "reportPreface", value = "前言", dataType = "String", dataTypeClass = String.class),
//        @ApiImplicitParam(name = "consummationProblem", value = "废弃：完善性问题", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "suitabilityProblem", value = "废弃：适宜性问题", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "effectivenessProblem", value = "废弃：有效性问题", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "liXingLiGaiQuestionNumber", value = "废弃：立行立改问题数量", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "liXingLiGaiQuestionHasRectifiedNumber", value = "废弃：立行立改问题已整改数量", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "richText", value = "废弃：富文本", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "generateTime", value = "生成时间", dataType = "Date", dataTypeClass = Date.class),
//        @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "createUserId", value = "创建者用户ID", dataType = "Long", dataTypeClass = Long.class),
        @ApiImplicitParam(name = "htmlOne", value = "1、（一）组织情况", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlTwo", value = "2、（二）岗检的时间、范围和开展形式", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlThree", value = "3、（三）岗检发现的主要问题", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlFour", value = "4、（四）原因分析", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlFive", value = "5、（五）取得成绩", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlSix", value = "6、（一）“立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlSeven", value = "7、（二）“非立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlEight", value = "8、三、下一步岗位责任提升计划", dataType = "String", dataTypeClass = String.class),
        @ApiImplicitParam(name = "htmlNine", value = "9、四、总结结论", dataType = "String", dataTypeClass = String.class),
//        @ApiImplicitParam(name = "status", value = "状态：1-待审核；3-通过；4-驳回；", dataType = "Integer", dataTypeClass = Integer.class),
//        @ApiImplicitParam(name = "statusByUserId", value = "审核人ID", dataType = "Long", dataTypeClass = Long.class),
//        @ApiImplicitParam(name = "statusByUserName", value = "审核人姓名", dataType = "String", dataTypeClass = String.class),
//        @ApiImplicitParam(name = "statusReason", value = "审核不通过原因", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:add')")
    @Log(title = "岗检报告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostCheckedReport postCheckedReport)
    {
        return toAjax(postCheckedReportService.insertPostCheckedReport(postCheckedReport));
    }

    /**
     * 修改岗检报告管理
     */
    @ApiOperation("修改岗检报告管理")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "reportNo", value = "编码", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "reportName", value = "岗检报告名称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "reportPreface", value = "前言", dataType = "String", dataTypeClass = String.class),
//                    @ApiImplicitParam(name = "consummationProblem", value = "废弃：完善性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "suitabilityProblem", value = "废弃：适宜性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "effectivenessProblem", value = "废弃：有效性问题", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "liXingLiGaiQuestionNumber", value = "废弃：立行立改问题数量", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "liXingLiGaiQuestionHasRectifiedNumber", value = "废弃：立行立改问题已整改数量", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "richText", value = "废弃：富文本", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "generateTime", value = "生成时间", dataType = "Date", dataTypeClass = Date.class),
//                    @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "createUserId", value = "创建者用户ID", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "htmlOne", value = "1、（一）组织情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlTwo", value = "2、（二）岗检的时间、范围和开展形式", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlThree", value = "3、（三）岗检发现的主要问题", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlFour", value = "4、（四）原因分析", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlFive", value = "5、（五）取得成绩", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlSix", value = "6、（一）“立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlSeven", value = "7、（二）“非立行立改”问题整改情况", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlEight", value = "8、三、下一步岗位责任提升计划", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "htmlNine", value = "9、四、总结结论", dataType = "String", dataTypeClass = String.class),
//                    @ApiImplicitParam(name = "status", value = "状态：1-待审核；3-通过；4-驳回；", dataType = "Integer", dataTypeClass = Integer.class),
//                    @ApiImplicitParam(name = "statusByUserId", value = "审核人ID", dataType = "Long", dataTypeClass = Long.class),
//                    @ApiImplicitParam(name = "statusByUserName", value = "审核人姓名", dataType = "String", dataTypeClass = String.class),
//                    @ApiImplicitParam(name = "statusReason", value = "审核不通过原因", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:edit')")
    @Log(title = "岗检报告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostCheckedReport postCheckedReport)
    {
        return toAjax(postCheckedReportService.updatePostCheckedReport(postCheckedReport));
    }

    /**
     * 删除岗检报告管理
     */
    @ApiOperation("删除岗检报告管理")
    @ApiImplicitParam(name = "ids", value = "Long类型的主键数组", dataType = "Long[]", dataTypeClass = Long[].class)
    @PreAuthorize("@ss.hasPermi('postCheck:postCheckedReport:remove')")
    @Log(title = "岗检报告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postCheckedReportService.deletePostCheckedReportByIds(ids));
    }

    @ApiOperation("岗检报告审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "status", value = "状态：3-通过；4-驳回；", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "reason", value = "未通过理由", dataType = "String", dataTypeClass = String.class),
    })
    @Log(title = "岗检报告审核", businessType = BusinessType.UPDATE)
    @PutMapping("/statusApprove")
    public AjaxResult statusApprove(Long id, Integer status, String statusReason) {

        // 判断审核的权限
        LoginUser loginUser = SecurityUtils.getLoginUser();
        // 当前登录用户的部门id 查询岗位id是否在内
        SysDept sysDept = sysDeptService.selectDeptById(loginUser.getDeptId());
        if (!sysDept.getDeptCode().equals(DeptCode.DEPT_ICFA.getCode())) {
            return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限，请联系管理员授权");
        }
        // 判断岗位是否在权限范围内
        SysPost sysPost = sysPostService.selectPostByDeptId(loginUser.getDeptId());
        if (sysPost.getPostLevel() != 1) {
            return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限，请联系管理员授权");
        }
        return toAjax(postCheckedReportService.statusApprove(id, status,  statusReason));
    }

}
