v1.0.30 #40
@@ -40,12 +40,30 @@ public class GaoEventController {
|
|||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
||||||
TimiException.required(page, "not found page");
|
TimiException.required(page, "not found page");
|
||||||
|
resolveStoreScope(page);
|
||||||
|
PageResult<GaoEvent> result = service.pageWithoutDeleted(page);
|
||||||
|
return attachEventRelations(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
||||||
|
@PostMapping("/list/history")
|
||||||
|
public PageResult<GaoEvent> listHistory(@RequestBody Page<GaoEvent> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
resolveStoreScope(page);
|
||||||
|
return attachEventRelations(service.page(page));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveStoreScope(Page<GaoEvent> page) {
|
||||||
if (!storeScopeService.hasGlobalScope()) {
|
if (!storeScopeService.hasGlobalScope()) {
|
||||||
GaoEvent example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoEvent());
|
GaoEvent example = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoEvent());
|
||||||
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
example.setStoreId(storeScopeService.resolveStoreId(example.getStoreId()));
|
||||||
page.setEqualsExample(example);
|
page.setEqualsExample(example);
|
||||||
}
|
}
|
||||||
PageResult<GaoEvent> result = service.page(page);
|
}
|
||||||
|
|
||||||
|
private PageResult<GaoEvent> attachEventRelations(PageResult<GaoEvent> result) {
|
||||||
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
||||||
for (GaoEvent event : result.getList()) {
|
for (GaoEvent event : result.getList()) {
|
||||||
event.setRoleCodeList(roleMap.get(event.getId()));
|
event.setRoleCodeList(roleMap.get(event.getId()));
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.SelectProvider;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,6 +16,12 @@ import java.util.List;
|
|||||||
/// @since 2026-07-27 15:53
|
/// @since 2026-07-27 15:53
|
||||||
public interface GaoEventMapper extends BaseMapper<GaoEvent, String> {
|
public interface GaoEventMapper extends BaseMapper<GaoEvent, String> {
|
||||||
|
|
||||||
|
@SelectProvider(type = GaoEventSQLProvider.class, method = "selectPageWithoutDeleted")
|
||||||
|
List<GaoEvent> selectPageWithoutDeleted(Page<GaoEvent> page);
|
||||||
|
|
||||||
|
@SelectProvider(type = GaoEventSQLProvider.class, method = "countPageWithoutDeleted")
|
||||||
|
long countPageWithoutDeleted(Page<GaoEvent> page);
|
||||||
|
|
||||||
List<GaoEvent> selectByIdList(Collection<String> idList);
|
List<GaoEvent> selectByIdList(Collection<String> idList);
|
||||||
|
|
||||||
List<GaoEvent> selectValidList(@Param("storeId") String storeId, @Param("now") Long now);
|
List<GaoEvent> selectValidList(@Param("storeId") String storeId, @Param("now") Long now);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.util.SQLProvider;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.builder.annotation.ProviderContext;
|
||||||
|
|
||||||
|
/// 登记事件分页查询 SQL 提供器
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
public class GaoEventSQLProvider extends SQLProvider {
|
||||||
|
|
||||||
|
/// 分页查询未删除的登记事件
|
||||||
|
public String selectPageWithoutDeleted(ProviderContext context, @Param("page") Page<?> page) {
|
||||||
|
EntityMeta meta = getEntityMeta(context);
|
||||||
|
return appendWithoutDeleted(buildSelectByPageSQL(meta, meta.getTable(), page, "#{offset}", "#{limit}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 统计未删除的登记事件
|
||||||
|
public String countPageWithoutDeleted(ProviderContext context, @Param("page") Page<?> page) {
|
||||||
|
EntityMeta meta = getEntityMeta(context);
|
||||||
|
return appendWithoutDeleted(buildCountByPageSQL(meta, meta.getTable(), page));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String appendWithoutDeleted(String sql) {
|
||||||
|
return sql.replace(
|
||||||
|
"WHERE 1 = 1",
|
||||||
|
"WHERE 1 = 1 AND (`status` IS NULL OR `status` <> '%s')".formatted(GaoEvent.Status.DELETED.name())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package com.imyeyu.api.modules.gao.service;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventOptionGroup;
|
import com.imyeyu.api.modules.gao.entity.GaoEventOptionGroup;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -15,6 +17,12 @@ import java.util.Map;
|
|||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
public interface GaoEventService extends BaseService<GaoEvent, String> {
|
public interface GaoEventService extends BaseService<GaoEvent, String> {
|
||||||
|
|
||||||
|
/// 分页查询未删除的登记事件
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 登记事件分页结果
|
||||||
|
PageResult<GaoEvent> pageWithoutDeleted(Page<GaoEvent> page);
|
||||||
|
|
||||||
Map<String, GaoEvent> mapByIdList(Collection<String> idList);
|
Map<String, GaoEvent> mapByIdList(Collection<String> idList);
|
||||||
|
|
||||||
Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList);
|
Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList);
|
||||||
|
|||||||
+12
@@ -17,6 +17,8 @@ import com.imyeyu.api.modules.system.service.LoggerService;
|
|||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
import com.imyeyu.java.bean.timi.TimiCode;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
@@ -61,6 +63,14 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoEvent> pageWithoutDeleted(Page<GaoEvent> page) {
|
||||||
|
PageResult<GaoEvent> result = new PageResult<>();
|
||||||
|
result.setTotal(mapper.countPageWithoutDeleted(page));
|
||||||
|
result.setList(mapper.selectPageWithoutDeleted(page));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void create(GaoEvent event) {
|
public void create(GaoEvent event) {
|
||||||
@@ -109,6 +119,7 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
|||||||
GaoEvent dbEvent = get(event.getId());
|
GaoEvent dbEvent = get(event.getId());
|
||||||
TimiException.required(dbEvent, "not found event");
|
TimiException.required(dbEvent, "not found event");
|
||||||
TimiException.requiredTrue(dbEvent.getStoreId().equals(event.getStoreId()), "event.storeId invalid");
|
TimiException.requiredTrue(dbEvent.getStoreId().equals(event.getStoreId()), "event.storeId invalid");
|
||||||
|
TimiException.requiredTrue(dbEvent.getStatus() != GaoEvent.Status.DELETED, "已删除登记事件不可编辑");
|
||||||
GaoEvent.ValueType oldValueType = dbEvent.getValueType();
|
GaoEvent.ValueType oldValueType = dbEvent.getValueType();
|
||||||
GaoEvent.ValueUnit oldValueUnit = dbEvent.getValueUnit();
|
GaoEvent.ValueUnit oldValueUnit = dbEvent.getValueUnit();
|
||||||
dbEvent.setName(event.getName());
|
dbEvent.setName(event.getName());
|
||||||
@@ -171,6 +182,7 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
|
|||||||
logger.setContent(jackson.writeValueAsString(optionGroupList));
|
logger.setContent(jackson.writeValueAsString(optionGroupList));
|
||||||
GaoEvent event = get(eventId);
|
GaoEvent event = get(eventId);
|
||||||
TimiException.required(event, "not found event");
|
TimiException.required(event, "not found event");
|
||||||
|
TimiException.requiredTrue(event.getStatus() != GaoEvent.Status.DELETED, "已删除登记事件不可编辑");
|
||||||
verifyOptionGroupList(optionGroupList);
|
verifyOptionGroupList(optionGroupList);
|
||||||
saveOptionGroupList(eventId, optionGroupList);
|
saveOptionGroupList(eventId, optionGroupList);
|
||||||
logger.setLevel(Logger.Level.INFO);
|
logger.setLevel(Logger.Level.INFO);
|
||||||
|
|||||||
Reference in New Issue
Block a user