package com.chinaweal.aiccs.aiccs.force.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.abnormal.entity.Gzaiccode;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSWrit;
import com.chinaweal.aiccs.aiccs.abnormal.service.IGzaiccodeService;
import com.chinaweal.aiccs.aiccs.abnormal.service.TSWritService;
import com.chinaweal.aiccs.aiccs.business.entity.XrOpinion;
import com.chinaweal.aiccs.aiccs.business.entity.XrTaskList;
import com.chinaweal.aiccs.aiccs.business.entity.dto.ApprovalFormDto;
import com.chinaweal.aiccs.aiccs.business.entity.vo.XrTaskListVo;
import com.chinaweal.aiccs.aiccs.business.rules.init.FlowUtil;
import com.chinaweal.aiccs.aiccs.business.service.IXrOpinionService;
import com.chinaweal.aiccs.aiccs.business.service.IXrTaskListService;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterRem;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterRes;
import com.chinaweal.aiccs.aiccs.force.entity.XrForceDeregisterSpe;
import com.chinaweal.aiccs.aiccs.force.entity.querydto.ForceDeregisterSpeQueryDto;
import com.chinaweal.aiccs.aiccs.force.entity.querydto.ForceDeregisterSpeSaveDto;
import com.chinaweal.aiccs.aiccs.force.mapper.XrForceDeregisterRemMapper;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterRemService;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterResService;
import com.chinaweal.aiccs.aiccs.force.service.IXrForceDeregisterSpeService;
import com.chinaweal.aiccs.aiccs.inspect.service.TSWorkNoService;
import com.chinaweal.aiccs.aiccs.seriousillegalPerson.common.emnu.AuthEnum;
import com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.aiccs.aiccs.writs.entity.Tswrittemplate;
import com.chinaweal.aiccs.aiccs.writs.service.TswrittemplateService;
import com.chinaweal.aiccs.common.constant.BaseDataConstant;
import com.chinaweal.aiccs.common.constant.FlowConstant;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.common.util.WorkNoUtil;
import com.chinaweal.aiccs.org.service.AicorgService;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.aicorg.pojo.AICPermission;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.exception.custom.BusinessException;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;


/**
 * 终止强制注销业务表 服务实现类
 *
 * @author zhouxy
 * @since 2025/9/29
 */
@Service
public class XrForceDeregisterRemServiceImpl extends ServiceImpl<XrForceDeregisterRemMapper, XrForceDeregisterRem> implements IXrForceDeregisterRemService {

    @Resource
    private AicorgService aicorgService;
    @Resource
    private IXrTaskListService iXrTaskListService;
    @Resource
    private IXrForceDeregisterSpeService xrForceDeregisterSpeService;
    @Resource
    private IXrForceDeregisterResService xrForceDeregisterResService;
    @Resource
    private TRBaseCodeService trBaseCodeService;
    @Resource
    private TswrittemplateService tswrittemplateService;
    @Resource
    private TSWorkNoService tsWorkNoService;
    @Resource
    private TSWritService tsWritService;
    @Resource
    private IXrOpinionService opinionService;
    @Resource
    private IGzaiccodeService gzaiccodeService;

    @Override
    public IPage<XrForceDeregisterRem> listXrForceDeregisterRem(BaseQuery<ForceDeregisterSpeQueryDto> query, AICUser user) {
        Map<String, AICPermission> aicPermissions = user.getAicPermissions();
        // 权限
        List<String> authList = new ArrayList<>();
        authList.add(user.getPrimaryKey());
        if (aicPermissions.containsKey(AuthEnum.XR_HANDLE.getTsPermissionCode())) {
            authList.add(user.getRegionID() + ":" +AuthEnum.XR_HANDLE.getCode());
        }
        ForceDeregisterSpeQueryDto entity = query.getEntity(ForceDeregisterSpeQueryDto.class);
        entity.setAuthList(authList);
        IPage<XrForceDeregisterRem> xrForceDeregisterRemIPage;
        Page<XrForceDeregisterRem> page = new Page<>(query.getCurrent(), query.getSize());
        if (Objects.equals(entity.getBusType(), "todo")) {  //待办
            entity.setBusStatus("0");
            xrForceDeregisterRemIPage = baseMapper.selectXrForceDeregisterRemTodo(page, entity);
        } else if (Objects.equals(entity.getBusType(), "history")) {    //记录
            String regOrg = aicorgService.getOrgnumberByUserLevel(user,false);
            entity.setRegOrg(regOrg);
            xrForceDeregisterRemIPage = baseMapper.selectXrForceDeregisterRemHistory(page, entity);
        } else {
            throw new BusinessException("查询列表类型错误，请联系管理员处理");
        }
        return xrForceDeregisterRemIPage;
    }

