package com.zcloud.basic.info.command;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.exception.BizException;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.system.client.user.facade.UserFacade;
import com.zcloud.basic.info.constant.RedisConstant;
import com.zcloud.basic.info.command.convertor.UserJobHandoverCoConvertor;
import com.zcloud.basic.info.domain.enums.*;
import com.zcloud.basic.info.domain.gateway.*;
import com.zcloud.basic.info.domain.model.*;
import com.zcloud.basic.info.dto.*;
import com.zcloud.basic.info.dto.clientobject.UserJobHandoverCO;
import com.zcloud.basic.info.persistence.dataobject.*;
import com.zcloud.basic.info.persistence.repository.*;
import com.zcloud.gbscommon.utils.Tools;
import com.zcloud.gbscommon.utils.ZcloudRedisUtil;
import com.zcloud.gbscommon.zcloudhidden.face.ZcloudHiddenFacade;
import com.zcloud.gbscommon.zcloudhidden.request.HiddenStatisticsListQry;
import com.zcloud.gbscommon.zcloudhidden.request.HiddenUpdateCmd;
import com.zcloud.gbscommon.zcloudhidden.response.HiddenListByUserCO;
import com.zcloud.gbscommon.zcloudhidden.response.HiddenListCO;
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserJobFacade;
import com.zcloud.gbscommon.zclouduser.request.ZcloudUserJobQry;
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserJobCo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * web-app
 *
 * @Author zhangyue
 * @Date 2025-11-04 14:07:38
 */
@Component
@AllArgsConstructor
@Slf4j
public class UserUpdateExe {
    private final UserGateway userGateway;

    private final UserRepository userRepository;

    private final UserEmploymentLogGateway userEmploymentLogGateway;

    private final CorpInfoRepository corpInfoRepository;
    private final UserCorpRepository userCorpRepository;
    private final UserCorpGateway userCorpGateway;
    private final UserChangeRecordGateway userChangeRecordGateway;
    private final DepartmentRepository departmentRepository;
    private final UserCorpRecordRepository userCorpRecordRepository;
    private final UserCorpRecordGateway userCorpRecordGateway;
    private final UserJobHandoverRepository userJobHandoverRepository;
    private final UserJobHandoverCoConvertor userJobHandoverCoConvertor;
    private final UserChangeRecordRepository userChangeRecordRepository;
    @DubboReference
    private UserFacade userFacade;
    private ZcloudRedisUtil zcloudRedisUtil;
    @DubboReference
    private ZcloudHiddenFacade zcloudHiddenFacade;




    @Transactional(rollbackFor = Exception.class)
    public void execute(UserUpdateCmd userUpdateCmd) {
        UserE userE = new UserE();
        BeanUtils.copyProperties(userUpdateCmd, userE);
        // 对比用户老数据与要修改数据，查看是否涉及调岗及入职
        UserDO userDO = userRepository.getInfoById(userUpdateCmd.getId());
        UserE oldUserE = new UserE();
        BeanUtils.copyProperties(userDO, oldUserE);
        boolean transferPositionFlag = userE.verifyTransferPosition(oldUserE, userE);
        String corpName = null;

        boolean res = userGateway.update(userE);
        // 保存履职记录
        if (!res) {
            throw new BizException("修改失败");
        }
        UserCorpDO infoByUserId = userCorpRepository.getInfoByUserId(userDO.getId(), AuthContext.getTenantId());
        if (UserFlowFlagEnum.FLOW.getCode().equals(userUpdateCmd.getFlowFlag())) {
            //流动人员,修改部门企业等信息
            if (infoByUserId != null) {
                UserCorpE userCorpE = new UserCorpE();
                BeanUtils.copyProperties(infoByUserId, userCorpE);
                userCorpE.initUpdate(userE);
                userCorpGateway.update(userCorpE);
            } else {
                UserCorpE userCorpE = new UserCorpE();
                BeanUtils.copyProperties(oldUserE, userCorpE);
                BeanUtils.copyProperties(userE, userCorpE);
//                userCorpE.initAdd( userE,oldUserE);
                userCorpE.setId(null);
                userCorpGateway.add(userCorpE);
                BeanUtils.copyProperties(userCorpE, infoByUserId);
            }
        }
      /*  if (transferPositionFlag) {
            //保存用户变更记录
            CorpInfoDO corpInfoDO = corpInfoRepository.getById(userE.getCorpinfoId());
            if (corpInfoDO != null && !ObjectUtils.isEmpty(corpInfoDO.getCorpName())) {
                corpName = corpInfoDO.getCorpName();
            }
            DepartmentDO departmentDO = departmentRepository.getById(userE.getDepartmentId());
            if (UserFlowFlagEnum.FLOW.getCode().equals(userDO.getFlowFlag())) {
                //获取
                UserCorpE userCorpE = new UserCorpE();
                BeanUtils.copyProperties(infoByUserId, userCorpE);
                oldUserE.setDepartmentId(infoByUserId.getDepartmentId());
                oldUserE.setOldFlowInfo(userCorpE);
            }
            // 增加用户变更记录
            UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
            userChangeRecordE.initUserUpdate(userE, oldUserE, corpName, departmentDO.getName());
            userChangeRecordGateway.add(userChangeRecordE);
            //TODO 处理未完成的工作


        }*/

    }

