admin
2024-09-27 17caebabf7a6a529b7039c71e21e5a324e31ea20
src/main/java/com/taoke/autopay/service/impl/WxUserOrderCountServiceImpl.java
@@ -2,6 +2,7 @@
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;
@@ -38,11 +39,14 @@
    @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;
        if(orderType!=null) {
        daoQuery.orderType=orderType.getType();
        }
        daoQuery.orderChannel = orderChannel;
        Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery);
        if(totalCount==null){
            totalCount = 0L;
@@ -50,15 +54,18 @@
        if(totalCount>Integer.MAX_VALUE){
            totalCount = (long)Integer.MAX_VALUE;
        }
       int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue());
       int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue(), orderChannel);
        if(maxCount==null){
            maxCount =Integer.MAX_VALUE;
        }
        maxCount = Math.min(submitCount, maxCount);
        WxUserOrderCount info = new WxUserOrderCount();
        info.setDay(day);
        if(orderType!=null) {
        info.setOrderType(orderType.getType());
        }
        info.setUid(uid);
        info.setOrderChannel(orderChannel);
        info.setId(OrderFactory.createId(info));
        // 判断是否存在
        WxUserOrderCount old = wxUserOrderCountMapper.selectByPrimaryKeyForUpdate(info.getId());
@@ -84,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;
        if(orderType!=null) {
        daoQuery.orderType=orderType.getType();
        }
        daoQuery.orderChannel = orderChannel;
        Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery);
        if(totalCount==null){
            totalCount = 0L;
@@ -96,7 +106,7 @@
        if(totalCount>Integer.MAX_VALUE){
            totalCount = (long)Integer.MAX_VALUE;
        }
        int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue());
        int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue(),orderChannel);
        if(maxCount==null){
            maxCount =Integer.MAX_VALUE;
        }
@@ -117,15 +127,34 @@
    }
    @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;
        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;
    }
}