    @Override
    public IPage<XrForceDeregisterSpe> forceSpePageByRegOrg(BaseQuery<ForceDeregisterSpeQueryDto> query, AICUser user) {
        ForceDeregisterSpeQueryDto entity = query.getEntity(ForceDeregisterSpeQueryDto.class);
        String forceRemType = entity.getForceRemType();
        IPage<XrForceDeregisterSpe> forceDeregisterSpeIPage = new Page<>();
        String entName = entity.getEntName();
        String searchUscc = entity.getSearchUscc();

        Page<XrForceDeregisterSpe> page = new Page<>(query.getCurrent(), query.getSize());
        LambdaQueryWrapper<XrForceDeregisterSpe> wrapper = new LambdaQueryWrapper<>();
        //按受理机关查询
        wrapper.eq(XrForceDeregisterSpe::getAcceptOrg, user.getRegionID())
                .eq(XrForceDeregisterSpe::getStatus,"3")
                .eq(XrForceDeregisterSpe::getForceRes,forceRemType); //由于前端已经按照要查的拟强制注销结果来设置值，因此这里直接作为参数查询。终止拟强制注销就只查1 正在进行拟强制注销公告的；恢复登记申请就只查4 已强制注销的
        if(StringUtils.isNotBlank(entName)){
            wrapper.like(XrForceDeregisterSpe::getEntName, entName);
        }
        if(StringUtils.isNotBlank(searchUscc)){
            wrapper.and(w -> w.eq(XrForceDeregisterSpe::getUniscId, searchUscc)
                    .or().eq(XrForceDeregisterSpe::getRegno, searchUscc));
        }

        forceDeregisterSpeIPage = xrForceDeregisterSpeService.page(page, wrapper);
        return forceDeregisterSpeIPage;
    }

    @Override
//    @DSTransactional
    public XrTaskListVo saveIvdAcceptList(ForceDeregisterSpeQueryDto queryDto, AICUser user) {
        String bizSeqNo = UUID.randomUUID().toString();
        XrForceDeregisterSpe forceSpe = queryDto.getXrForceDeregisterSpe();
        if (forceSpe == null) {
            throw new BusinessException("拟强制注销业务数据不能为空");
        }

        String entName = forceSpe.getEntName();
        //生成终止强制注销业务数据
        XrForceDeregisterRem xrForceRem = new XrForceDeregisterRem();
        BeanUtils.copyProperties(forceSpe, xrForceRem);
        String forceRemId = UUID.randomUUID().toString();
        xrForceRem.setForceRemId(forceRemId)
                .setBizSeqNo(bizSeqNo)
                .setStatus("0")
                .setForceRemType(queryDto.getForceRemType())
                .setApplyTime(LocalDateTime.now())
                .setAcceptOrg(user.getRegionID());
        // 保存业务信息
        this.save(xrForceRem);

        // 开启待办
        XrTaskList xrTaskList = new XrTaskList();
        String taskLikeId = UUID.randomUUID().toString();
        xrTaskList.setTaskLikeId(taskLikeId);
        xrTaskList.setBizSeqNo(bizSeqNo);
        xrTaskList.setBusType(BaseDataConstant.BUSINESS_TYPE_FORCE_DEREGISTER);
        xrTaskList.setAreaCode(user.getRegionID().substring(0, 6));
        xrTaskList.setBusName(entName);
        xrTaskList.setApplyOrgId(user.getOrgID());
        xrTaskList.setWorkFlowId(FlowUtil.FORCE_DEREGISTER_WORK_FLOW);
        // 将单个 pripId 转换为 List
        List<String> pripIdList = Collections.singletonList(forceSpe.getPripId());
        // 保存待办信息
        iXrTaskListService.startWorkFlow(xrTaskList,new String[]{user.getPrimaryKey()}, null,pripIdList, user);
        return new XrTaskListVo(taskLikeId, bizSeqNo, "");
    }

