fix gao store id

This commit is contained in:
Timi
2026-08-07 19:10:25 +08:00
parent ab79391cdc
commit 6e43ff349d
16 changed files with 138 additions and 81 deletions
@@ -1,6 +1,7 @@
package com.imyeyu.api.modules.gao.controller;
import com.fasterxml.jackson.annotation.JsonView;
import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.bean.RoleMatchMode;
import com.imyeyu.api.modules.common.entity.Attachment;
import com.imyeyu.api.modules.common.service.AttachmentService;
@@ -10,9 +11,12 @@ import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
import com.imyeyu.api.modules.user.service.RoleChecker;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiException;
@@ -42,14 +46,17 @@ import java.util.Map;
/// @author 夜雨
/// @since 2026-07-27 14:12
@RestController
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequiredArgsConstructor
@RequestMapping("/gao/customer")
public class GaoCustomerController {
private final UserService userService;
private final RoleChecker roleChecker;
private final AttachmentService attachmentService;
private final GaoCustomerService service;
private final GaoStoreService gaoStoreService;
private final UserLoginService userLoginService;
@AOPLog
@RequestRateLimit
@@ -92,6 +99,9 @@ public class GaoCustomerController {
@PostMapping("/create")
@JsonView(ResponseView.Public.class)
public String create(@RequestBody GaoCustomer customer) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.create(customer);
return customer.getId();
}
@@ -101,6 +111,9 @@ public class GaoCustomerController {
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
@PostMapping("/update")
public void update(@RequestBody GaoCustomer customer) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.updateWithAttachment(customer);
}
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.controller;
import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.bean.RoleMatchMode;
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
@@ -7,6 +8,9 @@ import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
import com.imyeyu.api.modules.gao.entity.GaoEvent;
import com.imyeyu.api.modules.gao.service.GaoEventService;
import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.user.service.RoleChecker;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.spring.annotation.AOPLog;
import com.imyeyu.spring.annotation.RequestRateLimit;
import com.imyeyu.spring.bean.Page;
@@ -26,12 +30,15 @@ import java.util.Map;
/// @author 夜雨
/// @since 2026-07-27 14:13
@RestController
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequiredArgsConstructor
@RequestMapping("/gao/event")
public class GaoEventController {
private final GaoEventService service;
private final RoleChecker roleChecker;
private final GaoStoreService gaoStoreService;
private final UserLoginService userLoginService;
@AOPLog
@RequestRateLimit
@@ -65,16 +72,22 @@ public class GaoEventController {
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
@PostMapping("/create")
public void create(@RequestBody GaoEvent registrationEvent) {
service.create(registrationEvent);
public void create(@RequestBody GaoEvent event) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.create(event);
}
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
@PostMapping("/update")
public void update(@RequestBody GaoEvent registrationEvent) {
service.update(registrationEvent);
public void update(@RequestBody GaoEvent event) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.update(event);
}
@AOPLog
@@ -1,6 +1,7 @@
package com.imyeyu.api.modules.gao.controller;
import com.fasterxml.jackson.annotation.JsonView;
import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.bean.RoleMatchMode;
import com.imyeyu.api.modules.common.entity.Attachment;
import com.imyeyu.api.modules.common.service.AttachmentService;
@@ -14,10 +15,14 @@ import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.gao.service.GaoEventRecordService;
import com.imyeyu.api.modules.gao.service.GaoEventService;
import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.gao.vo.GaoCustomerEventRankView;
import com.imyeyu.api.modules.gao.vo.GaoEventRecordPage;
import com.imyeyu.api.modules.gao.vo.GaoEventRecordRankPage;
import com.imyeyu.api.modules.user.service.RoleChecker;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.java.TimiJava;
import com.imyeyu.network.Network;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.annotation.AOPLog;
@@ -43,16 +48,19 @@ import java.util.Map;
/// @author 夜雨
/// @since 2026-07-27 14:11
@RestController
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@RequiredArgsConstructor
@RequestMapping("/gao/event/record")
public class GaoEventRecordController {
private final UserService userService;
private final RoleChecker roleChecker;
private final GaoEventService eventService;
private final AttachmentService attachmentService;
private final GaoCustomerService customerService;
private final GaoStoreService gaoStoreService;
private final GaoEventRecordService service;
private final UserLoginService userLoginService;
@AOPLog
@RequestRateLimit
@@ -92,22 +100,40 @@ public class GaoEventRecordController {
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
@PostMapping("/create")
public void create(@RequestBody GaoEventRecord record) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
record.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.create(record);
}
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
@PostMapping("/create/batch")
public void createBatch(@RequestBody List<GaoEventRecord> recordList) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
for (GaoEventRecord record : recordList) {
record.setStoreId(storeId);
}
}
service.createBatch(recordList);
}
@AOPLog
@RequestRateLimit
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_CREATE)
@PostMapping("/create/customer")
public void createWithCustomer(@RequestBody GaoCustomer customer) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
String storeId = gaoStoreService.getBelongIdByRequiredLoginUserId();
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
record.setStoreId(storeId);
}
}
service.createWithCustomer(customer);
}
@@ -116,6 +142,9 @@ public class GaoEventRecordController {
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_UPDATE)
@PostMapping("/update")
public void update(@RequestBody GaoEventRecord record) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
record.setStoreId(gaoStoreService.getBelongIdByRequiredLoginUserId());
}
service.update(record);
}
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.controller;
import com.imyeyu.api.bean.RoleMatchMode;
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
@@ -7,7 +8,6 @@ import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
import com.imyeyu.api.modules.gao.entity.GaoStore;
import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.bean.RoleMatchMode;
import com.imyeyu.network.Network;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.annotation.AOPLog;
@@ -105,8 +105,8 @@ public class GaoStoreController {
@AOPLog
@RequestRateLimit
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
@PostMapping("/detail/user")
public GaoStore getByLoginUser() {
@PostMapping("/user")
public GaoStore getLoginStore() {
return service.getByUserId(userLoginService.getRequireLoginUserId());
}
}
@@ -39,9 +39,9 @@ import java.util.Map;
/// @author 夜雨
/// @since 2026-07-30 14:15
@RestController
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
@RequiredArgsConstructor
@RequestMapping("/gao/user")
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
public class GaoUserController {
private final UserService userService;
@@ -99,6 +99,9 @@ public class GaoUserController {
@PostMapping("/create")
@JsonView(ResponseView.Public.class)
public GaoUser create(@RequestBody GaoUser gaoUser) {
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
gaoUser.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
}
service.create(gaoUser);
return service.get(gaoUser.getId());
}
@@ -2,8 +2,6 @@ package com.imyeyu.api.modules.gao.mapper;
import com.imyeyu.api.modules.gao.entity.GaoUser;
import com.imyeyu.spring.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
///
/// GAO 用户 Mapper
@@ -11,10 +9,4 @@ import org.apache.ibatis.annotations.Select;
/// @author Codex
/// @since 2026-07-30
public interface GaoUserMapper extends BaseMapper<GaoUser, String> {
@Select("SELECT * FROM `gao_user` WHERE `user_id` = #{userId} AND `deleted_at` IS NULL LIMIT 1")
GaoUser selectByUserId(@Param("userId") String userId);
@Select("SELECT * FROM `gao_user` WHERE `store_id` = #{storeId} AND `user_id` = #{userId} AND `deleted_at` IS NULL LIMIT 1")
GaoUser selectByStoreIdAndUserId(@Param("storeId") String storeId, @Param("userId") String userId);
}
@@ -20,6 +20,8 @@ public interface GaoStoreService extends BaseService<GaoStore, String> {
/// @return 门店
GaoStore getByUserId(String userId);
String getBelongIdByRequiredLoginUserId();
/// 导出门店列表
///
/// @param page 分页查询条件
@@ -91,7 +91,10 @@ public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEve
int registeredDateValue = dateValue(registeredAt);
long businessDayNo = businessDayService.resolveOpenBusinessDay(event.getStoreId(), registeredDateValue).getBusinessDayNo();
List<String> customerIdList = TimiJava.defaultIfEmpty(record.getCustomerIdList(), List.of(record.getCustomerId()));
List<String> customerIdList = record.getCustomerIdList();
if (TimiJava.isEmpty(customerIdList)) {
customerIdList = List.of(record.getCustomerId());
}
TimiException.required(customerIdList, "not found customerId or empty customerIdList");
GaoEventRecord firstRecord = null;
@@ -66,13 +66,8 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
event.setStatus(TimiJava.defaultIfNull(event.getStatus(), GaoEvent.Status.DRAFT));
event.setRequirePhoto(TimiJava.defaultIfNull(event.getRequirePhoto(), false));
event.setLimitType(TimiJava.defaultIfNull(event.getLimitType(), GaoEvent.LimitType.NONE));
if (TimiJava.isNotEmpty(event.getLimitType())) {
TimiException.requiredTrue(event.getLimitType().getMin() < event.getLimitValue(), "约束值最低 %s".formatted(event.getLimitType().getMin()));
}
if (event.getBeginAt() != null || event.getEndAt() != null) {
TimiException.requiredTrue(event.getBeginAt() == null || event.getEndAt() == null || event.getBeginAt() <= event.getEndAt(), "invalid beginAt or endAt");
}
event.setSort(TimiJava.defaultIfNull(event.getSort(), 0));
verifyEvent(event);
super.create(event);
saveRoleRelation(event.getId(), event.getRoleCodeList());
@@ -94,25 +89,27 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void update(GaoEvent entity) {
public void update(GaoEvent event) {
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_UPDATE");
try {
logger.setContent(jackson.writeValueAsString(entity));
GaoEvent dbEvent = get(entity.getId());
TimiException.requiredTrue(dbEvent.getStoreId().equals(entity.getStoreId()), "event.storeId invalid");
dbEvent.setName(entity.getName());
dbEvent.setDescription(entity.getDescription());
dbEvent.setColor(entity.getColor());
dbEvent.setStatus(entity.getStatus());
dbEvent.setRequirePhoto(entity.getRequirePhoto());
dbEvent.setLimitType(entity.getLimitType());
dbEvent.setLimitValue(entity.getLimitValue());
dbEvent.setBeginAt(entity.getBeginAt());
dbEvent.setEndAt(entity.getEndAt());
logger.setContent(jackson.writeValueAsString(event));
GaoEvent dbEvent = get(event.getId());
TimiException.requiredTrue(dbEvent.getStoreId().equals(event.getStoreId()), "event.storeId invalid");
dbEvent.setName(event.getName());
dbEvent.setDescription(event.getDescription());
dbEvent.setColor(event.getColor());
dbEvent.setStatus(event.getStatus());
dbEvent.setRequirePhoto(event.getRequirePhoto());
dbEvent.setLimitType(event.getLimitType());
dbEvent.setLimitValue(event.getLimitValue());
dbEvent.setBeginAt(event.getBeginAt());
dbEvent.setEndAt(event.getEndAt());
verifyEvent(dbEvent);
mapper.update(dbEvent);
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
saveRoleRelation(event.getId(), event.getRoleCodeList());
logger.setLevel(Logger.Level.INFO);
logger.setResult(entity.getId());
logger.setResult(event.getId());
} catch (TimiException e) {
logger.setLevel(Logger.Level.WARN);
logger.setException(e.getMessage());
@@ -192,6 +189,15 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
}
}
private void verifyEvent(GaoEvent event) {
if (TimiJava.isNotEmpty(event.getLimitType()) && event.getLimitType() != GaoEvent.LimitType.NONE) {
TimiException.requiredTrue(event.getLimitType().getMin() < event.getLimitValue(), "约束值最低 %s".formatted(event.getLimitType().getMin()));
}
if (event.getBeginAt() != null || event.getEndAt() != null) {
TimiException.requiredTrue(event.getBeginAt() == null || event.getEndAt() == null || event.getBeginAt() <= event.getEndAt(), "invalid beginAt or endAt");
}
}
private void saveRoleRelation(String eventId, List<String> roleCodeList) {
List<GaoEventRoleRelation> dbRoleRelationList = roleRelationMapper.selectAllByEventIdList(List.of(eventId));
Set<String> roleCodeSet = TimiJava.defaultIfEmpty(roleCodeList, List.<String>of()).stream().filter(TimiJava::isNotEmpty).collect(Collectors.toSet());
@@ -8,6 +8,7 @@ import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.gao.util.StoreXSSFBuilder;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException;
@@ -39,6 +40,7 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
private final ObjectMapper jackson;
private final LoggerService loggerService;
private final UserLoginService userLoginService;
private final GaoStoreMapper mapper;
private final StoreXSSFBuilder storeXSSFBuilder;
@@ -143,6 +145,11 @@ public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, St
return mapper.selectByUserId(userId);
}
@Override
public String getBelongIdByRequiredLoginUserId() {
return getByUserId(userLoginService.getRequireLoginUserId()).getId();
}
@Override
public byte[] export(Page<GaoStore> page) throws IOException {
page.setIndex(0);
@@ -9,7 +9,6 @@ import com.imyeyu.api.modules.gao.service.GaoStoreService;
import com.imyeyu.api.modules.gao.service.GaoUserService;
import com.imyeyu.api.modules.system.entity.Logger;
import com.imyeyu.api.modules.system.service.LoggerService;
import com.imyeyu.api.modules.user.service.RoleService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode;
@@ -33,7 +32,6 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
private final ObjectMapper jackson;
private final UserService userService;
private final RoleService roleService;
private final LoggerService loggerService;
private final GaoStoreService gaoStoreService;