初始化项目
This commit is contained in:
commit
60c416e553
79 files changed
+5609
No files matched your search
+170
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.18</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.bycrm</groupId>
|
||||
<artifactId>by-crm-backend</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>BY-CRM Backend</name>
|
||||
<description>经销商管理系统后端服务</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<mybatis-spring-boot.version>2.3.1</mybatis-spring-boot.version>
|
||||
<druid.version>1.2.20</druid.version>
|
||||
<jwt.version>0.11.5</jwt.version>
|
||||
<swagger.version>3.0.0</swagger.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<hutool.version>5.8.23</hutool.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Validation -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis-spring-boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL Driver -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Druid 数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache Commons Lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hutool 工具类 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SpotBugs (静态代码检查) -->
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<version>4.7.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- SpotBugs 插件 -->
|
||||
<plugin>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-maven-plugin</artifactId>
|
||||
<version>4.7.3.6</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs</artifactId>
|
||||
<version>4.7.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- Checkstyle 插件 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
<encoding>UTF-8</encoding>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<failsOnError>false</failsOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.bycrm;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 经销商管理系统主启动类
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class ByCrmApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ByCrmApplication.class, args);
|
||||
System.out.println("\n========================================");
|
||||
System.out.println("经销商管理系统启动成功!");
|
||||
System.out.println("Swagger文档地址: http://localhost:8080/api/swagger-ui/index.html");
|
||||
System.out.println("========================================\n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.bycrm.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 需要认证的注解
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AuthRequired {
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.bycrm.common;
|
||||
|
||||
/**
|
||||
* 系统常量
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
/**
|
||||
* JWT Token 前缀
|
||||
*/
|
||||
public static final String TOKEN_PREFIX = "Bearer ";
|
||||
|
||||
/**
|
||||
* JWT Token Header
|
||||
*/
|
||||
public static final String TOKEN_HEADER = "Authorization";
|
||||
|
||||
/**
|
||||
* 用户信息在 Redis 中的前缀
|
||||
*/
|
||||
public static final String USER_TOKEN_PREFIX = "user:token:";
|
||||
|
||||
/**
|
||||
* 客户状态 - 可报备
|
||||
*/
|
||||
public static final Integer CUSTOMER_STATUS_AVAILABLE = 0;
|
||||
|
||||
/**
|
||||
* 客户状态 - 保护中
|
||||
*/
|
||||
public static final Integer CUSTOMER_STATUS_PROTECTED = 1;
|
||||
|
||||
/**
|
||||
* 客户状态 - 已失效
|
||||
*/
|
||||
public static final Integer CUSTOMER_STATUS_EXPIRED = 2;
|
||||
|
||||
/**
|
||||
* 报备状态 - 待审核
|
||||
*/
|
||||
public static final Integer REPORT_STATUS_PENDING = 0;
|
||||
|
||||
/**
|
||||
* 报备状态 - 已通过
|
||||
*/
|
||||
public static final Integer REPORT_STATUS_APPROVED = 1;
|
||||
|
||||
/**
|
||||
* 报备状态 - 已驳回
|
||||
*/
|
||||
public static final Integer REPORT_STATUS_REJECTED = 2;
|
||||
|
||||
/**
|
||||
* 报备状态 - 已失效
|
||||
*/
|
||||
public static final Integer REPORT_STATUS_EXPIRED = 3;
|
||||
|
||||
/**
|
||||
* 用户角色 - 管理员
|
||||
*/
|
||||
public static final Integer USER_ROLE_ADMIN = 0;
|
||||
|
||||
/**
|
||||
* 用户角色 - 经销商用户
|
||||
*/
|
||||
public static final Integer USER_ROLE_DEALER = 1;
|
||||
|
||||
/**
|
||||
* 用户状态 - 禁用
|
||||
*/
|
||||
public static final Integer USER_STATUS_DISABLED = 0;
|
||||
|
||||
/**
|
||||
* 用户状态 - 启用
|
||||
*/
|
||||
public static final Integer USER_STATUS_ENABLED = 1;
|
||||
|
||||
/**
|
||||
* 经销商状态 - 禁用
|
||||
*/
|
||||
public static final Integer DEALER_STATUS_DISABLED = 0;
|
||||
|
||||
/**
|
||||
* 经销商状态 - 启用
|
||||
*/
|
||||
public static final Integer DEALER_STATUS_ENABLED = 1;
|
||||
|
||||
/**
|
||||
* 默认保护期天数
|
||||
*/
|
||||
public static final Integer DEFAULT_PROTECT_DAYS = 90;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.bycrm.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页结果
|
||||
*/
|
||||
@Data
|
||||
public class PageResult<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private Long total;
|
||||
|
||||
/**
|
||||
* 当前页数据
|
||||
*/
|
||||
private List<T> records;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
private Long current;
|
||||
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Long size;
|
||||
|
||||
/**
|
||||
* 总页数
|
||||
*/
|
||||
private Long pages;
|
||||
|
||||
public PageResult() {
|
||||
}
|
||||
|
||||
public PageResult(Long total, List<T> records, Long current, Long size) {
|
||||
this.total = total;
|
||||
this.records = records;
|
||||
this.current = current;
|
||||
this.size = size;
|
||||
this.pages = (total + size - 1) / size;
|
||||
}
|
||||
|
||||
public static <T> PageResult<T> of(Long total, List<T> records, Long current, Long size) {
|
||||
return new PageResult<>(total, records, current, size);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.bycrm.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 统一响应结果
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 响应消息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 响应数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp;
|
||||
|
||||
public Result() {
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Result(Integer code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功返回(无数据)
|
||||
*/
|
||||
public static <T> Result<T> success() {
|
||||
return new Result<>(200, "操作成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功返回(有数据)
|
||||
*/
|
||||
public static <T> Result<T> success(T data) {
|
||||
return new Result<>(200, "操作成功", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功返回(自定义消息)
|
||||
*/
|
||||
public static <T> Result<T> success(String message, T data) {
|
||||
return new Result<>(200, message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回
|
||||
*/
|
||||
public static <T> Result<T> error(String message) {
|
||||
return new Result<>(500, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回(自定义状态码)
|
||||
*/
|
||||
public static <T> Result<T> error(Integer code, String message) {
|
||||
return new Result<>(code, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 未授权返回
|
||||
*/
|
||||
public static <T> Result<T> unauthorized(String message) {
|
||||
return new Result<>(401, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁止访问返回
|
||||
*/
|
||||
public static <T> Result<T> forbidden(String message) {
|
||||
return new Result<>(403, message, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.bycrm.config;
|
||||
|
||||
import com.bycrm.common.Constants;
|
||||
import com.bycrm.util.JwtUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 认证拦截器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AuthInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
public AuthInterceptor(JwtUtil jwtUtil) {
|
||||
this.jwtUtil = jwtUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
// 设置当前用户ID到请求属性中
|
||||
String token = getTokenFromRequest(request);
|
||||
|
||||
if (token != null && jwtUtil.validateToken(token)) {
|
||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||
request.setAttribute("currentUserId", userId);
|
||||
request.setAttribute("currentUserRole", jwtUtil.getRoleFromToken(token));
|
||||
request.setAttribute("currentUserDealerId", jwtUtil.getDealerIdFromToken(token));
|
||||
return true;
|
||||
}
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"未授权,请先登录\"}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求中获取 Token
|
||||
*/
|
||||
private String getTokenFromRequest(HttpServletRequest request) {
|
||||
String bearerToken = request.getHeader(Constants.TOKEN_HEADER);
|
||||
if (bearerToken != null && bearerToken.startsWith(Constants.TOKEN_PREFIX)) {
|
||||
return bearerToken.substring(Constants.TOKEN_PREFIX.length());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.bycrm.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.bycrm.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MyBatis 配置
|
||||
*/
|
||||
@Configuration
|
||||
public class MyBatisConfig {
|
||||
|
||||
// MyBatis 配置主要通过 application.yml 配置
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.bycrm.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
/**
|
||||
* Swagger 配置
|
||||
*/
|
||||
@Configuration
|
||||
@EnableOpenApi
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.OAS_30)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.bycrm.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("经销商管理系统 API 文档")
|
||||
.description("经销商管理系统 RESTful API 接口文档")
|
||||
.contact(new Contact("BY CRM", "", ""))
|
||||
.version("1.0.0")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.bycrm.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Web MVC 配置
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
private final AuthInterceptor authInterceptor;
|
||||
|
||||
public WebMvcConfig(AuthInterceptor authInterceptor) {
|
||||
this.authInterceptor = authInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(Arrays.asList(
|
||||
"/auth/login",
|
||||
"/swagger-ui/**",
|
||||
"/swagger-resources/**",
|
||||
"/v3/api-docs/**",
|
||||
"/webjars/**",
|
||||
"/error",
|
||||
"/druid/**"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.bycrm.controller;
|
||||
|
||||
import com.bycrm.common.Result;
|
||||
import com.bycrm.dto.LoginDTO;
|
||||
import com.bycrm.service.UserService;
|
||||
import com.bycrm.vo.UserInfoVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 认证控制器
|
||||
*/
|
||||
@Api(tags = "认证管理")
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public AuthController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
@ApiOperation("用户登录")
|
||||
@PostMapping("/login")
|
||||
public Result<LoginResponse> login(@RequestBody LoginDTO loginDTO) {
|
||||
String token = userService.login(loginDTO);
|
||||
return Result.success(new LoginResponse(token));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
*/
|
||||
@ApiOperation("获取当前用户信息")
|
||||
@GetMapping("/user/info")
|
||||
public Result<UserInfoVO> getCurrentUser(HttpServletRequest request) {
|
||||
String token = getTokenFromRequest(request);
|
||||
UserInfoVO user = userService.getCurrentUser(token);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户退出
|
||||
*/
|
||||
@ApiOperation("用户退出")
|
||||
@PostMapping("/logout")
|
||||
public Result<Void> logout() {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求中获取 Token
|
||||
*/
|
||||
private String getTokenFromRequest(HttpServletRequest request) {
|
||||
String authorization = request.getHeader("Authorization");
|
||||
if (authorization != null && authorization.startsWith("Bearer ")) {
|
||||
return authorization.substring(7);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录响应
|
||||
*/
|
||||
@lombok.Data
|
||||
static class LoginResponse {
|
||||
private String token;
|
||||
|
||||
public LoginResponse(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.bycrm.controller;
|
||||
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.common.Result;
|
||||
import com.bycrm.dto.CustomerDTO;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.entity.Customer;
|
||||
import com.bycrm.service.CustomerService;
|
||||
import com.bycrm.vo.CustomerVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户控制器
|
||||
*/
|
||||
@Api(tags = "客户管理")
|
||||
@RestController
|
||||
@RequestMapping("/customer")
|
||||
public class CustomerController {
|
||||
|
||||
private final CustomerService customerService;
|
||||
|
||||
public CustomerController(CustomerService customerService) {
|
||||
this.customerService = customerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询客户
|
||||
*/
|
||||
@ApiOperation("分页查询客户")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult<CustomerVO>> getCustomerPage(
|
||||
@ApiParam("当前页") @RequestParam(defaultValue = "1") Long current,
|
||||
@ApiParam("每页大小") @RequestParam(defaultValue = "10") Long size,
|
||||
@ApiParam("客户名称") @RequestParam(required = false) String name,
|
||||
@ApiParam("所属行业") @RequestParam(required = false) String industry,
|
||||
@ApiParam("状态") @RequestParam(required = false) Integer status) {
|
||||
PageQuery query = new PageQuery();
|
||||
query.setCurrent(current);
|
||||
query.setSize(size);
|
||||
|
||||
PageResult<CustomerVO> result = customerService.getCustomerPage(query, name, industry, status);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取客户详情
|
||||
*/
|
||||
@ApiOperation("根据ID获取客户详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<CustomerVO> getCustomerById(@ApiParam("客户ID") @PathVariable Long id) {
|
||||
CustomerVO customer = customerService.getCustomerById(id);
|
||||
return Result.success(customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客户
|
||||
*/
|
||||
@ApiOperation("创建客户")
|
||||
@PostMapping
|
||||
public Result<Customer> createCustomer(@RequestBody CustomerDTO customerDTO, HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
Customer customer = customerService.createCustomer(customerDTO, currentUserId);
|
||||
return Result.success(customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新客户
|
||||
*/
|
||||
@ApiOperation("更新客户")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Void> updateCustomer(
|
||||
@ApiParam("客户ID") @PathVariable Long id,
|
||||
@RequestBody CustomerDTO customerDTO,
|
||||
HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
customerService.updateCustomer(id, customerDTO, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*/
|
||||
@ApiOperation("删除客户")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteCustomer(@ApiParam("客户ID") @PathVariable Long id, HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
customerService.deleteCustomer(id, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称搜索客户(用于客户唯一性校验)
|
||||
*/
|
||||
@ApiOperation("根据名称搜索客户")
|
||||
@GetMapping("/search")
|
||||
public Result<List<Customer>> searchByName(@ApiParam("客户名称") @RequestParam String name) {
|
||||
List<Customer> customers = customerService.searchByName(name);
|
||||
return Result.success(customers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.bycrm.controller;
|
||||
|
||||
import com.bycrm.common.Result;
|
||||
import com.bycrm.dto.DealerDTO;
|
||||
import com.bycrm.entity.Dealer;
|
||||
import com.bycrm.service.DealerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 经销商控制器
|
||||
*/
|
||||
@Api(tags = "经销商管理")
|
||||
@RestController
|
||||
@RequestMapping("/dealer")
|
||||
public class DealerController {
|
||||
|
||||
private final DealerService dealerService;
|
||||
|
||||
public DealerController(DealerService dealerService) {
|
||||
this.dealerService = dealerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有经销商
|
||||
*/
|
||||
@ApiOperation("查询所有经销商")
|
||||
@GetMapping("/list")
|
||||
public Result<List<Dealer>> getDealerList(
|
||||
@ApiParam("经销商名称") @RequestParam(required = false) String name,
|
||||
@ApiParam("经销商编码") @RequestParam(required = false) String code,
|
||||
@ApiParam("状态") @RequestParam(required = false) Integer status) {
|
||||
List<Dealer> dealers = dealerService.getDealerList(name, code, status);
|
||||
return Result.success(dealers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取经销商
|
||||
*/
|
||||
@ApiOperation("根据ID获取经销商")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Dealer> getDealerById(@ApiParam("经销商ID") @PathVariable Long id) {
|
||||
Dealer dealer = dealerService.getDealerById(id);
|
||||
return Result.success(dealer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建经销商
|
||||
*/
|
||||
@ApiOperation("创建经销商")
|
||||
@PostMapping
|
||||
public Result<Void> createDealer(@RequestBody DealerDTO dealerDTO) {
|
||||
dealerService.createDealer(dealerDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新经销商
|
||||
*/
|
||||
@ApiOperation("更新经销商")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Void> updateDealer(
|
||||
@ApiParam("经销商ID") @PathVariable Long id,
|
||||
@RequestBody DealerDTO dealerDTO) {
|
||||
dealerService.updateDealer(id, dealerDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除经销商
|
||||
*/
|
||||
@ApiOperation("删除经销商")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteDealer(@ApiParam("经销商ID") @PathVariable Long id) {
|
||||
dealerService.deleteDealer(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.bycrm.controller;
|
||||
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.common.Result;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.dto.ReportAuditDTO;
|
||||
import com.bycrm.dto.ReportDTO;
|
||||
import com.bycrm.service.ReportService;
|
||||
import com.bycrm.vo.ReportVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 报备控制器
|
||||
*/
|
||||
@Api(tags = "报备管理")
|
||||
@RestController
|
||||
@RequestMapping("/report")
|
||||
public class ReportController {
|
||||
|
||||
private final ReportService reportService;
|
||||
|
||||
public ReportController(ReportService reportService) {
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询报备
|
||||
*/
|
||||
@ApiOperation("分页查询报备")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult<ReportVO>> getReportPage(
|
||||
@ApiParam("当前页") @RequestParam(defaultValue = "1") Long current,
|
||||
@ApiParam("每页大小") @RequestParam(defaultValue = "10") Long size,
|
||||
@ApiParam("经销商ID") @RequestParam(required = false) Long dealerId,
|
||||
@ApiParam("经销商名称") @RequestParam(required = false) String dealerName,
|
||||
@ApiParam("客户名称") @RequestParam(required = false) String customerName,
|
||||
@ApiParam("状态") @RequestParam(required = false) Integer status,
|
||||
HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
|
||||
PageQuery query = new PageQuery();
|
||||
query.setCurrent(current);
|
||||
query.setSize(size);
|
||||
|
||||
PageResult<ReportVO> result = reportService.getReportPage(query, dealerId, dealerName, customerName, status, currentUserId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取报备详情
|
||||
*/
|
||||
@ApiOperation("根据ID获取报备详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<ReportVO> getReportById(@ApiParam("报备ID") @PathVariable Long id) {
|
||||
ReportVO report = reportService.getReportById(id);
|
||||
return Result.success(report);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建报备
|
||||
*/
|
||||
@ApiOperation("创建报备")
|
||||
@PostMapping
|
||||
public Result<Void> createReport(@RequestBody ReportDTO reportDTO, HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
reportService.createReport(reportDTO, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核报备
|
||||
*/
|
||||
@ApiOperation("审核报备")
|
||||
@PutMapping("/{id}/audit")
|
||||
public Result<Void> auditReport(
|
||||
@ApiParam("报备ID") @PathVariable Long id,
|
||||
@RequestBody ReportAuditDTO auditDTO,
|
||||
HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
reportService.auditReport(id, auditDTO, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回报备
|
||||
*/
|
||||
@ApiOperation("撤回报备")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> withdrawReport(@ApiParam("报备ID") @PathVariable Long id, HttpServletRequest request) {
|
||||
Long currentUserId = (Long) request.getAttribute("currentUserId");
|
||||
reportService.withdrawReport(id, currentUserId);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 客户请求 DTO
|
||||
*/
|
||||
@Data
|
||||
public class CustomerDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
@NotBlank(message = "客户名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 所属行业
|
||||
*/
|
||||
private String industry;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 经销商请求 DTO
|
||||
*/
|
||||
@Data
|
||||
public class DealerDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 经销商名称
|
||||
*/
|
||||
@NotBlank(message = "经销商名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 经销商编码
|
||||
*/
|
||||
@NotBlank(message = "经销商编码不能为空")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
@NotBlank(message = "联系人不能为空")
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@NotBlank(message = "联系电话不能为空")
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 登录请求 DTO
|
||||
*/
|
||||
@Data
|
||||
public class LoginDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 分页查询基类
|
||||
*/
|
||||
@Data
|
||||
public class PageQuery implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
private Long current = 1L;
|
||||
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Long size = 10L;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String orderBy;
|
||||
|
||||
/**
|
||||
* 排序方式:asc/desc
|
||||
*/
|
||||
private String orderDirection = "desc";
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 报备审核 DTO
|
||||
*/
|
||||
@Data
|
||||
public class ReportAuditDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 报备ID
|
||||
*/
|
||||
@NotNull(message = "报备ID不能为空")
|
||||
private Long reportId;
|
||||
|
||||
/**
|
||||
* 是否通过
|
||||
*/
|
||||
@NotNull(message = "审核结果不能为空")
|
||||
private Boolean approved;
|
||||
|
||||
/**
|
||||
* 驳回原因
|
||||
*/
|
||||
private String rejectReason;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.bycrm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 报备请求 DTO
|
||||
*/
|
||||
@Data
|
||||
public class ReportDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
@NotNull(message = "客户ID不能为空")
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 报备说明
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客户实体
|
||||
*/
|
||||
@Data
|
||||
public class Customer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 所属行业
|
||||
*/
|
||||
private String industry;
|
||||
|
||||
/**
|
||||
* 状态:0-可报备 1-保护中 2-已失效
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 经销商实体
|
||||
*/
|
||||
@Data
|
||||
public class Dealer implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 经销商ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 经销商名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 经销商编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 状态:0-禁用 1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据字典实体
|
||||
*/
|
||||
@Data
|
||||
public class Dict implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
private String dictCode;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dictName;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 字典项列表(不存储在数据库中)
|
||||
*/
|
||||
private transient List<DictItem> items;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 数据字典项实体
|
||||
*/
|
||||
@Data
|
||||
public class DictItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 字典项ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
* 字典项标签
|
||||
*/
|
||||
private String itemLabel;
|
||||
|
||||
/**
|
||||
* 字典项值
|
||||
*/
|
||||
private String itemValue;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 操作日志实体
|
||||
*/
|
||||
@Data
|
||||
public class OperationLog implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 日志ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名(不存储在数据库中)
|
||||
*/
|
||||
private transient String username;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 操作类型
|
||||
*/
|
||||
private String operation;
|
||||
|
||||
/**
|
||||
* 操作描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 报备实体
|
||||
*/
|
||||
@Data
|
||||
public class Report implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 报备ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 经销商ID
|
||||
*/
|
||||
private Long dealerId;
|
||||
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 报备说明
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态:0-待审核 1-已通过 2-已驳回 3-已失效
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 驳回原因
|
||||
*/
|
||||
private String rejectReason;
|
||||
|
||||
/**
|
||||
* 保护期开始时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime protectStartDate;
|
||||
|
||||
/**
|
||||
* 保护期结束时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime protectEndDate;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 关联查询字段 - 经销商名称
|
||||
*/
|
||||
private String dealerName;
|
||||
|
||||
/**
|
||||
* 关联查询字段 - 客户名称
|
||||
*/
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 关联查询字段 - 客户电话
|
||||
*/
|
||||
private String customerPhone;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.bycrm.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户实体
|
||||
*/
|
||||
@Data
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码(BCrypt加密)
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 关联经销商ID(管理员为NULL)
|
||||
*/
|
||||
private Long dealerId;
|
||||
|
||||
/**
|
||||
* 角色:0-管理员 1-经销商用户
|
||||
*/
|
||||
private Integer role;
|
||||
|
||||
/**
|
||||
* 状态:0-禁用 1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 关联查询字段 - 经销商名称
|
||||
*/
|
||||
private String dealerName;
|
||||
|
||||
/**
|
||||
* Token(不存储在数据库中,仅用于返回)
|
||||
*/
|
||||
private transient String token;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.bycrm.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*/
|
||||
@Getter
|
||||
public class BusinessException extends RuntimeException {
|
||||
|
||||
private final Integer code;
|
||||
|
||||
public BusinessException(String message) {
|
||||
super(message);
|
||||
this.code = 500;
|
||||
}
|
||||
|
||||
public BusinessException(Integer code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public BusinessException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = 500;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.bycrm.exception;
|
||||
|
||||
import com.bycrm.common.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*/
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public Result<Void> handleBusinessException(BusinessException e) {
|
||||
log.error("业务异常:{}", e.getMessage());
|
||||
return Result.error(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验异常
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public Result<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||
String message = e.getBindingResult().getFieldErrors().stream()
|
||||
.map(FieldError::getDefaultMessage)
|
||||
.collect(Collectors.joining(", "));
|
||||
log.error("参数校验异常:{}", message);
|
||||
return Result.error(400, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 约束违反异常
|
||||
*/
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
public Result<Void> handleConstraintViolationException(ConstraintViolationException e) {
|
||||
String message = e.getConstraintViolations().stream()
|
||||
.map(ConstraintViolation::getMessage)
|
||||
.collect(Collectors.joining(", "));
|
||||
log.error("约束违反异常:{}", message);
|
||||
return Result.error(400, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result<Void> handleException(Exception e) {
|
||||
log.error("系统异常", e);
|
||||
return Result.error("系统异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.bycrm.mapper;
|
||||
|
||||
import com.bycrm.entity.Customer;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomerMapper {
|
||||
|
||||
/**
|
||||
* 根据ID查询客户
|
||||
*/
|
||||
Customer selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询客户(用于客户唯一性校验)
|
||||
*/
|
||||
List<Customer> selectByNameLike(@Param("name") String name);
|
||||
|
||||
/**
|
||||
* 分页查询客户
|
||||
*/
|
||||
List<Customer> selectPage(@Param("query") PageQuery query, @Param("name") String name,
|
||||
@Param("industry") String industry, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 查询客户总数
|
||||
*/
|
||||
Long countPage(@Param("name") String name, @Param("industry") String industry, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 插入客户
|
||||
*/
|
||||
int insert(Customer customer);
|
||||
|
||||
/**
|
||||
* 更新客户
|
||||
*/
|
||||
int update(Customer customer);
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*/
|
||||
int deleteById(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.bycrm.mapper;
|
||||
|
||||
import com.bycrm.entity.Dealer;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 经销商 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DealerMapper {
|
||||
|
||||
/**
|
||||
* 根据ID查询经销商
|
||||
*/
|
||||
Dealer selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 根据编码查询经销商
|
||||
*/
|
||||
Dealer selectByCode(@Param("code") String code);
|
||||
|
||||
/**
|
||||
* 查询所有经销商
|
||||
*/
|
||||
List<Dealer> selectList(@Param("name") String name, @Param("code") String code, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 插入经销商
|
||||
*/
|
||||
int insert(Dealer dealer);
|
||||
|
||||
/**
|
||||
* 更新经销商
|
||||
*/
|
||||
int update(Dealer dealer);
|
||||
|
||||
/**
|
||||
* 删除经销商
|
||||
*/
|
||||
int deleteById(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.bycrm.mapper;
|
||||
|
||||
import com.bycrm.entity.Report;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报备 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ReportMapper {
|
||||
|
||||
/**
|
||||
* 根据ID查询报备(含关联信息)
|
||||
*/
|
||||
Report selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询客户的有效报备
|
||||
*/
|
||||
Report selectValidByCustomerId(@Param("customerId") Long customerId);
|
||||
|
||||
/**
|
||||
* 分页查询报备
|
||||
*/
|
||||
List<Report> selectPage(@Param("query") PageQuery query, @Param("dealerId") Long dealerId,
|
||||
@Param("dealerName") String dealerName, @Param("customerName") String customerName,
|
||||
@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 查询报备总数
|
||||
*/
|
||||
Long countPage(@Param("dealerId") Long dealerId, @Param("dealerName") String dealerName,
|
||||
@Param("customerName") String customerName, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 插入报备
|
||||
*/
|
||||
int insert(Report report);
|
||||
|
||||
/**
|
||||
* 更新报备
|
||||
*/
|
||||
int update(Report report);
|
||||
|
||||
/**
|
||||
* 删除报备
|
||||
*/
|
||||
int deleteById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询即将过期的报备(定时任务使用)
|
||||
*/
|
||||
List<Report> selectExpiringReports(@Param("endDate") String endDate);
|
||||
|
||||
/**
|
||||
* 批量更新报备状态为已失效
|
||||
*/
|
||||
int batchUpdateExpired(@Param("ids") List<Long> ids);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.bycrm.mapper;
|
||||
|
||||
import com.bycrm.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户
|
||||
*/
|
||||
User selectByUsername(@Param("username") String username);
|
||||
|
||||
/**
|
||||
* 根据ID查询用户
|
||||
*/
|
||||
User selectById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询所有用户
|
||||
*/
|
||||
List<User> selectList();
|
||||
|
||||
/**
|
||||
* 插入用户
|
||||
*/
|
||||
int insert(User user);
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*/
|
||||
int update(User user);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*/
|
||||
int deleteById(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.bycrm.service;
|
||||
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.dto.CustomerDTO;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.entity.Customer;
|
||||
import com.bycrm.vo.CustomerVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户服务接口
|
||||
*/
|
||||
public interface CustomerService {
|
||||
|
||||
/**
|
||||
* 分页查询客户
|
||||
*/
|
||||
PageResult<CustomerVO> getCustomerPage(PageQuery query, String name, String industry, Integer status);
|
||||
|
||||
/**
|
||||
* 根据 ID 获取客户详情
|
||||
*/
|
||||
CustomerVO getCustomerById(Long id);
|
||||
|
||||
/**
|
||||
* 创建客户
|
||||
*/
|
||||
Customer createCustomer(CustomerDTO customerDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 更新客户
|
||||
*/
|
||||
void updateCustomer(Long id, CustomerDTO customerDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*/
|
||||
void deleteCustomer(Long id, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 根据名称模糊查询客户(用于客户唯一性校验)
|
||||
*/
|
||||
List<Customer> searchByName(String name);
|
||||
|
||||
/**
|
||||
* 校验客户名称是否重复
|
||||
*/
|
||||
void checkCustomerNameDuplicate(String name);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.bycrm.service;
|
||||
|
||||
import com.bycrm.dto.DealerDTO;
|
||||
import com.bycrm.entity.Dealer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 经销商服务接口
|
||||
*/
|
||||
public interface DealerService {
|
||||
|
||||
/**
|
||||
* 查询所有经销商
|
||||
*/
|
||||
List<Dealer> getDealerList(String name, String code, Integer status);
|
||||
|
||||
/**
|
||||
* 根据 ID 获取经销商
|
||||
*/
|
||||
Dealer getDealerById(Long id);
|
||||
|
||||
/**
|
||||
* 创建经销商
|
||||
*/
|
||||
void createDealer(DealerDTO dealerDTO);
|
||||
|
||||
/**
|
||||
* 更新经销商
|
||||
*/
|
||||
void updateDealer(Long id, DealerDTO dealerDTO);
|
||||
|
||||
/**
|
||||
* 删除经销商
|
||||
*/
|
||||
void deleteDealer(Long id);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.bycrm.service;
|
||||
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.dto.ReportAuditDTO;
|
||||
import com.bycrm.dto.ReportDTO;
|
||||
import com.bycrm.vo.ReportVO;
|
||||
|
||||
/**
|
||||
* 报备服务接口
|
||||
*/
|
||||
public interface ReportService {
|
||||
|
||||
/**
|
||||
* 分页查询报备
|
||||
*/
|
||||
PageResult<ReportVO> getReportPage(PageQuery query, Long dealerId, String dealerName,
|
||||
String customerName, Integer status, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 根据 ID 获取报备详情
|
||||
*/
|
||||
ReportVO getReportById(Long id);
|
||||
|
||||
/**
|
||||
* 创建报备
|
||||
*/
|
||||
void createReport(ReportDTO reportDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 审核报备
|
||||
*/
|
||||
void auditReport(Long id, ReportAuditDTO auditDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 撤回报备
|
||||
*/
|
||||
void withdrawReport(Long id, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 处理过期报备(定时任务调用)
|
||||
*/
|
||||
void handleExpiredReports();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.bycrm.service;
|
||||
|
||||
import com.bycrm.dto.LoginDTO;
|
||||
import com.bycrm.entity.User;
|
||||
import com.bycrm.vo.UserInfoVO;
|
||||
|
||||
/**
|
||||
* 用户服务接口
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
String login(LoginDTO loginDTO);
|
||||
|
||||
/**
|
||||
* 根据 ID 获取用户信息
|
||||
*/
|
||||
User getUserById(Long id);
|
||||
|
||||
/**
|
||||
* 根据用户名获取用户信息
|
||||
*/
|
||||
User getUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
*/
|
||||
UserInfoVO getCurrentUser(String token);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.bycrm.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.bycrm.common.Constants;
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.dto.CustomerDTO;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.entity.Customer;
|
||||
import com.bycrm.entity.User;
|
||||
import com.bycrm.exception.BusinessException;
|
||||
import com.bycrm.mapper.CustomerMapper;
|
||||
import com.bycrm.mapper.UserMapper;
|
||||
import com.bycrm.service.CustomerService;
|
||||
import com.bycrm.vo.CustomerVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 客户服务实现
|
||||
*/
|
||||
@Service
|
||||
public class CustomerServiceImpl implements CustomerService {
|
||||
|
||||
private final CustomerMapper customerMapper;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
public CustomerServiceImpl(CustomerMapper customerMapper, UserMapper userMapper) {
|
||||
this.customerMapper = customerMapper;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CustomerVO> getCustomerPage(PageQuery query, String name, String industry, Integer status) {
|
||||
// 计算偏移量
|
||||
query.setOffset((query.getCurrent() - 1) * query.getSize());
|
||||
|
||||
List<Customer> customers = customerMapper.selectPage(query, name, industry, status);
|
||||
Long total = customerMapper.countPage(name, industry, status);
|
||||
|
||||
List<CustomerVO> voList = customers.stream().map(customer -> {
|
||||
CustomerVO vo = convertToVO(customer);
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return PageResult.of(total, voList, query.getCurrent(), query.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerVO getCustomerById(Long id) {
|
||||
Customer customer = customerMapper.selectById(id);
|
||||
if (customer == null) {
|
||||
throw new BusinessException("客户不存在");
|
||||
}
|
||||
return convertToVO(customer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Customer createCustomer(CustomerDTO customerDTO, Long currentUserId) {
|
||||
// 校验客户名称是否重复
|
||||
checkCustomerNameDuplicate(customerDTO.getName());
|
||||
|
||||
Customer customer = new Customer();
|
||||
BeanUtils.copyProperties(customerDTO, customer);
|
||||
customer.setStatus(Constants.CUSTOMER_STATUS_AVAILABLE);
|
||||
customer.setCreatedAt(LocalDateTime.now());
|
||||
customer.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
customerMapper.insert(customer);
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCustomer(Long id, CustomerDTO customerDTO, Long currentUserId) {
|
||||
Customer existingCustomer = customerMapper.selectById(id);
|
||||
if (existingCustomer == null) {
|
||||
throw new BusinessException("客户不存在");
|
||||
}
|
||||
|
||||
// 如果修改了名称,需要检查新名称是否与其他客户重复
|
||||
if (!existingCustomer.getName().equals(customerDTO.getName())) {
|
||||
checkCustomerNameDuplicate(customerDTO.getName());
|
||||
}
|
||||
|
||||
Customer customer = new Customer();
|
||||
BeanUtils.copyProperties(customerDTO, customer);
|
||||
customer.setId(id);
|
||||
customer.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
customerMapper.update(customer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCustomer(Long id, Long currentUserId) {
|
||||
Customer customer = customerMapper.selectById(id);
|
||||
if (customer == null) {
|
||||
throw new BusinessException("客户不存在");
|
||||
}
|
||||
|
||||
if (customer.getStatus() == Constants.CUSTOMER_STATUS_PROTECTED) {
|
||||
throw new BusinessException("客户处于保护期中,无法删除");
|
||||
}
|
||||
|
||||
customerMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Customer> searchByName(String name) {
|
||||
return customerMapper.selectByNameLike(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCustomerNameDuplicate(String name) {
|
||||
List<Customer> existingCustomers = customerMapper.selectByNameLike(name);
|
||||
if (existingCustomers.stream().anyMatch(c -> c.getName().equals(name))) {
|
||||
throw new BusinessException("客户名称已存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 VO
|
||||
*/
|
||||
private CustomerVO convertToVO(Customer customer) {
|
||||
CustomerVO vo = new CustomerVO();
|
||||
BeanUtils.copyProperties(customer, vo);
|
||||
|
||||
// 设置状态描述
|
||||
switch (customer.getStatus()) {
|
||||
case Constants.CUSTOMER_STATUS_AVAILABLE:
|
||||
vo.setStatusDesc("可报备");
|
||||
break;
|
||||
case Constants.CUSTOMER_STATUS_PROTECTED:
|
||||
vo.setStatusDesc("保护中");
|
||||
break;
|
||||
case Constants.CUSTOMER_STATUS_EXPIRED:
|
||||
vo.setStatusDesc("已失效");
|
||||
break;
|
||||
default:
|
||||
vo.setStatusDesc("未知");
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.bycrm.service.impl;
|
||||
|
||||
import com.bycrm.dto.DealerDTO;
|
||||
import com.bycrm.entity.Dealer;
|
||||
import com.bycrm.exception.BusinessException;
|
||||
import com.bycrm.mapper.DealerMapper;
|
||||
import com.bycrm.service.DealerService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 经销商服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DealerServiceImpl implements DealerService {
|
||||
|
||||
private final DealerMapper dealerMapper;
|
||||
|
||||
public DealerServiceImpl(DealerMapper dealerMapper) {
|
||||
this.dealerMapper = dealerMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dealer> getDealerList(String name, String code, Integer status) {
|
||||
return dealerMapper.selectList(name, code, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dealer getDealerById(Long id) {
|
||||
Dealer dealer = dealerMapper.selectById(id);
|
||||
if (dealer == null) {
|
||||
throw new BusinessException("经销商不存在");
|
||||
}
|
||||
return dealer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createDealer(DealerDTO dealerDTO) {
|
||||
// 检查编码是否重复
|
||||
Dealer existingDealer = dealerMapper.selectByCode(dealerDTO.getCode());
|
||||
if (existingDealer != null) {
|
||||
throw new BusinessException("经销商编码已存在");
|
||||
}
|
||||
|
||||
Dealer dealer = new Dealer();
|
||||
BeanUtils.copyProperties(dealerDTO, dealer);
|
||||
dealer.setCreatedAt(LocalDateTime.now());
|
||||
dealer.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
dealerMapper.insert(dealer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDealer(Long id, DealerDTO dealerDTO) {
|
||||
Dealer existingDealer = dealerMapper.selectById(id);
|
||||
if (existingDealer == null) {
|
||||
throw new BusinessException("经销商不存在");
|
||||
}
|
||||
|
||||
// 如果修改了编码,需要检查新编码是否与其他经销商重复
|
||||
if (!existingDealer.getCode().equals(dealerDTO.getCode())) {
|
||||
Dealer codeDealer = dealerMapper.selectByCode(dealerDTO.getCode());
|
||||
if (codeDealer != null && !codeDealer.getId().equals(id)) {
|
||||
throw new BusinessException("经销商编码已存在");
|
||||
}
|
||||
}
|
||||
|
||||
Dealer dealer = new Dealer();
|
||||
BeanUtils.copyProperties(dealerDTO, dealer);
|
||||
dealer.setId(id);
|
||||
dealer.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
dealerMapper.update(dealer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDealer(Long id) {
|
||||
Dealer dealer = dealerMapper.selectById(id);
|
||||
if (dealer == null) {
|
||||
throw new BusinessException("经销商不存在");
|
||||
}
|
||||
|
||||
dealerMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package com.bycrm.service.impl;
|
||||
|
||||
import com.bycrm.common.Constants;
|
||||
import com.bycrm.common.PageResult;
|
||||
import com.bycrm.dto.PageQuery;
|
||||
import com.bycrm.dto.ReportAuditDTO;
|
||||
import com.bycrm.dto.ReportDTO;
|
||||
import com.bycrm.entity.Report;
|
||||
import com.bycrm.entity.Customer;
|
||||
import com.bycrm.entity.User;
|
||||
import com.bycrm.exception.BusinessException;
|
||||
import com.bycrm.mapper.CustomerMapper;
|
||||
import com.bycrm.mapper.ReportMapper;
|
||||
import com.bycrm.mapper.UserMapper;
|
||||
import com.bycrm.service.ReportService;
|
||||
import com.bycrm.vo.ReportVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 报备服务实现
|
||||
*/
|
||||
@Service
|
||||
public class ReportServiceImpl implements ReportService {
|
||||
|
||||
private final ReportMapper reportMapper;
|
||||
private final CustomerMapper customerMapper;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Value("${crm.report.ttl-days:90}")
|
||||
private Integer protectDays;
|
||||
|
||||
@Value("${crm.report.allow-overlap:false}")
|
||||
private Boolean allowOverlap;
|
||||
|
||||
public ReportServiceImpl(ReportMapper reportMapper, CustomerMapper customerMapper, UserMapper userMapper) {
|
||||
this.reportMapper = reportMapper;
|
||||
this.customerMapper = customerMapper;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ReportVO> getReportPage(PageQuery query, Long dealerId, String dealerName,
|
||||
String customerName, Integer status, Long currentUserId) {
|
||||
// 获取当前用户
|
||||
User currentUser = userMapper.selectById(currentUserId);
|
||||
|
||||
// 如果是经销商用户,只能查看自己的报备
|
||||
if (currentUser.getRole() == Constants.USER_ROLE_DEALER) {
|
||||
dealerId = currentUser.getDealerId();
|
||||
}
|
||||
|
||||
// 计算偏移量
|
||||
query.setOffset((query.getCurrent() - 1) * query.getSize());
|
||||
|
||||
List<Report> reports = reportMapper.selectPage(query, dealerId, dealerName, customerName, status);
|
||||
Long total = reportMapper.countPage(dealerId, dealerName, customerName, status);
|
||||
|
||||
List<ReportVO> voList = reports.stream().map(this::convertToVO).collect(Collectors.toList());
|
||||
|
||||
return PageResult.of(total, voList, query.getCurrent(), query.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportVO getReportById(Long id) {
|
||||
Report report = reportMapper.selectById(id);
|
||||
if (report == null) {
|
||||
throw new BusinessException("报备不存在");
|
||||
}
|
||||
return convertToVO(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createReport(ReportDTO reportDTO, Long currentUserId) {
|
||||
// 获取当前用户
|
||||
User currentUser = userMapper.selectById(currentUserId);
|
||||
if (currentUser.getDealerId() == null) {
|
||||
throw new BusinessException("您未关联经销商,无法提交报备");
|
||||
}
|
||||
|
||||
// 检查客户是否存在
|
||||
Customer customer = customerMapper.selectById(reportDTO.getCustomerId());
|
||||
if (customer == null) {
|
||||
throw new BusinessException("客户不存在");
|
||||
}
|
||||
|
||||
// 防撞单校验:检查该客户是否已存在有效报备
|
||||
Report existingReport = reportMapper.selectValidByCustomerId(reportDTO.getCustomerId());
|
||||
if (existingReport != null && !allowOverlap) {
|
||||
throw new BusinessException("该客户已被其他经销商报备,无法重复报备");
|
||||
}
|
||||
|
||||
// 创建报备
|
||||
Report report = new Report();
|
||||
report.setDealerId(currentUser.getDealerId());
|
||||
report.setCustomerId(reportDTO.getCustomerId());
|
||||
report.setDescription(reportDTO.getDescription());
|
||||
report.setStatus(Constants.REPORT_STATUS_PENDING);
|
||||
report.setCreatedAt(LocalDateTime.now());
|
||||
report.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
reportMapper.insert(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void auditReport(Long id, ReportAuditDTO auditDTO, Long currentUserId) {
|
||||
// 获取当前用户
|
||||
User currentUser = userMapper.selectById(currentUserId);
|
||||
if (currentUser.getRole() != Constants.USER_ROLE_ADMIN) {
|
||||
throw new BusinessException("只有管理员才能审核报备");
|
||||
}
|
||||
|
||||
Report report = reportMapper.selectById(id);
|
||||
if (report == null) {
|
||||
throw new BusinessException("报备不存在");
|
||||
}
|
||||
|
||||
if (report.getStatus() != Constants.REPORT_STATUS_PENDING) {
|
||||
throw new BusinessException("该报备已被审核,无需重复操作");
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if (auditDTO.getApproved()) {
|
||||
// 审核通过
|
||||
report.setStatus(Constants.REPORT_STATUS_APPROVED);
|
||||
report.setProtectStartDate(now);
|
||||
report.setProtectEndDate(now.plusDays(protectDays));
|
||||
|
||||
// 更新客户状态为保护中
|
||||
Customer customer = customerMapper.selectById(report.getCustomerId());
|
||||
customer.setStatus(Constants.CUSTOMER_STATUS_PROTECTED);
|
||||
customerMapper.update(customer);
|
||||
} else {
|
||||
// 审核驳回
|
||||
report.setStatus(Constants.REPORT_STATUS_REJECTED);
|
||||
report.setRejectReason(auditDTO.getRejectReason());
|
||||
}
|
||||
|
||||
report.setUpdatedAt(now);
|
||||
reportMapper.update(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void withdrawReport(Long id, Long currentUserId) {
|
||||
User currentUser = userMapper.selectById(currentUserId);
|
||||
|
||||
Report report = reportMapper.selectById(id);
|
||||
if (report == null) {
|
||||
throw new BusinessException("报备不存在");
|
||||
}
|
||||
|
||||
// 只有报备提交者才能撤回
|
||||
if (!report.getDealerId().equals(currentUser.getDealerId())) {
|
||||
throw new BusinessException("您只能撤回自己的报备");
|
||||
}
|
||||
|
||||
if (report.getStatus() != Constants.REPORT_STATUS_PENDING) {
|
||||
throw new BusinessException("只能撤回待审核的报备");
|
||||
}
|
||||
|
||||
reportMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleExpiredReports() {
|
||||
// 查询所有保护期已到的报备
|
||||
String endDate = LocalDateTime.now().toString();
|
||||
List<Report> expiringReports = reportMapper.selectExpiringReports(endDate);
|
||||
|
||||
if (expiringReports.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 批量更新报备状态
|
||||
List<Long> ids = expiringReports.stream().map(Report::getId).collect(Collectors.toList());
|
||||
reportMapper.batchUpdateExpired(ids);
|
||||
|
||||
// 批量更新客户状态为可报备
|
||||
expiringReports.forEach(report -> {
|
||||
Customer customer = customerMapper.selectById(report.getCustomerId());
|
||||
if (customer != null && customer.getStatus() == Constants.CUSTOMER_STATUS_PROTECTED) {
|
||||
customer.setStatus(Constants.CUSTOMER_STATUS_AVAILABLE);
|
||||
customerMapper.update(customer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 VO
|
||||
*/
|
||||
private ReportVO convertToVO(Report report) {
|
||||
ReportVO vo = new ReportVO();
|
||||
BeanUtils.copyProperties(report, vo);
|
||||
|
||||
// 设置状态描述
|
||||
switch (report.getStatus()) {
|
||||
case Constants.REPORT_STATUS_PENDING:
|
||||
vo.setStatusDesc("待审核");
|
||||
break;
|
||||
case Constants.REPORT_STATUS_APPROVED:
|
||||
vo.setStatusDesc("已通过");
|
||||
// 计算剩余保护天数
|
||||
if (report.getProtectEndDate() != null) {
|
||||
long days = ChronoUnit.DAYS.between(LocalDateTime.now(), report.getProtectEndDate());
|
||||
vo.setRemainDays((int) Math.max(0, days));
|
||||
}
|
||||
break;
|
||||
case Constants.REPORT_STATUS_REJECTED:
|
||||
vo.setStatusDesc("已驳回");
|
||||
break;
|
||||
case Constants.REPORT_STATUS_EXPIRED:
|
||||
vo.setStatusDesc("已失效");
|
||||
break;
|
||||
default:
|
||||
vo.setStatusDesc("未知");
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.bycrm.service.impl;
|
||||
|
||||
import com.bycrm.common.Constants;
|
||||
import com.bycrm.entity.User;
|
||||
import com.bycrm.exception.BusinessException;
|
||||
import com.bycrm.mapper.UserMapper;
|
||||
import com.bycrm.service.UserService;
|
||||
import com.bycrm.util.JwtUtil;
|
||||
import com.bycrm.vo.UserInfoVO;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 用户服务实现
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
public UserServiceImpl(UserMapper userMapper, JwtUtil jwtUtil) {
|
||||
this.userMapper = userMapper;
|
||||
this.jwtUtil = jwtUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(com.bycrm.dto.LoginDTO loginDTO) {
|
||||
User user = userMapper.selectByUsername(loginDTO.getUsername());
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户名或密码错误");
|
||||
}
|
||||
|
||||
if (user.getStatus() == Constants.USER_STATUS_DISABLED) {
|
||||
throw new BusinessException("用户已被禁用");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(loginDTO.getPassword(), user.getPassword())) {
|
||||
throw new BusinessException("用户名或密码错误");
|
||||
}
|
||||
|
||||
return jwtUtil.generateToken(user.getId(), user.getUsername(), user.getRole(), user.getDealerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserById(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfoVO getCurrentUser(String token) {
|
||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
UserInfoVO vo = new UserInfoVO();
|
||||
vo.setUserId(user.getId());
|
||||
vo.setUsername(user.getUsername());
|
||||
vo.setRealName(user.getRealName());
|
||||
vo.setDealerId(user.getDealerId());
|
||||
vo.setDealerName(user.getDealerName());
|
||||
vo.setRole(user.getRole());
|
||||
vo.setRoleDesc(user.getRole() == Constants.USER_ROLE_ADMIN ? "管理员" : "经销商用户");
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.bycrm.task;
|
||||
|
||||
import com.bycrm.service.ReportService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 报备过期处理定时任务
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ReportExpireTask {
|
||||
|
||||
private final ReportService reportService;
|
||||
|
||||
public ReportExpireTask(ReportService reportService) {
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每天凌晨1点执行,处理过期的报备
|
||||
*/
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void handleExpiredReports() {
|
||||
log.info("开始处理过期报备...");
|
||||
try {
|
||||
reportService.handleExpiredReports();
|
||||
log.info("过期报备处理完成");
|
||||
} catch (Exception e) {
|
||||
log.error("处理过期报备失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.bycrm.util;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JWT 工具类
|
||||
*/
|
||||
@Component
|
||||
public class JwtUtil {
|
||||
|
||||
@Value("${jwt.secret}")
|
||||
private String secret;
|
||||
|
||||
@Value("${jwt.expiration}")
|
||||
private Long expiration;
|
||||
|
||||
/**
|
||||
* 生成 Token
|
||||
*/
|
||||
public String generateToken(Long userId, String username, Integer role, Long dealerId) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("userId", userId);
|
||||
claims.put("username", username);
|
||||
claims.put("role", role);
|
||||
claims.put("dealerId", dealerId);
|
||||
return generateToken(claims);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 Token
|
||||
*/
|
||||
public String generateToken(Map<String, Object> claims) {
|
||||
Date now = new Date();
|
||||
Date expiryDate = new Date(now.getTime() + expiration);
|
||||
|
||||
return Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.setIssuedAt(now)
|
||||
.setExpiration(expiryDate)
|
||||
.signWith(getSigningKey(), SignatureAlgorithm.HS512)
|
||||
.compact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Token 中获取 Claims
|
||||
*/
|
||||
public Claims getClaimsFromToken(String token) {
|
||||
return Jwts.parserBuilder()
|
||||
.setSigningKey(getSigningKey())
|
||||
.build()
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Token 中获取用户ID
|
||||
*/
|
||||
public Long getUserIdFromToken(String token) {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
return claims.get("userId", Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Token 中获取用户名
|
||||
*/
|
||||
public String getUsernameFromToken(String token) {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
return claims.get("username", String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Token 中获取角色
|
||||
*/
|
||||
public Integer getRoleFromToken(String token) {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
return claims.get("role", Integer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Token 中获取经销商ID
|
||||
*/
|
||||
public Long getDealerIdFromToken(String token) {
|
||||
Claims claims = getClaimsFromToken(token);
|
||||
return claims.get("dealerId", Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 Token 是否过期
|
||||
*/
|
||||
public boolean isTokenExpired(String token) {
|
||||
try {
|
||||
Date expiration = getClaimsFromToken(token).getExpiration();
|
||||
return expiration.before(new Date());
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 Token
|
||||
*/
|
||||
public boolean validateToken(String token) {
|
||||
try {
|
||||
return !isTokenExpired(token);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签名密钥
|
||||
*/
|
||||
private SecretKey getSigningKey() {
|
||||
byte[] keyBytes = secret.getBytes(StandardCharsets.UTF_8);
|
||||
return Keys.hmacShaKeyFor(keyBytes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.bycrm.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客户详情 VO
|
||||
*/
|
||||
@Data
|
||||
public class CustomerVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 所属行业
|
||||
*/
|
||||
private String industry;
|
||||
|
||||
/**
|
||||
* 状态:0-可报备 1-保护中 2-已失效
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
private String statusDesc;
|
||||
|
||||
/**
|
||||
* 当前报备经销商ID
|
||||
*/
|
||||
private Long currentDealerId;
|
||||
|
||||
/**
|
||||
* 当前报备经销商名称
|
||||
*/
|
||||
private String currentDealerName;
|
||||
|
||||
/**
|
||||
* 保护期结束时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime protectEndDate;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.bycrm.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 报备详情 VO
|
||||
*/
|
||||
@Data
|
||||
public class ReportVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 报备ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 经销商ID
|
||||
*/
|
||||
private Long dealerId;
|
||||
|
||||
/**
|
||||
* 经销商名称
|
||||
*/
|
||||
private String dealerName;
|
||||
|
||||
/**
|
||||
* 客户ID
|
||||
*/
|
||||
private Long customerId;
|
||||
|
||||
/**
|
||||
* 客户名称
|
||||
*/
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 客户电话
|
||||
*/
|
||||
private String customerPhone;
|
||||
|
||||
/**
|
||||
* 报备说明
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态:0-待审核 1-已通过 2-已驳回 3-已失效
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
private String statusDesc;
|
||||
|
||||
/**
|
||||
* 驳回原因
|
||||
*/
|
||||
private String rejectReason;
|
||||
|
||||
/**
|
||||
* 保护期开始时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime protectStartDate;
|
||||
|
||||
/**
|
||||
* 保护期结束时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime protectEndDate;
|
||||
|
||||
/**
|
||||
* 剩余保护天数
|
||||
*/
|
||||
private Integer remainDays;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.bycrm.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户信息 VO
|
||||
*/
|
||||
@Data
|
||||
public class UserInfoVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 真实姓名
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 经销商ID
|
||||
*/
|
||||
private Long dealerId;
|
||||
|
||||
/**
|
||||
* 经销商名称
|
||||
*/
|
||||
private String dealerName;
|
||||
|
||||
/**
|
||||
* 角色:0-管理员 1-经销商用户
|
||||
*/
|
||||
private Integer role;
|
||||
|
||||
/**
|
||||
* 角色描述
|
||||
*/
|
||||
private String roleDesc;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
server:
|
||||
port: 8080
|
||||
servlet:
|
||||
context-path: /api
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: by-crm
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/by_crm?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
druid:
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: SELECT 1
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
filters: stat,wall
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
login-username: admin
|
||||
login-password: admin123
|
||||
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
default-property-inclusion: non_null
|
||||
|
||||
# MyBatis 配置
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
type-aliases-package: com.bycrm.entity
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
# JWT 配置
|
||||
jwt:
|
||||
secret: by-crm-secret-key-2024-please-change-in-production
|
||||
expiration: 86400000 # 24小时,单位:毫秒
|
||||
|
||||
# CRM 业务配置
|
||||
crm:
|
||||
report:
|
||||
ttl-days: 90 # 保护期天数
|
||||
allow-overlap: false # 是否允许重叠报备(生产环境必须为 false)
|
||||
|
||||
# Swagger 配置
|
||||
springfox:
|
||||
documentation:
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
enabled: true
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
com.bycrm.mapper: debug
|
||||
org.springframework.web: info
|
||||
pattern:
|
||||
console: '%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{50} - %msg%n'
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bycrm.mapper.CustomerMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.bycrm.entity.Customer">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="address" property="address"/>
|
||||
<result column="industry" property="industry"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_customer WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByNameLike" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_customer
|
||||
WHERE name LIKE CONCAT('%', #{name}, '%')
|
||||
LIMIT 10
|
||||
</select>
|
||||
|
||||
<select id="selectPage" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_customer
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
AND name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="industry != null and industry != ''">
|
||||
AND industry = #{industry}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY created_at DESC
|
||||
LIMIT #{query.size} OFFSET #{query.offset}
|
||||
</select>
|
||||
|
||||
<select id="countPage" resultType="java.lang.Long">
|
||||
SELECT COUNT(*) FROM crm_customer
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
AND name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="industry != null and industry != ''">
|
||||
AND industry = #{industry}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.bycrm.entity.Customer" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO crm_customer (name, phone, address, industry, status)
|
||||
VALUES (#{name}, #{phone}, #{address}, #{industry}, #{status})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.bycrm.entity.Customer">
|
||||
UPDATE crm_customer
|
||||
<set>
|
||||
<if test="name != null and name != ''">name = #{name},</if>
|
||||
<if test="phone != null">phone = #{phone},</if>
|
||||
<if test="address != null">address = #{address},</if>
|
||||
<if test="industry != null">industry = #{industry},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
DELETE FROM crm_customer WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bycrm.mapper.DealerMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.bycrm.entity.Dealer">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="code" property="code"/>
|
||||
<result column="contact_person" property="contactPerson"/>
|
||||
<result column="contact_phone" property="contactPhone"/>
|
||||
<result column="email" property="email"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_dealer WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByCode" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_dealer WHERE code = #{code}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_dealer
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
AND name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="code != null and code != ''">
|
||||
AND code LIKE CONCAT('%', #{code}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY created_at DESC
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.bycrm.entity.Dealer" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO crm_dealer (name, code, contact_person, contact_phone, email, status)
|
||||
VALUES (#{name}, #{code}, #{contactPerson}, #{contactPhone}, #{email}, #{status})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.bycrm.entity.Dealer">
|
||||
UPDATE crm_dealer
|
||||
<set>
|
||||
<if test="name != null and name != ''">name = #{name},</if>
|
||||
<if test="code != null and code != ''">code = #{code},</if>
|
||||
<if test="contactPerson != null and contactPerson != ''">contact_person = #{contactPerson},</if>
|
||||
<if test="contactPhone != null and contactPhone != ''">contact_phone = #{contactPhone},</if>
|
||||
<if test="email != null">email = #{email},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
DELETE FROM crm_dealer WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bycrm.mapper.ReportMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.bycrm.entity.Report">
|
||||
<id column="id" property="id"/>
|
||||
<result column="dealer_id" property="dealerId"/>
|
||||
<result column="customer_id" property="customerId"/>
|
||||
<result column="description" property="description"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="reject_reason" property="rejectReason"/>
|
||||
<result column="protect_start_date" property="protectStartDate"/>
|
||||
<result column="protect_end_date" property="protectEndDate"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
<result column="dealer_name" property="dealerName"/>
|
||||
<result column="customer_name" property="customerName"/>
|
||||
<result column="customer_phone" property="customerPhone"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT r.*,
|
||||
d.name AS dealer_name,
|
||||
c.name AS customer_name,
|
||||
c.phone AS customer_phone
|
||||
FROM crm_report r
|
||||
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
||||
LEFT JOIN crm_customer c ON r.customer_id = c.id
|
||||
WHERE r.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectValidByCustomerId" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_report
|
||||
WHERE customer_id = #{customerId}
|
||||
AND status IN (0, 1)
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectPage" resultMap="BaseResultMap">
|
||||
SELECT r.*,
|
||||
d.name AS dealer_name,
|
||||
c.name AS customer_name,
|
||||
c.phone AS customer_phone
|
||||
FROM crm_report r
|
||||
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
||||
LEFT JOIN crm_customer c ON r.customer_id = c.id
|
||||
<where>
|
||||
<if test="dealerId != null">
|
||||
AND r.dealer_id = #{dealerId}
|
||||
</if>
|
||||
<if test="dealerName != null and dealerName != ''">
|
||||
AND d.name LIKE CONCAT('%', #{dealerName}, '%')
|
||||
</if>
|
||||
<if test="customerName != null and customerName != ''">
|
||||
AND c.name LIKE CONCAT('%', #{customerName}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND r.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY r.created_at DESC
|
||||
LIMIT #{query.size} OFFSET #{query.offset}
|
||||
</select>
|
||||
|
||||
<select id="countPage" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM crm_report r
|
||||
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
||||
LEFT JOIN crm_customer c ON r.customer_id = c.id
|
||||
<where>
|
||||
<if test="dealerId != null">
|
||||
AND r.dealer_id = #{dealerId}
|
||||
</if>
|
||||
<if test="dealerName != null and dealerName != ''">
|
||||
AND d.name LIKE CONCAT('%', #{dealerName}, '%')
|
||||
</if>
|
||||
<if test="customerName != null and customerName != ''">
|
||||
AND c.name LIKE CONCAT('%', #{customerName}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND r.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.bycrm.entity.Report" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO crm_report (dealer_id, customer_id, description, status, protect_start_date, protect_end_date)
|
||||
VALUES (#{dealerId}, #{customerId}, #{description}, #{status}, #{protectStartDate}, #{protectEndDate})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.bycrm.entity.Report">
|
||||
UPDATE crm_report
|
||||
<set>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="rejectReason != null">reject_reason = #{rejectReason},</if>
|
||||
<if test="protectStartDate != null">protect_start_date = #{protectStartDate},</if>
|
||||
<if test="protectEndDate != null">protect_end_date = #{protectEndDate},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
DELETE FROM crm_report WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="selectExpiringReports" resultMap="BaseResultMap">
|
||||
SELECT * FROM crm_report
|
||||
WHERE status = 1
|
||||
AND protect_end_date <= #{endDate}
|
||||
</select>
|
||||
|
||||
<update id="batchUpdateExpired">
|
||||
UPDATE crm_report
|
||||
SET status = 3
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bycrm.mapper.UserMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.bycrm.entity.User">
|
||||
<id column="id" property="id"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="real_name" property="realName"/>
|
||||
<result column="dealer_id" property="dealerId"/>
|
||||
<result column="role" property="role"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="created_at" property="createdAt"/>
|
||||
<result column="updated_at" property="updatedAt"/>
|
||||
<result column="dealer_name" property="dealerName"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||
SELECT u.*,
|
||||
d.name AS dealer_name
|
||||
FROM crm_user u
|
||||
LEFT JOIN crm_dealer d ON u.dealer_id = d.id
|
||||
WHERE u.username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT u.*,
|
||||
d.name AS dealer_name
|
||||
FROM crm_user u
|
||||
LEFT JOIN crm_dealer d ON u.dealer_id = d.id
|
||||
WHERE u.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT u.*,
|
||||
d.name AS dealer_name
|
||||
FROM crm_user u
|
||||
LEFT JOIN crm_dealer d ON u.dealer_id = d.id
|
||||
ORDER BY u.created_at DESC
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.bycrm.entity.User" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO crm_user (username, password, real_name, dealer_id, role, status)
|
||||
VALUES (#{username}, #{password}, #{realName}, #{dealerId}, #{role}, #{status})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.bycrm.entity.User">
|
||||
UPDATE crm_user
|
||||
<set>
|
||||
<if test="password != null and password != ''">password = #{password},</if>
|
||||
<if test="realName != null and realName != ''">real_name = #{realName},</if>
|
||||
<if test="dealerId != null">dealer_id = #{dealerId},</if>
|
||||
<if test="role != null">role = #{role},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
DELETE FROM crm_user WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user