|
@@ -207,6 +207,54 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
//退优惠券
|
|
|
sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
|
|
|
+
|
|
|
+ Date nowDate = new Date();
|
|
|
+ //增加商品库存
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(orderByOrderNo.getId());
|
|
|
+ String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
+ if(StringUtils.isNotBlank(goodsIds)){
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
+
|
|
|
+ // 进货清单
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
+ goodsProcurement.setUpdateTime(nowDate);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
|
|
|
if (byOrderNo != null) {
|
|
@@ -257,11 +305,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
goodsSellDto.setGoodsGroupPrice(groupPriceMap.get(goodsSellDto.getGoodsId()));
|
|
|
goodsSellDto.setTotalGoodsPrice(map.get(goodsSellDto.getGoodsId()).multiply(new BigDecimal(goodsSellDto.getGoodsNum())));
|
|
|
}
|
|
|
- Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+ Map<Integer, List<GoodsSellDto>> goodsSellDtoMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
BigDecimal groupAmount = BigDecimal.ZERO;
|
|
|
for (Integer id : goodsIds) {
|
|
|
- GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
|
|
|
+ GoodsSellDto goodsSellDto = goodsSellDtoMap.get(id).get(0);
|
|
|
amount = amount.add(goodsSellDto.getTotalGoodsPrice());
|
|
|
groupAmount = groupAmount.add(goodsSellDto.getGoodsGroupPrice());
|
|
|
}
|
|
@@ -320,35 +368,59 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
|
|
|
if(goodsSellDtos != null){
|
|
|
- String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
|
|
|
+ //String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for(GoodsSellDto goodsSellDto : goodsSellDtos){
|
|
|
+ for(int i = 0; i < goodsSellDto.getGoodsNum() ; i++){
|
|
|
+ sb.append(goodsSellDto.getGoodsId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
|
|
|
+
|
|
|
List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
|
|
|
- BigDecimal goodsPrice = goodsList.stream().map(t -> t.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- for(Goods g : goodsList){
|
|
|
- studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
- studentPaymentOrderDetail.setCreateTime(date);
|
|
|
- if(g.getType() == GoodsType.INSTRUMENT){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
- }else if(g.getType() == GoodsType.ACCESSORIES){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
- }else if(g.getType() == GoodsType.TEACHING || g.getType() == GoodsType.STAFF){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
- }else{
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(g.getId() + "");
|
|
|
-
|
|
|
- BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(g.getGroupPurchasePrice()).divide(goodsPrice, RoundingMode.UP);
|
|
|
-
|
|
|
- if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
|
|
|
- studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
- }else{
|
|
|
- studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
- studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
-
|
|
|
- totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
- studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIdsStr.split(",")){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goodsMap.get(Integer.parseInt(goodsIdStr)).getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ Goods goods = null;
|
|
|
+ for(String goodsIdStr : goodsIdsStr.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIdsStr.split(",").length == studentPaymentOrderDetailList.size() + 1){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -560,7 +632,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
repairInfo.setUpdateTime(date);
|
|
|
|
|
|
List<RepairGoodsDto> repairGoodsDtos = null;
|
|
|
- String goodIdList = null;
|
|
|
|
|
|
String goodsJson = repairInfo.getGoodsJson();
|
|
|
if (StringUtils.isNotEmpty(goodsJson)) {
|
|
@@ -571,7 +642,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
e.setGroupPurchasePrice(map.get(e.getId()));
|
|
|
});
|
|
|
repairInfo.setGoodsJson(JSONObject.toJSONString(repairGoodsDtos));
|
|
|
- goodIdList = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
}
|
|
|
|
|
|
BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
@@ -639,32 +709,52 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
if(StringUtils.isNotBlank(repairInfo.getGoodsJson()) && repairGoodsDtos != null){
|
|
|
String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
|
|
|
- for(Goods g : goodsList){
|
|
|
- studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
- studentPaymentOrderDetail.setCreateTime(date);
|
|
|
- if(g.getType() == GoodsType.INSTRUMENT){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
- }else if(g.getType() == GoodsType.ACCESSORIES){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
- }else if(g.getType() == GoodsType.TEACHING || g.getType() == GoodsType.STAFF){
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
- }else{
|
|
|
- studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(g.getId() + "");
|
|
|
-
|
|
|
- BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(g.getGroupPurchasePrice()).divide(goodsPrice, RoundingMode.UP);
|
|
|
-
|
|
|
- if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0){
|
|
|
- studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
- }else{
|
|
|
- studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
- }
|
|
|
- studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
- studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
-
|
|
|
- totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
- studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIds.split(",").length == studentPaymentOrderDetailList.size()){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -791,18 +881,32 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
) {
|
|
|
throw new BizException("邮寄信息必填");
|
|
|
}
|
|
|
+
|
|
|
+ List<RepairGoodsDto> repairGoodsDtos = null;
|
|
|
Date date = new Date();
|
|
|
StudentRepair studentRepair = studentRepairDao.get(repairInfo.getId());
|
|
|
studentDao.lockUser(studentRepair.getStudentId());
|
|
|
BigDecimal amount = studentRepair.getAmount();
|
|
|
String goodsJson = studentRepair.getGoodsJson();
|
|
|
if (StringUtils.isNotEmpty(goodsJson)) {
|
|
|
- List<RepairGoodsDto> repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
+ repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
BigDecimal reduce = repairGoodsDtos.stream().map(e -> e.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
amount = amount.add(reduce);
|
|
|
}
|
|
|
amount = amount.subtract(studentRepair.getExemptionAmount());
|
|
|
|
|
|
+ BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
|
+ if (StringUtils.isNoneBlank(goodsJson)) {
|
|
|
+ JSONArray goods = JSON.parseArray(goodsJson);
|
|
|
+ for (Object good : goods) {
|
|
|
+ JSONObject goodObject = (JSONObject) good;
|
|
|
+ BigDecimal groupPurchasePrice = goodObject.getBigDecimal("groupPurchasePrice");
|
|
|
+ if (Objects.nonNull(groupPurchasePrice)) {
|
|
|
+ goodsPrice = goodsPrice.add(groupPurchasePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
studentRepair.setUseBalancePayment(repairInfo.getUseBalancePayment());
|
|
|
studentRepair.setTransNo(orderNo);
|
|
@@ -835,6 +939,77 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
+ // 添加studentPaymentOrderDetail
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.REPAIR);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(null);
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().multiply(studentRepair.getAmount()).divide(goodsPrice.add(studentRepair.getAmount()), RoundingMode.UP));
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+
|
|
|
+ BigDecimal totalPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+ BigDecimal repairPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(studentRepair.getGoodsJson()) && repairGoodsDtos != null){
|
|
|
+ String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
+ List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIds.split(",").length == studentPaymentOrderDetailList.size()){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ }
|
|
|
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
if (studentRepair.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -957,36 +1132,51 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
saveSellOrder(studentPaymentOrder.getOrderNo());
|
|
|
} else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
|
|
|
- List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
|
|
|
- //增加商品库存
|
|
|
+ //增加商品库存
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
|
|
|
String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
if(StringUtils.isNotBlank(goodsIds)){
|
|
|
GoodsProcurement goodsProcurement = null;
|
|
|
- List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
|
|
|
List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
- for(Goods subGoods : goodsList){
|
|
|
- subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
|
|
|
- subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
|
|
|
- subGoods.setUpdateTime(nowDate);
|
|
|
- batchUpdateGoodsList.add(subGoods);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
|
|
|
// 进货清单
|
|
|
- goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
goodsProcurement.setUpdateTime(nowDate);
|
|
|
- goodsProcurementList.add(goodsProcurement);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- if(goodsProcurementList.size() > 0){
|
|
|
- goodsProcurementDao.batchUpdate(goodsProcurementList);
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if(batchUpdateGoodsList.size() > 0){
|
|
|
- goodsService.batchUpdate(batchUpdateGoodsList);
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -1369,36 +1559,51 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
throw new BizException("维修单更新失败");
|
|
|
}
|
|
|
|
|
|
- List<Goods> batchUpdateGoodsList = new ArrayList<Goods>();
|
|
|
//增加商品库存
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
|
|
|
String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
if(StringUtils.isNotBlank(goodsIds)){
|
|
|
GoodsProcurement goodsProcurement = null;
|
|
|
- List<GoodsProcurement> goodsProcurementList = new ArrayList<GoodsProcurement>();
|
|
|
List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
- for(Goods subGoods : goodsList){
|
|
|
- subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).incrementAndGet());
|
|
|
- subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).decrementAndGet());
|
|
|
- subGoods.setUpdateTime(nowDate);
|
|
|
- batchUpdateGoodsList.add(subGoods);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
|
|
|
// 进货清单
|
|
|
- goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
goodsProcurement.setUpdateTime(nowDate);
|
|
|
- goodsProcurementList.add(goodsProcurement);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- if(goodsProcurementList.size() > 0){
|
|
|
- goodsProcurementDao.batchUpdate(goodsProcurementList);
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if(batchUpdateGoodsList.size() > 0){
|
|
|
- goodsService.batchUpdate(batchUpdateGoodsList);
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|