推送公众号次数校验
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.czg.service.market.service.impl;
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.czg.account.service.ShopInfoService;
|
import com.czg.account.service.ShopInfoService;
|
||||||
import com.czg.config.RabbitPublisher;
|
import com.czg.config.RabbitPublisher;
|
||||||
@@ -15,15 +16,19 @@ import com.czg.market.service.MkShopCouponRecordService;
|
|||||||
import com.czg.service.RedisService;
|
import com.czg.service.RedisService;
|
||||||
import com.czg.service.market.mapper.AcPushEventMapper;
|
import com.czg.service.market.mapper.AcPushEventMapper;
|
||||||
import com.czg.service.market.mapper.SmsPushEventUserMapper;
|
import com.czg.service.market.mapper.SmsPushEventUserMapper;
|
||||||
|
import com.czg.system.service.SysParamsService;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公众号推送任务 服务层实现。
|
* 公众号推送任务 服务层实现。
|
||||||
@@ -31,12 +36,15 @@ import java.time.LocalDateTime;
|
|||||||
* @author ww
|
* @author ww
|
||||||
* @since 2025-10-20
|
* @since 2025-10-20
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPushEvent> implements AcPushEventService {
|
public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPushEvent> implements AcPushEventService {
|
||||||
@Resource
|
@Resource
|
||||||
private SmsPushEventUserMapper eventUserMapper;
|
private SmsPushEventUserMapper eventUserMapper;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopInfoService shopInfoService;
|
private ShopInfoService shopInfoService;
|
||||||
|
@DubboReference
|
||||||
|
private SysParamsService paramsService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkShopCouponRecordService couponRecordService;
|
private MkShopCouponRecordService couponRecordService;
|
||||||
@Resource
|
@Resource
|
||||||
@@ -80,6 +88,7 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
|
|||||||
} else {
|
} else {
|
||||||
param.setSendTime(LocalDateTime.now());
|
param.setSendTime(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
checkPushEventSendCount(param.getShopId());
|
||||||
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
|
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
|
||||||
save(pushEvent);
|
save(pushEvent);
|
||||||
if (param.getUserType() == 2) {
|
if (param.getUserType() == 2) {
|
||||||
@@ -127,6 +136,7 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
|
|||||||
} else {
|
} else {
|
||||||
param.setSendTime(LocalDateTime.now());
|
param.setSendTime(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
checkPushEventSendCount(param.getShopId());
|
||||||
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
|
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
|
||||||
updateById(pushEvent);
|
updateById(pushEvent);
|
||||||
eventUserMapper.deleteByQuery(new QueryWrapper()
|
eventUserMapper.deleteByQuery(new QueryWrapper()
|
||||||
@@ -158,4 +168,32 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
|
|||||||
pushEvent.setIsDel(1);
|
pushEvent.setIsDel(1);
|
||||||
updateById(pushEvent);
|
updateById(pushEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkPushEventSendCount(Long shopId) {
|
||||||
|
String maxSendCount = paramsService.getSysParamValue("ac_day_count");
|
||||||
|
if (StrUtil.isBlank(maxSendCount)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LocalDateTime todayStart = LocalDate.now().atStartOfDay();
|
||||||
|
LocalDateTime todayEnd = LocalDate.now().atTime(23, 59, 59);
|
||||||
|
|
||||||
|
Long maxCount = null;
|
||||||
|
try {
|
||||||
|
maxCount = Long.parseLong(maxSendCount);
|
||||||
|
if (maxCount < 0) {
|
||||||
|
throw new CzgException("每日最大发送量参数不能为负数");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.error("每日最大发送量参数格式错误,必须为整数", e);
|
||||||
|
}
|
||||||
|
Long sendCount = count(
|
||||||
|
new QueryWrapper()
|
||||||
|
.eq(AcPushEvent::getShopId, shopId)
|
||||||
|
.ne(AcPushEvent::getStatus, -1)
|
||||||
|
.between(AcPushEvent::getSendTime, todayStart, todayEnd)
|
||||||
|
);
|
||||||
|
if (maxCount != null && sendCount >= maxCount) {
|
||||||
|
throw new CzgException("今日已发送" + maxCount + "条,不能继续发送");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user