Commit 418472db39b1ec99d471bd305b51098d0c368285

Authored by 房远帅
1 parent d35da974

报价:业务员报价-审核流程

... ... @@ -22,6 +22,7 @@ import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerC
22 22 import com.lframework.xingyun.sc.procurement.entity.ProcurementForeignTradeCredit;
23 23 import com.lframework.xingyun.sc.procurement.service.credit.ProcurementDomesticCustomerCreditService;
24 24 import com.lframework.xingyun.sc.procurement.service.credit.ProcurementForeignTradeCreditService;
  25 +import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService;
25 26 import com.lframework.xingyun.sc.service.contract.ContractDistributorLineService;
26 27 import com.lframework.xingyun.sc.service.contract.ContractChangeApplicationService;
27 28 import com.lframework.xingyun.sc.service.contract.ContractDistributorStandardService;
... ... @@ -154,6 +155,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
154 155 private ProcurementDomesticCustomerCreditService procurementDomesticCustomerCreditService;
155 156 @Resource
156 157 private ProcurementForeignTradeCreditService procurementForeignTradeCreditService;
  158 + @Resource
  159 + private SalesmanQuotationService salesmanQuotationService;
157 160
158 161
159 162
... ... @@ -241,6 +244,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
241 244 case "IN_CHANGE_REVIEW":
242 245 handleResultDomesticCustomerCreditChangeReviewData(flowStatus, businessId);
243 246 break;
  247 + case "SALESMAN_QUOTATION":
  248 + handleSalesmanQuotationData(flowStatus, businessId);
  249 + break;
244 250 default:
245 251 break;
246 252 }
... ... @@ -1100,4 +1106,21 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1100 1106 }
1101 1107 }
1102 1108 }
  1109 +
  1110 + /**
  1111 + * 业务员报价审核业务数据处理
  1112 + *
  1113 + * @param flowStatus 审核结果
  1114 + * @param businessId 业务ID
  1115 + */
  1116 + private void handleSalesmanQuotationData(String flowStatus, String businessId) {
  1117 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1118 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1119 + salesmanQuotationService.updateApprovalStatus(businessId, "PASS");
  1120 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1121 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1122 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1123 + salesmanQuotationService.updateApprovalStatus(businessId, "REFUSE");
  1124 + }
  1125 + }