    @Transactional(rollbackFor = Exception.class)
    public boolean executePasswordRecover(AppUserRegisterCmd cmd) {

        // 根据手机号查询用户信息
        UserDO userDO = userRepository.getByPhone(cmd.getPhone());

        UserE userE = new UserE();
        userE.checkPassword(cmd.getNewPassword(), cmd.getConfirmPassword());

        // 获取redis验证码
        Object phoneCodeObj = zcloudRedisUtil.get(RedisConstant.PHONE_CODE_KEY + cmd.getPhone());
        if(phoneCodeObj == null || !phoneCodeObj.toString().equals(cmd.getPhoneCode())){
            throw new BizException("验证码已过期或错误");
        }
        zcloudRedisUtil.del(RedisConstant.PHONE_CODE_KEY + cmd.getPhone());

        BeanUtils.copyProperties(cmd, userE);
        userE.setId(userDO.getId());
        userE.encryptionPassword();
        userGateway.updatePassword(userE);

        return true;
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean updatePasswordFromApp(AppUserUpdatePassWordCmd cmd) {

        UserE userE = new UserE();
        userE.checkPassword(cmd.getNewPassword(), cmd.getConfirmPassword());

        BeanUtils.copyProperties(cmd, userE);
        userE.encryptionPassword();
        userGateway.updatePassword(userE);
        return true;
    }


    @Transactional(rollbackFor = Exception.class)
    public void executeChangePassword(Long id) {
        UserE userE = new UserE();
        userE.resetPassword();
        userRepository.changePassword(id, userE.getPassword());
    }


    @Transactional(rollbackFor = Exception.class)
    public Response executeUpdatePassword(UserUpdatePassWordCmd userUpdatePassWordCmd) {
        UserE userE = new UserE();
        BeanUtils.copyProperties(userUpdatePassWordCmd, userE);
        userE.encryptionPassword();
        return userGateway.updatePassword(userE);
    }

    @Transactional(rollbackFor = Exception.class)
    public Boolean updateUserFaceUrl(UserUpdateFaceUrlCmd cmd) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(cmd, userDO);
        return userRepository.updateFaceUrl(userDO);
    }

