package cn.ey.biz.module.system.service.bpm;

import cn.ey.biz.common.exception.ErrorCode;
import cn.ey.biz.framework.security.core.util.SecurityFrameworkUtils;
import cn.ey.biz.framework.web.core.util.WebFrameworkUtils;
import cn.ey.biz.module.system.api.bpm.dto.*;
import cn.ey.biz.module.system.controller.bpm.instance.vo.*;
import cn.ey.biz.module.system.convert.bpm.BpmProcessInstanceConvert;
import cn.ey.biz.module.system.dal.dataobject.bpm.BpmProcessInstanceExtDO;
import cn.ey.biz.module.system.dal.dataobject.category.CategoryDataDO;
import cn.ey.biz.module.system.dal.mapper.bpm.BpmProcessInstanceExtMapper;
import cn.ey.biz.module.system.enums.bpm.BpmEnum;
import cn.ey.biz.module.system.enums.bpm.MaimDateTyepEnum;
import cn.ey.biz.module.system.enums.category.CategoryAppEnum;
import cn.ey.biz.module.system.enums.hrm.HrmEnum;
import cn.ey.biz.module.system.service.category.CategoryDataService;
import cn.ey.biz.module.system.service.hrm.HrmUserInfoWithService;
import cn.ey.biz.module.system.service.hrm.HrmUserInfoWithServicelmpl;
import cn.ey.biz.module.weaver.api.*;
import cn.ey.biz.module.weaver.common.HrmGetter;
import cn.ey.biz.module.weaver.common.RSP;
import cn.ey.biz.module.weaver.common.UserContextHolder;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

import static cn.ey.biz.common.exception.util.ServiceExceptionUtil.exception;
import static cn.ey.biz.module.system.enums.ErrorCodeConstants.WORKFLOW_ID_NOT_FIND;


