package com.chinaweal.aiccs.aiccs.forcedCancellation.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.alibaba.fastjson.JSONObject;
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.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSAttachment;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSWrit;
import com.chinaweal.aiccs.aiccs.abnormal.entity.excel.EntExcel;
import com.chinaweal.aiccs.aiccs.abnormal.service.*;
import com.chinaweal.aiccs.aiccs.annual.service.NoannualreportService;
import com.chinaweal.aiccs.aiccs.asyncTask.RevokeAsyncTask;
import com.chinaweal.aiccs.aiccs.auditing.entity.TSOpinion;
import com.chinaweal.aiccs.aiccs.auditing.service.TSOpinionService;
import com.chinaweal.aiccs.aiccs.business.entity.TSTwfProcessNode;
import com.chinaweal.aiccs.aiccs.business.service.WorkFlowService;
import com.chinaweal.aiccs.aiccs.dict.service.CmsDictCodeService;
import com.chinaweal.aiccs.aiccs.entbase.entity.TREntPriseType;
import com.chinaweal.aiccs.aiccs.entbase.service.TREntPriseTypeService;
import com.chinaweal.aiccs.aiccs.forcedCancellation.entity.ForceLogoutNoticeDetail;
import com.chinaweal.aiccs.aiccs.forcedCancellation.entity.Vo.EnableListAndDXCheckVo;
import com.chinaweal.aiccs.aiccs.forcedCancellation.service.ForceLogoutNoticeDetailService;
import com.chinaweal.aiccs.aiccs.market.service.AreaSliceService;
import com.chinaweal.aiccs.aiccs.market.service.ITSUsualInspectService;
import com.chinaweal.aiccs.aiccs.punishment.util.BusTridMakeUtil;
import com.chinaweal.aiccs.aiccs.punishment.util.ExcelIePortUtils;
import com.chinaweal.aiccs.aiccs.punishment.util.ExcelListener;
import com.chinaweal.aiccs.aiccs.revoke.Vo.CaseVo;
import com.chinaweal.aiccs.aiccs.revoke.Vo.DisableListVo;
import com.chinaweal.aiccs.aiccs.revoke.Vo.EnableListAndCheckVo;
import com.chinaweal.aiccs.aiccs.revoke.entity.BizRevEnt;
import com.chinaweal.aiccs.aiccs.revoke.entity.TsCase;
import com.chinaweal.aiccs.aiccs.revoke.entity.Tsbizrevlist;
import com.chinaweal.aiccs.aiccs.revoke.entity.Tsrevtasklist;
import com.chinaweal.aiccs.aiccs.revoke.entity.dto.RevokeProcessDto;
import com.chinaweal.aiccs.aiccs.revoke.service.*;
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.entity.dto.WritTempEntInfoDto;
import com.chinaweal.aiccs.aiccs.writs.service.TswrittemplateService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aiccs.common.constant.BaseDataConstant;
import com.chinaweal.aiccs.common.constant.Constant;
import com.chinaweal.aiccs.common.util.ConstantsUtil;
import com.chinaweal.aiccs.common.util.DateUtils;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.common.util.WorkNoUtil;
import com.chinaweal.aiccs.common.util.filestorage.FileStorageService;
import com.chinaweal.aiccs.config.CommonConfig;
import com.chinaweal.aiccs.org.service.AicorgService;
import com.chinaweal.aiccs.redis.RedisService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.chinaweal.aiccs.org.service.TUsersService;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.aicorg.services.OrgUM;
import com.chinaweal.youfool.framework.springboot.exception.custom.BusinessException;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.page.PageRequestDto;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import com.chinaweal.youfool.framework.sso.util.SSOUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;

import static com.chinaweal.youfool.framework.springboot.rest.ResultCode.BUSINESS_LOGIC_ERROR;

/**
 * <p>
 * 拟强制注销公告明细表 前端控制器
 * </p>
 *
 * @author lwd
 * @since 2025-10-22
 */
@Slf4j
@RestController
@RequestMapping("/forceLogoutNoticeDetail")
public class ForceLogoutNoticeDetailController extends BaseController {

    @Autowired
    private ForceLogoutNoticeDetailService forceLogoutNoticeDetailService;
    @Autowired
    private EBaseinfoService eBaseinfoService;
    @Autowired
    private TsbizrevlistService tsbizrevlistService;
    @Autowired
    private ClueService clueService;
    @Autowired
    private TsrevtasklistService tsrevtasklistService;
    @Autowired
    private CaseService caseService;
    @Autowired
    private TSOpinionService tsOpinionService;
    @Autowired
    private IllegalactService illegalactService;
    @Autowired
    private TSOpinionService opinionService;
    @Autowired
    private TRBaseCodeService baseCodeService;
    @Autowired
    private AicorgService aicorgService;
    @Autowired
    private BusTridMakeUtil busTridMakeUtil;
    @Autowired
    private WorkFlowService workFlowService;
    @Autowired
    private TUsersService usersService;
    @Autowired
    private TREntPriseTypeService entPriseTypeService;
    @Autowired
    private TSAttachmentService attachmentService;
    @Resource
    private FileStorageService fileStorageService;
    @Resource
    private CmsDictCodeService cmsDictCodeService;
    @Resource
    private RevokeTempService revokeTempService;
    @Resource
    private IGzaiccodeService iGzaiccodeService;
    @Resource
    private TSAttachmentService tsAttachmentService;
    @Resource
    private BizRevEntService bizRevEntService;
    @Resource
    private IRevokeProcessService revokeProcessService;
    @Resource
    private RevokeAsyncTask revokeAsyncTask;
    @Resource
    private TSWritService tsWritService;
    @Resource
    private TSAbnListService tsAbnListService;
    @Resource
    private NoannualreportService noannualreportService;
    @Autowired
    private AreaSliceService areaSliceService;
    @Autowired
    private ITSUsualInspectService itsUsualInspectService;
    @Autowired
    private OrgUM orgUM;
    @Autowired
    private TswrittemplateService tswrittemplateService;
    @Autowired
    private RedisService redisService;

