| | |
| | | |
| | | // 2.1 插入商机 |
| | | CrmBusinessDO business = BeanUtils.toBean(createReqVO, CrmBusinessDO.class); |
| | | business.setStatusId(businessStatusService.getBusinessStatusListByTypeId(createReqVO.getStatusTypeId()).get(0).getId()); // 默认状态 |
| | | // 商机状态组为选填:未选择时不设置默认阶段,也不参与「商机状态组」维度的统计 |
| | | if (createReqVO.getStatusTypeId() != null) { |
| | | List<CrmBusinessStatusDO> statusList = businessStatusService.getBusinessStatusListByTypeId(createReqVO.getStatusTypeId()); |
| | | business.setStatusId(CollUtil.isNotEmpty(statusList) ? statusList.get(0).getId() : null); // 默认状态 |
| | | } |
| | | calculateTotalPrice(business, businessProducts); |
| | | businessMapper.insert(business); |
| | | // 2.2 插入商机关联商品 |
| | |
| | | if (product.getItemUnitId() == null) { |
| | | product.setItemUnitId(old.getItemUnitId()); |
| | | } |
| | | } else { |
| | | // 新产品:清除前端生成的临时 ID,让数据库 AUTO_INCREMENT 接管 |
| | | product.setId(null); |
| | | } |
| | | // 优先使用前端传入的 totalPrice,否则通过 businessPrice * count 计算 |
| | | if (o.getTotalPrice() != null) { |
| | |
| | | // 1.3 校验商机状态 |
| | | CrmBusinessStatusDO status = null; |
| | | if (reqVO.getStatusId() != null) { |
| | | // 商机状态组为选填:未设置状态组的商机没有可选阶段,不允许变更「商机阶段」 |
| | | if (business.getStatusTypeId() == null) { |
| | | throw exception(BUSINESS_UPDATE_STATUS_FAIL_NO_STATUS_TYPE, business.getName()); |
| | | } |
| | | status = businessStatusService.validateBusinessStatus(business.getStatusTypeId(), reqVO.getStatusId()); |
| | | } |
| | | // 1.4 校验是不是状态没变更 |
| | |
| | | // 3. 记录操作日志上下文 |
| | | LogRecordContext.putVariable("businessName", business.getName()); |
| | | LogRecordContext.putVariable("oldStatusName", getBusinessStatusName(business.getEndStatus(), |
| | | businessStatusService.getBusinessStatus(business.getStatusId()))); |
| | | business.getStatusId() != null ? businessStatusService.getBusinessStatus(business.getStatusId()) : null)); |
| | | LogRecordContext.putVariable("newStatusName", getBusinessStatusName(reqVO.getEndStatus(), status)); |
| | | } |
| | | |