/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.unis.policy.info.modular.auditRequest.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.auth.core.util.StpClientUtil;
import com.unis.basic.info.modular.enumInfo.mapper.BasicEnumMapper;
import com.unis.basic.info.modular.mq.dto.jkEnum;
import com.unis.basic.info.modular.mq.pub.RecPublishService;
import com.unis.basic.info.modular.unitInfo.entity.BasicEnum;
import com.unis.basic.info.modular.unitInfo.mapper.EnumMapper;
import com.unis.emergencySupport.modular.es.entity.EsNetworkEntry;
import com.unis.emergencySupport.modular.es.entity.EsNetworkEntryGrain;
import com.unis.emergencySupport.modular.es.entity.vo.EsNetworkEntryVO;
import com.unis.emergencySupport.modular.es.enums.EsNetworkEntryEnum;
import com.unis.emergencySupport.modular.es.mapper.EsNetworkEntryMapper;
import com.unis.emergencySupport.modular.es.param.EsNetworkEntryIdParam;
import com.unis.emergencySupport.modular.es.param.EsNetworkEntryPageParam;
import com.unis.emergencySupport.modular.es.service.EsNetworkEntryGrainService;
import com.unis.emergencySupport.modular.es.service.EsNetworkEntryService;
import com.unis.policy.info.modular.auditRecord.mapper.AuditRecordMapper;
import com.unis.policy.info.modular.auditRequest.enums.TypeEnum;
import com.unis.policy.info.modular.auditRequest.mapper.TFumigationRecordMapper;
import com.unis.basic.info.modular.unitInfo.entity.UnitInfo;
import com.unis.basic.info.modular.unitInfo.mapper.UnitInfoMapper;
import com.unis.common.enums.CommonSortOrderEnum;
import com.unis.common.exception.CommonException;
import com.unis.common.page.CommonPageRequest;
import com.unis.enterpriseManagement.info.modular.emPersonPlan.entity.EmPersonPlan;
import com.unis.enterpriseManagement.info.modular.emPersonPlan.service.EmPersonPlanService;
import com.unis.policy.info.modular.alPolicyFileReport.entity.AlPolicyFileReport;
import com.unis.policy.info.modular.alPolicyFileReport.service.AlPolicyFileReportService;
import com.unis.policy.info.modular.auditRecord.entity.AuditRecord;
import com.unis.policy.info.modular.auditRecord.service.AuditRecordService;
import com.unis.policy.info.modular.auditRequest.entity.AuditRequest;
import com.unis.policy.info.modular.auditRequest.entity.TFumigationRecord;
import com.unis.policy.info.modular.auditRequest.mapper.AuditRequestMapper;
import com.unis.policy.info.modular.auditRequest.param.*;
import com.unis.policy.info.modular.auditRequest.service.AuditRequestService;
import com.unis.policy.info.modular.auditRequest.vo.AuditRequestVO;
import com.unis.policy.info.modular.auditRequest.vo.PmApplicationVO;
import com.unis.policy.info.modular.auditRequest.vo.SqrEnterpriseVO;
import com.unis.policy.info.modular.auditRequest.vo.UnitInfoVO;
import com.unis.policy.info.modular.sqrEnterprise.entity.SqrEnterprise;
import com.unis.policy.info.modular.sqrEnterprise.mapper.SqrEnterpriseMapper;
import com.unis.policy.info.modular.sqrEnterprise.param.SqrEnterpriseIdParam;
import com.unis.policy.info.modular.sqrEnterpriseApply.entity.SqrEnterpriseApply;
import com.unis.policy.info.modular.sqrEnterpriseApply.mapper.SqrEnterpriseApplyMapper;
import com.unis.projectManagement.modular.pmApplication.entity.PmApplication;
import com.unis.projectManagement.modular.pmApplication.mapper.PmApplicationMapper;
import com.unis.projectManagement.modular.pmApplication.param.PmApplicationIdParam;
import com.unis.projectManagement.modular.pmApplication.param.PmApplicationPageParam;
import com.unis.projectManagement.modular.pmStorageConstruction.entity.PmStorageConstruction;
import com.unis.projectManagement.modular.pmStorageConstruction.mapper.PmStorageConstructionMapper;
import com.unis.projectManagement.modular.pmStorageConstruction.param.PmStorageConstructionIdParam;
import com.unis.projectManagement.modular.pmStorageConstruction.param.PmStorageConstructionPageParam;
import com.unis.projectManagement.modular.pmStorageConstructionFile.entity.PmStorageConstructionFile;
import com.unis.projectManagement.modular.pmStorageConstructionFile.mapper.PmStorageConstructionFileMapper;
import com.unis.projectManagement.modular.pmStorageConstructionPlan.entity.PmStorageConstructionPlan;
import com.unis.projectManagement.modular.pmStorageConstructionPlan.mapper.PmStorageConstructionPlanMapper;
import com.unis.sys.modular.org.entity.SysOrg;
import com.unis.sys.modular.org.mapper.SysOrgMapper;
import com.unis.sys.modular.user.entity.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 审核请求Service接口实现类
 *
 * @author TS
 * @date 2024/04/18 14:51
 **/
