feat(gao): support customer birthdate followup reminder
This commit is contained in:
@@ -24,4 +24,13 @@ public interface SettingEnum {
|
||||
String getDefaultValue();
|
||||
|
||||
Setting.ValueType getValueType();
|
||||
|
||||
/// 配置作用域
|
||||
///
|
||||
/// 业务级配置由业务对象自己维护,启动时不初始化记录
|
||||
///
|
||||
/// @return 配置作用域
|
||||
default Setting.Scope getScope() {
|
||||
return Setting.Scope.SYSTEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,19 @@ public class Setting extends UUIDEntity {
|
||||
JSON_OBJECT
|
||||
}
|
||||
|
||||
/// 配置作用域
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-16
|
||||
public enum Scope {
|
||||
|
||||
/// 系统级,bizId 固定为全零 UUID,启动时自动初始化
|
||||
SYSTEM,
|
||||
|
||||
/// 业务级,bizId 为业务对象 ID,启动时不初始化
|
||||
BUSINESS
|
||||
}
|
||||
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String bizType;
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.imyeyu.api.modules.gao.bean;
|
||||
|
||||
import com.imyeyu.api.annotation.SettingBizType;
|
||||
import com.imyeyu.api.bean.SettingEnum;
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/// GAO 门店配置
|
||||
///
|
||||
/// 门店级配置,bizId 为门店 ID
|
||||
/// 启动时的内建配置初始化只覆盖系统级配置,门店配置查不到记录时按默认值兜底
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@Getter
|
||||
@SettingBizType("GAO_STORE")
|
||||
@AllArgsConstructor
|
||||
public enum GaoStoreSetting implements SettingEnum {
|
||||
|
||||
/// 客户生日提醒开关
|
||||
CUSTOMER_BIRTHDAY_REMINDER_ENABLED(Boolean.FALSE.toString(), Setting.ValueType.BOOLEAN, "true 为启用客户生日提醒"),
|
||||
|
||||
/// 客户生日提醒负责人
|
||||
CUSTOMER_BIRTHDAY_REMINDER_RESPONSIBLE_USER_ID(null, Setting.ValueType.STRING, "客户生日提醒的负责人用户 ID");
|
||||
|
||||
final String defaultValue;
|
||||
|
||||
final Setting.ValueType valueType;
|
||||
|
||||
final String description;
|
||||
|
||||
/// 门店配置属于业务级配置,bizId 为门店 ID,启动时不初始化记录
|
||||
///
|
||||
/// @return 业务级作用域
|
||||
@Override
|
||||
public Setting.Scope getScope() {
|
||||
return Setting.Scope.BUSINESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.imyeyu.api.annotation.RequireCorePermission;
|
||||
import com.imyeyu.api.bean.CorePermissionCode;
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreSettingService;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/// GAO 门店配置接口
|
||||
///
|
||||
/// 门店配置固定读写当前登录用户所属门店,不接受请求指定门店
|
||||
/// 权限使用核心设置权限的读写,不额外引入 GAO 门店权限
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/gao/store/setting")
|
||||
public class GaoStoreSettingController {
|
||||
|
||||
private final GaoStoreSettingService service;
|
||||
private final GaoStoreService storeService;
|
||||
private final UserLoginService userLoginService;
|
||||
|
||||
/// 查询当前门店配置
|
||||
///
|
||||
/// 未配置的项返回默认值,不会创建记录
|
||||
///
|
||||
/// @param codeList 配置代码列表,为空返回全部
|
||||
/// @return 配置代码与配置的映射
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.SETTING_READ)
|
||||
@PostMapping("/map")
|
||||
public Map<String, Setting> map(@RequestBody(required = false) List<String> codeList) {
|
||||
return service.mapSetting(requireCurrentStoreId(), codeList);
|
||||
}
|
||||
|
||||
/// 保存当前门店配置
|
||||
///
|
||||
/// @param settingList 配置列表
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.SETTING_UPDATE)
|
||||
@PostMapping("/update")
|
||||
public void update(@RequestBody List<Setting> settingList) {
|
||||
service.updateSetting(requireCurrentStoreId(), settingList);
|
||||
}
|
||||
|
||||
/// 获取当前登录用户所属门店 ID
|
||||
///
|
||||
/// @return 门店 ID
|
||||
private String requireCurrentStoreId() {
|
||||
GaoStore store = storeService.getByUserId(userLoginService.getRequireLoginUserId());
|
||||
TimiException.required(store, "当前用户不属于任何门店");
|
||||
return store.getId();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.gao.entity;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
@@ -28,6 +29,16 @@ public class GaoCustomerFollowUpReminder extends UUIDEntity {
|
||||
COMPLETED
|
||||
}
|
||||
|
||||
/// 提醒来源
|
||||
public enum Source {
|
||||
|
||||
/// 手动创建
|
||||
MANUAL,
|
||||
|
||||
/// 系统创建
|
||||
SYSTEM
|
||||
}
|
||||
|
||||
/// 通知渠道
|
||||
public enum NotifyChannel {
|
||||
|
||||
@@ -56,6 +67,15 @@ public class GaoCustomerFollowUpReminder extends UUIDEntity {
|
||||
/// 提醒状态
|
||||
private Status status;
|
||||
|
||||
/// 来源
|
||||
private Source source;
|
||||
|
||||
/// 系统创建的幂等键,格式为 业务类型:业务维度,手动创建为空
|
||||
private String sourceKey;
|
||||
|
||||
/// 系统创建的扩展信息快照
|
||||
private JsonNode metadata;
|
||||
|
||||
/// true 为发送站内通知
|
||||
private Boolean internalNotifyEnabled;
|
||||
|
||||
|
||||
+15
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.gao.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomerFollowUpReminder;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerFollowUpReminderPage;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
@@ -50,4 +51,18 @@ public interface GaoCustomerFollowUpReminderMapper extends BaseMapper<GaoCustome
|
||||
/// @return 受影响行数
|
||||
int bindSmsNotifyDetailId(@Param("idList") Collection<String> idList,
|
||||
@Param("smsNotifyDetailId") String smsNotifyDetailId);
|
||||
|
||||
/// 查询指定门店的生日候选客户
|
||||
///
|
||||
/// 回填判断生日所需的字段,生日月日由调用方按历法计算,不在此处过滤
|
||||
///
|
||||
/// @param storeIdList 门店 ID 列表
|
||||
/// @return 生日候选客户
|
||||
List<GaoCustomer> selectBirthdayCandidate(@Param("storeIdList") Collection<String> storeIdList);
|
||||
|
||||
/// 创建系统提醒,幂等键冲突时跳过
|
||||
///
|
||||
/// @param reminder 提醒
|
||||
/// @return 受影响行数,0 为幂等键已存在
|
||||
int insertIgnore(GaoCustomerFollowUpReminder reminder);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ public interface GaoStoreMapper extends BaseMapper<GaoStore, String> {
|
||||
@Select("SELECT * FROM `gao_store` WHERE `auto_closed_day` = TRUE AND `status` = 'ACTIVE' " + NOT_DELETE)
|
||||
List<GaoStore> selectAllByAutoClosedDay();
|
||||
|
||||
/// 查询可用门店
|
||||
///
|
||||
/// @return 门店列表
|
||||
@Select("SELECT * FROM `gao_store` WHERE `status` = 'ACTIVE' " + NOT_DELETE)
|
||||
List<GaoStore> selectAllActivated();
|
||||
|
||||
/// 查询用户所属的可用门店
|
||||
///
|
||||
/// @param userId 用户 ID
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.imyeyu.api.modules.gao.service;
|
||||
|
||||
/// GAO 客户生日提醒生成服务
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
public interface GaoCustomerBirthdayReminderService {
|
||||
|
||||
/// 生成当天需要创建的生日提醒
|
||||
///
|
||||
/// 按门店配置筛选启用生日提醒的门店,为 7 天后过生日的客户提前创建跟进提醒
|
||||
/// 提醒时间取生日当天,站内通知和短信在生日当天发出
|
||||
///
|
||||
/// @return 实际创建数量
|
||||
int generate();
|
||||
}
|
||||
+15
@@ -1,8 +1,10 @@
|
||||
package com.imyeyu.api.modules.gao.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomerFollowUpReminder;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerFollowUpReminderPage;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerFollowUpReminderPageResult;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
/// GAO 客户跟进提醒服务
|
||||
@@ -34,6 +36,19 @@ public interface GaoCustomerFollowUpReminderService extends BaseService<GaoCusto
|
||||
/// @param id 跟进提醒 ID
|
||||
void complete(String id);
|
||||
|
||||
/// 为系统创建的提醒创建站内通知
|
||||
///
|
||||
/// 定时任务没有登录用户,站内通知的发送人使用系统用户
|
||||
///
|
||||
/// @param reminder 提醒,必须已持久化
|
||||
/// @param subject 通知主题
|
||||
/// @param content 通知正文
|
||||
/// @param contentType 正文类型
|
||||
/// @param responsibleUser 负责人
|
||||
/// @return 通知详情 ID
|
||||
String createSystemInternalNotify(GaoCustomerFollowUpReminder reminder, String subject, String content,
|
||||
NotifyDetail.ContentType contentType, User responsibleUser);
|
||||
|
||||
/// 创建当天的短信聚合批次
|
||||
void createSmsBatch();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ public interface GaoStoreService extends BaseService<GaoStore, String> {
|
||||
|
||||
List<GaoStore> listByAutoClosedDay();
|
||||
|
||||
/// 查询可用门店
|
||||
///
|
||||
/// @return 门店列表
|
||||
List<GaoStore> listActivated();
|
||||
|
||||
/// 按客户端提交的顺序更新排序
|
||||
///
|
||||
/// @param idList 门店 ID 列表
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.imyeyu.api.modules.gao.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreBirthdayReminderSetting;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/// GAO 门店配置服务
|
||||
///
|
||||
/// 门店配置属于业务级配置,bizId 为门店 ID,启动时不初始化记录
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
public interface GaoStoreSettingService {
|
||||
|
||||
/// 读取门店配置
|
||||
///
|
||||
/// 缺少记录的配置项返回带默认值的对象,不落库
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param codeList 配置代码列表,为空返回全部
|
||||
/// @return 配置代码与配置的映射
|
||||
Map<String, Setting> mapSetting(String storeId, Collection<String> codeList);
|
||||
|
||||
/// 保存门店配置
|
||||
///
|
||||
/// 合并写入,未提交的配置项保留
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param settingList 配置列表
|
||||
void updateSetting(String storeId, List<Setting> settingList);
|
||||
|
||||
/// 读取门店生日提醒配置
|
||||
///
|
||||
/// 用于定时任务判断是否生成提醒,包含负责人有效性
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @return 生日提醒配置
|
||||
GaoStoreBirthdayReminderSetting getBirthdayReminderSetting(String storeId);
|
||||
}
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
package com.imyeyu.api.modules.gao.service.implement;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomerFollowUpReminder;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoCustomerFollowUpReminderMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerBirthdayReminderService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerFollowUpReminderService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreSettingService;
|
||||
import com.imyeyu.api.modules.gao.util.LunarDate;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreBirthdayReminderSetting;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.utils.Time;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/// GAO 客户生日提醒生成服务实现
|
||||
///
|
||||
/// 定时任务没有登录用户,提醒的 created_by 和站内通知的发送人统一使用系统用户
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoCustomerBirthdayReminderServiceImplement implements GaoCustomerBirthdayReminderService {
|
||||
|
||||
/// 生日提前生成天数,记录提前进入待办列表,提醒时间取生日当天
|
||||
private static final int ADVANCE_DAYS = 7;
|
||||
|
||||
/// 生日当天的提醒时间点,站内通知和短信在该时间点发出
|
||||
private static final LocalTime REMIND_AT_TIME = LocalTime.of(8, 0);
|
||||
|
||||
/// 系统操作人用户 ID
|
||||
private static final String SYSTEM_USER_ID = TimiJava.ZERO_UUID;
|
||||
|
||||
/// 幂等键前缀,完整格式为 BIRTHDAY:年份
|
||||
private static final String SOURCE_KEY_PREFIX = "BIRTHDAY";
|
||||
|
||||
/// 元数据中的业务类型
|
||||
private static final String METADATA_BIZ_TYPE = "BIRTHDAY";
|
||||
|
||||
/// 站内信主题
|
||||
private static final String INTERNAL_SUBJECT = "客户生日提醒";
|
||||
|
||||
/// 站内信模板,正文支持跳转客户详情
|
||||
private static final String INTERNAL_TEMPLATE_NAME = "GaoCustomerBirthdayReminder.ftl";
|
||||
|
||||
/// 客户详情页路径
|
||||
private static final String CUSTOMER_DETAIL_PATH = "/management/customers";
|
||||
|
||||
private static final String ZONE_ID = "Asia/Shanghai";
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("MM-dd");
|
||||
|
||||
private final GaoCustomerFollowUpReminderMapper mapper;
|
||||
private final GaoCustomerFollowUpReminderService followUpReminderService;
|
||||
private final GaoStoreService storeService;
|
||||
private final GaoStoreSettingService storeSettingService;
|
||||
private final ObjectMapper jackson;
|
||||
private final Configuration freemarkerConfiguration;
|
||||
|
||||
/// 生成当天需要创建的生日提醒
|
||||
///
|
||||
/// 提前 7 天创建记录让待办提前可见,提醒时间取生日当天 08:00
|
||||
/// 站内通知和短信跟随提醒时间,在生日当天发出
|
||||
///
|
||||
/// @return 实际创建数量
|
||||
@Override
|
||||
public int generate() {
|
||||
ZoneId zoneId = ZoneId.of(ZONE_ID);
|
||||
LocalDate today = LocalDate.now(zoneId);
|
||||
LocalDate targetDate = today.plusDays(ADVANCE_DAYS);
|
||||
long remindAt = targetDate.atTime(REMIND_AT_TIME).atZone(zoneId).toInstant().toEpochMilli();
|
||||
Map<String, GaoStoreBirthdayReminderSetting> settingMap = loadEnabledSettingMap();
|
||||
if (settingMap.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
List<GaoCustomer> candidateList = mapper.selectBirthdayCandidate(settingMap.keySet());
|
||||
if (candidateList.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
String sourceKey = "%s:%d".formatted(SOURCE_KEY_PREFIX, targetDate.getYear());
|
||||
int created = 0;
|
||||
for (GaoCustomer customer : candidateList) {
|
||||
GaoStoreBirthdayReminderSetting setting = settingMap.get(customer.getStoreId());
|
||||
if (setting == null) {
|
||||
continue;
|
||||
}
|
||||
if (!LunarDate.isBirthday(targetDate, customer.getBirthdate(), customer.getBirthdateCalendar())) {
|
||||
continue;
|
||||
}
|
||||
GaoCustomerFollowUpReminder reminder = buildReminder(customer, setting, targetDate, remindAt, sourceKey);
|
||||
if (0 >= mapper.insertIgnore(reminder)) {
|
||||
continue;
|
||||
}
|
||||
created++;
|
||||
fillInternalNotify(reminder, customer, setting, targetDate);
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
/// 加载启用生日提醒的门店配置
|
||||
///
|
||||
/// 负责人不是门店启用中的用户时跳过该门店,避免提醒落到无效用户
|
||||
///
|
||||
/// @return 门店 ID 与配置的映射
|
||||
private Map<String, GaoStoreBirthdayReminderSetting> loadEnabledSettingMap() {
|
||||
List<GaoStore> storeList = storeService.listActivated();
|
||||
Map<String, GaoStoreBirthdayReminderSetting> map = new LinkedHashMap<>(storeList.size());
|
||||
for (GaoStore store : storeList) {
|
||||
GaoStoreBirthdayReminderSetting setting = storeSettingService.getBirthdayReminderSetting(store.getId());
|
||||
if (!Boolean.TRUE.equals(setting.getEnabled())) {
|
||||
continue;
|
||||
}
|
||||
if (!Boolean.TRUE.equals(setting.getResponsibleUserValid())) {
|
||||
log.warn("GAO 客户生日提醒跳过门店 {},负责人 {} 不是门店启用中的用户",
|
||||
store.getId(), setting.getResponsibleUserId());
|
||||
continue;
|
||||
}
|
||||
map.put(store.getId(), setting);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// 构建生日提醒
|
||||
///
|
||||
/// @param customer 客户
|
||||
/// @param setting 门店配置
|
||||
/// @param targetDate 生日当天
|
||||
/// @param remindAt 提醒时间
|
||||
/// @param sourceKey 幂等键
|
||||
/// @return 提醒
|
||||
private GaoCustomerFollowUpReminder buildReminder(GaoCustomer customer, GaoStoreBirthdayReminderSetting setting,
|
||||
LocalDate targetDate, long remindAt, String sourceKey) {
|
||||
GaoCustomerFollowUpReminder reminder = new GaoCustomerFollowUpReminder();
|
||||
reminder.setId(UUID.randomUUID().toString());
|
||||
reminder.setStoreId(customer.getStoreId());
|
||||
reminder.setCustomerId(customer.getId());
|
||||
reminder.setResponsibleUserId(setting.getResponsibleUserId());
|
||||
reminder.setContent(buildContent(customer, targetDate));
|
||||
reminder.setRemindAt(remindAt);
|
||||
reminder.setStatus(GaoCustomerFollowUpReminder.Status.PENDING);
|
||||
reminder.setSource(GaoCustomerFollowUpReminder.Source.SYSTEM);
|
||||
reminder.setSourceKey(sourceKey);
|
||||
reminder.setMetadata(buildMetadata(customer, targetDate));
|
||||
reminder.setInternalNotifyEnabled(true);
|
||||
reminder.setSmsNotifyEnabled(true);
|
||||
reminder.setCreatedBy(SYSTEM_USER_ID);
|
||||
reminder.setCreatedAt(Time.now());
|
||||
return reminder;
|
||||
}
|
||||
|
||||
/// 构建提醒内容
|
||||
///
|
||||
/// 记录会提前进入待办列表并跨多天展示,正文不写相对天数,只写生日当天日期
|
||||
///
|
||||
/// @param customer 客户
|
||||
/// @param targetDate 生日当天
|
||||
/// @return 提醒内容
|
||||
private String buildContent(GaoCustomer customer, LocalDate targetDate) {
|
||||
String name = TimiJava.isEmpty(customer.getName()) ? "未知客户" : customer.getName().trim();
|
||||
String dateText = targetDate.format(DATE_FORMATTER);
|
||||
if (isLunar(customer)) {
|
||||
return "客户「%s」生日 %s(%s),请安排关怀"
|
||||
.formatted(name, dateText, LunarDate.formatLunarMonthDay(targetDate));
|
||||
}
|
||||
return "客户「%s」生日 %s,请安排关怀".formatted(name, dateText);
|
||||
}
|
||||
|
||||
/// 构建提醒元数据快照
|
||||
///
|
||||
/// @param customer 客户
|
||||
/// @param targetDate 生日当天
|
||||
/// @return 元数据
|
||||
private ObjectNode buildMetadata(GaoCustomer customer, LocalDate targetDate) {
|
||||
ObjectNode node = jackson.createObjectNode();
|
||||
node.put("bizType", METADATA_BIZ_TYPE);
|
||||
node.put("birthdaySolar", targetDate.toString());
|
||||
boolean lunar = isLunar(customer);
|
||||
node.put("birthdayCalendar", lunar ? "LUNAR" : "SOLAR");
|
||||
if (lunar) {
|
||||
node.put("birthdayLunar", LunarDate.formatLunarMonthDay(targetDate));
|
||||
node.put("leapMonth", LunarDate.isLeapMonth(targetDate));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/// 补齐站内通知
|
||||
///
|
||||
/// 正文走模板渲染,比短信更完整,且带客户详情跳转
|
||||
/// 单条通知失败不影响其余记录生成,提醒本身已经落库
|
||||
///
|
||||
/// @param reminder 提醒
|
||||
/// @param customer 客户
|
||||
/// @param setting 门店配置
|
||||
/// @param targetDate 生日当天
|
||||
private void fillInternalNotify(GaoCustomerFollowUpReminder reminder, GaoCustomer customer,
|
||||
GaoStoreBirthdayReminderSetting setting, LocalDate targetDate) {
|
||||
if (!Boolean.TRUE.equals(reminder.getInternalNotifyEnabled()) || setting.getResponsibleUser() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String detailId = followUpReminderService.createSystemInternalNotify(reminder, INTERNAL_SUBJECT,
|
||||
buildInternalNotifyContent(customer, targetDate), NotifyDetail.ContentType.TIP_TAP,
|
||||
setting.getResponsibleUser());
|
||||
if (TimiJava.isEmpty(detailId)) {
|
||||
return;
|
||||
}
|
||||
reminder.setInternalNotifyDetailId(detailId);
|
||||
mapper.update(reminder);
|
||||
} catch (Exception e) {
|
||||
log.error("GAO 客户生日提醒创建站内通知失败,提醒 {}", reminder.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/// 渲染站内通知正文
|
||||
///
|
||||
/// @param customer 客户
|
||||
/// @param targetDate 生日当天
|
||||
/// @return 渲染后的正文
|
||||
private String buildInternalNotifyContent(GaoCustomer customer, LocalDate targetDate) {
|
||||
Map<String, Object> model = new LinkedHashMap<>();
|
||||
model.put("customerName", TimiJava.isEmpty(customer.getName()) ? "未知客户" : customer.getName().trim());
|
||||
model.put("birthdayText", targetDate.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
model.put("lunarText", isLunar(customer) ? "农历" + LunarDate.formatLunarMonthDay(targetDate) : null);
|
||||
model.put("telephone", customer.getTelephone());
|
||||
model.put("disease", customer.getDisease());
|
||||
model.put("remark", customer.getRemark());
|
||||
model.put("customerUrl", "%s/%s".formatted(CUSTOMER_DETAIL_PATH, customer.getId()));
|
||||
try {
|
||||
Template template = freemarkerConfiguration.getTemplate(INTERNAL_TEMPLATE_NAME);
|
||||
StringWriter writer = new StringWriter();
|
||||
template.process(model, writer);
|
||||
return writer.toString();
|
||||
} catch (IOException | TemplateException e) {
|
||||
throw new IllegalStateException("渲染客户生日提醒站内信模板失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// 判断客户是否按农历过生日
|
||||
///
|
||||
/// @param customer 客户
|
||||
/// @return true 为农历生日
|
||||
private boolean isLunar(GaoCustomer customer) {
|
||||
return customer.getBirthdateCalendar() == GaoCustomer.BirthdateCalendar.LUNAR;
|
||||
}
|
||||
}
|
||||
+43
-11
@@ -108,6 +108,10 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
Boolean.TRUE.equals(reminder.getSmsNotifyEnabled()));
|
||||
|
||||
reminder.setStatus(GaoCustomerFollowUpReminder.Status.PENDING);
|
||||
// 来源和系统扩展字段只由系统任务写入,忽略请求值
|
||||
reminder.setSource(GaoCustomerFollowUpReminder.Source.MANUAL);
|
||||
reminder.setSourceKey(null);
|
||||
reminder.setMetadata(null);
|
||||
reminder.setCreatedBy(userLoginService.getRequireLoginUserId());
|
||||
reminder.setUpdatedBy(null);
|
||||
reminder.setCompletedBy(null);
|
||||
@@ -116,7 +120,9 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER_FOLLOW_UP_REMINDER,
|
||||
reminder.getId(), reminder.getAttachmentList());
|
||||
if (Boolean.TRUE.equals(reminder.getInternalNotifyEnabled())) {
|
||||
reminder.setInternalNotifyDetailId(createInternalNotify(reminder, customer, responsibleUser));
|
||||
reminder.setInternalNotifyDetailId(createInternalNotify(reminder, "客户跟进提醒",
|
||||
buildInternalContent(customer, reminder), NotifyDetail.ContentType.TEXT,
|
||||
responsibleUser, userLoginService.getRequireLoginUserId()));
|
||||
super.update(reminder);
|
||||
}
|
||||
reminder.resolveNotifyChannelList();
|
||||
@@ -194,6 +200,27 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
super.delete(id);
|
||||
}
|
||||
|
||||
/// 为系统创建的提醒创建站内通知
|
||||
///
|
||||
/// @param reminder 提醒
|
||||
/// @param subject 通知主题
|
||||
/// @param content 通知正文
|
||||
/// @param contentType 正文类型
|
||||
/// @param responsibleUser 负责人
|
||||
/// @return 通知详情 ID
|
||||
@Override
|
||||
public String createSystemInternalNotify(GaoCustomerFollowUpReminder reminder, String subject, String content,
|
||||
NotifyDetail.ContentType contentType, User responsibleUser) {
|
||||
TimiException.required(reminder, "未找到客户跟进提醒");
|
||||
TimiException.required(reminder.getId(), "未找到客户跟进提醒 ID");
|
||||
TimiException.required(subject, "未找到通知主题");
|
||||
TimiException.required(content, "未找到通知内容");
|
||||
TimiException.required(responsibleUser, "未找到负责人用户");
|
||||
return createInternalNotify(reminder, subject, content,
|
||||
TimiJava.defaultIfNull(contentType, NotifyDetail.ContentType.TEXT),
|
||||
responsibleUser, TimiJava.ZERO_UUID);
|
||||
}
|
||||
|
||||
/// 创建当天的短信聚合批次
|
||||
@Override
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@@ -352,7 +379,9 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
NotifyDetail detail = TimiJava.isEmpty(reminder.getInternalNotifyDetailId())
|
||||
? null : notifyDetailService.get(reminder.getInternalNotifyDetailId());
|
||||
if (!oldInternalEnabled || detail == null || detail.getStatus() == NotifyDetail.Status.CANCEL) {
|
||||
reminder.setInternalNotifyDetailId(createInternalNotify(reminder, customer, responsibleUser));
|
||||
reminder.setInternalNotifyDetailId(createInternalNotify(reminder, "客户跟进提醒",
|
||||
buildInternalContent(customer, reminder), NotifyDetail.ContentType.TEXT,
|
||||
responsibleUser, userLoginService.getRequireLoginUserId()));
|
||||
return;
|
||||
}
|
||||
if (detail.getMsgType() == NotifyDetail.MsgType.INTERNAL
|
||||
@@ -367,17 +396,20 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
/// 创建站内通知
|
||||
///
|
||||
/// @param reminder 跟进提醒
|
||||
/// @param customer 客户
|
||||
/// @param subject 通知主题
|
||||
/// @param content 通知正文
|
||||
/// @param contentType 正文类型
|
||||
/// @param responsibleUser 负责人
|
||||
/// @param operatorUserId 操作人用户 ID
|
||||
/// @return 通知详情 ID
|
||||
private String createInternalNotify(GaoCustomerFollowUpReminder reminder, GaoCustomer customer,
|
||||
User responsibleUser) {
|
||||
private String createInternalNotify(GaoCustomerFollowUpReminder reminder, String subject, String content,
|
||||
NotifyDetail.ContentType contentType, User responsibleUser, String operatorUserId) {
|
||||
NotifyDetail detail = new NotifyDetail();
|
||||
detail.setMsgType(NotifyDetail.MsgType.INTERNAL);
|
||||
detail.setSubject("客户跟进提醒");
|
||||
detail.setContent(buildInternalContent(customer, reminder));
|
||||
detail.setContentType(NotifyDetail.ContentType.TEXT);
|
||||
detail.setSendFrom(userLoginService.getRequireLoginUserId());
|
||||
detail.setSubject(subject);
|
||||
detail.setContent(content);
|
||||
detail.setContentType(contentType);
|
||||
detail.setSendFrom(operatorUserId);
|
||||
detail.setSendTo(responsibleUser.getId());
|
||||
detail.setSendAt(reminder.getRemindAt());
|
||||
detail.setTimeoutAt(reminder.getRemindAt() + Time.D);
|
||||
@@ -397,7 +429,7 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
notify.setBizType(NOTIFY_BIZ_TYPE);
|
||||
notify.setBizRemindedType(INTERNAL_NOTIFY_TYPE);
|
||||
notify.setBizRemindedKey(reminder.getId());
|
||||
notify.setCreatedBy(userLoginService.getRequireLoginUserId());
|
||||
notify.setCreatedBy(operatorUserId);
|
||||
notify.setDetailList(List.of(detail));
|
||||
notifyService.create(notify);
|
||||
} else {
|
||||
@@ -415,7 +447,7 @@ public class GaoCustomerFollowUpReminderServiceImplement extends AbstractEntityS
|
||||
private String buildInternalContent(GaoCustomer customer, GaoCustomerFollowUpReminder reminder) {
|
||||
String content = reminder.getContent();
|
||||
String summary = content.length() <= 100 ? content : content.substring(0, 100) + "...";
|
||||
return "客户「%s」跟进提醒:%s\n提醒 ID:%s".formatted(customer.getName(), summary, reminder.getId());
|
||||
return "客户「%s」跟进提醒:%s".formatted(customer.getName(), summary);
|
||||
}
|
||||
|
||||
/// 取消尚未生效的站内通知
|
||||
|
||||
+8
@@ -200,6 +200,14 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
|
||||
return mapper.selectAllByAutoClosedDay();
|
||||
}
|
||||
|
||||
/// 查询可用门店
|
||||
///
|
||||
/// @return 门店列表
|
||||
@Override
|
||||
public List<GaoStore> listActivated() {
|
||||
return mapper.selectAllActivated();
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@OperationAudit(AuditOperation.GAO_STORE_SORT)
|
||||
@Override
|
||||
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
package com.imyeyu.api.modules.gao.service.implement;
|
||||
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
import com.imyeyu.api.modules.common.service.SettingService;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoStoreSetting;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoUserMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreSettingService;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoStoreBirthdayReminderSetting;
|
||||
import com.imyeyu.api.modules.system.audit.AuditOperation;
|
||||
import com.imyeyu.api.modules.system.audit.OperationAudit;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/// GAO 门店配置服务实现
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoStoreSettingServiceImplement implements GaoStoreSettingService {
|
||||
|
||||
/// 门店配置的业务类型
|
||||
private static final String BIZ_TYPE = GaoStoreSetting.CUSTOMER_BIRTHDAY_REMINDER_ENABLED.getBizType();
|
||||
|
||||
private final SettingService settingService;
|
||||
private final GaoStoreService storeService;
|
||||
private final GaoUserMapper gaoUserMapper;
|
||||
private final UserService userService;
|
||||
|
||||
/// 读取门店配置
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param codeList 配置代码列表
|
||||
/// @return 配置代码与配置的映射
|
||||
@Override
|
||||
public Map<String, Setting> mapSetting(String storeId, Collection<String> codeList) {
|
||||
TimiException.required(storeId, "未找到门店 ID");
|
||||
Map<String, Setting> dbMap = new LinkedHashMap<>();
|
||||
for (Setting dbSetting : settingService.listByBizId(BIZ_TYPE, storeId)) {
|
||||
dbMap.put(dbSetting.getCode(), dbSetting);
|
||||
}
|
||||
Map<String, Setting> result = new LinkedHashMap<>(GaoStoreSetting.values().length);
|
||||
for (GaoStoreSetting key : GaoStoreSetting.values()) {
|
||||
if (TimiJava.isNotEmpty(codeList) && !codeList.contains(key.name())) {
|
||||
continue;
|
||||
}
|
||||
Setting dbSetting = dbMap.get(key.name());
|
||||
result.put(key.name(), dbSetting == null ? buildDefaultSetting(key) : dbSetting);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 保存门店配置
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param settingList 配置列表
|
||||
@Override
|
||||
@OperationAudit(AuditOperation.GAO_STORE_SETTING_UPDATE)
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
public void updateSetting(String storeId, List<Setting> settingList) {
|
||||
TimiException.required(storeId, "未找到门店 ID");
|
||||
TimiException.required(storeService.get(storeId), "未找到门店");
|
||||
Map<String, Setting> mergedMap = new LinkedHashMap<>();
|
||||
for (Setting dbSetting : settingService.listByBizId(BIZ_TYPE, storeId)) {
|
||||
mergedMap.put(dbSetting.getCode(), dbSetting);
|
||||
}
|
||||
for (Setting request : TimiJava.safeIterable(settingList)) {
|
||||
TimiException.required(request, "未找到配置项");
|
||||
GaoStoreSetting key = requireKey(request.getCode());
|
||||
Setting merged = mergedMap.get(key.name());
|
||||
if (merged == null) {
|
||||
merged = buildDefaultSetting(key);
|
||||
mergedMap.put(key.name(), merged);
|
||||
}
|
||||
merged.setValue(request.getValue());
|
||||
}
|
||||
validateBirthdayReminder(storeId, mergedMap);
|
||||
List<Setting> saveList = new ArrayList<>(mergedMap.values());
|
||||
for (Setting item : saveList) {
|
||||
GaoStoreSetting key = requireKey(item.getCode());
|
||||
item.setBizType(BIZ_TYPE);
|
||||
item.setBizId(storeId);
|
||||
item.setCode(key.name());
|
||||
item.setDescription(key.getDescription());
|
||||
item.setValueType(key.getValueType());
|
||||
// 门店配置固定私有,不接受前端控制
|
||||
item.setIsPrivate(true);
|
||||
}
|
||||
settingService.updateByBizId(BIZ_TYPE, storeId, saveList);
|
||||
}
|
||||
|
||||
/// 读取门店生日提醒配置
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @return 生日提醒配置
|
||||
@Override
|
||||
public GaoStoreBirthdayReminderSetting getBirthdayReminderSetting(String storeId) {
|
||||
GaoStoreBirthdayReminderSetting setting = new GaoStoreBirthdayReminderSetting();
|
||||
setting.setStoreId(storeId);
|
||||
if (TimiJava.isEmpty(storeId)) {
|
||||
setting.setEnabled(false);
|
||||
setting.setResponsibleUserValid(false);
|
||||
return setting;
|
||||
}
|
||||
setting.setEnabled(readBoolean(storeId, GaoStoreSetting.CUSTOMER_BIRTHDAY_REMINDER_ENABLED));
|
||||
String responsibleUserId = readString(storeId, GaoStoreSetting.CUSTOMER_BIRTHDAY_REMINDER_RESPONSIBLE_USER_ID);
|
||||
setting.setResponsibleUserId(responsibleUserId);
|
||||
User responsibleUser = TimiJava.isEmpty(responsibleUserId) ? null : userService.get(responsibleUserId);
|
||||
setting.setResponsibleUser(responsibleUser);
|
||||
setting.setResponsibleUserValid(responsibleUser != null && isStoreEnabledUser(storeId, responsibleUserId));
|
||||
return setting;
|
||||
}
|
||||
|
||||
/// 校验生日提醒的配置组合
|
||||
///
|
||||
/// 启用时必须存在有效负责人,否则提醒会落到无效用户
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param settingMap 合并后的配置
|
||||
private void validateBirthdayReminder(String storeId, Map<String, Setting> settingMap) {
|
||||
Setting enabledSetting = settingMap.get(GaoStoreSetting.CUSTOMER_BIRTHDAY_REMINDER_ENABLED.name());
|
||||
if (enabledSetting == null || !enabledSetting.isTrue()) {
|
||||
return;
|
||||
}
|
||||
Setting responsibleSetting = settingMap.get(
|
||||
GaoStoreSetting.CUSTOMER_BIRTHDAY_REMINDER_RESPONSIBLE_USER_ID.name());
|
||||
String responsibleUserId = responsibleSetting == null ? null : responsibleSetting.asString();
|
||||
TimiException.required(responsibleUserId, "启用生日提醒时必须指定负责人");
|
||||
TimiException.requiredTrue(isStoreEnabledUser(storeId, responsibleUserId),
|
||||
"负责人不是当前门店启用中的 GAO 用户");
|
||||
}
|
||||
|
||||
/// 按配置代码查找配置项
|
||||
///
|
||||
/// @param code 配置代码
|
||||
/// @return 配置项
|
||||
private GaoStoreSetting requireKey(String code) {
|
||||
GaoStoreSetting key = Arrays.stream(GaoStoreSetting.values())
|
||||
.filter(item -> item.name().equals(code))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
TimiException.required(key, "不支持的配置项 %s".formatted(code));
|
||||
return key;
|
||||
}
|
||||
|
||||
/// 构建带默认值的配置对象
|
||||
///
|
||||
/// @param key 配置项
|
||||
/// @return 配置
|
||||
private Setting buildDefaultSetting(GaoStoreSetting key) {
|
||||
Setting setting = new Setting();
|
||||
setting.setBizType(BIZ_TYPE);
|
||||
setting.setCode(key.name());
|
||||
setting.setDescription(key.getDescription());
|
||||
setting.setValue(key.getDefaultValue());
|
||||
setting.setValueType(key.getValueType());
|
||||
setting.setIsPrivate(true);
|
||||
return setting;
|
||||
}
|
||||
|
||||
/// 读取布尔配置,缺少记录时使用默认值
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param key 配置项
|
||||
/// @return 配置值
|
||||
private boolean readBoolean(String storeId, GaoStoreSetting key) {
|
||||
Setting dbSetting = settingService.getByCode(BIZ_TYPE, storeId, key.name());
|
||||
if (dbSetting == null) {
|
||||
return Boolean.parseBoolean(key.getDefaultValue());
|
||||
}
|
||||
return dbSetting.isTrue();
|
||||
}
|
||||
|
||||
/// 读取字符串配置,缺少记录或空值时使用默认值
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param key 配置项
|
||||
/// @return 配置值
|
||||
private String readString(String storeId, GaoStoreSetting key) {
|
||||
Setting dbSetting = settingService.getByCode(BIZ_TYPE, storeId, key.name());
|
||||
String value = dbSetting == null ? null : dbSetting.asString();
|
||||
return TimiJava.isEmpty(value) ? key.getDefaultValue() : value;
|
||||
}
|
||||
|
||||
/// 判断用户是否为目标门店启用中的 GAO 用户
|
||||
///
|
||||
/// @param storeId 门店 ID
|
||||
/// @param userId 用户 ID
|
||||
/// @return true 为启用中的门店用户
|
||||
private boolean isStoreEnabledUser(String storeId, String userId) {
|
||||
if (TimiJava.isEmpty(userId)) {
|
||||
return false;
|
||||
}
|
||||
GaoUser example = new GaoUser();
|
||||
example.setStoreId(storeId);
|
||||
example.setUserId(userId);
|
||||
example.setEnabled(true);
|
||||
return gaoUserMapper.selectByExample(example) != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.imyeyu.api.modules.gao.task;
|
||||
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerBirthdayReminderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/// GAO 客户生日提醒定时任务
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GaoCustomerBirthdayReminderTask {
|
||||
|
||||
private static final String ZONE_ID = "Asia/Shanghai";
|
||||
|
||||
private final GaoCustomerBirthdayReminderService service;
|
||||
|
||||
/// 每天早上七点生成生日提醒
|
||||
///
|
||||
/// 为 7 天后过生日的客户提前创建记录,提醒时间取生日当天八点
|
||||
/// 站内通知在生日当天八点发送,短信由生日当天八点开始的短信批次任务聚合
|
||||
/// cron 可通过 gao.customer.birthday-reminder.cron 覆盖,便于开发环境验证
|
||||
@Scheduled(cron = "${gao.customer.birthday-reminder.cron:0 0 7 * * ?}", zone = ZONE_ID)
|
||||
public void generate() {
|
||||
try {
|
||||
service.generate();
|
||||
} catch (Exception e) {
|
||||
log.error("GAO 客户生日提醒生成失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.imyeyu.api.modules.gao.util;
|
||||
|
||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.LunarYear;
|
||||
import com.nlf.calendar.Solar;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/// 农历生日工具
|
||||
///
|
||||
/// 数据库只保存公历出生日期,农历客户的农历月日由公历反推
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
public final class LunarDate {
|
||||
|
||||
private LunarDate() {
|
||||
}
|
||||
|
||||
/// 判断目标公历日期是否为客户生日
|
||||
///
|
||||
/// 公历客户按公历月日匹配,2 月 29 日在平年按 2 月 28 日提醒
|
||||
/// 农历客户按农历月日匹配,闰月生日在当年没有该闰月时按普通月提醒,保证每年最多提醒一次
|
||||
///
|
||||
/// @param target 目标公历日期
|
||||
/// @param birthdate 客户出生日期,公历
|
||||
/// @param calendar 出生日期录入历法
|
||||
/// @return true 为目标客户的生日
|
||||
public static boolean isBirthday(LocalDate target, LocalDate birthdate, GaoCustomer.BirthdateCalendar calendar) {
|
||||
if (target == null || birthdate == null) {
|
||||
return false;
|
||||
}
|
||||
if (calendar == GaoCustomer.BirthdateCalendar.LUNAR) {
|
||||
return isLunarBirthday(target, birthdate);
|
||||
}
|
||||
int monthValue = birthdate.getMonthValue();
|
||||
int dayOfMonth = birthdate.getDayOfMonth();
|
||||
if (monthValue == 2 && dayOfMonth == 29) {
|
||||
return target.getMonthValue() == 2 && target.getDayOfMonth() == (target.isLeapYear() ? 29 : 28);
|
||||
}
|
||||
return target.getMonthValue() == monthValue && target.getDayOfMonth() == dayOfMonth;
|
||||
}
|
||||
|
||||
/// 判断目标公历日期是否命中农历生日
|
||||
///
|
||||
/// @param target 目标公历日期
|
||||
/// @param birthdate 客户出生日期
|
||||
/// @return true 为农历生日
|
||||
private static boolean isLunarBirthday(LocalDate target, LocalDate birthdate) {
|
||||
Lunar birthLunar = toLunar(birthdate);
|
||||
Lunar targetLunar = toLunar(target);
|
||||
int birthMonth = Math.abs(birthLunar.getMonth());
|
||||
if (birthMonth != Math.abs(targetLunar.getMonth()) || birthLunar.getDay() != targetLunar.getDay()) {
|
||||
return false;
|
||||
}
|
||||
// 农历月为负数表示闰月
|
||||
boolean birthLeap = 0 > birthLunar.getMonth();
|
||||
boolean targetLeap = 0 > targetLunar.getMonth();
|
||||
if (!birthLeap) {
|
||||
// 普通月生日,闰月的同月同日不算生日
|
||||
return !targetLeap;
|
||||
}
|
||||
// 闰月生日,当年存在该闰月时只认闰月,否则按普通月提醒
|
||||
boolean hasLeapMonth = birthMonth == LunarYear.fromYear(target.getYear()).getLeapMonth();
|
||||
return hasLeapMonth == targetLeap;
|
||||
}
|
||||
|
||||
/// 公历转换为农历
|
||||
///
|
||||
/// @param date 公历日期
|
||||
/// @return 农历
|
||||
public static Lunar toLunar(LocalDate date) {
|
||||
return Solar.fromYmd(date.getYear(), date.getMonthValue(), date.getDayOfMonth()).getLunar();
|
||||
}
|
||||
|
||||
/// 格式化为农历月日
|
||||
///
|
||||
/// @param date 公历日期
|
||||
/// @return 农历月日,如「冬月初八」「闰五月初一」
|
||||
public static String formatLunarMonthDay(LocalDate date) {
|
||||
Lunar lunar = toLunar(date);
|
||||
return "%s月%s".formatted(lunar.getMonthInChinese(), lunar.getDayInChinese());
|
||||
}
|
||||
|
||||
/// 判断公历日期所在年的农历是否闰月
|
||||
///
|
||||
/// @param date 公历日期
|
||||
/// @return true 为闰月
|
||||
public static boolean isLeapMonth(LocalDate date) {
|
||||
return 0 > toLunar(date).getMonth();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.imyeyu.api.modules.gao.vo;
|
||||
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import lombok.Data;
|
||||
|
||||
/// GAO 门店客户生日提醒配置
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-15
|
||||
@Data
|
||||
public class GaoStoreBirthdayReminderSetting {
|
||||
|
||||
/// 门店 ID
|
||||
private String storeId;
|
||||
|
||||
/// true 为启用客户生日提醒
|
||||
private Boolean enabled;
|
||||
|
||||
/// 负责人用户 ID
|
||||
private String responsibleUserId;
|
||||
|
||||
/// 负责人用户
|
||||
private User responsibleUser;
|
||||
|
||||
/// true 为负责人仍是当前门店启用中的 GAO 用户
|
||||
private Boolean responsibleUserValid;
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public enum AuditOperation {
|
||||
GAO_STORE_UPDATE(Logger.Module.GAO),
|
||||
GAO_STORE_DELETE(Logger.Module.GAO),
|
||||
GAO_STORE_SORT(Logger.Module.GAO),
|
||||
GAO_STORE_SETTING_UPDATE(Logger.Module.GAO),
|
||||
GAO_CUSTOMER_FOLLOW_UP_REMINDER_CREATE(Logger.Module.GAO),
|
||||
GAO_CUSTOMER_FOLLOW_UP_REMINDER_UPDATE(Logger.Module.GAO),
|
||||
GAO_CUSTOMER_FOLLOW_UP_REMINDER_COMPLETE(Logger.Module.GAO),
|
||||
|
||||
@@ -41,6 +41,10 @@ public class InitBuiltinSetting implements ApplicationRunner {
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
for (SettingEnum item : findSettingEnumList()) {
|
||||
if (item.getScope() != Setting.Scope.SYSTEM) {
|
||||
// 业务级配置由业务对象自己维护,启动时不初始化
|
||||
continue;
|
||||
}
|
||||
if (settingService.getSystem(item) == null) {
|
||||
Setting setting = new Setting();
|
||||
setting.setBizType(item.getBizType());
|
||||
|
||||
Reference in New Issue
Block a user