    private static final String CACHE_PREFIX_FORCE_LOGOUT = "force_logout_notice:";

    @ApiOperation("excel文件查询参数解析")
    @PostMapping("fileParamDXExplain")
    @Transactional
    public RestResult<?> fileParamExplain(@ApiParam("上传的excel文件") MultipartFile file, @ApiParam("参数模型名称") String model,
                                          @ApiParam("名单类型") String illegalType) {
        AssertUtils.isNotNull(file);
        AssertUtils.isNotBlank(model);
        AssertUtils.isNotBlank(illegalType);

        AICUser user = SSOUtil.getUser();
        String userOrg = StringUtils.substring(user.getRegionID(), 0, 6);//user.getRegionID();

        // 读取excel数据
        List<EntExcel> entDtos;
        try {
            ExcelListener excelListener = ExcelIePortUtils.getExcelListener(file, new EntExcel(), 1, 1);
            Object objList = excelListener.getDatas();
            entDtos = (List<EntExcel>) objList;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("文件数据读取出错");
        }
        ArrayList<EBaseinfo> enableList = new ArrayList<>();
        HashSet<EBaseinfo> enableSet = new HashSet<>();
        ArrayList<DisableListVo> disableList = new ArrayList<>();//不可导
        Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CA19");
        if (CollectionUtils.isEmpty(entDtos)) {
            return RestResult.error(ResultCode.PARAM_IS_BLANK, "不可上传空文件，请重新选择");
        }
        // 保存文件至服务器
        for (EntExcel entDto : entDtos) {
            LambdaQueryWrapper<EBaseinfo> wrapper = new LambdaQueryWrapper<>();
            EBaseinfo baseinfoModel = new EBaseinfo();
            baseinfoModel.setUniscid(entDto.getUniscid());
            baseinfoModel.setRegno(entDto.getRegno());
            baseinfoModel.setEntname(entDto.getEntname());

            wrapper.select(EBaseinfo::getRegorg, EBaseinfo::getPripid, EBaseinfo::getEntname, EBaseinfo::getRegno, EBaseinfo::getName, EBaseinfo::getRegstate, EBaseinfo::getRegstateCn, EBaseinfo::getEnttypeCn, EBaseinfo::getEnttype, EBaseinfo::getUniscid, EBaseinfo::getSuporg);
            if (StringUtils.isNotBlank(baseinfoModel.getUniscid())) {
                wrapper.eq(EBaseinfo::getUniscid, baseinfoModel.getUniscid());
            } else if (StringUtils.isNotBlank(baseinfoModel.getRegno())) {
                wrapper.eq(EBaseinfo::getRegno, baseinfoModel.getRegno());
            } else {
                wrapper.eq(EBaseinfo::getEntname, baseinfoModel.getEntname());
                // 用名称查主体的时候，可能会出现同名的情况
                List<EBaseinfo> list = eBaseinfoService.list(wrapper);
                if (list.size() > 1) {// 多家同名的时候，返回不可导原因“主体名称重名，请填写准确的统一码或注册号”
                    DisableListVo disableListVo = new DisableListVo();
                    disableListVo.setEntname(baseinfoModel.getEntname());
                    disableListVo.setReason("主体名称重名，请填写准确的统一码或注册号");
                    disableList.add(disableListVo);
                    continue;
                }
            }
            EBaseinfo eBaseinfo = eBaseinfoService.getOne(wrapper);
            if (eBaseinfo != null) {
                DisableListVo disableListVo = new DisableListVo();
                TRBaseCode baseCode = codeMap.get(eBaseinfo.getRegstate());
                if (baseCode != null) {
                    eBaseinfo.setRegstateCn(baseCode.getName());
                }

                //筛选过滤登记机关非本机关的市场主体到不可导入清单
                if (userOrg != null) {
                    String s = StringUtils.substring(eBaseinfo.getRegorg(), 0, 6);
                    if (!s.equals(userOrg)) {
                        disableListVo.setReason("登记机关非本机关的市场主体");
                        disableListVo.setEntname(eBaseinfo.getEntname());
                        disableListVo.setUniscid(eBaseinfo.getUniscid());
                        disableListVo.setRegno(eBaseinfo.getRegno());
                        disableListVo.setRegstateCn(eBaseinfo.getRegstateCn());
                        disableList.add(disableListVo);
                        continue;
                    }
                }


                if ("2".equals(eBaseinfo.getRegstate()) || "5".equals(eBaseinfo.getRegstate())) {//吊销未注销，撤销才可以注销
                    if (validInBiz(eBaseinfo.getPripid())) {// 检验是否在办理中了
                        disableListVo.setReason("该主体正在办理批量注销中");//企业状态为不可导原因
                    } else {
                        if (enableSet.add(eBaseinfo)) {
                            enableList.add(eBaseinfo);
                        }
                        continue;
                    }
                } else {
                    disableListVo.setReason("企业状态为" + eBaseinfo.getRegstateCn());//企业状态为不可导原因
                }

                disableListVo.setEntname(eBaseinfo.getEntname());
                disableListVo.setUniscid(eBaseinfo.getUniscid());
                disableListVo.setRegno(eBaseinfo.getRegno());
                disableListVo.setRegstateCn(eBaseinfo.getRegstateCn());
                disableList.add(disableListVo);

            } else {
                DisableListVo disableListVo = new DisableListVo();
                disableListVo.setEntname(baseinfoModel.getEntname());
                disableListVo.setUniscid(baseinfoModel.getUniscid());
                disableListVo.setRegno(baseinfoModel.getRegno());
                disableListVo.setReason("主体信息有误");
                disableList.add(disableListVo);
            }
        }
        String enableListId = UUID.randomUUID().toString();
        String disableListId = UUID.randomUUID().toString();
        HashMap<String, Object> groupMap = new HashMap<>();
        groupMap.put("enableListId", enableListId);
        groupMap.put("disableListId", disableListId);
        groupMap.put("disableList", disableList);
        redisService.set(CACHE_PREFIX_FORCE_LOGOUT + enableListId, JSON.toJSONString(enableList), 20 * 60);
        redisService.set(CACHE_PREFIX_FORCE_LOGOUT + disableListId, JSON.toJSONString(disableList), 20 * 60);
        groupMap.put("enableSize", enableList.size());
        groupMap.put("disableSize", disableList.size());

        return RestResult.ok(groupMap);
    }

