|
|
@@ -19,8 +19,10 @@ import java.util.Optional;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.entity.OrderSkuSync;
|
|
|
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -56,21 +58,6 @@ import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
|
|
|
import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
|
|
|
import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
|
|
|
-import com.ym.mec.biz.dal.entity.ActivityUserMapper;
|
|
|
-import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.Goods;
|
|
|
-import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroup;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
|
|
|
-import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentGoodsSell;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentRegistration;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroupActivity;
|
|
|
import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
|
|
|
import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
@@ -115,92 +102,104 @@ import com.ym.mec.thirdparty.yqpay.YqPayUtil;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
@Service
|
|
|
public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentPaymentOrderDao studentPaymentOrderDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private YqPayFeignService yqPayFeignService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentRegistrationService studentRegistrationService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
@Lazy
|
|
|
private VipGroupService vipGroupService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private MusicGroupService musicGroupService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SporadicChargeInfoService sporadicChargeInfoService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private PracticeGroupService practiceGroupService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysUserCashAccountDao sysUserCashAccountDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentRepairService studentRepairService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SubjectChangeService subjectChangeService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private DegreeRegistrationService degreeRegistrationService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private IdGeneratorService idGeneratorService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysConfigDao sysConfigDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private GoodsDao goodsDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private GoodsService goodsService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentInstrumentService studentInstrumentService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ReplacementInstrumentActivityService replacementInstrumentActivityService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ChildrenDayReserveService childrenDayReserveService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private MemberRankSettingService memberRankSettingService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private PayService payService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private CloudTeacherOrderService cloudTeacherOrderService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysCouponCodeService sysCouponCodeService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private VipGroupActivityService vipGroupActivityService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ActivityUserMapperService activityUserMapperService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private TenantConfigService tenantConfigService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private GoodsProcurementDao goodsProcurementDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysPaymentConfigService sysPaymentConfigService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SellOrderDao sellOrderDao;
|
|
|
@Lazy
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private ContractService contractService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private HfMerchantConfigService hfMerchantConfigService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private StudentDao studentDao;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private YeepayPaymentService yeepayPaymentService;
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
|
|
|
+ @Resource
|
|
|
+ private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
|
|
|
+ @Resource
|
|
|
+ private StudentRepairDao studentRepairDao;
|
|
|
+ @Resource
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
+ @Resource
|
|
|
+ private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
@Override
|
|
|
@@ -485,11 +484,11 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateOrder(Map<String, String> rpMap) throws Exception {
|
|
|
- DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
|
|
|
+ DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? SUCCESS : DealStatusEnum.FAILED;
|
|
|
StudentPaymentOrder order = findOrderByOrderNo(rpMap.get("merOrderNo"));
|
|
|
//关闭或失败的订单查询订单成功,订单改成成功,钱退到余额
|
|
|
- if (order != null && (order.getStatus().equals(DealStatusEnum.CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(DealStatusEnum.SUCCESS)) {
|
|
|
- String memo = order.getStatus().equals(DealStatusEnum.CLOSE) ? "关闭订单" : "失败订单";
|
|
|
+ if (order != null && (order.getStatus().equals(CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(SUCCESS)) {
|
|
|
+ String memo = order.getStatus().equals(CLOSE) ? "关闭订单" : "失败订单";
|
|
|
memo = memo + ",实际支付成功,退到用户余额";
|
|
|
//更新订单状态
|
|
|
order.setStatus(status);
|
|
|
@@ -516,7 +515,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (status.equals(DealStatusEnum.SUCCESS)) {
|
|
|
+ if (status.equals(SUCCESS)) {
|
|
|
order.setPayTime(new Date());
|
|
|
} else {
|
|
|
order.setMemo(rpMap.get("remarks"));
|
|
|
@@ -534,7 +533,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
callOrderCallBack(order);
|
|
|
|
|
|
- if (status.equals(DealStatusEnum.SUCCESS)
|
|
|
+ if (status.equals(SUCCESS)
|
|
|
&& StringUtils.isNotBlank(order.getPaymentChannel())
|
|
|
&& (order.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || order.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode()))
|
|
|
&& !rpMap.containsKey("simulation")) {
|
|
|
@@ -734,7 +733,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
memberRankSettingService.liveBuyOrderCallback(order);
|
|
|
} else if (order.getType().equals(OrderTypeEnum.MALL_BUY)) {
|
|
|
// 商城购买订单回调
|
|
|
- this.mallBuyOrderCallback(order);
|
|
|
+ studentPaymentOrderService.mallBuyOrderCallback(order);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -897,7 +896,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
List<StudentPaymentOrderExportDto> orders = studentPaymentOrderDao.getUserApplyOrders(studentId, musicGroupId);
|
|
|
StudentRegistration studentRegister = studentRegistrationService.getStudentRegister(musicGroupId, studentId);
|
|
|
for (StudentPaymentOrderExportDto order : orders) {
|
|
|
- if ((DealStatusEnum.ING.equals(order.getStatus()) || DealStatusEnum.SUCCESS.equals(order.getStatus())) &&
|
|
|
+ if ((DealStatusEnum.ING.equals(order.getStatus()) || SUCCESS.equals(order.getStatus())) &&
|
|
|
studentRegister.getPayingStatus().equals(2)) {
|
|
|
order.setPayingStatus(2);
|
|
|
}
|
|
|
@@ -1142,7 +1141,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return BaseController.failed(HttpStatus.CONTINUE, "您有支付中的订单,是否继续支付");
|
|
|
}
|
|
|
//处理关闭订单
|
|
|
- order.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ order.setStatus(CLOSE);
|
|
|
order.setMemo("关闭订单");
|
|
|
|
|
|
|
|
|
@@ -1215,7 +1214,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
StudentRegistration studentRegistration = studentRegistrationService.getStudentRegister(musicGroupId, userId);
|
|
|
//获取学员在乐团的状态,如果是在读,那么不处理人数
|
|
|
if (studentRegistration.getMusicGroupStatus() == StudentMusicGroupStatusEnum.APPLY) {
|
|
|
- List<StudentPaymentOrder> oldStudentPaymentOrderList = this.queryByCondition(GroupType.MUSIC, musicGroupId, userId, DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
|
|
|
+ List<StudentPaymentOrder> oldStudentPaymentOrderList = this.queryByCondition(GroupType.MUSIC, musicGroupId, userId, SUCCESS, OrderTypeEnum.APPLY);
|
|
|
//判断是否有成功的订单,如果有,表示已经处理过人数
|
|
|
if (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0) {
|
|
|
List<StudentPaymentOrderDetail> orderDetail = studentPaymentOrderDetailService.getOrderDetail(order.getId());
|
|
|
@@ -1305,14 +1304,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return studentPaymentOrderDao.getMemberIngOrder(member, status);
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private StudentRepairDao studentRepairDao;
|
|
|
- @Autowired
|
|
|
- private MusicGroupDao musicGroupDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Map createOrder(MallCreateOrderModel model) throws Exception {
|
|
|
@@ -1382,7 +1373,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
if (studentPaymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ studentPaymentOrder.setStatus(SUCCESS);
|
|
|
}
|
|
|
studentPaymentOrder.setGroupType(GroupType.MALL_SELL);
|
|
|
studentPaymentOrder.setUserId(model.getUserId());
|
|
|
@@ -1503,7 +1494,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
Map<Integer, String> map = new HashMap<>();
|
|
|
map.put(userId, userId.toString());
|
|
|
|
|
|
- if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
+ if (studentPaymentOrder.getStatus() == SUCCESS) {
|
|
|
try {
|
|
|
contractService.transferProduceContract(userId, null, studentPaymentOrder.getType());
|
|
|
} catch (Exception e) {
|
|
|
@@ -1627,7 +1618,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
rechargeDetail.setAmount(amount);
|
|
|
rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
|
|
|
rechargeDetail.setComment("缴费前充值");
|
|
|
- rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ rechargeDetail.setStatus(SUCCESS);
|
|
|
rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
|
|
|
rechargeDetail.setUserId(userId);
|
|
|
@@ -1642,12 +1633,12 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
paymentDetail.setAmount(amount.negate());
|
|
|
paymentDetail.setBalance(cashAccount.getBalance());
|
|
|
paymentDetail.setComment("商品销售");
|
|
|
- paymentDetail.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ paymentDetail.setStatus(SUCCESS);
|
|
|
paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
paymentDetail.setType(PlatformCashAccountDetailTypeEnum.GOODS_SELL);
|
|
|
paymentDetail.setUserId(userId);
|
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
|
- } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
+ } else if (studentPaymentOrder.getStatus() == CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
|
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "商城购买支付失败");
|
|
|
@@ -1795,6 +1786,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Transactional
|
|
|
public OrderCancelModel cancelOrder(StudentPaymentOrder order, String reason) {
|
|
|
OrderCancelModel model = new OrderCancelModel();
|
|
|
+ model.setSuccess(true);
|
|
|
try {
|
|
|
HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
@@ -1831,22 +1823,28 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
model.setStatus(false);
|
|
|
order.setStatus(CLOSE);
|
|
|
order.setMemo(reason);
|
|
|
- } else {
|
|
|
+ } else if (status.equals("pending")){
|
|
|
// 执行关单操作
|
|
|
+ Map<String, String> closeInfo = new HashMap<>();
|
|
|
if(StringUtils.equals(order.getPaymentChannel(), PaymentChannelEnum.ADAPAY.getCode())) {
|
|
|
- Payment.closeWithKey(order.getTransNo(),"", hfMerchantConfig.getMerKey());
|
|
|
+ closeInfo = Payment.closeWithKey(order.getTransNo(), "", hfMerchantConfig.getMerKey());
|
|
|
}else if(StringUtils.equals(order.getPaymentChannel(), PaymentChannelEnum.YEEPAY.getCode())) {
|
|
|
- yeepayPaymentService.close(hfMerchantConfig, order.getTransNo(),"", order.getOrderNo());
|
|
|
+ closeInfo = yeepayPaymentService.close(hfMerchantConfig, order.getTransNo(), "", order.getOrderNo());
|
|
|
}
|
|
|
+ boolean success = "success".equals(closeInfo.get("status"));
|
|
|
model.setStatus(false);
|
|
|
order.setStatus(CLOSE);
|
|
|
+ model.setSuccess(success);
|
|
|
+ model.setMessage(closeInfo.get("msg"));
|
|
|
+ }
|
|
|
+ if (model.getSuccess()) {
|
|
|
+ TenantContextHolder.setTenantId(order.getTenantId());
|
|
|
+ callOrderCallBack(order);
|
|
|
+ TenantContextHolder.clearTenantId();
|
|
|
}
|
|
|
- TenantContextHolder.setTenantId(order.getTenantId());
|
|
|
- callOrderCallBack(order);
|
|
|
- TenantContextHolder.clearTenantId();
|
|
|
- model.setSuccess(true);
|
|
|
- } catch (Exception e) {
|
|
|
+ }catch (Exception e) {
|
|
|
model.setSuccess(false);
|
|
|
+ model.setMessage(e.getMessage());
|
|
|
logger.error("订单[{}]取消失败", order.getTransNo(), e);
|
|
|
}
|
|
|
return model;
|
|
|
@@ -2218,50 +2216,48 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return;
|
|
|
}
|
|
|
List<String> orderNos = orderSkuSyncs.stream().map(e -> e.getOrderNo()).collect(Collectors.toList());
|
|
|
+ Map<String, List<OrderSkuSync.SkuSync>> skuMap = orderSkuSyncs.stream().collect(Collectors.toMap(OrderSkuSync::getOrderNo, OrderSkuSync::getSkuSyncList));
|
|
|
List<SellOrder> sellOrders = sellOrderDao.queryByOrganNos(orderNos);
|
|
|
+ //检查学校商品采购订单
|
|
|
+ List<MusicGroupPaymentCalenderAddress> calenderAddresses = musicGroupPaymentCalenderAddressService.lambdaQuery().
|
|
|
+ in(MusicGroupPaymentCalenderAddress::getOrderNo, orderNos).
|
|
|
+ eq(MusicGroupPaymentCalenderAddress::getDeliveryFlag, false).list();
|
|
|
+ if (CollectionUtils.isNotEmpty(calenderAddresses)) {
|
|
|
+ Map<String, MusicGroupPaymentCalenderAddress> addressMap = calenderAddresses.stream().
|
|
|
+ collect(Collectors.toMap(MusicGroupPaymentCalenderAddress::getOrderNo, e -> e));
|
|
|
+ List<String> addressOrders = calenderAddresses.stream().map(MusicGroupPaymentCalenderAddress::getOrderNo).collect(Collectors.toList());
|
|
|
+ for (String addressOrder : addressOrders) {
|
|
|
+ MusicGroupPaymentCalenderAddress address = addressMap.get(addressOrder);
|
|
|
+ address.setDeliveryDetail(JSON.toJSONString(skuMap.get(addressOrder)));
|
|
|
+ address.setDeliveryFlag(true);
|
|
|
+ }
|
|
|
+ musicGroupPaymentCalenderAddressService.updateBatchById(calenderAddresses);
|
|
|
+ }
|
|
|
if (CollectionUtils.isEmpty(sellOrders)) {
|
|
|
- throw new BizException("订单不存在");
|
|
|
+ return;
|
|
|
}
|
|
|
sellOrders = sellOrders.stream().filter(e -> e.getDeliveryTime() == null).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isEmpty(sellOrders)){
|
|
|
return;
|
|
|
}
|
|
|
+ String format = DateUtil.format(new Date(), DateUtil.ISO_EXPANDED_DATE_FORMAT);
|
|
|
Map<String,List<SellOrder>> sellOrderMap = sellOrders.stream().collect(Collectors.groupingBy(SellOrder::getOrderNo));
|
|
|
- Map<String,Map<Long,BigDecimal>> skuCostMap = new HashMap<>(orderSkuSyncs.size());
|
|
|
for (OrderSkuSync orderSkuSync : orderSkuSyncs) {
|
|
|
List<SellOrder> dtos = sellOrderMap.get(orderSkuSync.getOrderNo());
|
|
|
if(CollectionUtils.isEmpty(dtos)){
|
|
|
continue;
|
|
|
}
|
|
|
- //获取sku平均成本价
|
|
|
- Map<Long,List<OrderSkuSync.SkuSync>> skuMap = orderSkuSync.getSkuSyncList().stream().collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getSku));
|
|
|
- Map<Long,BigDecimal> costMap = new HashMap<>(skuMap.keySet().size());
|
|
|
- for (Long skuId : skuMap.keySet()) {
|
|
|
- List<OrderSkuSync.SkuSync> skuSyncs = skuMap.get(skuId);
|
|
|
- //汇总成本价
|
|
|
- BigDecimal costPrice = skuSyncs.stream().map(e -> e.getPrice().multiply(new BigDecimal(e.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- //获取总数
|
|
|
- int count = skuSyncs.stream().mapToInt(e -> e.getCount()).sum();
|
|
|
- BigDecimal avgCostPrice = costPrice;
|
|
|
- if (count > 1) {
|
|
|
- avgCostPrice = costPrice.divide(new BigDecimal(count), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- costMap.put(skuId,avgCostPrice);
|
|
|
- }
|
|
|
- skuCostMap.put(orderSkuSync.getOrderNo(),costMap);
|
|
|
- }
|
|
|
- Date now = new Date();
|
|
|
- String format = DateUtil.format(now, DateUtil.ISO_EXPANDED_DATE_FORMAT);
|
|
|
- for (String orderNo : sellOrderMap.keySet()) {
|
|
|
- List<SellOrder> sellOrderList = sellOrderMap.get(orderNo);
|
|
|
- Map<Long,BigDecimal> costMap = skuCostMap.get(orderNo);
|
|
|
- for (SellOrder sellOrder : sellOrderList) {
|
|
|
- BigDecimal costPrice = costMap.get(sellOrder.getGoodsSkuId().longValue());
|
|
|
- if(costPrice == null){
|
|
|
- throw new BizException("商品[{}]成本价不存在",sellOrder.getGoodsSkuId());
|
|
|
+ Map<Long,List<SellOrder>> goodsSkuMap = dtos.stream().collect(Collectors.groupingBy(e->e.getGoodsSkuId().longValue()));
|
|
|
+ for (OrderSkuSync.SkuSync skuSync : orderSkuSync.getSkuSyncList()) {
|
|
|
+ List<SellOrder> sellOrderList = goodsSkuMap.get(skuSync.getSku());
|
|
|
+ for (int i = 0; i < skuSync.getCount(); i++) {
|
|
|
+ SellOrder sellOrder = sellOrderList.get(i);
|
|
|
+ if (sellOrder != null) {
|
|
|
+ sellOrder.setDeliveryTime(format);
|
|
|
+ sellOrder.setSellCost(skuSync.getPrice());
|
|
|
+ sellOrder.setStockType(StringUtils.equalsIgnoreCase(skuSync.getType(),"INTERNAL")?StockType.INTERNAL:StockType.EXTERNAL);
|
|
|
+ }
|
|
|
}
|
|
|
- sellOrder.setSellCost(costPrice);
|
|
|
- sellOrder.setDeliveryTime(format);
|
|
|
}
|
|
|
}
|
|
|
sellOrderDao.batchUpdate(sellOrders);
|