    public void executeResignation(UserResignationCmd userResignationCmd) {
        //获取用户信息,并更新离职状态为离职
        UserDO userDO = userRepository.getInfoById(userResignationCmd.getUserId());
        //
        UserE userE = null;
        Long corpinfoId = userResignationCmd.getCorpinfoId() == null ? AuthContext.getTenantId() : userResignationCmd.getCorpinfoId();
        Integer employmentFlagBefore;
        if (UserFlowFlagEnum.FLOW.getCode().equals(userDO.getFlowFlag())) {
            UserCorpDO userCorpDO = userCorpRepository.getInfoByUserId(userDO.getId(), corpinfoId);
            if (userCorpDO == null) {
                return;
            }
            employmentFlagBefore = userCorpDO.getEmploymentFlag();
            userE = userCorpRepository.executeResignation(userCorpDO, corpinfoId, UserEmploymentFlagEnum.RESIGNATION.getCode());
        } else {
            userE = new UserE();
            BeanUtils.copyProperties(userDO, userE);
            employmentFlagBefore = userDO.getEmploymentFlag();
            userE.setEmploymentFlag(UserEmploymentFlagEnum.RESIGNATION.getCode());
            userGateway.update(userE);
        }
        if (userE == null) {
            return;
        }

        //修改企业入职记录

        UserCorpRecordDO userCorpRecordDO = userCorpRecordRepository.getInfoByUserId(userDO.getId(), corpinfoId, UserEmploymentFlagEnum.ON.getCode());
        UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
        if (userCorpRecordDO != null) {
            BeanUtils.copyProperties(userCorpRecordDO, userCorpRecordE);
            userCorpRecordE.executeResignation(userCorpRecordE, userE, UserEmploymentFlagEnum.RESIGNATION.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode());
            userCorpRecordGateway.update(userCorpRecordE);
        } else {
            userCorpRecordE.initResignation(userE, UserEmploymentFlagEnum.RESIGNATION.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode());
            userCorpRecordGateway.add(userCorpRecordE);
        }

        // 增加用户变更记录
        UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
        userChangeRecordE.executeResignation(userE, UserEmploymentFlagEnum.RESIGNATION.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode(), employmentFlagBefore);
        userChangeRecordGateway.add(userChangeRecordE);
        //TODO 处理未完成工作
         List<UserJobHandoverDO> allJob = getUserJob(userDO.getId(),corpinfoId,userChangeRecordE.getUserChangeRecordId());
         if(CollUtil.isNotEmpty(allJob)) {
             userJobHandoverRepository.saveBatch(allJob);
//        //TODO 离职发送,循环调用，失败的话，返回失败，
             ResignatioChangeJob(allJob);
         }
    }



    public void executeReviewStatus(UserReviewStatusCmd userReviewStatusCmd) {
        //获取用户信息,并更新审核状态
        UserDO userDO = userRepository.getInfoById(userReviewStatusCmd.getUserId());
        //
        UserEmploymentFlagEnum employmentFlagEnum = UserEmploymentFlagEnum.getByCode(userReviewStatusCmd.getEmploymentFlag());
        Integer employmentFlagAfter = null;
        switch (employmentFlagEnum) {
            case ENTRY_AUDIT:
                //入职待审核
                ReviewEntryAudit(userDO, userReviewStatusCmd);
                break;
            case RESIGNATION_AUDIT:
                //离职待审核
                ReviewResignationAudit(userDO, userReviewStatusCmd);
                break;
            default:
                throw new IllegalArgumentException("审核记录已完成");
        }

    }

