Compare commits
11
Commits
6e43ff349d
..
v1.0.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea430f2468 | ||
|
|
f76f79744a | ||
|
|
19daaff907 | ||
|
|
db94d8f932 | ||
|
|
53618fe362 | ||
|
|
523edffc4e | ||
|
|
c7ddb1a8b0 | ||
|
|
45c9fc814a | ||
|
|
407dc13ac4 | ||
|
|
0c06bf16c2 | ||
|
|
1db39e77d3 |
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourcePerFileMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java/com/imyeyu/api/modules/user/mapper/UserMapper.java" value="05742bdc-a11a-4147-9168-ef976a70258a" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/GaoCustomerMapper.xml" value="05742bdc-a11a-4147-9168-ef976a70258a" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
-1
@@ -3,7 +3,6 @@
|
|||||||
<component name="SqlDialectMappings">
|
<component name="SqlDialectMappings">
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V1__init_schema.sql" dialect="MariaDB" />
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V1__init_schema.sql" dialect="MariaDB" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V2__init_system_data.sql" dialect="GenericSQL" />
|
<file url="file://$PROJECT_DIR$/src/main/resources/db/migration/timiserver/V2__init_system_data.sql" dialect="GenericSQL" />
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources/mapper/timi-server/GaoEventRecordMapper.xml" dialect="MariaDB" />
|
|
||||||
<file url="PROJECT" dialect="MariaDB" />
|
<file url="PROJECT" dialect="MariaDB" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||||
<artifactId>TimiServerAPI</artifactId>
|
<artifactId>TimiServerAPI</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.0.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>TimiServerAPI</name>
|
<name>TimiServerAPI</name>
|
||||||
<description>imyeyu.com API</description>
|
<description>imyeyu.com API</description>
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.spring</groupId>
|
<groupId>com.imyeyu.spring</groupId>
|
||||||
<artifactId>timi-spring</artifactId>
|
<artifactId>timi-spring</artifactId>
|
||||||
<version>0.0.19</version>
|
<version>0.0.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.network</groupId>
|
<groupId>com.imyeyu.network</groupId>
|
||||||
@@ -188,12 +188,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
<artifactId>timi-utils</artifactId>
|
<artifactId>timi-utils</artifactId>
|
||||||
<version>0.0.13</version>
|
<version>0.0.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.font.icon</groupId>
|
<groupId>com.imyeyu.font.icon</groupId>
|
||||||
@@ -230,10 +230,6 @@
|
|||||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||||
<version>${springboot.version}</version>
|
<version>${springboot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -23,7 +22,6 @@ public class BeanConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public ObjectMapper jackson() {
|
public ObjectMapper jackson() {
|
||||||
return JsonMapper.builder()
|
return JsonMapper.builder()
|
||||||
.addModule(new JavaTimeModule())
|
|
||||||
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
.defaultDateFormat(Time.dateTime)
|
.defaultDateFormat(Time.dateTime)
|
||||||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
import com.imyeyu.api.annotation.EnableSettingInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
import com.imyeyu.api.annotation.RequestRateLimitInterceptor;
|
||||||
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
import com.imyeyu.api.annotation.RequireCorePermissionInterceptor;
|
||||||
@@ -79,7 +78,6 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
JsonMapper jsonMapper = JsonMapper.builder()
|
JsonMapper jsonMapper = JsonMapper.builder()
|
||||||
.addModule(new JavaTimeModule())
|
|
||||||
// 设置默认属性包含规则:忽略 null 值
|
// 设置默认属性包含规则:忽略 null 值
|
||||||
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
.serializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
// 日期格式化
|
// 日期格式化
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.imyeyu.api.modules.common.controller;
|
|||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.api.modules.common.service.TempFileService;
|
import com.imyeyu.api.modules.common.service.TempFileService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
import com.imyeyu.api.modules.common.vo.attach.TempFileResp;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.network.Network;
|
import com.imyeyu.network.Network;
|
||||||
@@ -181,7 +183,32 @@ public class AttachmentController {
|
|||||||
return service.pageByBizId(bizType, bizId, attachTypeList, page);
|
return service.pageByBizId(bizType, bizId, attachTypeList, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按业务差分更新附件
|
||||||
|
*
|
||||||
|
* @param req 更新请求
|
||||||
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/update/biz")
|
||||||
|
public void updateByBiz(@RequestBody BizUpdateReq req) {
|
||||||
|
service.updateByBiz(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按业务删除全部附件
|
||||||
|
*
|
||||||
|
* @param req 删除请求
|
||||||
|
*/
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/delete/biz")
|
||||||
|
public void deleteByBiz(@RequestBody BizDeleteReq req) {
|
||||||
|
service.deleteByBiz(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
@IgnoreGlobalReturn
|
@IgnoreGlobalReturn
|
||||||
@GetMapping({"/read/{id}", "/download/{id}"})
|
@GetMapping({"/read/{id}", "/download/{id}"})
|
||||||
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
public void readById(@PathVariable String id, @RequestParam(required = false) Integer thumbWidth, @RequestParam(required = false) Integer thumbHeight) throws UnsupportedEncodingException {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.common.entity;
|
package com.imyeyu.api.modules.common.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.imyeyu.api.TimiServerAPI;
|
import com.imyeyu.api.TimiServerAPI;
|
||||||
import com.imyeyu.api.modules.common.bean.attachment.AccessKey;
|
import com.imyeyu.api.modules.common.bean.attachment.AccessKey;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.ref.Ref;
|
import com.imyeyu.java.ref.Ref;
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
@@ -34,7 +33,7 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
GAO_CUSTOMER,
|
GAO_CUSTOMER,
|
||||||
|
|
||||||
GAO_EVENT_RECORD,
|
GAO_REGISTRATION_EVENT_RECORD,
|
||||||
|
|
||||||
TEMP_FILE,
|
TEMP_FILE,
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ public class Attachment extends UUIDEntity {
|
|||||||
|
|
||||||
protected String mimeType;
|
protected String mimeType;
|
||||||
|
|
||||||
protected ObjectNode metadata;
|
protected JsonNode metadata;
|
||||||
|
|
||||||
protected Long size;
|
protected Long size;
|
||||||
|
|
||||||
@@ -83,14 +82,6 @@ public class Attachment extends UUIDEntity {
|
|||||||
@Transient
|
@Transient
|
||||||
protected MultipartFile file;
|
protected MultipartFile file;
|
||||||
|
|
||||||
public String buildMongoName() {
|
|
||||||
StringBuilder result = new StringBuilder(bizType.name());
|
|
||||||
if (TimiJava.isNotEmpty(attachType)) {
|
|
||||||
result.append('_').append(attachType.toUpperCase());
|
|
||||||
}
|
|
||||||
return result.append('_').append(name).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream openInputStream() {
|
public InputStream openInputStream() {
|
||||||
AttachmentService service = TimiServerAPI.applicationContext.getBean(AttachmentService.class);
|
AttachmentService service = TimiServerAPI.applicationContext.getBean(AttachmentService.class);
|
||||||
return service.getInputStreamByMongoId(mongoId);
|
return service.getInputStreamByMongoId(mongoId);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import com.imyeyu.api.modules.common.entity.Attachment;
|
|||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.mapper.RawMapper;
|
import com.imyeyu.spring.mapper.RawMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +32,7 @@ public interface AttachmentMapper extends BaseMapper<Attachment, String>, RawMap
|
|||||||
|
|
||||||
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
List<Attachment> selectByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes, Page<Attachment> page);
|
||||||
|
|
||||||
List<Attachment> selectByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, List<String> attachTypes);
|
List<Attachment> selectByBizIdList(@Param("bizType") Attachment.BizType bizType, @Param("bizIdList") List<String> bizIdList, @Param("attachTypes") List<String> attachTypes);
|
||||||
|
|
||||||
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
long countByBizId(Attachment.BizType bizType, String bizId, List<String> attachTypes);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.imyeyu.api.modules.common.service;
|
package com.imyeyu.api.modules.common.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -18,13 +19,6 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public interface AttachmentService extends BaseService<Attachment, String> {
|
public interface AttachmentService extends BaseService<Attachment, String> {
|
||||||
|
|
||||||
///
|
|
||||||
/// 克隆附件,复制业务属性和文件内容并生成新的附件记录
|
|
||||||
///
|
|
||||||
/// @param id 源附件 ID
|
|
||||||
/// @return 克隆后的附件
|
|
||||||
Attachment clone(String id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按需获取或创建缩略图附件。
|
* 按需获取或创建缩略图附件。
|
||||||
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
* <p>当附件为图片或视频时,若指定尺寸的缩略图已存在则直接返回缓存,
|
||||||
@@ -58,14 +52,14 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
List<Attachment> listByBizId(Attachment.BizType bizType, String bizId, String... attachTypes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据多个业务 ID 批量获取附件
|
* 根据多个业务 ID 批量获取附件。
|
||||||
*
|
*
|
||||||
* @param bizType 业务类型
|
* @param bizType 业务类型
|
||||||
* @param bizIdList 业务 ID 列表
|
* @param bizIdList 业务 ID 列表
|
||||||
* @param attachTypes 附件类型,可为 null
|
* @param attachTypes 附件类型,可为 null
|
||||||
* @return 按业务 ID 分组的附件列表
|
* @return 按业务 ID 分组的附件列表
|
||||||
*/
|
*/
|
||||||
Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes);
|
Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, List<String> bizIdList, String... attachTypes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据业务获取所有附件
|
* 根据业务获取所有附件
|
||||||
@@ -90,8 +84,10 @@ public interface AttachmentService extends BaseService<Attachment, String> {
|
|||||||
* <li>请求有、数据库有、无 tempFileId → 仅更新元数据</li>
|
* <li>请求有、数据库有、无 tempFileId → 仅更新元数据</li>
|
||||||
* <li>请求有、数据库有、有 tempFileId → 更新文件与元数据</li>
|
* <li>请求有、数据库有、有 tempFileId → 更新文件与元数据</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param req 差分更新请求
|
||||||
*/
|
*/
|
||||||
void updateByBizId(Attachment.BizType bizType, String bizId, List<Attachment> list);
|
void updateByBiz(BizUpdateReq req);
|
||||||
|
|
||||||
void deleteByBizId(Attachment.BizType bizType, String bizId);
|
void deleteByBiz(BizDeleteReq req);
|
||||||
}
|
}
|
||||||
|
|||||||
+120
-114
@@ -8,6 +8,8 @@ import com.imyeyu.api.modules.common.bean.attachment.Metadata;
|
|||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
import com.imyeyu.api.modules.common.mapper.AttachmentMapper;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizDeleteReq;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
import com.imyeyu.api.util.JavaCV;
|
import com.imyeyu.api.util.JavaCV;
|
||||||
import com.imyeyu.io.IO;
|
import com.imyeyu.io.IO;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
@@ -41,7 +43,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -69,88 +71,6 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void create(Attachment attachment) {
|
|
||||||
TimiException.required(attachment.getBizType(), "not found String");
|
|
||||||
TimiException.required(attachment.getName(), "not found attachment.name");
|
|
||||||
String mongoId = null;
|
|
||||||
try {
|
|
||||||
if (attachment.getFile() != null) {
|
|
||||||
attachment.setInputStream(attachment.getFile().getInputStream());
|
|
||||||
}
|
|
||||||
InputStream is = attachment.getInputStream();
|
|
||||||
TimiException.required(is, "not found attachment.inputStream");
|
|
||||||
|
|
||||||
mongoId = gridFsTemplate.store(attachment.getInputStream(), attachment.buildMongoName()).toString();
|
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
|
||||||
attachment.setMongoId(mongoId);
|
|
||||||
attachment.setSize(gridFSFile.getLength());
|
|
||||||
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setUploaderIp(TimiSpring.getRequestIP());
|
|
||||||
attachment.setIsDestroyed(false);
|
|
||||||
if (attachment.getMimeType().startsWith("image")) {
|
|
||||||
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
|
||||||
ObjectNode metadata = TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode());
|
|
||||||
metadata.put("width", image.getWidth());
|
|
||||||
metadata.put("height", image.getHeight());
|
|
||||||
attachment.setMetadata(metadata);
|
|
||||||
}
|
|
||||||
mapper.insert(attachment);
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (mongoId != null) {
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(mongoId)));
|
|
||||||
}
|
|
||||||
log.error("create error", e);
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "TODO read attachment input stream error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(Attachment attachment) {
|
|
||||||
String newMongoId = null;
|
|
||||||
try {
|
|
||||||
if (attachment.getFile() != null) {
|
|
||||||
attachment.setInputStream(attachment.getFile().getInputStream());
|
|
||||||
}
|
|
||||||
InputStream stream = attachment.getInputStream();
|
|
||||||
if (stream == null) {
|
|
||||||
// 无新文件,仅更新元数据字段
|
|
||||||
super.update(attachment);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
|
||||||
Attachment old = mapper.selectRaw(attachment.getId());
|
|
||||||
// 存储新文件
|
|
||||||
newMongoId = gridFsTemplate.store(stream, attachment.buildMongoName()).toString();
|
|
||||||
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
|
||||||
attachment.setMongoId(newMongoId);
|
|
||||||
attachment.setSize(gridFSFile.getLength());
|
|
||||||
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
|
||||||
if (attachment.getMimeType().startsWith("image")) {
|
|
||||||
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
|
||||||
ObjectNode metadata = TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode());
|
|
||||||
metadata.put("width", image.getWidth());
|
|
||||||
metadata.put("height", image.getHeight());
|
|
||||||
attachment.setMetadata(metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新数据库后删除旧 GridFS 文件
|
|
||||||
super.update(attachment);
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
|
||||||
if (TimiJava.isNotEmpty(newMongoId)) {
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(newMongoId)));
|
|
||||||
}
|
|
||||||
log.error("update error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "TODO update file error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
@@ -188,30 +108,101 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public Attachment clone(String id) {
|
public void create(Attachment attachment) {
|
||||||
TimiException.required(id, "not found id");
|
TimiException.required(attachment.getBizType(), "not found String");
|
||||||
Attachment source = mapper.selectRaw(id);
|
TimiException.required(attachment.getName(), "not found attachment.name");
|
||||||
TimiException.required(source, "not found attachment");
|
String mongoId = null;
|
||||||
TimiException.required(source.getMongoId(), "not found mongoId");
|
try {
|
||||||
|
if (attachment.getFile() != null) {
|
||||||
Attachment target = new Attachment();
|
attachment.setInputStream(attachment.getFile().getInputStream());
|
||||||
target.setBizType(source.getBizType());
|
|
||||||
target.setBizId(source.getBizId());
|
|
||||||
target.setAttachType(source.getAttachType());
|
|
||||||
target.setTitle(source.getTitle());
|
|
||||||
target.setName(source.getName());
|
|
||||||
target.setMetadata(source.getMetadata() == null ? null : source.getMetadata().deepCopy());
|
|
||||||
target.setDestroyAt(source.getDestroyAt());
|
|
||||||
try (InputStream inputStream = getInputStreamByMongoId(source.getMongoId())) {
|
|
||||||
target.setInputStream(inputStream);
|
|
||||||
create(target);
|
|
||||||
return target;
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (target.getMongoId() != null) {
|
|
||||||
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(target.getMongoId())));
|
|
||||||
}
|
}
|
||||||
log.error("clone attachment error, id={}", id, e);
|
InputStream is = attachment.getInputStream();
|
||||||
throw new TimiException(TimiCode.ERROR, "clone attachment error", e);
|
TimiException.required(is, "not found attachment.inputStream");
|
||||||
|
|
||||||
|
StringBuilder mongoName = new StringBuilder(attachment.getBizType().name());
|
||||||
|
if (TimiJava.isNotEmpty(attachment.getAttachType())) {
|
||||||
|
mongoName.append("_").append(attachment.getAttachType().toUpperCase()).append("_");
|
||||||
|
}
|
||||||
|
mongoName.append(attachment.getName());
|
||||||
|
|
||||||
|
mongoId = gridFsTemplate.store(attachment.getInputStream(), mongoName.toString()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(mongoId)));
|
||||||
|
attachment.setMongoId(mongoId);
|
||||||
|
attachment.setSize(gridFSFile.getLength());
|
||||||
|
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setUploaderIp(TimiSpring.getRequestIP());
|
||||||
|
attachment.setIsDestroyed(false);
|
||||||
|
if (attachment.getMimeType().startsWith("image")) {
|
||||||
|
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
||||||
|
attachment.setMetadata(TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode()));
|
||||||
|
if (attachment.getMetadata() instanceof ObjectNode obj) {
|
||||||
|
obj.put("width", image.getWidth());
|
||||||
|
obj.put("height", image.getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mapper.insert(attachment);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (mongoId != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(mongoId)));
|
||||||
|
}
|
||||||
|
log.error("create error", e);
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "TODO read attachment input stream error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(Attachment attachment) {
|
||||||
|
String newMongoId = null;
|
||||||
|
try {
|
||||||
|
if (attachment.getFile() != null) {
|
||||||
|
attachment.setInputStream(attachment.getFile().getInputStream());
|
||||||
|
}
|
||||||
|
InputStream stream = attachment.getInputStream();
|
||||||
|
if (stream == null) {
|
||||||
|
// 无新文件,仅更新元数据字段
|
||||||
|
super.update(attachment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 有新文件时,先查旧记录获取旧 mongoId 和兜底字段
|
||||||
|
Attachment old = mapper.selectRaw(attachment.getId());
|
||||||
|
// 构建存储名,优先取调用方设置的字段,否则沿用旧值
|
||||||
|
Attachment.BizType bizType = TimiJava.defaultIfNull(attachment.getBizType(), old.getBizType());
|
||||||
|
String attachType = TimiJava.defaultIfEmpty(attachment.getAttachType(), old.getAttachType());
|
||||||
|
String name = TimiJava.defaultIfEmpty(attachment.getName(), old.getName());
|
||||||
|
StringBuilder mongoName = new StringBuilder(bizType.name());
|
||||||
|
if (TimiJava.isNotEmpty(attachType)) {
|
||||||
|
mongoName.append("_").append(attachType.toUpperCase()).append("_");
|
||||||
|
}
|
||||||
|
mongoName.append(name);
|
||||||
|
|
||||||
|
// 存储新文件
|
||||||
|
newMongoId = gridFsTemplate.store(stream, mongoName.toString()).toString();
|
||||||
|
GridFSFile gridFSFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(newMongoId)));
|
||||||
|
attachment.setMongoId(newMongoId);
|
||||||
|
attachment.setSize(gridFSFile.getLength());
|
||||||
|
attachment.setMd5(IO.md5(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
attachment.setMimeType(new Tika().detect(gridFSBucket.openDownloadStream(gridFSFile.getObjectId())));
|
||||||
|
if (attachment.getMimeType().startsWith("image")) {
|
||||||
|
BufferedImage image = ImageIO.read(gridFSBucket.openDownloadStream(gridFSFile.getObjectId()));
|
||||||
|
attachment.setMetadata(TimiJava.defaultIfNull(attachment.getMetadata(), jackson.createObjectNode()));
|
||||||
|
if (attachment.getMetadata() instanceof ObjectNode obj) {
|
||||||
|
obj.put("width", image.getWidth());
|
||||||
|
obj.put("height", image.getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新数据库后删除旧 GridFS 文件
|
||||||
|
super.update(attachment);
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(old.getMongoId())));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 新文件已上传但后续操作失败,清理新文件防止孤儿数据
|
||||||
|
if (newMongoId != null) {
|
||||||
|
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(newMongoId)));
|
||||||
|
}
|
||||||
|
log.error("update error", e);
|
||||||
|
throw new TimiException(TimiCode.ERROR, "TODO update file error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,9 +216,9 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
if (!isImage && !isVideo) {
|
if (!isImage && !isVideo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// 命中缓存直接返回
|
||||||
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
Attachment cached = mapper.selectThumb(source.getBizType(), source.getId(), requestWidth, requestHeight);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
// 命中缓存直接返回
|
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -322,8 +313,19 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, Collection<String> bizIdList, String... attachTypes) {
|
public Map<String, List<Attachment>> mapByBizIdList(Attachment.BizType bizType, List<String> bizIdList, String... attachTypes) {
|
||||||
return mapper.selectByBizIdList(bizType, bizIdList, List.of(attachTypes)).stream().collect(Collectors.groupingBy(Attachment::getBizId));
|
if (bizIdList == null || bizIdList.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
List<String> normalizedBizIdList = bizIdList.stream()
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (normalizedBizIdList.isEmpty()) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
return mapper.selectByBizIdList(bizType, new ArrayList<>(normalizedBizIdList), List.of(attachTypes)).stream()
|
||||||
|
.collect(Collectors.groupingBy(Attachment::getBizId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -346,12 +348,16 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void updateByBizId(Attachment.BizType bizType, String bizId, List<Attachment> list) {
|
public void updateByBiz(BizUpdateReq req) {
|
||||||
|
Attachment.BizType bizType = req.getBizType();
|
||||||
|
String bizId = req.getBizId();
|
||||||
|
List<Attachment> items = req.getItems();
|
||||||
|
|
||||||
// 数据库现有附件
|
// 数据库现有附件
|
||||||
List<Attachment> dbList = mapper.selectAllByBizId(bizType, bizId);
|
List<Attachment> dbList = mapper.selectAllByBizId(bizType, bizId);
|
||||||
Set<String> dbIds = dbList.stream().map(Attachment::getId).collect(Collectors.toSet());
|
Set<String> dbIds = dbList.stream().map(Attachment::getId).collect(Collectors.toSet());
|
||||||
// 请求附件 ID
|
// 请求附件 ID
|
||||||
Set<String> reqIds = list.stream().map(Attachment::getId).filter(Objects::nonNull).collect(Collectors.toSet());
|
Set<String> reqIds = items.stream().map(Attachment::getId).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||||
// 数据库有、请求无:删除
|
// 数据库有、请求无:删除
|
||||||
for (Attachment attach : dbList) {
|
for (Attachment attach : dbList) {
|
||||||
if (!reqIds.contains(attach.getId())) {
|
if (!reqIds.contains(attach.getId())) {
|
||||||
@@ -359,7 +365,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Attachment item : list) {
|
for (Attachment item : items) {
|
||||||
boolean isNew = item.getId() == null || !dbIds.contains(item.getId());
|
boolean isNew = item.getId() == null || !dbIds.contains(item.getId());
|
||||||
String tempFileId = item.getTempFileId();
|
String tempFileId = item.getTempFileId();
|
||||||
|
|
||||||
@@ -426,8 +432,8 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void deleteByBizId(Attachment.BizType bizType, String bizId) {
|
public void deleteByBiz(BizDeleteReq req) {
|
||||||
List<Attachment> attachmentList = mapper.selectAllByBizId(bizType, bizId);
|
List<Attachment> attachmentList = mapper.selectAllByBizId(req.getBizType(), req.getBizId());
|
||||||
for (Attachment attachment : attachmentList) {
|
for (Attachment attachment : attachmentList) {
|
||||||
delete(attachment.getId());
|
delete(attachment.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -46,8 +46,8 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
|
|
||||||
public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException {
|
public List<TempFileResp> create(List<MultipartFile> files, Long ttl) throws TimiException {
|
||||||
Logger logger = new Logger();
|
Logger logger = new Logger();
|
||||||
logger.setModule(Logger.Module.COMMON);
|
logger.setModule("TEMP_FILE");
|
||||||
logger.setOperation("TEMP_FILE_STORE");
|
logger.setOperation("STORE");
|
||||||
logger.setIp(TimiSpring.getRequestIP());
|
logger.setIp(TimiSpring.getRequestIP());
|
||||||
try {
|
try {
|
||||||
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
logger.setContent(jackson.writeValueAsString(logRequestArgs(files, ttl)));
|
||||||
@@ -116,8 +116,8 @@ public class TempFileServiceImplement implements TempFileService {
|
|||||||
@Override
|
@Override
|
||||||
public void save(TempFileSaveReq request) {
|
public void save(TempFileSaveReq request) {
|
||||||
Logger logger = new Logger();
|
Logger logger = new Logger();
|
||||||
logger.setModule(Logger.Module.COMMON);
|
logger.setModule("TEMP_FILE");
|
||||||
logger.setOperation("TEMP_FILE_SAVE");
|
logger.setOperation("SAVE");
|
||||||
logger.setIp(TimiSpring.getRequestIP());
|
logger.setIp(TimiSpring.getRequestIP());
|
||||||
try {
|
try {
|
||||||
logger.setContent(jackson.writeValueAsString(request));
|
logger.setContent(jackson.writeValueAsString(request));
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo.attach;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务附件差分更新请求
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-03-11 00:00
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BizDeleteReq {
|
||||||
|
|
||||||
|
/** 业务类型 */
|
||||||
|
private Attachment.BizType bizType;
|
||||||
|
|
||||||
|
/** 业务 ID */
|
||||||
|
private String bizId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.imyeyu.api.modules.common.vo.attach;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务附件差分更新请求
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2026-03-11 00:00
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BizUpdateReq {
|
||||||
|
|
||||||
|
/** 业务类型 */
|
||||||
|
private Attachment.BizType bizType;
|
||||||
|
|
||||||
|
/** 业务 ID */
|
||||||
|
private String bizId;
|
||||||
|
|
||||||
|
/** 附件项列表 */
|
||||||
|
private List<Attachment> items = new ArrayList<>();
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import com.imyeyu.java.TimiJava;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
@@ -33,9 +32,6 @@ public class RequireGaoRoleInterceptor implements HandlerInterceptor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
RequireGaoRole annotation = handlerMethod.getMethodAnnotation(RequireGaoRole.class);
|
RequireGaoRole annotation = handlerMethod.getMethodAnnotation(RequireGaoRole.class);
|
||||||
if (annotation == null) {
|
|
||||||
annotation = AnnotatedElementUtils.findMergedAnnotation(handlerMethod.getBeanType(), RequireGaoRole.class);
|
|
||||||
}
|
|
||||||
if (annotation == null || TimiJava.isEmpty(annotation.value())) {
|
if (annotation == null || TimiJava.isEmpty(annotation.value())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.imyeyu.api.modules.gao.bean;
|
|||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.user.bean.BuiltinPermissionCode;
|
import com.imyeyu.api.modules.user.bean.BuiltinPermissionCode;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 模块权限枚举
|
/// GAO 模块权限枚举
|
||||||
@@ -11,43 +10,29 @@ import lombok.Getter;
|
|||||||
/// @since 2026-07-26
|
/// @since 2026-07-26
|
||||||
public enum GaoPermissionCode implements BuiltinPermissionCode {
|
public enum GaoPermissionCode implements BuiltinPermissionCode {
|
||||||
|
|
||||||
STORE_CREATE("STORE:CREATE", "门店创建", false, true),
|
|
||||||
|
|
||||||
STORE_READ("STORE:READ", "门店读取", true, true),
|
|
||||||
|
|
||||||
STORE_EXPORT("STORE:EXPORT", "门店导出", false, true),
|
|
||||||
|
|
||||||
STORE_UPDATE("STORE:UPDATE", "门店修改", true, true),
|
|
||||||
|
|
||||||
STORE_DELETE("STORE:DELETE", "门店删除", false, true),
|
|
||||||
|
|
||||||
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建"),
|
CUSTOMER_CREATE("CUSTOMER:CREATE", "客户创建"),
|
||||||
|
|
||||||
CUSTOMER_READ("CUSTOMER:READ", "客户读取"),
|
CUSTOMER_READ("CUSTOMER:READ", "客户读取"),
|
||||||
|
|
||||||
CUSTOMER_EXPORT("CUSTOMER:EXPORT", "客户导出", true),
|
|
||||||
|
|
||||||
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改"),
|
CUSTOMER_UPDATE("CUSTOMER:UPDATE", "客户修改"),
|
||||||
|
|
||||||
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除"),
|
CUSTOMER_DELETE("CUSTOMER:DELETE", "客户删除"),
|
||||||
|
|
||||||
EVENT_CREATE("EVENT:CREATE", "登记事件创建"),
|
REGISTRATION_EVENT_CREATE("REGISTRATION_EVENT:CREATE", "登记事件创建"),
|
||||||
|
|
||||||
EVENT_READ("EVENT:READ", "登记事件读取"),
|
REGISTRATION_EVENT_READ("REGISTRATION_EVENT:READ", "登记事件读取"),
|
||||||
|
|
||||||
EVENT_UPDATE("EVENT:UPDATE", "登记事件修改"),
|
REGISTRATION_EVENT_UPDATE("REGISTRATION_EVENT:UPDATE", "登记事件修改"),
|
||||||
|
|
||||||
EVENT_DELETE("EVENT:DELETE", "登记事件删除"),
|
REGISTRATION_EVENT_DELETE("REGISTRATION_EVENT:DELETE", "登记事件删除"),
|
||||||
|
|
||||||
EVENT_RECORD_CREATE("EVENT_RECORD:CREATE", "登记事件记录创建"),
|
REGISTRATION_EVENT_RECORD_CREATE("REGISTRATION_EVENT_RECORD:CREATE", "登记事件记录创建"),
|
||||||
|
|
||||||
EVENT_RECORD_READ("EVENT_RECORD:READ", "登记事件记录读取"),
|
REGISTRATION_EVENT_RECORD_READ("REGISTRATION_EVENT_RECORD:READ", "登记事件记录读取"),
|
||||||
|
|
||||||
EVENT_RECORD_EXPORT("EVENT_RECORD:EXPORT", "登记事件记录导出", true),
|
REGISTRATION_EVENT_RECORD_UPDATE("REGISTRATION_EVENT_RECORD:UPDATE", "登记事件记录修改"),
|
||||||
|
|
||||||
EVENT_RECORD_UPDATE("EVENT_RECORD:UPDATE", "登记事件记录修改"),
|
REGISTRATION_EVENT_RECORD_DELETE("REGISTRATION_EVENT_RECORD:DELETE", "登记事件记录删除"),
|
||||||
|
|
||||||
EVENT_RECORD_DELETE("EVENT_RECORD:DELETE", "登记事件记录删除"),
|
|
||||||
|
|
||||||
STAT_READ("STAT:READ", "统计读取"),
|
STAT_READ("STAT:READ", "统计读取"),
|
||||||
|
|
||||||
@@ -63,28 +48,16 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
|
|
||||||
final String value;
|
final String value;
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
|
|
||||||
/// `true` 为初始化时授权给店长角色
|
|
||||||
@Getter
|
|
||||||
final boolean grantToStoreManager;
|
final boolean grantToStoreManager;
|
||||||
|
|
||||||
/// `true` 为初始化时授权给全局管理员角色
|
|
||||||
@Getter
|
|
||||||
final boolean grantToGlobalManager;
|
|
||||||
|
|
||||||
GaoPermissionCode(String value, String defaultName) {
|
GaoPermissionCode(String value, String defaultName) {
|
||||||
this(value, defaultName, false, false);
|
this(value, defaultName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager) {
|
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager) {
|
||||||
this(value, defaultName, grantToStoreManager, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
GaoPermissionCode(String value, String defaultName, boolean grantToStoreManager, boolean grantToGlobalManager) {
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.defaultName = defaultName;
|
this.defaultName = defaultName;
|
||||||
this.grantToStoreManager = grantToStoreManager;
|
this.grantToStoreManager = grantToStoreManager;
|
||||||
this.grantToGlobalManager = grantToGlobalManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,4 +84,11 @@ public enum GaoPermissionCode implements BuiltinPermissionCode {
|
|||||||
public boolean isGrantToAdmin() {
|
public boolean isGrantToAdmin() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// true 为初始化时授权给店长角色
|
||||||
|
///
|
||||||
|
/// @return 是否授权给店长角色
|
||||||
|
public boolean isGrantToStoreManager() {
|
||||||
|
return grantToStoreManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,12 @@ import lombok.AllArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum GaoRoleCode implements BuiltinRoleCode {
|
public enum GaoRoleCode implements BuiltinRoleCode {
|
||||||
|
|
||||||
/// 全局管理员
|
|
||||||
GLOBAL_MANAGER("全局管理员", null),
|
|
||||||
|
|
||||||
/// 店长
|
/// 店长
|
||||||
STORE_MANAGER("店长", GLOBAL_MANAGER.name()),
|
STORE_MANAGER("店长"),
|
||||||
|
|
||||||
EMPLOYEE("员工", STORE_MANAGER.name());
|
EMPLOYEE("员工");
|
||||||
|
|
||||||
final String defaultName;
|
final String defaultName;
|
||||||
final String parentCode;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModuleCode getModuleCode() {
|
public ModuleCode getModuleCode() {
|
||||||
@@ -40,6 +36,6 @@ public enum GaoRoleCode implements BuiltinRoleCode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParentCode() {
|
public String getParentCode() {
|
||||||
return parentCode;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,29 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
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;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
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.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.network.Network;
|
|
||||||
import com.imyeyu.spring.TimiSpring;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.util.ResponseView;
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -38,25 +33,28 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
///
|
||||||
/// GAO 客户接口
|
/// GAO 客户接口
|
||||||
///
|
///
|
||||||
/// @author 夜雨
|
/// @author Codex
|
||||||
/// @since 2026-07-27 14:12
|
/// @since 2026-07-27
|
||||||
@RestController
|
@RestController
|
||||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/customer")
|
@RequestMapping("/gao/customer")
|
||||||
|
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||||
public class GaoCustomerController {
|
public class GaoCustomerController {
|
||||||
|
|
||||||
private final UserService userService;
|
private static final String SIGN_IN_REGISTRATION_EVENT_NAME = "签到";
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
private final GaoCustomerService service;
|
private final GaoCustomerService service;
|
||||||
private final GaoStoreService gaoStoreService;
|
private final GaoRegistrationEventRecordService registrationEventRecordService;
|
||||||
private final UserLoginService userLoginService;
|
private final GaoRegistrationEventService registrationEventService;
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@@ -65,32 +63,74 @@ public class GaoCustomerController {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public PageResult<GaoCustomer> list(@RequestBody Page<GaoCustomer> page) {
|
public PageResult<GaoCustomer> list(@RequestBody Page<GaoCustomer> page) {
|
||||||
PageResult<GaoCustomer> result = service.page(page);
|
PageResult<GaoCustomer> result = service.page(page);
|
||||||
|
fillLastSignInAt(result.getList());
|
||||||
List<String> idList = result.getList().stream().map(GaoCustomer::getId).distinct().toList();
|
|
||||||
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
|
||||||
for (GaoCustomer customer : result.getList()) {
|
|
||||||
customer.setAttachmentList(attachmentMap.get(customer.getId()));
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/search")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public List<GaoCustomer> search(@RequestBody GaoCustomerSearchReq req) {
|
||||||
|
return service.search(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/search/page")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public PageResult<GaoCustomer> searchPage(@RequestBody Page<GaoCustomerSearchReq> page) {
|
||||||
|
return service.searchPage(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(@RequestBody GaoCustomerSearchReq req, HttpServletResponse resp) throws IOException {
|
||||||
|
String fileName = URLEncoder.encode("客户列表.xlsx", "UTF-8").replace("+", "%20");
|
||||||
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
resp.setHeader("Content-Disposition", "attachment; filename=\"gao-customer.xlsx\"; filename*=UTF-8''" + fileName);
|
||||||
|
resp.getOutputStream().write(service.exportSearchExcel(req));
|
||||||
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer detail(@RequestParam String id) {
|
public GaoCustomer detail(@RequestParam String id) {
|
||||||
GaoCustomer customer = service.get(id);
|
return service.get(id);
|
||||||
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
}
|
||||||
GaoCustomer introducerCustomer = service.get(customer.getIntroducerCustomerId());
|
|
||||||
introducerCustomer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, introducerCustomer.getId()));
|
@AOPLog
|
||||||
customer.setIntroducerCustomer(introducerCustomer);
|
@RequestRateLimit
|
||||||
}
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
if (TimiJava.isNotEmpty(customer.getCreatorUserId())) {
|
@PostMapping("/detail/code")
|
||||||
customer.setCreatorUser(userService.get(customer.getCreatorUserId()));
|
@JsonView(ResponseView.Public.class)
|
||||||
}
|
public GaoCustomer detailByCode(@RequestParam String code) {
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
return service.getByCode(code);
|
||||||
return customer;
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/detail/code/nullable")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoCustomer nullableDetailByCode(@RequestParam String code) {
|
||||||
|
return service.getNullableByCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
|
@PostMapping("/invited/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public List<GaoCustomer> invitedList(@RequestParam String introducerCustomerId) {
|
||||||
|
return service.listInvited(introducerCustomerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -98,12 +138,17 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_CREATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public String create(@RequestBody GaoCustomer customer) {
|
public GaoCustomer create(@RequestBody GaoCustomer customer) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
|
||||||
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
service.create(customer);
|
service.create(customer);
|
||||||
return customer.getId();
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/quick/register")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoRegistrationEventRecord quickRegister(@RequestBody GaoQuickRegistrationEventRecordReq req) {
|
||||||
|
return registrationEventRecordService.quickRegister(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -111,10 +156,7 @@ public class GaoCustomerController {
|
|||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public void update(@RequestBody GaoCustomer customer) {
|
public void update(@RequestBody GaoCustomer customer) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
service.update(customer);
|
||||||
customer.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
service.updateWithAttachment(customer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -127,78 +169,27 @@ public class GaoCustomerController {
|
|||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/find/id")
|
@PostMapping("/invite/create")
|
||||||
@JsonView(ResponseView.Public.class)
|
public void createInvite(@RequestBody GaoCustomerInviteUpdateReq req) {
|
||||||
public GaoCustomer findById(@RequestParam String id) {
|
service.saveInviteRelation(req);
|
||||||
GaoCustomer customer = service.get(id);
|
|
||||||
TimiException.required(customer, "not found customer");
|
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
|
||||||
return customer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/find/code")
|
@PostMapping("/invite/detail")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoCustomer findByCode(@RequestParam String storeId, @RequestParam String code) {
|
public GaoCustomer inviteDetail(@RequestParam String customerId) {
|
||||||
GaoCustomer customer = service.getByCode(storeId, code);
|
return service.get(customerId);
|
||||||
if (customer == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
|
||||||
return customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/find/name")
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
public GaoCustomer findByName(@RequestParam String storeId, @RequestParam String name) {
|
|
||||||
GaoCustomer customer = service.getByName(storeId, name);
|
|
||||||
if (customer == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
customer.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId()));
|
|
||||||
return customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_EXPORT)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export(@RequestBody Page<GaoCustomer> page) throws IOException {
|
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
|
||||||
String contentDisposition = Network.getFileDownloadHeader("客户列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
resp.setHeader("Content-Disposition", contentDisposition);
|
|
||||||
resp.getOutputStream().write(service.export(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
|
||||||
@PostMapping("/invited/list")
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
public List<GaoCustomer> listInvited(@RequestParam String introducerCustomerId) {
|
|
||||||
List<GaoCustomer> result = service.listInvited(introducerCustomerId);
|
|
||||||
List<String> idList = result.stream().map(GaoCustomer::getId).distinct().toList();
|
|
||||||
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, idList);
|
|
||||||
for (GaoCustomer customer : result) {
|
|
||||||
customer.setAttachmentList(attachMap.get(customer.getId()));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_UPDATE)
|
||||||
@PostMapping("/invite/save")
|
@PostMapping("/invite/update")
|
||||||
public void saveInvite(@RequestParam String introducerCustomerId, @RequestParam String customerId) {
|
public void updateInvite(@RequestBody GaoCustomerInviteUpdateReq req) {
|
||||||
service.saveInviteRelation(introducerCustomerId, customerId);
|
service.saveInviteRelation(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -209,21 +200,46 @@ public class GaoCustomerController {
|
|||||||
service.deleteInviteRelation(customerId);
|
service.deleteInviteRelation(customerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 按天统计客户新增数和累计总数
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/state/daily")
|
@PostMapping("/stat/daily")
|
||||||
public List<GaoCustomerDailyStateView> dailyStat(@RequestBody GaoCustomerTrendStateReq req) {
|
/// 按天统计客户新增数和累计总数
|
||||||
return service.stateDailyTrend(req);
|
public List<GaoCustomerDailyStatView> dailyStat(@RequestBody GaoCustomerTrendStatReq req) {
|
||||||
|
return service.statDailyTrend(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 统计客户性别分布
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
@RequireGaoPermission(GaoPermissionCode.CUSTOMER_READ)
|
||||||
@PostMapping("/state/gender")
|
@PostMapping("/stat/gender")
|
||||||
public List<GaoCustomerGenderStatView> genderStat(@RequestParam String storeId) {
|
/// 统计客户性别分布
|
||||||
return service.stateGender(storeId);
|
public List<GaoCustomerGenderStatView> genderStat() {
|
||||||
|
return service.statGender();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillLastSignInAt(List<GaoCustomer> customerList) {
|
||||||
|
if (customerList == null || customerList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String signInRegistrationEventId = null;
|
||||||
|
for (GaoRegistrationEvent registrationEvent : registrationEventService.listEnabled()) {
|
||||||
|
if (SIGN_IN_REGISTRATION_EVENT_NAME.equals(registrationEvent.getName())) {
|
||||||
|
signInRegistrationEventId = registrationEvent.getId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (signInRegistrationEventId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> customerIdList = customerList.stream().map(GaoCustomer::getId).toList();
|
||||||
|
Map<String, GaoRegistrationEventRecord> recordMap = registrationEventRecordService.listLatestByCustomerIdListAndRegistrationEventId(customerIdList, signInRegistrationEventId).stream()
|
||||||
|
.collect(Collectors.toMap(GaoRegistrationEventRecord::getCustomerId, Function.identity(), (left, right) -> left));
|
||||||
|
for (GaoCustomer customer : customerList) {
|
||||||
|
GaoRegistrationEventRecord record = recordMap.get(customer.getId());
|
||||||
|
if (record != null) {
|
||||||
|
customer.setLastSignInAt(record.getRegisteredAt());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
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;
|
|
||||||
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;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
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.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/// GAO 登记事件接口
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 14:13
|
|
||||||
@RestController
|
|
||||||
@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
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoEvent> list(@RequestBody Page<GaoEvent> page) {
|
|
||||||
PageResult<GaoEvent> result = service.page(page);
|
|
||||||
Map<String, List<String>> roleMap = service.mapRoleCodeListByEventIdList(result.getList().stream().map(GaoEvent::getId).toList());
|
|
||||||
for (GaoEvent event : result.getList()) {
|
|
||||||
event.setRoleCodeList(roleMap.get(event.getId()));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@PostMapping("/list/valid")
|
|
||||||
public List<GaoEvent> listValid(@RequestParam String storeId) {
|
|
||||||
return service.listValid(storeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoEvent detail(@RequestParam String id) {
|
|
||||||
return service.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_CREATE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
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 event) {
|
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
|
||||||
event.setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
service.update(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_UPDATE)
|
|
||||||
@PostMapping("/sort")
|
|
||||||
public void sort(@RequestBody List<String> idList) {
|
|
||||||
service.sort(idList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
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;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
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.entity.GaoEvent;
|
|
||||||
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;
|
|
||||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.util.ResponseView;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
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.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/// GAO 登记事件记录接口
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 14:11
|
|
||||||
@RestController
|
|
||||||
@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
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
public PageResult<GaoEventRecord> list(@RequestBody GaoEventRecordPage page) {
|
|
||||||
PageResult<GaoEventRecord> result = service.pageByRange(page);
|
|
||||||
{
|
|
||||||
List<String> customerIdList = result.getList().stream().map(GaoEventRecord::getCustomerId).toList();
|
|
||||||
Map<String, GaoEvent> eventMap = eventService.mapByIdList(result.getList().stream().map(GaoEventRecord::getEventId).toList());
|
|
||||||
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(customerIdList);
|
|
||||||
Map<String, List<Attachment>> attachMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
|
||||||
for (GaoEventRecord record : result.getList()) {
|
|
||||||
record.setEvent(eventMap.get(record.getEventId()));
|
|
||||||
record.setCustomer(customerMap.get(record.getCustomerId()));
|
|
||||||
record.getCustomer().setAttachmentList(attachMap.get(record.getCustomerId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
public GaoEventRecord detail(@RequestParam String id) {
|
|
||||||
GaoEventRecord record = service.get(id);
|
|
||||||
record.setCustomer(customerService.get(record.getCustomerId()));
|
|
||||||
record.getCustomer().setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_CUSTOMER, record.getCustomerId()));
|
|
||||||
record.setEvent(eventService.get(record.getEventId()));
|
|
||||||
record.setOperator(userService.get(record.getOperatorUserId()));
|
|
||||||
record.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId()));
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.EVENT_RECORD_EXPORT)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export(@RequestBody GaoEventRecordPage page) throws IOException {
|
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
|
||||||
String contentDisposition = Network.getFileDownloadHeader("登记事件记录-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
resp.setHeader("Content-Disposition", contentDisposition);
|
|
||||||
resp.getOutputStream().write(service.export(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 按时间范围查询客户登记排行榜
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
|
||||||
@PostMapping("/rank")
|
|
||||||
public PageResult<GaoCustomerEventRankView> eventRank(@RequestBody GaoEventRecordRankPage page) {
|
|
||||||
PageResult<GaoCustomerEventRankView> result = service.pageRankByRange(page);
|
|
||||||
List<String> customerIdList = result.getList().stream().map(GaoCustomerEventRankView::getCustomerId).distinct().toList();
|
|
||||||
if (customerIdList.isEmpty()) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Map<String, GaoCustomer> customerMap = customerService.mapByIdList(customerIdList);
|
|
||||||
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList);
|
|
||||||
for (GaoCustomerEventRankView view : result.getList()) {
|
|
||||||
GaoCustomer customer = customerMap.get(view.getCustomerId());
|
|
||||||
if (customer != null) {
|
|
||||||
customer.setAttachmentList(attachmentMap.get(view.getCustomerId()));
|
|
||||||
}
|
|
||||||
view.setCustomer(customer);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
||||||
|
import com.imyeyu.api.bean.RoleMatchMode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 登记事件接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/registration-event")
|
||||||
|
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||||
|
public class GaoRegistrationEventController {
|
||||||
|
|
||||||
|
private final GaoRegistrationEventService service;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
public PageResult<GaoRegistrationEvent> list(@RequestBody Page<GaoRegistrationEvent> page) {
|
||||||
|
return service.pageWithRegistrationEventLimit(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/enabled/list")
|
||||||
|
public List<GaoRegistrationEvent> enabledList() {
|
||||||
|
return service.listEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public GaoRegistrationEvent detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_CREATE)
|
||||||
|
@PostMapping("/create")
|
||||||
|
public void create(@RequestBody GaoRegistrationEvent registrationEvent) {
|
||||||
|
service.create(registrationEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoRegistrationEvent registrationEvent) {
|
||||||
|
service.update(registrationEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
+191
@@ -0,0 +1,191 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
|
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.entity.GaoRegistrationEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordListItemView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
||||||
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
|
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||||
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// GAO 登记事件记录接口
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/gao/registration-event-record")
|
||||||
|
@RequireGaoRole(value = {GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
||||||
|
public class GaoRegistrationEventRecordController {
|
||||||
|
|
||||||
|
private final GaoRegistrationEventRecordService service;
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public PageResult<GaoRegistrationEventRecord> list(@RequestBody Page<GaoRegistrationEventRecord> page) {
|
||||||
|
return service.page(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/range/page")
|
||||||
|
public PageResult<GaoRegistrationEventRecordListItemView> rangePage(@RequestBody Page<GaoRegistrationEventRecordRangeReq> page) {
|
||||||
|
return service.pageByRange(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/detail")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoRegistrationEventRecord detail(@RequestParam String id) {
|
||||||
|
return service.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@PostMapping("/create")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoRegistrationEventRecord create(@RequestBody GaoRegistrationEventRecordCreateReq req) {
|
||||||
|
return service.createRecord(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_UPDATE)
|
||||||
|
@PostMapping("/update")
|
||||||
|
public void update(@RequestBody GaoRegistrationEventRecord record) {
|
||||||
|
service.update(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_DELETE)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public void delete(@RequestParam String id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/period/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public List<GaoRegistrationEventRecord> periodList(@RequestBody GaoRegistrationEventRecordPeriodReq req) {
|
||||||
|
return service.listByRegistrationEventAndPeriod(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/range/list")
|
||||||
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public List<GaoRegistrationEventRecord> rangeList(@RequestBody GaoRegistrationEventRecordRangeReq req) {
|
||||||
|
return service.listByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/range/calendar/list")
|
||||||
|
public List<GaoRegistrationEventRecordCalendarView> calendarRangeList(@RequestBody GaoRegistrationEventRecordRangeReq req) {
|
||||||
|
return service.listCalendarByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@IgnoreGlobalReturn
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.REGISTRATION_EVENT_RECORD_READ)
|
||||||
|
@PostMapping("/range/export")
|
||||||
|
public void rangeExport(@RequestBody GaoRegistrationEventRecordRangeReq req, HttpServletResponse resp) throws IOException {
|
||||||
|
String fileName = URLEncoder.encode("登记事件记录.xlsx", "UTF-8").replace("+", "%20");
|
||||||
|
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
resp.setHeader("Content-Disposition", "attachment; filename=\"gao-registration-event-record.xlsx\"; filename*=UTF-8''" + fileName);
|
||||||
|
resp.getOutputStream().write(service.exportRangeExcel(req));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/period/stat")
|
||||||
|
public List<GaoRegistrationEventPeriodStatView> periodStat(@RequestBody GaoRegistrationEventRecordPeriodReq req) {
|
||||||
|
return service.statByRegistrationEventAndPeriodType(req.getRegistrationEventId(), req.getPeriodType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/stat")
|
||||||
|
public List<GaoCustomerRegisterStatView> customerStat(@RequestParam String customerId) {
|
||||||
|
return service.statByCustomerId(customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/range/stat")
|
||||||
|
/// 按时间段统计单个客户各登记事件记录数
|
||||||
|
public List<GaoCustomerRegisterStatView> customerRangeStat(@RequestBody GaoRegistrationEventRecordStatReq req) {
|
||||||
|
return service.statByCustomerAndRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/all-customer/range/stat")
|
||||||
|
/// 按时间段统计全部客户各登记事件记录数
|
||||||
|
public List<GaoCustomerRegisterStatView> allCustomerRangeStat(@RequestBody GaoRegistrationEventRecordStatReq req) {
|
||||||
|
return service.statAllCustomerByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/customer/registration-event/daily/stat")
|
||||||
|
/// 按天统计单个客户单个登记事件记录趋势
|
||||||
|
public List<GaoRegistrationEventRecordDailyStatView> customerRegistrationEventDailyStat(@RequestBody GaoRegistrationEventRecordTrendStatReq req) {
|
||||||
|
return service.statDailyByCustomerAndRegistrationEvent(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AOPLog
|
||||||
|
@RequestRateLimit
|
||||||
|
@RequireGaoPermission(GaoPermissionCode.STAT_READ)
|
||||||
|
@PostMapping("/all-customer/registration-event/daily/stat")
|
||||||
|
/// 按天统计全部客户单个登记事件记录趋势
|
||||||
|
public List<GaoRegistrationEventRecordDailyStatView> allCustomerRegistrationEventDailyStat(@RequestBody GaoRegistrationEventRecordTrendStatReq req) {
|
||||||
|
return service.statDailyByRegistrationEvent(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,14 +14,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
/// GAO 角色接口
|
/// GAO 角色接口
|
||||||
///
|
///
|
||||||
/// @author 夜雨
|
/// @author Codex
|
||||||
/// @since 2026-07-28 14:15
|
/// @since 2026-07-28
|
||||||
@RestController
|
@RestController
|
||||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/role")
|
@RequestMapping("/gao/role")
|
||||||
|
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
||||||
public class GaoRoleController {
|
public class GaoRoleController {
|
||||||
|
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
|||||||
-82
@@ -1,82 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.controller;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
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.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 门店营业日接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/store/business/day")
|
|
||||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
|
||||||
public class GaoStoreBusinessDayController {
|
|
||||||
|
|
||||||
private final GaoStoreBusinessDayService service;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoStoreBusinessDay> list(@RequestBody Page<GaoStoreBusinessDay> page) {
|
|
||||||
return service.page(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
|
||||||
@PostMapping("/calendar")
|
|
||||||
public List<GaoStoreBusinessDay> calendar(@RequestParam String storeId, @RequestParam Integer beginDateValue, @RequestParam Integer endDateValue) {
|
|
||||||
return service.listByDateRange(storeId, beginDateValue, endDateValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoStoreBusinessDay detail(@RequestParam String id) {
|
|
||||||
return service.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_CREATE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
public String create(@RequestBody GaoStoreBusinessDay businessDay) {
|
|
||||||
service.create(businessDay);
|
|
||||||
return businessDay.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
|
||||||
@PostMapping("/update")
|
|
||||||
public void update(@RequestBody GaoStoreBusinessDay businessDay) {
|
|
||||||
service.update(businessDay);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
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;
|
|
||||||
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.network.Network;
|
|
||||||
import com.imyeyu.spring.TimiSpring;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
|
||||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
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.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// GAO 门店接口
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/gao/store")
|
|
||||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
|
||||||
public class GaoStoreController {
|
|
||||||
|
|
||||||
private final GaoStoreService service;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResult<GaoStore> list(@RequestBody Page<GaoStore> page) {
|
|
||||||
return service.page(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_READ)
|
|
||||||
@PostMapping("/detail")
|
|
||||||
public GaoStore detail(@RequestParam String id) {
|
|
||||||
return service.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_CREATE)
|
|
||||||
@PostMapping("/create")
|
|
||||||
public String create(@RequestBody GaoStore store) {
|
|
||||||
service.create(store);
|
|
||||||
return store.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
|
||||||
@PostMapping("/update")
|
|
||||||
public void update(@RequestBody GaoStore store) {
|
|
||||||
service.update(store);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_DELETE)
|
|
||||||
@PostMapping("/delete")
|
|
||||||
public void delete(@RequestParam String id) {
|
|
||||||
service.delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_UPDATE)
|
|
||||||
@PostMapping("/sort")
|
|
||||||
public void sort(@RequestBody List<String> idList) {
|
|
||||||
service.sort(idList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@IgnoreGlobalReturn
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.STORE_EXPORT)
|
|
||||||
@PostMapping("/export")
|
|
||||||
public void export(@RequestBody Page<GaoStore> page) throws IOException {
|
|
||||||
HttpServletResponse resp = TimiSpring.getResponse();
|
|
||||||
String contentDisposition = Network.getFileDownloadHeader("门店列表-%s.xlsx".formatted(Time.serialize.format(Time.now())));
|
|
||||||
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
||||||
resp.setHeader("Content-Disposition", contentDisposition);
|
|
||||||
resp.getOutputStream().write(service.export(page));
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoRole(value = {GaoRoleCode.GLOBAL_MANAGER, GaoRoleCode.STORE_MANAGER, GaoRoleCode.EMPLOYEE}, mode = RoleMatchMode.ANY)
|
|
||||||
@PostMapping("/user")
|
|
||||||
public GaoStore getLoginStore() {
|
|
||||||
return service.getByUserId(userLoginService.getRequireLoginUserId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,23 +2,14 @@ package com.imyeyu.api.modules.gao.controller;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonView;
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
import com.imyeyu.api.modules.gao.annotation.RequireGaoRole;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||||
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
import com.imyeyu.api.modules.gao.bean.GaoRoleCode;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
@@ -32,26 +23,20 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
///
|
||||||
/// GAO 用户接口
|
/// GAO 用户接口
|
||||||
///
|
///
|
||||||
/// @author 夜雨
|
/// @author Codex
|
||||||
/// @since 2026-07-30 14:15
|
/// @since 2026-07-30
|
||||||
@RestController
|
@RestController
|
||||||
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/gao/user")
|
@RequestMapping("/gao/user")
|
||||||
|
@RequireGaoRole(GaoRoleCode.STORE_MANAGER)
|
||||||
public class GaoUserController {
|
public class GaoUserController {
|
||||||
|
|
||||||
private final UserService userService;
|
|
||||||
private final RoleService roleService;
|
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final GaoUserService service;
|
private final GaoUserService service;
|
||||||
private final UserRoleService userRoleService;
|
private final RoleService roleService;
|
||||||
private final GaoStoreService gaoStoreService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@@ -59,22 +44,7 @@ public class GaoUserController {
|
|||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public PageResult<GaoUser> list(@RequestBody Page<GaoUser> page) {
|
public PageResult<GaoUser> list(@RequestBody Page<GaoUser> page) {
|
||||||
if (!roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name())) {
|
return service.pageWithUser(page);
|
||||||
// 非全局管理只能看所在店用户
|
|
||||||
page.setEqualsExample(TimiJava.defaultIfNull(page.getEqualsExample(), new GaoUser()));
|
|
||||||
page.getEqualsExample().setStoreId(gaoStoreService.getByUserId(userLoginService.getRequireLoginUserId()).getId());
|
|
||||||
}
|
|
||||||
PageResult<GaoUser> result = service.page(page);
|
|
||||||
{
|
|
||||||
List<String> userIdList = result.getList().stream().map(GaoUser::getUserId).toList();
|
|
||||||
Map<String, User> userMap = userService.mapByIdList(userIdList);
|
|
||||||
Map<String, List<Role>> roleMap = userRoleService.mapRoleListByUserIdList(userIdList);
|
|
||||||
for (GaoUser gaoUser : result.getList()) {
|
|
||||||
gaoUser.setUser(userMap.get(gaoUser.getUserId()));
|
|
||||||
gaoUser.getUser().setRoleEntityList(roleMap.get(gaoUser.getUserId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -83,14 +53,16 @@ public class GaoUserController {
|
|||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoUser detail(@RequestParam String id) {
|
public GaoUser detail(@RequestParam String id) {
|
||||||
GaoUser result = service.get(id);
|
return service.get(id);
|
||||||
{
|
}
|
||||||
User user = userService.get(result.getUserId());
|
|
||||||
user.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.USER, user.getId()));
|
@AOPLog
|
||||||
user.setRoleEntityList(userRoleService.listRoleByUserId(user.getId()));
|
@RequestRateLimit
|
||||||
result.setUser(user);
|
@RequireGaoPermission(GaoPermissionCode.USER_READ)
|
||||||
}
|
@PostMapping("/detail/user")
|
||||||
return result;
|
@JsonView(ResponseView.Public.class)
|
||||||
|
public GaoUser detailByUserId(@RequestParam String userId) {
|
||||||
|
return service.getByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@@ -99,9 +71,6 @@ public class GaoUserController {
|
|||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
public GaoUser create(@RequestBody GaoUser gaoUser) {
|
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);
|
service.create(gaoUser);
|
||||||
return service.get(gaoUser.getId());
|
return service.get(gaoUser.getId());
|
||||||
}
|
}
|
||||||
@@ -116,17 +85,6 @@ public class GaoUserController {
|
|||||||
return service.get(gaoUser.getId());
|
return service.get(gaoUser.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
|
||||||
@RequestRateLimit
|
|
||||||
@RequireGaoRole(GaoRoleCode.GLOBAL_MANAGER)
|
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_UPDATE)
|
|
||||||
@PostMapping("/transfer/store")
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
public GaoUser transferStore(@RequestBody GaoUser gaoUser) {
|
|
||||||
service.transferStore(gaoUser);
|
|
||||||
return service.get(gaoUser.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequireGaoPermission(GaoPermissionCode.USER_DELETE)
|
@RequireGaoPermission(GaoPermissionCode.USER_DELETE)
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.user.bean.Gender;
|
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.api.modules.user.bean.Gender;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -33,24 +30,9 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
PHOTO
|
PHOTO
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// 出生日期使用的历法
|
|
||||||
///
|
|
||||||
public enum BirthdateCalendar {
|
|
||||||
|
|
||||||
/// 公历
|
|
||||||
SOLAR,
|
|
||||||
|
|
||||||
/// 农历
|
|
||||||
LUNAR
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 客户编码
|
/// 客户编码
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 姓名
|
/// 姓名
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@@ -58,14 +40,7 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
private Gender gender;
|
private Gender gender;
|
||||||
|
|
||||||
/// 年龄
|
/// 年龄
|
||||||
private Long age;
|
private Integer age;
|
||||||
|
|
||||||
/// 出生日期,数据库只保存公历日期
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
|
||||||
private LocalDate birthdate;
|
|
||||||
|
|
||||||
/// 出生日期录入时使用的历法
|
|
||||||
private BirthdateCalendar birthdateCalendar;
|
|
||||||
|
|
||||||
/// 电话
|
/// 电话
|
||||||
private String telephone;
|
private String telephone;
|
||||||
@@ -85,27 +60,24 @@ public class GaoCustomer extends UUIDEntity {
|
|||||||
/// 介绍人客户 ID
|
/// 介绍人客户 ID
|
||||||
private String introducerCustomerId;
|
private String introducerCustomerId;
|
||||||
|
|
||||||
private Long invitedCount;
|
|
||||||
|
|
||||||
/// 录入用户 ID
|
/// 录入用户 ID
|
||||||
private String creatorUserId;
|
private String creatorUserId;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private Long lastSignInAt;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoCustomer introducerCustomer;
|
private GaoCustomer introducerCustomer;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private User creatorUser;
|
private User creatorUser;
|
||||||
|
|
||||||
|
private Long invitedCount;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
|
/// 临时照片附件 ID 列表
|
||||||
@Transient
|
@Transient
|
||||||
private GaoEventRecord eventRecord;
|
private List<String> attachmentIdList;
|
||||||
|
|
||||||
@Transient
|
|
||||||
private List<GaoEventRecord> eventRecordList;
|
|
||||||
|
|
||||||
public boolean hasIntroducer() {
|
|
||||||
return TimiJava.isNotEmpty(introducerCustomerId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoEvent extends UUIDEntity {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件状态
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-01
|
|
||||||
public enum Status {
|
|
||||||
|
|
||||||
/// 草稿,未发布不可登记
|
|
||||||
DRAFT,
|
|
||||||
|
|
||||||
/// 可登记
|
|
||||||
ACTIVE,
|
|
||||||
|
|
||||||
/// 无效,不可登记但保留统计
|
|
||||||
INACTIVE,
|
|
||||||
|
|
||||||
/// 已删除,不可登记但保留统计
|
|
||||||
DELETED
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 登记限制类型
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-08-01 14:37
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum LimitType {
|
|
||||||
|
|
||||||
/// 不限制
|
|
||||||
NONE(null),
|
|
||||||
|
|
||||||
/// 每天上午、下午各 N 次
|
|
||||||
DAILY_HALF_DAY(1L),
|
|
||||||
|
|
||||||
/// 每个自然日 N 次
|
|
||||||
NATURAL_DAY(1L),
|
|
||||||
|
|
||||||
/// 每隔 N 小时一次
|
|
||||||
INTERVAL_HOUR(1L),
|
|
||||||
|
|
||||||
/// 每个自然月 N 次
|
|
||||||
NATURAL_MONTH(1L),
|
|
||||||
|
|
||||||
/// 事件总登记次数上限
|
|
||||||
TOTAL_LIMIT(1L),
|
|
||||||
|
|
||||||
/// 单个客户总登记次数上限
|
|
||||||
CUSTOMER_TOTAL_LIMIT(1L);
|
|
||||||
|
|
||||||
final Long min;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 登记事件名称
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 说明
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
/// 统计图表颜色
|
|
||||||
private String color;
|
|
||||||
|
|
||||||
/// 状态
|
|
||||||
private Status status;
|
|
||||||
|
|
||||||
/// true 为登记时要求拍照
|
|
||||||
private Boolean requirePhoto;
|
|
||||||
|
|
||||||
/// 登记限制类型
|
|
||||||
private LimitType limitType;
|
|
||||||
|
|
||||||
/// 登记限制数值,按限制类型表示小时数或次数
|
|
||||||
private Integer limitValue;
|
|
||||||
|
|
||||||
/// 可登记起始时间戳,毫秒,空为不限制
|
|
||||||
private Long beginAt;
|
|
||||||
|
|
||||||
/// 可登记终止时间戳,毫秒,空为不限制
|
|
||||||
private Long endAt;
|
|
||||||
|
|
||||||
/// 排序值
|
|
||||||
private Integer sort;
|
|
||||||
|
|
||||||
/// 可登记角色代码列表
|
|
||||||
@Transient
|
|
||||||
private List<String> roleCodeList;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class GaoRegistrationEvent extends UUIDEntity {
|
||||||
|
|
||||||
|
/// 登记事件名称
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/// 说明
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/// true 为启用
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
/// true 为登记时要求拍照
|
||||||
|
private Boolean requirePhoto;
|
||||||
|
|
||||||
|
/// 排序值
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/// 可登记角色代码列表
|
||||||
|
@Transient
|
||||||
|
private List<String> roleCodeList;
|
||||||
|
}
|
||||||
+5
-14
@@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class GaoEventRecord extends UUIDEntity {
|
public class GaoRegistrationEventRecord extends UUIDEntity {
|
||||||
|
|
||||||
///
|
///
|
||||||
/// 登记事件记录附件类型
|
/// 登记事件记录附件类型
|
||||||
@@ -31,11 +31,8 @@ public class GaoEventRecord extends UUIDEntity {
|
|||||||
/// 客户 ID
|
/// 客户 ID
|
||||||
private String customerId;
|
private String customerId;
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 登记登记事件 ID
|
/// 登记登记事件 ID
|
||||||
private String eventId;
|
private String registrationEventId;
|
||||||
|
|
||||||
/// 操作管理员用户 ID
|
/// 操作管理员用户 ID
|
||||||
private String operatorUserId;
|
private String operatorUserId;
|
||||||
@@ -46,17 +43,11 @@ public class GaoEventRecord extends UUIDEntity {
|
|||||||
/// 登记时间
|
/// 登记时间
|
||||||
private Long registeredAt;
|
private Long registeredAt;
|
||||||
|
|
||||||
/// 登记日期值,格式为 yyyyMMdd
|
|
||||||
private Integer registeredDateValue;
|
|
||||||
|
|
||||||
/// 营业日递增序号
|
|
||||||
private Long businessDayNo;
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoCustomer customer;
|
private GaoCustomer customer;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private GaoEvent event;
|
private GaoRegistrationEvent registrationEvent;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private User operator;
|
private User operator;
|
||||||
@@ -64,7 +55,7 @@ public class GaoEventRecord extends UUIDEntity {
|
|||||||
@Transient
|
@Transient
|
||||||
private List<Attachment> attachmentList;
|
private List<Attachment> attachmentList;
|
||||||
|
|
||||||
/// 客户 ID 列表,批量登记时使用
|
/// 临时照片附件 ID 列表
|
||||||
@Transient
|
@Transient
|
||||||
private List<String> customerIdList;
|
private List<String> attachmentIdList;
|
||||||
}
|
}
|
||||||
+2
-2
@@ -11,10 +11,10 @@ import lombok.EqualsAndHashCode;
|
|||||||
/// @since 2026-07-28
|
/// @since 2026-07-28
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class GaoEventRoleRelation extends UUIDEntity {
|
public class GaoRegistrationEventRoleRelation extends UUIDEntity {
|
||||||
|
|
||||||
/// 登记事件 ID
|
/// 登记事件 ID
|
||||||
private String eventId;
|
private String registrationEventId;
|
||||||
|
|
||||||
/// 角色代码
|
/// 角色代码
|
||||||
private String roleCode;
|
private String roleCode;
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoStore extends UUIDEntity {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 门店状态
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public enum Status {
|
|
||||||
|
|
||||||
/// 可用
|
|
||||||
ACTIVE,
|
|
||||||
|
|
||||||
/// 停用
|
|
||||||
INACTIVE,
|
|
||||||
|
|
||||||
/// 已删除
|
|
||||||
DELETED
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 门店编码
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
/// 门店名称
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/// 状态
|
|
||||||
private Status status;
|
|
||||||
|
|
||||||
/// 电话
|
|
||||||
private String telephone;
|
|
||||||
|
|
||||||
/// 地址
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
/// 备注
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
/// 排序值
|
|
||||||
private Integer sort;
|
|
||||||
|
|
||||||
public boolean isActivated() {
|
|
||||||
return status == Status.ACTIVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
|
||||||
|
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店营业日
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoStoreBusinessDay extends UUIDEntity {
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 营业状态
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public enum OpenStatus {
|
|
||||||
|
|
||||||
/// 营业
|
|
||||||
OPEN,
|
|
||||||
|
|
||||||
/// 休息
|
|
||||||
CLOSED
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 日期值,格式为 yyyyMMdd
|
|
||||||
private Integer dateValue;
|
|
||||||
|
|
||||||
/// 营业状态
|
|
||||||
private OpenStatus openStatus;
|
|
||||||
|
|
||||||
/// 营业日递增序号,仅营业日有值
|
|
||||||
private Long businessDayNo;
|
|
||||||
|
|
||||||
/// 原因
|
|
||||||
private String reason;
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.imyeyu.api.modules.gao.entity;
|
package com.imyeyu.api.modules.gao.entity;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 用户
|
/// GAO 用户
|
||||||
///
|
///
|
||||||
@@ -18,9 +21,6 @@ public class GaoUser extends UUIDEntity {
|
|||||||
/// 用户 ID
|
/// 用户 ID
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// true 为启用
|
/// true 为启用
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
|
|
||||||
@@ -29,4 +29,10 @@ public class GaoUser extends UUIDEntity {
|
|||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<Role> roleList;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private List<String> roleIdList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
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.Select;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -16,23 +16,41 @@ import java.util.List;
|
|||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
||||||
|
|
||||||
List<GaoCustomer> selectByIdList(Collection<String> idList);
|
@Select("SELECT * FROM `gao_customer` WHERE `code` = #{code} AND `deleted_at` IS NULL LIMIT 1")
|
||||||
|
GaoCustomer selectByCode(@Param("code") String code);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM `gao_customer` WHERE `name` = #{name} AND `deleted_at` IS NULL LIMIT 1")
|
||||||
|
GaoCustomer selectByName(@Param("name") String name);
|
||||||
|
|
||||||
|
List<GaoCustomer> selectByIdList(@Param("idList") List<String> idList);
|
||||||
|
|
||||||
|
List<GaoCustomer> search(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
|
||||||
|
|
||||||
|
Long countSearch(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
|
||||||
|
|
||||||
|
List<GaoCustomer> searchPage(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId, @Param("offset") Long offset, @Param("size") Long size);
|
||||||
|
|
||||||
|
List<GaoCustomer> selectInvitedList(@Param("introducerCustomerId") String introducerCustomerId);
|
||||||
|
|
||||||
|
Long countInvited(@Param("introducerCustomerId") String introducerCustomerId);
|
||||||
|
|
||||||
|
void updateInvitedCountDelta(@Param("customerId") String customerId, @Param("delta") Long delta);
|
||||||
|
|
||||||
/// 统计每日新增客户数
|
/// 统计每日新增客户数
|
||||||
///
|
///
|
||||||
/// @param beginCreatedAt 开始创建时间
|
/// @param beginCreatedAt 开始创建时间
|
||||||
/// @param endCreatedAt 结束创建时间
|
/// @param endCreatedAt 结束创建时间
|
||||||
/// @return 每日新增客户数
|
/// @return 每日新增客户数
|
||||||
List<GaoCustomerDailyStateView> stateDailyNewCustomer(@Param("storeId") String storeId, @Param("beginCreatedAt") Long beginCreatedAt, @Param("endCreatedAt") Long endCreatedAt);
|
List<GaoCustomerDailyStatView> statDailyNewCustomer(@Param("beginCreatedAt") Long beginCreatedAt, @Param("endCreatedAt") Long endCreatedAt);
|
||||||
|
|
||||||
/// 统计开始时间前客户总数
|
/// 统计开始时间前客户总数
|
||||||
///
|
///
|
||||||
/// @param beginCreatedAt 开始创建时间
|
/// @param beginCreatedAt 开始创建时间
|
||||||
/// @return 客户总数
|
/// @return 客户总数
|
||||||
Long countCreatedBefore(@Param("storeId") String storeId, @Param("beginCreatedAt") Long beginCreatedAt);
|
Long countCreatedBefore(@Param("beginCreatedAt") Long beginCreatedAt);
|
||||||
|
|
||||||
/// 统计客户性别分布
|
/// 统计客户性别分布
|
||||||
///
|
///
|
||||||
/// @return 性别统计列表
|
/// @return 性别统计列表
|
||||||
List<GaoCustomerGenderStatView> stateGender(@Param("storeId") String storeId);
|
List<GaoCustomerGenderStatView> statGender();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件 Mapper
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 15:53
|
|
||||||
public interface GaoEventMapper extends BaseMapper<GaoEvent, String> {
|
|
||||||
|
|
||||||
List<GaoEvent> selectByIdList(Collection<String> idList);
|
|
||||||
|
|
||||||
List<GaoEvent> selectValidList(@Param("storeId") String storeId, @Param("now") Long now);
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
|
||||||
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.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// 登记事件记录 Mapper
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 14:11
|
|
||||||
public interface GaoEventRecordMapper extends BaseMapper<GaoEventRecord, String> {
|
|
||||||
|
|
||||||
Long count(String storeId, String customerId, String eventId, Long beginAt, Long endAt);
|
|
||||||
|
|
||||||
/// 按门店和登记日期统计登记记录数
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param registeredDateValue 登记日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 登记记录数
|
|
||||||
Long countByStoreIdAndRegisteredDateValue(@Param("storeId") String storeId, @Param("registeredDateValue") Integer registeredDateValue);
|
|
||||||
|
|
||||||
/// 同步门店指定日期的登记记录营业日序号快照
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param registeredDateValue 登记日期值,格式为 yyyyMMdd
|
|
||||||
/// @param businessDayNo 营业日序号
|
|
||||||
void updateBusinessDayNoByStoreIdAndRegisteredDateValue(@Param("storeId") String storeId, @Param("registeredDateValue") Integer registeredDateValue, @Param("businessDayNo") Long businessDayNo);
|
|
||||||
|
|
||||||
long countByRange(GaoEventRecordPage page);
|
|
||||||
|
|
||||||
/// 按任意时间范围查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
List<GaoEventRecord> selectByRange(GaoEventRecordPage page);
|
|
||||||
|
|
||||||
/// 统计客户登记排行榜总数
|
|
||||||
///
|
|
||||||
/// @param page 排行榜分页请求
|
|
||||||
/// @return 客户数
|
|
||||||
long countRankByRange(GaoEventRecordRankPage page);
|
|
||||||
|
|
||||||
/// 分页查询客户登记排行榜
|
|
||||||
///
|
|
||||||
/// @param page 排行榜分页请求
|
|
||||||
/// @return 客户登记排行榜
|
|
||||||
List<GaoCustomerEventRankView> selectRankByRange(GaoEventRecordRankPage page);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRoleRelation;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// 登记事件角色关联 Mapper
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-28 14:23
|
|
||||||
public interface GaoEventRoleRelationMapper extends BaseMapper<GaoEventRoleRelation, String> {
|
|
||||||
|
|
||||||
List<GaoEventRoleRelation> selectAllByEventIdList(Collection<String> idList);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public interface GaoRegistrationEventMapper extends BaseMapper<GaoRegistrationEvent, String> {
|
||||||
|
|
||||||
|
List<GaoRegistrationEvent> selectByIdList(@Param("idList") List<String> idList);
|
||||||
|
|
||||||
|
@Select("SELECT * FROM `gao_registration_event` WHERE `enabled` = TRUE AND `deleted_at` IS NULL ORDER BY `sort` ASC, `created_at` ASC")
|
||||||
|
List<GaoRegistrationEvent> selectEnabledList();
|
||||||
|
}
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordListItemView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public interface GaoRegistrationEventRecordMapper extends BaseMapper<GaoRegistrationEventRecord, String> {
|
||||||
|
|
||||||
|
/// 按登记事件查询客户最后登记事件记录
|
||||||
|
///
|
||||||
|
/// @param customerIdList 客户 ID 列表
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @return 最后登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> selectByRegistrationEventAndPeriod(@Param("registrationEventId") String registrationEventId, @Param("periodType") GaoRegistrationEventRecordPeriodReq.PeriodType periodType, @Param("periodValue") Integer periodValue);
|
||||||
|
|
||||||
|
/// 按周期统计登记事件记录
|
||||||
|
///
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param periodType 周期类型
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(@Param("registrationEventId") String registrationEventId, @Param("periodType") GaoRegistrationEventRecordPeriodReq.PeriodType periodType);
|
||||||
|
|
||||||
|
/// 统计客户所有登记
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statByCustomerId(@Param("customerId") String customerId);
|
||||||
|
|
||||||
|
/// 按时间段统计单个客户登记
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @param endRegisteredAt 结束登记时间
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statByCustomerIdAndRange(@Param("customerId") String customerId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
||||||
|
|
||||||
|
/// 按时间段统计全部客户登记
|
||||||
|
///
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @param endRegisteredAt 结束登记时间
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statAllCustomerByRange(@Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
||||||
|
|
||||||
|
/// 统计单个客户单个登记事件的每日登记事件记录数
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @param endRegisteredAt 结束登记时间
|
||||||
|
/// @return 每日统计
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> statDailyCountByCustomerIdAndRegistrationEventIdRange(@Param("customerId") String customerId, @Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
||||||
|
|
||||||
|
/// 统计全部客户单个登记事件的每日登记事件记录数
|
||||||
|
///
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @param endRegisteredAt 结束登记时间
|
||||||
|
/// @return 每日统计
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> statDailyCountByRegistrationEventIdRange(@Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt, @Param("endRegisteredAt") Long endRegisteredAt);
|
||||||
|
|
||||||
|
/// 统计时间段前单个客户单个登记事件累计登记事件记录数
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @return 累计登记数
|
||||||
|
Long countBeforeByCustomerIdAndRegistrationEventId(@Param("customerId") String customerId, @Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt);
|
||||||
|
|
||||||
|
/// 统计时间段前全部客户单个登记事件累计登记事件记录数
|
||||||
|
///
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param beginRegisteredAt 开始登记时间
|
||||||
|
/// @return 累计登记数
|
||||||
|
Long countBeforeByRegistrationEventId(@Param("registrationEventId") String registrationEventId, @Param("beginRegisteredAt") Long beginRegisteredAt);
|
||||||
|
|
||||||
|
/// 查询客户指定登记事件的最后登记事件记录
|
||||||
|
///
|
||||||
|
/// @param customerIdList 客户 ID 列表
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @return 最后登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> selectLatestByCustomerIdListAndRegistrationEventId(@Param("customerIdList") List<String> customerIdList, @Param("registrationEventId") String registrationEventId);
|
||||||
|
|
||||||
|
/// 查询客户全部登记事件的最后登记事件记录
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 最后登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> selectLatestByCustomerId(@Param("customerId") String customerId);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> selectByRange(@Param("req") GaoRegistrationEventRecordRangeReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询日历轻量记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 日历轻量记录列表
|
||||||
|
List<GaoRegistrationEventRecordCalendarView> selectCalendarByRange(@Param("req") GaoRegistrationEventRecordRangeReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围统计登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 登记事件记录数
|
||||||
|
Long countByRange(@Param("req") GaoRegistrationEventRecordRangeReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围分页查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @param offset 偏移量
|
||||||
|
/// @param size 每页条数
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecordListItemView> selectPageByRange(@Param("req") GaoRegistrationEventRecordRangeReq req, @Param("offset") Long offset, @Param("size") Long size);
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.mapper;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
||||||
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件角色关联 Mapper
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-28
|
||||||
|
public interface GaoRegistrationEventRoleRelationMapper extends BaseMapper<GaoRegistrationEventRoleRelation, String> {
|
||||||
|
|
||||||
|
@Select("SELECT `role_code` FROM `gao_registration_event_role_relation` WHERE `registration_event_id` = #{registrationEventId} AND `deleted_at` IS NULL ORDER BY `created_at` ASC")
|
||||||
|
List<String> selectRoleCodeListByRegistrationEventId(@Param("registrationEventId") String registrationEventId);
|
||||||
|
|
||||||
|
@Select({
|
||||||
|
"<script>",
|
||||||
|
"SELECT * FROM `gao_registration_event_role_relation`",
|
||||||
|
"WHERE `registration_event_id` IN",
|
||||||
|
"<foreach collection='registrationEventIdList' item='registrationEventId' open='(' separator=',' close=')'>",
|
||||||
|
"#{registrationEventId}",
|
||||||
|
"</foreach>",
|
||||||
|
"AND `deleted_at` IS NULL",
|
||||||
|
"ORDER BY `created_at` ASC",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<GaoRegistrationEventRoleRelation> selectByRegistrationEventIdList(@Param("registrationEventIdList") List<String> registrationEventIdList);
|
||||||
|
|
||||||
|
@Update("UPDATE `gao_registration_event_role_relation` SET `deleted_at` = UNIX_TIMESTAMP() WHERE `registration_event_id` = #{registrationEventId} AND `deleted_at` IS NULL")
|
||||||
|
void deleteByRegistrationEventId(@Param("registrationEventId") String registrationEventId);
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.mapper;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店营业日 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public interface GaoStoreBusinessDayMapper extends BaseMapper<GaoStoreBusinessDay, String> {
|
|
||||||
|
|
||||||
/// 按门店和日期查询营业日
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param dateValue 日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日
|
|
||||||
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` = #{dateValue} AND `deleted_at` IS NULL LIMIT 1")
|
|
||||||
GaoStoreBusinessDay selectByStoreIdAndDateValue(@Param("storeId") String storeId, @Param("dateValue") Integer dateValue);
|
|
||||||
|
|
||||||
/// 查询指定日期前最后一个营业日序号
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param dateValue 日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日序号
|
|
||||||
@Select("SELECT MAX(`business_day_no`) FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` < #{dateValue} AND `open_status` = 'OPEN' AND `deleted_at` IS NULL")
|
|
||||||
Long selectLastBusinessDayNoBefore(@Param("storeId") String storeId, @Param("dateValue") Integer dateValue);
|
|
||||||
|
|
||||||
/// 查询指定日期及之后的营业日
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日列表
|
|
||||||
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `open_status` = 'OPEN' AND `deleted_at` IS NULL ORDER BY `date_value` ASC")
|
|
||||||
List<GaoStoreBusinessDay> selectOpenListFromDate(@Param("storeId") String storeId, @Param("beginDateValue") Integer beginDateValue);
|
|
||||||
|
|
||||||
/// 查询日期范围内的营业日
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
|
||||||
/// @param endDateValue 结束日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日列表
|
|
||||||
@Select("SELECT * FROM `gao_store_business_day` WHERE `store_id` = #{storeId} AND `date_value` >= #{beginDateValue} AND `date_value` <= #{endDateValue} AND `deleted_at` IS NULL ORDER BY `date_value` ASC")
|
|
||||||
List<GaoStoreBusinessDay> selectByStoreIdAndDateRange(@Param("storeId") String storeId, @Param("beginDateValue") Integer beginDateValue, @Param("endDateValue") Integer endDateValue);
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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 java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店 Mapper
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public interface GaoStoreMapper extends BaseMapper<GaoStore, String> {
|
|
||||||
|
|
||||||
List<GaoStore> selectByIdList(@Param("idList") Collection<String> idList);
|
|
||||||
|
|
||||||
/// 查询用户所属的可用门店
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 门店
|
|
||||||
GaoStore selectByUserId(@Param("userId") String userId);
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ package com.imyeyu.api.modules.gao.mapper;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 用户 Mapper
|
/// GAO 用户 Mapper
|
||||||
@@ -9,4 +11,7 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-30
|
/// @since 2026-07-30
|
||||||
public interface GaoUserMapper extends BaseMapper<GaoUser, String> {
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +1,60 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStateView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStateReq;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
||||||
import com.imyeyu.spring.bean.Page;
|
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.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
///
|
||||||
/// 客户服务
|
/// 客户服务
|
||||||
///
|
///
|
||||||
/// @author 夜雨
|
/// @author Codex
|
||||||
/// @since 2026-07-27 14:12
|
/// @since 2026-07-27
|
||||||
public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
||||||
|
|
||||||
void updateWithAttachment(GaoCustomer customer);
|
|
||||||
|
|
||||||
/// 按编码查询客户
|
/// 按编码查询客户
|
||||||
///
|
///
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param code 客户编码
|
/// @param code 客户编码
|
||||||
/// @return 客户
|
/// @return 客户
|
||||||
GaoCustomer getByCode(String storeId, String code);
|
GaoCustomer getByCode(String code);
|
||||||
|
|
||||||
/// 按姓名查询客户
|
/// 按编码查询客户,不存在时返回 null
|
||||||
///
|
///
|
||||||
/// @param storeId 门店 ID
|
/// @param code 客户编码
|
||||||
/// @param name 姓名
|
|
||||||
/// @return 客户
|
/// @return 客户
|
||||||
GaoCustomer getByName(String storeId, String name);
|
GaoCustomer getNullableByCode(String code);
|
||||||
|
|
||||||
List<GaoCustomer> listByIdList(Collection<String> idList);
|
/// 按编码获取或快速创建客户
|
||||||
|
///
|
||||||
|
/// @param code 客户编码
|
||||||
|
/// @return 客户
|
||||||
|
GaoCustomer getOrQuickCreateByCode(String code);
|
||||||
|
|
||||||
default Map<String, GaoCustomer> mapByIdList(Collection<String> idList) {
|
/// 搜索客户
|
||||||
return listByIdList(idList).stream().collect(Collectors.toMap(GaoCustomer::getId, item -> item));
|
///
|
||||||
}
|
/// @param req 搜索请求
|
||||||
|
/// @return 客户列表
|
||||||
|
List<GaoCustomer> search(GaoCustomerSearchReq req);
|
||||||
|
|
||||||
|
/// 分页搜索客户
|
||||||
|
///
|
||||||
|
/// @param page 分页搜索请求
|
||||||
|
/// @return 客户分页结果
|
||||||
|
PageResult<GaoCustomer> searchPage(Page<GaoCustomerSearchReq> page);
|
||||||
|
|
||||||
/// 按搜索条件导出客户 Excel
|
/// 按搜索条件导出客户 Excel
|
||||||
///
|
///
|
||||||
|
/// @param req 搜索请求
|
||||||
/// @return xlsx 文件字节
|
/// @return xlsx 文件字节
|
||||||
byte[] export(Page<GaoCustomer> page) throws IOException;
|
byte[] exportSearchExcel(GaoCustomerSearchReq req) throws IOException;
|
||||||
|
|
||||||
/// 查询邀请的客户
|
/// 查询邀请的客户
|
||||||
///
|
///
|
||||||
@@ -54,9 +64,8 @@ public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
|||||||
|
|
||||||
/// 保存邀请关系
|
/// 保存邀请关系
|
||||||
///
|
///
|
||||||
/// @param introducerCustomerId 邀请来源客户 ID
|
/// @param req 邀请关系请求
|
||||||
/// @param customerId 客户 ID
|
void saveInviteRelation(GaoCustomerInviteUpdateReq req);
|
||||||
void saveInviteRelation(String introducerCustomerId, String customerId);
|
|
||||||
|
|
||||||
/// 删除邀请关系
|
/// 删除邀请关系
|
||||||
///
|
///
|
||||||
@@ -67,11 +76,10 @@ public interface GaoCustomerService extends BaseService<GaoCustomer, String> {
|
|||||||
///
|
///
|
||||||
/// @param req 趋势统计请求
|
/// @param req 趋势统计请求
|
||||||
/// @return 每日趋势列表
|
/// @return 每日趋势列表
|
||||||
List<GaoCustomerDailyStateView> stateDailyTrend(GaoCustomerTrendStateReq req);
|
List<GaoCustomerDailyStatView> statDailyTrend(GaoCustomerTrendStatReq req);
|
||||||
|
|
||||||
/// 统计客户性别分布
|
/// 统计客户性别分布
|
||||||
///
|
///
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @return 性别统计列表
|
/// @return 性别统计列表
|
||||||
List<GaoCustomerGenderStatView> stateGender(String storeId);
|
List<GaoCustomerGenderStatView> statGender();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
|
||||||
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.java.TimiJava;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// 登记事件记录服务
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 14:09
|
|
||||||
public interface GaoEventRecordService extends BaseService<GaoEventRecord, String> {
|
|
||||||
|
|
||||||
default void createBatch(List<GaoEventRecord> recordList) {
|
|
||||||
for (GaoEventRecord record : TimiJava.safeIterable(recordList)) {
|
|
||||||
create(record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void createWithCustomer(GaoCustomer customer);
|
|
||||||
|
|
||||||
/// 按任意时间范围查询登记事件记录
|
|
||||||
///
|
|
||||||
/// @param req 范围查询请求
|
|
||||||
/// @return 登记事件记录列表
|
|
||||||
PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage req);
|
|
||||||
|
|
||||||
/// 按时间范围查询客户登记排行榜
|
|
||||||
///
|
|
||||||
/// @param page 范围查询请求,不传时间为全部时间
|
|
||||||
/// @return 客户登记排行榜
|
|
||||||
PageResult<GaoCustomerEventRankView> pageRankByRange(GaoEventRecordRankPage page);
|
|
||||||
|
|
||||||
/// 按任意时间范围导出登记事件记录 Excel
|
|
||||||
///
|
|
||||||
/// @param page 范围查询请求
|
|
||||||
/// @return xlsx 文件字节
|
|
||||||
byte[] export(GaoEventRecordPage page) throws IOException;
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-07-27
|
|
||||||
public interface GaoEventService extends BaseService<GaoEvent, String> {
|
|
||||||
|
|
||||||
Map<String, GaoEvent> mapByIdList(Collection<String> idList);
|
|
||||||
|
|
||||||
Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList);
|
|
||||||
|
|
||||||
/// 查询启用的登记事件
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @return 登记事件列表
|
|
||||||
List<GaoEvent> listValid(String storeId);
|
|
||||||
|
|
||||||
/// 查询登记事件要求的角色
|
|
||||||
///
|
|
||||||
/// @param eventId 登记事件 ID
|
|
||||||
/// @return 角色代码列表
|
|
||||||
List<String> listRoleCode(String eventId);
|
|
||||||
|
|
||||||
/// 按客户端提交的顺序更新登记事件排序
|
|
||||||
///
|
|
||||||
/// @param idList 登记事件 ID 列表
|
|
||||||
void sort(List<String> idList);
|
|
||||||
}
|
|
||||||
+120
@@ -0,0 +1,120 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordListItemView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public interface GaoRegistrationEventRecordService extends BaseService<GaoRegistrationEventRecord, String> {
|
||||||
|
|
||||||
|
/// 创建登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 创建请求
|
||||||
|
/// @return 创建后的登记事件记录
|
||||||
|
GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req);
|
||||||
|
|
||||||
|
/// 快速录入客户并创建登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 快速录入请求
|
||||||
|
/// @return 创建后的登记事件记录
|
||||||
|
GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> listByRange(GaoRegistrationEventRecordRangeReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围查询日历轻量记录
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return 日历轻量记录列表
|
||||||
|
List<GaoRegistrationEventRecordCalendarView> listCalendarByRange(GaoRegistrationEventRecordRangeReq req);
|
||||||
|
|
||||||
|
/// 按任意时间范围分页查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 登记事件记录分页结果
|
||||||
|
PageResult<GaoRegistrationEventRecordListItemView> pageByRange(Page<GaoRegistrationEventRecordRangeReq> page);
|
||||||
|
|
||||||
|
/// 按任意时间范围导出登记事件记录 Excel
|
||||||
|
///
|
||||||
|
/// @param req 范围查询请求
|
||||||
|
/// @return xlsx 文件字节
|
||||||
|
byte[] exportRangeExcel(GaoRegistrationEventRecordRangeReq req) throws IOException;
|
||||||
|
|
||||||
|
/// 按周期查询登记事件记录
|
||||||
|
///
|
||||||
|
/// @param req 周期请求
|
||||||
|
/// @return 登记事件记录列表
|
||||||
|
List<GaoRegistrationEventRecord> listByRegistrationEventAndPeriod(GaoRegistrationEventRecordPeriodReq req);
|
||||||
|
|
||||||
|
/// 按周期统计登记事件记录
|
||||||
|
///
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @param periodType 周期类型
|
||||||
|
/// @return 统计列表
|
||||||
|
List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(String registrationEventId, GaoRegistrationEventRecordPeriodReq.PeriodType periodType);
|
||||||
|
|
||||||
|
/// 查询客户指定登记事件的最后登记事件记录
|
||||||
|
///
|
||||||
|
/// @param customerIdList 客户 ID 列表
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @return 每个客户的最后登记事件记录
|
||||||
|
List<GaoRegistrationEventRecord> listLatestByCustomerIdListAndRegistrationEventId(List<String> customerIdList, String registrationEventId);
|
||||||
|
|
||||||
|
/// 统计客户所有登记
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statByCustomerId(String customerId);
|
||||||
|
|
||||||
|
/// 按时间段统计单个客户登记
|
||||||
|
///
|
||||||
|
/// @param req 统计请求
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statByCustomerAndRange(GaoRegistrationEventRecordStatReq req);
|
||||||
|
|
||||||
|
/// 按时间段统计全部客户登记
|
||||||
|
///
|
||||||
|
/// @param req 统计请求
|
||||||
|
/// @return 统计结果
|
||||||
|
List<GaoCustomerRegisterStatView> statAllCustomerByRange(GaoRegistrationEventRecordStatReq req);
|
||||||
|
|
||||||
|
/// 按时间段统计单个客户单个登记事件每日趋势
|
||||||
|
///
|
||||||
|
/// @param req 趋势统计请求
|
||||||
|
/// @return 每日趋势列表
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> statDailyByCustomerAndRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req);
|
||||||
|
|
||||||
|
/// 按时间段统计全部客户单个登记事件每日趋势
|
||||||
|
///
|
||||||
|
/// @param req 趋势统计请求
|
||||||
|
/// @return 每日趋势列表
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> statDailyByRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req);
|
||||||
|
|
||||||
|
/// 查询客户全部登记事件的最后登记事件记录
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @return 每个登记事件的最后登记事件记录
|
||||||
|
List<GaoRegistrationEventRecord> listLatestByCustomerId(String customerId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件服务
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public interface GaoRegistrationEventService extends BaseService<GaoRegistrationEvent, String> {
|
||||||
|
|
||||||
|
/// 分页查询登记事件并填充可登记角色
|
||||||
|
///
|
||||||
|
/// @param page 分页参数
|
||||||
|
/// @return 登记事件分页
|
||||||
|
PageResult<GaoRegistrationEvent> pageWithRegistrationEventLimit(Page<GaoRegistrationEvent> page);
|
||||||
|
|
||||||
|
/// 查询启用的登记事件
|
||||||
|
///
|
||||||
|
/// @return 登记事件列表
|
||||||
|
List<GaoRegistrationEvent> listEnabled();
|
||||||
|
|
||||||
|
/// 查询登记事件要求的角色
|
||||||
|
///
|
||||||
|
/// @param registrationEventId 登记事件 ID
|
||||||
|
/// @return 角色代码列表
|
||||||
|
List<String> listRoleCode(String registrationEventId);
|
||||||
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店营业日服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public interface GaoStoreBusinessDayService extends BaseService<GaoStoreBusinessDay, String> {
|
|
||||||
|
|
||||||
/// 解析营业日,不存在时按默认营业日创建
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param dateValue 日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日
|
|
||||||
GaoStoreBusinessDay resolveOpenBusinessDay(String storeId, Integer dateValue);
|
|
||||||
|
|
||||||
/// 重算门店营业日序号并同步登记记录快照
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
|
||||||
void rebuildBusinessDayNo(String storeId, Integer beginDateValue);
|
|
||||||
|
|
||||||
/// 查询日期范围内的营业日
|
|
||||||
///
|
|
||||||
/// @param storeId 门店 ID
|
|
||||||
/// @param beginDateValue 开始日期值,格式为 yyyyMMdd
|
|
||||||
/// @param endDateValue 结束日期值,格式为 yyyyMMdd
|
|
||||||
/// @return 营业日列表
|
|
||||||
java.util.List<GaoStoreBusinessDay> listByDateRange(String storeId, Integer beginDateValue, Integer endDateValue);
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店服务
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
public interface GaoStoreService extends BaseService<GaoStore, String> {
|
|
||||||
|
|
||||||
/// 查询用户所属门店
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 门店
|
|
||||||
GaoStore getByUserId(String userId);
|
|
||||||
|
|
||||||
String getBelongIdByRequiredLoginUserId();
|
|
||||||
|
|
||||||
/// 导出门店列表
|
|
||||||
///
|
|
||||||
/// @param page 分页查询条件
|
|
||||||
/// @return xlsx 文件字节
|
|
||||||
byte[] export(Page<GaoStore> page) throws IOException;
|
|
||||||
|
|
||||||
/// 按客户端提交的顺序更新排序
|
|
||||||
///
|
|
||||||
/// @param idList 门店 ID 列表
|
|
||||||
void sort(List<String> idList);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.imyeyu.api.modules.gao.service;
|
package com.imyeyu.api.modules.gao.service;
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
|
import com.imyeyu.spring.bean.Page;
|
||||||
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -10,8 +12,15 @@ import com.imyeyu.spring.service.BaseService;
|
|||||||
/// @since 2026-07-30
|
/// @since 2026-07-30
|
||||||
public interface GaoUserService extends BaseService<GaoUser, String> {
|
public interface GaoUserService extends BaseService<GaoUser, String> {
|
||||||
|
|
||||||
/// 调整 GAO 用户所属门店
|
/// 按用户 ID 查询 GAO 用户
|
||||||
///
|
///
|
||||||
/// @param gaoUser GAO 用户,必须包含 ID 和目标门店 ID
|
/// @param userId 用户 ID
|
||||||
void transferStore(GaoUser gaoUser);
|
/// @return GAO 用户
|
||||||
|
GaoUser getByUserId(String userId);
|
||||||
|
|
||||||
|
/// 分页查询并填充用户详情
|
||||||
|
///
|
||||||
|
/// @param page 分页请求
|
||||||
|
/// @return GAO 用户分页
|
||||||
|
PageResult<GaoUser> pageWithUser(Page<GaoUser> page);
|
||||||
}
|
}
|
||||||
|
|||||||
+334
-252
@@ -1,30 +1,37 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
import com.imyeyu.api.modules.gao.util.CustomerXSSFBuilder;
|
|
||||||
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.system.entity.Logger;
|
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerInviteUpdateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerSearchReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerTrendStatReq;
|
||||||
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.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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -32,33 +39,28 @@ import java.time.ZoneId;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
///
|
||||||
/// 客户服务实现
|
/// 客户服务实现
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-27
|
/// @since 2026-07-27
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService {
|
public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustomer, String> implements GaoCustomerService {
|
||||||
|
|
||||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
||||||
private final ObjectMapper jackson;
|
|
||||||
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
|
|
||||||
private final GaoCustomerMapper mapper;
|
private final GaoCustomerMapper mapper;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
private final CustomerXSSFBuilder customerXSSFBuilder;
|
private final UserLoginService userLoginService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<GaoCustomer, String> mapper() {
|
protected BaseMapper<GaoCustomer, String> mapper() {
|
||||||
@@ -66,288 +68,196 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create(GaoCustomer customer) {
|
public void create(GaoCustomer entity) {
|
||||||
TimiException.required(customer.getName(), "not found customer.name");
|
checkEntity(entity, false);
|
||||||
TimiException.required(customer.getStoreId(), "not found customer.storeId");
|
entity.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
super.create(entity);
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_CREATE");
|
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
||||||
try {
|
changeInvitedCount(entity.getIntroducerCustomerId(), 1L);
|
||||||
logger.setContent(jackson.writeValueAsString(customer));
|
loadDetailTransient(entity);
|
||||||
{
|
|
||||||
GaoCustomer byName = getByName(customer.getStoreId(), customer.getName());
|
|
||||||
TimiException.requiredNull(byName, "该姓名客户已登记");
|
|
||||||
}
|
|
||||||
if (TimiJava.isNotEmpty(customer.getCode())) {
|
|
||||||
GaoCustomer byCode = getByCode(customer.getStoreId(), customer.getCode());
|
|
||||||
TimiException.requiredNull(byCode, "该编码客户已登记");
|
|
||||||
}
|
|
||||||
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
|
||||||
TimiException.requiredTrue(!customer.getIntroducerCustomerId().equals(customer.getId()), "customer.introducerCustomerId invalid");
|
|
||||||
GaoCustomer introducerCustomer = super.get(customer.getIntroducerCustomerId());
|
|
||||||
TimiException.required(introducerCustomer, "not found introducer customer");
|
|
||||||
TimiException.requiredTrue(customer.getStoreId().equals(introducerCustomer.getStoreId()), "介绍人和客户不属于同一门店");
|
|
||||||
}
|
|
||||||
|
|
||||||
customer.setBirthdateCalendar(TimiJava.defaultIfNull(customer.getBirthdateCalendar(), GaoCustomer.BirthdateCalendar.SOLAR));
|
|
||||||
if (TimiJava.isNotEmpty(customer.getBirthdate())) {
|
|
||||||
customer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
|
||||||
}
|
|
||||||
customer.setInvitedCount(0L);
|
|
||||||
if (customer.hasIntroducer()) {
|
|
||||||
customer.setInvitedCount(1L);
|
|
||||||
}
|
|
||||||
customer.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
|
||||||
|
|
||||||
super.create(customer);
|
|
||||||
// 附件
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), customer.getAttachmentList());
|
|
||||||
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(customer.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("新增 GAO 客户失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "新增 GAO 客户失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(GaoCustomer customer) {
|
public void update(GaoCustomer entity) {
|
||||||
TimiException.required(customer, "not found customer");
|
GaoCustomer dbCustomer = checkEntity(entity, true);
|
||||||
TimiException.required(customer.getId(), "not found customer.id");
|
super.update(entity);
|
||||||
TimiException.required(customer.getName(), "not found customer.name");
|
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
||||||
TimiException.required(customer.getStoreId(), "not found customer.storeId");
|
syncIntroducerInvitedCount(dbCustomer.getIntroducerCustomerId(), entity.getIntroducerCustomerId());
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_UPDATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(customer));
|
|
||||||
GaoCustomer dbCustomer = get(customer.getId());
|
|
||||||
TimiException.requiredTrue(dbCustomer.getStoreId().equals(customer.getStoreId()), "customer.storeId invalid");
|
|
||||||
dbCustomer.setCode(TimiJava.defaultIfEmpty(customer.getCode(), null));
|
|
||||||
{
|
|
||||||
if (!Objects.equals(dbCustomer.getCode(), customer.getCode()) && TimiJava.isNotEmpty(customer.getCode())) {
|
|
||||||
GaoCustomer byCode = getByCode(customer.getStoreId(), customer.getCode());
|
|
||||||
TimiException.requiredTrue(byCode == null || !byCode.getId().equals(dbCustomer.getId()), "该姓名客户已登记");
|
|
||||||
}
|
|
||||||
if (!Objects.equals(dbCustomer.getName(), customer.getName())) {
|
|
||||||
GaoCustomer byName = getByName(customer.getStoreId(), customer.getName());
|
|
||||||
TimiException.requiredTrue(byName == null || !byName.getId().equals(dbCustomer.getId()), "该姓名客户已登记");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dbCustomer.setName(customer.getName());
|
|
||||||
dbCustomer.setGender(customer.getGender());
|
|
||||||
dbCustomer.setAge(customer.getAge());
|
|
||||||
dbCustomer.setBirthdateCalendar(customer.getBirthdateCalendar());
|
|
||||||
if (TimiJava.isNotEmpty(customer.getBirthdate())) {
|
|
||||||
dbCustomer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
|
||||||
}
|
|
||||||
dbCustomer.setTelephone(customer.getTelephone());
|
|
||||||
dbCustomer.setAddress(customer.getAddress());
|
|
||||||
dbCustomer.setRemark(customer.getRemark());
|
|
||||||
dbCustomer.setDisease(customer.getDisease());
|
|
||||||
dbCustomer.setConditioningPart(customer.getConditioningPart());
|
|
||||||
mapper.update(dbCustomer);
|
|
||||||
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(customer.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("修改 GAO 客户失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "修改 GAO 客户失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE");
|
GaoCustomer customer = super.get(id);
|
||||||
try {
|
super.delete(id);
|
||||||
logger.setContent(id);
|
changeInvitedCount(customer.getIntroducerCustomerId(), -1L);
|
||||||
GaoCustomer customer = get(id);
|
}
|
||||||
super.delete(id);
|
|
||||||
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
@Override
|
||||||
logger.setLevel(Logger.Level.INFO);
|
public GaoCustomer get(String id) {
|
||||||
logger.setResult(id);
|
GaoCustomer customer = super.get(id);
|
||||||
} catch (TimiException e) {
|
loadDetailTransient(customer);
|
||||||
logger.setLevel(Logger.Level.WARN);
|
return customer;
|
||||||
logger.setException(e.getMessage());
|
}
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
@Override
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
public GaoCustomer getByCode(String code) {
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
TimiException.required(code, "not found customer.code");
|
||||||
log.error("删除 GAO 客户失败", e);
|
GaoCustomer customer = mapper.selectByCode(code);
|
||||||
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户失败", e);
|
TimiException.required(customer, "not found customer");
|
||||||
} finally {
|
loadDetailTransient(customer);
|
||||||
loggerService.create(logger);
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoCustomer getNullableByCode(String code) {
|
||||||
|
TimiException.required(code, "not found customer.code");
|
||||||
|
GaoCustomer customer = mapper.selectByCode(code);
|
||||||
|
loadDetailTransient(customer);
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoCustomer getOrQuickCreateByCode(String code) {
|
||||||
|
GaoCustomer customer = getNullableByCode(code);
|
||||||
|
if (customer != null) {
|
||||||
|
return customer;
|
||||||
}
|
}
|
||||||
|
customer = new GaoCustomer();
|
||||||
|
customer.setCode(code);
|
||||||
|
customer.setName(code);
|
||||||
|
create(customer);
|
||||||
|
return customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateWithAttachment(GaoCustomer customer) {
|
public List<GaoCustomer> search(GaoCustomerSearchReq req) {
|
||||||
update(customer);
|
req = resolveSearchReq(req);
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_CUSTOMER, customer.getId(), customer.getAttachmentList());
|
List<GaoCustomer> list = mapper.search(req.getKeyword(), req.getIntroducerCustomerId());
|
||||||
|
loadListTransient(list);
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GaoCustomer getByCode(String storeId, String code) {
|
public PageResult<GaoCustomer> searchPage(Page<GaoCustomerSearchReq> page) {
|
||||||
TimiException.required(storeId, "not found storeId");
|
TimiException.required(page, "not found page");
|
||||||
TimiException.required(code, "not found code");
|
TimiException.required(page.getIndex(), "not found page.index");
|
||||||
GaoCustomer example = new GaoCustomer();
|
TimiException.required(page.getSize(), "not found page.size");
|
||||||
example.setStoreId(storeId);
|
TimiException.requiredTrue(0 <= page.getIndex(), "page.index lt 0");
|
||||||
example.setCode(code);
|
TimiException.requiredTrue(0 < page.getSize(), "page.size lte 0");
|
||||||
return mapper.selectByExample(example);
|
GaoCustomerSearchReq req = resolveSearchReq(page.getEqualsExample());
|
||||||
|
Long total = TimiJava.defaultIfNull(mapper.countSearch(req.getKeyword(), req.getIntroducerCustomerId()), 0L);
|
||||||
|
List<GaoCustomer> list = mapper.searchPage(req.getKeyword(), req.getIntroducerCustomerId(), page.getIndex() * page.getSize(), page.getSize());
|
||||||
|
loadListTransient(list);
|
||||||
|
PageResult<GaoCustomer> result = new PageResult<>();
|
||||||
|
result.setTotal(total);
|
||||||
|
result.setList(list);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GaoCustomer getByName(String storeId, String name) {
|
public byte[] exportSearchExcel(GaoCustomerSearchReq req) throws IOException {
|
||||||
TimiException.required(storeId, "not found storeId");
|
List<GaoCustomer> list = search(req);
|
||||||
TimiException.required(name, "not found name");
|
loadIntroducerCustomer(list);
|
||||||
GaoCustomer example = new GaoCustomer();
|
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||||
example.setStoreId(storeId);
|
Sheet sheet = workbook.createSheet("客户列表");
|
||||||
example.setName(name);
|
CellStyle titleStyle = workbook.createCellStyle();
|
||||||
return mapper.selectByExample(example);
|
Font titleFont = workbook.createFont();
|
||||||
}
|
titleFont.setBold(true);
|
||||||
|
titleFont.setFontHeightInPoints((short) 14);
|
||||||
|
titleStyle.setFont(titleFont);
|
||||||
|
CellStyle headerStyle = workbook.createCellStyle();
|
||||||
|
Font headerFont = workbook.createFont();
|
||||||
|
headerFont.setBold(true);
|
||||||
|
headerStyle.setFont(headerFont);
|
||||||
|
|
||||||
@Override
|
appendRow(sheet, 0, titleStyle, "客户列表导出");
|
||||||
public List<GaoCustomer> listByIdList(Collection<String> idList) {
|
appendRow(sheet, 1, null, "生成时间", EXPORT_TIME_FORMATTER.format(Instant.now()));
|
||||||
return mapper.selectByIdList(new HashSet<>(idList));
|
appendRow(sheet, 2, null, "关键词", req == null || req.getKeyword() == null || req.getKeyword().isBlank() ? "全部" : req.getKeyword().trim());
|
||||||
}
|
appendRow(sheet, 3, null, "记录总数", String.valueOf(list.size()));
|
||||||
|
appendRow(sheet, 5, headerStyle, "客户编码", "姓名", "性别", "年龄", "电话", "地址", "病症", "备注", "邀请人", "邀请客户数", "创建时间");
|
||||||
@Override
|
int rowIndex = 6;
|
||||||
public byte[] export(Page<GaoCustomer> page) throws IOException {
|
|
||||||
page.setIndex(0);
|
|
||||||
page.setSize(Long.MAX_VALUE);
|
|
||||||
List<GaoCustomer> list = mapper.selectByPage(page);
|
|
||||||
{
|
|
||||||
List<String> idList = list.stream().map(GaoCustomer::getIntroducerCustomerId).filter(TimiJava::isNotEmpty).distinct().toList();
|
|
||||||
Map<String, GaoCustomer> map = mapByIdList(idList);
|
|
||||||
for (GaoCustomer customer : list) {
|
for (GaoCustomer customer : list) {
|
||||||
customer.setIntroducerCustomer(map.get(customer.getIntroducerCustomerId()));
|
appendRow(sheet, rowIndex, null,
|
||||||
|
text(customer.getCode()),
|
||||||
|
text(customer.getName()),
|
||||||
|
formatGender(customer),
|
||||||
|
customer.getAge() == null ? "" : String.valueOf(customer.getAge()),
|
||||||
|
text(customer.getTelephone()),
|
||||||
|
text(customer.getAddress()),
|
||||||
|
text(customer.getDisease()),
|
||||||
|
text(customer.getRemark()),
|
||||||
|
customer.getIntroducerCustomer() == null ? "" : text(customer.getIntroducerCustomer().getName()),
|
||||||
|
customer.getInvitedCount() == null ? "0" : String.valueOf(customer.getInvitedCount()),
|
||||||
|
formatExportTime(customer.getCreatedAt())
|
||||||
|
);
|
||||||
|
rowIndex++;
|
||||||
}
|
}
|
||||||
|
for (int index = 0; index < 11; index++) {
|
||||||
|
sheet.autoSizeColumn(index);
|
||||||
|
sheet.setColumnWidth(index, Math.min(Math.max(sheet.getColumnWidth(index), 10 * 256), 36 * 256));
|
||||||
|
}
|
||||||
|
workbook.write(output);
|
||||||
|
return output.toByteArray();
|
||||||
}
|
}
|
||||||
return customerXSSFBuilder.build(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomer> listInvited(String introducerCustomerId) {
|
public List<GaoCustomer> listInvited(String introducerCustomerId) {
|
||||||
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
||||||
GaoCustomer example = new GaoCustomer();
|
List<GaoCustomer> list = mapper.selectInvitedList(introducerCustomerId);
|
||||||
example.setIntroducerCustomerId(introducerCustomerId);
|
loadListTransient(list);
|
||||||
return mapper.selectAllByExample(example);
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void saveInviteRelation(String introducerCustomerId, String customerId) {
|
public void saveInviteRelation(GaoCustomerInviteUpdateReq req) {
|
||||||
TimiException.required(customerId, "not found customerId");
|
TimiException.required(req, "not found invite req");
|
||||||
TimiException.required(introducerCustomerId, "not found introducerCustomerId");
|
TimiException.required(req.getCustomerId(), "not found invite req.customerId");
|
||||||
|
GaoCustomer customer = super.get(req.getCustomerId());
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_SAVE_INVITE_RELATION");
|
String oldIntroducerCustomerId = customer.getIntroducerCustomerId();
|
||||||
try {
|
customer.setIntroducerCustomerId(req.getIntroducerCustomerId());
|
||||||
logger.setContent("introducerCustomerId: %s, customerId: %s".formatted(introducerCustomerId, customerId));
|
checkEntity(customer, true);
|
||||||
GaoCustomer customer = get(customerId);
|
super.update(customer);
|
||||||
TimiException.required(customer, "not found customer");
|
syncIntroducerInvitedCount(oldIntroducerCustomerId, customer.getIntroducerCustomerId());
|
||||||
GaoCustomer introducerCustomer = get(introducerCustomerId);
|
|
||||||
TimiException.required(introducerCustomer, "not found introducerCustomer");
|
|
||||||
TimiException.requiredTrue(customer.getStoreId().equals(introducerCustomer.getStoreId()), "介绍人和客户不属于同一门店");
|
|
||||||
if (introducerCustomer.getIntroducerCustomerId().equals(customer.getIntroducerCustomerId())) {
|
|
||||||
throw new TimiException(TimiCode.ARG_BAD, "customer can not upper be introducer customer");
|
|
||||||
}
|
|
||||||
// 存在旧的邀请来源
|
|
||||||
if (TimiJava.isNotEmpty(customer.getIntroducerCustomerId())) {
|
|
||||||
if (customer.getIntroducerCustomerId().equals(introducerCustomerId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
|
||||||
}
|
|
||||||
customer.setIntroducerCustomerId(introducerCustomerId);
|
|
||||||
mapper.update(customer);
|
|
||||||
changeInvitedCount(introducerCustomerId, +1);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("保存 GAO 客户邀请关系失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "保存 GAO 客户邀请关系失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void deleteInviteRelation(String customerId) {
|
public void deleteInviteRelation(String customerId) {
|
||||||
TimiException.required(customerId, "not found customerId");
|
TimiException.required(customerId, "not found customerId");
|
||||||
|
GaoCustomer customer = super.get(customerId);
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_CUSTOMER_DELETE_INVITE_RELATION");
|
String oldIntroducerCustomerId = customer.getIntroducerCustomerId();
|
||||||
try {
|
customer.setIntroducerCustomerId(null);
|
||||||
logger.setContent(customerId);
|
super.update(customer);
|
||||||
GaoCustomer customer = get(customerId);
|
changeInvitedCount(oldIntroducerCustomerId, -1L);
|
||||||
customer.setIntroducerCustomerId(null);
|
|
||||||
mapper.update(customer);
|
|
||||||
|
|
||||||
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(customerId);
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("删除 GAO 客户邀请关系失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "删除 GAO 客户邀请关系失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomerDailyStateView> stateDailyTrend(GaoCustomerTrendStateReq req) {
|
public List<GaoCustomerDailyStatView> statDailyTrend(GaoCustomerTrendStatReq req) {
|
||||||
TimiException.required(req, "not found req");
|
TimiException.required(req, "not found req");
|
||||||
TimiException.required(req.getStoreId(), "not found req.storeId");
|
|
||||||
TimiException.required(req.getBeginCreatedAt(), "not found req.beginCreatedAt");
|
TimiException.required(req.getBeginCreatedAt(), "not found req.beginCreatedAt");
|
||||||
TimiException.required(req.getEndCreatedAt(), "not found req.endCreatedAt");
|
TimiException.required(req.getEndCreatedAt(), "not found req.endCreatedAt");
|
||||||
TimiException.requiredTrue(req.getEndCreatedAt() >= req.getBeginCreatedAt(), "req.endCreatedAt lt req.beginCreatedAt");
|
TimiException.requiredTrue(req.getEndCreatedAt() >= req.getBeginCreatedAt(), "req.endCreatedAt lt req.beginCreatedAt");
|
||||||
ZoneId zoneId = ZoneId.systemDefault();
|
ZoneId zoneId = ZoneId.systemDefault();
|
||||||
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginCreatedAt()).atZone(zoneId).toLocalDate();
|
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginCreatedAt()).atZone(zoneId).toLocalDate();
|
||||||
LocalDate endDate = Instant.ofEpochMilli(req.getEndCreatedAt()).atZone(zoneId).toLocalDate();
|
LocalDate endDate = Instant.ofEpochMilli(req.getEndCreatedAt()).atZone(zoneId).toLocalDate();
|
||||||
|
checkDailyStatRange(beginDate, endDate);
|
||||||
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
|
||||||
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
|
||||||
|
|
||||||
long beginCreatedAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
long beginCreatedAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
||||||
long endCreatedAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
long endCreatedAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
||||||
Map<Integer, Long> newCustomerCountMap = new HashMap<>();
|
Map<Integer, Long> newCustomerCountMap = new HashMap<>();
|
||||||
for (GaoCustomerDailyStateView view : mapper.stateDailyNewCustomer(req.getStoreId(), beginCreatedAt, endCreatedAt)) {
|
for (GaoCustomerDailyStatView view : mapper.statDailyNewCustomer(beginCreatedAt, endCreatedAt)) {
|
||||||
newCustomerCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getNewCustomerCount(), 0L));
|
newCustomerCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getNewCustomerCount(), 0L));
|
||||||
}
|
}
|
||||||
long totalCustomerCount = TimiJava.defaultIfNull(mapper.countCreatedBefore(req.getStoreId(), beginCreatedAt), 0L);
|
long totalCustomerCount = TimiJava.defaultIfNull(mapper.countCreatedBefore(beginCreatedAt), 0L);
|
||||||
List<GaoCustomerDailyStateView> list = new ArrayList<>();
|
List<GaoCustomerDailyStatView> list = new ArrayList<>();
|
||||||
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
||||||
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
||||||
long newCustomerCount = TimiJava.defaultIfNull(newCustomerCountMap.get(dateValue), 0L);
|
long newCustomerCount = TimiJava.defaultIfNull(newCustomerCountMap.get(dateValue), 0L);
|
||||||
totalCustomerCount += newCustomerCount;
|
totalCustomerCount += newCustomerCount;
|
||||||
GaoCustomerDailyStateView view = new GaoCustomerDailyStateView();
|
GaoCustomerDailyStatView view = new GaoCustomerDailyStatView();
|
||||||
view.setDateValue(dateValue);
|
view.setDateValue(dateValue);
|
||||||
view.setNewCustomerCount(newCustomerCount);
|
view.setNewCustomerCount(newCustomerCount);
|
||||||
view.setTotalCustomerCount(totalCustomerCount);
|
view.setTotalCustomerCount(totalCustomerCount);
|
||||||
@@ -357,17 +267,189 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GaoCustomerGenderStatView> stateGender(String storeId) {
|
public List<GaoCustomerGenderStatView> statGender() {
|
||||||
TimiException.required(storeId, "not found storeId");
|
return mapper.statGender();
|
||||||
return mapper.stateGender(storeId);
|
}
|
||||||
|
|
||||||
|
private void checkDailyStatRange(LocalDate beginDate, LocalDate endDate) {
|
||||||
|
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
||||||
|
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoCustomerSearchReq resolveSearchReq(GaoCustomerSearchReq req) {
|
||||||
|
return req == null ? new GaoCustomerSearchReq() : req;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GaoCustomer checkEntity(GaoCustomer entity, boolean requireId) {
|
||||||
|
TimiException.required(entity, "not found customer");
|
||||||
|
GaoCustomer dbCustomer = null;
|
||||||
|
entity.setCode(normalizeText(entity.getCode()));
|
||||||
|
entity.setIntroducerCustomerId(normalizeText(entity.getIntroducerCustomerId()));
|
||||||
|
if (requireId) {
|
||||||
|
TimiException.required(entity.getId(), "not found customer.id");
|
||||||
|
dbCustomer = super.get(entity.getId());
|
||||||
|
entity.setCreatorUserId(dbCustomer.getCreatorUserId());
|
||||||
|
}
|
||||||
|
TimiException.required(entity.getName(), "not found customer.name");
|
||||||
|
entity.setName(entity.getName().trim());
|
||||||
|
TimiException.requiredTrue(!entity.getName().isEmpty(), "not found customer.name");
|
||||||
|
GaoCustomer duplicateCustomer = mapper.selectByName(entity.getName());
|
||||||
|
if (duplicateCustomer != null && !duplicateCustomer.getId().equals(entity.getId())) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "客户姓名已存在");
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(entity.getCode())) {
|
||||||
|
duplicateCustomer = mapper.selectByCode(entity.getCode());
|
||||||
|
if (duplicateCustomer != null && !duplicateCustomer.getId().equals(entity.getId())) {
|
||||||
|
throw new TimiException(TimiCode.ARG_BAD, "客户编码已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(entity.getIntroducerCustomerId())) {
|
||||||
|
TimiException.requiredTrue(!entity.getIntroducerCustomerId().equals(entity.getId()), "customer.introducerCustomerId invalid");
|
||||||
|
TimiException.required(super.get(entity.getIntroducerCustomerId()), "not found introducer customer");
|
||||||
|
}
|
||||||
|
return dbCustomer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDetailTransient(GaoCustomer customer) {
|
||||||
|
if (customer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loadIntroducerCustomer(List.of(customer));
|
||||||
|
if (TimiJava.isNotEmpty(customer.getCreatorUserId())) {
|
||||||
|
customer.setCreatorUser(userService.get(customer.getCreatorUserId()));
|
||||||
|
}
|
||||||
|
loadAttachmentList(List.of(customer));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadListTransient(List<GaoCustomer> customerList) {
|
||||||
|
loadAttachmentList(customerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadIntroducerCustomer(List<GaoCustomer> customerList) {
|
||||||
|
if (customerList == null || customerList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> introducerCustomerIdList = customerList.stream()
|
||||||
|
.map(GaoCustomer::getIntroducerCustomerId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (introducerCustomerIdList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, GaoCustomer> introducerCustomerMap = mapper.selectByIdList(new ArrayList<>(introducerCustomerIdList)).stream()
|
||||||
|
.collect(Collectors.toMap(GaoCustomer::getId, item -> item, (left, right) -> left));
|
||||||
|
for (GaoCustomer customer : customerList) {
|
||||||
|
customer.setIntroducerCustomer(introducerCustomerMap.get(customer.getIntroducerCustomerId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAttachmentList(List<GaoCustomer> customerList) {
|
||||||
|
if (customerList == null || customerList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> customerIdList = customerList.stream()
|
||||||
|
.map(GaoCustomer::getId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList, GaoCustomer.AttachType.PHOTO.name());
|
||||||
|
for (GaoCustomer customer : customerList) {
|
||||||
|
customer.setAttachmentList(attachmentMap.getOrDefault(customer.getId(), List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncIntroducerInvitedCount(String oldIntroducerCustomerId, String newIntroducerCustomerId) {
|
||||||
|
String normalizedOldIntroducerCustomerId = normalizeText(oldIntroducerCustomerId);
|
||||||
|
String normalizedNewIntroducerCustomerId = normalizeText(newIntroducerCustomerId);
|
||||||
|
if (Objects.equals(normalizedOldIntroducerCustomerId, normalizedNewIntroducerCustomerId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
changeInvitedCount(normalizedOldIntroducerCustomerId, -1L);
|
||||||
|
changeInvitedCount(normalizedNewIntroducerCustomerId, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeInvitedCount(String customerId, long delta) {
|
private void changeInvitedCount(String customerId, long delta) {
|
||||||
if (delta == 0) {
|
String normalizedCustomerId = normalizeText(customerId);
|
||||||
|
if (normalizedCustomerId == null || delta == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GaoCustomer customer = get(customerId);
|
mapper.updateInvitedCountDelta(normalizedCustomerId, delta);
|
||||||
customer.setInvitedCount(customer.getInvitedCount() + delta);
|
}
|
||||||
mapper.update(customer);
|
|
||||||
|
private String normalizeText(String value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String trimmedValue = value.trim();
|
||||||
|
return trimmedValue.isEmpty() ? null : trimmedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveAttachment(String customerId, List<Attachment> attachmentList) {
|
||||||
|
if (attachmentList == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Attachment attachment : attachmentList) {
|
||||||
|
attachment.setBizType(Attachment.BizType.GAO_CUSTOMER);
|
||||||
|
attachment.setBizId(customerId);
|
||||||
|
attachment.setAttachType(GaoCustomer.AttachType.PHOTO.name());
|
||||||
|
}
|
||||||
|
BizUpdateReq req = new BizUpdateReq();
|
||||||
|
req.setBizType(Attachment.BizType.GAO_CUSTOMER);
|
||||||
|
req.setBizId(customerId);
|
||||||
|
req.setItems(attachmentList);
|
||||||
|
attachmentService.updateByBiz(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Attachment> resolveAttachmentList(GaoCustomer customer) {
|
||||||
|
if (customer.getAttachmentIdList() != null) {
|
||||||
|
return buildPhotoAttachmentList(customer.getAttachmentIdList());
|
||||||
|
}
|
||||||
|
return customer.getAttachmentList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Attachment> buildPhotoAttachmentList(List<String> attachmentIdList) {
|
||||||
|
List<Attachment> list = new ArrayList<>();
|
||||||
|
for (String attachmentId : attachmentIdList) {
|
||||||
|
if (attachmentId == null || attachmentId.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Attachment attachment = new Attachment();
|
||||||
|
attachment.setTempFileId(attachmentId.trim());
|
||||||
|
attachment.setAttachType(GaoCustomer.AttachType.PHOTO.name());
|
||||||
|
list.add(attachment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
|
||||||
|
Row row = sheet.createRow(rowIndex);
|
||||||
|
for (int index = 0; index < values.length; index++) {
|
||||||
|
row.createCell(index).setCellValue(values[index]);
|
||||||
|
if (style != null) {
|
||||||
|
row.getCell(index).setCellStyle(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatGender(GaoCustomer customer) {
|
||||||
|
if (customer.getGender() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return switch (customer.getGender()) {
|
||||||
|
case MALE -> "男";
|
||||||
|
case FEMALE -> "女";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatExportTime(Long value) {
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return EXPORT_TIME_FORMATTER.format(Instant.ofEpochMilli(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String text(Object value) {
|
||||||
|
return value == null ? "" : value.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-310
@@ -1,310 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
|
||||||
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.GaoStoreBusinessDayService;
|
|
||||||
import com.imyeyu.api.modules.gao.util.EventRecordXSSFBuilder;
|
|
||||||
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.system.entity.Logger;
|
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
|
||||||
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;
|
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.time.temporal.TemporalAdjusters;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/// 登记事件记录服务实现
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 14:11
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoEventRecordServiceImplement extends AbstractEntityService<GaoEventRecord, String> implements GaoEventRecordService {
|
|
||||||
|
|
||||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
||||||
|
|
||||||
private final ObjectMapper jackson;
|
|
||||||
private final RoleChecker roleChecker;
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
private final GaoEventService eventService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
private final AttachmentService attachmentService;
|
|
||||||
private final GaoCustomerService customerService;
|
|
||||||
private final GaoStoreBusinessDayService businessDayService;
|
|
||||||
|
|
||||||
private final GaoEventRecordMapper mapper;
|
|
||||||
|
|
||||||
private final EventRecordXSSFBuilder xssfBuilder;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoEventRecord, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void create(GaoEventRecord record) {
|
|
||||||
TimiException.required(record, "not found record");
|
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_BATCH_CREATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(record));
|
|
||||||
|
|
||||||
String loginUserId = userLoginService.getRequireLoginUserId();
|
|
||||||
Long registeredAt = TimiJava.defaultIfNull(record.getRegisteredAt(), Time.now());
|
|
||||||
GaoEvent event = eventService.get(record.getEventId());
|
|
||||||
TimiException.required(event.getStoreId(), "not found event.storeId");
|
|
||||||
// 检查权限
|
|
||||||
checkEventPermission(event);
|
|
||||||
int registeredDateValue = dateValue(registeredAt);
|
|
||||||
long businessDayNo = businessDayService.resolveOpenBusinessDay(event.getStoreId(), registeredDateValue).getBusinessDayNo();
|
|
||||||
|
|
||||||
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;
|
|
||||||
List<String> logIdList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < customerIdList.size(); i++) {
|
|
||||||
String customerId = customerIdList.get(i);
|
|
||||||
// 检查事件可登记
|
|
||||||
checkEventCreatable(customerId, event, registeredAt);
|
|
||||||
GaoCustomer customer = customerService.get(customerId);
|
|
||||||
TimiException.required(customer, "not found customer");
|
|
||||||
TimiException.requiredTrue(event.getStoreId().equals(customer.getStoreId()), "客户和登记事件不属于同一门店");
|
|
||||||
|
|
||||||
GaoEventRecord dbRecord = new GaoEventRecord();
|
|
||||||
dbRecord.setCustomerId(customerId);
|
|
||||||
dbRecord.setStoreId(event.getStoreId());
|
|
||||||
dbRecord.setEventId(record.getEventId());
|
|
||||||
dbRecord.setOperatorUserId(loginUserId);
|
|
||||||
dbRecord.setRemark(record.getRemark());
|
|
||||||
dbRecord.setRegisteredAt(registeredAt);
|
|
||||||
dbRecord.setRegisteredDateValue(registeredDateValue);
|
|
||||||
dbRecord.setBusinessDayNo(businessDayNo);
|
|
||||||
super.create(dbRecord);
|
|
||||||
// 附件
|
|
||||||
if (i == 0) {
|
|
||||||
// 第一个记录储存附件
|
|
||||||
firstRecord = dbRecord;
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_EVENT_RECORD, dbRecord.getId(), record.getAttachmentList());
|
|
||||||
} else {
|
|
||||||
// 其他记录克隆第一个记录附件
|
|
||||||
List<Attachment> attachmentList = attachmentService.listByBizId(Attachment.BizType.GAO_EVENT_RECORD, firstRecord.getId());
|
|
||||||
for (Attachment attachment : attachmentList) {
|
|
||||||
Attachment clone = attachmentService.clone(attachment.getId());
|
|
||||||
clone.setId(dbRecord.getId());
|
|
||||||
attachmentService.update(clone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logIdList.add(dbRecord.getId());
|
|
||||||
}
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(String.join(",", logIdList));
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("create event record error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "create event record error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(GaoEventRecord record) {
|
|
||||||
TimiException.required(record, "not found record");
|
|
||||||
TimiException.required(record.getId(), "not found record.id");
|
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_RECORD_UPDATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(record));
|
|
||||||
TimiException.required(record.getCustomerId(), "not found record.customerId");
|
|
||||||
TimiException.required(record.getEventId(), "not found record.eventId");
|
|
||||||
|
|
||||||
record.setRegisteredAt(TimiJava.defaultIfNull(record.getRegisteredAt(), Time.now()));
|
|
||||||
|
|
||||||
GaoEvent event = eventService.get(record.getEventId());
|
|
||||||
TimiException.required(event.getStoreId(), "not found event.storeId");
|
|
||||||
checkEventPermission(event);
|
|
||||||
checkEventCreatable(record.getCustomerId(), event, record.getRegisteredAt());
|
|
||||||
GaoCustomer customer = customerService.get(record.getCustomerId());
|
|
||||||
TimiException.required(customer, "not found customer");
|
|
||||||
TimiException.requiredTrue(event.getStoreId().equals(customer.getStoreId()), "客户和登记事件不属于同一门店");
|
|
||||||
int registeredDateValue = dateValue(record.getRegisteredAt());
|
|
||||||
record.setStoreId(event.getStoreId());
|
|
||||||
record.setRegisteredDateValue(registeredDateValue);
|
|
||||||
record.setBusinessDayNo(businessDayService.resolveOpenBusinessDay(event.getStoreId(), registeredDateValue).getBusinessDayNo());
|
|
||||||
|
|
||||||
super.update(record);
|
|
||||||
attachmentService.updateByBizId(Attachment.BizType.GAO_EVENT_RECORD, record.getId(), record.getAttachmentList());
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(record.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("修改 GAO 登记记录失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "修改 GAO 登记记录失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void createWithCustomer(GaoCustomer customer) {
|
|
||||||
TimiException.required(customer, "not found customer");
|
|
||||||
if (TimiJava.isNotEmpty(customer.getId())) {
|
|
||||||
// 有 ID 表示给已有客户绑定新编码;编码不能被其他客户占用
|
|
||||||
GaoCustomer dbCustomer = customerService.get(customer.getId());
|
|
||||||
TimiException.required(dbCustomer, "not found customer");
|
|
||||||
if (TimiJava.isNotEmpty(customer.getCode())) {
|
|
||||||
GaoCustomer byCode = customerService.getByCode(dbCustomer.getStoreId(), customer.getCode());
|
|
||||||
TimiException.requiredTrue(byCode == null || dbCustomer.getId().equals(byCode.getId()), "该编码客户已登记");
|
|
||||||
dbCustomer.setCode(customer.getCode());
|
|
||||||
customerService.update(dbCustomer);
|
|
||||||
}
|
|
||||||
customer.setId(dbCustomer.getId());
|
|
||||||
} else {
|
|
||||||
// 无 ID 表示新开客户档案;创建客户只强制姓名唯一,其余字段按请求透传
|
|
||||||
customerService.create(customer);
|
|
||||||
}
|
|
||||||
if (TimiJava.isEmpty(customer.getEventRecordList())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (GaoEventRecord record : TimiJava.safeIterable(customer.getEventRecordList())) {
|
|
||||||
record.setCustomerId(customer.getId());
|
|
||||||
}
|
|
||||||
createBatch(customer.getEventRecordList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoEventRecord> pageByRange(GaoEventRecordPage page) {
|
|
||||||
TimiException.required(page.getStoreId(), "not found page.storeId");
|
|
||||||
PageResult<GaoEventRecord> result = new PageResult<>();
|
|
||||||
result.setTotal(mapper.countByRange(page));
|
|
||||||
result.setList(mapper.selectByRange(page));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] export(GaoEventRecordPage page) throws IOException {
|
|
||||||
TimiException.required(page.getStoreId(), "not found page.storeId");
|
|
||||||
List<GaoEventRecord> list = mapper.selectByRange(page);
|
|
||||||
return xssfBuilder.build(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<GaoCustomerEventRankView> pageRankByRange(GaoEventRecordRankPage page) {
|
|
||||||
TimiException.required(page.getStoreId(), "not found page.storeId");
|
|
||||||
PageResult<GaoCustomerEventRankView> result = new PageResult<>();
|
|
||||||
result.setTotal(mapper.countRankByRange(page));
|
|
||||||
result.setList(mapper.selectRankByRange(page));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEventPermission(GaoEvent event) {
|
|
||||||
List<String> roleCodeList = eventService.listRoleCode(event.getId());
|
|
||||||
TimiException.requiredTrue(roleCodeList != null && !roleCodeList.isEmpty(), "登记事件未配置可登记角色");
|
|
||||||
roleChecker.checkAny(ModuleCode.GAO, roleCodeList.toArray(String[]::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEventCreatable(String customerId, GaoEvent event, long registeredAt) {
|
|
||||||
TimiException.requiredTrue(event.getStatus() == null || event.getStatus() == GaoEvent.Status.ACTIVE, "登记事件不可登记");
|
|
||||||
TimiException.requiredTrue(event.getBeginAt() == null || event.getBeginAt() <= registeredAt, "登记事件未到可登记时间");
|
|
||||||
TimiException.requiredTrue(event.getEndAt() == null || registeredAt <= event.getEndAt(), "登记事件已过可登记时间");
|
|
||||||
GaoEvent.LimitType limitType = TimiJava.defaultIfNull(event.getLimitType(), GaoEvent.LimitType.NONE);
|
|
||||||
switch (limitType) {
|
|
||||||
case DAILY_HALF_DAY -> {
|
|
||||||
long today = Time.today(registeredAt);
|
|
||||||
long noon = today + Time.D / 2;
|
|
||||||
long beginAt = today, endAt;
|
|
||||||
if (today + registeredAt < noon) {
|
|
||||||
// 上半日
|
|
||||||
endAt = noon;
|
|
||||||
} else {
|
|
||||||
// 下半日
|
|
||||||
beginAt = noon;
|
|
||||||
endAt = today + Time.D;
|
|
||||||
}
|
|
||||||
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当前半日已登记该事件");
|
|
||||||
}
|
|
||||||
case NATURAL_DAY -> {
|
|
||||||
long beginAt = Time.today(registeredAt);
|
|
||||||
long endAt = beginAt + Time.D;
|
|
||||||
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当前半日已登记该事件");
|
|
||||||
}
|
|
||||||
case INTERVAL_HOUR -> {
|
|
||||||
long beginAt = registeredAt - event.getLimitValue() * Time.H;
|
|
||||||
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, registeredAt);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户登记该事件间隔不足");
|
|
||||||
}
|
|
||||||
case NATURAL_MONTH -> {
|
|
||||||
ZoneId zone = ZoneId.systemDefault();
|
|
||||||
ZonedDateTime zdt = Instant.ofEpochMilli(registeredAt).atZone(zone);
|
|
||||||
long beginAt = zdt.with(TemporalAdjusters.firstDayOfMonth()).truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();
|
|
||||||
long endAt = zdt.with(TemporalAdjusters.firstDayOfNextMonth()).truncatedTo(ChronoUnit.DAYS).toInstant().toEpochMilli();
|
|
||||||
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), beginAt, endAt);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该客户当月已登记该事件");
|
|
||||||
}
|
|
||||||
case TOTAL_LIMIT -> {
|
|
||||||
Long count = mapper.count(event.getStoreId(), null, event.getId(), null, null);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < event.getLimitValue(), "登记事件总次数已达上限");
|
|
||||||
}
|
|
||||||
case CUSTOMER_TOTAL_LIMIT -> {
|
|
||||||
Long count = mapper.count(event.getStoreId(), customerId, event.getId(), null, null);
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < event.getLimitValue(), "该客户登记该事件次数已达上限");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int dateValue(long time) {
|
|
||||||
LocalDate date = Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).toLocalDate();
|
|
||||||
return Integer.parseInt(DAY_FORMATTER.format(date));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-224
@@ -1,224 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEvent;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRoleRelation;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoEventMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoEventRoleRelationMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoEventService;
|
|
||||||
import com.imyeyu.api.modules.system.entity.Logger;
|
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
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.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 登记事件服务实现
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-07-27 09:00
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, String> implements GaoEventService {
|
|
||||||
|
|
||||||
private final ObjectMapper jackson;
|
|
||||||
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
|
|
||||||
private final GaoEventMapper mapper;
|
|
||||||
private final GaoEventRoleRelationMapper roleRelationMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoEvent, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void create(GaoEvent event) {
|
|
||||||
TimiException.required(event, "not found event");
|
|
||||||
TimiException.required(event.getStoreId(), "not found event.storeId");
|
|
||||||
TimiException.required(event.getName(), "not found event.name");
|
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_CREATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(event));
|
|
||||||
|
|
||||||
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));
|
|
||||||
event.setSort(TimiJava.defaultIfNull(event.getSort(), 0));
|
|
||||||
verifyEvent(event);
|
|
||||||
super.create(event);
|
|
||||||
|
|
||||||
saveRoleRelation(event.getId(), event.getRoleCodeList());
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(event.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("create event error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "create event error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void update(GaoEvent event) {
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_UPDATE");
|
|
||||||
try {
|
|
||||||
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(event.getId(), event.getRoleCodeList());
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(event.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("update event error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "update event error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void delete(String id) {
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_EVENT_DELETE");
|
|
||||||
try {
|
|
||||||
logger.setContent(id);
|
|
||||||
GaoEvent event = get(id);
|
|
||||||
event.setStatus(GaoEvent.Status.DELETED);
|
|
||||||
super.update(event);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(id);
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("delete event error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "delete event error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, GaoEvent> mapByIdList(Collection<String> idList) {
|
|
||||||
return mapper.selectByIdList(new HashSet<>(idList)).stream().collect(Collectors.toMap(GaoEvent::getId, Function.identity()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, List<String>> mapRoleCodeListByEventIdList(Collection<String> eventIdList) {
|
|
||||||
return roleRelationMapper.selectAllByEventIdList(new HashSet<>(eventIdList))
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.groupingBy(GaoEventRoleRelation::getEventId, Collectors.mapping(GaoEventRoleRelation::getRoleCode, Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoEvent> listValid(String storeId) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
return mapper.selectValidList(storeId, Time.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> listRoleCode(String eventId) {
|
|
||||||
GaoEventRoleRelation example = new GaoEventRoleRelation();
|
|
||||||
example.setEventId(eventId);
|
|
||||||
return roleRelationMapper.selectAllByExample(example).stream().map(GaoEventRoleRelation::getRoleCode).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void sort(List<String> idList) {
|
|
||||||
if (TimiJava.isEmpty(idList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
idList = new ArrayList<>(new LinkedHashSet<>(idList));
|
|
||||||
Map<String, GaoEvent> eventMap = mapper.selectByIdList(idList).stream().collect(Collectors.toMap(GaoEvent::getId, Function.identity()));
|
|
||||||
for (int i = 0; i < idList.size(); i++) {
|
|
||||||
GaoEvent event = eventMap.get(idList.get(i));
|
|
||||||
event.setSort(i);
|
|
||||||
mapper.update(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
Set<String> retainedRoleCodeSet = new HashSet<>();
|
|
||||||
for (GaoEventRoleRelation dbEventRole : dbRoleRelationList) {
|
|
||||||
String roleCode = dbEventRole.getRoleCode();
|
|
||||||
if (roleCode != null) {
|
|
||||||
roleCode = roleCode.trim();
|
|
||||||
}
|
|
||||||
if (!roleCodeSet.contains(roleCode) || !retainedRoleCodeSet.add(roleCode)) {
|
|
||||||
roleRelationMapper.delete(dbEventRole.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (String roleCode : roleCodeSet) {
|
|
||||||
if (retainedRoleCodeSet.contains(roleCode)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
GaoEventRoleRelation relation = new GaoEventRoleRelation();
|
|
||||||
relation.setEventId(eventId);
|
|
||||||
relation.setRoleCode(roleCode);
|
|
||||||
roleRelationMapper.insert(relation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+499
@@ -0,0 +1,499 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRecord;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoCustomerMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRecordMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventRecordService;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventPeriodStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerRegisterStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoQuickRegistrationEventRecordReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCalendarView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordCreateReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordDailyStatView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordListItemView;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordPeriodReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordRangeReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordStatReq;
|
||||||
|
import com.imyeyu.api.modules.gao.vo.GaoRegistrationEventRecordTrendStatReq;
|
||||||
|
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.api.modules.user.mapper.UserMapper;
|
||||||
|
import com.imyeyu.java.TimiJava;
|
||||||
|
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.service.AbstractEntityService;
|
||||||
|
import com.imyeyu.utils.Time;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoRegistrationEventRecordServiceImplement extends AbstractEntityService<GaoRegistrationEventRecord, String> implements GaoRegistrationEventRecordService {
|
||||||
|
|
||||||
|
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
private static final DateTimeFormatter EXPORT_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
||||||
|
|
||||||
|
private final GaoRegistrationEventRecordMapper mapper;
|
||||||
|
private final GaoCustomerMapper customerMapper;
|
||||||
|
private final GaoRegistrationEventMapper registrationEventMapper;
|
||||||
|
private final UserMapper userMapper;
|
||||||
|
private final AttachmentService attachmentService;
|
||||||
|
private final RoleChecker roleChecker;
|
||||||
|
private final UserLoginService userLoginService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final GaoCustomerService customerService;
|
||||||
|
private final GaoRegistrationEventService registrationEventService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoRegistrationEventRecord, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoRegistrationEventRecord createRecord(GaoRegistrationEventRecordCreateReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||||
|
String customerId = resolveCustomerId(req);
|
||||||
|
GaoRegistrationEvent registrationEvent = registrationEventService.get(req.getRegistrationEventId());
|
||||||
|
checkRegistrationEventPermission(registrationEvent);
|
||||||
|
if (Boolean.TRUE.equals(registrationEvent.getRequirePhoto())) {
|
||||||
|
TimiException.requiredTrue(req.getAttachmentIdList() != null && !req.getAttachmentIdList().isEmpty(), "required record photo");
|
||||||
|
}
|
||||||
|
|
||||||
|
GaoRegistrationEventRecord record = new GaoRegistrationEventRecord();
|
||||||
|
record.setCustomerId(customerId);
|
||||||
|
record.setRegistrationEventId(req.getRegistrationEventId());
|
||||||
|
record.setOperatorUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
record.setRemark(req.getRemark());
|
||||||
|
record.setRegisteredAt(TimiJava.defaultIfNull(req.getRegisteredAt(), Time.now()));
|
||||||
|
super.create(record);
|
||||||
|
saveAttachment(record.getId(), buildPhotoAttachmentList(req.getAttachmentIdList()));
|
||||||
|
return get(record.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public GaoRegistrationEventRecord quickRegister(GaoQuickRegistrationEventRecordReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getCustomerCode(), "not found req.customerCode");
|
||||||
|
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||||
|
GaoCustomer customer = customerService.getOrQuickCreateByCode(req.getCustomerCode());
|
||||||
|
GaoRegistrationEventRecordCreateReq recordReq = new GaoRegistrationEventRecordCreateReq();
|
||||||
|
recordReq.setCustomerId(customer.getId());
|
||||||
|
recordReq.setRegistrationEventId(req.getRegistrationEventId());
|
||||||
|
recordReq.setRemark(req.getRemark());
|
||||||
|
recordReq.setAttachmentIdList(req.getAttachmentIdList());
|
||||||
|
return createRecord(recordReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GaoRegistrationEventRecord entity) {
|
||||||
|
TimiException.required(entity, "not found record");
|
||||||
|
TimiException.required(entity.getId(), "not found record.id");
|
||||||
|
TimiException.required(entity.getCustomerId(), "not found record.customerId");
|
||||||
|
TimiException.required(entity.getRegistrationEventId(), "not found record.registrationEventId");
|
||||||
|
customerService.get(entity.getCustomerId());
|
||||||
|
GaoRegistrationEvent registrationEvent = registrationEventService.get(entity.getRegistrationEventId());
|
||||||
|
checkRegistrationEventPermission(registrationEvent);
|
||||||
|
entity.setRegisteredAt(TimiJava.defaultIfNull(entity.getRegisteredAt(), Time.now()));
|
||||||
|
super.update(entity);
|
||||||
|
saveAttachment(entity.getId(), resolveAttachmentList(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoRegistrationEventRecord get(String id) {
|
||||||
|
GaoRegistrationEventRecord record = super.get(id);
|
||||||
|
loadTransient(List.of(record));
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecord> listByRegistrationEventAndPeriod(GaoRegistrationEventRecordPeriodReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||||
|
TimiException.required(req.getPeriodType(), "not found req.periodType");
|
||||||
|
TimiException.required(req.getPeriodValue(), "not found req.periodValue");
|
||||||
|
List<GaoRegistrationEventRecord> list = mapper.selectByRegistrationEventAndPeriod(req.getRegistrationEventId(), req.getPeriodType(), req.getPeriodValue());
|
||||||
|
loadTransient(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecord> listByRange(GaoRegistrationEventRecordRangeReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
List<GaoRegistrationEventRecord> list = mapper.selectByRange(req);
|
||||||
|
loadTransient(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecordCalendarView> listCalendarByRange(GaoRegistrationEventRecordRangeReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
return mapper.selectCalendarByRange(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoRegistrationEventRecordListItemView> pageByRange(Page<GaoRegistrationEventRecordRangeReq> page) {
|
||||||
|
TimiException.required(page, "not found page");
|
||||||
|
TimiException.required(page.getIndex(), "not found page.index");
|
||||||
|
TimiException.required(page.getSize(), "not found page.size");
|
||||||
|
TimiException.requiredTrue(0 <= page.getIndex(), "page.index lt 0");
|
||||||
|
TimiException.requiredTrue(0 < page.getSize(), "page.size lte 0");
|
||||||
|
GaoRegistrationEventRecordRangeReq req = TimiJava.defaultIfNull(page.getEqualsExample(), new GaoRegistrationEventRecordRangeReq());
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
Long total = TimiJava.defaultIfNull(mapper.countByRange(req), 0L);
|
||||||
|
List<GaoRegistrationEventRecordListItemView> list = mapper.selectPageByRange(req, page.getIndex() * page.getSize(), page.getSize());
|
||||||
|
PageResult<GaoRegistrationEventRecordListItemView> result = new PageResult<>();
|
||||||
|
result.setTotal(total);
|
||||||
|
result.setList(list);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] exportRangeExcel(GaoRegistrationEventRecordRangeReq req) throws IOException {
|
||||||
|
List<GaoRegistrationEventRecord> list = listByRange(req);
|
||||||
|
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||||
|
Sheet sheet = workbook.createSheet("登记事件记录");
|
||||||
|
CellStyle titleStyle = workbook.createCellStyle();
|
||||||
|
Font titleFont = workbook.createFont();
|
||||||
|
titleFont.setBold(true);
|
||||||
|
titleFont.setFontHeightInPoints((short) 14);
|
||||||
|
titleStyle.setFont(titleFont);
|
||||||
|
CellStyle headerStyle = workbook.createCellStyle();
|
||||||
|
Font headerFont = workbook.createFont();
|
||||||
|
headerFont.setBold(true);
|
||||||
|
headerStyle.setFont(headerFont);
|
||||||
|
|
||||||
|
appendRow(sheet, 0, titleStyle, "登记事件记录导出");
|
||||||
|
appendRow(sheet, 1, null, "生成时间", EXPORT_TIME_FORMATTER.format(Instant.now()));
|
||||||
|
appendRow(sheet, 2, null, "时间范围", "%s ~ %s".formatted(formatExportTime(req.getBeginRegisteredAt()), formatExportTime(req.getEndRegisteredAt())));
|
||||||
|
appendRow(sheet, 3, null, "事件筛选", buildEventFilterText(req));
|
||||||
|
appendRow(sheet, 4, null, "关键词", req.getKeyword() == null || req.getKeyword().isBlank() ? "全部" : req.getKeyword().trim());
|
||||||
|
appendRow(sheet, 5, null, "记录总数", String.valueOf(list.size()));
|
||||||
|
appendRow(sheet, 7, headerStyle, "客户编码", "客户姓名", "登记事件", "登记时间", "登记人", "备注");
|
||||||
|
int rowIndex = 8;
|
||||||
|
for (GaoRegistrationEventRecord record : list) {
|
||||||
|
appendRow(sheet, rowIndex, null,
|
||||||
|
record.getCustomer() == null ? "" : text(record.getCustomer().getCode()),
|
||||||
|
record.getCustomer() == null ? "" : text(record.getCustomer().getName()),
|
||||||
|
record.getRegistrationEvent() == null ? "" : text(record.getRegistrationEvent().getName()),
|
||||||
|
formatExportTime(record.getRegisteredAt()),
|
||||||
|
getOperatorName(record),
|
||||||
|
text(record.getRemark())
|
||||||
|
);
|
||||||
|
rowIndex++;
|
||||||
|
}
|
||||||
|
for (int index = 0; index < 6; index++) {
|
||||||
|
sheet.autoSizeColumn(index);
|
||||||
|
sheet.setColumnWidth(index, Math.min(Math.max(sheet.getColumnWidth(index), 12 * 256), 40 * 256));
|
||||||
|
}
|
||||||
|
workbook.write(output);
|
||||||
|
return output.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventPeriodStatView> statByRegistrationEventAndPeriodType(String registrationEventId, GaoRegistrationEventRecordPeriodReq.PeriodType periodType) {
|
||||||
|
TimiException.required(registrationEventId, "not found registrationEventId");
|
||||||
|
TimiException.required(periodType, "not found periodType");
|
||||||
|
return mapper.statByRegistrationEventAndPeriodType(registrationEventId, periodType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecord> listLatestByCustomerIdListAndRegistrationEventId(List<String> customerIdList, String registrationEventId) {
|
||||||
|
TimiException.required(registrationEventId, "not found registrationEventId");
|
||||||
|
if (TimiJava.isEmpty(customerIdList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<GaoRegistrationEventRecord> list = mapper.selectLatestByCustomerIdListAndRegistrationEventId(customerIdList, registrationEventId);
|
||||||
|
loadTransient(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoCustomerRegisterStatView> statByCustomerId(String customerId) {
|
||||||
|
TimiException.required(customerId, "not found customerId");
|
||||||
|
return mapper.statByCustomerId(customerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoCustomerRegisterStatView> statByCustomerAndRange(GaoRegistrationEventRecordStatReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getCustomerId(), "not found req.customerId");
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
return mapper.statByCustomerIdAndRange(req.getCustomerId(), req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoCustomerRegisterStatView> statAllCustomerByRange(GaoRegistrationEventRecordStatReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
return mapper.statAllCustomerByRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecordDailyStatView> statDailyByCustomerAndRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getCustomerId(), "not found req.customerId");
|
||||||
|
customerService.get(req.getCustomerId());
|
||||||
|
return buildDailyTrend(req, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecordDailyStatView> statDailyByRegistrationEvent(GaoRegistrationEventRecordTrendStatReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
return buildDailyTrend(req, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEventRecord> listLatestByCustomerId(String customerId) {
|
||||||
|
TimiException.required(customerId, "not found customerId");
|
||||||
|
List<GaoRegistrationEventRecord> list = mapper.selectLatestByCustomerId(customerId);
|
||||||
|
loadTransient(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveCustomerId(GaoRegistrationEventRecordCreateReq req) {
|
||||||
|
if (TimiJava.isNotEmpty(req.getCustomerId())) {
|
||||||
|
customerService.get(req.getCustomerId());
|
||||||
|
return req.getCustomerId();
|
||||||
|
}
|
||||||
|
TimiException.required(req.getCustomerCode(), "not found req.customerCode");
|
||||||
|
GaoCustomer customer = customerService.getByCode(req.getCustomerCode());
|
||||||
|
return customer.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkRegistrationEventPermission(GaoRegistrationEvent registrationEvent) {
|
||||||
|
List<String> roleCodeList = registrationEventService.listRoleCode(registrationEvent.getId());
|
||||||
|
if (roleCodeList != null && !roleCodeList.isEmpty()) {
|
||||||
|
roleChecker.checkAny(ModuleCode.GAO, roleCodeList.toArray(String[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkStatRange(Long beginRegisteredAt, Long endRegisteredAt) {
|
||||||
|
TimiException.required(beginRegisteredAt, "not found beginRegisteredAt");
|
||||||
|
TimiException.required(endRegisteredAt, "not found endRegisteredAt");
|
||||||
|
TimiException.requiredTrue(endRegisteredAt >= beginRegisteredAt, "endRegisteredAt lt beginRegisteredAt");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GaoRegistrationEventRecordDailyStatView> buildDailyTrend(GaoRegistrationEventRecordTrendStatReq req, boolean byCustomer) {
|
||||||
|
TimiException.required(req.getRegistrationEventId(), "not found req.registrationEventId");
|
||||||
|
registrationEventService.get(req.getRegistrationEventId());
|
||||||
|
checkStatRange(req.getBeginRegisteredAt(), req.getEndRegisteredAt());
|
||||||
|
ZoneId zoneId = ZoneId.systemDefault();
|
||||||
|
LocalDate beginDate = Instant.ofEpochMilli(req.getBeginRegisteredAt()).atZone(zoneId).toLocalDate();
|
||||||
|
LocalDate endDate = Instant.ofEpochMilli(req.getEndRegisteredAt()).atZone(zoneId).toLocalDate();
|
||||||
|
checkDailyStatRange(beginDate, endDate);
|
||||||
|
long beginRegisteredAt = beginDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
||||||
|
long endRegisteredAt = endDate.plusDays(1).atStartOfDay(zoneId).toInstant().toEpochMilli() - 1;
|
||||||
|
Map<Integer, Long> dailyCountMap = new HashMap<>();
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> dbList = byCustomer
|
||||||
|
? mapper.statDailyCountByCustomerIdAndRegistrationEventIdRange(req.getCustomerId(), req.getRegistrationEventId(), beginRegisteredAt, endRegisteredAt)
|
||||||
|
: mapper.statDailyCountByRegistrationEventIdRange(req.getRegistrationEventId(), beginRegisteredAt, endRegisteredAt);
|
||||||
|
for (GaoRegistrationEventRecordDailyStatView view : dbList) {
|
||||||
|
dailyCountMap.put(view.getDateValue(), TimiJava.defaultIfNull(view.getDailyCount(), 0L));
|
||||||
|
}
|
||||||
|
long totalCount = byCustomer
|
||||||
|
? TimiJava.defaultIfNull(mapper.countBeforeByCustomerIdAndRegistrationEventId(req.getCustomerId(), req.getRegistrationEventId(), beginRegisteredAt), 0L)
|
||||||
|
: TimiJava.defaultIfNull(mapper.countBeforeByRegistrationEventId(req.getRegistrationEventId(), beginRegisteredAt), 0L);
|
||||||
|
List<GaoRegistrationEventRecordDailyStatView> list = new ArrayList<>();
|
||||||
|
for (LocalDate date = beginDate; !date.isAfter(endDate); date = date.plusDays(1)) {
|
||||||
|
int dateValue = Integer.parseInt(DAY_FORMATTER.format(date));
|
||||||
|
long dailyCount = TimiJava.defaultIfNull(dailyCountMap.get(dateValue), 0L);
|
||||||
|
totalCount += dailyCount;
|
||||||
|
GaoRegistrationEventRecordDailyStatView view = new GaoRegistrationEventRecordDailyStatView();
|
||||||
|
view.setDateValue(dateValue);
|
||||||
|
view.setDailyCount(dailyCount);
|
||||||
|
view.setTotalCount(totalCount);
|
||||||
|
list.add(view);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadTransient(List<GaoRegistrationEventRecord> recordList) {
|
||||||
|
if (recordList == null || recordList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> customerIdList = recordList.stream()
|
||||||
|
.map(GaoRegistrationEventRecord::getCustomerId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, GaoCustomer> customerMap = customerMapper.selectByIdList(new ArrayList<>(customerIdList)).stream()
|
||||||
|
.collect(Collectors.toMap(GaoCustomer::getId, Function.identity(), (left, right) -> left));
|
||||||
|
|
||||||
|
List<String> registrationEventIdList = recordList.stream()
|
||||||
|
.map(GaoRegistrationEventRecord::getRegistrationEventId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, GaoRegistrationEvent> registrationEventMap = registrationEventMapper.selectByIdList(new ArrayList<>(registrationEventIdList)).stream()
|
||||||
|
.collect(Collectors.toMap(GaoRegistrationEvent::getId, Function.identity(), (left, right) -> left));
|
||||||
|
|
||||||
|
List<String> operatorUserIdList = recordList.stream()
|
||||||
|
.map(GaoRegistrationEventRecord::getOperatorUserId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, com.imyeyu.api.modules.user.entity.User> userMap = userMapper.listByIdList(new ArrayList<>(operatorUserIdList)).stream()
|
||||||
|
.collect(Collectors.toMap(com.imyeyu.api.modules.user.entity.User::getId, Function.identity(), (left, right) -> left));
|
||||||
|
|
||||||
|
List<String> recordIdList = recordList.stream()
|
||||||
|
.map(GaoRegistrationEventRecord::getId)
|
||||||
|
.filter(TimiJava::isNotEmpty)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, List<Attachment>> attachmentMap = attachmentService.mapByBizIdList(
|
||||||
|
Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD,
|
||||||
|
recordIdList,
|
||||||
|
GaoRegistrationEventRecord.AttachType.PHOTO.name()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (GaoRegistrationEventRecord record : recordList) {
|
||||||
|
record.setCustomer(customerMap.get(record.getCustomerId()));
|
||||||
|
record.setRegistrationEvent(registrationEventMap.get(record.getRegistrationEventId()));
|
||||||
|
record.setOperator(userMap.get(record.getOperatorUserId()));
|
||||||
|
record.setAttachmentList(attachmentMap.getOrDefault(record.getId(), List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkDailyStatRange(LocalDate beginDate, LocalDate endDate) {
|
||||||
|
long days = ChronoUnit.DAYS.between(beginDate, endDate) + 1;
|
||||||
|
TimiException.requiredTrue(days <= 366, "daily stat range too large");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveAttachment(String recordId, List<Attachment> attachmentList) {
|
||||||
|
if (attachmentList == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Attachment attachment : attachmentList) {
|
||||||
|
attachment.setBizType(Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD);
|
||||||
|
attachment.setBizId(recordId);
|
||||||
|
attachment.setAttachType(GaoRegistrationEventRecord.AttachType.PHOTO.name());
|
||||||
|
}
|
||||||
|
BizUpdateReq req = new BizUpdateReq();
|
||||||
|
req.setBizType(Attachment.BizType.GAO_REGISTRATION_EVENT_RECORD);
|
||||||
|
req.setBizId(recordId);
|
||||||
|
req.setItems(attachmentList);
|
||||||
|
attachmentService.updateByBiz(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Attachment> resolveAttachmentList(GaoRegistrationEventRecord record) {
|
||||||
|
if (record.getAttachmentIdList() != null) {
|
||||||
|
return buildPhotoAttachmentList(record.getAttachmentIdList());
|
||||||
|
}
|
||||||
|
return record.getAttachmentList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Attachment> buildPhotoAttachmentList(List<String> attachmentIdList) {
|
||||||
|
if (attachmentIdList == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<Attachment> list = new ArrayList<>();
|
||||||
|
for (String attachmentId : attachmentIdList) {
|
||||||
|
if (attachmentId == null || attachmentId.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Attachment attachment = new Attachment();
|
||||||
|
attachment.setTempFileId(attachmentId.trim());
|
||||||
|
attachment.setAttachType(GaoRegistrationEventRecord.AttachType.PHOTO.name());
|
||||||
|
list.add(attachment);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendRow(Sheet sheet, int rowIndex, CellStyle style, String... values) {
|
||||||
|
Row row = sheet.createRow(rowIndex);
|
||||||
|
for (int index = 0; index < values.length; index++) {
|
||||||
|
row.createCell(index).setCellValue(values[index]);
|
||||||
|
if (style != null) {
|
||||||
|
row.getCell(index).setCellStyle(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildEventFilterText(GaoRegistrationEventRecordRangeReq req) {
|
||||||
|
if ((req.getRegistrationEventId() == null || req.getRegistrationEventId().isBlank()) && (req.getRegistrationEventIdList() == null || req.getRegistrationEventIdList().isEmpty())) {
|
||||||
|
return "全部事件";
|
||||||
|
}
|
||||||
|
if (req.getRegistrationEventId() != null && !req.getRegistrationEventId().isBlank()) {
|
||||||
|
return "事件 ID:" + req.getRegistrationEventId();
|
||||||
|
}
|
||||||
|
StringJoiner joiner = new StringJoiner("、");
|
||||||
|
req.getRegistrationEventIdList().stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(item -> !item.isBlank())
|
||||||
|
.forEach(joiner::add);
|
||||||
|
return "事件 ID:" + joiner;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatExportTime(Long value) {
|
||||||
|
if (value == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return EXPORT_TIME_FORMATTER.format(Instant.ofEpochMilli(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getOperatorName(GaoRegistrationEventRecord record) {
|
||||||
|
if (record.getOperator() == null) {
|
||||||
|
return text(record.getOperatorUserId());
|
||||||
|
}
|
||||||
|
if (record.getOperator().getNick() != null && !record.getOperator().getNick().isBlank()) {
|
||||||
|
return record.getOperator().getNick();
|
||||||
|
}
|
||||||
|
if (record.getOperator().getName() != null && !record.getOperator().getName().isBlank()) {
|
||||||
|
return record.getOperator().getName();
|
||||||
|
}
|
||||||
|
return text(record.getOperatorUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String text(Object value) {
|
||||||
|
return value == null ? "" : value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEventRoleRelation;
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventRoleRelationMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.mapper.GaoRegistrationEventMapper;
|
||||||
|
import com.imyeyu.api.modules.gao.service.GaoRegistrationEventService;
|
||||||
|
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.service.AbstractEntityService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件服务实现
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GaoRegistrationEventServiceImplement extends AbstractEntityService<GaoRegistrationEvent, String> implements GaoRegistrationEventService {
|
||||||
|
|
||||||
|
private final GaoRegistrationEventMapper mapper;
|
||||||
|
private final GaoRegistrationEventRoleRelationMapper roleRelationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BaseMapper<GaoRegistrationEvent, String> mapper() {
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<GaoRegistrationEvent> pageWithRegistrationEventLimit(Page<GaoRegistrationEvent> page) {
|
||||||
|
PageResult<GaoRegistrationEvent> result = page(page);
|
||||||
|
loadRegistrationEventLimit(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void create(GaoRegistrationEvent entity) {
|
||||||
|
checkEntity(entity, false);
|
||||||
|
super.create(entity);
|
||||||
|
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void update(GaoRegistrationEvent entity) {
|
||||||
|
checkEntity(entity, true);
|
||||||
|
super.update(entity);
|
||||||
|
saveRoleRelation(entity.getId(), entity.getRoleCodeList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void delete(String id) {
|
||||||
|
roleRelationMapper.deleteByRegistrationEventId(id);
|
||||||
|
super.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoRegistrationEvent get(String id) {
|
||||||
|
GaoRegistrationEvent registrationEvent = super.get(id);
|
||||||
|
registrationEvent.setRoleCodeList(roleRelationMapper.selectRoleCodeListByRegistrationEventId(id));
|
||||||
|
return registrationEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GaoRegistrationEvent> listEnabled() {
|
||||||
|
List<GaoRegistrationEvent> list = mapper.selectEnabledList();
|
||||||
|
loadRegistrationEventLimit(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> listRoleCode(String registrationEventId) {
|
||||||
|
return roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEventId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEntity(GaoRegistrationEvent entity, boolean requireId) {
|
||||||
|
TimiException.required(entity, "not found registrationEvent");
|
||||||
|
if (requireId) {
|
||||||
|
TimiException.required(entity.getId(), "not found registrationEvent.id");
|
||||||
|
}
|
||||||
|
TimiException.required(entity.getName(), "not found registrationEvent.name");
|
||||||
|
if (entity.getEnabled() == null) {
|
||||||
|
entity.setEnabled(true);
|
||||||
|
}
|
||||||
|
if (entity.getRequirePhoto() == null) {
|
||||||
|
entity.setRequirePhoto(false);
|
||||||
|
}
|
||||||
|
if (entity.getSort() == null) {
|
||||||
|
entity.setSort(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRoleRelation(String registrationEventId, List<String> roleCodeList) {
|
||||||
|
roleRelationMapper.deleteByRegistrationEventId(registrationEventId);
|
||||||
|
if (roleCodeList == null || roleCodeList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<String> distinctCodeSet = new LinkedHashSet<>(roleCodeList);
|
||||||
|
for (String roleCode : distinctCodeSet) {
|
||||||
|
if (roleCode == null || roleCode.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
GaoRegistrationEventRoleRelation relation = new GaoRegistrationEventRoleRelation();
|
||||||
|
relation.setRegistrationEventId(registrationEventId);
|
||||||
|
relation.setRoleCode(roleCode.trim());
|
||||||
|
roleRelationMapper.insert(relation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadRegistrationEventLimit(GaoRegistrationEvent registrationEvent) {
|
||||||
|
registrationEvent.setRoleCodeList(roleRelationMapper.selectRoleCodeListByRegistrationEventId(registrationEvent.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadRegistrationEventLimit(List<GaoRegistrationEvent> registrationEventList) {
|
||||||
|
if (registrationEventList == null || registrationEventList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> registrationEventIdList = registrationEventList.stream()
|
||||||
|
.map(GaoRegistrationEvent::getId)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<String, List<String>> roleCodeMap = roleRelationMapper.selectByRegistrationEventIdList(new ArrayList<>(registrationEventIdList)).stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
GaoRegistrationEventRoleRelation::getRegistrationEventId,
|
||||||
|
Collectors.mapping(GaoRegistrationEventRoleRelation::getRoleCode, Collectors.toList())
|
||||||
|
));
|
||||||
|
for (GaoRegistrationEvent registrationEvent : registrationEventList) {
|
||||||
|
registrationEvent.setRoleCodeList(roleCodeMap.getOrDefault(registrationEvent.getId(), List.of()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-135
@@ -1,135 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStoreBusinessDay;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoEventRecordMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoStoreBusinessDayMapper;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreBusinessDayService;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店营业日服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoStoreBusinessDayServiceImplement extends AbstractEntityService<GaoStoreBusinessDay, String> implements GaoStoreBusinessDayService {
|
|
||||||
|
|
||||||
private final GaoStoreBusinessDayMapper mapper;
|
|
||||||
private final GaoEventRecordMapper eventRecordMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoStoreBusinessDay, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
public void create(GaoStoreBusinessDay businessDay) {
|
|
||||||
prepareBusinessDay(businessDay);
|
|
||||||
super.create(businessDay);
|
|
||||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
|
|
||||||
rebuildBusinessDayNo(businessDay.getStoreId(), businessDay.getDateValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
public void update(GaoStoreBusinessDay businessDay) {
|
|
||||||
TimiException.required(businessDay, "not found businessDay");
|
|
||||||
TimiException.required(businessDay.getId(), "not found businessDay.id");
|
|
||||||
GaoStoreBusinessDay dbBusinessDay = get(businessDay.getId());
|
|
||||||
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) {
|
|
||||||
checkNoRecord(dbBusinessDay);
|
|
||||||
}
|
|
||||||
prepareBusinessDay(businessDay);
|
|
||||||
super.update(businessDay);
|
|
||||||
rebuildBusinessDayNo(businessDay.getStoreId(), businessDay.getDateValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
public void delete(String id) {
|
|
||||||
GaoStoreBusinessDay businessDay = get(id);
|
|
||||||
TimiException.required(businessDay, "not found businessDay");
|
|
||||||
if (businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.OPEN) {
|
|
||||||
checkNoRecord(businessDay);
|
|
||||||
}
|
|
||||||
super.delete(id);
|
|
||||||
rebuildBusinessDayNo(businessDay.getStoreId(), businessDay.getDateValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public GaoStoreBusinessDay resolveOpenBusinessDay(String storeId, Integer dateValue) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(dateValue, "not found dateValue");
|
|
||||||
GaoStoreBusinessDay businessDay = mapper.selectByStoreIdAndDateValue(storeId, dateValue);
|
|
||||||
if (businessDay != null) {
|
|
||||||
TimiException.requiredTrue(businessDay.getOpenStatus() == GaoStoreBusinessDay.OpenStatus.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);
|
|
||||||
super.create(businessDay);
|
|
||||||
rebuildBusinessDayNo(storeId, dateValue);
|
|
||||||
return mapper.selectByStoreIdAndDateValue(storeId, dateValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void rebuildBusinessDayNo(String storeId, Integer beginDateValue) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(beginDateValue, "not found beginDateValue");
|
|
||||||
long businessDayNo = TimiJava.defaultIfNull(mapper.selectLastBusinessDayNoBefore(storeId, beginDateValue), 0L);
|
|
||||||
for (GaoStoreBusinessDay businessDay : mapper.selectOpenListFromDate(storeId, beginDateValue)) {
|
|
||||||
businessDayNo++;
|
|
||||||
if (!Long.valueOf(businessDayNo).equals(businessDay.getBusinessDayNo())) {
|
|
||||||
businessDay.setBusinessDayNo(businessDayNo);
|
|
||||||
mapper.update(businessDay);
|
|
||||||
}
|
|
||||||
eventRecordMapper.updateBusinessDayNoByStoreIdAndRegisteredDateValue(storeId, businessDay.getDateValue(), businessDayNo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GaoStoreBusinessDay> listByDateRange(String storeId, Integer beginDateValue, Integer endDateValue) {
|
|
||||||
TimiException.required(storeId, "not found storeId");
|
|
||||||
TimiException.required(beginDateValue, "not found beginDateValue");
|
|
||||||
TimiException.required(endDateValue, "not found endDateValue");
|
|
||||||
TimiException.requiredTrue(beginDateValue <= endDateValue, "endDateValue lt beginDateValue");
|
|
||||||
return mapper.selectByStoreIdAndDateRange(storeId, beginDateValue, endDateValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void prepareBusinessDay(GaoStoreBusinessDay businessDay) {
|
|
||||||
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.setBusinessDayNo(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
businessDay.setBusinessDayNo(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkNoRecord(GaoStoreBusinessDay businessDay) {
|
|
||||||
Long count = eventRecordMapper.countByStoreIdAndRegisteredDateValue(businessDay.getStoreId(), businessDay.getDateValue());
|
|
||||||
TimiException.requiredTrue(TimiJava.defaultIfNull(count, 0L) < 1, "该营业日已有登记记录,不能改为休息或删除");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-191
@@ -1,191 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoStoreMapper;
|
|
||||||
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;
|
|
||||||
import com.imyeyu.spring.bean.Page;
|
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// GAO 门店服务实现
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GaoStoreServiceImplement extends AbstractEntityService<GaoStore, String> implements GaoStoreService {
|
|
||||||
|
|
||||||
private final ObjectMapper jackson;
|
|
||||||
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
private final GaoStoreMapper mapper;
|
|
||||||
private final StoreXSSFBuilder storeXSSFBuilder;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BaseMapper<GaoStore, String> mapper() {
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(GaoStore store) {
|
|
||||||
TimiException.required(store, "not found store");
|
|
||||||
TimiException.required(store.getCode(), "not found store.code");
|
|
||||||
TimiException.required(store.getName(), "not found store.name");
|
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_STORE_CREATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(store));
|
|
||||||
checkUnique(store);
|
|
||||||
store.setStatus(TimiJava.defaultIfNull(store.getStatus(), GaoStore.Status.ACTIVE));
|
|
||||||
store.setSort(TimiJava.defaultIfNull(store.getSort(), 0));
|
|
||||||
super.create(store);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(store.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("新增 GAO 门店失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "新增 GAO 门店失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(GaoStore store) {
|
|
||||||
TimiException.required(store, "not found store");
|
|
||||||
TimiException.required(store.getId(), "not found store.id");
|
|
||||||
TimiException.required(store.getCode(), "not found store.code");
|
|
||||||
TimiException.required(store.getName(), "not found store.name");
|
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_STORE_UPDATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(store));
|
|
||||||
checkUnique(store);
|
|
||||||
GaoStore dbStore = get(store.getId());
|
|
||||||
dbStore.setCode(store.getCode());
|
|
||||||
dbStore.setName(store.getName());
|
|
||||||
dbStore.setStatus(store.getStatus());
|
|
||||||
dbStore.setTelephone(store.getTelephone());
|
|
||||||
dbStore.setAddress(store.getAddress());
|
|
||||||
dbStore.setRemark(store.getRemark());
|
|
||||||
super.update(dbStore);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(store.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("修改 GAO 门店失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "修改 GAO 门店失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(String id) {
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_STORE_DELETE");
|
|
||||||
try {
|
|
||||||
logger.setContent(id);
|
|
||||||
GaoStore store = get(id);
|
|
||||||
store.setStatus(GaoStore.Status.DELETED);
|
|
||||||
super.update(store);
|
|
||||||
super.delete(id);
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(id);
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("删除 GAO 门店失败", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "删除 GAO 门店失败", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GaoStore getByUserId(String userId) {
|
|
||||||
TimiException.required(userId, "not found userId");
|
|
||||||
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);
|
|
||||||
page.setSize(Long.MAX_VALUE);
|
|
||||||
List<GaoStore> list = mapper.selectByPage(page);
|
|
||||||
return storeXSSFBuilder.build(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void sort(List<String> idList) {
|
|
||||||
if (TimiJava.isEmpty(idList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GaoStore> storeList = mapper.selectByIdList(new LinkedHashSet<>(idList));
|
|
||||||
Map<String, GaoStore> storeMap = storeList.stream().collect(Collectors.toMap(GaoStore::getId, Function.identity()));
|
|
||||||
for (int i = 0; i < idList.size(); i++) {
|
|
||||||
GaoStore store = storeMap.get(idList.get(i));
|
|
||||||
if (store == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
store.setSort(i);
|
|
||||||
mapper.update(store);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkUnique(GaoStore store) {
|
|
||||||
GaoStore codeExample = new GaoStore();
|
|
||||||
codeExample.setCode(store.getCode());
|
|
||||||
GaoStore byCode = mapper.selectByExample(codeExample);
|
|
||||||
TimiException.requiredTrue(byCode == null || byCode.getId().equals(store.getId()), "该门店编码已存在");
|
|
||||||
|
|
||||||
GaoStore nameExample = new GaoStore();
|
|
||||||
nameExample.setName(store.getName());
|
|
||||||
GaoStore byName = mapper.selectByExample(nameExample);
|
|
||||||
TimiException.requiredTrue(byName == null || byName.getId().equals(store.getId()), "该门店名称已存在");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+123
-101
@@ -1,41 +1,47 @@
|
|||||||
package com.imyeyu.api.modules.gao.service.implement;
|
package com.imyeyu.api.modules.gao.service.implement;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
import com.imyeyu.api.modules.gao.entity.GaoUser;
|
||||||
import com.imyeyu.api.modules.gao.mapper.GaoUserMapper;
|
import com.imyeyu.api.modules.gao.mapper.GaoUserMapper;
|
||||||
import com.imyeyu.api.modules.gao.service.GaoStoreService;
|
|
||||||
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
import com.imyeyu.api.modules.gao.service.GaoUserService;
|
||||||
import com.imyeyu.api.modules.system.entity.Logger;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
|
import com.imyeyu.api.modules.user.mapper.UserMapper;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
|
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeReq;
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// GAO 用户服务实现
|
/// GAO 用户服务实现
|
||||||
///
|
///
|
||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-30
|
/// @since 2026-07-30
|
||||||
@Slf4j
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, String> implements GaoUserService {
|
public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, String> implements GaoUserService {
|
||||||
|
|
||||||
private final ObjectMapper jackson;
|
|
||||||
private final UserService userService;
|
|
||||||
private final LoggerService loggerService;
|
|
||||||
private final GaoStoreService gaoStoreService;
|
|
||||||
|
|
||||||
private final GaoUserMapper mapper;
|
private final GaoUserMapper mapper;
|
||||||
|
private final UserMapper userMapper;
|
||||||
|
private final UserService userService;
|
||||||
|
private final RoleService roleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BaseMapper<GaoUser, String> mapper() {
|
protected BaseMapper<GaoUser, String> mapper() {
|
||||||
@@ -44,109 +50,125 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
|
|||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void create(GaoUser gaoUser) {
|
public void create(GaoUser entity) {
|
||||||
TimiException.required(gaoUser.getStoreId(), "not found storeId");
|
prepareUser(entity);
|
||||||
TimiException.required(gaoUser.getUser(), "not found user");
|
checkEntity(entity, false);
|
||||||
TimiException.required(gaoUser.getUser().getName(), "not found user.name");
|
super.create(entity);
|
||||||
TimiException.required(gaoUser.getUser().getPhoneNo(), "not found user.phoneNo");
|
saveUserRole(entity);
|
||||||
|
loadUser(entity);
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_CREATE");
|
|
||||||
try {
|
|
||||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
|
||||||
|
|
||||||
GaoStore store = gaoStoreService.get(gaoUser.getStoreId());
|
|
||||||
TimiException.required(store, "not found store");
|
|
||||||
TimiException.requiredTrue(store.isActivated(), "门店不可用");
|
|
||||||
|
|
||||||
userService.create(gaoUser.getUser());
|
|
||||||
userService.verifyPhoneNo(gaoUser.getUser().getId());
|
|
||||||
gaoUser.setUserId(gaoUser.getUser().getId());
|
|
||||||
gaoUser.setEnabled(TimiJava.defaultIfNull(gaoUser.getEnabled(), true));
|
|
||||||
super.create(gaoUser);
|
|
||||||
|
|
||||||
logger.setLevel(Logger.Level.INFO);
|
|
||||||
logger.setResult(gaoUser.getId());
|
|
||||||
} catch (TimiException e) {
|
|
||||||
logger.setLevel(Logger.Level.WARN);
|
|
||||||
logger.setException(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("create user error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "create user error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@Override
|
@Override
|
||||||
public void update(GaoUser gaoUser) {
|
public void update(GaoUser entity) {
|
||||||
|
checkEntity(entity, true);
|
||||||
|
updateUser(entity);
|
||||||
|
super.update(entity);
|
||||||
|
saveUserRole(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoUser get(String id) {
|
||||||
|
GaoUser gaoUser = super.get(id);
|
||||||
|
loadUser(gaoUser);
|
||||||
|
return gaoUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GaoUser getByUserId(String userId) {
|
||||||
|
TimiException.required(userId, "not found userId");
|
||||||
|
GaoUser gaoUser = mapper.selectByUserId(userId);
|
||||||
TimiException.required(gaoUser, "not found gao user");
|
TimiException.required(gaoUser, "not found gao user");
|
||||||
TimiException.required(gaoUser.getId(), "not found gao user.id");
|
loadUser(gaoUser);
|
||||||
|
return gaoUser;
|
||||||
|
}
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_UPDATE");
|
@Override
|
||||||
try {
|
public PageResult<GaoUser> pageWithUser(Page<GaoUser> page) {
|
||||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
PageResult<GaoUser> result = page(page);
|
||||||
|
loadUser(result.getList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
GaoUser dbGaoUser = super.get(gaoUser.getId());
|
private void checkEntity(GaoUser entity, boolean requireId) {
|
||||||
TimiException.required(dbGaoUser, "not found gao user");
|
TimiException.required(entity, "not found gao user");
|
||||||
|
if (requireId) {
|
||||||
dbGaoUser.setEnabled(gaoUser.getEnabled());
|
TimiException.required(entity.getId(), "not found gao user.id");
|
||||||
dbGaoUser.setRemark(gaoUser.getRemark());
|
}
|
||||||
super.update(dbGaoUser);
|
TimiException.required(entity.getUserId(), "not found gao user.userId");
|
||||||
|
TimiException.required(userMapper.select(entity.getUserId()), "not found user");
|
||||||
logger.setLevel(Logger.Level.INFO);
|
GaoUser dbGaoUser = mapper.selectByUserId(entity.getUserId());
|
||||||
logger.setResult(gaoUser.getId());
|
if (dbGaoUser != null && !dbGaoUser.getId().equals(entity.getId())) {
|
||||||
} catch (TimiException e) {
|
throw new TimiException(TimiCode.ARG_BAD, "GAO 用户已存在");
|
||||||
logger.setLevel(Logger.Level.WARN);
|
}
|
||||||
logger.setException(e.getMessage());
|
if (entity.getEnabled() == null) {
|
||||||
throw e;
|
entity.setEnabled(true);
|
||||||
} catch (Exception e) {
|
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("update user error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "update user error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
private void prepareUser(GaoUser entity) {
|
||||||
@Override
|
TimiException.required(entity, "not found gao user");
|
||||||
public void transferStore(GaoUser gaoUser) {
|
if (TimiJava.isNotEmpty(entity.getUserId())) {
|
||||||
TimiException.required(gaoUser, "not found gao user");
|
return;
|
||||||
TimiException.required(gaoUser.getId(), "not found gao user.id");
|
}
|
||||||
TimiException.required(gaoUser.getStoreId(), "not found gao user.storeId");
|
User user = entity.getUser();
|
||||||
|
TimiException.required(user, "not found gao user.user");
|
||||||
|
user.setPhoneNoVerifyAt(TimiJava.defaultIfNull(user.getPhoneNoVerifyAt(), Time.now()));
|
||||||
|
userService.create(user);
|
||||||
|
entity.setUserId(user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
Logger logger = new Logger(Logger.Module.GAO, "GAO_USER_TRANSFER_STORE");
|
private void updateUser(GaoUser entity) {
|
||||||
try {
|
User reqUser = entity.getUser();
|
||||||
logger.setContent(jackson.writeValueAsString(gaoUser));
|
if (reqUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
User user = userService.get(entity.getUserId());
|
||||||
|
if (reqUser.getName() != null) {
|
||||||
|
user.setName(reqUser.getName());
|
||||||
|
}
|
||||||
|
if (reqUser.getNick() != null) {
|
||||||
|
user.setNick(reqUser.getNick());
|
||||||
|
}
|
||||||
|
if (reqUser.getPhoneNo() != null) {
|
||||||
|
user.setPhoneNo(reqUser.getPhoneNo());
|
||||||
|
}
|
||||||
|
if (reqUser.getEmail() != null) {
|
||||||
|
user.setEmail(reqUser.getEmail());
|
||||||
|
}
|
||||||
|
userService.update(user);
|
||||||
|
}
|
||||||
|
|
||||||
GaoStore store = gaoStoreService.get(gaoUser.getStoreId());
|
private void saveUserRole(GaoUser entity) {
|
||||||
TimiException.required(store, "not found store");
|
if (entity.getRoleIdList() == null) {
|
||||||
TimiException.requiredTrue(store.isActivated(), "门店不可用");
|
return;
|
||||||
|
}
|
||||||
|
UserRoleAuthorizeReq req = new UserRoleAuthorizeReq();
|
||||||
|
req.setUserId(entity.getUserId());
|
||||||
|
req.setModuleCode(ModuleCode.GAO);
|
||||||
|
req.setRoleIdList(entity.getRoleIdList());
|
||||||
|
roleService.authorizeUserRole(req);
|
||||||
|
}
|
||||||
|
|
||||||
GaoUser dbGaoUser = super.get(gaoUser.getId());
|
private void loadUser(GaoUser gaoUser) {
|
||||||
TimiException.required(dbGaoUser, "not found gao user");
|
if (gaoUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gaoUser.setUser(userMapper.select(gaoUser.getUserId()));
|
||||||
|
gaoUser.setRoleList(roleService.listByUserId(gaoUser.getUserId(), ModuleCode.GAO));
|
||||||
|
}
|
||||||
|
|
||||||
dbGaoUser.setStoreId(gaoUser.getStoreId());
|
private void loadUser(List<GaoUser> gaoUserList) {
|
||||||
super.update(dbGaoUser);
|
if (gaoUserList == null || gaoUserList.isEmpty()) {
|
||||||
|
return;
|
||||||
logger.setLevel(Logger.Level.INFO);
|
}
|
||||||
logger.setResult(gaoUser.getId());
|
List<String> userIdList = gaoUserList.stream().map(GaoUser::getUserId).distinct().toList();
|
||||||
} catch (TimiException e) {
|
Map<String, User> userMap = userMapper.listByIdList(new ArrayList<>(userIdList)).stream()
|
||||||
logger.setLevel(Logger.Level.WARN);
|
.collect(Collectors.toMap(User::getId, Function.identity(), (left, right) -> left));
|
||||||
logger.setException(e.getMessage());
|
for (GaoUser gaoUser : gaoUserList) {
|
||||||
throw e;
|
gaoUser.setUser(userMap.get(gaoUser.getUserId()));
|
||||||
} catch (Exception e) {
|
List<Role> roleList = roleService.listByUserId(gaoUser.getUserId(), ModuleCode.GAO);
|
||||||
logger.setLevel(Logger.Level.ERROR);
|
gaoUser.setRoleList(roleList);
|
||||||
logger.setException(TimiJava.serializeThrowable(e));
|
|
||||||
log.error("transfer user store error", e);
|
|
||||||
throw new TimiException(TimiCode.ERROR, "transfer user store error", e);
|
|
||||||
} finally {
|
|
||||||
loggerService.create(logger);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.util;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import com.imyeyu.api.util.BaseXSSFBuilder;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-08-04 15:59
|
|
||||||
@Component
|
|
||||||
public class CustomerXSSFBuilder extends BaseXSSFBuilder<GaoCustomer> {
|
|
||||||
|
|
||||||
public byte[] build(List<GaoCustomer> list) throws IOException {
|
|
||||||
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
||||||
Sheet sheet = workbook.createSheet("客户列表");
|
|
||||||
CellStyle titleStyle = createTitleStyle(workbook);
|
|
||||||
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
||||||
|
|
||||||
appendRow(sheet, 0, titleStyle, "客户列表导出");
|
|
||||||
appendRow(sheet, 1, null, "生成时间", Time.nowString());
|
|
||||||
appendRow(sheet, 2, null, "记录总数", String.valueOf(list.size()));
|
|
||||||
appendRow(sheet, 3, headerStyle, "客户编码", "姓名", "性别", "出生日期(公历)", "出生日期历法", "年龄", "电话", "地址", "病症", "备注", "邀请人", "邀请客户数", "创建时间");
|
|
||||||
int rowIndex = 4;
|
|
||||||
for (GaoCustomer customer : list) {
|
|
||||||
appendRow(sheet, rowIndex, null,
|
|
||||||
text(customer.getCode()),
|
|
||||||
text(customer.getName()),
|
|
||||||
gender(customer.getGender()),
|
|
||||||
text(customer.getBirthdate()),
|
|
||||||
formatBirthdateCalendar(customer),
|
|
||||||
customer.getAge() == null ? "" : String.valueOf(customer.getAge()),
|
|
||||||
text(customer.getTelephone()),
|
|
||||||
text(customer.getAddress()),
|
|
||||||
text(customer.getDisease()),
|
|
||||||
text(customer.getRemark()),
|
|
||||||
customer.getIntroducerCustomer() == null ? "" : text(customer.getIntroducerCustomer().getName()),
|
|
||||||
String.valueOf(customer.getInvitedCount()),
|
|
||||||
Time.toDateTime(customer.getCreatedAt())
|
|
||||||
);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
for (int index = 0; index < 13; index++) {
|
|
||||||
sheet.autoSizeColumn(index);
|
|
||||||
sheet.setColumnWidth(index, Math.clamp(sheet.getColumnWidth(index), 10 * 256, 36 * 256));
|
|
||||||
}
|
|
||||||
workbook.write(output);
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatBirthdateCalendar(GaoCustomer customer) {
|
|
||||||
if (customer.getBirthdateCalendar() == null) {
|
|
||||||
return "公历";
|
|
||||||
}
|
|
||||||
return customer.getBirthdateCalendar() == GaoCustomer.BirthdateCalendar.LUNAR ? "农历" : "公历";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.util;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoEventRecord;
|
|
||||||
import com.imyeyu.api.util.BaseXSSFBuilder;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-08-05 11:03
|
|
||||||
@Component
|
|
||||||
public class EventRecordXSSFBuilder extends BaseXSSFBuilder<GaoEventRecord> {
|
|
||||||
|
|
||||||
public byte[] build(List<GaoEventRecord> list) throws IOException {
|
|
||||||
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
||||||
Sheet sheet = workbook.createSheet("登记事件记录");
|
|
||||||
CellStyle titleStyle = createTitleStyle(workbook);
|
|
||||||
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
||||||
|
|
||||||
appendRow(sheet, 0, titleStyle, "登记事件记录导出");
|
|
||||||
appendRow(sheet, 1, null, "生成时间", Time.nowString());
|
|
||||||
appendRow(sheet, 2, null, "记录总数", String.valueOf(list.size()));
|
|
||||||
appendRow(sheet, 3, headerStyle, "客户编码", "客户姓名", "登记事件", "登记时间", "登记人", "备注");
|
|
||||||
int rowIndex = 4;
|
|
||||||
for (GaoEventRecord record : list) {
|
|
||||||
appendRow(sheet, rowIndex, null,
|
|
||||||
record.getCustomer() == null ? "" : text(record.getCustomer().getCode()),
|
|
||||||
record.getCustomer() == null ? "" : text(record.getCustomer().getName()),
|
|
||||||
record.getEvent() == null ? "" : text(record.getEvent().getName()),
|
|
||||||
Time.toDateTime(record.getRegisteredAt()),
|
|
||||||
record.getOperator().getName(),
|
|
||||||
text(record.getRemark())
|
|
||||||
);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
sheet.autoSizeColumn(i);
|
|
||||||
sheet.setColumnWidth(i, Math.clamp(sheet.getColumnWidth(i), 12 * 256, 40 * 256));
|
|
||||||
}
|
|
||||||
workbook.write(output);
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.util;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoStore;
|
|
||||||
import com.imyeyu.api.util.BaseXSSFBuilder;
|
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 门店 Excel 构建器
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-06
|
|
||||||
@Component
|
|
||||||
public class StoreXSSFBuilder extends BaseXSSFBuilder<GaoStore> {
|
|
||||||
|
|
||||||
/// 构建门店列表 Excel
|
|
||||||
///
|
|
||||||
/// @param list 门店列表
|
|
||||||
/// @return xlsx 文件字节
|
|
||||||
/// @throws IOException 写入异常
|
|
||||||
public byte[] build(List<GaoStore> list) throws IOException {
|
|
||||||
try (Workbook workbook = new XSSFWorkbook(); ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
||||||
Sheet sheet = workbook.createSheet("门店列表");
|
|
||||||
CellStyle titleStyle = createTitleStyle(workbook);
|
|
||||||
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
||||||
|
|
||||||
appendRow(sheet, 0, titleStyle, "门店列表导出");
|
|
||||||
appendRow(sheet, 1, null, "生成时间", Time.nowString());
|
|
||||||
appendRow(sheet, 2, null, "记录总数", String.valueOf(list.size()));
|
|
||||||
appendRow(sheet, 3, headerStyle, "门店编码", "门店名称", "状态", "电话", "地址", "备注", "排序", "创建时间");
|
|
||||||
int rowIndex = 4;
|
|
||||||
for (GaoStore store : list) {
|
|
||||||
appendRow(sheet, rowIndex, null,
|
|
||||||
text(store.getCode()),
|
|
||||||
text(store.getName()),
|
|
||||||
store.getStatus() == null ? "" : store.getStatus().name(),
|
|
||||||
text(store.getTelephone()),
|
|
||||||
text(store.getAddress()),
|
|
||||||
text(store.getRemark()),
|
|
||||||
store.getSort() == null ? "" : String.valueOf(store.getSort()),
|
|
||||||
Time.toDateTime(store.getCreatedAt())
|
|
||||||
);
|
|
||||||
rowIndex++;
|
|
||||||
}
|
|
||||||
for (int index = 0; index < 8; index++) {
|
|
||||||
sheet.autoSizeColumn(index);
|
|
||||||
sheet.setColumnWidth(index, Math.clamp(sheet.getColumnWidth(index), 10 * 256, 36 * 256));
|
|
||||||
}
|
|
||||||
workbook.write(output);
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -8,7 +8,7 @@ import lombok.Data;
|
|||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-28
|
/// @since 2026-07-28
|
||||||
@Data
|
@Data
|
||||||
public class GaoCustomerDailyStateView {
|
public class GaoCustomerDailyStatView {
|
||||||
|
|
||||||
/// 日期值,格式为 yyyyMMdd
|
/// 日期值,格式为 yyyyMMdd
|
||||||
private Integer dateValue;
|
private Integer dateValue;
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// 客户登记排行榜视图
|
|
||||||
///
|
|
||||||
/// @author Codex
|
|
||||||
/// @since 2026-08-03
|
|
||||||
@Data
|
|
||||||
public class GaoCustomerEventRankView {
|
|
||||||
|
|
||||||
/// 排名
|
|
||||||
private Integer rank;
|
|
||||||
|
|
||||||
/// 客户 ID
|
|
||||||
private String customerId;
|
|
||||||
|
|
||||||
/// 客户
|
|
||||||
private GaoCustomer customer;
|
|
||||||
|
|
||||||
/// 累计登记天数
|
|
||||||
private Long totalEventDays;
|
|
||||||
|
|
||||||
/// 累计登记次数
|
|
||||||
private Long totalEventCount;
|
|
||||||
|
|
||||||
/// 最近连续登记天数
|
|
||||||
private Long recentContinuousEventDays;
|
|
||||||
|
|
||||||
/// 最后登记时间
|
|
||||||
private Long latestRegisteredAt;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 客户邀请关系更新请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoCustomerInviteUpdateReq {
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 介绍人客户 ID
|
||||||
|
private String introducerCustomerId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 客户登记统计视图
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoCustomerRegisterStatView {
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 客户姓名
|
||||||
|
private String customerName;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 登记事件名称
|
||||||
|
private String registrationEventName;
|
||||||
|
|
||||||
|
/// 数量
|
||||||
|
private Long count;
|
||||||
|
|
||||||
|
/// 最后登记时间
|
||||||
|
private Long latestRegisteredAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 客户搜索请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoCustomerSearchReq {
|
||||||
|
|
||||||
|
/// 关键字,匹配编码、姓名、手机号、电话、住址、病症、条例部位
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
|
/// 介绍人客户 ID
|
||||||
|
private String introducerCustomerId;
|
||||||
|
}
|
||||||
+1
-4
@@ -8,10 +8,7 @@ import lombok.Data;
|
|||||||
/// @author Codex
|
/// @author Codex
|
||||||
/// @since 2026-07-28
|
/// @since 2026-07-28
|
||||||
@Data
|
@Data
|
||||||
public class GaoCustomerTrendStateReq {
|
public class GaoCustomerTrendStatReq {
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 开始创建时间
|
/// 开始创建时间
|
||||||
private Long beginCreatedAt;
|
private Long beginCreatedAt;
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
|
||||||
|
|
||||||
import com.imyeyu.java.bean.BasePage;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-08-05 12:44
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class GaoEventRecordRankPage extends BasePage {
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 客户 ID,为空查询全部客户
|
|
||||||
private String customerId;
|
|
||||||
|
|
||||||
/// 登记事件 ID 列表,为空查询全部登记事件
|
|
||||||
private List<String> eventIdList;
|
|
||||||
|
|
||||||
/// 开始登记时间
|
|
||||||
private Long beginAt;
|
|
||||||
|
|
||||||
/// 结束登记时间
|
|
||||||
private Long endAt;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 快速录入并登记请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-28
|
||||||
|
@Data
|
||||||
|
public class GaoQuickRegistrationEventRecordReq {
|
||||||
|
|
||||||
|
/// 客户编码
|
||||||
|
private String customerCode;
|
||||||
|
|
||||||
|
/// 登记登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 备注
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/// 临时照片附件 ID 列表
|
||||||
|
private List<String> attachmentIdList = new ArrayList<>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件周期统计视图
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventPeriodStatView {
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 周期值
|
||||||
|
private Integer periodValue;
|
||||||
|
|
||||||
|
/// 数量
|
||||||
|
private Long count;
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录日历轻量视图
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-01
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordCalendarView {
|
||||||
|
|
||||||
|
/// 记录 ID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 客户编码
|
||||||
|
private String customerCode;
|
||||||
|
|
||||||
|
/// 客户姓名
|
||||||
|
private String customerName;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 登记时间
|
||||||
|
private Long registeredAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记登记事件记录创建请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordCreateReq {
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 客户编码,扫码登记可直接传这个
|
||||||
|
private String customerCode;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 备注
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/// 登记时间
|
||||||
|
private Long registeredAt;
|
||||||
|
|
||||||
|
/// 临时照片附件 ID 列表
|
||||||
|
private List<String> attachmentIdList = new ArrayList<>();
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录每日统计视图
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-28
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordDailyStatView {
|
||||||
|
|
||||||
|
/// 日期值,格式为 yyyyMMdd
|
||||||
|
private Integer dateValue;
|
||||||
|
|
||||||
|
/// 当日登记数
|
||||||
|
private Long dailyCount;
|
||||||
|
|
||||||
|
/// 截止当日累计登记数
|
||||||
|
private Long totalCount;
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录列表项视图
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-08-01
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordListItemView {
|
||||||
|
|
||||||
|
/// 记录 ID
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/// 客户 ID
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 客户姓名
|
||||||
|
private String customerName;
|
||||||
|
|
||||||
|
/// 客户头像附件 ID
|
||||||
|
private String customerPhotoAttachmentId;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 登记事件名称
|
||||||
|
private String registrationEventName;
|
||||||
|
|
||||||
|
/// 登记时间
|
||||||
|
private Long registeredAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录按周期查询请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordPeriodReq {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 周期类型
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
public enum PeriodType {
|
||||||
|
|
||||||
|
DAY,
|
||||||
|
|
||||||
|
MONTH,
|
||||||
|
|
||||||
|
YEAR
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 周期类型
|
||||||
|
private PeriodType periodType;
|
||||||
|
|
||||||
|
/// 周期值,日为 yyyyMMdd,月为 yyyyMM,年为 yyyy
|
||||||
|
private Integer periodValue;
|
||||||
|
}
|
||||||
+9
-12
@@ -1,35 +1,32 @@
|
|||||||
package com.imyeyu.api.modules.gao.vo;
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
import com.imyeyu.java.bean.BasePage;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// 登记事件记录范围查询请求
|
/// 登记事件记录范围查询请求
|
||||||
///
|
///
|
||||||
/// @author 夜雨
|
/// @author Codex
|
||||||
/// @since 2026-07-28 11:01
|
/// @since 2026-07-28
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
public class GaoRegistrationEventRecordRangeReq {
|
||||||
public class GaoEventRecordPage extends BasePage {
|
|
||||||
|
|
||||||
/// 门店 ID
|
|
||||||
private String storeId;
|
|
||||||
|
|
||||||
/// 客户 ID,为空查询全部客户
|
/// 客户 ID,为空查询全部客户
|
||||||
private String customerId;
|
private String customerId;
|
||||||
|
|
||||||
|
/// 登记事件 ID,为空查询全部登记事件
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
/// 登记事件 ID 列表,为空查询全部登记事件
|
/// 登记事件 ID 列表,为空查询全部登记事件
|
||||||
private List<String> eventIdList;
|
private List<String> registrationEventIdList;
|
||||||
|
|
||||||
/// 关键词,匹配客户、登记事件、备注、登记人
|
/// 关键词,匹配客户、登记事件、备注、登记人
|
||||||
private String keyword;
|
private String keyword;
|
||||||
|
|
||||||
/// 开始登记时间
|
/// 开始登记时间
|
||||||
private Long beginAt;
|
private Long beginRegisteredAt;
|
||||||
|
|
||||||
/// 结束登记时间
|
/// 结束登记时间
|
||||||
private Long endAt;
|
private Long endRegisteredAt;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录统计请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-28
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordStatReq {
|
||||||
|
|
||||||
|
/// 客户 ID,全部客户统计时不传
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 开始登记时间
|
||||||
|
private Long beginRegisteredAt;
|
||||||
|
|
||||||
|
/// 结束登记时间
|
||||||
|
private Long endRegisteredAt;
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件记录趋势统计请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-28
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventRecordTrendStatReq {
|
||||||
|
|
||||||
|
/// 客户 ID,全部客户趋势时不传
|
||||||
|
private String customerId;
|
||||||
|
|
||||||
|
/// 登记事件 ID
|
||||||
|
private String registrationEventId;
|
||||||
|
|
||||||
|
/// 开始登记时间
|
||||||
|
private Long beginRegisteredAt;
|
||||||
|
|
||||||
|
/// 结束登记时间
|
||||||
|
private Long endRegisteredAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.imyeyu.api.modules.gao.vo;
|
||||||
|
|
||||||
|
import com.imyeyu.api.modules.gao.entity.GaoRegistrationEvent;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// 登记事件保存请求
|
||||||
|
///
|
||||||
|
/// @author Codex
|
||||||
|
/// @since 2026-07-27
|
||||||
|
@Data
|
||||||
|
public class GaoRegistrationEventSaveReq {
|
||||||
|
|
||||||
|
/// 登记事件
|
||||||
|
private GaoRegistrationEvent registrationEvent;
|
||||||
|
|
||||||
|
/// 可登记角色代码列表
|
||||||
|
private List<String> roleCodeList = new ArrayList<>();
|
||||||
|
}
|
||||||
@@ -17,21 +17,6 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Logger implements IDEntity<String>, Creatable {
|
public class Logger implements IDEntity<String>, Creatable {
|
||||||
|
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @author 夜雨
|
|
||||||
/// @since 2026-08-03 11:43
|
|
||||||
public enum Module {
|
|
||||||
|
|
||||||
SYSTEM,
|
|
||||||
|
|
||||||
COMMON,
|
|
||||||
|
|
||||||
USER,
|
|
||||||
|
|
||||||
GAO,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志级别
|
* 日志级别
|
||||||
*
|
*
|
||||||
@@ -58,7 +43,7 @@ public class Logger implements IDEntity<String>, Creatable {
|
|||||||
private Level level;
|
private Level level;
|
||||||
|
|
||||||
/** 模块名称 */
|
/** 模块名称 */
|
||||||
private Module module;
|
private String module;
|
||||||
|
|
||||||
/** 操作描述 */
|
/** 操作描述 */
|
||||||
private String operation;
|
private String operation;
|
||||||
@@ -84,26 +69,7 @@ public class Logger implements IDEntity<String>, Creatable {
|
|||||||
/** 创建时间 */
|
/** 创建时间 */
|
||||||
private Long createdAt;
|
private Long createdAt;
|
||||||
|
|
||||||
public Logger(Module module, String operation) {
|
public Logger(Level level) {
|
||||||
this.module = module;
|
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger(Module module, Level level, String operation) {
|
|
||||||
this.module = module;
|
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.operation = operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Logger info(Module module, String operation) {
|
|
||||||
return new Logger(module, Level.INFO, operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Logger warning(Module module, String operation) {
|
|
||||||
return new Logger(module, Level.WARN, operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Logger error(Module module, String operation) {
|
|
||||||
return new Logger(module, Level.ERROR, operation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,29 +16,41 @@ public interface LoggerService extends GettableService<Logger, String>, Pageable
|
|||||||
|
|
||||||
void createSync(Logger logger);
|
void createSync(Logger logger);
|
||||||
|
|
||||||
void create(Logger.Module module, Logger.Level level, String operation, String content, String result);
|
void create(Logger.Level level, String module, String operation, String userId, String content, String result);
|
||||||
|
|
||||||
default void info(Logger.Module module, String operation) {
|
default void info(String module, String operation, String userId) {
|
||||||
create(module, Logger.Level.INFO, operation, null, null);
|
create(Logger.Level.INFO, module, operation, userId, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void info(Logger.Module module, String operation, String content, String result) {
|
default void info(String module, String operation, String content, String result) {
|
||||||
create(module, Logger.Level.INFO, operation, content, result);
|
create(Logger.Level.INFO, module, operation, null, content, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void warning(Logger.Module module, String operation) {
|
default void info(String module, String operation, String userId, String content, String result) {
|
||||||
create(module, Logger.Level.WARN, operation, null, null);
|
create(Logger.Level.INFO, module, operation, userId, content, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void warning(Logger.Module module, String operation, String content, String result) {
|
default void warning(String module, String operation, String userId) {
|
||||||
create(module, Logger.Level.WARN, operation, content, result);
|
create(Logger.Level.WARN, module, operation, userId, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void error(Logger.Module module, String operation) {
|
default void warning(String module, String operation, String content, String result) {
|
||||||
create(module, Logger.Level.ERROR, operation, null, null);
|
create(Logger.Level.WARN, module, operation, null, content, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void error(Logger.Module module, String operation, String content, String result) {
|
default void warning(String module, String operation, String userId, String content, String result) {
|
||||||
create(module, Logger.Level.ERROR, operation, content, result);
|
create(Logger.Level.WARN, module, operation, userId, content, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void error(String module, String operation, String userId) {
|
||||||
|
create(Logger.Level.ERROR, module, operation, userId, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void error(String module, String operation, String content, String result) {
|
||||||
|
create(Logger.Level.ERROR, module, operation, null, content, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void error(String module, String operation, String userId, String content, String result) {
|
||||||
|
create(Logger.Level.ERROR, module, operation, userId, content, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-14
@@ -3,7 +3,6 @@ package com.imyeyu.api.modules.system.service.implement;
|
|||||||
import com.imyeyu.api.modules.system.entity.Logger;
|
import com.imyeyu.api.modules.system.entity.Logger;
|
||||||
import com.imyeyu.api.modules.system.mapper.LoggerMapper;
|
import com.imyeyu.api.modules.system.mapper.LoggerMapper;
|
||||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -19,8 +18,6 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class LoggerServiceImplement extends AbstractEntityService<Logger, String> implements LoggerService {
|
public class LoggerServiceImplement extends AbstractEntityService<Logger, String> implements LoggerService {
|
||||||
|
|
||||||
private final UserLoginService userLoginService;
|
|
||||||
|
|
||||||
private final LoggerMapper mapper;
|
private final LoggerMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,24 +28,19 @@ public class LoggerServiceImplement extends AbstractEntityService<Logger, String
|
|||||||
@Override
|
@Override
|
||||||
public void create(Logger logger) {
|
public void create(Logger logger) {
|
||||||
// 默认异步
|
// 默认异步
|
||||||
Thread.startVirtualThread(() -> createSync(logger));
|
Thread.startVirtualThread(() -> super.create(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createSync(Logger logger) {
|
public void createSync(Logger logger) {
|
||||||
// TODO 异步请求上下文已丢失
|
|
||||||
// if (TimiJava.isEmpty(logger.getUserId())) {
|
|
||||||
// User loginUser = userLoginService.getLoginUser();
|
|
||||||
// if (TimiJava.isNotEmpty(loginUser)) {
|
|
||||||
// logger.setUserId(loginUser.getId());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// logger.setIp(TimiJava.defaultIfEmpty(logger.getIp(), TimiSpring.getRequestIP()));
|
|
||||||
super.create(logger);
|
super.create(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(Logger.Module module, Logger.Level level, String operation, String content, String result) {
|
public void create(Logger.Level level, String module, String operation, String userId, String content, String result) {
|
||||||
Logger log = new Logger(module, level, operation);
|
Logger log = new Logger(level);
|
||||||
|
log.setModule(module);
|
||||||
|
log.setOperation(operation);
|
||||||
|
log.setUserId(userId);
|
||||||
log.setContent(content);
|
log.setContent(content);
|
||||||
log.setResult(result);
|
log.setResult(result);
|
||||||
create(log);
|
create(log);
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import com.imyeyu.api.modules.user.entity.Permission;
|
|||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.api.modules.user.service.PermissionService;
|
import com.imyeyu.api.modules.user.service.PermissionService;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeReq;
|
||||||
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeRequest;
|
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.bean.Page;
|
import com.imyeyu.spring.bean.Page;
|
||||||
import com.imyeyu.spring.bean.PageResult;
|
import com.imyeyu.spring.bean.PageResult;
|
||||||
@@ -38,7 +37,6 @@ import java.util.List;
|
|||||||
public class RoleController {
|
public class RoleController {
|
||||||
|
|
||||||
private final RoleService service;
|
private final RoleService service;
|
||||||
private final UserRoleService userRoleService;
|
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
|
|
||||||
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
||||||
@@ -88,26 +86,26 @@ public class RoleController {
|
|||||||
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
||||||
@RequireCorePermission(CorePermissionCode.USER_ROLE_READ)
|
@RequireCorePermission(CorePermissionCode.USER_ROLE_READ)
|
||||||
@PostMapping("/authorized/list")
|
@PostMapping("/authorized/list")
|
||||||
public List<Role> listUserRole(@RequestParam(required = false) ModuleCode moduleCode, @RequestParam String userId) {
|
public List<Role> listUserRole(@RequestParam String userId, @RequestParam(required = false) ModuleCode moduleCode) {
|
||||||
if (moduleCode != null) {
|
if (moduleCode != null) {
|
||||||
return userRoleService.listRoleByUserId(moduleCode, userId);
|
return service.listByUserId(userId, moduleCode);
|
||||||
}
|
}
|
||||||
return userRoleService.listRoleByUserId(userId);
|
return service.listByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
||||||
@RequireCorePermission(value = {CorePermissionCode.USER_ROLE_CREATE, CorePermissionCode.USER_ROLE_DELETE})
|
@RequireCorePermission(value = {CorePermissionCode.USER_ROLE_CREATE, CorePermissionCode.USER_ROLE_DELETE})
|
||||||
@PostMapping("/authorized/create")
|
@PostMapping("/authorized/create")
|
||||||
public void authorizeUserRole(@RequestBody UserRoleAuthorizeRequest req) {
|
public void authorizeUserRole(@RequestBody UserRoleAuthorizeReq req) {
|
||||||
userRoleService.authorizeUserRole(req);
|
service.authorizeUserRole(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
@RequireCoreRole(value = {CoreRoleCode.ADMIN, CoreRoleCode.USER_ROLE_ADMIN}, mode = RoleMatchMode.ANY)
|
||||||
@RequireCorePermission(CorePermissionCode.USER_ROLE_READ)
|
@RequireCorePermission(CorePermissionCode.USER_ROLE_READ)
|
||||||
@PostMapping("/authorized/permission")
|
@PostMapping("/authorized/permission")
|
||||||
public List<Permission> listAuthorizedPermission(@RequestParam String userId) {
|
public List<Permission> listAuthorizedPermission(@RequestParam String userId) {
|
||||||
return userRoleService.listAllPermissionByUserId(userId);
|
return service.listAllPermissionByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillRoleDetail(Role role) {
|
private void fillRoleDetail(Role role) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.imyeyu.api.bean.CorePermissionCode;
|
|||||||
import com.imyeyu.api.bean.CoreRoleCode;
|
import com.imyeyu.api.bean.CoreRoleCode;
|
||||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||||
|
import com.imyeyu.api.modules.common.vo.attach.BizUpdateReq;
|
||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
@@ -16,7 +17,6 @@ import com.imyeyu.api.modules.user.vo.LoginResponse;
|
|||||||
import com.imyeyu.api.modules.user.vo.PhoneVerifyCodeSendRequest;
|
import com.imyeyu.api.modules.user.vo.PhoneVerifyCodeSendRequest;
|
||||||
import com.imyeyu.api.modules.user.vo.PhoneVerifyRequest;
|
import com.imyeyu.api.modules.user.vo.PhoneVerifyRequest;
|
||||||
import com.imyeyu.api.modules.user.vo.UpdatePasswordRequest;
|
import com.imyeyu.api.modules.user.vo.UpdatePasswordRequest;
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.spring.TimiSpring;
|
import com.imyeyu.spring.TimiSpring;
|
||||||
import com.imyeyu.spring.annotation.AOPLog;
|
import com.imyeyu.spring.annotation.AOPLog;
|
||||||
import com.imyeyu.spring.annotation.CaptchaValid;
|
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||||
@@ -131,7 +131,6 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
@RequiredToken
|
@RequiredToken
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
@RequestMapping("/login/token")
|
@RequestMapping("/login/token")
|
||||||
@@ -142,24 +141,37 @@ public class UserController {
|
|||||||
/**
|
/**
|
||||||
* 更新当前用户资料
|
* 更新当前用户资料
|
||||||
*
|
*
|
||||||
* @param user 用户资料
|
* @param req 用户资料
|
||||||
* @return 最新登录用户
|
* @return 最新登录用户
|
||||||
*/
|
*/
|
||||||
@AOPLog
|
@AOPLog
|
||||||
@RequiredToken
|
@RequiredToken
|
||||||
@RequestRateLimit
|
@RequestRateLimit
|
||||||
|
@RequireCorePermission(CorePermissionCode.USER_UPDATE)
|
||||||
@PostMapping("/current/update")
|
@PostMapping("/current/update")
|
||||||
public LoginResponse updateCurrent(@RequestBody User user) {
|
public LoginResponse updateCurrent(@RequestBody User req) {
|
||||||
User loginUser = userLoginService.getRequireLoginUser();
|
User loginUser = userLoginService.getRequireLoginUser();
|
||||||
User dbUser = userService.get(loginUser.getId());
|
User user = userService.get(loginUser.getId());
|
||||||
dbUser.setName(TimiJava.defaultIfEmpty(user.getName(), dbUser.getName()));
|
if (req.getName() != null) {
|
||||||
dbUser.setNick(TimiJava.defaultIfEmpty(user.getNick(), dbUser.getNick()));
|
user.setName(req.getName());
|
||||||
dbUser.setGender(TimiJava.defaultIfNull(user.getGender(), dbUser.getGender()));
|
}
|
||||||
dbUser.setDescription(user.getDescription());
|
if (req.getNick() != null) {
|
||||||
dbUser.setAvatarType(TimiJava.defaultIfNull(user.getAvatarType(), dbUser.getAvatarType()));
|
user.setNick(req.getNick());
|
||||||
dbUser.setWrapperType(TimiJava.defaultIfNull(user.getAvatarType(), dbUser.getWrapperType()));
|
}
|
||||||
userService.update(dbUser);
|
if (req.getGender() != null) {
|
||||||
updateCurrentAvatar(loginUser.getId(), user.getTempFileIdList());
|
user.setGender(req.getGender());
|
||||||
|
}
|
||||||
|
if (req.getDescription() != null) {
|
||||||
|
user.setDescription(req.getDescription());
|
||||||
|
}
|
||||||
|
if (req.getAvatarType() != null) {
|
||||||
|
user.setAvatarType(req.getAvatarType());
|
||||||
|
}
|
||||||
|
if (req.getWrapperType() != null) {
|
||||||
|
user.setWrapperType(req.getWrapperType());
|
||||||
|
}
|
||||||
|
userService.update(user);
|
||||||
|
updateCurrentAvatar(loginUser.getId(), req.getTempFileIdList());
|
||||||
return userLoginService.login(TimiSpring.getToken(), loginUser.getId());
|
return userLoginService.login(TimiSpring.getToken(), loginUser.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +245,9 @@ public class UserController {
|
|||||||
if (tempFileIdList == null || tempFileIdList.isEmpty()) {
|
if (tempFileIdList == null || tempFileIdList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BizUpdateReq req = new BizUpdateReq();
|
||||||
|
req.setBizType(Attachment.BizType.USER);
|
||||||
|
req.setBizId(userId);
|
||||||
List<Attachment> items = attachmentService.listByBizId(Attachment.BizType.USER, userId).stream()
|
List<Attachment> items = attachmentService.listByBizId(Attachment.BizType.USER, userId).stream()
|
||||||
.filter(item -> !User.AttachType.AVATAR.name().equals(item.getAttachType()))
|
.filter(item -> !User.AttachType.AVATAR.name().equals(item.getAttachType()))
|
||||||
.map(item -> {
|
.map(item -> {
|
||||||
@@ -249,6 +264,7 @@ public class UserController {
|
|||||||
}).toList();
|
}).toList();
|
||||||
items = new ArrayList<>(items);
|
items = new ArrayList<>(items);
|
||||||
items.addAll(avatarItems);
|
items.addAll(avatarItems);
|
||||||
attachmentService.updateByBizId(Attachment.BizType.USER, userId, items);
|
req.setItems(items);
|
||||||
|
attachmentService.updateByBiz(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.imyeyu.api.modules.user.bean.Gender;
|
|||||||
import com.imyeyu.spring.annotation.table.Transient;
|
import com.imyeyu.spring.annotation.table.Transient;
|
||||||
import com.imyeyu.spring.entity.UUIDEntity;
|
import com.imyeyu.spring.entity.UUIDEntity;
|
||||||
import com.imyeyu.spring.util.ResponseView;
|
import com.imyeyu.spring.util.ResponseView;
|
||||||
import com.imyeyu.utils.Regex;
|
|
||||||
import com.imyeyu.utils.Time;
|
import com.imyeyu.utils.Time;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -105,7 +104,7 @@ public class User extends UUIDEntity {
|
|||||||
protected String lastLoginIP;
|
protected String lastLoginIP;
|
||||||
|
|
||||||
/** 上次登录时间 */
|
/** 上次登录时间 */
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Admin.class)
|
||||||
protected Long lastLoginAt;
|
protected Long lastLoginAt;
|
||||||
|
|
||||||
/** 解除禁言时间 */
|
/** 解除禁言时间 */
|
||||||
@@ -124,10 +123,6 @@ public class User extends UUIDEntity {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
protected List<String> permissionList;
|
protected List<String> permissionList;
|
||||||
|
|
||||||
@Transient
|
|
||||||
@JsonView(ResponseView.Public.class)
|
|
||||||
protected List<Role> roleEntityList;
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
protected List<Attachment> attachmentList;
|
protected List<Attachment> attachmentList;
|
||||||
@@ -140,10 +135,6 @@ public class User extends UUIDEntity {
|
|||||||
@JsonView(ResponseView.Public.class)
|
@JsonView(ResponseView.Public.class)
|
||||||
protected List<String> tempFileIdList;
|
protected List<String> tempFileIdList;
|
||||||
|
|
||||||
public boolean isValidPhone() {
|
|
||||||
return Regex.isMatch(Regex.MOBILE_PHONE, phoneNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return true 为禁言中 */
|
/** @return true 为禁言中 */
|
||||||
public boolean isMuting() {
|
public boolean isMuting() {
|
||||||
return unmuteAt != null && Time.now() < unmuteAt;
|
return unmuteAt != null && Time.now() < unmuteAt;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package com.imyeyu.api.modules.user.mapper;
|
|||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +15,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface RoleMapper extends BaseMapper<Role, String> {
|
public interface RoleMapper extends BaseMapper<Role, String> {
|
||||||
|
|
||||||
List<Role> selectByIdList(Collection<String> idList);
|
List<Role> selectByIdList(List<String> idList);
|
||||||
|
|
||||||
List<Role> selectByModuleCode(ModuleCode moduleCode);
|
List<Role> selectByModuleCodeAndCodeList(@Param("moduleCode") ModuleCode moduleCode, @Param("codeList") List<String> codeList);
|
||||||
|
|
||||||
|
List<Role> selectByModuleCode(@Param("moduleCode") ModuleCode moduleCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.imyeyu.api.modules.user.entity.User;
|
|||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,5 +32,5 @@ public interface UserMapper extends BaseMapper<User, String> {
|
|||||||
* @param idList 用户 ID 列表
|
* @param idList 用户 ID 列表
|
||||||
* @return 用户列表
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
List<User> listByIdList(Collection<String> idList);
|
List<User> listByIdList(List<String> idList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package com.imyeyu.api.modules.user.mapper;
|
|||||||
|
|
||||||
import com.imyeyu.api.modules.user.entity.UserRole;
|
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +15,5 @@ public interface UserRoleMapper extends BaseMapper<UserRole, String> {
|
|||||||
|
|
||||||
void createBatch(List<UserRole> userRoleList);
|
void createBatch(List<UserRole> userRoleList);
|
||||||
|
|
||||||
List<UserRole> selectByUserIdList(@Param("userIdList") Collection<String> userIdList);
|
|
||||||
|
|
||||||
void deleteByRoleIdList(String userId, List<String> roleIdList);
|
void deleteByRoleIdList(String userId, List<String> roleIdList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package com.imyeyu.api.modules.user.service;
|
|||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.user.entity.Permission;
|
import com.imyeyu.api.modules.user.entity.Permission;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
|
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeReq;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/// 角色服务
|
/// 角色服务
|
||||||
@@ -14,13 +14,60 @@ import java.util.List;
|
|||||||
/// @since 2026-05-13 14:46
|
/// @since 2026-05-13 14:46
|
||||||
public interface RoleService extends BaseService<Role, String> {
|
public interface RoleService extends BaseService<Role, String> {
|
||||||
|
|
||||||
|
/// 给用户授权角色
|
||||||
|
///
|
||||||
|
/// @param req 用户角色授权请求
|
||||||
|
void authorizeUserRole(UserRoleAuthorizeReq req);
|
||||||
|
|
||||||
|
/// 查询用户直属角色
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 角色列表
|
||||||
|
List<Role> listByUserId(String userId);
|
||||||
|
|
||||||
|
/// 查询用户指定模块直属角色
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @param moduleCode 模块代码
|
||||||
|
/// @return 角色列表
|
||||||
|
List<Role> listByUserId(String userId, ModuleCode moduleCode);
|
||||||
|
|
||||||
/// 查询模块角色
|
/// 查询模块角色
|
||||||
///
|
///
|
||||||
/// @param moduleCode 模块代码
|
/// @param moduleCode 模块代码
|
||||||
/// @return 角色列表
|
/// @return 角色列表
|
||||||
List<Role> listByModuleCode(ModuleCode moduleCode);
|
List<Role> listByModuleCode(ModuleCode moduleCode);
|
||||||
|
|
||||||
List<Role> listByIdList(Collection<String> idList);
|
/// 查询用户直属角色编码
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 角色编码列表,格式为 MODULE:ROLE
|
||||||
|
default List<String> listCodeByUserId(String userId) {
|
||||||
|
return listByUserId(userId).stream().map(role -> "%s:%s".formatted(role.getModuleCode().name(), role.getCode())).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 查询用户全部角色编码
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 包含子角色的角色编码列表,格式为 MODULE:ROLE
|
||||||
|
List<String> listAllCodeByUserId(String userId);
|
||||||
|
|
||||||
|
/// 查询用户全部权限
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 权限列表
|
||||||
|
List<Permission> listAllPermissionByUserId(String userId);
|
||||||
|
|
||||||
|
/// 查询用户全部权限编码
|
||||||
|
///
|
||||||
|
/// @param userId 用户 ID
|
||||||
|
/// @return 权限编码列表,格式为 MODULE:PERMISSION
|
||||||
|
default List<String> listAllPermissionCodeByUserId(String userId) {
|
||||||
|
return listAllPermissionByUserId(userId).stream()
|
||||||
|
.map(permission -> "%s:%s".formatted(permission.getModuleCode().name(), permission.getCode()))
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
/// 查询直属子角色
|
/// 查询直属子角色
|
||||||
///
|
///
|
||||||
@@ -33,10 +80,4 @@ public interface RoleService extends BaseService<Role, String> {
|
|||||||
/// @param roleId 角色 ID
|
/// @param roleId 角色 ID
|
||||||
/// @return 权限列表
|
/// @return 权限列表
|
||||||
List<Permission> listPermissionByRoleId(String roleId);
|
List<Permission> listPermissionByRoleId(String roleId);
|
||||||
|
|
||||||
/// 递归获取角色及其所有子角色的 ID 列表
|
|
||||||
///
|
|
||||||
/// @param idList 角色 ID 列表
|
|
||||||
/// @return 包含所有子角色的 ID 列表
|
|
||||||
List<String> listAllRoleIdIncludingChildren(Collection<String> idList);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.imyeyu.api.modules.user.service;
|
|||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
||||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||||
import com.imyeyu.spring.TimiSpring;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录服务
|
* 用户登录服务
|
||||||
@@ -28,11 +27,7 @@ public interface UserLoginService {
|
|||||||
*
|
*
|
||||||
* @return 用户
|
* @return 用户
|
||||||
*/
|
*/
|
||||||
default User getLoginUser() {
|
User getLoginUser();
|
||||||
return getLoginUser(TimiSpring.getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
User getLoginUser(String token);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据令牌获取必须有效登录的用户,否则抛出错误
|
* 根据令牌获取必须有效登录的用户,否则抛出错误
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
package com.imyeyu.api.modules.user.service;
|
package com.imyeyu.api.modules.user.service;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.modules.user.entity.Permission;
|
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
|
||||||
import com.imyeyu.api.modules.user.entity.UserRole;
|
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||||
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeRequest;
|
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/// 用户角色绑定服务
|
/// 用户角色绑定服务
|
||||||
///
|
///
|
||||||
@@ -22,62 +16,11 @@ public interface UserRoleService extends BaseService<UserRole, String> {
|
|||||||
/// @param list 用户角色绑定列表
|
/// @param list 用户角色绑定列表
|
||||||
void createBatch(List<UserRole> list);
|
void createBatch(List<UserRole> list);
|
||||||
|
|
||||||
/// 给用户授权角色
|
/// 查询用户角色绑定
|
||||||
///
|
///
|
||||||
/// @param req 用户角色授权请求
|
/// @param userId 用户 ID
|
||||||
void authorizeUserRole(UserRoleAuthorizeRequest req);
|
|
||||||
|
|
||||||
List<UserRole> listByUserId(String userId);
|
|
||||||
|
|
||||||
/// 查询多个用户角色绑定
|
|
||||||
///
|
|
||||||
/// @param userIdList 用户 ID 列表
|
|
||||||
/// @return 用户角色绑定列表
|
/// @return 用户角色绑定列表
|
||||||
List<UserRole> listByUserIdList(Collection<String> userIdList);
|
List<UserRole> listByUserId(String userId);
|
||||||
|
|
||||||
/// 查询用户直属角色
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 角色列表
|
|
||||||
List<Role> listRoleByUserId(String userId);
|
|
||||||
|
|
||||||
/// 查询用户指定模块直属角色
|
|
||||||
///
|
|
||||||
/// @param moduleCode 模块代码
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 角色列表
|
|
||||||
List<Role> listRoleByUserId(ModuleCode moduleCode, String userId);
|
|
||||||
|
|
||||||
/// 查询用户直属角色编码
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 角色编码列表,格式为 MODULE:ROLE
|
|
||||||
default List<String> listRoleCodeByUserId(String userId) {
|
|
||||||
return listRoleByUserId(userId).stream().map(role -> "%s:%s".formatted(role.getModuleCode().name(), role.getCode())).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 查询用户全部角色编码
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 包含子角色的角色编码列表,格式为 MODULE:ROLE
|
|
||||||
List<String> listAllRoleCodeByUserId(String userId);
|
|
||||||
|
|
||||||
/// 查询用户全部权限
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 权限列表
|
|
||||||
List<Permission> listAllPermissionByUserId(String userId);
|
|
||||||
|
|
||||||
/// 查询用户全部权限编码
|
|
||||||
///
|
|
||||||
/// @param userId 用户 ID
|
|
||||||
/// @return 权限编码列表,格式为 MODULE:PERMISSION
|
|
||||||
default List<String> listAllPermissionCodeByUserId(String userId) {
|
|
||||||
return listAllPermissionByUserId(userId).stream()
|
|
||||||
.map(permission -> "%s:%s".formatted(permission.getModuleCode().name(), permission.getCode()))
|
|
||||||
.distinct()
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 查询用户直属角色 ID
|
/// 查询用户直属角色 ID
|
||||||
///
|
///
|
||||||
@@ -88,12 +31,6 @@ public interface UserRoleService extends BaseService<UserRole, String> {
|
|||||||
return bindingList.stream().map(UserRole::getRoleId).toList();
|
return bindingList.stream().map(UserRole::getRoleId).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 按用户 ID 分组查询直属角色
|
|
||||||
///
|
|
||||||
/// @param idList 用户 ID 列表
|
|
||||||
/// @return 用户角色映射
|
|
||||||
Map<String, List<Role>> mapRoleListByUserIdList(Collection<String> idList);
|
|
||||||
|
|
||||||
/// 删除用户指定角色绑定
|
/// 删除用户指定角色绑定
|
||||||
///
|
///
|
||||||
/// @param userId 用户 ID
|
/// @param userId 用户 ID
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ package com.imyeyu.api.modules.user.service;
|
|||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.spring.service.BaseService;
|
import com.imyeyu.spring.service.BaseService;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户管理服务
|
* 用户管理服务
|
||||||
*
|
*
|
||||||
@@ -23,10 +20,4 @@ public interface UserService extends BaseService<User, String> {
|
|||||||
User getByPhoneNo(String phoneNo);
|
User getByPhoneNo(String phoneNo);
|
||||||
|
|
||||||
User getByVerifiedPhoneNo(String phoneNo);
|
User getByVerifiedPhoneNo(String phoneNo);
|
||||||
|
|
||||||
void verifyEmail(String id);
|
|
||||||
|
|
||||||
void verifyPhoneNo(String id);
|
|
||||||
|
|
||||||
Map<String, User> mapByIdList(Collection<String> idList);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -4,7 +4,6 @@ import com.imyeyu.api.bean.ModuleCode;
|
|||||||
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -26,7 +25,7 @@ import java.util.Set;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PermissionCheckerImplement implements PermissionChecker {
|
public class PermissionCheckerImplement implements PermissionChecker {
|
||||||
|
|
||||||
private final UserRoleService userRoleService;
|
private final RoleService roleService;
|
||||||
private final UserLoginService userLoginService;
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
public Set<String> codeSet() {
|
public Set<String> codeSet() {
|
||||||
@@ -35,7 +34,7 @@ public class PermissionCheckerImplement implements PermissionChecker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> codeSet(String userId) {
|
public Set<String> codeSet(String userId) {
|
||||||
return new HashSet<>(userRoleService.listAllPermissionCodeByUserId(userId));
|
return new HashSet<>(roleService.listAllPermissionCodeByUserId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@ package com.imyeyu.api.modules.user.service.implement;
|
|||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.modules.user.service.RoleChecker;
|
import com.imyeyu.api.modules.user.service.RoleChecker;
|
||||||
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -24,12 +24,12 @@ import java.util.Set;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoleCheckerImplement implements RoleChecker {
|
public class RoleCheckerImplement implements RoleChecker {
|
||||||
|
|
||||||
private final UserRoleService userRoleService;
|
private final RoleService roleService;
|
||||||
private final UserLoginService userLoginService;
|
private final UserLoginService userLoginService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> codeSet() {
|
public Set<String> codeSet() {
|
||||||
return new HashSet<>(userRoleService.listAllRoleCodeByUserId(userLoginService.getRequireLoginUserId()));
|
return new HashSet<>(roleService.listAllCodeByUserId(userLoginService.getRequireLoginUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+108
-7
@@ -2,17 +2,23 @@ package com.imyeyu.api.modules.user.service.implement;
|
|||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
import com.imyeyu.api.bean.ModuleCode;
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||||
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
||||||
|
import com.imyeyu.api.modules.common.mapper.MultilingualMapper;
|
||||||
import com.imyeyu.api.modules.common.service.MultilingualService;
|
import com.imyeyu.api.modules.common.service.MultilingualService;
|
||||||
import com.imyeyu.api.modules.user.entity.Permission;
|
import com.imyeyu.api.modules.user.entity.Permission;
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
import com.imyeyu.api.modules.user.entity.Role;
|
||||||
import com.imyeyu.api.modules.user.entity.RolePermission;
|
import com.imyeyu.api.modules.user.entity.RolePermission;
|
||||||
import com.imyeyu.api.modules.user.entity.RoleRelation;
|
import com.imyeyu.api.modules.user.entity.RoleRelation;
|
||||||
|
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||||
import com.imyeyu.api.modules.user.mapper.RoleMapper;
|
import com.imyeyu.api.modules.user.mapper.RoleMapper;
|
||||||
import com.imyeyu.api.modules.user.mapper.RolePermissionMapper;
|
import com.imyeyu.api.modules.user.mapper.RolePermissionMapper;
|
||||||
import com.imyeyu.api.modules.user.mapper.RoleRelationMapper;
|
import com.imyeyu.api.modules.user.mapper.RoleRelationMapper;
|
||||||
import com.imyeyu.api.modules.user.service.PermissionService;
|
import com.imyeyu.api.modules.user.service.PermissionService;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
|
import com.imyeyu.api.modules.user.service.UserRoleService;
|
||||||
|
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeReq;
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
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.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
@@ -22,7 +28,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -37,7 +42,9 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoleServiceImplement extends AbstractEntityService<Role, String> implements RoleService {
|
public class RoleServiceImplement extends AbstractEntityService<Role, String> implements RoleService {
|
||||||
|
|
||||||
|
private final UserRoleService userRoleService;
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
|
private final MultilingualMapper multilingualMapper;
|
||||||
private final MultilingualService multilingualService;
|
private final MultilingualService multilingualService;
|
||||||
|
|
||||||
private final RoleMapper mapper;
|
private final RoleMapper mapper;
|
||||||
@@ -146,6 +153,67 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
|
@Override
|
||||||
|
public void authorizeUserRole(UserRoleAuthorizeReq req) {
|
||||||
|
TimiException.required(req, "not found req");
|
||||||
|
TimiException.required(req.getUserId(), "not found req.userId");
|
||||||
|
if (req.getModuleCode() == null) {
|
||||||
|
throw new TimiException(TimiCode.ARG_MISS, "moduleCode");
|
||||||
|
}
|
||||||
|
List<UserRole> bindingList = userRoleService.listByUserId(req.getUserId());
|
||||||
|
List<String> bindingRoleIdList = bindingList.stream().map(UserRole::getRoleId).toList();
|
||||||
|
Set<String> dbIdSet = mapper.selectByIdList(bindingRoleIdList).stream()
|
||||||
|
.filter(role -> req.getModuleCode() == role.getModuleCode())
|
||||||
|
.map(Role::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Set<String> newIdSet = new HashSet<>();
|
||||||
|
if (TimiJava.isNotEmpty(req.getRoleIdList())) {
|
||||||
|
newIdSet.addAll(mapper.selectByIdList(req.getRoleIdList()).stream()
|
||||||
|
.filter(role -> req.getModuleCode() == role.getModuleCode())
|
||||||
|
.map(Role::getId)
|
||||||
|
.toList());
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(req.getRoleCodeList())) {
|
||||||
|
newIdSet.addAll(mapper.selectByModuleCodeAndCodeList(req.getModuleCode(), req.getRoleCodeList()).stream().map(Role::getId).toList());
|
||||||
|
}
|
||||||
|
Set<String> deleteIdList = new HashSet<>(dbIdSet);
|
||||||
|
deleteIdList.removeAll(newIdSet);
|
||||||
|
|
||||||
|
Set<String> addIdList = new HashSet<>(newIdSet);
|
||||||
|
addIdList.removeAll(dbIdSet);
|
||||||
|
|
||||||
|
if (TimiJava.isNotEmpty(deleteIdList)) {
|
||||||
|
userRoleService.deleteByRoleIdList(req.getUserId(), new ArrayList<>(deleteIdList));
|
||||||
|
}
|
||||||
|
if (TimiJava.isNotEmpty(addIdList)) {
|
||||||
|
List<UserRole> roleBindingList = new ArrayList<>();
|
||||||
|
long now = Time.now();
|
||||||
|
for (String roleId : addIdList) {
|
||||||
|
UserRole roleBinding = new UserRole();
|
||||||
|
roleBinding.setId(UUID.randomUUID().toString());
|
||||||
|
roleBinding.setUserId(req.getUserId());
|
||||||
|
roleBinding.setRoleId(roleId);
|
||||||
|
roleBinding.setCreatedAt(now);
|
||||||
|
roleBindingList.add(roleBinding);
|
||||||
|
}
|
||||||
|
userRoleService.createBatch(roleBindingList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Role> listByUserId(String userId) {
|
||||||
|
return mapper.selectByIdList(userRoleService.listRoleIdByUserId(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Role> listByUserId(String userId, ModuleCode moduleCode) {
|
||||||
|
TimiException.required(moduleCode, "not found moduleCode");
|
||||||
|
return listByUserId(userId).stream()
|
||||||
|
.filter(role -> moduleCode == role.getModuleCode())
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> listByModuleCode(ModuleCode moduleCode) {
|
public List<Role> listByModuleCode(ModuleCode moduleCode) {
|
||||||
TimiException.required(moduleCode, "not found moduleCode");
|
TimiException.required(moduleCode, "not found moduleCode");
|
||||||
@@ -153,8 +221,20 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> listByIdList(Collection<String> idList) {
|
public List<String> listAllCodeByUserId(String userId) {
|
||||||
return mapper.selectByIdList(new HashSet<>(idList));
|
List<String> roleIdList = listByUserId(userId).stream().map(Role::getId).toList();
|
||||||
|
List<String> allRoleIdList = getAllRoleIdsIncludingChildren(roleIdList);
|
||||||
|
if (TimiJava.isEmpty(allRoleIdList)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
return mapper.selectByIdList(allRoleIdList).stream().map(role -> "%s:%s".formatted(role.getModuleCode().name(), role.getCode())).distinct().toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Permission> listAllPermissionByUserId(String userId) {
|
||||||
|
List<String> roleIdList = listByUserId(userId).stream().map(Role::getId).toList();
|
||||||
|
List<String> allRoleIdList = getAllRoleIdsIncludingChildren(roleIdList);
|
||||||
|
return permissionService.listByRoleId(allRoleIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,13 +248,20 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Permission> listPermissionByRoleId(String roleId) {
|
public List<Permission> listPermissionByRoleId(String roleId) {
|
||||||
List<String> allRoleIdList = listAllRoleIdIncludingChildren(List.of(roleId));
|
List<String> allRoleIdList = getAllRoleIdsIncludingChildren(List.of(roleId));
|
||||||
return permissionService.listByRoleId(allRoleIdList);
|
return permissionService.listByRoleId(allRoleIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> listAllRoleIdIncludingChildren(Collection<String> idList) {
|
/// 递归获取角色及其所有子角色的 ID 列表
|
||||||
Set<String> allRoleIdSet = new HashSet<>(idList);
|
///
|
||||||
List<String> currentLevelRoleIdList = new ArrayList<>(idList);
|
/// @param roleIdList 角色 ID 列表
|
||||||
|
/// @return 包含所有子角色的 ID 列表
|
||||||
|
private List<String> getAllRoleIdsIncludingChildren(List<String> roleIdList) {
|
||||||
|
if (TimiJava.isEmpty(roleIdList)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
Set<String> allRoleIdSet = new HashSet<>(roleIdList);
|
||||||
|
List<String> currentLevelRoleIdList = new ArrayList<>(roleIdList);
|
||||||
|
|
||||||
while (TimiJava.isNotEmpty(currentLevelRoleIdList)) {
|
while (TimiJava.isNotEmpty(currentLevelRoleIdList)) {
|
||||||
List<String> childRoleIdList = roleRelationMapper.selectChildRoleIdListByParentRoleIdList(currentLevelRoleIdList);
|
List<String> childRoleIdList = roleRelationMapper.selectChildRoleIdListByParentRoleIdList(currentLevelRoleIdList);
|
||||||
@@ -190,4 +277,18 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
|
|||||||
}
|
}
|
||||||
return new ArrayList<>(allRoleIdSet);
|
return new ArrayList<>(allRoleIdSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String saveNameMultilingual(String langId, String name) {
|
||||||
|
if (TimiJava.isEmpty(name)) {
|
||||||
|
return langId;
|
||||||
|
}
|
||||||
|
if (TimiJava.isEmpty(langId)) {
|
||||||
|
return multilingualService.create(name);
|
||||||
|
}
|
||||||
|
Multilingual multilingual = new Multilingual();
|
||||||
|
multilingual.setId(langId);
|
||||||
|
multilingual.setZhCN(name);
|
||||||
|
multilingualMapper.updateSelective(multilingual);
|
||||||
|
return langId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-13
@@ -9,7 +9,6 @@ import com.imyeyu.api.modules.user.bean.BootstrapData;
|
|||||||
import com.imyeyu.api.modules.user.entity.User;
|
import com.imyeyu.api.modules.user.entity.User;
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
import com.imyeyu.api.modules.user.service.RoleService;
|
||||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserService;
|
import com.imyeyu.api.modules.user.service.UserService;
|
||||||
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
||||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||||
@@ -26,8 +25,8 @@ import org.springframework.context.annotation.Lazy;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/// 用户登录服务实现
|
/// 用户登录服务实现
|
||||||
///
|
///
|
||||||
@@ -46,7 +45,6 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final SettingService settingService;
|
private final SettingService settingService;
|
||||||
private final UserRoleService userRoleService;
|
|
||||||
private final AttachmentService attachmentService;
|
private final AttachmentService attachmentService;
|
||||||
|
|
||||||
private final Redis<String, String> redisUserToken;
|
private final Redis<String, String> redisUserToken;
|
||||||
@@ -88,21 +86,16 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
|||||||
result.setUser(userService.get(userId));
|
result.setUser(userService.get(userId));
|
||||||
|
|
||||||
User user = result.getUser();
|
User user = result.getUser();
|
||||||
user.setLastLoginIP(TimiSpring.getRequestIP());
|
user.setPermissionList(roleService.listAllPermissionCodeByUserId(user.getId()));
|
||||||
user.setLastLoginAt(Time.now());
|
user.setRoleList(roleService.listAllCodeByUserId(user.getId()));
|
||||||
userService.update(user);
|
|
||||||
|
|
||||||
user.setPermissionList(userRoleService.listAllPermissionCodeByUserId(user.getId()));
|
|
||||||
user.setRoleList(userRoleService.listAllRoleCodeByUserId(user.getId()));
|
|
||||||
user.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.USER, user.getId()));
|
user.setAttachmentList(attachmentService.listByBizId(Attachment.BizType.USER, user.getId()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getLoginUser(String token) {
|
public User getLoginUser() {
|
||||||
if (TimiJava.isEmpty(token)) {
|
String token = TimiSpring.getToken();
|
||||||
return null;
|
TimiException.required(token, "not found token");
|
||||||
}
|
|
||||||
String userId = redisUserToken.get(getUserTokenKey(token));
|
String userId = redisUserToken.get(getUserTokenKey(token));
|
||||||
if (TimiJava.isEmpty(userId)) {
|
if (TimiJava.isEmpty(userId)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
-117
@@ -1,34 +1,14 @@
|
|||||||
package com.imyeyu.api.modules.user.service.implement;
|
package com.imyeyu.api.modules.user.service.implement;
|
||||||
|
|
||||||
import com.imyeyu.api.bean.ModuleCode;
|
|
||||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
|
||||||
import com.imyeyu.api.modules.user.entity.Permission;
|
|
||||||
import com.imyeyu.api.modules.user.entity.Role;
|
|
||||||
import com.imyeyu.api.modules.user.entity.UserRole;
|
import com.imyeyu.api.modules.user.entity.UserRole;
|
||||||
import com.imyeyu.api.modules.user.mapper.UserRoleMapper;
|
import com.imyeyu.api.modules.user.mapper.UserRoleMapper;
|
||||||
import com.imyeyu.api.modules.user.service.PermissionService;
|
|
||||||
import com.imyeyu.api.modules.user.service.RoleService;
|
|
||||||
import com.imyeyu.api.modules.user.service.UserRoleService;
|
import com.imyeyu.api.modules.user.service.UserRoleService;
|
||||||
import com.imyeyu.api.modules.user.vo.role.UserRoleAuthorizeRequest;
|
|
||||||
import com.imyeyu.java.TimiJava;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiCode;
|
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/// 用户角色服务实现
|
/// 用户角色服务实现
|
||||||
///
|
///
|
||||||
@@ -38,9 +18,6 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UserRoleServiceImplement extends AbstractEntityService<UserRole, String> implements UserRoleService {
|
public class UserRoleServiceImplement extends AbstractEntityService<UserRole, String> implements UserRoleService {
|
||||||
|
|
||||||
private final RoleService roleService;
|
|
||||||
private final PermissionService permissionService;
|
|
||||||
|
|
||||||
private final UserRoleMapper mapper;
|
private final UserRoleMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,49 +30,6 @@ public class UserRoleServiceImplement extends AbstractEntityService<UserRole, St
|
|||||||
mapper.createBatch(list);
|
mapper.createBatch(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
|
||||||
@Override
|
|
||||||
public void authorizeUserRole(UserRoleAuthorizeRequest req) {
|
|
||||||
TimiException.required(req, "not found req");
|
|
||||||
TimiException.required(req.getUserId(), "not found req.userId");
|
|
||||||
if (req.getModuleCode() == null) {
|
|
||||||
throw new TimiException(TimiCode.ARG_MISS, "moduleCode");
|
|
||||||
}
|
|
||||||
List<UserRole> bindingList = listByUserId(req.getUserId());
|
|
||||||
List<String> bindingRoleIdList = bindingList.stream().map(UserRole::getRoleId).toList();
|
|
||||||
Set<String> dbIdSet = roleService.listByIdList(bindingRoleIdList)
|
|
||||||
.stream()
|
|
||||||
.filter(role -> req.getModuleCode() == role.getModuleCode())
|
|
||||||
.map(Role::getId)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
Set<String> newIdSet = new HashSet<>();
|
|
||||||
if (TimiJava.isNotEmpty(req.getRoleIdList())) {
|
|
||||||
newIdSet.addAll(roleService.listByIdList(req.getRoleIdList()).stream().filter(role -> req.getModuleCode() == role.getModuleCode()).map(Role::getId).toList());
|
|
||||||
}
|
|
||||||
Set<String> deleteIdList = new HashSet<>(dbIdSet);
|
|
||||||
deleteIdList.removeAll(newIdSet);
|
|
||||||
|
|
||||||
Set<String> addIdList = new HashSet<>(newIdSet);
|
|
||||||
addIdList.removeAll(dbIdSet);
|
|
||||||
|
|
||||||
if (TimiJava.isNotEmpty(deleteIdList)) {
|
|
||||||
deleteByRoleIdList(req.getUserId(), new ArrayList<>(deleteIdList));
|
|
||||||
}
|
|
||||||
if (TimiJava.isNotEmpty(addIdList)) {
|
|
||||||
List<UserRole> roleBindingList = new ArrayList<>();
|
|
||||||
long now = Time.now();
|
|
||||||
for (String roleId : addIdList) {
|
|
||||||
UserRole roleBinding = new UserRole();
|
|
||||||
roleBinding.setId(UUID.randomUUID().toString());
|
|
||||||
roleBinding.setUserId(req.getUserId());
|
|
||||||
roleBinding.setRoleId(roleId);
|
|
||||||
roleBinding.setCreatedAt(now);
|
|
||||||
roleBindingList.add(roleBinding);
|
|
||||||
}
|
|
||||||
createBatch(roleBindingList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserRole> listByUserId(String userId) {
|
public List<UserRole> listByUserId(String userId) {
|
||||||
UserRole example = new UserRole();
|
UserRole example = new UserRole();
|
||||||
@@ -103,57 +37,6 @@ public class UserRoleServiceImplement extends AbstractEntityService<UserRole, St
|
|||||||
return mapper.selectAllByExample(example);
|
return mapper.selectAllByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserRole> listByUserIdList(Collection<String> userIdList) {
|
|
||||||
return mapper.selectByUserIdList(userIdList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Role> listRoleByUserId(String userId) {
|
|
||||||
List<UserRole> userRoleList = listByUserId(userId);
|
|
||||||
return roleService.listByIdList(userRoleList.stream().map(UserRole::getRoleId).toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Role> listRoleByUserId(ModuleCode moduleCode, String userId) {
|
|
||||||
TimiException.required(moduleCode, "not found moduleCode");
|
|
||||||
return listRoleByUserId(userId).stream().filter(role -> moduleCode == role.getModuleCode()).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> listAllRoleCodeByUserId(String userId) {
|
|
||||||
List<String> roleIdList = listRoleByUserId(userId).stream().map(Role::getId).toList();
|
|
||||||
List<String> allRoleIdList = roleService.listAllRoleIdIncludingChildren(roleIdList);
|
|
||||||
if (TimiJava.isEmpty(allRoleIdList)) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
return roleService.listByIdList(allRoleIdList).stream().map(role -> "%s:%s".formatted(role.getModuleCode().name(), role.getCode())).distinct().toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Permission> listAllPermissionByUserId(String userId) {
|
|
||||||
List<String> roleIdList = listRoleByUserId(userId).stream().map(Role::getId).toList();
|
|
||||||
List<String> allRoleIdList = roleService.listAllRoleIdIncludingChildren(roleIdList);
|
|
||||||
return permissionService.listByRoleId(allRoleIdList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, List<Role>> mapRoleListByUserIdList(Collection<String> idList) {
|
|
||||||
if (TimiJava.isEmpty(idList)) {
|
|
||||||
return Map.of();
|
|
||||||
}
|
|
||||||
List<UserRole> userRoleList = listByUserIdList(idList);
|
|
||||||
if (TimiJava.isEmpty(userRoleList)) {
|
|
||||||
return Map.of();
|
|
||||||
}
|
|
||||||
Map<String, Role> roleMap = roleService.listByIdList(userRoleList.stream().map(UserRole::getRoleId).distinct().toList())
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toMap(Role::getId, Function.identity()));
|
|
||||||
return userRoleList.stream()
|
|
||||||
.filter(userRole -> roleMap.containsKey(userRole.getRoleId()))
|
|
||||||
.collect(Collectors.groupingBy(UserRole::getUserId, Collectors.mapping(userRole -> roleMap.get(userRole.getRoleId()), Collectors.toList())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteByRoleIdList(String userId, List<String> roleIdList) {
|
public void deleteByRoleIdList(String userId, List<String> roleIdList) {
|
||||||
mapper.deleteByRoleIdList(userId, roleIdList);
|
mapper.deleteByRoleIdList(userId, roleIdList);
|
||||||
|
|||||||
+7
-26
@@ -11,18 +11,11 @@ import com.imyeyu.spring.mapper.BaseMapper;
|
|||||||
import com.imyeyu.spring.service.AbstractEntityService;
|
import com.imyeyu.spring.service.AbstractEntityService;
|
||||||
import com.imyeyu.utils.Digest;
|
import com.imyeyu.utils.Digest;
|
||||||
import com.imyeyu.utils.Regex;
|
import com.imyeyu.utils.Regex;
|
||||||
import com.imyeyu.utils.Time;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户管理服务实现
|
* 用户管理服务实现
|
||||||
*
|
*
|
||||||
@@ -34,6 +27,8 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
||||||
public class UserServiceImplement extends AbstractEntityService<User, String> implements UserService, TimiJava {
|
public class UserServiceImplement extends AbstractEntityService<User, String> implements UserService, TimiJava {
|
||||||
|
|
||||||
|
private static final String REGEX_PHONE_NO = "^1\\d{10}$";
|
||||||
|
|
||||||
private final UserMapper mapper;
|
private final UserMapper mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,7 +51,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
if (TimiJava.isNotEmpty(user.getPhoneNo())) {
|
if (TimiJava.isNotEmpty(user.getPhoneNo())) {
|
||||||
TimiException.requiredTrue(user.isValidPhone(), "invalid phone");
|
validatePhoneNo(user.getPhoneNo());
|
||||||
User byPhoneNo = getByVerifiedPhoneNo(user.getPhoneNo());
|
User byPhoneNo = getByVerifiedPhoneNo(user.getPhoneNo());
|
||||||
TimiException.requiredNull(byPhoneNo, "existed phone number");
|
TimiException.requiredNull(byPhoneNo, "existed phone number");
|
||||||
}
|
}
|
||||||
@@ -70,6 +65,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
|||||||
dbUser.setPassword(Digest.argon2id(user.getPassword()));
|
dbUser.setPassword(Digest.argon2id(user.getPassword()));
|
||||||
dbUser.setEmail(user.getEmail());
|
dbUser.setEmail(user.getEmail());
|
||||||
dbUser.setPhoneNo(user.getPhoneNo());
|
dbUser.setPhoneNo(user.getPhoneNo());
|
||||||
|
dbUser.setPhoneNoVerifyAt(user.getPhoneNoVerifyAt());
|
||||||
dbUser.setExp(TimiJava.defaultIfNull(user.getExp(), 0));
|
dbUser.setExp(TimiJava.defaultIfNull(user.getExp(), 0));
|
||||||
super.create(dbUser);
|
super.create(dbUser);
|
||||||
user.setId(dbUser.getId());
|
user.setId(dbUser.getId());
|
||||||
@@ -92,7 +88,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
|||||||
TimiException.requiredTrue(byEmail == null || byEmail.getId().equals(dbUser.getId()), "existed email");
|
TimiException.requiredTrue(byEmail == null || byEmail.getId().equals(dbUser.getId()), "existed email");
|
||||||
}
|
}
|
||||||
if (TimiJava.isNotEmpty(phoneNo)) {
|
if (TimiJava.isNotEmpty(phoneNo)) {
|
||||||
TimiException.requiredTrue(user.isValidPhone(), "invalid phone");
|
validatePhoneNo(phoneNo);
|
||||||
if (!phoneNo.equals(dbUser.getPhoneNo())) {
|
if (!phoneNo.equals(dbUser.getPhoneNo())) {
|
||||||
User byPhoneNo = getByVerifiedPhoneNo(phoneNo);
|
User byPhoneNo = getByVerifiedPhoneNo(phoneNo);
|
||||||
TimiException.requiredTrue(byPhoneNo == null || byPhoneNo.getId().equals(dbUser.getId()), "existed phone number");
|
TimiException.requiredTrue(byPhoneNo == null || byPhoneNo.getId().equals(dbUser.getId()), "existed phone number");
|
||||||
@@ -142,22 +138,7 @@ public class UserServiceImplement extends AbstractEntityService<User, String> im
|
|||||||
return mapper.selectByVerifiedPhoneNo(phoneNo);
|
return mapper.selectByVerifiedPhoneNo(phoneNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void validatePhoneNo(String phoneNo) {
|
||||||
public void verifyEmail(String id) {
|
TimiException.requiredTrue(Regex.isMatch(REGEX_PHONE_NO, phoneNo), "invalid phone number");
|
||||||
User user = get(id);
|
|
||||||
user.setEmailVerifyAt(Time.now());
|
|
||||||
update(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void verifyPhoneNo(String id) {
|
|
||||||
User user = get(id);
|
|
||||||
user.setPhoneNoVerifyAt(Time.now());
|
|
||||||
update(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, User> mapByIdList(Collection<String> idList) {
|
|
||||||
return mapper.listByIdList(new HashSet<>(idList)).stream().collect(Collectors.toMap(User::getId, Function.identity()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -10,11 +10,13 @@ import java.util.List;
|
|||||||
/// @author 夜雨
|
/// @author 夜雨
|
||||||
/// @since 2026-07-17 14:16
|
/// @since 2026-07-17 14:16
|
||||||
@Data
|
@Data
|
||||||
public class UserRoleAuthorizeRequest {
|
public class UserRoleAuthorizeReq {
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
private ModuleCode moduleCode;
|
private ModuleCode moduleCode;
|
||||||
|
|
||||||
private List<String> roleIdList;
|
private List<String> roleIdList;
|
||||||
|
|
||||||
|
private List<String> roleCodeList;
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user