1103 1126 }
... ...
... ... @@ -81,7 +81,8 @@ public class SalesmanQuotationController extends DefaultBaseController {
81 81 * @return 详情
82 82 */
83 83 @ApiOperation("详情")
84   - @HasPermission({"procure-manage:sales-price:query"})
  84 + @HasPermission({"procure-manage:sales-price:query", "procure-manage:sales-price:review",
  85 + "procure-manage:sales-price:approve"})
85 86 @ApiImplicitParam(value = "id", name = "id", paramType = "query", required = true)
86 87 @GetMapping("")
87 88 public InvokeResult<SalesmanQuotation> get(@NotBlank(message = "id不能为空!") String id) {
... ...
... ... @@ -237,6 +237,24 @@ public class SalesmanQuotation extends BaseEntity implements BaseDto {
237 237 private String status;
238 238
239 239 /**
  240 + * 是否展示审核按钮(非持久化字段)
  241 + */
  242 + @TableField(exist = false)
  243 + private Boolean showExamine = false;
  244 +
  245 + /**
  246 + * 是否展示审核详情按钮(非持久化字段)
  247 + */
  248 + @TableField(exist = false)
  249 + private Boolean showExamineDetail;
  250 +
  251 + /**
  252 + * 角色code(非持久化字段)
  253 + */
  254 + @TableField(exist = false)
  255 + private String roleCode;
  256 +
  257 + /**
240 258 * 报价明细列表
241 259 */
242 260 @TableField(exist = false)
... ...
... ... @@ -4,6 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
4 4 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
5 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6 6 import com.github.pagehelper.PageInfo;
  7 +import com.lframework.starter.bpm.dto.FlowTaskDto;
  8 +import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
  9 +import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
  10 +import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
  11 +import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
7 12 import com.lframework.starter.common.exceptions.impl.DefaultClientException;
8 13 import com.lframework.starter.common.utils.Assert;
9 14 import com.lframework.starter.common.utils.CollectionUtil;
... ... @@ -17,7 +22,9 @@ import com.lframework.starter.web.core.utils.OpLogUtil;
17 22 import com.lframework.starter.web.core.utils.PageHelperUtil;
18 23 import com.lframework.starter.web.core.utils.PageResultUtil;
19 24 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  25 +import com.lframework.starter.web.inner.entity.SysRole;
20 26 import com.lframework.starter.web.inner.entity.SysUser;
  27 +import com.lframework.starter.web.inner.service.system.SysRoleService;
21 28 import com.lframework.starter.web.inner.service.system.SysUserService;
22 29 import com.lframework.xingyun.basedata.entity.BreedRelationship;
23 30 import com.lframework.xingyun.basedata.service.breed.BreedRelationshipService;
... ... @@ -43,8 +50,11 @@ import java.time.LocalDateTime;
43 50 import java.time.format.DateTimeFormatter;
44 51 import java.util.ArrayList;
45 52 import java.util.Collections;
  53 +import java.util.HashSet;
46 54 import java.util.List;
47 55 import java.util.Map;
  56 +import java.util.Objects;
  57 +import java.util.Set;
48 58 import java.util.stream.Collectors;
49 59 import org.apache.commons.lang3.StringUtils;
50 60 import org.springframework.stereotype.Service;
... ... @@ -58,14 +68,26 @@ import javax.annotation.Resource;
58 68 public class SalesmanQuotationServiceImpl
59 69 extends BaseMpServiceImpl<SalesmanQuotationMapper, SalesmanQuotation>
60 70 implements SalesmanQuotationService {
  71 +
  72 + /**
  73 + * 流程标识
  74 + */
  75 + private static final String BPM_FLAG = "SALESMAN_QUOTATION";
  76 +
61 77 @Resource
62 78 private SysUserService sysUserService;
63 79 @Resource
  80 + private FlowInstanceWrapperService flowInstanceWrapperService;
  81 + @Resource
  82 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  83 + @Resource
64 84 private ProcurementDomesticCustomerCreditService procurementDomesticCustomerCreditService;
65 85 @Resource
66 86 private BreedRelationshipService breedRelationshipService;
67 87 @Resource
68 88 private SalesmanQuotationLineService salesmanQuotationLineService;
  89 + @Resource
  90 + private SysRoleService sysRoleService;
69 91
70 92 /**
71 93 * 编号前缀
... ... @@ -97,6 +119,7 @@ public class SalesmanQuotationServiceImpl
97 119
98 120 PageHelperUtil.startPage(pageIndex, pageSize);
99 121 List<SalesmanQuotation> datas = this.query(vo);
  122 + fillShowExamineInfo(datas);
100 123 return PageResultUtil.convert(new PageInfo<>(datas));
101 124 }
102 125
... ... @@ -127,6 +150,7 @@ public class SalesmanQuotationServiceImpl
127 150 QuerySalesmanQuotationLineVo lineQueryVo = new QuerySalesmanQuotationLineVo();
128 151 lineQueryVo.setQuotationId(id);
129 152 data.setQuotationLineList(salesmanQuotationLineService.query(lineQueryVo));
  153 + fillShowExamineInfo(Collections.singletonList(data));
130 154
131 155 return data;
132 156 }
... ... @@ -153,6 +177,33 @@ public class SalesmanQuotationServiceImpl
153 177 getBaseMapper().insert(data);
154 178
155 179 saveCreateLines(data.getId(), vo.getQuotationLineList(), quotationBreedMap, vo.getPriced());
  180 + SalesmanQuotation salesmanQuotation = getBaseMapper().findById(data.getId());
  181 + List<SysRole> sysRoleList = sysRoleService.getByUserId(SecurityUtil.getCurrentUser().getId());
  182 + String roleCode = null;
  183 + if (CollectionUtil.isNotEmpty(sysRoleList)) {
  184 + // 1. 提取角色列表中的所有 code,转换为 Set 集合,提升后续判断效率
  185 + Set<String> roleCodeSet = sysRoleList.stream()
  186 + .map(SysRole::getCode)
  187 + .collect(Collectors.toSet());
  188 +
  189 + // 2. 判断是否包含采购主管相关的角色
  190 + if (roleCodeSet.contains("htcgeczg") || roleCodeSet.contains("htcgyczg")
  191 + || roleCodeSet.contains("ltcgczg") || roleCodeSet.contains("ztcgczg")) {
  192 + roleCode = "cgczg";
  193 + } else if (roleCodeSet.contains("qyjl")) {
  194 + // 3. 如果没有,继续判断是否包含区域经理
  195 + roleCode = "qyjl";
  196 + } else if (roleCodeSet.contains("nmcgkywy")) {
  197 + // 4. 如果还没有,继续判断是否包含内贸采购科业务员
  198 + roleCode = "nmcgkywy";
  199 + } else {
  200 + throw new DefaultClientException("当前角色无法发起报价!");
  201 + }
  202 + } else {
  203 + throw new DefaultClientException("当前角色无法发起报价!");
  204 + }
  205 + salesmanQuotation.setRoleCode(roleCode);
  206 + flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, salesmanQuotation);
156 207
157 208 OpLogUtil.setVariable("id", data.getId());
158 209 OpLogUtil.setExtra(vo);
... ... @@ -183,6 +234,33 @@ public class SalesmanQuotationServiceImpl
183 234 getBaseMapper().updateById(data);
184 235
185 236 saveOrUpdateLines(data.getId(), vo.getQuotationLineList(), quotationBreedMap, vo.getPriced());
  237 + SalesmanQuotation salesmanQuotation = getBaseMapper().findById(data.getId());
  238 + List<SysRole> sysRoleList = sysRoleService.getByUserId(SecurityUtil.getCurrentUser().getId());
  239 + String roleCode = null;
  240 + if (CollectionUtil.isNotEmpty(sysRoleList)) {
  241 + // 1. 提取角色列表中的所有 code,转换为 Set 集合,提升后续判断效率
  242 + Set<String> roleCodeSet = sysRoleList.stream()
  243 + .map(SysRole::getCode)
  244 + .collect(Collectors.toSet());
  245 +
  246 + // 2. 判断是否包含采购主管相关的角色
  247 + if (roleCodeSet.contains("htcgeczg") || roleCodeSet.contains("htcgyczg")
  248 + || roleCodeSet.contains("ltcgczg") || roleCodeSet.contains("ztcgczg")) {
  249 + roleCode = "cgczg";
  250 + } else if (roleCodeSet.contains("qyjl")) {
  251 + // 3. 如果没有,继续判断是否包含区域经理
  252 + roleCode = "qyjl";
  253 + } else if (roleCodeSet.contains("nmcgkywy")) {
  254 + // 4. 如果还没有,继续判断是否包含内贸采购科业务员
  255 + roleCode = "nmcgkywy";
  256 + } else {
  257 + throw new DefaultClientException("当前角色无法发起报价!");
  258 + }
  259 + } else {
  260 + throw new DefaultClientException("当前角色无法发起报价!");
  261 + }
  262 + salesmanQuotation.setRoleCode(roleCode);
  263 + flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, salesmanQuotation);
186 264
187 265 OpLogUtil.setVariable("id", data.getId());
188 266 OpLogUtil.setExtra(vo);
... ... @@ -209,6 +287,24 @@ public class SalesmanQuotationServiceImpl
209 287 OpLogUtil.setExtra(data);
210 288 }
211 289
  290 + /**
  291 + * 更新审核状态
  292 + *
  293 + * @param id 主键ID
  294 + * @param approvalStatus 审核状态
  295 + */
  296 + @Override
  297 + public void updateApprovalStatus(String id, String approvalStatus) {
  298 + if (StringUtils.isBlank(id) || StringUtils.isBlank(approvalStatus)) {
  299 + throw new DefaultClientException("业务员报价ID、审核状态不能为空!");
  300 + }
  301 +
  302 + Wrapper<SalesmanQuotation> wrapper = Wrappers.lambdaUpdate(SalesmanQuotation.class)
  303 + .set(SalesmanQuotation::getApprovalStatus, approvalStatus)
  304 + .eq(SalesmanQuotation::getId, id);
  305 + getBaseMapper().update(wrapper);
  306 + }
  307 +
212 308
213 309 /**
214 310 * 构建新增实体
... ... @@ -242,6 +338,7 @@ public class SalesmanQuotationServiceImpl
242 338 data.setSupplierId(supplier.getId());
243 339 data.setPurchaseDepartment(supplier.getPurchaseDepartment());
244 340 data.setRegion(supplier.getRegion());
  341 + data.setApprovalStatus(CustomerDevelopStatus.AUDIT.name());
245 342 data.setValidityPeriod(vo.getValidityPeriod());
246 343 data.setLongTermOperation(vo.getLongTermOperation());
247 344 data.setTerminalCustomer(vo.getTerminalCustomer());
... ... @@ -284,6 +381,7 @@ public class SalesmanQuotationServiceImpl
284 381 data.setSupplierId(supplier.getId());
285 382 data.setPurchaseDepartment(supplier.getPurchaseDepartment());
286 383 data.setRegion(supplier.getRegion());
  384 + data.setApprovalStatus(CustomerDevelopStatus.AUDIT.name());
287 385 data.setValidityPeriod(vo.getValidityPeriod());
288 386 data.setLongTermOperation(vo.getLongTermOperation());
289 387 data.setTerminalCustomer(vo.getTerminalCustomer());
... ... @@ -587,6 +685,43 @@ public class SalesmanQuotationServiceImpl
587 685 }
588 686
589 687 /**
  688 + * 回填审核按钮展示信息
  689 + *
  690 + * @param datas 数据列表
  691 + */
  692 + private void fillShowExamineInfo(List<SalesmanQuotation> datas) {
  693 + if (CollectionUtil.isEmpty(datas)) {
  694 + return;
  695 + }
  696 +
  697 + List<SalesmanQuotation> validDatas = datas.stream()
  698 + .filter(Objects::nonNull)
  699 + .collect(Collectors.toList());
  700 + if (CollectionUtil.isEmpty(validDatas)) {
  701 + return;
  702 + }
  703 +
  704 + List<String> businessIds = validDatas.stream().map(SalesmanQuotation::getId).collect(Collectors.toList());
  705 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  706 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  707 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  708 + : new HashSet<>();
  709 +
  710 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  711 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  712 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  713 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  714 + : new HashSet<>();
  715 +
  716 + for (SalesmanQuotation data : validDatas) {
  717 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  718 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  719 + data.setShowExamineDetail(hasFlow && StringUtils.isNotBlank(data.getApprovalStatus()));
  720 + data.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(data.getApprovalStatus()));
  721 + }
  722 + }
  723 +
  724 + /**
590 725 * 清理缓存
591 726 *
592 727 * @param key 缓存键
... ...
... ... @@ -60,6 +60,14 @@ public interface SalesmanQuotationService extends BaseMpService<SalesmanQuotatio
60 60 void cancel(String id);
61 61
62 62 /**
  63 + * 更新审核状态
  64 + *
  65 + * @param id 主键ID
  66 + * @param approvalStatus 审核状态
  67 + */
  68 + void updateApprovalStatus(String id, String approvalStatus);
  69 +
  70 + /**
63 71 * 生成编号
64 72 *
65 73 * @return 编号
... ...