    /**
     * 离职
     * @param userDO
     * @param userReviewStatusCmd
     */
    private void ReviewResignationAudit(UserDO userDO, UserReviewStatusCmd userReviewStatusCmd) {
        Integer reviewStatus = userReviewStatusCmd.getReviewStatus();
        //TODO 驳回需要待处理，暂时按照只能通过处理
        Integer employmentFlag = UserChangeRecordStatusEnum.APPROVED.getCode().equals(reviewStatus) ? UserEmploymentFlagEnum.RESIGNATION.getCode() : UserEmploymentFlagEnum.ON.getCode();
        UserE userE = null;
        Long corpinfoId = userReviewStatusCmd.getCorpinfoId() == null ? AuthContext.getTenantId() : userReviewStatusCmd.getCorpinfoId();
        if (UserFlowFlagEnum.FLOW.getCode().equals(userDO.getFlowFlag())) {
            userE = userCorpRepository.executeReviewStatus(userDO.getId(), corpinfoId, employmentFlag);
        } else {
            userE = new UserE();
            BeanUtils.copyProperties(userDO, userE);
            userE.setEmploymentFlag(employmentFlag);
            userGateway.update(userE);
        }
        if (userE == null) {
            return;
        }
        if (UserChangeRecordStatusEnum.APPROVED.getCode().equals(reviewStatus)) {
            //修改企业入职记录
            UserCorpRecordDO userCorpRecordDO = userCorpRecordRepository.getInfoByUserId(userDO.getId(), corpinfoId, UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
            UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
            if (userCorpRecordDO != null) {
                BeanUtils.copyProperties(userCorpRecordDO, userCorpRecordE);
                userCorpRecordE.executeResignation(userCorpRecordE, userE, UserEmploymentFlagEnum.RESIGNATION.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode());
                userCorpRecordGateway.update(userCorpRecordE);
            } else {
                userCorpRecordE.initResignation(userE, UserEmploymentFlagEnum.RESIGNATION.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode());
                userCorpRecordGateway.add(userCorpRecordE);
            }
            UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
            userChangeRecordE.executeReviewStatus(userE, UserEmploymentFlagEnum.RESIGNATION.getCode(),UserChangeRecordStatusEnum.APPROVED.getCode());
            userChangeRecordGateway.add(userChangeRecordE);
            ////TODO 通知GBS用户绑定租户

            // TODO 人员离职，相关工作处理，有一个失败则，审批失败

            //处理未完成的工作
            //获取未完成工作
            List<UserJobHandoverDO> allJob = userJobHandoverRepository.getListByChangerRecordId(userChangeRecordE.getUserChangeRecordId());
            if(CollUtil.isNotEmpty(allJob)){
                 ResignatioChangeJob(allJob);
            }
        } else {
            //驳回
            UserCorpRecordDO userCorpRecordDO = userCorpRecordRepository.getInfoByUserId(userDO.getId(), corpinfoId, UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
            UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
            if (userCorpRecordDO != null) {
                BeanUtils.copyProperties(userCorpRecordDO, userCorpRecordE);
                userCorpRecordE.executeResignation(userCorpRecordE, userE, UserEmploymentFlagEnum.ON.getCode(), UserChangeRecordStatusEnum.REJECTED.getCode());
                userCorpRecordGateway.update(userCorpRecordE);
            } else {
                userCorpRecordE.initResignation(userE, UserEmploymentFlagEnum.ON.getCode(), UserChangeRecordStatusEnum.REJECTED.getCode());
                userCorpRecordGateway.add(userCorpRecordE);
            }
            UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
            userChangeRecordE.executeReviewStatus(userE, UserEmploymentFlagEnum.ON.getCode(),UserChangeRecordStatusEnum.REJECTED.getCode());
            userChangeRecordGateway.add(userChangeRecordE);
        }
    }

    private void ReviewEntryAudit(UserDO userDO, UserReviewStatusCmd userReviewStatusCmd) {
        Integer reviewStatus = userReviewStatusCmd.getReviewStatus();
        //TODO 驳回需要待处理，暂时按照只能通过处理
        Integer employmentFlag = UserChangeRecordStatusEnum.APPROVED.getCode().equals(reviewStatus) ? UserEmploymentFlagEnum.ON.getCode() : UserEmploymentFlagEnum.NOT_ON.getCode();
        UserE userE = null;
        Long corpinfoId = userReviewStatusCmd.getCorpinfoId() == null ? AuthContext.getTenantId() : userReviewStatusCmd.getCorpinfoId();
        if (UserFlowFlagEnum.FLOW.getCode().equals(userDO.getFlowFlag())) {
            userE = userCorpRepository.executeReviewStatus(userDO.getId(), corpinfoId, employmentFlag);
        } else {
            userE = new UserE();
            BeanUtils.copyProperties(userDO, userE);
            userE.setEmploymentFlag(employmentFlag);
            userGateway.update(userE);
        }
        if (userE == null) {
            return;
        }
        if (UserChangeRecordStatusEnum.APPROVED.getCode().equals(reviewStatus)) {
            //增加企业入职记录
            //增加用户入职企业.  驳回不增加下边信息
         /*   CorpInfoDO corpInfoDO = corpInfoRepository.getById(userE.getCorpinfoId());
            DepartmentDO departmentDO = departmentRepository.getById(userE.getDepartmentId());

            UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
            BeanUtils.copyProperties(userDO, userCorpRecordE);
            userCorpRecordE.initAdd(userE, corpInfoDO.getCorpName(), departmentDO.getName());
            userCorpRecordGateway.add(userCorpRecordE);*/
            UserCorpRecordDO userCorpRecordDO = userCorpRecordRepository.getInfoByUserId(userDO.getId(), corpinfoId, UserEmploymentFlagEnum.ENTRY_AUDIT.getCode());
            UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
            if (userCorpRecordDO != null) {
                BeanUtils.copyProperties(userCorpRecordDO, userCorpRecordE);
                userCorpRecordE.executeEntryAudit(userCorpRecordE, userE, UserEmploymentFlagEnum.ON.getCode(), UserChangeRecordStatusEnum.APPROVED.getCode());
                userCorpRecordGateway.update(userCorpRecordE);
            }

            // 增加用户变更记录 ,获取变更记录
            UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
            userChangeRecordE.executeReviewStatus(userE, UserEmploymentFlagEnum.ON.getCode(),UserChangeRecordStatusEnum.APPROVED.getCode());
            userCorpRecordE.setStartTime( LocalDateTime.now());
            userChangeRecordGateway.add(userChangeRecordE);

            //TODO 通知GBS用户绑定租户，底座尚不支持用户绑定多个租户

        } else {
            //驳回
            //驳回
            UserCorpRecordDO userCorpRecordDO = userCorpRecordRepository.getInfoByUserId(userDO.getId(), corpinfoId, UserEmploymentFlagEnum.ENTRY_AUDIT.getCode());
            UserCorpRecordE userCorpRecordE = new UserCorpRecordE();
            if (userCorpRecordDO != null) {
                BeanUtils.copyProperties(userCorpRecordDO, userCorpRecordE);
                userCorpRecordE.executeEntryAudit(userCorpRecordE, userE, UserEmploymentFlagEnum.NOT_ON.getCode(), UserChangeRecordStatusEnum.REJECTED.getCode());
                userCorpRecordGateway.update(userCorpRecordE);
            }
            UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
            userChangeRecordE.executeReviewStatus(userE, UserEmploymentFlagEnum.NOT_ON.getCode(),UserChangeRecordStatusEnum.REJECTED.getCode());
            userChangeRecordGateway.add(userChangeRecordE);
        }

    }

    public void appUserResignation(AppUserResignationCmd appUserResignationCmd) {
        //更新状态，添加记录
        UserDO userDO = userRepository.getInfoById(appUserResignationCmd.getId());
        if (userDO == null) {
            throw new IllegalArgumentException("用户信息不存在");
        }
        UserE userE = null;
        Long corpinfoId = appUserResignationCmd.getCorpinfoId() == null ? AuthContext.getTenantId() : appUserResignationCmd.getCorpinfoId();
        Integer employmentFlagBefore = null;
        if (UserFlowFlagEnum.FLOW.getCode().equals(userDO.getFlowFlag())) {
            UserCorpDO userCorpDO = userCorpRepository.getInfoByUserId(userDO.getId(), corpinfoId);
            if (userCorpDO == null) {
                return;
            }
            employmentFlagBefore = userCorpDO.getEmploymentFlag();
            userE = userCorpRepository.executeResignation(userCorpDO, corpinfoId, UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
        } else {
            userE = new UserE();
            BeanUtils.copyProperties(userDO, userE);
            employmentFlagBefore = userDO.getEmploymentFlag();
            userE.setEmploymentFlag(UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode());
            userGateway.update(userE);
        }

        //插入变更记录
        UserChangeRecordE userChangeRecordE = new UserChangeRecordE();
        userChangeRecordE.executeResignation(userE, UserEmploymentFlagEnum.RESIGNATION_AUDIT.getCode(), UserChangeRecordStatusEnum.PENDING.getCode(), employmentFlagBefore);
        userChangeRecordGateway.add(userChangeRecordE);
        //TODO 处理未完成工作
        List<UserJobHandoverDO> allJob = getUserJob(userDO.getId(),corpinfoId,userChangeRecordE.getUserChangeRecordId());
        if(CollUtil.isNotEmpty(allJob)){
            userJobHandoverRepository.saveBatch(allJob);
        }
    }

    private List<UserJobHandoverDO> getUserJob(Long userId, Long corpinfoId, String userChangeRecordId) {
        ZcloudUserJobQry zcloudUserJobQry = new ZcloudUserJobQry();
        zcloudUserJobQry.setUserId(userId);
        zcloudUserJobQry.setCorpinfoId(corpinfoId);
        List<UserJobHandoverDO> allJob = new ArrayList<>();
        //隐患id
        HiddenStatisticsListQry hiddenStatisticsListQry = new HiddenStatisticsListQry() ;
        hiddenStatisticsListQry.setUserId(userId);
        //隐患要求传入企业id
        hiddenStatisticsListQry.setDeptId(corpinfoId);
        List<HiddenListByUserCO> hiddenListCOList =null;
        try{
            MultiResponse<HiddenListByUserCO> hiddenListCOMultiResponse = zcloudHiddenFacade.listByUserId(hiddenStatisticsListQry);
            hiddenListCOList = hiddenListCOMultiResponse.getData();
        }catch (Exception e){
            log.error("获取用户隐患信息异常, userId: {}, corpinfoId: {}", userId, corpinfoId,e);
        }
        if(CollUtil.isNotEmpty(hiddenListCOList)){
            hiddenListCOList.forEach(info -> {
                UserJobHandoverDO userJobHandoverDO = new UserJobHandoverDO();
                userJobHandoverDO.setUserJobHandoverId(Tools.get32UUID());
                userJobHandoverDO.setUserId(userId);
                userJobHandoverDO.setWorkProject(info.getWorkProject());
                userJobHandoverDO.setWorkContent(info.getWorkContent());
                userJobHandoverDO.setForeignKey(info.getHiddenId());
                userJobHandoverDO.setWorkType(UserJobHandoverWorkTypeEnum.HIDDENINFO.getCode());
                userJobHandoverDO.setUserChangeRecordId(userChangeRecordId);
                userJobHandoverDO.setCorpinfoId(corpinfoId);
                allJob.add(userJobHandoverDO);
            });
        }
        //循环获取所有未完成工作
     /*   userJobFacadeList.forEach(userJobFacade -> {
            try {
                MultiResponse<ZcloudUserJobCo> userJob = userJobFacade.getUserJob(zcloudUserJobQry);
                List<ZcloudUserJobCo> data = userJob.getData();
                List<UserJobHandoverDO> userJobHandoverEList = userJobHandoverCoConvertor.converCosToDOs( data);
                userJobHandoverEList.forEach(userJobHandoverE -> {
                    userJobHandoverE.setUserChangeRecordId(userChangeRecordId);
                });
                allJob.addAll(userJobHandoverEList);
            }catch (Exception e){
                log.error("获取用户未完成工作失败, userId: {}, corpinfoId: {},类信息{}", userId, corpinfoId,userJobFacade.getClass(),e);
            }
        });*/
        return allJob;
    }
    private void ResignatioChangeJob(List<UserJobHandoverDO> allJob) {
        allJob.forEach(info->{
            //取消工作
            UserJobHandoverWorkTypeEnum workTypeEnum = UserJobHandoverWorkTypeEnum.getByCode(info.getWorkType());
            switch (workTypeEnum){
                case HIDDENINFO:
                    HiddenUpdateCmd cmd = new HiddenUpdateCmd();
                    cmd.setUserId(info.getUserId());
                    //隐患信息，需要传入企业id
                    cmd.setDeptId(info.getCorpinfoId());
                    SingleResponse singleResponse = zcloudHiddenFacade.updateHiddenByUserId(cmd);
                    userJobHandoverRepository.processUserJobHandover(info.getUserChangeRecordId());
                    //隐患出异常是直接抛异常
                    break;
            }



        });



    }


}
