|
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -61,8 +62,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentDao studentDao;
|
|
|
@Autowired
|
|
|
- private GoodsService goodsService;
|
|
|
- @Autowired
|
|
|
private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
|
@Autowired
|
|
|
private SellOrderService sellOrderService;
|
|
@@ -70,6 +69,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
@Autowired
|
|
|
private ContractService contractService;
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
@@ -106,7 +107,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
Integer studentId = sysUser.getId();
|
|
@@ -123,15 +124,26 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentGoodsSell.setOrderNo(orderNo);
|
|
|
|
|
|
List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
-// Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
-// String[] goodsIds = goodsId.split(",");
|
|
|
+
|
|
|
+// String[] goodsIds = goodsJson.split(",");
|
|
|
Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
+ for (GoodsSellDto goodsSellDto : goodsSellDtos) {
|
|
|
+ goodsSellDto.setGoodsPrice(map.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));
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
for (Integer id : goodsIds) {
|
|
|
- amount.add(map.get(id));
|
|
|
+ GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
|
|
|
+ amount = amount.add(goodsSellDto.getTotalGoodsPrice());
|
|
|
}
|
|
|
- studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
|
|
|
+ amount = amount.subtract(studentGoodsSell.getMarketAmount());
|
|
|
+ if(amount.signum() < 0){
|
|
|
+ throw new BizException("操作失败:订单金额异常");
|
|
|
+ }
|
|
|
+ studentGoodsSell.setOrganId(sysUser.getOrganId());
|
|
|
studentGoodsSell.setTotalAmount(amount);
|
|
|
+ studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
|
|
|
if(studentGoodsSell.getId() == null){
|
|
|
studentGoodsSellDao.insert(studentGoodsSell);
|
|
|
}else {
|
|
@@ -144,7 +156,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
return repairInfoMap;
|
|
|
}
|
|
|
|
|
|
- List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
|
|
|
+// List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
|
|
|
|
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
studentPaymentOrder.setUserId(studentId);
|
|
@@ -158,9 +170,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
- Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
+ /*Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
|
- for (Integer id : goodsIds) {
|
|
|
+ for (String id : goodsIds) {
|
|
|
Goods e = collect.get(id).get(0);
|
|
|
StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
|
|
@@ -174,12 +186,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
studentPaymentOrderDetail.setType(type);
|
|
|
studentPaymentOrderDetail.setPrice(e.getGroupPurchasePrice());
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(id.toString());
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(id);
|
|
|
studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
|
studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
}
|
|
|
- studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);*/
|
|
|
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
@@ -526,7 +538,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public void goodsSellorderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ public void goodsSellOrderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
//更新订单信息
|
|
|
studentPaymentOrder.setUpdateTime(nowDate);
|
|
@@ -572,11 +584,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
|
}
|
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
|
- //销售订单详情
|
|
|
- List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
|
|
|
- if (orderDetails.size() > 0) {
|
|
|
- sellOrderService.addOrderDetail2SellOrder(orderDetails, studentPaymentOrder, null);
|
|
|
- }
|
|
|
+ saveSellOrder(studentPaymentOrder.getOrderNo());
|
|
|
} else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
|
|
@@ -584,6 +592,50 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void saveSellOrder(String orderNo){
|
|
|
+ StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
|
|
|
+ StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
|
|
|
+ String goodsJson = studentGoodsSell.getGoodsJson();
|
|
|
+ List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(goodsJson, GoodsSellDto.class);
|
|
|
+ Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+ List<Integer> goodsId = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
+ List<Goods> goodsByIds = goodsService.findGoodsByIds(StringUtils.join(goodsId, ","));
|
|
|
+ Map<Integer, List<Goods>> goodsMap = goodsByIds.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
+ Map<String, BigDecimal> costMap = new HashMap<>(2);
|
|
|
+ List<SellOrder> sellOrders = new ArrayList<>();
|
|
|
+ goodsId.forEach(e->{
|
|
|
+ GoodsSellDto goodsSellDto = collect.get(e).get(0);
|
|
|
+ Goods goods = goodsMap.get(e).get(0);
|
|
|
+
|
|
|
+ costMap.put("sellCost", goods.getDiscountPrice());
|
|
|
+ if (goods.getAgreeCostPrice() != null) {
|
|
|
+ costMap.put("SellCost2", goods.getAgreeCostPrice());
|
|
|
+ }
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
+ sellOrder.setOrganId(orderByOrderNo.getOrganId());
|
|
|
+ sellOrder.setTransNo(orderByOrderNo.getTransNo());
|
|
|
+ sellOrder.setOrderId(orderByOrderNo.getId());
|
|
|
+ sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
|
|
|
+ sellOrder.setExpectAmount(orderByOrderNo.getExpectAmount());
|
|
|
+ sellOrder.setActualAmount(orderByOrderNo.getActualAmount());
|
|
|
+ sellOrder.setBalanceAmount(orderByOrderNo.getBalancePaymentAmount());
|
|
|
+ sellOrder.setSellCost(goods.getDiscountPrice());
|
|
|
+ sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
|
|
|
+ sellOrder.setType(SellTypeEnum.valueOf(goods.getType().getCode()));
|
|
|
+ sellOrder.setGoodsId(e);
|
|
|
+ sellOrder.setGoodsName(goods.getName());
|
|
|
+ sellOrder.setNum(goodsSellDto.getGoodsNum());
|
|
|
+ sellOrder.setUserId(studentGoodsSell.getUserId());
|
|
|
+ sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(orderByOrderNo.getMerNos());
|
|
|
+ sellOrder.setSellTime(orderByOrderNo.getPayTime());
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
+ });
|
|
|
+ if(sellOrders.size() > 0){
|
|
|
+ sellOrderService.batchInsert(sellOrders);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|