|  |  |  | 
|---|
|  |  |  | 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.model.Contract; | 
|---|
|  |  |  | 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实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | contractMapper.deleteById(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 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Contract findById(Integer id) { | 
|---|
|  |  |  | return contractMapper.selectById(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 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PageData<Contract> findPage(PageWrap<Contract> pageWrap) { | 
|---|
|  |  |  | IPage<Contract> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<Contract> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | MPJLambdaWrapper<Contract> queryWrapper = new MPJLambdaWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | 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 (pageWrap.getModel().getCreator() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getCreator, pageWrap.getModel().getCreator()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCreateDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditor() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getEditor, pageWrap.getModel().getEditor()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEditDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getIsdeleted() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getRemark() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getRemark, pageWrap.getModel().getRemark()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getName() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getName, pageWrap.getModel().getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCompanyId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getCompanyId, pageWrap.getModel().getCompanyId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getContent() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getContent, pageWrap.getModel().getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStatus() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getStatus, pageWrap.getModel().getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getComSignUserId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getComSignUserId, pageWrap.getModel().getComSignUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getComSignDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getComSignDate, Utils.Date.getStart(pageWrap.getModel().getComSignDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getComSignDate, Utils.Date.getEnd(pageWrap.getModel().getComSignDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getComSignInfo() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getComSignInfo, pageWrap.getModel().getComSignInfo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getType() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getType, pageWrap.getModel().getType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSignUserId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getSignUserId, pageWrap.getModel().getSignUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSignDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getSignDate, Utils.Date.getStart(pageWrap.getModel().getSignDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getSignDate, Utils.Date.getEnd(pageWrap.getModel().getSignDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getSignInfo() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getSignInfo, pageWrap.getModel().getSignInfo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getFileUrl() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getFileUrl, pageWrap.getModel().getFileUrl()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getFileSignUrl() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getFileSignUrl, pageWrap.getModel().getFileSignUrl()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDoneFileUrl() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getDoneFileUrl, pageWrap.getModel().getDoneFileUrl()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getAppyno() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getAppyno, pageWrap.getModel().getAppyno()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getDoneApplyno() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getDoneApplyno, pageWrap.getModel().getDoneApplyno()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getStartTime() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getStartTime, Utils.Date.getStart(pageWrap.getModel().getStartTime())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getStartTime, Utils.Date.getEnd(pageWrap.getModel().getStartTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getEndTime() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getEndTime, Utils.Date.getStart(pageWrap.getModel().getEndTime())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getEndTime, Utils.Date.getEnd(pageWrap.getModel().getEndTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCancelDate() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().ge(Contract::getCancelDate, Utils.Date.getStart(pageWrap.getModel().getCancelDate())); | 
|---|
|  |  |  | queryWrapper.lambda().le(Contract::getCancelDate, Utils.Date.getEnd(pageWrap.getModel().getCancelDate())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCancelUserId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getCancelUserId, pageWrap.getModel().getCancelUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pageWrap.getModel().getCancelInfo() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(Contract::getCancelInfo, pageWrap.getModel().getCancelInfo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(sortData.getProperty()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(contractMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|