| package com.doumee.service.business.impl; | 
|   | 
| import com.doumee.biz.system.SystemDictDataBiz; | 
| import com.doumee.core.constants.ResponseStatus; | 
| import com.doumee.core.exception.BusinessException; | 
| import com.doumee.core.model.LoginUserInfo; | 
| import com.doumee.core.model.PageData; | 
| import com.doumee.core.model.PageWrap; | 
| import com.doumee.core.utils.Constants; | 
| import com.doumee.core.utils.Utils; | 
| import com.doumee.dao.business.CompanyMapper; | 
| import com.doumee.dao.business.ContractMapper; | 
| import com.doumee.dao.business.MultifileMapper; | 
| import com.doumee.dao.business.NoticesMapper; | 
| import com.doumee.dao.business.join.ContractJoinMapper; | 
| import com.doumee.dao.business.model.*; | 
| import com.doumee.dao.system.model.SystemUser; | 
| import com.doumee.service.business.ContractService; | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
| import com.baomidou.mybatisplus.core.metadata.IPage; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.doumee.service.business.third.SignService; | 
| import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Objects; | 
|   | 
| /** | 
|  * 合同信息表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2024/10/28 19:16 | 
|  */ | 
| @Service | 
| public class ContractServiceImpl implements ContractService { | 
|   | 
|     @Autowired | 
|     private ContractMapper contractMapper; | 
|   | 
|     @Autowired | 
|     private ContractJoinMapper contractJoinMapper; | 
|   | 
|     @Autowired | 
|     private MultifileMapper multifileMapper; | 
|   | 
|     @Autowired | 
|     private SystemDictDataBiz systemDictDataBiz; | 
|   | 
|     @Autowired | 
|     private CompanyMapper companyMapper;  | 
|      | 
|     @Autowired | 
|     private SignService signService; | 
|   | 
|     @Autowired | 
|     private NoticesMapper noticesMapper; | 
|   | 
|     @Override | 
|     public Integer create(Contract contract) { | 
|         LoginUserInfo loginUserInfo =   (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         initCreateParam(contract); | 
|         contract.setIsdeleted(Constants.ZERO); | 
|         contract.setCreateDate(new Date()); | 
|         contract.setCreator(loginUserInfo.getId()); | 
|         contract.setEditor(loginUserInfo.getId()); | 
|         contract.setEditDate(new Date()); | 
|         contract.setStatus(Constants.ZERO); | 
|         contract.setFileUrl(contract.getFileUrl()); | 
|         Company company = companyMapper.selectById(contract.getCompanyId()); | 
|         if(Constants.equalsInteger(loginUserInfo.getType(),Constants.ZERO)){ | 
|             if(Constants.equalsInteger(company.getType(),Constants.ONE)){ | 
|                 contract.setSignType(Constants.ZERO); | 
|             }else{ | 
|                 contract.setSignType(Constants.ONE); | 
|             } | 
|         }else if(Constants.equalsInteger(loginUserInfo.getType(),Constants.TWO)){ | 
|             contract.setPartyCompanyId(loginUserInfo.getCompanyId()); | 
|             contract.setSignType(Constants.TWO); | 
|         }else{ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"企业用户无法进行该操作!"); | 
|         } | 
|         contractMapper.insert(contract); | 
|   | 
|         Multifile file = contract.getMultifile(); | 
|         file.setIsdeleted(Constants.ZERO); | 
|         file.setCreateDate(contract.getCreateDate()); | 
|         file.setCreator(contract.getCreator()); | 
|         file.setObjId(contract.getId()); | 
|         file.setObjType(Constants.MultiFile.CONTRACT_PDF.getKey()); | 
|         file.setType(Constants.formatIntegerNum(file.getType())); | 
|         multifileMapper.insert(file); | 
|   | 
|   | 
|   | 
|         //存储待办信息 | 
|         Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.CONTRACT; | 
|         //平台待办 | 
|         Notices notices = new Notices(noticeObjectType, | 
|                 Constants.equalsInteger(contract.getSignType(),Constants.TWO)?Constants.TWO:Constants.ZERO | 
|                 ,contract.getId(), | 
|                 this.getNoticeInfo(contract,company), | 
|                 Constants.equalsInteger(contract.getSignType(),Constants.TWO)? | 
|                 contract.getPartyCompanyId():null | 
|                 ,Constants.NoticeType.ZERO); | 
|         noticesMapper.insert(notices); | 
|   | 
|         return contract.getId(); | 
|     } | 
|   | 
|     public String getNoticeInfo(Contract contract,Company company){ | 
|         String noticeInfo = contract.getName(); | 
|         //商户信息 | 
|         if(Constants.equalsInteger(contract.getSignType(),Constants.TWO)){ | 
|             Company shop = companyMapper.selectById(contract.getPartyCompanyId()); | 
|             noticeInfo  = noticeInfo + "("+shop.getName()+"/"+company.getName()+")"; | 
|         }else{ | 
|             noticeInfo  = noticeInfo + "(平台/"+company.getName()+")"; | 
|         } | 
|         return noticeInfo; | 
|     } | 
|   | 
|   | 
|     private void initCreateParam(Contract contract) { | 
|         if(StringUtils.isBlank(contract.getName()) | 
|                 || Objects.isNull(contract.getType()) | 
|                 || Objects.isNull(contract.getCompanyId()) | 
|                 || Objects.isNull(contract.getStartTime()) | 
|                 || Objects.isNull(contract.getEndTime()) | 
|                 || Objects.isNull(contract.getMultifile()) | 
|                  || Objects.isNull(contract.getMultifile().getFileurl()) | 
|         ){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|         } | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public void deleteById(Integer id) { | 
|         LoginUserInfo loginUserInfo =   (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         Contract contract = contractJoinMapper.selectById(id); | 
|         if(Objects.isNull(contract)){ | 
|             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到合同信息"); | 
|         } | 
|         if(!Constants.equalsInteger(contract.getStatus(),Constants.CONTRACT_STATUS.CANCEL.getKey())){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"合同信息信息已流转"); | 
|         } | 
|         contract.setStatus(Constants.CONTRACT_STATUS.CLOSE.getKey()); | 
|         contract.setIsdeleted(Constants.ONE); | 
|         contract.setEditor(loginUserInfo.getId()); | 
|         contract.setEditDate(new Date()); | 
|         contractMapper.updateById(contract); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(Contract contract) { | 
|         UpdateWrapper<Contract> deleteWrapper = new UpdateWrapper<>(contract); | 
|         contractMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         contractMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(Contract contract) { | 
|         contractMapper.updateById(contract); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<Contract> contracts) { | 
|         if (CollectionUtils.isEmpty(contracts)) { | 
|             return; | 
|         } | 
|         for (Contract contract: contracts) { | 
|             this.updateById(contract); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public Contract findById(Integer id) { | 
|         MPJLambdaWrapper<Contract> queryWrapper = new MPJLambdaWrapper<>(); | 
|         queryWrapper.selectAll(Contract.class); | 
|         queryWrapper.select("  ifnull(t2.name,'安徽云易保科技有限公司') as partyCompanyName , t3.name as companyName "); | 
|         queryWrapper.select(" t4.REALNAME as firstSignUserName  , t5.REALNAME as doneSignUserName "); | 
|         queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Contract::getCreator); | 
|         queryWrapper.leftJoin(" company t2 on t2.id = t.PARTY_COMPANY_ID "); | 
|         queryWrapper.leftJoin(" company t3 on t3.id = t.COMPANY_ID "); | 
|         queryWrapper.leftJoin(" system_user t4 on t4.id = t.SIGN_USER_ID  "); | 
|         queryWrapper.leftJoin(" system_user t5 on t5.id = t.COM_SIGN_USER_ID  "); | 
|         queryWrapper.eq(Contract::getId,id); | 
|         queryWrapper.last(" limit 1"); | 
|         Contract contract = contractJoinMapper.selectJoinOne(Contract.class,queryWrapper); | 
|   | 
|   | 
|         Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() | 
|                 .eq(Multifile::getObjType,Constants.MultiFile.CONTRACT_PDF.getKey()) | 
|                 .eq(Multifile::getObjId,contract.getId()) | 
|                 .last(" limit 1 ") | 
|         ); | 
|   | 
|         if(Objects.nonNull(multifile)&&StringUtils.isNotBlank(multifile.getFileurl())){ | 
|             String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+ | 
|                     systemDictDataBiz.queryByCode(Constants.OSS,Constants.CONTRACT).getCode(); | 
|             multifile.setFileurlFull(url + multifile.getFileurl()); | 
|             contract.setMultifile(multifile); | 
|         } | 
|   | 
|         if(Constants.equalsInteger(contract.getStatus(),Constants.ONE) || Constants.equalsInteger(contract.getStatus(),Constants.THREE) ){ | 
|             Multifile multiFirstFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() | 
|                     .eq(Multifile::getObjType,Constants.MultiFile.CONTRACT_FIRST_PDF.getKey()) | 
|                     .eq(Multifile::getObjId,contract.getId()) | 
|                     .last(" limit 1 ") | 
|             ); | 
|             String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+ | 
|                     systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode(); | 
|   | 
|             if(Objects.nonNull(multiFirstFile)&&StringUtils.isNotBlank(multiFirstFile.getFileurl())){ | 
|                 multiFirstFile.setFileurlFull(path + multiFirstFile.getFileurl()); | 
|                 contract.setMultiFirstFile(multiFirstFile); | 
|             } | 
|   | 
|             if(StringUtils.isNotBlank(contract.getDoneFileUrl())){ | 
|                 Multifile multiDoneFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() | 
|                         .eq(Multifile::getObjType,Constants.MultiFile.CONTRACT_DONE_PDF.getKey()) | 
|                         .eq(Multifile::getObjId,contract.getId()) | 
|                         .last(" limit 1 ") | 
|                 ); | 
|   | 
|                 if(Objects.nonNull(multiDoneFile)&&StringUtils.isNotBlank(multiDoneFile.getFileurl())){ | 
|                     multiDoneFile.setFileurlFull(path + multiDoneFile.getFileurl()); | 
|                     contract.setMultiDoneFile(multiDoneFile); | 
|                 } | 
|             } | 
|   | 
|         } | 
|   | 
|         return contract; | 
|     } | 
|   | 
|     @Override | 
|     public Contract findOne(Contract contract) { | 
|         QueryWrapper<Contract> wrapper = new QueryWrapper<>(contract); | 
|         return contractMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<Contract> findList(Contract contract) { | 
|         QueryWrapper<Contract> wrapper = new QueryWrapper<>(contract); | 
|         return contractMapper.selectList(wrapper); | 
|     } | 
|    | 
|     @Override | 
|     public PageData<Contract> findPage(PageWrap<Contract> pageWrap) { | 
|         IPage<Contract> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         MPJLambdaWrapper<Contract> queryWrapper = new MPJLambdaWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         queryWrapper.selectAll(Contract.class); | 
|         queryWrapper.select("  ifnull(t2.name,'安徽云易保科技有限公司') as partyCompanyName , t3.name as companyName "); | 
|         queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Contract::getCreator); | 
|         queryWrapper.leftJoin(" company t2 on t2.id = t.PARTY_COMPANY_ID "); | 
|         queryWrapper.leftJoin(" company t3 on t3.id = t.COMPANY_ID "); | 
|         queryWrapper.eq(Contract::getIsdeleted,Constants.ZERO); | 
|         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getCompanyId()), | 
|                 Contract::getCompanyId,pageWrap.getModel().getCompanyId()); | 
|   | 
|         queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()), | 
|                 Contract::getName,pageWrap.getModel().getName()); | 
|   | 
|         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getStatus()), | 
|                 Contract::getStatus,pageWrap.getModel().getStatus()); | 
|   | 
|         queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getSignType()), | 
|                 Contract::getSignType,pageWrap.getModel().getSignType()); | 
|   | 
|         LoginUserInfo loginUserInfo =   (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(Constants.equalsInteger(loginUserInfo.getType(),Constants.ONE)){ | 
|             //企业可看数据 | 
|             queryWrapper.eq(Contract::getCompanyId,loginUserInfo.getCompanyId()); | 
|         }else if(Constants.equalsInteger(loginUserInfo.getType(),Constants.TWO)){ | 
|             //商户可看到的数据 | 
|             queryWrapper.and(i->i.eq(Contract::getPartyCompanyId,loginUserInfo.getCompanyId()).or() | 
|                     .eq(Contract::getCompanyId,loginUserInfo.getCompanyId())); | 
|         } | 
|         if(Objects.nonNull(pageWrap.getModel().getQueryStatus())){ | 
|             if(Constants.equalsInteger(pageWrap.getModel().getQueryStatus(),Constants.ZERO)){ | 
|                 queryWrapper.apply(" t.status = 0 and t.sign_type in (0,1) "); | 
|             }else if(Constants.equalsInteger(pageWrap.getModel().getQueryStatus(),Constants.ONE)){ | 
|                 queryWrapper.apply(" ( (t.status = 0 and t.sign_type = 2 ) or ( t.status = 1 and t.sign_type = 0 )  )"); | 
|             }else if(Constants.equalsInteger(pageWrap.getModel().getQueryStatus(),Constants.TWO)){ | 
|                 queryWrapper.apply(" ( (t.status = 1 and t.sign_type = 1 ) or ( t.status = 1 and t.sign_type = 2 )  )"); | 
|             }else{ | 
|                 queryWrapper.eq(Contract::getStatus,pageWrap.getModel().getQueryStatus()); | 
|             } | 
|         } | 
|         queryWrapper.orderByDesc(Contract::getCreateDate); | 
|         PageData<Contract> pageData = PageData.from(contractJoinMapper.selectJoinPage(page,Contract.class, queryWrapper)); | 
|         for (Contract contract:pageData.getRecords()) { | 
|             this.dealQueryStauts(contract); | 
|         } | 
|         return pageData; | 
|     } | 
|   | 
|     public void dealQueryStauts(Contract contract){ | 
|         if(Constants.equalsInteger(contract.getSignType(),Constants.ZERO)){ | 
|             if(Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|                 contract.setQueryStatus(Constants.ZERO); | 
|             }else if(Constants.equalsInteger(contract.getStatus(),Constants.ONE)){ | 
|                 contract.setQueryStatus(Constants.ONE); | 
|             }else{ | 
|                 contract.setQueryStatus(contract.getStatus()); | 
|             } | 
|         }else if(Constants.equalsInteger(contract.getSignType(),Constants.ONE)){ | 
|             if(Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|                 contract.setQueryStatus(Constants.ZERO); | 
|             }else if(Constants.equalsInteger(contract.getStatus(),Constants.ONE)){ | 
|                 contract.setQueryStatus(Constants.TWO); | 
|             }else{ | 
|                 contract.setQueryStatus(contract.getStatus()); | 
|             } | 
|         }else{ | 
|             if(Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|                 contract.setQueryStatus(Constants.ONE); | 
|             }else if(Constants.equalsInteger(contract.getStatus(),Constants.ONE)){ | 
|                 contract.setQueryStatus(Constants.TWO); | 
|             }else{ | 
|                 contract.setQueryStatus(contract.getStatus()); | 
|             } | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public void cancel(Integer id) { | 
|         LoginUserInfo loginUserInfo =   (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         Contract contract = contractJoinMapper.selectById(id); | 
|         if(Objects.isNull(contract)){ | 
|             throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到合同信息"); | 
|         } | 
|         if(!Constants.equalsInteger(contract.getStatus(),Constants.CONTRACT_STATUS.WAIT.getKey())){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"合同信息信息已流转"); | 
|         } | 
|         if(StringUtils.isNotBlank(contract.getApplyNo())){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"合同签署中,无法进行取消"); | 
|         } | 
|   | 
|         contract.setStatus(Constants.CONTRACT_STATUS.CANCEL.getKey()); | 
|         contract.setCancelDate(new Date()); | 
|         contract.setCancelUserId(loginUserInfo.getId()); | 
|         contract.setEditor(loginUserInfo.getId()); | 
|         contract.setEditDate(new Date()); | 
|         contractMapper.updateById(contract); | 
|   | 
|         //删除待办 | 
|         Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.CONTRACT; | 
|         noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,contract.getId())); | 
|   | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public long count(Contract contract) { | 
|         QueryWrapper<Contract> wrapper = new QueryWrapper<>(contract); | 
|         return contractMapper.selectCount(wrapper); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public  String getContractSignLink(Integer id) { | 
|         if(id == null ){ | 
|             throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
|         } | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         MPJLambdaWrapper<Contract> queryWrapper = new MPJLambdaWrapper<>(); | 
|         queryWrapper.selectAll(Contract.class); | 
|         queryWrapper.select("  ifnull(t2.name,'安徽云易保科技有限公司') as partyCompanyName , t3.name as companyName "); | 
|         queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Contract::getCreator); | 
|         queryWrapper.leftJoin(" company t2 on t2.id = t.PARTY_COMPANY_ID "); | 
|         queryWrapper.leftJoin(" company t3 on t3.id = t.COMPANY_ID "); | 
|         queryWrapper.eq(Contract::getIsdeleted,Constants.ZERO); | 
|         queryWrapper.eq(Contract::getId,id); | 
|         queryWrapper.last(" limit 1"); | 
|         Contract contract = contractJoinMapper.selectJoinOne(Contract.class,queryWrapper); | 
|         if(contract == null ||!Constants.equalsInteger(contract.getIsdeleted(),Constants.ZERO) ){ | 
|             throw  new BusinessException(ResponseStatus.DATA_EMPTY); | 
|         } | 
|         Company company = companyMapper.selectById(contract.getCompanyId()); | 
|         if(Objects.isNull(company)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到企业信息!"); | 
|         } | 
|         //当前签署人 0=我方;2=企业/商户 | 
|         Integer signatory =  Constants.ZERO; | 
|         //判断当前是否可以签署 | 
|         if(Constants.equalsInteger(user.getType(),Constants.ZERO)){ | 
|             //判断平台是否可以签署 | 
|             if(!( !Constants.equalsInteger(contract.getSignType(),Constants.TWO) && Constants.equalsInteger(contract.getStatus(),Constants.ZERO))){ | 
|                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前非平台用户可签署流程"); | 
|             } | 
|         }else if(Constants.equalsInteger(user.getType(),Constants.TWO)){ | 
|             //平台创建的 | 
|             if(!Constants.equalsInteger(contract.getSignType(),Constants.TWO) ){ | 
|                 signatory = Constants.ONE; | 
|                 //判断状态是否等于待商户签署 签署企业是否等于当前登录人企业 | 
|                 if(!(Constants.equalsInteger(contract.getStatus(),Constants.ONE) && Constants.equalsInteger(contract.getCompanyId(),user.getCompanyId()))){ | 
|                     throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前非商户用户可签署流程"); | 
|                 } | 
|             }else{ | 
|                 //商户创建 | 
|                 //判断状态是否等于待商户签署 | 
|                 if(!Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|                     throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前非商户用户可签署流程"); | 
|                 } | 
|             } | 
|         }else{ | 
|             signatory = Constants.ONE; | 
|             //企业用户判断 | 
|             if(!(Constants.equalsInteger(contract.getCompanyId(),user.getCompanyId()) && Constants.equalsInteger(contract.getStatus(),Constants.ONE) )){ | 
|                 throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前非企业用户可签署流程"); | 
|             } | 
|         } | 
|   | 
|         Constants.ApplyLogType applyLogType = null; | 
|         String info = ""; | 
|   | 
|         Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() | 
|                 .eq(Multifile::getObjId,contract.getId()) | 
|                 .eq(Multifile::getObjType,Constants.MultiFile.CONTRACT_PDF.getKey()) | 
|                 .eq(Multifile::getIsdeleted,Constants.ZERO).last("limit 1")); | 
|         if(f == null || StringUtils.isBlank(f.getFileurl())){ | 
|             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取待签章文件失败,请联系确认签署文件是否正确!"); | 
|         } | 
|         String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode(); | 
|         if(Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|             url = url + systemDictDataBiz.queryByCode(Constants.OSS,Constants.CONTRACT).getCode() + f.getFileurl(); | 
|         }else{ | 
|             url = url + systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode() + contract.getFileSignUrl(); | 
|         } | 
|   | 
|         String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode(); | 
|   | 
|         String companyName = ""; | 
|         String creditCode = ""; | 
|         String email = ""; | 
|         //平台签署 | 
|         if(!Constants.equalsInteger(contract.getSignType(),Constants.TWO) && Constants.equalsInteger(contract.getStatus(),Constants.ZERO)){ | 
|             companyName = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLAT_COMPANY_NAME).getCode(); | 
|             creditCode = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLAT_CREDIT_CODE).getCode(); | 
|             email = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLAT_EMAIL).getCode(); | 
|         }else if((Constants.equalsInteger(contract.getSignType(),Constants.ZERO)  && Constants.equalsInteger(contract.getStatus(),Constants.ONE))|| | 
|                 Constants.equalsInteger(contract.getSignType(),Constants.TWO)  && Constants.equalsInteger(contract.getStatus(),Constants.ZERO) | 
|         )  { | 
|             //商户签署 | 
|             Company shop = null; | 
|             if(Constants.equalsInteger(contract.getStatus(),Constants.ONE)){ | 
|                 shop = companyMapper.selectById(contract.getCompanyId()); | 
|             }else{ | 
|                 shop = companyMapper.selectById(contract.getPartyCompanyId()); | 
|             } | 
|             if(Objects.isNull(shop)){ | 
|                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到商户信息"); | 
|             } | 
|             companyName = shop.getName(); | 
|             creditCode = shop.getCode(); | 
|             email = shop.getEmail(); | 
|         } else { | 
|             companyName = Constants.equalsInteger(contract.getStatus(),Constants.ZERO)?contract.getPartyCompanyName():contract.getCompanyName(); | 
|             creditCode = company.getCode(); | 
|             email = company.getEmail(); | 
|         } | 
|         String applyNo = signService.applySign(contract.getName(),url, | 
|                 companyName | 
|                 ,creditCode,email,null,company.getSignId(),notifyUrl); | 
|         if(StringUtils.isBlank(applyNo) ){ | 
|             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!"); | 
|         } | 
|         String link = signService.signLink(applyNo,companyName,creditCode); | 
|         if(StringUtils.isBlank(link) ){ | 
|             throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!"); | 
|         } | 
|         Contract update= new Contract(); | 
|         update.setId(contract.getId()); | 
|         update.setEditor(user.getId()); | 
|         update.setEditDate(new Date()); | 
|         if(Constants.equalsInteger(signatory,Constants.ZERO)){ | 
|             update.setApplyNo(applyNo); | 
|             update.setSignUserId(user.getId()); | 
|             update.setSignDate(new Date()); | 
|   | 
|             //存储待办信息 | 
|             Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.CONTRACT; | 
|             noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,update.getId())); | 
|             Notices notices = new Notices(noticeObjectType, | 
|                     Constants.equalsInteger(contract.getSignType(),Constants.TWO)?Constants.ONE:Constants.TWO | 
|                     ,contract.getId(), | 
|                     this.getNoticeInfo(contract,company), | 
|                     contract.getCompanyId() | 
|                     ,Constants.NoticeType.ZERO); | 
|             noticesMapper.insert(notices); | 
|   | 
|         }else{ | 
|             update.setDoneApplyNo(applyNo); | 
|             update.setComSignUserId(user.getId()); | 
|             update.setComSignDate(new Date()); | 
|         } | 
|         contractMapper.updateById(update); | 
|         return  link; | 
|     } | 
|   | 
|   | 
| } |