    /**
     * 验证企业是否已在在办业务中
     *
     * @param pripid 主体id
     * @return true: 在办中；false：未办
     */
    public boolean validInBiz(String pripid) {
        LambdaQueryWrapper<ForceLogoutNoticeDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ForceLogoutNoticeDetail::getPripid, pripid)
                .eq(ForceLogoutNoticeDetail::getIsRemove, "0")
                .and(i -> i.notIn(ForceLogoutNoticeDetail::getForceRes, "3", "5")
                        .or()
                        .isNull(ForceLogoutNoticeDetail::getForceRes));
        List<ForceLogoutNoticeDetail> list = forceLogoutNoticeDetailService.list(wrapper);
        return CollectionUtils.isNotEmpty(list);
    }


    //获取批量注销企业
    @PostMapping("getZXEnableList")
    public RestResult<?> getZXEnableList(String enableListId) {
        String enableListJson = redisService.get(CACHE_PREFIX_FORCE_LOGOUT + enableListId);
        if (StringUtils.isBlank(enableListJson)) {
            return RestResult.error(ResultCode.DATA_NONE, "缓存数据已过期，请重新上传");
        }
        List<EBaseinfo> enableList = JSON.parseObject(enableListJson, new TypeReference<List<EBaseinfo>>() {});
        List<EnableListAndDXCheckVo> enableListAndCheckVos = new ArrayList<>();
        for (EBaseinfo eBaseinfo : enableList) {
            EnableListAndDXCheckVo checkAndRevResult = new EnableListAndDXCheckVo();
            checkAndRevResult.setUscc(eBaseinfo.getUniscid());
            checkAndRevResult.setEntname(eBaseinfo.getEntname());
            checkAndRevResult.setRegOrgCN(StringUtils.isBlank(eBaseinfo.getRegorg()) ? "" : baseCodeService.getRegorgName(eBaseinfo.getRegorg()));
            checkAndRevResult.setSupOrgCn(StringUtils.isBlank(eBaseinfo.getSuporg()) ? "" : baseCodeService.getSuporg(eBaseinfo.getSuporg()));
            checkAndRevResult.setCheckStatus(eBaseinfo.getRegstateCn());
            checkAndRevResult.setPripid(eBaseinfo.getPripid());
            enableListAndCheckVos.add(checkAndRevResult);

        }
        String enableListAndCheckId = UUID.randomUUID().toString();
        HashMap<String, Object> groupMap = new HashMap<>();
        groupMap.put("enableAndCheckList", enableListAndCheckVos);
        groupMap.put("enableAndCheckListId", enableListAndCheckId);
        redisService.set(CACHE_PREFIX_FORCE_LOGOUT + enableListAndCheckId, JSON.toJSONString(enableListAndCheckVos), 20 * 60);
        return RestResult.ok(groupMap);
    }

    /**
     * 名单导入创建待办
     *
     * @param paramStr
     * @param request
     * @return
     */
    @Transactional
    @PostMapping(value = "/savePlZxAccept.do")
    public RestResult<?> savePlZxAccept(@RequestBody String paramStr, HttpServletRequest request) {
        AICUser aicUser = getLoginUser(request);
        if(aicUser == null){
            return RestResult.error(ResultCode.USER_NOT_LOGGED_IN);
        }
        JSONObject jsonObject = JSONObject.parseObject(paramStr);
        String selectList = jsonObject.getString("selectList");
        String illegalType = jsonObject.getString("illegalType");
        AssertUtils.isNotEmpty(selectList,illegalType);
        List<String> pripids = JSONObject.parseArray(selectList,String.class);
        if(pripids.size() == 0) return RestResult.error(ResultCode.PARAM_IS_INVALID,"参数有误");
        //生成业务号
        String bizSeq = UUID.randomUUID().toString();
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime newDateTime = LocalDateTime.now();
        List<EBaseinfo> eBaseinfoList = new ArrayList<>();
        ArrayList<Tsbizrevlist> tsbizrevlists = new ArrayList<>();
        for (String pripid : pripids) {
            LambdaQueryWrapper<EBaseinfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.select(EBaseinfo::getRegorg, EBaseinfo::getPripid, EBaseinfo::getEntname, EBaseinfo::getRegno, EBaseinfo::getName, EBaseinfo::getRegstate, EBaseinfo::getRegstateCn, EBaseinfo::getEnttypeCn, EBaseinfo::getEnttype, EBaseinfo::getUniscid);
            wrapper.eq(EBaseinfo::getPripid, pripid);
            EBaseinfo eBaseinfo = eBaseinfoService.getOne(wrapper);
            if(eBaseinfo == null) continue;
            eBaseinfoList.add(eBaseinfo);
            newDateTime = newDateTime.plus(1, ChronoUnit.SECONDS);
            ForceLogoutNoticeDetail forceLogoutNoticeDetail = new ForceLogoutNoticeDetail();
            forceLogoutNoticeDetail.setBizseqId(bizSeq);
            forceLogoutNoticeDetail.setPripid(eBaseinfo.getPripid());
            forceLogoutNoticeDetail.setEntName(eBaseinfo.getEntname());    //企业名称
            forceLogoutNoticeDetail.setRegNo(eBaseinfo.getRegno());//注册号
            forceLogoutNoticeDetail.setUniscid(eBaseinfo.getUniscid());//统一码
            forceLogoutNoticeDetail.setLeRep(eBaseinfo.getName());//法定代表人
            forceLogoutNoticeDetail.setForceRra(illegalType);
            forceLogoutNoticeDetail.setRegOrg(eBaseinfo.getRegorg());
            forceLogoutNoticeDetail.setRegOrgCn(eBaseinfo.getRegorgCn());
            forceLogoutNoticeDetail.setDom(eBaseinfo.getDom());
            forceLogoutNoticeDetail.setStatus("1");
            forceLogoutNoticeDetail.setIsDecisionPublish("0");
            forceLogoutNoticeDetail.setNoOpenState("0");
            forceLogoutNoticeDetail.setHandleOrg(eBaseinfo.getRegorg());
            forceLogoutNoticeDetail.setHandleOrgCn(eBaseinfo.getRegorgCn());
            if(StringUtils.isNotEmpty(eBaseinfo.getEnttypeCn())) {
                forceLogoutNoticeDetail.setEnttypeCn(eBaseinfo.getEnttypeCn());//企业类型
            } else {
                TREntPriseType entPriseType = entPriseTypeService.getEntPriseTypeFromCache(eBaseinfo.getEnttype());
                if (entPriseType != null) {
                    forceLogoutNoticeDetail.setEnttypeCn(entPriseType.getDisplayvalue());
                }
            }
            forceLogoutNoticeDetail.setEnttype(eBaseinfo.getEnttype());
            forceLogoutNoticeDetail.setIsRemove("0");
            forceLogoutNoticeDetail.setCreateTime(newDateTime);
            forceLogoutNoticeDetail.setLauptime(now);
            forceLogoutNoticeDetail.setForceRraDate(LocalDate.now());
            forceLogoutNoticeDetailService.save(forceLogoutNoticeDetail);
        }
        Tsbizrevlist tsbizrevlistModel = new Tsbizrevlist();
        tsbizrevlistModel.setBizseq(bizSeq);//业务号
        tsbizrevlistModel.setSettime(LocalDate.now());//发现线索时间
        String orgCode = aicorgService.getRegionCodeByUser(aicUser);
        tsbizrevlistModel.setHandleOrg(orgCode);
        tsbizrevlistModel.setHandleOrgCn(iGzaiccodeService.getNameByCode(orgCode));
        tsbizrevlistModel.setLauptime(now);
        tsbizrevlists.add(tsbizrevlistModel);

        //案件名称   规则： 关于+第一家公司名称+等+XX家+企业类型+的批量吊销
        String casename = "关于" + eBaseinfoList.get(0).getEntname() + "等" +
                eBaseinfoList.size() + "户" + ("公司") + "的批量注销";
//         吊销待办
        Tsrevtasklist revtasklistModel = new Tsrevtasklist();
        revtasklistModel.setBizseqid(bizSeq);
        revtasklistModel.setBustype(BaseDataConstant.DEACTIVATIONL_TYPE_BATCH);

        revtasklistModel.setBusname(casename);
        revtasklistModel.setAreaCode(orgCode);
        //开启流程--录入线索
        revtasklistModel = forceLogoutNoticeDetailService.saveRevListZXAccept(aicUser, revtasklistModel, tsbizrevlists);
        if (StringUtils.isNotBlank(revtasklistModel.getTasklistid())) {
            Map<String, String> result = new HashMap<>();
            result.put("tasklistid", revtasklistModel.getTasklistid());
            result.put("bizseq", bizSeq);
            result.put("workflowid", revtasklistModel.getWorkflowid());
            return RestResult.ok(result);
        }
        return OK;
    }

    /**
     * 验证业务中企业状态，不符合（注销，撤销)的自动剔除
     * @param bizseq 业务号
     * @return
     */
    @PostMapping("getZxEntByBizseq")
    public RestResult<?> getZxEntByBizseq (String bizseq){
        LambdaQueryWrapper<ForceLogoutNoticeDetail> lqW = new LambdaQueryWrapper<>();
        lqW.eq(ForceLogoutNoticeDetail::getBizseqId,bizseq)
                .eq(ForceLogoutNoticeDetail::getIsRemove,"0");
        List<ForceLogoutNoticeDetail> list = forceLogoutNoticeDetailService.list(lqW);
        if(CollectionUtils.isEmpty(list)){
            return RestResult.error(ResultCode.DATA_NONE,"该业务无主体信息");
        }
        ArrayList<String> enableCodeList = new ArrayList<>();// "1" 可批吊的情况
        enableCodeList.add(ConstantsUtil.QUALIFICATION_OPEN);
        for (ForceLogoutNoticeDetail each : list) {
            LambdaQueryWrapper<EBaseinfo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(EBaseinfo::getPripid, each.getPripid());
            EBaseinfo eBaseinfo = eBaseinfoService.getOne(queryWrapper);
            if (eBaseinfo != null) {
                String regState = eBaseinfo.getRegstate(); // 企业状态（国标）
                String entStatus = eBaseinfo.getEntStatus();  // 企业状态（市标）
                if ("2".equals(regState) || "5".equals(regState)) {
                    forceLogoutNoticeDetailService.update(new ForceLogoutNoticeDetail().setNoOpenState("1"), new LambdaQueryWrapper<>(each).eq(ForceLogoutNoticeDetail::getBizseqId, bizseq).eq(ForceLogoutNoticeDetail::getPripid, each.getPripid()));
                } else {
                    forceLogoutNoticeDetailService.update(new ForceLogoutNoticeDetail().setNoOpenState("0"), new LambdaQueryWrapper<>(each).eq(ForceLogoutNoticeDetail::getBizseqId, bizseq).eq(ForceLogoutNoticeDetail::getPripid, each.getPripid()));
                }
            }
        }
        return RestResult.ok();
    }


    /**
     * 获取拟吊销主体列表 分页
     *
     * @param pageRequestDto 分页参数
     * @param request
     * @return
     */
    @PostMapping("/getForceLogoutNoticetPage")
    public RestResult<?> getForceLogoutNoticetPage(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request) {
        AssertUtils.isNotNull(pageRequestDto,pageRequestDto.getCustomParamMap());// 要改 bizseq必传
        pageRequestDto.checkDefault(1, 10, "insertTime");
        Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
        String bizseq = StringUtils.tranObject(customParamMap.get("bizseq"));
        if(StringUtils.isBlank(bizseq))return RestResult.error(ResultCode.PARAM_IS_BLANK);
        // 搜索统一码和注册号
        String searchCode = StringUtils.tranObject(customParamMap.get("searchCode"));
        //判断入参为统一码还是注册号
        if (StringUtils.isNotBlank(searchCode)) {
            if (StringUtils.isUscc(searchCode)) {
                customParamMap.put("uniscid",searchCode);
            } else {
                customParamMap.put("regno",searchCode);
            }
        }
        IPage<Tsbizrevlist> revEntPage = tsbizrevlistService.getForceLogoutNoticetPage(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), customParamMap);


        if(CollectionUtils.isNotEmpty(revEntPage.getRecords())){ // 封装企业状态
            Map<String, TRBaseCode> codeMap = baseCodeService.getBaseCodeMapFormCache("CA19");
            for (Tsbizrevlist record : revEntPage.getRecords()) {
                EBaseinfo eBaseinfo = eBaseinfoService.getOne(new LambdaQueryWrapper<EBaseinfo>().eq(EBaseinfo::getPripid, record.getPripid()));
                record.setRegstate(eBaseinfo.getRegstate());
                TRBaseCode code = codeMap.get(eBaseinfo.getRegstate());
                if(code != null) {
                    record.setRegstateCn(code.getName());
                }
                if (record.getEnttypeCn() == null) {
                    TREntPriseType type = entPriseTypeService.getEntPriseTypeFromCache(record.getEnttype());
                    if (type != null) {
                        record.setEnttypeCn(type.getDisplayvalue());
                    }
                }

            }
        }
        return RestResult.ok(revEntPage);

    }

    /**
     * 通过企业id添加主体至拟注销企业列表
     *
     * @param pripid   企业id
     * @param bizseq    业务号id
     * @param bizStatus 业务状态
     * @param request
     * @return
     */
    @Transactional
    @PostMapping("insertZxRevListByPripid")
    public RestResult<?> insertZxRevListByPripid(String pripid, String bizseq, String bizStatus,String bizEntType, HttpServletRequest request) {
        AssertUtils.isNotBlank(bizseq, pripid, bizStatus);
        AICUser user = getLoginUser(request);
//        String[] pripidArray = pripids.split(Constant.SEMICOLON); // 批量改个案
        EBaseinfo eBaseinfo = eBaseinfoService.getOneByPripid(pripid);
        LocalDateTime newDateTime = LocalDateTime.now();
        // 验证企业状态
        if(!"2".equals(eBaseinfo.getRegstate()) && !"5".equals(eBaseinfo.getRegstate())){
            return RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR,"该主体状态非吊销，未注销或撤销，无法新增！");
        }
        // 验证是否在办
        List<Tsbizrevlist> bizRevEntDB = tsbizrevlistService.selectInZxBiz(pripid);
        if (CollectionUtils.isNotEmpty(bizRevEntDB)) {
            return RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR,"主体已在办理注销业务中，无法新增！");
        }

        List<ForceLogoutNoticeDetail> forceLogoutNoticeDetailList = forceLogoutNoticeDetailService.getByBizSeqId(bizseq);
        ForceLogoutNoticeDetail forceLogoutNoticeDetail = new ForceLogoutNoticeDetail();
        forceLogoutNoticeDetail.setBizseqId(bizseq);
        forceLogoutNoticeDetail.setPripid(eBaseinfo.getPripid());
        forceLogoutNoticeDetail.setEntName(eBaseinfo.getEntname());    //企业名称
        forceLogoutNoticeDetail.setRegNo(eBaseinfo.getRegno());//注册号
        forceLogoutNoticeDetail.setUniscid(eBaseinfo.getUniscid());//统一码
        forceLogoutNoticeDetail.setLeRep(eBaseinfo.getName());//法定代表人
        if (forceLogoutNoticeDetailList.size() > 0) {
            forceLogoutNoticeDetail.setForceRra(forceLogoutNoticeDetailList.get(0).getForceRra());
        }
        forceLogoutNoticeDetail.setRegOrg(eBaseinfo.getRegorg());
        forceLogoutNoticeDetail.setRegOrgCn(eBaseinfo.getRegorgCn());
        forceLogoutNoticeDetail.setDom(eBaseinfo.getDom());
        forceLogoutNoticeDetail.setStatus("1");
        forceLogoutNoticeDetail.setIsDecisionPublish("0");
        forceLogoutNoticeDetail.setNoOpenState("0");
        forceLogoutNoticeDetail.setHandleOrg(eBaseinfo.getRegorg());
        forceLogoutNoticeDetail.setHandleOrgCn(eBaseinfo.getRegorgCn());
        if(StringUtils.isNotEmpty(eBaseinfo.getEnttypeCn())) {
            forceLogoutNoticeDetail.setEnttypeCn(eBaseinfo.getEnttypeCn());//企业类型
        } else {
            TREntPriseType entPriseType = entPriseTypeService.getEntPriseTypeFromCache(eBaseinfo.getEnttype());
            if (entPriseType != null) {
                forceLogoutNoticeDetail.setEnttypeCn(entPriseType.getDisplayvalue());
            }
        }
        forceLogoutNoticeDetail.setEnttype(eBaseinfo.getEnttype());
        forceLogoutNoticeDetail.setIsRemove("0");
        forceLogoutNoticeDetail.setCreateTime(newDateTime);
        forceLogoutNoticeDetail.setLauptime(newDateTime);
        forceLogoutNoticeDetail.setForceRraDate(LocalDate.now());
        forceLogoutNoticeDetail.setStatus("1");
        boolean insert = forceLogoutNoticeDetailService.save(forceLogoutNoticeDetail);
        if(insert){
            List<ForceLogoutNoticeDetail> forceLogoutNoticeDetails = forceLogoutNoticeDetailService.getByBizSeqId(bizseq);
            String caseName = "";
            if(caseName != null) {
                List<Tsrevtasklist> revtasklist = tsrevtasklistService.selectByBizSeqID(bizseq);
                caseName = replaceCompanyCount(revtasklist.get(0).getBusname(),forceLogoutNoticeDetails.size());
                Tsrevtasklist tsrevtasklist = revtasklist.get(0);
                tsrevtasklist.setBusname(caseName);
                boolean update = tsrevtasklistService.updateById(tsrevtasklist);
                if(update) {
                    return RestResult.ok(caseName);
                }else {
                    throw new BusinessException("更新待办名称失败");
                }

            }else {
                throw new BusinessException("更新案件名称失败");
            }
        }
        throw new BusinessException("新增失败");
    }

    /**
     * 替换公司数量数字（更精确的方法）
     * @param text 原始文本
     * @param newCount 新的公司数量
     * @return 替换后的文本
     */
    public static String replaceCompanyCount(String text, int newCount) {
        if (text == null || text.isEmpty()) {
            return text;
        }

        // 匹配"等X家公司"模式中的数字
        String regex = "(?<=等)\\d+(?=家公司)";
        return text.replaceAll(regex, String.valueOf(newCount));
    }

    /**
     * 剔除附件预上传
     *
     * @param file      文件id
     * @param bizseq    业务号
     * @param request   请求信息
     * @return          上传文件的信息
     * @author          Lee
     * @since           2021年5月10日 14:20:30
     */
    @PostMapping("remUploadAdvanceZx")
    public RestResult<?> remUploadAdvanceZx(MultipartFile file, String bizseq, HttpServletRequest request) {
        // 获得上传目录
        AICUser curUser = getLoginUser(request);
        LambdaQueryWrapper<ForceLogoutNoticeDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ForceLogoutNoticeDetail::getBizseqId,bizseq).eq(ForceLogoutNoticeDetail::getIsRemove,"1").orderByDesc(ForceLogoutNoticeDetail::getRemoveTime);
        List<ForceLogoutNoticeDetail> list = forceLogoutNoticeDetailService.list(wrapper);

        String remNoStr = "remNO1";
        int remNo = 1;
        if(list.size() > 0 && list.get(0).getRemNo() != null){
            remNo = list.get(0).getRemNo()+ 1;
            remNoStr = "remNO" + remNo;
        }
        String oldFileName = file.getOriginalFilename();
        String filePath = "BatchRevocation" + File.separator + bizseq + File.separator + remNoStr + File.separator + System.currentTimeMillis() + oldFileName;
        String realPath = CommonConfig.getUploadPath() + File.separator + filePath;
        String ext = StringUtils.isNotBlank(oldFileName) && oldFileName.lastIndexOf(Constant.DOT) > -1 ? oldFileName.substring(oldFileName.lastIndexOf(Constant.DOT)) : StringUtils.EMPTY;
        String contentType = file.getContentType();//文件的类型（MIME）、内容类型
        try(InputStream is = file.getInputStream();
            ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

            if (StringUtils.containsIgnoreCase(contentType, "image")
                    && file.getSize() >= 5 * 1024 * 1024) { // 小于5M不压缩
                //压缩图片
                TimeInterval timer = DateUtil.timer();
                Thumbnails.of(is).scale(1f).outputQuality(0.5f).toOutputStream(bos);
                log.debug("图片压缩耗时： {} ms", timer.interval());
                fileStorageService.writeFromStream(realPath, new ByteArrayInputStream(bos.toByteArray()));
            } else {
                fileStorageService.writeFromStream(realPath, is);
            }
        } catch (Exception e) {
            log.error("上传出错", e);
            return RestResult.error(ResultCode.MYSTERIOUS_ERROR,"上传失败");
        }

        AICUser user = getLoginUser(request);
        TSAttachment tsAttachmentModel1 = new TSAttachment();
        tsAttachmentModel1.setBizseq(bizseq);
        tsAttachmentModel1.setRemNo(remNo);
        tsAttachmentModel1.setPripid(StringUtils.EMPTY);
        tsAttachmentModel1.setFileext(ext);
        tsAttachmentModel1.setFilename(oldFileName);
        tsAttachmentModel1.setTemppath(realPath);
        tsAttachmentModel1.setUploaddate(LocalDate.now());
        tsAttachmentModel1.setUserid(user.getPrimaryKey());
        tsAttachmentModel1.setUsername(user.getName());
