REQ-3581: 备份
This commit is contained in:
parent
1e04a7e1c7
commit
7c7616f938
@ -40,7 +40,7 @@ public class AssignWeixinAppUrlByOrgRequest implements OrgPerson {
|
||||
private SignUrlType urlType;
|
||||
|
||||
/**
|
||||
* 签署方编号, 可以使用该编号指定动态签署方的信息
|
||||
* 签署方编号, 可以使用该编号指定动态签署方的信息, 或未指定将自动分配
|
||||
* 该编号在创建合同的时候会返回
|
||||
*/
|
||||
private String recipientId;
|
||||
|
||||
@ -12,7 +12,7 @@ public class AssignWeixinAppUrlByOrgResponse {
|
||||
|
||||
/**
|
||||
* 有效期为5分钟.
|
||||
* pc: 扫码地址
|
||||
* pc: 二维码地址
|
||||
* app: 微信小程序地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
@ -16,6 +16,13 @@ public class SignByOrg {
|
||||
|
||||
private final List<OrgRecipientId> recipientIds = new ArrayList<>();
|
||||
|
||||
public Approver getApproverOrThrow(List<Approver> approvers, String recipientId) {
|
||||
return approvers.stream()
|
||||
.filter(a -> a.getEssRecipientId().equals(recipientId))
|
||||
.findFirst()
|
||||
.orElseThrow(InternalError::new);
|
||||
}
|
||||
|
||||
public String assign(List<Approver> approvers, Long ouId, @Nullable String recipientId) {
|
||||
if (recipientId != null) {
|
||||
OrgRecipientId saved = findByRecipientId(recipientId).orElse(null);
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
package cn.axzo.nanopart.ess.server.ess;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.nanopart.ess.api.domain.OrgPerson;
|
||||
import cn.axzo.nanopart.ess.api.domain.contract.Approver;
|
||||
import cn.axzo.nanopart.ess.api.domain.contract.EssApproveDetail;
|
||||
import cn.axzo.nanopart.ess.api.domain.contract.OrgPersonInfo;
|
||||
import cn.axzo.nanopart.ess.api.enums.EssContractState;
|
||||
import cn.axzo.nanopart.ess.api.enums.EssSealType;
|
||||
import cn.axzo.nanopart.ess.api.request.AssignWeixinAppUrlByOrgRequest;
|
||||
import cn.axzo.nanopart.ess.api.request.CreateContractRequest;
|
||||
import cn.axzo.nanopart.ess.api.request.RevokeContractRequest;
|
||||
import cn.axzo.nanopart.ess.api.response.CreateContractResponse;
|
||||
@ -22,7 +21,7 @@ import cn.axzo.nanopart.ess.server.entity.EssOrg;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssPerson;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssSeal;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssSealPerson;
|
||||
import cn.axzo.nanopart.ess.server.entity.domain.AssignedApprovers;
|
||||
import cn.axzo.nanopart.ess.server.entity.domain.ApproverAssignType;
|
||||
import cn.axzo.nanopart.ess.server.ess.domain.JsonObjectAsString;
|
||||
import cn.axzo.nanopart.ess.server.ess.domain.SealPersons;
|
||||
import cn.axzo.nanopart.ess.server.ess.support.EssSupport;
|
||||
@ -33,15 +32,12 @@ import com.tencentcloudapi.essbasic.v20210526.models.ChannelCreateFlowByFilesRes
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@ -164,33 +160,33 @@ public class ContractManager {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String assignContractRecipientId(String essContractId, Long ouId, String essRecipientId) {
|
||||
EssContract contract = essContractDao.find(essContractId, true).orElse(null);
|
||||
BizAssertions.assertNotNull(contract, "合同不存在: {}", essContractId);
|
||||
public String assignRecipientIdByOrg(AssignWeixinAppUrlByOrgRequest request) {
|
||||
EssContract contract = essContractDao.find(request.getEssContractId(), true).orElse(null);
|
||||
BizAssertions.assertNotNull(contract, "找不到合同信息, essContractId={}", request.getEssContractId());
|
||||
//noinspection DataFlowIssue
|
||||
AssignedApprovers assignedApprovers = contract.getAssignedApprovers();
|
||||
String recipientId = assignedApprovers.findRecipientId(ouId).orElse(null);
|
||||
if (recipientId != null) return recipientId;
|
||||
EssPerson contractCreator = getContractCreatorOrThrow(contract);
|
||||
Approver assignedApprover = assignRecipientId(contract, person, essRecipientId);
|
||||
checkApproverSeals(assignedApprover);
|
||||
essClient.assignApprover(contract.getEssContractId(), contractCreator,
|
||||
person, assignedApprover.getEssRecipientId());
|
||||
contract.getAssignedApprovers().add(assignedApprover);
|
||||
BizAssertions.assertTrue(contract.getIsDynamicApprover().isYes(), "合同不支持动态签署");
|
||||
BizAssertions.assertEquals(ApproverAssignType.ORG_WEIXIN_APP, contract.getAssignType(), "签署方式不正确");
|
||||
String assignedRecipientId = contract.getAssignedApprovers()
|
||||
.getSignByOrg()
|
||||
.assign(contract.getApprovers(), request.getOuId(), request.getRecipientId());
|
||||
Approver approver = contract.getAssignedApprovers()
|
||||
.getSignByOrg()
|
||||
.getApproverOrThrow(contract.getApprovers(), assignedRecipientId);
|
||||
checkApproverSeals(request, approver.getSealTypes());
|
||||
essContractDao.updateAssignedApprovers(contract);
|
||||
return assignedRecipientId;
|
||||
}
|
||||
|
||||
void checkApproverSeals(Approver approver) {
|
||||
List<EssSealType> sealTypes = approver.getSealTypes();
|
||||
public void checkApproverSeals(OrgPerson person, List<EssSealType> sealTypes) {
|
||||
if (CollectionUtils.isEmpty(sealTypes))
|
||||
sealTypes = Arrays.stream(EssSealType.values()).collect(toList());
|
||||
List<EssSeal> seals = essSealDao
|
||||
.getByOrgAndSealTypes(approver.getOuId(), sealTypes);
|
||||
.getByOrgAndSealTypes(person.getOuId(), sealTypes);
|
||||
BizAssertions.assertNotEmpty(seals, "单位没有指定类型的印章");
|
||||
boolean found = false;
|
||||
for (EssSeal seal : seals) {
|
||||
EssSealPerson sealPerson = essSealPersonDao
|
||||
.findBySealAndPersonId(seal.getEssSealId(), approver.getPersonId())
|
||||
.findBySealAndPersonId(seal.getEssSealId(), person.getPersonId())
|
||||
.orElse(null);
|
||||
found = sealPerson != null;
|
||||
if (found)
|
||||
@ -199,46 +195,6 @@ public class ContractManager {
|
||||
BizAssertions.assertTrue(found, "签署人员没有指定类型的印章");
|
||||
}
|
||||
|
||||
private Approver assignRecipientId(EssContract contract, OrgPerson person, String essRecipientId) {
|
||||
contract.getAssignedApprovers().isRecipientIdUsed(essRecipientId);
|
||||
Function<String, Boolean> isRecipientIdUsed = recipientId ->
|
||||
contract.getAssignedApprovers().stream()
|
||||
.map(Approver::getEssRecipientId)
|
||||
.anyMatch(approver -> approver.equals(recipientId));
|
||||
Supplier<Integer> findFree = () -> {
|
||||
for (int i = 0; i < contract.preciseApproverSize(); i++) {
|
||||
String recipientId = contract.getPreciseApprover(i).getEssRecipientId();
|
||||
if (!isRecipientIdUsed.apply(recipientId))
|
||||
return i;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Supplier<Integer> findIdx = () -> {
|
||||
for (int i = 0; i < contract.preciseApproverSize(); i++) {
|
||||
if (contract.getPreciseApprover(i).getEssRecipientId().equals(essRecipientId))
|
||||
return i;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Integer idx;
|
||||
if (StringUtils.isNotBlank(essRecipientId)) {
|
||||
BizAssertions.assertFalse(isRecipientIdUsed.apply(essRecipientId), "签署方编号已经被使用");
|
||||
idx = findIdx.get();
|
||||
BizAssertions.assertNotNull(idx, "找不到指定的签署方编号");
|
||||
} else {
|
||||
idx = findFree.get();
|
||||
BizAssertions.assertNotNull(idx, "合同签署人员已满, 无法再指定新的签署人");
|
||||
}
|
||||
Approver approver = contract.getPreciseApprover(idx);
|
||||
Approver assignedApprover = BeanMapper.copyBean(approver, Approver.class);
|
||||
assignedApprover.setEssRecipientId(approver.getEssRecipientId());
|
||||
OrgPersonInfo signPerson = new OrgPersonInfo();
|
||||
signPerson.setOuId(person.getOuId());
|
||||
signPerson.setPersonId(person.getPersonId());
|
||||
assignedApprover.setSignPerson(signPerson);
|
||||
return assignedApprover;
|
||||
}
|
||||
|
||||
public EssPerson getContractCreatorOrThrow(EssContract contract) {
|
||||
EssPerson creator = essPersonDao.findOrNull(contract.getCreatorOuId(), contract.getCreatorPersonId());
|
||||
BizAssertions.assertNotNull(creator, "找不到合同发起人信息");
|
||||
|
||||
@ -16,7 +16,6 @@ import cn.axzo.nanopart.ess.server.entity.EssContract;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssPerson;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssSeal;
|
||||
import cn.axzo.nanopart.ess.server.entity.EssSealPerson;
|
||||
import cn.axzo.nanopart.ess.server.entity.domain.ApproverAssignType;
|
||||
import cn.axzo.nanopart.ess.server.ess.domain.OrgAndPerson;
|
||||
import cn.axzo.nanopart.ess.server.ess.domain.SealAndPerson;
|
||||
import cn.axzo.nanopart.ess.server.ess.support.EssProps;
|
||||
@ -106,18 +105,7 @@ public class EssService {
|
||||
public String assignWeixinAppUrlByOrg(AssignWeixinAppUrlByOrgRequest request) {
|
||||
EssPerson signPerson = essPersonDao.findOrNull(request);
|
||||
BizAssertions.assertNotNull(signPerson, "当前签署人员未加入单位, 无法签署");
|
||||
String recipientId = transactionTemplate.execute(unused -> {
|
||||
EssContract contract = essContractDao.find(request.getEssContractId(), true).orElse(null);
|
||||
BizAssertions.assertNotNull(contract, "找不到合同信息, essContractId={}", request.getEssContractId());
|
||||
//noinspection DataFlowIssue
|
||||
BizAssertions.assertTrue(contract.getIsDynamicApprover().isYes(), "合同不支持动态签署");
|
||||
BizAssertions.assertEquals(ApproverAssignType.ORG_WEIXIN_APP, contract.getAssignType(), "签署方式不正确");
|
||||
String assignedRecipientId = contract.getAssignedApprovers()
|
||||
.getSignByOrg()
|
||||
.assign(contract.getApprovers(), request.getOuId(), request.getRecipientId());
|
||||
essContractDao.updateAssignedApprovers(contract);
|
||||
return assignedRecipientId;
|
||||
});
|
||||
String recipientId = contractManager.assignRecipientIdByOrg(request);
|
||||
CreateSignUrlsResponse essResponse = essClient
|
||||
.getContractSignUrlWeixinApp(request.getEssContractId(), signPerson, recipientId);
|
||||
SignUrlInfo signUrlInfo = essResponse.getSignUrlInfos()[0];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user