Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松 2025-10-21 17:36:25 +08:00
commit 15d93a54cd
1 changed files with 38 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.service.ShopInfoService;
import com.czg.config.RabbitPublisher;
@ -15,15 +16,19 @@ import com.czg.market.service.MkShopCouponRecordService;
import com.czg.service.RedisService;
import com.czg.service.market.mapper.AcPushEventMapper;
import com.czg.service.market.mapper.SmsPushEventUserMapper;
import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
/**
* 公众号推送任务 服务层实现
@ -31,12 +36,15 @@ import java.time.LocalDateTime;
* @author ww
* @since 2025-10-20
*/
@Slf4j
@Service
public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPushEvent> implements AcPushEventService {
@Resource
private SmsPushEventUserMapper eventUserMapper;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
private SysParamsService paramsService;
@Resource
private MkShopCouponRecordService couponRecordService;
@Resource
@ -80,6 +88,7 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
} else {
param.setSendTime(LocalDateTime.now());
}
checkPushEventSendCount(param.getShopId());
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
save(pushEvent);
if (param.getUserType() == 2) {
@ -127,6 +136,7 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
} else {
param.setSendTime(LocalDateTime.now());
}
checkPushEventSendCount(param.getShopId());
AcPushEvent pushEvent = BeanUtil.toBean(param, AcPushEvent.class);
updateById(pushEvent);
eventUserMapper.deleteByQuery(new QueryWrapper()
@ -158,4 +168,32 @@ public class AcPushEventServiceImpl extends ServiceImpl<AcPushEventMapper, AcPus
pushEvent.setIsDel(1);
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 + "条,不能继续发送");
}
}
}