v1.0.12 #19

Merged
timi merged 7 commits from dev into master 2026-08-12 17:02:43 +00:00
10 changed files with 104 additions and 11 deletions
Showing only changes of commit 5b9391a50a - Show all commits
@@ -48,6 +48,9 @@ public class GaoStore extends UUIDEntity {
/// 备注
private String remark;
/// true 为启用自动计算营业日休息日
private Boolean autoClosedDay;
/// 排序值
private Integer sort;
@@ -18,7 +18,7 @@ public class GaoStoreBusinessDay extends UUIDEntity {
///
/// @author Codex
/// @since 2026-08-06
public enum OpenStatus {
public enum Status {
/// 营业
OPEN,
@@ -34,7 +34,7 @@ public class GaoStoreBusinessDay extends UUIDEntity {
private Integer dateValue;
/// 营业状态
private OpenStatus openStatus;
private Status status;
/// 营业日递增序号,仅营业日有值
private Long businessDayNo;
@@ -3,6 +3,7 @@ package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoStore;
import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
@@ -16,6 +17,12 @@ public interface GaoStoreMapper extends BaseMapper<GaoStore, String> {
List<GaoStore> selectByIdList(@Param("idList") Collection<String> idList);
/// 查询启用自动计算营业日休息日的可用门店
///
/// @return 门店列表
@Select("SELECT * FROM `gao_store` WHERE `auto_closed_day` = TRUE AND `status` = 'ACTIVE' " + NOT_DELETE)
List<GaoStore> selectAllByAutoClosedDay();
/// 查询用户所属的可用门店
///
/// @param userId 用户 ID
@@ -23,6 +23,12 @@ public interface GaoStoreBusinessDayService extends BaseService<GaoStoreBusiness
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
void rebuildBusinessDayNo(String storeId, Integer beginDateValue);
/// 自动补记门店休息日
///
/// @param storeId 门店 ID
/// @param dateValue 日期值,格式为 yyyyMMdd
void autoCloseBusinessDay(String storeId, Integer dateValue);
/// 查询日期范围内的营业日
///
/// @param storeId 门店 ID
@@ -22,6 +22,8 @@ public interface GaoStoreService extends BaseService<GaoStore, String> {
String getBelongIdByRequiredLoginUserId();
List<GaoStore> listByAutoClosedDay();
/// 导出门店列表
///
/// @param page 分页查询条件
@@ -37,7 +37,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
public void create(GaoStoreBusinessDay businessDay) {
prepareBusinessDay(businessDay);
super.create(businessDay);
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN) {
rebuildBusinessDayNo(businessDay.getStoreId(), businessDay.getDateValue());
}
}
@@ -51,7 +51,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
TimiException.required(dbBusinessDay, "not found dbBusinessDay");
TimiException.requiredTrue(dbBusinessDay.getStoreId().equals(businessDay.getStoreId()), "businessDay.storeId invalid");
TimiException.requiredTrue(dbBusinessDay.getDateValue().equals(businessDay.getDateValue()), "businessDay.dateValue invalid");
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.CLOSED) {
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.CLOSED) {
checkNoRecord(dbBusinessDay);
}
prepareBusinessDay(businessDay);
@@ -64,7 +64,7 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
public void delete(String id) {
GaoStoreBusinessDay businessDay = get(id);
TimiException.required(businessDay, "not found businessDay");
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN) {
checkNoRecord(businessDay);
}
super.delete(id);
@@ -78,14 +78,14 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
TimiException.required(dateValue, "not found dateValue");
GaoStoreBusinessDay businessDay = mapper.selectByStoreIdAndDateValue(storeId, dateValue);
if (businessDay != null) {
TimiException.requiredTrue(businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN, "门店当日休息,不能登记");
TimiException.requiredTrue(businessDay.getStatus() == GaoStoreBusinessDay.Status.OPEN, "门店当日休息,不能登记");
TimiException.required(businessDay.getBusinessDayNo(), "not found businessDay.businessDayNo");
return businessDay;
}
businessDay = new GaoStoreBusinessDay();
businessDay.setStoreId(storeId);
businessDay.setDateValue(dateValue);
businessDay.setOpenStatus(GaoStoreBusinessDay.OpenStatus.OPEN);
businessDay.setStatus(GaoStoreBusinessDay.Status.OPEN);
super.create(businessDay);
rebuildBusinessDayNo(storeId, dateValue);
return mapper.selectByStoreIdAndDateValue(storeId, dateValue);
@@ -107,6 +107,26 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
}
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void autoCloseBusinessDay(String storeId, Integer dateValue) {
TimiException.required(storeId, "not found storeId");
TimiException.required(dateValue, "not found dateValue");
if (mapper.selectByStoreIdAndDateValue(storeId, dateValue) != null) {
return;
}
Long count = eventRecordMapper.countByStoreIdAndRegisteredDateValue(storeId, dateValue);
if (0 < TimiJava.defaultIfNull(count, 0L)) {
return;
}
GaoStoreBusinessDay businessDay = new GaoStoreBusinessDay();
businessDay.setStoreId(storeId);
businessDay.setDateValue(dateValue);
businessDay.setStatus(GaoStoreBusinessDay.Status.CLOSED);
businessDay.setReason("系统自动判定休息");
super.create(businessDay);
}
@Override
public List<GaoStoreBusinessDay> listByDateRange(String storeId, Integer beginDateValue, Integer endDateValue) {
TimiException.required(storeId, "not found storeId");
@@ -120,8 +140,8 @@ public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<G
TimiException.required(businessDay, "not found businessDay");
TimiException.required(businessDay.getStoreId(), "not found businessDay.storeId");
TimiException.required(businessDay.getDateValue(), "not found businessDay.dateValue");
businessDay.setOpenStatus(TimiJava.defaultIfNull(businessDay.getOpenStatus(), GaoStoreBusinessDay.OpenStatus.OPEN));
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.CLOSED) {
businessDay.setStatus(TimiJava.defaultIfNull(businessDay.getStatus(), GaoStoreBusinessDay.Status.OPEN));
if (businessDay.getStatus() == GaoStoreBusinessDay.Status.CLOSED) {
businessDay.setBusinessDayNo(null);
return;
}
@@ -62,6 +62,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
logger.setContent(jackson.writeValueAsString(store));
checkUnique(store);
store.setStatus(TimiJava.defaultIfNull(store.getStatus(), GaoStore.Status.ACTIVE));
store.setAutoClosedDay(TimiJava.defaultIfNull(store.getAutoClosedDay(), false));
store.setSort(TimiJava.defaultIfNull(store.getSort(), 0));
super.create(store);
logger.setLevel(Logger.Level.INFO);
@@ -99,6 +100,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
dbStore.setTelephone(store.getTelephone());
dbStore.setAddress(store.getAddress());
dbStore.setRemark(store.getRemark());
dbStore.setAutoClosedDay(TimiJava.defaultIfNull(store.getAutoClosedDay(), false));
super.update(dbStore);
logger.setLevel(Logger.Level.INFO);
logger.setResult(store.getId());
@@ -153,6 +155,11 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
return getByUserId(userLoginService.getRequireLoginUserId()).getId();
}
@Override
public List<GaoStore> listByAutoClosedDay() {
return mapper.selectAllByAutoClosedDay();
}
@Override
public byte[] export(Page<GaoStore> page) throws IOException {
page.setIndex(0);
@@ -0,0 +1,43 @@
package com.imyeyu.api.modules.gao.task;
import com.imyeyu.api.modules.gao.entity.GaoStore;
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
import com.imyeyu.api.modules.gao.service.GaoStoreService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
///
/// GAO 门店营业日自动休息任务
///
/// @author Codex
/// @since 2026-08-12
@Slf4j
@Service
@RequiredArgsConstructor
public class GaoStoreAutoCloseDayTask {
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
private final GaoStoreService storeService;
private final GaoStoreBusinessDayService businessDayService;
/// 每天零点后自动补记前一天无登记门店的休息日
@Scheduled(cron = "0 1 0 * * ?")
public void run() {
int dateValue = Integer.parseInt(DAY_FORMATTER.format(LocalDate.now().minusDays(1)));
List<GaoStore> storeList = storeService.listByAutoClosedDay();
for (GaoStore store : storeList) {
try {
businessDayService.autoCloseBusinessDay(store.getId(), dateValue);
} catch (Exception e) {
log.error("自动补记 GAO 门店休息日失败: storeId[{}], dateValue[{}]", store.getId(), dateValue, e);
}
}
}
}
@@ -35,7 +35,7 @@ public class StoreXSSFBuilder extends BaseXSSFBuilder<GaoStore> {
appendRow(sheet, 0, titleStyle, "门店列表导出");
appendRow(sheet, 1, null, "生成时间", Time.nowString());
appendRow(sheet, 2, null, "记录总数", String.valueOf(list.size()));
appendRow(sheet, 3, headerStyle, "门店编码", "门店名称", "状态", "电话", "地址", "备注", "排序", "创建时间");
appendRow(sheet, 3, headerStyle, "门店编码", "门店名称", "状态", "电话", "地址", "备注", "自动计算休息日", "排序", "创建时间");
int rowIndex = 4;
for (GaoStore store : list) {
appendRow(sheet, rowIndex, null,
@@ -45,12 +45,13 @@ public class StoreXSSFBuilder extends BaseXSSFBuilder<GaoStore> {
text(store.getTelephone()),
text(store.getAddress()),
text(store.getRemark()),
Boolean.TRUE.equals(store.getAutoClosedDay()) ? "" : "",
store.getSort() == null ? "" : String.valueOf(store.getSort()),
Time.toDateTime(store.getCreatedAt())
);
rowIndex++;
}
for (int index = 0; index < 8; index++) {
for (int index = 0; index < 9; index++) {
sheet.autoSizeColumn(index);
sheet.setColumnWidth(index, Math.clamp(sheet.getColumnWidth(index), 10 * 256, 36 * 256));
}
@@ -0,0 +1,4 @@
ALTER TABLE `gao_store`
ADD COLUMN `auto_closed_day` BOOLEAN NOT NULL DEFAULT FALSE COMMENT 'true 为启用自动计算休息日' AFTER `remark`;
ALTER TABLE `gao_store_business_day`
RENAME COLUMN `open_status` TO `status`;