|
|
@@ -0,0 +1,278 @@
|
|
|
+package com.jzg.organization.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.core.base.BaseController;
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.dto.PtlAgreementDispatch;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.dto.PtlAgreementDispatchAction;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.dto.PtlAgreementDispatchAfterAction;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.dto.PtlAgreementDispatchRulesAttrLink;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.vo.PtlAgreementDispatchQuery;
|
|
|
+import com.jzg.commons.entity.agreement.dispatch.vo.PtlAgreementDispatchVo;
|
|
|
+import com.jzg.commons.entity.agreement.po.PtlAgreementAttribution;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesAttr;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesDictLabal;
|
|
|
+import com.jzg.commons.entity.po.SysDict;
|
|
|
+import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
+import com.jzg.organization.client.EsmInsCompanyClient;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementDispatchActionMapper;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementDispatchAfterActionMapper;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementDispatchMapper;
|
|
|
+import com.jzg.organization.mapper.PtlAgreementDispatchRulesAttrLinkMapper;
|
|
|
+import com.jzg.organization.service.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+* @author dongxin
|
|
|
+* @description 针对表【ptl_agreement_dept(协议授权部门表)】的数据库操作Service实现
|
|
|
+* @createDate 2025-02-18 17:58:58
|
|
|
+*/
|
|
|
+@Service
|
|
|
+public class PtlAgreementDispatchServiceImpl extends ServiceImpl<PtlAgreementDispatchMapper, PtlAgreementDispatch>
|
|
|
+ implements PtlAgreementDispatchService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementDispatchRulesAttrLinkMapper rulesAttrLinkMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementDispatchActionMapper actionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementUndwrtRulesAttrService ptlAgreementUndwrtRulesAttrService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementUndwrtRulesDictLabalService ptlAgreementUndwrtRulesDictLabalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SysDictService sysDictService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementService ptlAgreementService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EsmInsCompanyClient esmInsCompanyClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PtlAgreementDispatchAfterActionMapper afterActionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BaseController baseController;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public String addAgreementDispatch(PtlAgreementDispatchVo.DispatchVo ptlAgreementDispatchVo) {
|
|
|
+ PtlAgreementDispatch dispatch = new PtlAgreementDispatch(ptlAgreementDispatchVo);
|
|
|
+ baseMapper.insert(dispatch);
|
|
|
+
|
|
|
+ for (PtlAgreementDispatchRulesAttrLink link : ptlAgreementDispatchVo.getAttrLinks()){
|
|
|
+ link.setDispatchId(dispatch.getId());
|
|
|
+ }
|
|
|
+ rulesAttrLinkMapper.insert(ptlAgreementDispatchVo.getAttrLinks());
|
|
|
+
|
|
|
+ for (PtlAgreementDispatchAction action : ptlAgreementDispatchVo.getActions()){
|
|
|
+ action.setId(IdGenerate.nextId());
|
|
|
+ action.setDispatchId(dispatch.getId());
|
|
|
+ }
|
|
|
+ actionMapper.insert(ptlAgreementDispatchVo.getActions());
|
|
|
+
|
|
|
+ return dispatch.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addAgreementDispatchAction(List<PtlAgreementDispatchAfterAction> ptlAgreementDispatchVo) {
|
|
|
+ for (PtlAgreementDispatchAfterAction action : ptlAgreementDispatchVo){
|
|
|
+ action.setId(IdGenerate.nextId());
|
|
|
+ }
|
|
|
+ afterActionMapper.insert(ptlAgreementDispatchVo);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean updateAgreementDispatch(PtlAgreementDispatchVo.DispatchVo ptlAgreementDispatchVo) {
|
|
|
+ this.deleteAgreementDispatch(ptlAgreementDispatchVo.getDispatchId());
|
|
|
+ this.addAgreementDispatch(ptlAgreementDispatchVo);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean deleteAgreementDispatch(String dispatchId) {
|
|
|
+ baseMapper.deleteById(dispatchId);
|
|
|
+ rulesAttrLinkMapper.delete(new LambdaQueryWrapper<PtlAgreementDispatchRulesAttrLink>()
|
|
|
+ .eq(PtlAgreementDispatchRulesAttrLink::getDispatchId,dispatchId));
|
|
|
+ actionMapper.delete(new LambdaQueryWrapper<PtlAgreementDispatchAction>()
|
|
|
+ .eq(PtlAgreementDispatchAction::getDispatchId,dispatchId));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PtlAgreementDispatchVo getAgreementDispatch(PtlAgreementDispatchQuery ptlAgreementDispatchQuery) {
|
|
|
+ List<PtlAgreementDispatch> ptlAgreementDispatches = baseMapper.selectList(new LambdaQueryWrapper<PtlAgreementDispatch>()
|
|
|
+ .eq(PtlAgreementDispatch::getCompanyId, ptlAgreementDispatchQuery.getCompanyId()));
|
|
|
+ PtlAgreementDispatchVo dispatchVos = new PtlAgreementDispatchVo();
|
|
|
+ List<String> dispatchIds = ptlAgreementDispatches.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
+ if (dispatchIds.size() > 0) {
|
|
|
+ List<SysDict> dispatchBeforeActionDict = sysDictService.getByTypeCode("dispatch_before_action");
|
|
|
+ List<SysDict> dispatchAfterActionDict = sysDictService.getByTypeCode("dispatch_after_action");
|
|
|
+
|
|
|
+ // 查询保司所有的规则属性 然后进行分组
|
|
|
+ List<PtlAgreementDispatchRulesAttrLink> ptlAgreementDispatchRulesAttrLinks = rulesAttrLinkMapper.selectList(new LambdaQueryWrapper<PtlAgreementDispatchRulesAttrLink>()
|
|
|
+ .in(PtlAgreementDispatchRulesAttrLink::getDispatchId, dispatchIds));
|
|
|
+
|
|
|
+ // 获取所有保司的动作
|
|
|
+ List<PtlAgreementDispatchAction> ptlAgreementDispatchActions = actionMapper.getActions(dispatchIds);
|
|
|
+
|
|
|
+ // 获取保司的报价失败之后的动作
|
|
|
+ List<PtlAgreementDispatchAfterAction> ptlAgreementDispatchAfterActions = afterActionMapper.getAfterActions(ptlAgreementDispatchQuery.getCompanyId());
|
|
|
+ int index = 1;
|
|
|
+ for(PtlAgreementDispatch dispatch : ptlAgreementDispatches){
|
|
|
+ if(dispatch.getDispatchName().equals("")){
|
|
|
+ dispatch.setDispatchName("规则" + index);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ List<PtlAgreementDispatchRulesAttrLink> attrLinks = ptlAgreementDispatchRulesAttrLinks.stream().filter(x -> x.getDispatchId().equals(dispatch.getId())).collect(Collectors.toList());
|
|
|
+ List<PtlAgreementDispatchAction> actions = ptlAgreementDispatchActions.stream().filter(x -> x.getDispatchId().equals(dispatch.getId())).collect(Collectors.toList());
|
|
|
+ for(PtlAgreementDispatchRulesAttrLink attrlink : attrLinks){
|
|
|
+ if (attrlink.getOperator() != null) {
|
|
|
+ if (attrlink.getOperator().equals("1")) {
|
|
|
+ attrlink.setOperatorDesc("包含");
|
|
|
+ }
|
|
|
+ if (attrlink.getOperator().equals("2")) {
|
|
|
+ attrlink.setOperatorDesc("小于");
|
|
|
+ }
|
|
|
+ if (attrlink.getOperator().equals("3")) {
|
|
|
+ attrlink.setOperatorDesc("小于等于");
|
|
|
+ }
|
|
|
+ if (attrlink.getOperator().equals("4")) {
|
|
|
+ attrlink.setOperatorDesc("大于");
|
|
|
+ }
|
|
|
+ if (attrlink.getOperator().equals("5")) {
|
|
|
+ attrlink.setOperatorDesc("大于等于");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ attrlink.setOperatorDesc("未知");
|
|
|
+ }
|
|
|
+ PtlAgreementUndwrtRulesAttr undwrtRuleAttrByAttrCode = ptlAgreementUndwrtRulesAttrService.getUndwrtRuleAttrByAttrCode(attrlink.getAttrCode());
|
|
|
+ if(undwrtRuleAttrByAttrCode != null && undwrtRuleAttrByAttrCode.getDictId() != null){
|
|
|
+ attrlink.setAttrCodeName(undwrtRuleAttrByAttrCode.getAttrName());
|
|
|
+ List<PtlAgreementUndwrtRulesDictLabal> dictLabelsByTypeCode = ptlAgreementUndwrtRulesDictLabalService.getDictLabelsByTypeCode(undwrtRuleAttrByAttrCode.getDictId());
|
|
|
+ PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = dictLabelsByTypeCode.stream().filter(x -> x.getCode().equals(attrlink.getMin())).findFirst().orElse(null);
|
|
|
+ if(ptlAgreementUndwrtRulesDictLabal != null){
|
|
|
+ if(attrlink.getAttrDesc() == null){
|
|
|
+ attrlink.setAttrDesc(new ArrayList<>());
|
|
|
+ }
|
|
|
+ attrlink.getAttrDesc().add(ptlAgreementUndwrtRulesDictLabal.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(PtlAgreementDispatchAction action : actions){
|
|
|
+ SysDict sysDict = dispatchBeforeActionDict.stream().filter(x -> x.getValue().equals(action.getActionCode())).findFirst().orElse(null);
|
|
|
+ if(sysDict == null){
|
|
|
+ action.setActionName("未知动作");
|
|
|
+ }else{
|
|
|
+ action.setActionName(sysDict.getLabel());
|
|
|
+ if("specify_agreement".equals(action.getActionCode())){
|
|
|
+ if(action.getActionJson() != null) {
|
|
|
+ PtlAgreement byId = ptlAgreementService.getById(action.getActionJson().get("agreementId").toString());
|
|
|
+ if(byId != null) {
|
|
|
+ action.getActionJson().put("agreementName", byId.getAgreementName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if("change_bs_account".equals(action.getActionCode())){
|
|
|
+ HttpResult<PtlAgreementAttribution> agreementAttribution = esmInsCompanyClient.getAgreementAttribution(action.getActionJson().get("accountId").toString(), baseController.getToken(), baseController.getUserSystemCode());
|
|
|
+ if(agreementAttribution.getCode() == 200){
|
|
|
+ PtlAgreementAttribution data = agreementAttribution.getData();
|
|
|
+ action.getActionJson().put("userName",data.getUsername());
|
|
|
+ action.getActionJson().put("companyName",data.getInsCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PtlAgreementDispatchVo.DispatchVo vo = new PtlAgreementDispatchVo.DispatchVo(dispatch,attrLinks,actions);
|
|
|
+ dispatchVos.getDispatchVos().add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(PtlAgreementDispatchAfterAction afterAction : ptlAgreementDispatchAfterActions){
|
|
|
+ SysDict sysDict = dispatchBeforeActionDict.stream().filter(x -> x.getValue().equals(afterAction.getActionCode())).findFirst().orElse(null);
|
|
|
+ if(sysDict == null){
|
|
|
+ afterAction.setActionName("未知动作");
|
|
|
+ }else{
|
|
|
+ afterAction.setActionName(sysDict.getLabel());
|
|
|
+ if("specify_agreement".equals(afterAction.getActionCode())){
|
|
|
+ if(afterAction.getActionJson() != null) {
|
|
|
+ PtlAgreement byId = ptlAgreementService.getById(afterAction.getActionJson().get("agreementId").toString());
|
|
|
+ if(byId != null) {
|
|
|
+ afterAction.getActionJson().put("agreementName", byId.getAgreementName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if("change_bs_account".equals(afterAction.getActionCode())){
|
|
|
+ HttpResult<PtlAgreementAttribution> agreementAttribution = esmInsCompanyClient.getAgreementAttribution(afterAction.getActionJson().get("accountId").toString(), baseController.getToken(), baseController.getUserSystemCode());
|
|
|
+ if(agreementAttribution.getCode() == 200){
|
|
|
+ PtlAgreementAttribution data = agreementAttribution.getData();
|
|
|
+ afterAction.getActionJson().put("userName",data.getUsername());
|
|
|
+ afterAction.getActionJson().put("companyName",data.getInsCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dispatchVos.setAfterActions(ptlAgreementDispatchAfterActions);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return dispatchVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PtlAgreementDispatchVo.DispatchVo> getAgreementDispatchAction(List<String> dispatchIds) {
|
|
|
+ List<PtlAgreementDispatchVo.DispatchVo> dispatchVos = new ArrayList<>();
|
|
|
+
|
|
|
+ if (!dispatchIds.isEmpty()) {
|
|
|
+ List<PtlAgreementDispatchAction> ptlAgreementDispatchActions = actionMapper.selectList(new LambdaQueryWrapper<PtlAgreementDispatchAction>()
|
|
|
+ .in(PtlAgreementDispatchAction::getDispatchId, dispatchIds));
|
|
|
+
|
|
|
+ // 进行分组
|
|
|
+ Map<String, List<PtlAgreementDispatchAction>> groupedByDispatchId = ptlAgreementDispatchActions.stream()
|
|
|
+ .collect(Collectors.groupingBy(PtlAgreementDispatchAction::getDispatchId));
|
|
|
+
|
|
|
+ // 遍历示例
|
|
|
+ groupedByDispatchId.forEach((dispatchId, actions) -> {
|
|
|
+ PtlAgreementDispatch byId = this.getById(dispatchId);
|
|
|
+ PtlAgreementDispatchVo.DispatchVo vo = new PtlAgreementDispatchVo.DispatchVo();
|
|
|
+ vo.setDispatchId(dispatchId);
|
|
|
+ vo.setCompanyId(byId.getCompanyId());
|
|
|
+ vo.setActions(actions);
|
|
|
+ dispatchVos.add(vo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return dispatchVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateDispatchName(String dispatchId, String name) {
|
|
|
+ PtlAgreementDispatch dispatch = baseMapper.selectById(dispatchId);
|
|
|
+ if(dispatch != null) {
|
|
|
+ dispatch.setDispatchName(name);
|
|
|
+ baseMapper.updateById(dispatch);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|