From 7a923e32e55e9c34830690341469cc170f65092e Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 16 十一月 2026 09:32:35 +0800
Subject: [PATCH] feat: 完善销售和投标业务流程
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/bidbond/CrmBidBondServiceImpl.java | 99 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 90 insertions(+), 9 deletions(-)
diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/bidbond/CrmBidBondServiceImpl.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/bidbond/CrmBidBondServiceImpl.java
index 846ec7f..1088a2a 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/bidbond/CrmBidBondServiceImpl.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/bidbond/CrmBidBondServiceImpl.java
@@ -10,9 +10,11 @@
import cn.iocoder.yudao.module.crm.controller.admin.bidbond.vo.CrmBidBondSaleOrderRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.bidbond.vo.CrmBidBondSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.bidbond.CrmBidBondDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.bidbond.CrmBidProgressDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationDO;
import cn.iocoder.yudao.module.crm.dal.mysql.bidbond.CrmBidBondMapper;
+import cn.iocoder.yudao.module.crm.dal.mysql.bidbond.CrmBidProgressMapper;
import cn.iocoder.yudao.module.crm.dal.mysql.quotation.CrmSaleQuotationMapper;
import cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.crm.enums.bidbond.CrmBidBondRefundStatusEnum;
@@ -51,6 +53,8 @@
@Resource
private CrmBidBondMapper bidBondMapper;
@Resource
+ private CrmBidProgressMapper bidProgressMapper;
+ @Resource
private CrmSaleQuotationMapper saleQuotationMapper;
@Resource
private CrmCustomerService customerService;
@@ -60,6 +64,9 @@
@Override
@Transactional(rollbackFor = Exception.class)
public Long createBidBond(CrmBidBondSaveReqVO createReqVO) {
+ if (!CrmBidResultEnum.PENDING.getResult().equals(createReqVO.getBidResult())) {
+ throw new ServiceException(400, "鏂版姇鏍囧繀椤诲厛鐧昏涓哄緟寮�鏍囷紝璇峰湪杩囩▼璺熻繘涓櫥璁扮粨鏋�");
+ }
CrmBidBondDO bond = validateAndBuild(createReqVO);
bond.setId(null);
bond.setNo(generateBondNo());
@@ -68,6 +75,7 @@
if (bond.getQuotationId() != null) {
saleQuotationMapper.bindBidBond(bond.getQuotationId(), bond.getId(), bond.getNo());
}
+ insertProgress(bond, "CREATED", null, CrmBidResultEnum.PENDING.getResult(), null);
return bond.getId();
}
@@ -75,6 +83,13 @@
@Transactional(rollbackFor = Exception.class)
public void updateBidBond(CrmBidBondSaveReqVO updateReqVO) {
CrmBidBondDO oldBond = validateBidBondExists(updateReqVO.getId());
+ if (!Objects.equals(oldBond.getBidResult(), updateReqVO.getBidResult())) {
+ throw new ServiceException(400, "涓爣缁撴灉鍙兘閫氳繃鎶曟爣杩囩▼璺熻繘鐧昏");
+ }
+ if (CrmBidResultEnum.WON.getResult().equals(oldBond.getBidResult())
+ && !Objects.equals(oldBond.getQuotationId(), updateReqVO.getQuotationId())) {
+ throw new ServiceException(400, "宸蹭腑鏍囨姇鏍囦笉鑳芥洿鎹㈡姤浠峰崟");
+ }
CrmBidBondDO updateObj = validateAndBuild(updateReqVO);
updateObj.setId(updateReqVO.getId());
// 鍗曞彿涓嶅厑璁镐慨鏀癸紝淇濇寔鍘熷��
@@ -93,6 +108,10 @@
@Transactional(rollbackFor = Exception.class)
public void deleteBidBond(Long id) {
CrmBidBondDO bond = validateBidBondExists(id);
+ if (!CrmBidResultEnum.PENDING.getResult().equals(bond.getBidResult())
+ || bidProgressMapper.selectByBidBondId(id).size() > 1) {
+ throw new ServiceException(400, "宸叉湁鎶曟爣杩囩▼璁板綍锛屼笉鑳藉垹闄�");
+ }
if (CrmBidResultEnum.WON.getResult().equals(bond.getBidResult()) && bond.getQuotationId() != null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.BID_BOND_DELETE_FAIL_WON);
}
@@ -101,6 +120,72 @@
saleQuotationMapper.bindBidBond(bond.getQuotationId(), null, null);
}
bidBondMapper.deleteById(id);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void recordProgress(Long id, String action, String remark) {
+ CrmBidBondDO bond = bidBondMapper.selectByIdForUpdate(id);
+ if (bond == null) throw new ServiceException(400, "鎶曟爣璁板綍涓嶅瓨鍦�");
+ int from = bond.getBidResult();
+ int target;
+ switch (action) {
+ case "FOLLOW_UP" -> {
+ if (from == CrmBidResultEnum.WON.getResult()) throw new ServiceException(400, "宸蹭腑鏍囨姇鏍囦笉鑳界户缁窡杩涘紑鏍囪繃绋�");
+ target = from;
+ }
+ case "WON" -> {
+ if (from != CrmBidResultEnum.PENDING.getResult()) throw new ServiceException(400, "鍙湁寰呭紑鏍囨姇鏍囧彲浠ョ櫥璁颁腑鏍�");
+ target = CrmBidResultEnum.WON.getResult();
+ }
+ case "LOST" -> {
+ if (from != CrmBidResultEnum.PENDING.getResult()) throw new ServiceException(400, "鍙湁寰呭紑鏍囨姇鏍囧彲浠ョ櫥璁版湭涓爣");
+ target = CrmBidResultEnum.LOST.getResult();
+ }
+ case "REBID" -> {
+ if (from != CrmBidResultEnum.LOST.getResult()) throw new ServiceException(400, "鍙湁鏈腑鏍囨姇鏍囧彲浠ラ噸鏂版姇鏍�");
+ CrmSaleQuotationDO quotation = saleQuotationMapper.selectById(bond.getQuotationId());
+ List<CrmBidProgressDO> history = bidProgressMapper.selectByBidBondId(id);
+ int lastRound = history.stream().filter(e -> "LOST".equals(e.getAction())
+ || ("IMPORTED".equals(e.getAction()) && Objects.equals(e.getToResult(), CrmBidResultEnum.LOST.getResult())))
+ .map(CrmBidProgressDO::getQuotationRound).filter(Objects::nonNull)
+ .max(Integer::compareTo).orElse(0);
+ if (quotation == null || quotation.getRevisionNo() == null || quotation.getRevisionNo() <= lastRound) {
+ throw new ServiceException(400, "璇峰厛瀹屾垚涓嬩竴杞姤浠凤紝鍐嶉噸鏂版姇鏍�");
+ }
+ target = CrmBidResultEnum.PENDING.getResult();
+ }
+ default -> throw new ServiceException(400, "涓嶆敮鎸佺殑鎶曟爣杩囩▼鍔ㄤ綔");
+ }
+ if (remark == null || remark.isBlank()) throw new ServiceException(400, "璇峰~鍐欐湰娆¤窡杩涜鏄�");
+ if (remark.length() > 500) throw new ServiceException(400, "璺熻繘璇存槑涓嶈兘瓒呰繃500瀛�");
+ CrmSaleQuotationDO quotation = saleQuotationMapper.selectById(bond.getQuotationId());
+ bond.setBidResult(target);
+ bond.setQuotationRound(quotation != null ? quotation.getRevisionNo() : bond.getQuotationRound());
+ if (target == CrmBidResultEnum.WON.getResult()) {
+ bond.setRefundStatus(CrmBidBondRefundStatusEnum.NO_NEED.getStatus());
+ bond.setRefundAmount(null);
+ bond.setRefundDate(null);
+ }
+ bidBondMapper.updateByIdIncludingNulls(bond);
+ insertProgress(bond, action, from, target, remark);
+ }
+
+ @Override
+ public List<CrmBidProgressDO> getProgressList(Long id) {
+ validateBidBondExists(id);
+ return bidProgressMapper.selectByBidBondId(id);
+ }
+
+ private void insertProgress(CrmBidBondDO bond, String action, Integer from, Integer to, String remark) {
+ CrmBidProgressDO event = new CrmBidProgressDO();
+ event.setBidBondId(bond.getId());
+ event.setAction(action);
+ event.setFromResult(from);
+ event.setToResult(to);
+ event.setQuotationRound(bond.getQuotationRound());
+ event.setRemark(remark);
+ bidProgressMapper.insert(event);
}
@Override
@@ -194,9 +279,9 @@
"涓爣缁撴灉涓恒�愭湭涓爣銆戞椂涓嶈兘鍏宠仈閿�鍞鍗昜" + order.getNo()
+ "]銆傚宸蹭腑鏍囷紝璇峰厛灏嗕腑鏍囩粨鏋滄敼涓恒�愬凡涓爣銆戯紱濡傜‘鏈腑鏍囷紝璇锋竻绌哄叧鑱旈攢鍞鍗曘��");
}
- // 閫変腑閿�鍞鍗曡鏄庡凡涓爣锛屽緟寮�鏍囨椂鑷姩缃负宸蹭腑鏍�
if (CrmBidResultEnum.PENDING.getResult().equals(bidResult)) {
- bidResult = CrmBidResultEnum.WON.getResult();
+ throw new ServiceException(ErrorCodeConstants.BID_BOND_SALE_ORDER_NOT_APPROVE.getCode(),
+ "寰呭紑鏍囨椂涓嶈兘鍏宠仈閿�鍞鍗曪紝璇峰厛鏄庣‘涓爣缁撴灉銆�");
}
saleOrderNo = order.getNo();
}
@@ -223,14 +308,10 @@
* 鏍¢獙骞跺姞杞藉叧鑱旀姤浠峰崟
*/
private CrmSaleQuotationDO validateQuotation(CrmBidBondSaveReqVO reqVO, Integer bidResult) {
- // 涓爣鏃舵姤浠峰崟蹇呭~锛屼繚璇佷腑鏍囧悗鍙互鎹杞悎鍚�
- if (CrmBidResultEnum.WON.getResult().equals(bidResult) && reqVO.getQuotationId() == null) {
- throw new ServiceException(ErrorCodeConstants.BID_BOND_WON_QUOTATION_REQUIRED.getCode(),
- "涓爣缁撴灉涓恒�愬凡涓爣銆戞椂蹇呴』鍏宠仈鎶ヤ环鍗曪紝鍚﹀垯鏃犳硶鍑鎶ヤ环鍗曡浆鍚堝悓銆�"
- + "璇烽�夋嫨鏈涓爣鐨勯攢鍞姤浠峰崟鍚庨噸鏂颁繚瀛樸��");
- }
+ // 鎶曟爣璁板綍蹇呴』缁戝畾鏈鎶ヤ环锛屽緟寮�鏍囦笌鏈腑鏍囦篃闇�瑕佷繚鐣欐姤浠峰叧鑱斻��
if (reqVO.getQuotationId() == null) {
- return null;
+ throw new ServiceException(ErrorCodeConstants.BID_BOND_WON_QUOTATION_REQUIRED.getCode(),
+ "鎶曟爣璁板綍蹇呴』鍏宠仈鏈閿�鍞姤浠峰崟锛岃閫夋嫨鎶ヤ环鍗曞悗閲嶆柊淇濆瓨銆�");
}
CrmSaleQuotationDO quotation = saleQuotationMapper.selectById(reqVO.getQuotationId());
if (quotation == null) {
--
Gitblit v1.9.3