    @Override
//    @DSTransactional
    public void processControlRem(ForceDeregisterSpeSaveDto forceSaveDto, AICUser user) {
        XrTaskList xrTaskList = iXrTaskListService.getOne(new LambdaQueryWrapper<XrTaskList>().eq(XrTaskList::getBizSeqNo, forceSaveDto.getBizSeqNo()));
        LambdaQueryWrapper<XrForceDeregisterRem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(XrForceDeregisterRem::getBizSeqNo, forceSaveDto.getBizSeqNo());
        List<XrForceDeregisterRem> xrForceDeregisterRemList = list(queryWrapper);
        if (xrForceDeregisterRemList.isEmpty()) {
            throw new BusinessException("暂无数据");
        }
        LocalDateTime localDateTime = LocalDateTime.now();
//        // 转发业务
//        if (StringUtils.equals(FlowConstant.LINK_TYPE_REASSIGNMENT,forceQueryDto.getNextNodeID())) {
//            //查出转办单位的单位编号
//            TOrgunits nextOrg = aicorgService.getTOrgunitsById(forceQueryDto.getNextOrgID());
//            xrTaskList.setNextOrgId(nextOrg.getOrgNumber());
//            iXrTaskForwardService.saveByBizSeqNo(forceQueryDto, user,true);
//            iXrTaskListService.updateWorkFlow(forceQueryDto.getOpinion(), xrTaskList,
//                    forceQueryDto.getNextNodeID(), forceQueryDto.getNextPerformerIds(), AuthEnum.XR_HANDLE.getCode());
//            return;
//        }
//        Xrbasecode xrbasecode;

        for (XrForceDeregisterRem xrForceDeregisterRem : xrForceDeregisterRemList) {
            XrForceDeregisterRem forceDeregisterRem = forceSaveDto.getXrForceDeregisterRem();
            switch (forceSaveDto.getNextNodeID()) {
                case FlowConstant.LINK_TYPE_EXAMINE:
                    // 保存值
                    xrForceDeregisterRem = forceDeregisterRem;
                    TRBaseCode xrbasecode = trBaseCodeService.getOne(new LambdaQueryWrapper<TRBaseCode>()
                            .eq(TRBaseCode::getCodeid, "C13043").eq(TRBaseCode::getCode, xrForceDeregisterRem.getEndForceRra()));
                    //将拟强制注销业务表的数据分别传到 拟强制注销公告表和拟强制注销公告详细表
                    xrForceDeregisterRem.setForceRes("3")   //设置为“终止拟强制注销”
                            .setEndForceRraCn(xrbasecode.getName())
                            .setStatus(FlowConstant.LINK_STATUS_ONE); // 审批流程中把状态设置成 "审核中"
                    break;
                case FlowConstant.LINK_TYPE_APPROVE:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_TWO); // 审批流程中把状态设置成 "审批"
                    break;
                case FlowConstant.LINK_TYPE_END:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_THREE); // 审批流程中把状态设置成 "通过"
                    xrForceDeregisterRem = toEndXrForceDeregisterRem(xrForceDeregisterRem, user);
                    break;
                case FlowConstant.LINK_TYPE_NULLIFY:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_FIVE); // 审批流程中把状态设置成 "不通过"
                    break;
                case FlowConstant.LINK_TYPE_EXAMINE_FINISH:
                case FlowConstant.LINK_TYPE_APPROVE_FINISH:
                case FlowConstant.LINK_TYPE_LAW_FINISH:
                case FlowConstant.LINK_TYPE_UP_EXAMINE_FINISH:
                case FlowConstant.LINK_TYPE_UP_APPROVE_FINISH:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_FOUR); // 审批流程中把状态设置成 "作废"
                    break;
                case FlowConstant.LINK_TYPE_EXAMINE_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_ONE);
                    break;
                case FlowConstant.LINK_TYPE_HANDLE_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_ZERO);
                    break;
                case FlowConstant.LINK_TYPE_LAW_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_SEVEN);
                    break;
                default:
                    break;
            }
            saveOrUpdate(xrForceDeregisterRem);
        }
        iXrTaskListService.updateWorkFlow(forceSaveDto.getOpinion(), xrTaskList,
                forceSaveDto.getNextNodeID(), forceSaveDto.getNextPerformerIds(), null);

    }

    /**
     * 办结拟终止强制注销业务
     *
     * @param xrForceRem
     * @param user
     */
    private XrForceDeregisterRem toEndXrForceDeregisterRem(XrForceDeregisterRem xrForceRem, AICUser user) {
        //补全业务表的字段
        xrForceRem.setJudauth(xrForceRem.getRegOrg())
                .setJudauthCn(xrForceRem.getRegOrgCn())
                .setForceResDate(LocalDate.now());
        //补全公告详细信息
        XrForceDeregisterRes xrForceDeregisterRes = xrForceDeregisterResService.getById(xrForceRem.getForceResId());
        xrForceDeregisterRes.setForceResDate(LocalDate.now())
                .setForceRes(xrForceRem.getForceRes())
                .setEndForceRra(xrForceRem.getEndForceRra())
                .setEndForceRraCn(xrForceRem.getEndForceRraCn());
        //修改拟强制注销业务表信息
        //因为一开始就是将业务表和详细表两个id存相同的值，因此可以用详细表id直接查
        XrForceDeregisterSpe forceSpe = xrForceDeregisterSpeService.getById(xrForceDeregisterRes.getForceResId());
        forceSpe.setForceRes(xrForceRem.getForceRes())
                .setForceResDate(LocalDate.now());

        xrForceDeregisterResService.saveOrUpdate(xrForceDeregisterRes);
        xrForceDeregisterSpeService.saveOrUpdate(forceSpe);
        return xrForceRem;
    }

    @Override
    public String generateDecisionContent(AICUser user,XrForceDeregisterRem xrForceDeregisterRem) {
        String isAccept = xrForceDeregisterRem.getIsAccept();
        //根据是否予以恢复来决定文书类型
        String workNoType = isAccept.equals("1") ? WorkNoUtil.WORKNOTYPE_75 : WorkNoUtil.WORKNOTYPE_76;
        //查找对应的模板
        Tswrittemplate templateDB = tswrittemplateService.getOne(new LambdaQueryWrapper<Tswrittemplate>()
                .eq(Tswrittemplate::getWritsType, workNoType)
                .eq(Tswrittemplate::getIsTemplate, "1"));
//        String city = WorkNoUtil.getCityByAreaCode(xrForceDeregisterRem.getRegOrg().substring(0, 4));
        Gzaiccode one = gzaiccodeService.getOne(new LambdaQueryWrapper<Gzaiccode>()
                .eq(Gzaiccode::getScountrycode, xrForceDeregisterRem.getRegOrg()));
        String city = one.getScountryextcode();
        String content = templateDB.getContent();
        String noticeContent = "";
        if(isAccept.equals("1")){   //予以恢复
            noticeContent = content.replace("{{entName}}", xrForceDeregisterRem.getEntName())
                    .replace("你（单位）申请的已于", "\n        你（单位）申请的已于")
                    .replace("{{uniscId}}", xrForceDeregisterRem.getUniscId())
                    .replace("你（单位）如不服本决定", "\n        你（单位）如不服本决定")
                    .replace("{{government}}", StringUtils.isNotEmpty(city) ? city + "市场监督管理局或" + city + "人民政府" : "   ")
                    .replace("{{city}}", city);
        } else if(isAccept.equals("0")){   //不予恢复
            noticeContent = content.replace("{{entName}}", xrForceDeregisterRem.getEntName())
                    .replace("我局于", "\n        我局于")
                    .replace("你（单位）如不服本决定", "\n        你（单位）如不服本决定")
                    .replace("{{government}}", StringUtils.isNotEmpty(city) ? city + "市场监督管理局或" + city + "人民政府" : "   ")
                    .replace("{{city}}", city);
        }
        return noticeContent;
    }

    @Override
