|
@@ -214,55 +214,62 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
List<EhsdPurchaseArrival> purchaseArrivalList = purchase.getPurchaseArrivalList();
|
|
|
- List<EhsdPurchaseProductMountings> addMountingsList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseProductList)) {
|
|
|
- for (EhsdPurchaseProduct s : purchaseProductList) {//产品
|
|
|
- long id;
|
|
|
- if (ObjectUtils.isNotEmpty(s.getId())) {
|
|
|
- id = s.getId();
|
|
|
- } else {
|
|
|
- id = IdWorker.getId();
|
|
|
- }
|
|
|
- s.setId(id);
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
|
|
|
- purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
|
- addMountingsList.addAll(purchaseProductMountingsList);
|
|
|
- }
|
|
|
|
|
|
- if ("0".equals(purchase.getDataResource())) {
|
|
|
- //计算采购数量是否大于申购数量
|
|
|
- List<EhsdPurchaseProduct> purchaseDetailList1 = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
|
|
|
- s.getSubscribeDetailId()));
|
|
|
- //求和
|
|
|
- BigDecimal purchaseCount = purchaseDetailList1.stream()
|
|
|
- .map(EhsdPurchaseProduct::getQuantity)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- //计算历史采购数量+本次采购数量之和
|
|
|
- BigDecimal count = purchaseCount.add(s.getQuantity());
|
|
|
- //判断采购数量是否大于申购数量
|
|
|
- SubscribeDetail subscribeDetail = subscribeDetailService.getById(s.getSubscribeDetailId());
|
|
|
- if (count.compareTo(subscribeDetail.getCount()) > 0) {
|
|
|
- throw new ServiceException("采购数量不能大于申购数量");
|
|
|
- }
|
|
|
+ //防止空指针
|
|
|
+ purchaseArrivalList = (purchaseArrivalList == null ? new ArrayList<>() : purchaseArrivalList);
|
|
|
+ purchaseProjectList = (purchaseProjectList == null ? new ArrayList<>() : purchaseProjectList);
|
|
|
+ purchaseProductList = (purchaseProductList == null ? new ArrayList<>() : purchaseProductList);
|
|
|
+
|
|
|
+ //产品(采购明细)
|
|
|
+ for (EhsdPurchaseProduct s : purchaseProductList) {
|
|
|
+ long id;
|
|
|
+ if (ObjectUtils.isNotEmpty(s.getId())) {
|
|
|
+ id = s.getId();
|
|
|
+ } else {
|
|
|
+ id = IdWorker.getId();
|
|
|
+ }
|
|
|
+ s.setId(id);
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
+ if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
|
|
|
+ purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
|
+ }
|
|
|
+ //修改或删除数据
|
|
|
+ purchaseProductMountingsService.editLinked(purchaseProductMountingsList,
|
|
|
+ EhsdPurchaseProductMountings::getPurchaseProductId, id);
|
|
|
+
|
|
|
+ if ("0".equals(purchase.getDataResource())) {
|
|
|
+ //计算采购数量是否大于申购数量
|
|
|
+ List<EhsdPurchaseProduct> purchaseDetailList1 = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
|
|
|
+ s.getSubscribeDetailId()));
|
|
|
+ //求和
|
|
|
+ BigDecimal purchaseCount = purchaseDetailList1.stream()
|
|
|
+ .map(EhsdPurchaseProduct::getQuantity)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //计算历史采购数量+本次采购数量之和
|
|
|
+ BigDecimal count = purchaseCount.add(s.getQuantity());
|
|
|
+ //判断采购数量是否大于申购数量
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getById(s.getSubscribeDetailId());
|
|
|
+ if (count.compareTo(subscribeDetail.getCount()) > 0) {
|
|
|
+ throw new ServiceException("采购数量不能大于申购数量");
|
|
|
}
|
|
|
}
|
|
|
- purchaseProductService.saveOrUpdateBatch(purchaseProductList);
|
|
|
- purchaseProductMountingsService.saveOrUpdateBatch(addMountingsList);
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseProjectList)) {//到货
|
|
|
- for (EhsdPurchaseProject s : purchaseProjectList) {
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- }
|
|
|
- purchaseProjectService.saveOrUpdateBatch(purchaseProjectList);
|
|
|
+ //修改或删除数据
|
|
|
+ purchaseProductService.editLinked(purchaseProductList, EhsdPurchaseProduct::getPurchaseId, purchase.getId());
|
|
|
+
|
|
|
+ //收费项目
|
|
|
+ for (EhsdPurchaseProject s : purchaseProjectList) {
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseArrivalList)) {//收费项目
|
|
|
- for (EhsdPurchaseArrival s : purchaseArrivalList) {
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- }
|
|
|
- purchaseArrivalService.saveOrUpdateBatch(purchaseArrivalList);
|
|
|
+ purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
|
|
|
+
|
|
|
+ //到货
|
|
|
+ for (EhsdPurchaseArrival s : purchaseArrivalList) {
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
}
|
|
|
+ purchaseArrivalService.editLinked(purchaseArrivalList, EhsdPurchaseArrival::getPurchaseId, purchase.getId());
|
|
|
+
|
|
|
return purchase;
|
|
|
}
|
|
|
|