@Service
@Validated
@Slf4j
public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService {

    @Resource
    DoCreateRequestService doCreateRequestService;
    @Resource
    BpmProcessInstanceExtMapper bpmProcessInstanceExtMapper;
    @Resource
    GetWorkflowRequestService getWorkflowRequestService;
    @Resource
    GetWorkflowRequestLogsService getWorkflowRequestLogsService;
    @Resource
    GetRequestFlowChartService getRequestFlowChartService;
    @Resource
    WithdrawRequestService withdrawRequestService;
    @Resource
    CategoryDataService categoryDataService;
    @Resource
    DoForceOverService doForceOverService;
    @Resource
    ForwardRequestService forwardRequestService;
    @Resource
    GetSimpleModeDataService getSimpleModeDataService;
    @Resource
    HrmUserInfoWithService hrmUserInfoWithService;
    @Resource
    GetStatusByIdService getStatusByIdService;
    @Resource
    ReceiveRequestInfoByJsonService receiveRequestInfoByJsonService;
    @Resource
    DeleteUserRequestInfoByJsonService deleteUserRequestInfoByJsonService;
    @Resource
    AddAgentSaveService addAgentSaveService;
    @Resource
    DeleteRequestService deleteRequestService;
    @Resource
    CheckOperatorAndSharedService checkOperatorAndSharedService;
    @Resource
    GetRequestBtnGroupService getRequestBtnGroupService;


    @Transactional
    @Override
    public String createProcessInstance(BpmProcessInstanceCreateReqVO createReqVO) {
        // 先保存数据到数据库中
        BpmProcessInstanceExtDO entity = BpmProcessInstanceConvert.INSTANCE.convert(createReqVO);
        // 调用内部方法
        return createProcessInstanceInner(createReqVO.getMainData(), createReqVO.getProcessDefinitionId(), entity,createReqVO.getIsnextflow(),createReqVO.getSysCode(),createReqVO.getEyredirecturl(),createReqVO.getRemark());
    }

    @Transactional
    @Override
    public String createProcessInstance(BpmProcessInstanceCreateDTO createDTO) {
        // 先保存数据到数据库中
        BpmProcessInstanceExtDO entity = BpmProcessInstanceConvert.INSTANCE.convert(createDTO);
        // 调用内部方法
        return createProcessInstanceInner(createDTO.getMainData(), createDTO.getProcessDefinitionId(), entity,createDTO.getIsnextflow(),createDTO.getSysCode(),createDTO.getEyredirecturl(),createDTO.getRemark());
    }

    public String createProcessInstanceInner(List<BpmProcessInstanceMainDataDTO> mainData, String processDefinitionId, BpmProcessInstanceExtDO entity, Integer otherParams,String sysCode,String eyredirecturl,String remark) {
        //先保存数据到数据库中
        entity.setStartUserId(null);
        bpmProcessInstanceExtMapper.insert(entity);
        //调用创建流程实例
        DoCreateRequestService.DoCreateRequest request = new DoCreateRequestService.DoCreateRequest();
        CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(), processDefinitionId);//createReqVO.getProcessDefinitionId()
        if(categoryDataDO!=null){
            request.setWorkflowId(Integer.parseInt(categoryDataDO.getValue()));
        }else{
            throw exception(WORKFLOW_ID_NOT_FIND);
        }
        request.setRequestName(entity.getName());
        //人力code转泛微Id
        manpowerAnalysis(mainData);
        request.setMainData(JSON.toJSONString(mainData));//createReqVO.getVariables().get("mainData")
        request.setEysystemcode(sysCode);
        request.setEyredirecturl(eyredirecturl);
        request.setRemark(remark);
        //附加参数
        if(otherParams!=null){
            Map<String,String> mapOtherParams=new HashMap<>();
            mapOtherParams.put("isnextflow",String.valueOf(otherParams));
            request.setOtherParams(JSON.toJSONString(mapOtherParams));
        }
        log.info("泛微入参:{}.", JSON.toJSONString(request));
        RSP<DoCreateRequestService.DoCreateResponse> response = doCreateRequestService.doCreateRequest(request);
        log.info("泛微返回参数:{}.", JSON.toJSONString(response));
        if(response.isSuccess()){
            //更新流程
            entity.setProcessInstanceId(String.valueOf(response.getData().getRequestid()));
            bpmProcessInstanceExtMapper.updateById(entity);
            return entity.getProcessInstanceId();
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public void cancelProcessInstance( BpmProcessInstanceCancelReqVO cancelReqVO) {
        WithdrawRequestService.WithdrawRequest request=new WithdrawRequestService.WithdrawRequest();
        request.setRemark(cancelReqVO.getReason());
        request.setRequestId(cancelReqVO.getId());
        RSP<WithdrawRequestService.WithdrawResponse> response=withdrawRequestService.withdrawRequest(request);
        if(!response.isSuccess()){
            throw exception(new ErrorCode(-1, JSON.toJSONString(response.getErrMsg())));
        }
    }

    @Override
    public BpmWorkflowRespVO getWorkflowRequest(BpmWorkflowReqVO reqVO) {
        GetWorkflowRequestService.WorkflowRequest request = new GetWorkflowRequestService.WorkflowRequest();
        request.setRequestId(reqVO.getRequestId());
        RSP<GetWorkflowRequestService.WorkflowResponse> response=getWorkflowRequestService.getWorkflowRequest(reqVO.getRequestId());
        if(response.isSuccess()){
            GetWorkflowRequestService.WorkflowResponse workflowResp =response.getData();
            BpmWorkflowRespVO result=BpmProcessInstanceConvert.INSTANCE.convert(workflowResp);
            CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(),reqVO.getProcessDefinitionId()+workflowResp.getCurrentNodeId());
            if(categoryDataDO!=null){
                result.setVueTemplate(categoryDataDO.getValue());
            }
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response.getErrMsg())));
        }
    }

    /**
     * 提供给系统
     * @param reqVO
     * @return
     */
    @Override
    public BpmWorkflowRespDTO getWorkflowRequest(BpmWorkflowDTO reqVO) {
        GetWorkflowRequestService.WorkflowRequest request = new GetWorkflowRequestService.WorkflowRequest();
        request.setRequestId(reqVO.getRequestId());
        RSP<GetWorkflowRequestService.WorkflowResponse> response=getWorkflowRequestService.getWorkflowRequest(reqVO.getRequestId());
        if(response.isSuccess()){
            GetWorkflowRequestService.WorkflowResponse workflowResp =response.getData();
            BpmWorkflowRespDTO result=BpmProcessInstanceConvert.INSTANCE.convertDto(workflowResp);
            CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(),reqVO.getProcessDefinitionId()+workflowResp.getCurrentNodeId());
            if(categoryDataDO!=null){
                result.setVueTemplate(categoryDataDO.getValue());
            }
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response.getErrMsg())));
        }
    }

    @Override
    public List<BpmWorkflowRequestLogsRespVO> getWorkflowRequestLogs(Long userId, BpmWorkflowLogsReqVO reqVO) {
        GetWorkflowRequestLogsService.WorkflowRequestLogsRequest request = new GetWorkflowRequestLogsService.WorkflowRequestLogsRequest();
        request.setConditions(reqVO.getConditions());
        request.setEndId(reqVO.getEndId());
        request.setPageSize(reqVO.getPageSize());
        request.setRequestId(reqVO.getRequestId());
        request.setUserId(userId+"");
        request.setWorkflowId(reqVO.getWorkflowId());
        List<GetWorkflowRequestLogsService.WorkflowRequestLogsResponse> response = getWorkflowRequestLogsService.getWorkflowRequestLogs(request);
        if(CollectionUtil.isNotEmpty(response)){
            List<BpmWorkflowRequestLogsRespVO> list = BpmProcessInstanceConvert.INSTANCE.convertList(response);
            return list;
        }else{
            throw exception(new ErrorCode(-1,"无记录"));
        }
    }

    @Override
    public BpmFlowChartRespVO getRequestFlowChart(BpmFlowChartReqVO reqVO) {
        GetRequestFlowChartService.RequestFlowChartRequest request = new GetRequestFlowChartService.RequestFlowChartRequest();
        request.setOtherParams(reqVO.getOtherParams());
        request.setRequestid(reqVO.getRequestid());
        RSP<GetRequestFlowChartService.RequestFlowChartResponse> response = getRequestFlowChartService.getRequestFlowChart(reqVO.getRequestid());
        if(response.isSuccess()){
            BpmFlowChartRespVO result=new BpmFlowChartRespVO();
            result.setChartUrl(response.getData().getChartUrl());
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response.getErrMsg())));
        }
    }

    @Override
    public BpmProcessInstanceRespVO getProcessInstanceVO(BpmProcessInstanceReqVO reqVO) {
        BpmProcessInstanceExtDO bpmProcessInstanceExtDO = bpmProcessInstanceExtMapper.selectOne(reqVO);
        return BpmProcessInstanceConvert.INSTANCE.convert(bpmProcessInstanceExtDO);
    }

    @Override
    public void doForceOver(BpmDoForceOverReqVO reqVO) {
        if(reqVO!=null ){
            DoForceOverService.DoForceOverRequest request=new DoForceOverService.DoForceOverRequest();
            request.setOtherParams(reqVO.getOtherParams());
            request.setRequestId(reqVO.getRequestId());
            RSP<DoForceOverService.DoForceOverResponse> response=doForceOverService.doForceOver(request);
            if(!response.isSuccess()){
                throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
            }
        }
    }

    @Override
    public void forwardRequest(List<BpmForwardRequestReqVO> reqListVO) {
        if(reqListVO!=null && reqListVO.size()>0){
            for(BpmForwardRequestReqVO reqVO:reqListVO){
                ForwardRequestService.forwardRequest  request= new ForwardRequestService.forwardRequest();
                request.setForwardFlag(reqVO.getForwardFlag());
                request.setOtherParams(reqVO.getOtherParams());
                request.setRemark(reqVO.getRemark());
                request.setRequestId(reqVO.getRequestId());
                //根据code获取泛微用户
                HrmUserInfoWithServicelmpl.Item item=hrmUserInfoWithService.getWeaverUser(reqVO.getForwardResourceIds());
                if(item!=null){
                    request.setForwardResourceIds(item.getId());
                }
                RSP<ForwardRequestService.ForwardResponse> response=forwardRequestService.forwardRequest(request);
                if(!response.isSuccess()){
                    throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
                }
            }
        }
    }

    @Override
    public BpmSimpleModeDataRespVo getSimpleModeData(BpmSimpleModeDataReqVO reqVO) {
        GetSimpleModeDataService.SimpleModeDataRequest request=new GetSimpleModeDataService.SimpleModeDataRequest();
        request.setRequestId(reqVO.getRequestId());
        request.setRequestType(reqVO.getRequestType());
        CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(), reqVO.getWorkflowId());
        if(categoryDataDO!=null){
            request.setWorkflowid(categoryDataDO.getValue());
        }
        GetSimpleModeDataService.SimpleModeDataResponse  response=getSimpleModeDataService.getSimpleModeData(request);
        if(response!=null){
            BpmSimpleModeDataRespVo  result=BpmProcessInstanceConvert.INSTANCE.convert(response);
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString("无记录")));
        }
    }

    @Override
    public void withdrawRequest(BpmWithdrawRequestDTO bpmWithdrawRequestDTO) {
        WithdrawRequestService.WithdrawRequest request=new WithdrawRequestService.WithdrawRequest();
        request.setIsremind(bpmWithdrawRequestDTO.getIsremind());
        request.setRemark(bpmWithdrawRequestDTO.getRemark());
        request.setRequestId(bpmWithdrawRequestDTO.getRequestId());
        RSP<WithdrawRequestService.WithdrawResponse> response=withdrawRequestService.withdrawRequest(request);
        if(!response.isSuccess()){
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public String getStatusById(BpmGetStatusByIdDTO bpmGetStatusByIdDTO) {
        GetStatusByIdService.StatusByIdRequest request=new GetStatusByIdService.StatusByIdRequest();
        request.setRequestid(bpmGetStatusByIdDTO.getRequestId());
        GetStatusByIdService.StatusByIdResponse  response=getStatusByIdService.getStatusById(request);
        if(response.getApi_status()){
            return  response.getApi_data().getStatus();
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public void doForceOver(BpmDoForceOverDTO bpmDoForceOverDT) {
        if(bpmDoForceOverDT!=null ){
            DoForceOverService.DoForceOverRequest request=new DoForceOverService.DoForceOverRequest();
            Map<String,String> mapOtherParams=new HashMap<>();
            mapOtherParams.put("ismonitor","1");
            request.setOtherParams(JSON.toJSONString(mapOtherParams));
            request.setRequestId(bpmDoForceOverDT.getRequestId());
            RSP<DoForceOverService.DoForceOverResponse> response=doForceOverService.doForceOver(request);
            if(!response.isSuccess()){
                throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
            }
        }
    }

    @Override
    public ReceiveRequestInfoByJsonRespDTO ReceiveRequestInfoByJson(ReceiveRequestInfoByJsonDTO receiveDTO) {
        ReceiveRequestInfoByJsonService.ReceiveRequestInfoByJsonRequest  request=new ReceiveRequestInfoByJsonService.ReceiveRequestInfoByJsonRequest();
        request.setSyscode(receiveDTO.getSyscode());
        request.setFlowid(receiveDTO.getFlowid());
        request.setRequestname(receiveDTO.getRequestname());
        request.setWorkflowname(receiveDTO.getWorkflowname());
        request.setNodename(receiveDTO.getNodename());
        request.setPcurl(receiveDTO.getPcurl());
        request.setAppurl(receiveDTO.getAppurl());
        request.setIsremark(receiveDTO.getIsremark());
        request.setViewtype(receiveDTO.getViewtype());
        request.setCreator(receiveDTO.getCreator());
        request.setCreatedatetime(receiveDTO.getCreatedatetime());
        request.setReceiver(receiveDTO.getReceiver());
        request.setReceivedatetime(receiveDTO.getReceivedatetime());
        request.setReceivets(receiveDTO.getReceivets());
        ReceiveRequestInfoByJsonService.ReceiveRequestInfoByJsonResponse response=receiveRequestInfoByJsonService.receiveRequestInfoByJson(request);
        if(response!=null){
            ReceiveRequestInfoByJsonRespDTO result=BpmProcessInstanceConvert.INSTANCE.convert(response);
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString("无信息")));
        }
    }

    @Override
    public DeleteUserRequestInfoByJsonRespDTO deleteUserRequestInfoByJson(DeleteUserRequestInfoByJsonDTO deleteDTO) {
        DeleteUserRequestInfoByJsonService.DeleteUserRequestInfoByJsonRequest request=new DeleteUserRequestInfoByJsonService.DeleteUserRequestInfoByJsonRequest();
        request.setSyscode(deleteDTO.getSyscode());
        request.setFlowid(deleteDTO.getFlowid());
        request.setUserid(deleteDTO.getUserid());
        DeleteUserRequestInfoByJsonService.DeleteUserRequestInfoByJsonResponse response=deleteUserRequestInfoByJsonService.deleteUserRequestInfoByJson(request);
        if(response!=null){
            DeleteUserRequestInfoByJsonRespDTO result=new DeleteUserRequestInfoByJsonRespDTO();
            result.setSyscode(response.getSyscode());
            result.setDataType(response.getDataType());
            result.setOperType(response.getOperType());
            result.setOperResult(response.getOperResult());
            result.setMessage(response.getMessage());
            return result;
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString("无信息")));
        }
    }

    @Override
    public String addAgentSave(BpmAddAgentSaveDTO saveDTO) {
        CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(), HrmEnum.WEAVER_USERID.getCode());
        UserContextHolder.set(HrmGetter.USER_ID,categoryDataDO.getValue());
        AddAgentSaveService.AddAgentSaveRequest request=new AddAgentSaveService.AddAgentSaveRequest();
        request.setMethod(saveDTO.getMethod());
        request.setBagentuid(hrmUserInfoWithService.getWeaverUser(saveDTO.getBagentuid()).getId());
        request.setAgentuid(hrmUserInfoWithService.getWeaverUser(saveDTO.getAgentuid()).getId());
        request.setBeginDate(saveDTO.getBeginDate());
        request.setBeginTime(saveDTO.getBeginTime());
        request.setEndDate(saveDTO.getEndDate());
        request.setEndTime(saveDTO.getEndTime());
        request.setIsCreateAgenter(saveDTO.getIsCreateAgenter());
        request.setIsProxyDeal(saveDTO.getIsProxyDeal());
        request.setRangetype(saveDTO.getRangetype());
        request.setAgentrange(saveDTO.getAgentrange());
        request.setIsPendThing(saveDTO.getIsPendThing());
        request.setOverlapMethod(saveDTO.getOverlapMethod());
        AddAgentSaveService.AddAgentSaveResponse response=addAgentSaveService.addAgentSave(request);
        if(response.getAgentresult().equals("success")){
            return response.getAgentresult();
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public void deleteRequest(BpmDeleteRequestDTO deleteDTO) {
        CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(), HrmEnum.WEAVER_USERID.getCode());
        UserContextHolder.set(HrmGetter.USER_ID, categoryDataDO.getValue());
        DeleteRequestService.DeleteRequest  request= new DeleteRequestService.DeleteRequest();
        request.setRequestId(deleteDTO.getRequestId());
        Map<String,String> mapOtherParams=new HashMap<>();
        mapOtherParams.put("ismonitor","1");
        request.setOtherParams(JSON.toJSONString(mapOtherParams));
        RSP<DeleteRequestService.DeleteResponse> response=deleteRequestService.deleteRequest(request);
        if(!response.isSuccess()){
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public boolean checkOperatorAndShared(CheckOperatorAndSharedRequestDTO operatorDTO) {
        CategoryDataDO categoryDataDO=categoryDataService.getCategoryDataKey(CategoryAppEnum.ADMIN.getApp(), BpmEnum.WEAVER_FLOW.getCode(), HrmEnum.WEAVER_USERID.getCode());
        UserContextHolder.set(HrmGetter.USER_ID,categoryDataDO.getValue());
        CheckOperatorAndSharedService.CheckOperatorAndSharedRequest request=new CheckOperatorAndSharedService.CheckOperatorAndSharedRequest();
        request.setRequestid(operatorDTO.getRequestId());
        //如不传userCode自动获取当前userCode
        String userCode=operatorDTO.getUserCode();
        if(StringUtil.isBlank(userCode)){
            userCode = SecurityFrameworkUtils.getLoginUser().getUserCode();
        }
        request.setUserid(hrmUserInfoWithService.getWeaverUser(userCode).getId());
        CheckOperatorAndSharedService.CheckOperatorAndSharedResponse response=checkOperatorAndSharedService.checkOperatorAndShared(request);
        if(response.getCode().equals("SUCCESS")){
            return response.getIsOperator();
        }else{
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    @Override
    public String getRequestBtnGroup(CheckOperatorAndSharedRequestDTO btnGroupDTO) {
        GetRequestBtnGroupService.RequestBtnGroupRequest request=new GetRequestBtnGroupService.RequestBtnGroupRequest();
        request.setRequestid(btnGroupDTO.getRequestId());
        if(StringUtil.isNotBlank(btnGroupDTO.getUserCode())){
            WebFrameworkUtils.setLoginUserCode(btnGroupDTO.getUserCode());
        }
        GetRequestBtnGroupService.RequestBtnGroupResponse response=getRequestBtnGroupService.getRequestBtnGroup(request);
        if(response.getCode().equals("SUCCESS")){
            return response.getBtnGroup();
        }else {
            throw exception(new ErrorCode(-1, JSON.toJSONString(response)));
        }
    }

    /**
     *
     * @param operatorDTO
     * @return
     */
    @Override
    public boolean checkOperatorAndSharedButton(CheckOperatorAndSharedRequestDTO operatorDTO) {
        if(operatorDTO.getAuthType().equals("QUERY")){
            return checkOperatorAndShared(operatorDTO);
        }else {
            String btnGroup=getRequestBtnGroup(operatorDTO);
            if(StringUtil.isNotBlank(btnGroup) && btnGroup.contains(operatorDTO.getAuthType().toLowerCase()) ){
                return true;
            }else {
                return false;
            }
        }
    }

    // 人力code转泛微id
    public void manpowerAnalysis(List<BpmProcessInstanceMainDataDTO> mainData){
        if(CollectionUtil.isNotEmpty(mainData)){
            for(BpmProcessInstanceMainDataDTO ma:mainData){
                if(ma.getType()!=null && ma.getType().equals(MaimDateTyepEnum.PERSON.getType())){
                    List<String> strAll=new ArrayList<>();
                    String fieldValue =ma.getFieldValue();
                    if(StringUtil.isNotBlank(fieldValue)){
                        List<String> result = Arrays.asList(fieldValue.split(","));
                        for(String st:result){
                            HrmUserInfoWithServicelmpl.Item item=hrmUserInfoWithService.getWeaverUser(st);
                            strAll.add(item.getId());
                        }
                        String  strval= strAll.stream().collect(Collectors.joining(","));
                        ma.setFieldValue(strval);
                    }
                }
            }
        }
    }

}