//    @DSTransactional
    public void processControlRecovery(ForceDeregisterSpeSaveDto forceSaveDto, AICUser user) {
        XrTaskList xrTaskList = iXrTaskListService.getOne(new LambdaQueryWrapper<XrTaskList>().eq(XrTaskList::getBizSeqNo, forceSaveDto.getBizSeqNo()));
        LambdaQueryWrapper<XrForceDeregisterRem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(XrForceDeregisterRem::getBizSeqNo, forceSaveDto.getBizSeqNo());
        List<XrForceDeregisterRem> xrForceDeregisterRemList = list(queryWrapper);
        if (xrForceDeregisterRemList.isEmpty()) {
            throw new BusinessException("暂无数据");
        }
        LocalDateTime localDateTime = LocalDateTime.now();
//        // 转发业务
//        if (StringUtils.equals(FlowConstant.LINK_TYPE_REASSIGNMENT,forceQueryDto.getNextNodeID())) {
//            //查出转办单位的单位编号
//            TOrgunits nextOrg = aicorgService.getTOrgunitsById(forceQueryDto.getNextOrgID());
//            xrTaskList.setNextOrgId(nextOrg.getOrgNumber());
//            iXrTaskForwardService.saveByBizSeqNo(forceQueryDto, user,true);
//            iXrTaskListService.updateWorkFlow(forceQueryDto.getOpinion(), xrTaskList,
//                    forceQueryDto.getNextNodeID(), forceQueryDto.getNextPerformerIds(), AuthEnum.XR_HANDLE.getCode());
//            return;
//        }

        for (XrForceDeregisterRem xrForceDeregisterRem : xrForceDeregisterRemList) {
            XrForceDeregisterRem forceDeregisterRem = forceSaveDto.getXrForceDeregisterRem();
            switch (forceSaveDto.getNextNodeID()) {
                case FlowConstant.LINK_TYPE_EXAMINE:
                    // 保存值
                    xrForceDeregisterRem = forceDeregisterRem;
                    //将拟强制注销业务表的数据分别传到 拟强制注销公告表和拟强制注销公告详细表
                    xrForceDeregisterRem.setForceRes("5")   //设置为“恢复登记”
                            .setForceResDate(LocalDate.now())
                            .setStatus(FlowConstant.LINK_STATUS_ONE); // 审批流程中把状态设置成 "审核中"
                    break;
                case FlowConstant.LINK_TYPE_APPROVE:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_TWO); // 审批流程中把状态设置成 "审批"
                    break;
                case FlowConstant.LINK_TYPE_END:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_THREE); // 审批流程中把状态设置成 "通过"
                    xrForceDeregisterRem = toEndXrForceDeregisterRecovery(xrForceDeregisterRem, user);
                    break;
                case FlowConstant.LINK_TYPE_NULLIFY:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_FIVE); // 审批流程中把状态设置成 "不通过"
                    break;
                case FlowConstant.LINK_TYPE_EXAMINE_FINISH:
                case FlowConstant.LINK_TYPE_APPROVE_FINISH:
                case FlowConstant.LINK_TYPE_LAW_FINISH:
                case FlowConstant.LINK_TYPE_UP_EXAMINE_FINISH:
                case FlowConstant.LINK_TYPE_UP_APPROVE_FINISH:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_FOUR); // 审批流程中把状态设置成 "作废"
                    break;
                case FlowConstant.LINK_TYPE_EXAMINE_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_ONE);
                    break;
                case FlowConstant.LINK_TYPE_HANDLE_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_ZERO);
                    break;
                case FlowConstant.LINK_TYPE_LAW_RETURN:
                    xrForceDeregisterRem.setStatus(FlowConstant.LINK_STATUS_SEVEN);
                    break;
                default:
                    break;
            }
            saveOrUpdate(xrForceDeregisterRem);
        }
        iXrTaskListService.updateWorkFlow(forceSaveDto.getOpinion(), xrTaskList,
                forceSaveDto.getNextNodeID(), forceSaveDto.getNextPerformerIds(), null);

    }

    private XrForceDeregisterRem toEndXrForceDeregisterRecovery(XrForceDeregisterRem xrForceRem, AICUser user) {
        //补全业务表的字段
        xrForceRem.setJudauth(xrForceRem.getRegOrg())
                .setJudauthCn(xrForceRem.getRegOrgCn())
                .setForceResDate(LocalDate.now());
        //补全公告详细信息
        XrForceDeregisterRes xrForceDeregisterRes = xrForceDeregisterResService.getById(xrForceRem.getForceResId());
        xrForceDeregisterRes.setForceResDate(LocalDate.now())
                .setForceRes(xrForceRem.getForceRes());
        //修改拟强制注销业务表信息
        //因为一开始就是将业务表和详细表两个id存相同的值，因此可以用详细表id直接查
        XrForceDeregisterSpe forceSpe = xrForceDeregisterSpeService.getById(xrForceDeregisterRes.getForceResId());
        forceSpe.setForceRes(xrForceRem.getForceRes())
                .setForceResDate(LocalDate.now());

        //根据决定书送达公告生成文书表数据
        TSWrit tsWritModel = new TSWrit();
        tsWritModel.setWritsid(UUID.randomUUID().toString());
        String workNoType = xrForceRem.getIsAccept().equals("1") ? WorkNoUtil.WORKNOTYPE_75 : WorkNoUtil.WORKNOTYPE_76;
        //获取补全后的内容
        tsWritModel.setWritsno(tsWorkNoService.generateDocNo(workNoType, xrForceRem.getRegOrg()))
                .setWritsname(WorkNoUtil.getWorkNoTypeName(workNoType))
                .setContent(xrForceRem.getDecisionContent())
                .setBizseq(xrForceRem.getBizSeqNo())
                .setWritstype(workNoType)
                .setAreaCode(xrForceRem.getRegOrg())
                .setCreatetime(LocalDateTime.now());

        xrForceDeregisterResService.saveOrUpdate(xrForceDeregisterRes);
        xrForceDeregisterSpeService.saveOrUpdate(forceSpe);
        tsWritService.save(tsWritModel);
        return xrForceRem;
    }

    @Override
    public ApprovalFormDto getApprovalFormByBizSeqNo(String bizSeqNo, String forceRemId) {
        ApprovalFormDto approvalFormDto = new ApprovalFormDto();
        XrForceDeregisterRem xrForceDeregisterRem = this.getById(forceRemId);
        LambdaQueryWrapper<XrTaskList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(XrTaskList::getBizSeqNo, bizSeqNo);
        XrTaskList one = iXrTaskListService.getOne(queryWrapper);
        List<XrOpinion> data = opinionService.list(new LambdaQueryWrapper<XrOpinion>()
                .eq(XrOpinion::getTaskListId,one.getTaskLikeId()).orderByDesc(XrOpinion::getUpdateTime));
        BeanUtils.copyProperties(xrForceDeregisterRem, approvalFormDto);
        approvalFormDto.setAreaName(xrForceDeregisterRem.getJudauthCn());
        approvalFormDto.setUniscId(xrForceDeregisterRem.getUniscId());
        approvalFormDto.setOpinion(data);
        //事实和理由
        approvalFormDto.setLostCreditExplain("");

        //决定书
        String workNoType = xrForceDeregisterRem.getIsAccept().equals("1") ? WorkNoUtil.WORKNOTYPE_75 : WorkNoUtil.WORKNOTYPE_76;
        TSWrit writ = tsWritService.getOne(new LambdaQueryWrapper<TSWrit>()
                .eq(TSWrit::getWritstype, workNoType)
                .eq(TSWrit::getBizseq, bizSeqNo));
        HashMap<String, Object> map = new HashMap<>();
        if (writ != null) {
            //公告内容
            map.put("writsNo", writ.getWritsno());
            map.put("content", writ.getContent());
            map.put("writsName", writ.getWritsname());
            map.put("areaName", xrForceDeregisterRem.getJudauthCn());
            map.put("writTime", writ.getCreatetime());
            approvalFormDto.setRepairMap(map);
        }
        return approvalFormDto;
    }

}
