From fa677dec1c55db004a31beefb1e346e18c7858c2 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 20 二月 2025 18:41:29 +0800 Subject: [PATCH] bug修改 --- src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java | 76 +++++++++++++++++++++++++++---------- 1 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java b/src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java index 4adf590..4d094cc 100644 --- a/src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java +++ b/src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java @@ -1,12 +1,16 @@ package com.taoke.autopay.service.impl; +import com.taoke.autopay.dao.KeyOrderMapper; import com.taoke.autopay.dao.WxUserOrderCountMapper; +import com.taoke.autopay.entity.OrderChannelEnum; import com.taoke.autopay.entity.OrderCountTypeEnum; import com.taoke.autopay.entity.WxUserOrderCount; import com.taoke.autopay.exception.WxOrderCountException; import com.taoke.autopay.factory.OrderFactory; +import com.taoke.autopay.service.KeyOrderService; import com.taoke.autopay.service.UserSettingService; import com.taoke.autopay.service.WxUserOrderCountService; +import com.taoke.autopay.utils.TimeUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,14 +33,20 @@ @Resource private UserSettingService userSettingService; + @Resource + private KeyOrderMapper keyOrderMapper; + @Transactional(rollbackFor = Exception.class) @Override - public void addOrderCount(Long uid, OrderCountTypeEnum orderType, String day, int count, Integer maxCount) throws WxOrderCountException { + public void addOrderCount(Long uid, OrderCountTypeEnum orderType, OrderChannelEnum orderChannel, String day, int count, Integer maxCount) throws WxOrderCountException { // 缁熻鐢ㄦ埛鎬绘鏁� WxUserOrderCountMapper.DaoQuery daoQuery=new WxUserOrderCountMapper.DaoQuery(); daoQuery.uid = uid; - daoQuery.orderType=orderType.getType(); + if(orderType!=null) { + daoQuery.orderType = orderType.getType(); + } + daoQuery.orderChannel = orderChannel; Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery); if(totalCount==null){ totalCount = 0L; @@ -44,15 +54,18 @@ if(totalCount>Integer.MAX_VALUE){ totalCount = (long)Integer.MAX_VALUE; } - int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue()); + int submitCount = userSettingService.getLimitCountByTotalCount(orderType.getType(), (int)totalCount.longValue(), orderChannel); if(maxCount==null){ maxCount =Integer.MAX_VALUE; } maxCount = Math.min(submitCount, maxCount); WxUserOrderCount info = new WxUserOrderCount(); info.setDay(day); - info.setOrderType(orderType.getType()); + if(orderType!=null) { + info.setOrderType(orderType.getType()); + } info.setUid(uid); + info.setOrderChannel(orderChannel); info.setId(OrderFactory.createId(info)); // 鍒ゆ柇鏄惁瀛樺湪 WxUserOrderCount old = wxUserOrderCountMapper.selectByPrimaryKeyForUpdate(info.getId()); @@ -78,11 +91,14 @@ } @Override - public void isOrderCountLimit(Long uid, OrderCountTypeEnum orderType, String day, int count, Integer maxCount) throws WxOrderCountException{ + public void isOrderCountLimit(Long uid, OrderCountTypeEnum orderType,OrderChannelEnum orderChannel, String day, int count, Integer maxCount) throws WxOrderCountException{ WxUserOrderCountMapper.DaoQuery daoQuery=new WxUserOrderCountMapper.DaoQuery(); daoQuery.uid = uid; - daoQuery.orderType=orderType.getType(); + if(orderType!=null) { + daoQuery.orderType = orderType.getType(); + } + daoQuery.orderChannel = orderChannel; Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery); if(totalCount==null){ totalCount = 0L; @@ -90,37 +106,55 @@ if(totalCount>Integer.MAX_VALUE){ totalCount = (long)Integer.MAX_VALUE; } - int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue()); + int submitCount = userSettingService.getLimitCountByTotalCount(orderType.getType(), (int)totalCount.longValue(),orderChannel); if(maxCount==null){ maxCount =Integer.MAX_VALUE; } maxCount = Math.min(submitCount, maxCount); - WxUserOrderCount info = new WxUserOrderCount(); - info.setDay(day); - info.setOrderType(orderType.getType()); - info.setUid(uid); - info.setId(OrderFactory.createId(info)); - // 鍒ゆ柇鏄惁瀛樺湪 - WxUserOrderCount old = wxUserOrderCountMapper.selectByPrimaryKeyForUpdate(info.getId()); - - if (old != null) { - if (maxCount != null && maxCount < count + old.getOrderCount()) { - throw new WxOrderCountException(String.format("浠婃棩瓒呰繃鏈�澶ф彁浜ゆ鏁帮紙%s娆★級", maxCount)); - } + // 缁熻浠婂ぉ鐨勬彁浜ゆ鏁� + KeyOrderMapper.DaoQuery orderQuery=new KeyOrderMapper.DaoQuery(); + orderQuery.uid = uid; + orderQuery.minCreateTime =new Date( TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMdd"),"yyyyMMdd")); + if(orderType!=null&&orderType!=OrderCountTypeEnum.SUBMIT_TOKEN_COUNT){ + orderQuery.orderType=orderType.getType(); } + long todayCount = keyOrderMapper.count(orderQuery); + if (maxCount != null && maxCount < count + todayCount) { + throw new WxOrderCountException(String.format("浠婃棩瓒呰繃鏈�澶ф彁浜ゆ鏁帮紙%s娆★級", maxCount)); + } + } @Override - public WxUserOrderCount get(Long uid, OrderCountTypeEnum orderType, String day) { + public WxUserOrderCount get(Long uid, OrderCountTypeEnum orderType,OrderChannelEnum orderChannel, String day) { WxUserOrderCountMapper.DaoQuery daoQuery = new WxUserOrderCountMapper.DaoQuery(); daoQuery.uid = uid; daoQuery.day = day; - daoQuery.orderType = orderType.getType(); + if(orderType!=null) { + daoQuery.orderType = orderType.getType(); + } + daoQuery.orderChannel = orderChannel; List<WxUserOrderCount> list = wxUserOrderCountMapper.list(daoQuery); if (list.size() > 0) { return list.get(0); } return null; } + + @Override + public long sum(Long uid, OrderCountTypeEnum orderType, OrderChannelEnum orderChannel,String day) { + WxUserOrderCountMapper.DaoQuery daoQuery=new WxUserOrderCountMapper.DaoQuery(); + daoQuery.uid = uid; + if(orderType!=null) { + daoQuery.orderType = orderType.getType(); + } + daoQuery.orderChannel = orderChannel; + daoQuery.day = day; + Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery); + if(totalCount==null){ + return 0; + } + return totalCount; + } } -- Gitblit v1.8.0