@Service
public class AuditRequestServiceImpl
        extends ServiceImpl<AuditRequestMapper, AuditRequest> implements AuditRequestService {

    @Resource
    private EsNetworkEntryService esNetworkEntryService;

    @Resource
    private EsNetworkEntryGrainService esNetworkEntryGrainService;
    @Resource
    private EsNetworkEntryMapper esNetworkEntryMapper;

    @Autowired
    private AlPolicyFileReportService alPolicyFileReportService;

    @Autowired
    private AuditRecordService auditRecordService;

    @Resource
    private AuditRequestMapper auditRequestMapper;

    @Resource
    private SqrEnterpriseMapper sqrEnterpriseMapper;

    @Resource
    private SqrEnterpriseApplyMapper sqrEnterpriseApplyMapper;

    @Resource
    private UnitInfoMapper unitInfoMapper;

    @Autowired
    private EmPersonPlanService emPersonPlanService;

    @Autowired
    private TFumigationRecordMapper tFumigationRecordMapper;

    @Autowired
    private SysOrgMapper sysOrgMapper;

    @Autowired
    private EnumMapper enumMapper;

    @Autowired
    private PmApplicationMapper pmApplicationMapper;

    @Autowired
    private PmStorageConstructionMapper pmStorageConstructionMapper;

    @Autowired
    private PmStorageConstructionPlanMapper pmStorageConstructionPlanMapper;

    @Autowired
    private PmStorageConstructionFileMapper pmStorageConstructionFileMapper;

    /*@Value("${jsgjjsjUrl}")
    private String jsgjjsjUrl;*/

    @Resource
    private RecPublishService recPublishService;

    @Override
    public Page<AuditRequest> page(AuditRequestPageParam auditRequestPageParam) {
        QueryWrapper<AuditRequest> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isAllNotEmpty(auditRequestPageParam.getSortField(), auditRequestPageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(auditRequestPageParam.getSortOrder());
            queryWrapper.orderBy(true, auditRequestPageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(auditRequestPageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(AuditRequest::getId);
        }
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void audit(AuditRequestAddParam auditRequestAddParam) {
        //业务类型  \r\n1：政策规范性文件申报；\r\n2：人才规划；\r\n3：承储资格；
        //设置默认值
        auditRequestAddParam.setAuditStatus(1); // 审核通过，默认
        auditRequestAddParam.setType("1");
        AlPolicyFileReport alPolicyFileReport = alPolicyFileReportService.getById(auditRequestAddParam.getRequestId());
        if (ObjectUtil.isEmpty(alPolicyFileReport)) {
            throw new CommonException("政策规范性文件申报不存在，id为{}", auditRequestAddParam.getRequestId());
        }
        //表示已完成
        if (alPolicyFileReport.getStatus() == 3) {
            throw new CommonException("政策规范性文件已完成，id值为：{}", alPolicyFileReport.getId());
        }
        //判断文件申报是否已经发起流程
        if (alPolicyFileReport.getStatus() != 1) {
            throw new CommonException("政策规范性文件申报未发起流程，id为{}", auditRequestAddParam.getRequestId());
        }

        AuditRequest request = BeanUtil.toBean(auditRequestAddParam, AuditRequest.class);

        //查询审核是否已经存在
        LambdaQueryWrapper<AuditRequest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AuditRequest::getType, auditRequestAddParam.getType());
        queryWrapper.eq(AuditRequest::getStep, auditRequestAddParam.getStep());
        queryWrapper.eq(AuditRequest::getRequestId, auditRequestAddParam.getRequestId());
        AuditRequest request1 = super.getOne(queryWrapper, false);
        if (request1 != null) { //表示数据已经进行审核或者驳回
            if (request1.getAuditStatus() == 1) { //表示是审核通过
                throw new CommonException(StringUtils.equals("1", auditRequestAddParam.getStep()) ? "已进行合法性审核" : "已进行过会审核");
            } else { //
                request.setId(request1.getId()); //设置id进行修改操作
            }

        }
        //如果是过会审核要查询已进行合法性审核并且通过
        if (StringUtils.equals("2", auditRequestAddParam.getStep())) {
            queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AuditRequest::getType, auditRequestAddParam.getType());
            queryWrapper.eq(AuditRequest::getStep, 1); // 合法性审核
            queryWrapper.eq(AuditRequest::getRequestId, auditRequestAddParam.getRequestId());
            queryWrapper.eq(AuditRequest::getAuditStatus, 1); //审核通过
            if (super.getOne(queryWrapper, false) == null) {
                throw new CommonException("未进行合法性审核或合法性审核未通过");
            }
            //修改政策文件状态为3：完成
            alPolicyFileReport.setStatus(3);
            if (!alPolicyFileReportService.updateById(alPolicyFileReport)) {
                throw new CommonException("修改政策规范性文件申报失败，id为{}", auditRequestAddParam.getRequestId());
            }
        }


        if (!this.saveOrUpdate(request)) {
            throw new CommonException("保存审核请求失败");
        }
        //保存审核记录
        saveRecord(request);
    }

    private void saveRecord(AuditRequest request) {
        AuditRecord auditRecord = new AuditRecord();
        auditRecord.setAuditRequestId(request.getId());
        auditRecord.setStep(request.getStep());
        auditRecord.setType(request.getType());
        auditRecord.setRequestId(request.getRequestId()); //申请id
        auditRecord.setAuditStatus(request.getAuditStatus());
        auditRecord.setAuditAdvice(request.getAuditAdvice());
        auditRecord.setAuditUserId(request.getAuditUserId());
        auditRecord.setAuditTime(request.getAuditTime());
        auditRecord.setAttachment(request.getAttachment());
        if (!auditRecordService.save(auditRecord)) {
            throw new CommonException("保存审核记录失败");
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void reject(AuditRequestAddParam auditRequestAddParam) {
        //设置默认值
        auditRequestAddParam.setAuditStatus(2); // 核驳回，默认
        auditRequestAddParam.setType("1"); //默认值 业务类型 1：政策规范性文件申报
        AlPolicyFileReport alPolicyFileReport = alPolicyFileReportService.getById(auditRequestAddParam.getRequestId());
        if (ObjectUtil.isEmpty(alPolicyFileReport)) {
            throw new CommonException("政策规范性文件申报不存在，id为{}", auditRequestAddParam.getRequestId());
        }
        //表示已完成
        if (alPolicyFileReport.getStatus() == 3) {
            throw new CommonException("政策规范性文件已完成，id值为：{}", alPolicyFileReport.getId());
        }
        //判断文件申报是否已经发起流程
        if (alPolicyFileReport.getStatus() != 1) {
            throw new CommonException("政策规范性文件申报未发起流程，id为{}", auditRequestAddParam.getRequestId());
        }
        AuditRequest request = BeanUtil.toBean(auditRequestAddParam, AuditRequest.class);

        //查询审核是否已经存在
        LambdaQueryWrapper<AuditRequest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AuditRequest::getType, auditRequestAddParam.getType());
        queryWrapper.eq(AuditRequest::getStep, auditRequestAddParam.getStep());
        queryWrapper.eq(AuditRequest::getRequestId, auditRequestAddParam.getRequestId());
        AuditRequest request1 = super.getOne(queryWrapper, false);
        if (!ObjectUtil.isEmpty(request1)) { //表示数据已经进行审核或者驳回
            if (request1.getAuditStatus() == 1) { //表示是审核通过
                throw new CommonException(StringUtils.equals("1", auditRequestAddParam.getStep()) ? "已进行合法性审核,不能驳回" : "已进行过会审核,不能驳回");
            } else { //
                request.setId(request1.getId()); //设置id进行修改操作
            }

        }
        AuditRequest request2 = null;
        //如果是过会审核要查询已进行合法性审核并且通过
        if (StringUtils.equals("2", auditRequestAddParam.getStep())) {
            queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AuditRequest::getType, auditRequestAddParam.getType());
            queryWrapper.eq(AuditRequest::getRequestId, auditRequestAddParam.getRequestId());
            queryWrapper.eq(AuditRequest::getStep, 1); // 合法性审核
            queryWrapper.eq(AuditRequest::getAuditStatus, 1); //审核通过
            request2 = super.getOne(queryWrapper, false);
            if (ObjectUtil.isEmpty(request2)) {
                throw new CommonException("未进行合法性审核或合法性审核未通过");
            }
        }
        if (!this.saveOrUpdate(request)) {
            throw new CommonException("保存驳回请求失败");
        }
        //保存当前审核操作审核记录
        saveRecord(request);
        //驳回是一驳到底，需要重新启动流程
        alPolicyFileReport.setStatus(2); //状态 0：待发起；1：已发起；2：驳回；
        if (!alPolicyFileReportService.updateById(alPolicyFileReport)) {
            throw new CommonException("修改政策规范性文件申报失败，id为{}", auditRequestAddParam.getRequestId());
        }
        //如果是过会审核要查询已进行合法性审核并且通过
        if (StringUtils.equals("2", auditRequestAddParam.getStep())) {
            if (!ObjectUtil.isEmpty(request2)) {
                //设置合法性审核为驳回状态，并保存驳回记录
                request2.setAuditStatus(2); //状态 0：待审核；1：已审核；2：驳回；
                request2.setAuditTime(request.getAuditTime());
                request2.setAuditAdvice(request.getAuditAdvice());
                request2.setAttachment(request.getAttachment());
                if (!this.saveOrUpdate(request2)) {
                    throw new CommonException("保存驳回合法性请求失败");
                }
                //保存合法性驳回审核记录
                saveRecord(request2);
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<AuditRequestIdParam> auditRequestIdParamList) {
        // 执行删除
        this.removeByIds(CollStreamUtil.toList(auditRequestIdParamList, AuditRequestIdParam::getId));
    }

    @Override
    public JSONObject detail(AuditRequestDetailParam auditRequestDetailParam) {
        JSONObject jsonObject = new JSONObject();
        if (StringUtils.isNotBlank(auditRequestDetailParam.getRequestId())) {
            AuditRequest auditRequest = this.queryEntity(auditRequestDetailParam.getRequestId());
            jsonObject.put("auditRequest", auditRequest);
        }
        if (StringUtils.isNotBlank(auditRequestDetailParam.getReportId())) {

            if (StringUtils.equals("2", auditRequestDetailParam.getType())) { //人才规划
                EmPersonPlan emPersonPlan = emPersonPlanService.queryEntity(auditRequestDetailParam.getReportId());
                jsonObject.put("emPersonPlan", emPersonPlan);
                return jsonObject;
            } else if (StringUtils.equals("3", auditRequestDetailParam.getType())) {  //承储资格审批

            }
            //表示是政策文件审核 ,默认是
            AlPolicyFileReport alPolicyFileReport = alPolicyFileReportService.queryEntity(auditRequestDetailParam.getReportId());
            jsonObject.put("alPolicyFileReport", alPolicyFileReport);
            //表示是过会审核，需要展示审核记录
            if (StringUtils.equals("2", auditRequestDetailParam.getStep())) {
                List<Map<String, Object>> records = auditRequestMapper.queryReconds(alPolicyFileReport.getId());
                jsonObject.put("records", records);
            }
        }
        return jsonObject;
    }


    @Override
    public AuditRequest queryEntity(String id) {
        AuditRequest auditRequest = this.getById(id);
        if (ObjectUtil.isEmpty(auditRequest)) {
            throw new CommonException("审核请求不存在，id值为：{}", id);
        }
        return auditRequest;
    }


    /**
     * 承储资格审批 --点击审批的接口
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void eligibilityApproval(AuditRequestStorageAddParam auditRequestStorageAddParam) {


        //查询是否有申请的记录
        LambdaQueryWrapper<AuditRequest> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AuditRequest::getType, 3);
        wrapper.eq(AuditRequest::getStep, 1);
        wrapper.eq(AuditRequest::getAuditStatus, 0);
        wrapper.eq(AuditRequest::getRequestId, auditRequestStorageAddParam.getRequestId());

        List<AuditRequest> auditRequests = auditRequestMapper.selectList(wrapper);

        if (CollectionUtil.isEmpty(auditRequests)) {
            throw new CommonException("审核申请记录不存在，请求id为{}", auditRequestStorageAddParam.getRequestId());
        }

        //审批时，传的是biz_sqr_enterprise_apply的id；
        SqrEnterpriseApply sqrEnterpriseApply = sqrEnterpriseApplyMapper.selectById(auditRequestStorageAddParam.getRequestId());
        if (ObjectUtil.isEmpty(sqrEnterpriseApply)) {
            throw new CommonException("承储资格申请数据不存在，id为{}", auditRequestStorageAddParam.getRequestId());
        }

        SqrEnterprise sqrEnterprise = sqrEnterpriseMapper.selectById(sqrEnterpriseApply.getSqrEnterpriseId());
        if (ObjectUtil.isEmpty(sqrEnterprise)) {
            throw new CommonException("承储资格资格认定数据不存在，id为{}", sqrEnterpriseApply.getSqrEnterpriseId());
        }

        //添加审批意见
        //类型
        AuditRequest auditRequest = auditRequests.get(0);
        BeanUtil.copyProperties(auditRequestStorageAddParam, auditRequest);

        auditRequest.setAuditTime(new Date());
        auditRequest.setCreateTime(new Date());
        auditRequestMapper.updateById(auditRequest);


        //修改企业申请状态
        /*sqrEnterpriseApplyMapper.update(null, new LambdaUpdateWrapper<SqrEnterpriseApply>()
                .eq(SqrEnterpriseApply::getId, sqrEnterpriseApply.getId())
        );*/


        //修改承储资格资格认定
        if (auditRequestStorageAddParam.getAuditStatus() == 1) {
            sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                    .eq(SqrEnterprise::getId, sqrEnterprise.getId())
                    .set(SqrEnterprise::getStatus, 2));

            if (sqrEnterpriseApply.getApplyType() == 2) {
                sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                        .eq(SqrEnterprise::getId, sqrEnterprise.getId())
                        .set(SqrEnterprise::getStorageExpireTime, new Date()));
            }

        }
        if (auditRequestStorageAddParam.getAuditStatus() == 2) {
            sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                    .eq(SqrEnterprise::getId, sqrEnterprise.getId())
                    .set(SqrEnterprise::getStatus, 0));
        }

        AuditRequest auditRequest1 = auditRequests.get(0);
        BeanUtil.copyProperties(auditRequestStorageAddParam, auditRequest1);
        auditRequest1.setStep(1);
        auditRequest1.setType(3);
        auditRequest1.setAuditTime(new Date());

        saveRecord(auditRequest1);
    }

    /*    * 承储资格审批 --审批接口 审批时，做回显数据
     *
     * @author hjc
     * @date  2024/04/18 14:51
     */
    @Override
    public SqrEnterpriseVO getAudit(SqrEnterpriseIdParam enterpriseIdParam) {

        //通过申请id进行回显数据  biz_sqr_enterprise

        return sqrEnterpriseMapper.selectSqrEnterpriseVO(enterpriseIdParam.getId());
    }

    /**
     * 承储资格审批--获取详情
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public JSONObject getSqrEnterpriseDetail(AuditRequestGetDetailParam auditRequestGetDetailParam) {


        JSONObject jsonObject = new JSONObject();

        SqrEnterpriseApply sqrEnterpriseApply = sqrEnterpriseApplyMapper.selectById(auditRequestGetDetailParam.getRequestId());
        jsonObject.put("sqrEnterpriseApply", sqrEnterpriseApply);

        //获取承储申请的数据
        LambdaQueryWrapper<SqrEnterprise> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SqrEnterprise::getId, sqrEnterpriseApply.getSqrEnterpriseId());
        SqrEnterprise sqrEnterprise = sqrEnterpriseMapper.selectOne(wrapper);
        jsonObject.put("sqrEnterprise", sqrEnterprise);

        //获取企业信息数据
        UnitInfo unitInfo = unitInfoMapper.selectOne(Wrappers.lambdaQuery(UnitInfo.class)
                .eq(UnitInfo::getId, sqrEnterpriseApply.getUnitInfoId()));
        BasicEnum basicEnum = enumMapper.selectById(unitInfo.getDwlx());
        unitInfo.setDwlx(basicEnum.getDictLabel());

        jsonObject.put("unitInfo", unitInfo);

        AuditRequest auditRequest = auditRequestMapper.selectOne(Wrappers.lambdaQuery(AuditRequest.class)
                .eq(AuditRequest::getRequestId, sqrEnterpriseApply.getId())
        );
        jsonObject.put("auditRequest", auditRequest);

        return jsonObject;
    }

    /**
     * 承储资格审批--分页展示列表数据
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public Page<AuditRequestVO> pageSqrEnterprise(AuditRequestPageParam auditRequestPageParam) {

        Page<AuditRequestVO> page = new Page<>(auditRequestPageParam.getCurrent(), auditRequestPageParam.getSize());
        return auditRequestMapper.selectMyPage(page, auditRequestPageParam.getDwmc());

    }


    /**
     * 承储资格企业--分页展示列表数据
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public Page<AuditRequestVO> pageEnterprise(AuditRequestPageParam auditRequestPageParam) {
        Page<AuditRequestVO> page = new Page<>(auditRequestPageParam.getCurrent(), auditRequestPageParam.getSize());
        return auditRequestMapper.enterprisePage(page, auditRequestPageParam.getDwmc());
    }


    /**
     * 承储资格企业--查看详情
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public SqrEnterpriseVO enterpriseInfo(String id) {
        return sqrEnterpriseMapper.enterpriseInfo(id);
    }


    /**
     * 承储资格延续申请--分页查询
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public Page<AuditRequestVO> continuationPage(AuditRequestPageParam auditRequestPageParam) {
        Page<AuditRequestVO> page = new Page<>(auditRequestPageParam.getCurrent(), auditRequestPageParam.getSize());
        return auditRequestMapper.continuationPage(page, auditRequestPageParam.getDwmc());
    }

    /**
     * 补发证书--分页查询
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public Page<AuditRequestVO> reissuePage(AuditRequestPageParam auditRequestPageParam) {
        Page<AuditRequestVO> page = new Page<>(auditRequestPageParam.getCurrent(), auditRequestPageParam.getSize());
        return auditRequestMapper.reissuePage(page, auditRequestPageParam.getDwmc());
    }


    /**
     * 补发证书--查看详情
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public UnitInfoVO reissueInfo(String id) {

        //通过申请id查看数据
        return auditRequestMapper.selectReissueInfo(id);
    }


    /**
     * 补发证书--审核
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void reissueAudit(AuditRequestStorageAddParam auditRequestStorageAddParam) {
        //查询是否有申请的记录
        LambdaQueryWrapper<AuditRequest> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AuditRequest::getType, 3);
        wrapper.eq(AuditRequest::getStep, 1);
        wrapper.eq(AuditRequest::getAuditStatus, 0);
        wrapper.eq(AuditRequest::getRequestId, auditRequestStorageAddParam.getRequestId());

        List<AuditRequest> auditRequests = auditRequestMapper.selectList(wrapper);

        if (CollectionUtil.isEmpty(auditRequests)) {
            throw new CommonException("审核申请记录不存在，请求id为{}", auditRequestStorageAddParam.getRequestId());
        }


        //审批时，传的是biz_sqr_enterprise_apply的id；
        SqrEnterpriseApply sqrEnterpriseApply = sqrEnterpriseApplyMapper.selectById(auditRequestStorageAddParam.getRequestId());
        if (ObjectUtil.isEmpty(sqrEnterpriseApply)) {
            throw new CommonException("承储资格申请数据不存在，id为{}", auditRequestStorageAddParam.getRequestId());
        }

   /*     SqrEnterprise sqrEnterprise = sqrEnterpriseMapper.selectById(sqrEnterpriseApply.getSqrEnterpriseId());
        if (ObjectUtil.isEmpty(sqrEnterprise)) {
            throw new CommonException("承储资格资格认定数据不存在，id为{}", sqrEnterpriseApply.getSqrEnterpriseId());
        }*/


        //添加审批意见
        AuditRequest auditRequest = auditRequests.get(0);
        BeanUtil.copyProperties(auditRequestStorageAddParam, auditRequest);

        auditRequest.setAuditTime(new Date());
        auditRequest.setCreateTime(new Date());
        auditRequestMapper.updateById(auditRequest);


        //修改企业申请状态
        sqrEnterpriseApplyMapper.update(null, new LambdaUpdateWrapper<SqrEnterpriseApply>()
                .eq(SqrEnterpriseApply::getId, sqrEnterpriseApply.getId())
                .eq(SqrEnterpriseApply::getApplyType, 3)
                .set(SqrEnterpriseApply::getReissueTime, auditRequestStorageAddParam.getAuditStatus() == 1 ? new Date() : null));

        //如果状态是1 通过 设置补发时间
        //转台是2 驳回  不需要设置补发时间

     /*   //修改承储资格资格认定
        if (auditRequestStorageAddParam.getAuditStatus() == 1) {
            sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                    .eq(SqrEnterprise::getId, sqrEnterprise.getId())
                    .set(SqrEnterprise::getStatus, 2));
        }
        if (auditRequestStorageAddParam.getAuditStatus() == 2) {
            sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                    .eq(SqrEnterprise::getId, sqrEnterprise.getId())
                    .set(SqrEnterprise::getStatus, 0));
        }*/

        BeanUtil.copyProperties(auditRequestStorageAddParam, auditRequest);
        auditRequest.setStep(1);
        auditRequest.setType(3);
        auditRequest.setAuditTime(new Date());

        saveRecord(auditRequest);
    }


    /**
     * 信息变更审批--分页
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Override
    public Page<AuditRequestVO> infoChangesPage(AuditRequestPageParam auditRequestPageParam) {
        Page<AuditRequestVO> page = new Page<>(auditRequestPageParam.getCurrent(), auditRequestPageParam.getSize());
        return auditRequestMapper.infoChangesPage(page, auditRequestPageParam.getDwmc());

    }


    /**
     * 信息变更审批--审核
     *
     * @author hjc
     * @date 2024/04/18 14:51
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void infoChangesAudit(AuditRequestStorageAddParam auditRequestGetDetailParam) {
        String requestId = auditRequestGetDetailParam.getRequestId();
        //获取对应的请求数据
        SqrEnterpriseApply sqrEnterpriseApply = sqrEnterpriseApplyMapper.selectById(requestId);
        if (ObjectUtil.isEmpty(sqrEnterpriseApply)) {
            throw new CommonException("承储资格认定未进行提交申请审核，id为{}", sqrEnterpriseApply.getSqrEnterpriseId());
        }

    /*    SqrEnterprise sqrEnterprise = sqrEnterpriseMapper.selectById(sqrEnterpriseApply.getSqrEnterpriseId());
        if (ObjectUtil.isEmpty(sqrEnterprise)) {
            throw new CommonException("承储企业未找到对应数据，id为{}", sqrEnterpriseApply.getSqrEnterpriseId());
        }
*/
        List<AuditRequest> auditRequests = auditRequestMapper.selectList(new LambdaQueryWrapper<AuditRequest>()
                .eq(AuditRequest::getRequestId, requestId)
                .eq(AuditRequest::getStep, 1)
                .eq(AuditRequest::getType, 3)
                .eq(AuditRequest::getAuditStatus, 0));
        if (CollectionUtil.isEmpty(auditRequests)) {
            throw new CommonException("审核请求不存在，id为{}", sqrEnterpriseApply.getSqrEnterpriseId());
        }


        sqrEnterpriseMapper.update(null, new LambdaUpdateWrapper<SqrEnterprise>()
                .eq(SqrEnterprise::getId, sqrEnterpriseApply.getSqrEnterpriseId())
                .set(SqrEnterprise::getStatus, auditRequestGetDetailParam.getAuditStatus() == 2 ? 0 : 2)
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getFullTimeStaffCount,
                        sqrEnterpriseApply.getFullTimeStaffCount())
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getCertifiedInspectorCount,
                        sqrEnterpriseApply.getCertifiedInspectorCount())
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getCertifiedStorekeeperCount,
                        sqrEnterpriseApply.getCertifiedStorekeeperCount())
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getStorageExpireTime,
                        sqrEnterpriseApply.getStorageExpireTime())
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getWarehouseFacilitySituation,
                        sqrEnterpriseApply.getWarehouseFacilitySituation())
                .set(auditRequestGetDetailParam.getAuditStatus() == 1,
                        SqrEnterprise::getAttachment,
                        sqrEnterpriseApply.getAttachment()));
        auditRequestMapper.update(null, new LambdaUpdateWrapper<AuditRequest>()
                .eq(AuditRequest::getId, auditRequests.get(0).getId())
                .set(AuditRequest::getAuditStatus, auditRequestGetDetailParam.getAuditStatus() == 2 ? 2 : 1)
                .set(AuditRequest::getAuditUserId, auditRequestGetDetailParam.getAuditUserId())
                .set(AuditRequest::getUpdateTime, new Date())
                .set(AuditRequest::getAuditTime, auditRequestGetDetailParam.getAuditTime())
                .set(AuditRequest::getAuditAdvice, auditRequestGetDetailParam.getAuditAdvice()));

        AuditRequest auditRequest = auditRequests.get(0);
        BeanUtil.copyProperties(auditRequestGetDetailParam, auditRequest);
        auditRequest.setStep(1);
        auditRequest.setType(3);
        auditRequest.setAuditTime(new Date());


        this.saveRecord(auditRequest);
    }

    /**
     * 行人才规则审核/驳回操作
     *
     * @param auditRequestAddParam
     * @return
     */
    @Override
    public String auditPersonPlan(AuditRequestAddParam auditRequestAddParam) {
        //设置默认值
//            auditRequestAddParam.setAuditStatus(2); // 审核驳回，默认
        auditRequestAddParam.setType("2"); //默认值 业务类型 2：人才规划
        auditRequestAddParam.setStep("1"); //默认值 1：规划审批
        EmPersonPlan emPersonPlan = emPersonPlanService.queryEntity(auditRequestAddParam.getRequestId());
        //判断人才规划是否已经发起流程
        if (emPersonPlan.getStatus() != 1) {
            throw new CommonException("企业管理-人才规划未发起流程，id为{}", auditRequestAddParam.getRequestId());
        }

        AuditRequest request = BeanUtil.toBean(auditRequestAddParam, AuditRequest.class);

        //查询审核是否已经存在
        LambdaQueryWrapper<AuditRequest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AuditRequest::getType, auditRequestAddParam.getType());
        queryWrapper.eq(AuditRequest::getStep, auditRequestAddParam.getStep());
        queryWrapper.eq(AuditRequest::getRequestId, auditRequestAddParam.getRequestId());
        AuditRequest request1 = super.getOne(queryWrapper, false);
        if (!ObjectUtil.isEmpty(request1)) { //表示数据已经进行审核或者驳回
            request.setId(request1.getId());
            if (request1.getAuditStatus() == 1) //表示是审核
                throw new CommonException("已审核通过");
        }
        if (!this.saveOrUpdate(request)) {
            throw new CommonException("保存驳回请求失败");
        }
        //保存当前审核操作审核记录
        saveRecord(request);
        if (auditRequestAddParam.getAuditStatus() == 2) {
            //驳回是一驳到底，需要重新启动流程
            emPersonPlan.setStatus(2); //状态 0：待发起；1：已发起；2：驳回 3:完成；
        } else {
            emPersonPlan.setStatus(3); //状态 0：待发起；1：已发起；2：驳回 3:完成；
        }
        if (!emPersonPlanService.updateById(emPersonPlan)) {
            throw new CommonException("修改企业管理-人才规划失败，id为{}", auditRequestAddParam.getRequestId());
        }
        return "操作成功";
    }


    /**
     * 获取熏蒸备案分页
     *
     * @author hjc
     * @date 2024/05/18 15:59
     */
    @Override
    public Page<TFumigationRecord> tFumigationRecordPage(TFumigationRecordPageParam tFumigationRecordPageParam) {
        QueryWrapper<TFumigationRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status_type", 1);
        if (StringUtils.isNotEmpty(tFumigationRecordPageParam.getOrderNumber())) {
            queryWrapper.like("order_number", tFumigationRecordPageParam.getOrderNumber());
        }
        if (StringUtils.isNotEmpty(tFumigationRecordPageParam.getOrgName())) {
            queryWrapper.like("org_name", tFumigationRecordPageParam.getOrgName());
        }
        if (ObjectUtil.isAllNotEmpty(tFumigationRecordPageParam.getSortField(), tFumigationRecordPageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(tFumigationRecordPageParam.getSortOrder());
            queryWrapper.orderBy(true, tFumigationRecordPageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(tFumigationRecordPageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(TFumigationRecord::getCreateTime);
        }
        return tFumigationRecordMapper.selectPage(CommonPageRequest.defaultPage(), queryWrapper);

    }

    /**
     * 获取熏蒸备案详情
     *
     * @author hjc
     * @date 2024/05/18 15:59
     */
    @Override
    public TFumigationRecord gettFumigationRecordDetail(TFumigationRecordIdParam tFumigationRecordIdParam) {
        return tFumigationRecordMapper.selectById(tFumigationRecordIdParam.getId());
    }


    /**
     * 审核熏蒸备案
     *
     * @author hjc
     * @date 2024/05/18 15:59
     */
    @Transactional
    @Override
    public void auditTFumigationRecordById(TFumigationRecordAuditParam param) {

       /* SysUser user = (SysUser) StpClientUtil.getTokenSession().get("loginUser");
        SysOrg sysOrg = sysOrgMapper.selectById(user.getOrgId());
        if (ObjectUtil.isNotEmpty(sysOrg) && "1774729858638458882".equals(sysOrg.getId())) {
            throw new CommonException("您未有审核权限,组织id为{}", sysOrg.getId());
        }*/
        TFumigationRecord tFumigationRecord = tFumigationRecordMapper.selectTFumigationRecordById(param.getId());
        if (param.getAuditStatus() == 1) {
            //tFumigationRecord.setStatusType(2);
            tFumigationRecordMapper.updateTFumigationRecordTwo(param.getId());
        }
        if (param.getAuditStatus() == 2) {
            //tFumigationRecord.setStatusType(3);
            tFumigationRecordMapper.updateTFumigationRecordThere(param.getId());
        }
        //更新表状态
        //tFumigationRecordMapper.updateById(tFumigationRecord);


        AuditRequest auditRequest = auditRequestMapper.selectOne(Wrappers.lambdaQuery(AuditRequest.class)
                .eq(AuditRequest::getRequestId, param.getId()));
        auditRequest.setAuditStatus(param.getAuditStatus());
        auditRequest.setAuditTime(new Date());
        this.updateById(auditRequest);

        //添加保存记录
        auditRequest.setAuditStatus(param.getAuditStatus());
        auditRequest.setAuditTime(new Date());

        saveRecord(auditRequest);

    }

    @Override
    public Page<EsNetworkEntry> esNetworkEntryPage(EsNetworkEntryPageParam esNetworkEntryPageParam) {

        Page<EsNetworkEntry> page = new Page<>(esNetworkEntryPageParam.getCurrent(), esNetworkEntryPageParam.getSize());
        return auditRequestMapper.esNetworkEntryPage(page, esNetworkEntryPageParam);

    }

    @Override
    public EsNetworkEntryVO selectesNetworkEntryDetail(EsNetworkEntryIdParam esNetworkEntryIdParam) {
        EsNetworkEntryVO esNetworkEntryVO = esNetworkEntryMapper.selectesNetworkEntryDetail(esNetworkEntryIdParam);
        QueryWrapper<EsNetworkEntryGrain> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("es_network_entry_id", esNetworkEntryIdParam.getId());
        List<EsNetworkEntryGrain> esNetworkEntryGrains = esNetworkEntryGrainService.list(queryWrapper);
        esNetworkEntryVO.setEsNetworkEntryGrainList(esNetworkEntryGrains);
        return esNetworkEntryVO;
    }

    /**
     * 通用的审批
     *
     * @param auditRequestEditParam
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void esNetworkEntryRequest(AuditRequestEditParam auditRequestEditParam) {
        Integer type = auditRequestEditParam.getType();
        if (ObjectUtil.isEmpty(auditRequestEditParam)) {
            throw new CommonException("审批申报不存在，id为{}", auditRequestEditParam.getId());
        }
        AuditRequest request = BeanUtil.toBean(auditRequestEditParam, AuditRequest.class);
        if (TypeEnum.YJBZ_YJWD.getType().equals(type)) {
            AuditRequest request1 = new AuditRequest();
            request1.setId(request.getRequestId());
            request1.setAuditStatus(request.getAuditStatus());
            request1.setAuditAdvice(request.getAuditAdvice());
            request1.setRequestId(request.getId());

//            request.setRequestId(request.getId());
//            request.setAuditStatus(auditRequestEditParam.getAuditStatus());
//            request.setId(request.getRequestId());
            this.updateById(request1);
            QueryWrapper<EsNetworkEntry> esNetworkEntryQueryWrapper = new QueryWrapper<>();
            EsNetworkEntry esNetworkEntry = esNetworkEntryService.queryEntity(auditRequestEditParam.getId());
            if(auditRequestEditParam.getAuditStatus()==1){
                esNetworkEntry.setStatus(3);
            }
            if(auditRequestEditParam.getAuditStatus()==2){
                esNetworkEntry.setStatus(auditRequestEditParam.getAuditStatus());
            }
            esNetworkEntryService.updateById(esNetworkEntry);

            AuditRecord auditRecord =new AuditRecord();
            auditRecord.setType(5);
            auditRecord.setStep(1);
            auditRecord.setAuditRequestId(auditRequestEditParam.getRequestId());
            auditRecord.setRequestId(auditRequestEditParam.getId());
            auditRecord.setAuditStatus(auditRequestEditParam.getAuditStatus());
            //auditRecord.setId(auditRequestEditParam.getRequestId());
            auditRecordService.save(auditRecord);
        }
    }


    /**
     * 获取项目审批分页
     *
     * @author hjc
     * @date 2024/05/27 17:26
     */
    @Override
    public Page<PmApplicationVO> approvalPage(PmApplicationByStatusPageParam pmApplicationPageParam) {

        //查申请表数据
        Page<PmApplicationVO> page = new Page<>(pmApplicationPageParam.getCurrent(), pmApplicationPageParam.getSize());
        return auditRequestMapper.selectApprovalPage(page, pmApplicationPageParam.getProjectName(),
                pmApplicationPageParam.getAuditStatus());

    }

    /**
     * 获取项目申报管理表详情
     *
     * @author hjc
     * @date 2024/05/27 17:26
     */
    @Override
    public PmApplicationVO getPmApplicationDetail(PmApplicationIdParam pmApplicationIdParam) {

        PmApplicationVO vo = new PmApplicationVO();
        PmApplication pmApplication = pmApplicationMapper.selectById(pmApplicationIdParam.getId());

        //设置省
        if (StringUtils.isNotEmpty(pmApplication.getConstructionLocationProvince())) {
            BasicEnum province = enumMapper.selectById(pmApplication.getConstructionLocationProvince());
            if (ObjectUtil.isNotEmpty(province)){
                pmApplication.setConstructionLocationProvince(province.getDictLabel());
            }
        }
        //设置市
        if (StringUtils.isNotEmpty(pmApplication.getConstructionLocationCity())) {
            BasicEnum city = enumMapper.selectById(pmApplication.getConstructionLocationCity());
            if (ObjectUtil.isNotEmpty(city)){
                pmApplication.setConstructionLocationCity(city.getDictLabel());
            }

        }
        //设置区
        if (StringUtils.isNotEmpty(pmApplication.getConstructionLocationDistrict())) {
            BasicEnum district = enumMapper.selectById(pmApplication.getConstructionLocationDistrict());
            if (ObjectUtil.isNotEmpty(district)){
                pmApplication.setConstructionLocationDistrict(district.getDictLabel());
            }

        }
        BeanUtils.copyProperties(pmApplication, vo);

        AuditRequest auditRequest = auditRequestMapper.selectOne(Wrappers.lambdaQuery(AuditRequest.class)
                .eq(AuditRequest::getRequestId, pmApplicationIdParam.getId()));
        if (ObjectUtil.isNotEmpty(auditRequest)) {
            vo.setAuditAdvice(auditRequest.getAuditAdvice());
        }

        return vo;

    }

    /**
     * 项目管理-审核
     *
     * @author hjc
     * @date 2024/05/18 15:59
     */
    @Override
    public void auditPmApplicationById(PmApplicationParam param) {
        //查询是否有申请的记录
        LambdaQueryWrapper<AuditRequest> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AuditRequest::getType, 6);
        wrapper.eq(AuditRequest::getStep, 1);
        wrapper.eq(AuditRequest::getAuditStatus, 0);
        wrapper.eq(AuditRequest::getRequestId, param.getRequestId());

        List<AuditRequest> auditRequests = auditRequestMapper.selectList(wrapper);

        if (CollectionUtil.isEmpty(auditRequests)) {
            throw new CommonException("审核申请记录不存在，请求id为{}", param.getRequestId());
        }

        //添加审批意见
        //类型
        AuditRequest auditRequest = auditRequests.get(0);
        BeanUtil.copyProperties(param, auditRequest);

        auditRequest.setAuditTime(new Date());
        auditRequest.setCreateTime(new Date());
        auditRequestMapper.updateById(auditRequest);

        saveRecord(auditRequest);

        //如果传入的状态是1 已审核
        if (param.getAuditStatus() == 1) {
            //设置表状态为3
            pmApplicationMapper.update(null, Wrappers.lambdaUpdate(PmApplication.class)
                    .eq(PmApplication::getId, param.getRequestId())
                    .set(PmApplication::getStatus, 3));

            /**
             * 上传国家局
             */
            //操作标志 、表名、业务id、单位id
            recPublishService.sendMessage("i", jkEnum.xmxx.getTableName(),param.getRequestId()+"",Integer.valueOf(0));
        }
        //如果传入的状态是2 驳回
        if (param.getAuditStatus() == 2) {
            //设置表状态为2
            pmApplicationMapper.update(null, Wrappers.lambdaUpdate(PmApplication.class)
                    .eq(PmApplication::getId, param.getRequestId())
                    .set(PmApplication::getStatus, 2));
        }

    }


    /**
     * 获取仓储设施投资-仓储设施建设审批分页
     *
     * @author hjc
     * @date 2024/05/30 15:58
     */
    @Override
    public Page<PmStorageConstruction> pmStorageConstructionPage(PmStorageConstructionPageParam pageParam) {

        Page<PmStorageConstruction> page = new Page<>(pageParam.getCurrent(), pageParam.getSize());
        return auditRequestMapper.selectPmStorageConstructionPage(page, pageParam.getProjectName());

    }

    /**
     * 获取仓储设施投资-仓储设施建设审批详情
     *
     * @author hjc
     * @date 2024/05/30 15:58
     */
    @Override
    public JSONObject getPmStorageConstruction(PmStorageConstructionIdParam param) {

        JSONObject jsonObject = new JSONObject();

        //仓储设施建设基础数据
        PmStorageConstruction pmStorageConstruction = pmStorageConstructionMapper.selectById(param.getId());
        jsonObject.put("pmStorageConstruction", pmStorageConstruction);

        //添加进度计划
        List<PmStorageConstructionPlan> pmStorageConstructionPlanList = pmStorageConstructionPlanMapper.selectList(Wrappers.lambdaQuery(PmStorageConstructionPlan.class)
                .eq(PmStorageConstructionPlan::getPmStorageConstructionId, pmStorageConstruction.getId()));
        jsonObject.put("pmStorageConstructionPlanList", pmStorageConstructionPlanList);

        //添加申报资料
        List<PmStorageConstructionFile> pmStorageConstructionFileList = pmStorageConstructionFileMapper.selectList(Wrappers.lambdaQuery(PmStorageConstructionFile.class)
                .eq(PmStorageConstructionFile::getPmStorageConstructionId, pmStorageConstruction.getId()));
        jsonObject.put("pmStorageConstructionFileList", pmStorageConstructionFileList);


        //查看申请表数据
        AuditRequest auditRequest = auditRequestMapper.selectOne(Wrappers.lambdaQuery(AuditRequest.class)
                .eq(AuditRequest::getRequestId, pmStorageConstruction.getId()));
        jsonObject.put("auditRequest", auditRequest);

        return jsonObject;

    }

    /**
     * 仓储设施建设审批-审核
     *
     * @author hjc
     * @date 2024/05/18 15:59
     */
    @Override
    public void auditPmStorageConstructionById(PmStorageConstructionAuditParam param) {

        //查询是否有申请的记录
        LambdaQueryWrapper<AuditRequest> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AuditRequest::getType, 9);
        wrapper.eq(AuditRequest::getStep, 1);
        wrapper.eq(AuditRequest::getAuditStatus, 0);
        wrapper.eq(AuditRequest::getRequestId, param.getRequestId());

        List<AuditRequest> auditRequests = auditRequestMapper.selectList(wrapper);

        if (CollectionUtil.isEmpty(auditRequests)) {
            throw new CommonException("审核申请记录不存在，请求id为{}", param.getRequestId());
        }

        //添加审批意见
        //类型
        AuditRequest auditRequest = auditRequests.get(0);
        BeanUtil.copyProperties(param, auditRequest);

        auditRequest.setAuditTime(new Date());
        auditRequest.setCreateTime(new Date());
        auditRequestMapper.updateById(auditRequest);

        saveRecord(auditRequest);

        //如果传入的状态是1 已审核
        if (param.getAuditStatus() == 1) {
            //设置表状态为3
            pmStorageConstructionMapper.update(null, Wrappers.lambdaUpdate(PmStorageConstruction.class)
                    .eq(PmStorageConstruction::getId, param.getRequestId())
                    .set(PmStorageConstruction::getStatus, 3));
        }
        //如果传入的状态是2 驳回
        if (param.getAuditStatus() == 2) {
            //设置表状态为2
            pmStorageConstructionMapper.update(null, Wrappers.lambdaUpdate(PmStorageConstruction.class)
                    .eq(PmStorageConstruction::getId, param.getRequestId())
                    .set(PmStorageConstruction::getStatus, 2));
        }
    }


}