//        tsAttachmentModel1.setAttachtype("");
        attachmentService.save(tsAttachmentModel1);
        return RestResult.ok(tsAttachmentModel1);
    }

    /**
     * 通过企业id从拟注销企业列表移除主体
     *
     * @param pripids      企业id
     * @param bizseq       业务号id
     * @param removeReason 剔除原因
     * @param request
     * @return
     */
    @Transactional
    @PostMapping("removeRevListByPripidZx")
    public RestResult<?> removeRevListByPripidZx(String pripids, String bizseq, String removeReason, String remNo, HttpServletRequest request) {
        AICUser user = getLoginUser(request);
        if (user == null) return RestResult.error(ResultCode.USER_NOT_LOGGED_IN);
        AssertUtils.isNotBlank(bizseq, pripids);
        String[] pripidArray = pripids.split(Constant.SEMICOLON);
        ForceLogoutNoticeDetail forceLogoutNoticeDetail = new ForceLogoutNoticeDetail();
        forceLogoutNoticeDetail.setRemNo(Integer.valueOf(remNo));//剔除批次
        forceLogoutNoticeDetail.setRemHandler(user.getName());//剔除人
        forceLogoutNoticeDetail.setRemoveTime(LocalDateTime.now());//剔除时间
        forceLogoutNoticeDetail.setRemoveReason(removeReason);//剔除原因
        forceLogoutNoticeDetail.setIsRemove("1");//设为剔除
        boolean remove = forceLogoutNoticeDetailService.update(forceLogoutNoticeDetail, new LambdaQueryWrapper<ForceLogoutNoticeDetail>().eq(ForceLogoutNoticeDetail::getBizseqId, bizseq).in(ForceLogoutNoticeDetail::getPripid, pripidArray));
        if(!remove) {
            log.info("剔除更新{}失败",pripids);
            throw new BusinessException("剔除失败");
        }

        for (String pripid : pripidArray) {
            List<TSAttachment> attachments = attachmentService.getByPripidAndBizseq(pripid, bizseq);
            if(CollectionUtils.isNotEmpty(attachments)) {
                for (TSAttachment attachment : attachments) {
                    boolean removeById = attachmentService.removeById(attachment.getAttachmentid());
                    if (!removeById) {
                        log.info("批吊剔除主体时，删除文件信息失败,主体id{}业务号{}", pripid, bizseq);
                        throw new BusinessException("剔除失败");
                    } else {
                        log.info("批吊剔除主体时,成功删除文件信息：{}",attachment);
                    }
                }
            }
        }

        List<ForceLogoutNoticeDetail> forceLogoutNoticeDetails = forceLogoutNoticeDetailService.getByBizSeqId(bizseq);
        String caseName = "";
        if(caseName != null) {
            List<Tsrevtasklist> revtasklist = tsrevtasklistService.selectByBizSeqID(bizseq);
            caseName = replaceCompanyCount(revtasklist.get(0).getBusname(),forceLogoutNoticeDetails.size());
            Tsrevtasklist tsrevtasklist = revtasklist.get(0);
            tsrevtasklist.setBusname(caseName);
            boolean update = tsrevtasklistService.updateById(tsrevtasklist);
            if(update) {
                return RestResult.ok(caseName);
            }else {
                log.info("批吊剔除主体时,业务号{}更新待办名称失败：{}",bizseq,caseName);
                throw new BusinessException("更新待办名称失败");
            }
        }else {
            log.info("批吊剔除主体时,业务号{}更新案件名称失败：{}",bizseq,caseName);
            throw new BusinessException("更新案件名称失败");
        }
    }

    /**
     * 拟注销主体列表剔除记录 分页
     *
     * @param pageRequestDto 分页参数
     * @param request
     * @return
     */
    @PostMapping("getRemoveRecordZx")
    public RestResult<?> getRemoveRecordZx(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request) {
        AssertUtils.isNotNull(pageRequestDto);
        pageRequestDto.checkDefault(1, 10, "removeTime");
        return RestResult.ok(forceLogoutNoticeDetailService.defaultPaging(pageRequestDto, w -> {
            LambdaQueryWrapper<ForceLogoutNoticeDetail> wrapper = w.lambda();
            Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
            if (customParamMap == null) return;

            String bizseq = StringUtils.tranObject(customParamMap.get("bizseq"));
            //已移除拟吊銷列表的主体
            if (StringUtils.isNotBlank(bizseq)) {
                wrapper.eq(ForceLogoutNoticeDetail::getBizseqId, bizseq)
                        .eq(ForceLogoutNoticeDetail::getIsRemove, '1');
            }
            // 搜索统一码和注册号
            String searchCode = StringUtils.tranObject(customParamMap.get("searchCode"));
            //判断入参为统一码还是注册号
            if (StringUtils.isNotBlank(searchCode)) {
                if (StringUtils.isUscc(searchCode)) {
                    wrapper.eq(ForceLogoutNoticeDetail::getUniscid, searchCode);
                } else {
                    wrapper.eq(ForceLogoutNoticeDetail::getRegNo, searchCode);
                }
            }
            //主体名称
            String searchEntName = StringUtils.tranObject(customParamMap.get("searchEntName"));
            wrapper.like(StringUtils.isNotBlank(searchEntName),ForceLogoutNoticeDetail::getEntName,searchEntName);
            //剔除原因
            String searchReason = StringUtils.tranObject(customParamMap.get("searchReason"));
            wrapper.like(StringUtils.isNotBlank(searchReason),ForceLogoutNoticeDetail::getRemoveReason,searchReason);
            //处理人
            String searchHandler = StringUtils.tranObject(customParamMap.get("searchHandler"));
            wrapper.like(StringUtils.isNotBlank(searchHandler),ForceLogoutNoticeDetail::getRemHandler,searchHandler);
            //手动/自动剔除
            String searchRemType = StringUtils.tranObject(customParamMap.get("searchRemType"));
            if(StringUtils.isNotBlank(searchRemType)){
                if(searchRemType.equals("0")){//表自动
                    wrapper.eq(ForceLogoutNoticeDetail::getRemNo,0);//对应0批次
                }else if (searchRemType.equals("1")){//表手动
                    wrapper.ne(ForceLogoutNoticeDetail::getRemNo,0);//对应除0外其他批次
                }
            }
            //剔除时间
            String remStartDate = StringUtils.tranObject(customParamMap.get("remStartDate"));
            String remEndDate = StringUtils.tranObject(customParamMap.get("remEndDate"));
            if(StringUtils.isNotBlank(remStartDate) && StringUtils.isNotBlank(remStartDate)){
                remStartDate =  DateUtils.dateTimeFormat(remStartDate);
                remEndDate =  DateUtils.dateTimeFormat(remEndDate);
                wrapper.between(ForceLogoutNoticeDetail::getRemoveTime,remStartDate,remEndDate);
            }
            wrapper.orderByDesc(ForceLogoutNoticeDetail::getRemoveTime);
        }, null));
    }

    /**
     * 剔除附件回显
     */
    @PostMapping("/getRemFileListZx")
    public List<TSAttachment> getRemFileListZx(TSAttachment tsWritModel) {
        LambdaQueryWrapper<TSAttachment> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TSAttachment::getBizseq,tsWritModel.getBizseq())
                .eq(TSAttachment::getRemNo,tsWritModel.getRemNo());
        return attachmentService.list(wrapper);
    }

    /**
     * 通过业务id获取相应案件信息
     * @param bizseq
     * @return
     */
    @GetMapping("getForceLogoutNoticeInfoByBizseq")
    public RestResult<?> getForceLogoutNoticeInfoByBizseq(String bizseq){
        AssertUtils.isNotBlank(bizseq);
        List<Tsrevtasklist> revtasklist = tsrevtasklistService.selectByBizSeqID(bizseq);
        List<ForceLogoutNoticeDetail> forceLogoutNoticeDetails = forceLogoutNoticeDetailService.getByBizSeqId(bizseq);

        EnableListAndDXCheckVo enableListAndDXCheckVo = new EnableListAndDXCheckVo();

        enableListAndDXCheckVo.setEntname(revtasklist.get(0).getBusname());
        if ("1".equals(forceLogoutNoticeDetails.get(0).getForceRra())) {
            enableListAndDXCheckVo.setForceRra("被吊销营业执照，满三年未向公司登记机关申请注销公司登记");
        }else if ("2".equals(forceLogoutNoticeDetails.get(0).getForceRra())) {
            enableListAndDXCheckVo.setForceRra("被责令关闭，满三年未向公司登记机关申请注销公司登记");
        }else if ("3".equals(forceLogoutNoticeDetails.get(0).getForceRra())) {
            enableListAndDXCheckVo.setForceRra("被撤销，满三年未向公司登记机关申请注销公司登记");
        }



        return RestResult.ok(enableListAndDXCheckVo);
    }


    /**
     * 批量注销业务获取文书模板内容
     *
     * @param writTempEntInfoDto 文书模板内容参数对象
     * @return
     */
    @ApiOperation("批吊业务获取文书模板内容")
    @PostMapping("getForceLogoutContentsWithBizseq")
    public RestResult<?> getForceLogoutContentsWithBizseq(@RequestBody WritTempEntInfoDto writTempEntInfoDto, HttpServletRequest request) {
        AICUser user = getLoginUser(request);
        AssertUtils.isNotBlank(writTempEntInfoDto.getBizseq(), writTempEntInfoDto.getWritsType(), writTempEntInfoDto.getNeedTemplate());

        String writsType = writTempEntInfoDto.getWritsType();
        String bizseq = writTempEntInfoDto.getBizseq();
//        String type = writTempEntInfoDto.getType();
        // 先查找业务中有没有编辑保存过的文书内容，有则返回
        LambdaQueryWrapper<Tswrittemplate> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Tswrittemplate::getBizseq, bizseq)
                .eq(Tswrittemplate::getWritsType, writsType)
                .eq(Tswrittemplate::getIsTemplate, "0");// 是否为模板 “0”否“1”是
        Tswrittemplate writtemplateBiz = tswrittemplateService.getOne(wrapper);
        if (writtemplateBiz == null && "1".equals(writTempEntInfoDto.getNeedTemplate())) {// 没有则查找初始模板
            // 不同文书类型对模板内容有 不同处理
            Tswrittemplate templateDB = getTemplateWithWritstype(writsType);
            if (templateDB != null) {
                return RestResult.ok(templateDB);
            }
        }
        return RestResult.ok(writtemplateBiz);
    }

    /**
     * 根据文书类型获取文书模板内容
     *
     * @param writsType 文书模板内容参数对象
     * @return
     */
    @ApiOperation("根据文书类型获取文书模板内容")
    @PostMapping("getContentsWithWritstype")
    public Tswrittemplate getTemplateWithWritstype(String writsType) {
        AssertUtils.isNotBlank(writsType);
        LambdaQueryWrapper<Tswrittemplate> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Tswrittemplate::getWritsType, writsType)
                .eq(Tswrittemplate::getIsTemplate, "1");// 是否为模板
        Tswrittemplate template = tswrittemplateService.getOne(wrapper);
        return template;
    }

    @PostMapping("/bizRevNextZ")
    public RestResult<?> bizRevNextZ(@RequestBody @Validated RevokeProcessDto revokeProcessDto, BindingResult bindingResult, HttpServletRequest request){
        AssertUtils.isBndingValidit(bindingResult);
        AICUser user = getLoginUser(request);
        if (user == null) throw new BusinessException("登录超时，请重新登录");

        Tsrevtasklist taskListModel = tsrevtasklistService.getById(revokeProcessDto.getTasklistid());
        Tsbizrevlist tsbizrevlist = tsbizrevlistService.getOneBybizseq(revokeProcessDto.getBizseq());
        AssertUtils.isTrue(taskListModel != null && tsbizrevlist != null, ResultCode.DATA_NONE);
        TSTwfProcessNode twfProcessNode = workFlowService.findCurrentNode(taskListModel.getWorkflowid());
        String currentnode = twfProcessNode.getCurrentnode();
        try {
            revokeProcessService.processControlZx(revokeProcessDto, taskListModel,tsbizrevlist, user);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("批吊业务号{}流程扭转出错"+e,revokeProcessDto.getBizseq());
            return RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR,"流程扭转出错");
        }
        try {
            if("decisionEnter".equals(revokeProcessDto.getNextNodeID())){
                if("approvalHearing".equals(currentnode)) {
                    LocalDateTime now = LocalDateTime.now();
                    LocalDate nowDate = LocalDate.now();
                    // 异步生成听证告知书
                    revokeAsyncTask.revHearingNoticeTask(revokeProcessDto.getBizseq(), tsbizrevlist.getHandleOrg(), now, nowDate);
                }
            }else if("sendEnter".equals(revokeProcessDto.getNextNodeID())){
                if("approvalDecision".equals(currentnode)){
                    // 异步生成决定书
                    revokeAsyncTask.revPunishDecTask(revokeProcessDto.getBizseq(), tsbizrevlist.getHandleOrg());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("批吊业务号{}异步附件任务执行异常"+e,revokeProcessDto.getBizseq());
        }

        return RestResult.ok();
    }
}
