84 changed files with 4528 additions and 0 deletions
@ -0,0 +1,230 @@ |
|||
<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> |
|||
<groupId>com.zhongyun</groupId> |
|||
<artifactId>zhongyun-points</artifactId> |
|||
<version>1.0.0</version> |
|||
<packaging>pom</packaging> |
|||
|
|||
<name>points</name> |
|||
<description>points</description> |
|||
<url>https://www.xxxxx.io</url> |
|||
|
|||
<!--<parent> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-parent</artifactId> |
|||
<version>2.1.11.RELEASE</version> |
|||
</parent>--> |
|||
|
|||
<parent> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-parent</artifactId> |
|||
<version>2.1.11.RELEASE</version> |
|||
</parent> |
|||
|
|||
<modules> |
|||
<module>zhongyun-common</module> |
|||
<module>zhongyun-points-admin</module> |
|||
</modules> |
|||
|
|||
<properties> |
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
|||
<java.version>1.8</java.version> |
|||
<junit.version>4.12</junit.version> |
|||
<jedis.version>3.5.2</jedis.version> |
|||
<druid.version>1.2.14</druid.version> |
|||
<mybatisplus.version>3.4.2</mybatisplus.version> |
|||
<sqlserver.version>4.0</sqlserver.version> |
|||
<oracle.version>11.2.0.3</oracle.version> |
|||
<dameng.version>8.1.2.141</dameng.version> |
|||
<commons.lang.version>3.7</commons.lang.version> |
|||
<commons.fileupload.version>1.3.1</commons.fileupload.version> |
|||
<commons.io.version>2.5</commons.io.version> |
|||
<commons.codec.version>1.10</commons.codec.version> |
|||
<guava.version>20.0</guava.version> |
|||
<joda.time.version>2.9.9</joda.time.version> |
|||
<hutool.version>5.7.22</hutool.version> |
|||
<mysql.version>8.0.20</mysql.version> |
|||
<gson.version>2.8.6</gson.version> |
|||
<jsoup.version>1.11.3</jsoup.version> |
|||
<knife4j.version>2.0.9</knife4j.version> |
|||
<lombok.version>1.18.4</lombok.version> |
|||
<docker.plugin.version>1.1.1</docker.plugin.version> |
|||
<spring-cloud.version>Greenwich.SR4</spring-cloud.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<!-- SpringCloud 微服务 --> |
|||
<dependency> |
|||
<groupId>org.springframework.cloud</groupId> |
|||
<artifactId>spring-cloud-dependencies</artifactId> |
|||
<version>${spring-cloud.version}</version> |
|||
<type>pom</type> |
|||
<scope>import</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-alibaba-dependencies</artifactId> |
|||
<version>2.1.0.RELEASE</version> |
|||
<type>pom</type> |
|||
<scope>import</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>junit</groupId> |
|||
<artifactId>junit</artifactId> |
|||
<version>${junit.version}</version> |
|||
<scope>test</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-test</artifactId> |
|||
<scope>test</scope> |
|||
<exclusions> |
|||
<exclusion> |
|||
<artifactId>log4j-api</artifactId> |
|||
<groupId>org.apache.logging.log4j</groupId> |
|||
</exclusion> |
|||
<exclusion> |
|||
<artifactId>log4j-to-slf4j</artifactId> |
|||
<groupId>org.apache.logging.log4j</groupId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-aop</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-context-support</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-validation</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-configuration-processor</artifactId> |
|||
<optional>true</optional> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
<version>${mysql.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>druid-spring-boot-starter</artifactId> |
|||
<version>${druid.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>mybatis-plus-boot-starter</artifactId> |
|||
<version>${mybatisplus.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.commons</groupId> |
|||
<artifactId>commons-lang3</artifactId> |
|||
<version>${commons.lang.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>commons-fileupload</groupId> |
|||
<artifactId>commons-fileupload</artifactId> |
|||
<version>${commons.fileupload.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>commons-io</groupId> |
|||
<artifactId>commons-io</artifactId> |
|||
<version>${commons.io.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>commons-codec</groupId> |
|||
<artifactId>commons-codec</artifactId> |
|||
<version>${commons.codec.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.google.guava</groupId> |
|||
<artifactId>guava</artifactId> |
|||
<version>${guava.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>joda-time</groupId> |
|||
<artifactId>joda-time</artifactId> |
|||
<version>${joda.time.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.google.code.gson</groupId> |
|||
<artifactId>gson</artifactId> |
|||
<version>${gson.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>cn.hutool</groupId> |
|||
<artifactId>hutool-all</artifactId> |
|||
<version>${hutool.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.jsoup</groupId> |
|||
<artifactId>jsoup</artifactId> |
|||
<version>${jsoup.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.xiaoymin</groupId> |
|||
<artifactId>knife4j-spring-boot-starter</artifactId> |
|||
<version>${knife4j.version}</version> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>org.springframework.plugin</groupId> |
|||
<artifactId>spring-plugin-core</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<!--强制解决knife4j与spring-plugin-core版本冲突问题--> |
|||
<dependency> |
|||
<groupId>org.springframework.plugin</groupId> |
|||
<artifactId>spring-plugin-core</artifactId> |
|||
<version>2.0.0.RELEASE</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.plugin</groupId> |
|||
<artifactId>spring-plugin-metadata</artifactId> |
|||
<version>2.0.0.RELEASE</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.projectlombok</groupId> |
|||
<artifactId>lombok</artifactId> |
|||
<version>${lombok.version}</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<!-- 阿里云maven仓库 --> |
|||
<repositories> |
|||
<repository> |
|||
<id>public</id> |
|||
<name>aliyun nexus</name> |
|||
<url>https://maven.aliyun.com/repository/public/</url> |
|||
<releases> |
|||
<enabled>true</enabled> |
|||
</releases> |
|||
</repository> |
|||
</repositories> |
|||
<pluginRepositories> |
|||
<pluginRepository> |
|||
<id>public</id> |
|||
<name>aliyun nexus</name> |
|||
<url>https://maven.aliyun.com/repository/public/</url> |
|||
<releases> |
|||
<enabled>true</enabled> |
|||
</releases> |
|||
<snapshots> |
|||
<enabled>false</enabled> |
|||
</snapshots> |
|||
</pluginRepository> |
|||
</pluginRepositories> |
|||
</project> |
@ -0,0 +1,16 @@ |
|||
<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"> |
|||
<parent> |
|||
<groupId>com.zhongyun</groupId> |
|||
<artifactId>zhongyun-points</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<artifactId>zhongyun-common</artifactId> |
|||
<packaging>jar</packaging> |
|||
<description>zhongyun-common</description> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
|
|||
</project> |
@ -0,0 +1,215 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.constant; |
|||
|
|||
/** |
|||
* 常量 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface Constant { |
|||
/** |
|||
* 成功 |
|||
*/ |
|||
int SUCCESS = 1; |
|||
/** |
|||
* 失败 |
|||
*/ |
|||
int FAIL = 0; |
|||
/** |
|||
* OK |
|||
*/ |
|||
String OK = "OK"; |
|||
/** |
|||
* 用户标识 |
|||
*/ |
|||
String USER_KEY = "userId"; |
|||
/** |
|||
* 菜单根节点标识 |
|||
*/ |
|||
Long MENU_ROOT = 0L; |
|||
/** |
|||
* 部门根节点标识 |
|||
*/ |
|||
Long DEPT_ROOT = 0L; |
|||
/** |
|||
* 数据字典根节点标识 |
|||
*/ |
|||
Long DICT_ROOT = 0L; |
|||
/** |
|||
* 升序 |
|||
*/ |
|||
String ASC = "asc"; |
|||
/** |
|||
* 降序 |
|||
*/ |
|||
String DESC = "desc"; |
|||
/** |
|||
* 创建时间字段名 |
|||
*/ |
|||
String CREATE_DATE = "create_date"; |
|||
|
|||
/** |
|||
* 创建时间字段名 |
|||
*/ |
|||
String ID = "id"; |
|||
|
|||
/** |
|||
* 数据权限过滤 |
|||
*/ |
|||
String SQL_FILTER = "sqlFilter"; |
|||
|
|||
/** |
|||
* 当前页码 |
|||
*/ |
|||
String PAGE = "page"; |
|||
/** |
|||
* 每页显示记录数 |
|||
*/ |
|||
String LIMIT = "limit"; |
|||
/** |
|||
* 排序字段 |
|||
*/ |
|||
String ORDER_FIELD = "orderField"; |
|||
/** |
|||
* 排序方式 |
|||
*/ |
|||
String ORDER = "order"; |
|||
/** |
|||
* token header |
|||
*/ |
|||
String TOKEN_HEADER = "token"; |
|||
|
|||
/** |
|||
* 云存储配置KEY |
|||
*/ |
|||
String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY"; |
|||
/** |
|||
* 邮件配置KEY |
|||
*/ |
|||
String MAIL_CONFIG_KEY = "MAIL_CONFIG_KEY"; |
|||
/** |
|||
* 代码生成参数KEY |
|||
*/ |
|||
String DEV_TOOLS_PARAM_KEY = "DEV_TOOLS_PARAM_KEY"; |
|||
|
|||
/** |
|||
* 定时任务状态 |
|||
*/ |
|||
enum ScheduleStatus { |
|||
/** |
|||
* 暂停 |
|||
*/ |
|||
PAUSE(0), |
|||
/** |
|||
* 正常 |
|||
*/ |
|||
NORMAL(1); |
|||
|
|||
private int value; |
|||
|
|||
ScheduleStatus(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int getValue() { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 云服务商 |
|||
*/ |
|||
enum CloudService { |
|||
/** |
|||
* 七牛云 |
|||
*/ |
|||
QINIU(1), |
|||
/** |
|||
* 阿里云 |
|||
*/ |
|||
ALIYUN(2), |
|||
/** |
|||
* 腾讯云 |
|||
*/ |
|||
QCLOUD(3), |
|||
/** |
|||
* FASTDFS |
|||
*/ |
|||
FASTDFS(4), |
|||
/** |
|||
* 本地 |
|||
*/ |
|||
LOCAL(5), |
|||
/** |
|||
* MinIO |
|||
*/ |
|||
MINIO(6); |
|||
|
|||
private int value; |
|||
|
|||
CloudService(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int getValue() { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 短信服务商 |
|||
*/ |
|||
enum SmsService { |
|||
/** |
|||
* 阿里云 |
|||
*/ |
|||
ALIYUN(1), |
|||
/** |
|||
* 腾讯云 |
|||
*/ |
|||
QCLOUD(2), |
|||
/** |
|||
* 七牛 |
|||
*/ |
|||
QINIU(3); |
|||
|
|||
private int value; |
|||
|
|||
SmsService(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int getValue() { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 订单状态 |
|||
*/ |
|||
enum OrderStatus { |
|||
/** |
|||
* 已取消 |
|||
*/ |
|||
CANCEL(-1), |
|||
/** |
|||
* 等待付款 |
|||
*/ |
|||
WAITING(0), |
|||
/** |
|||
* 已完成 |
|||
*/ |
|||
FINISH(1); |
|||
|
|||
private int value; |
|||
|
|||
OrderStatus(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int getValue() { |
|||
return value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.dao; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* 基础Dao |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface BaseDao<T> extends BaseMapper<T> { |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 基础实体类,所有实体都需要继承 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
public abstract class BaseEntity implements Serializable { |
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
/** |
|||
* 创建者 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Long creator; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createDate; |
|||
} |
@ -0,0 +1,67 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.exception; |
|||
|
|||
/** |
|||
* 错误编码,由5位数字组成,前2位为模块编码,后3位为业务编码 |
|||
* <p> |
|||
* 如:10001(10代表系统模块,001代表业务代码) |
|||
* </p> |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface ErrorCode { |
|||
int INTERNAL_SERVER_ERROR = 500; |
|||
int UNAUTHORIZED = 401; |
|||
int FORBIDDEN = 403; |
|||
|
|||
int NOT_NULL = 10001; |
|||
int DB_RECORD_EXISTS = 10002; |
|||
int PARAMS_GET_ERROR = 10003; |
|||
int ACCOUNT_PASSWORD_ERROR = 10004; |
|||
int ACCOUNT_DISABLE = 10005; |
|||
int IDENTIFIER_NOT_NULL = 10006; |
|||
int CAPTCHA_ERROR = 10007; |
|||
int SUB_MENU_EXIST = 10008; |
|||
int PASSWORD_ERROR = 10009; |
|||
int ACCOUNT_NOT_EXIST = 10010; |
|||
int SUPERIOR_DEPT_ERROR = 10011; |
|||
int SUPERIOR_MENU_ERROR = 10012; |
|||
int DATA_SCOPE_PARAMS_ERROR = 10013; |
|||
int DEPT_SUB_DELETE_ERROR = 10014; |
|||
int DEPT_USER_DELETE_ERROR = 10015; |
|||
int ACT_DEPLOY_ERROR = 10016; |
|||
int ACT_MODEL_IMG_ERROR = 10017; |
|||
int ACT_MODEL_EXPORT_ERROR = 10018; |
|||
int UPLOAD_FILE_EMPTY = 10019; |
|||
int TOKEN_NOT_EMPTY = 10020; |
|||
int TOKEN_INVALID = 10021; |
|||
int ACCOUNT_LOCK = 10022; |
|||
int ACT_DEPLOY_FORMAT_ERROR = 10023; |
|||
int OSS_UPLOAD_FILE_ERROR = 10024; |
|||
int SEND_SMS_ERROR = 10025; |
|||
int MAIL_TEMPLATE_NOT_EXISTS = 10026; |
|||
int REDIS_ERROR = 10027; |
|||
int JOB_ERROR = 10028; |
|||
int INVALID_SYMBOL = 10029; |
|||
int JSON_FORMAT_ERROR = 10030; |
|||
int SMS_CONFIG = 10031; |
|||
int TASK_CLIME_FAIL = 10032; |
|||
int NONE_EXIST_PROCESS = 10033; |
|||
int SUPERIOR_NOT_EXIST = 10034; |
|||
int REJECT_MESSAGE = 10035; |
|||
int ROLLBACK_MESSAGE = 10036; |
|||
int UNCLAIM_ERROR_MESSAGE = 10037; |
|||
int SUPERIOR_REGION_ERROR = 10038; |
|||
int REGION_SUB_DELETE_ERROR = 10039; |
|||
int PROCESS_START_ERROR = 10040; |
|||
int REJECT_PROCESS_PARALLEL_ERROR = 10041; |
|||
int REJECT_PROCESS_HANDLEING_ERROR = 10042; |
|||
int END_PROCESS_PARALLEL_ERROR = 10043; |
|||
int END_PROCESS_HANDLEING_ERROR = 10044; |
|||
int END_PROCESS_MESSAGE = 10045; |
|||
int BACK_PROCESS_PARALLEL_ERROR = 10046; |
|||
int BACK_PROCESS_HANDLEING_ERROR = 10047; |
|||
int DEL_MYSELF_ERROR = 10048; |
|||
} |
@ -0,0 +1,69 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.exception; |
|||
|
|||
|
|||
import com.zhongyun.common.utils.MessageUtils; |
|||
|
|||
/** |
|||
* 自定义异常 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public class RenException extends RuntimeException { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
private int code; |
|||
private String msg; |
|||
|
|||
public RenException(int code) { |
|||
this.code = code; |
|||
this.msg = MessageUtils.getMessage(code); |
|||
} |
|||
|
|||
public RenException(int code, String... params) { |
|||
this.code = code; |
|||
this.msg = MessageUtils.getMessage(code, params); |
|||
} |
|||
|
|||
public RenException(int code, Throwable e) { |
|||
super(e); |
|||
this.code = code; |
|||
this.msg = MessageUtils.getMessage(code); |
|||
} |
|||
|
|||
public RenException(int code, Throwable e, String... params) { |
|||
super(e); |
|||
this.code = code; |
|||
this.msg = MessageUtils.getMessage(code, params); |
|||
} |
|||
|
|||
public RenException(String msg) { |
|||
super(msg); |
|||
this.code = ErrorCode.INTERNAL_SERVER_ERROR; |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public RenException(String msg, Throwable e) { |
|||
super(msg, e); |
|||
this.code = ErrorCode.INTERNAL_SERVER_ERROR; |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
|
|||
public void setMsg(String msg) { |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(int code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.page; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 分页工具类 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "分页数据") |
|||
public class PageData<T> implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "总记录数") |
|||
private int total; |
|||
|
|||
@ApiModelProperty(value = "列表数据") |
|||
private List<T> list; |
|||
|
|||
/** |
|||
* 分页 |
|||
* @param list 列表数据 |
|||
* @param total 总记录数 |
|||
*/ |
|||
public PageData(List<T> list, long total) { |
|||
this.list = list; |
|||
this.total = (int)total; |
|||
} |
|||
} |
@ -0,0 +1,110 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.service; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Collection; |
|||
|
|||
/** |
|||
* 基础服务接口,所有Service接口都要继承 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface BaseService<T> { |
|||
Class<T> currentModelClass(); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入一条记录(选择字段,策略插入) |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
*/ |
|||
boolean insert(T entity); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入(批量),该方法不支持 Oracle、SQL Server |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
*/ |
|||
boolean insertBatch(Collection<T> entityList); |
|||
|
|||
/** |
|||
* <p> |
|||
* 插入(批量),该方法不支持 Oracle、SQL Server |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
* @param batchSize 插入批次数量 |
|||
*/ |
|||
boolean insertBatch(Collection<T> entityList, int batchSize); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 选择修改 |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
*/ |
|||
boolean updateById(T entity); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 whereEntity 条件,更新记录 |
|||
* </p> |
|||
* |
|||
* @param entity 实体对象 |
|||
* @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper} |
|||
*/ |
|||
boolean update(T entity, Wrapper<T> updateWrapper); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据ID 批量更新 |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
*/ |
|||
boolean updateBatchById(Collection<T> entityList); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据ID 批量更新 |
|||
* </p> |
|||
* |
|||
* @param entityList 实体对象集合 |
|||
* @param batchSize 更新批次数量 |
|||
*/ |
|||
boolean updateBatchById(Collection<T> entityList, int batchSize); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 查询 |
|||
* </p> |
|||
* |
|||
* @param id 主键ID |
|||
*/ |
|||
T selectById(Serializable id); |
|||
|
|||
/** |
|||
* <p> |
|||
* 根据 ID 删除 |
|||
* </p> |
|||
* |
|||
* @param id 主键ID |
|||
*/ |
|||
boolean deleteById(Serializable id); |
|||
|
|||
/** |
|||
* <p> |
|||
* 删除(根据ID 批量删除) |
|||
* </p> |
|||
* |
|||
* @param idList 主键ID列表 |
|||
*/ |
|||
boolean deleteBatchIds(Collection<? extends Serializable> idList); |
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.zhongyun.common.service; |
|||
|
|||
|
|||
import com.zhongyun.common.page.PageData; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* CRUD基础服务接口 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface CrudService<T, D> extends BaseService<T> { |
|||
|
|||
PageData<D> page(Map<String, Object> params); |
|||
|
|||
List<D> list(Map<String, Object> params); |
|||
|
|||
D get(Long id); |
|||
|
|||
void save(D dto); |
|||
|
|||
void update(D dto); |
|||
|
|||
void delete(Long[] ids); |
|||
|
|||
} |
@ -0,0 +1,213 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|||
import com.baomidou.mybatisplus.core.enums.SqlMethod; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.metadata.OrderItem; |
|||
import com.baomidou.mybatisplus.core.toolkit.Constants; |
|||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; |
|||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.BaseService; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import org.apache.ibatis.binding.MapperMethod; |
|||
import org.apache.ibatis.logging.Log; |
|||
import org.apache.ibatis.logging.LogFactory; |
|||
import org.apache.ibatis.session.SqlSession; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.function.BiConsumer; |
|||
|
|||
/** |
|||
* 基础服务类,所有Service都要继承 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements BaseService<T> { |
|||
@Autowired |
|||
protected M baseDao; |
|||
protected Log log = LogFactory.getLog(getClass()); |
|||
|
|||
/** |
|||
* 获取分页对象 |
|||
* @param params 分页查询参数 |
|||
* @param defaultOrderField 默认排序字段 |
|||
* @param isAsc 排序方式 |
|||
*/ |
|||
protected IPage<T> getPage(Map<String, Object> params, String defaultOrderField, boolean isAsc) { |
|||
//分页参数
|
|||
long curPage = 1; |
|||
long limit = 10; |
|||
|
|||
if(params.get(Constant.PAGE) != null){ |
|||
curPage = Long.parseLong((String)params.get(Constant.PAGE)); |
|||
} |
|||
if(params.get(Constant.LIMIT) != null){ |
|||
limit = Long.parseLong((String)params.get(Constant.LIMIT)); |
|||
} |
|||
|
|||
//分页对象
|
|||
Page<T> page = new Page<>(curPage, limit); |
|||
|
|||
//分页参数
|
|||
params.put(Constant.PAGE, page); |
|||
|
|||
//排序字段
|
|||
String orderField = (String)params.get(Constant.ORDER_FIELD); |
|||
String order = (String)params.get(Constant.ORDER); |
|||
|
|||
//前端字段排序
|
|||
if(StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)){ |
|||
if(Constant.ASC.equalsIgnoreCase(order)) { |
|||
return page.addOrder(OrderItem.asc(orderField)); |
|||
}else { |
|||
return page.addOrder(OrderItem.desc(orderField)); |
|||
} |
|||
} |
|||
|
|||
//没有排序字段,则不排序
|
|||
if(StringUtils.isBlank(defaultOrderField)){ |
|||
return page; |
|||
} |
|||
|
|||
//默认排序
|
|||
if(isAsc) { |
|||
page.addOrder(OrderItem.asc(defaultOrderField)); |
|||
}else { |
|||
page.addOrder(OrderItem.desc(defaultOrderField)); |
|||
} |
|||
|
|||
return page; |
|||
} |
|||
|
|||
protected <T> PageData<T> getPageData(List<?> list, long total, Class<T> target){ |
|||
List<T> targetList = ConvertUtils.sourceToTarget(list, target); |
|||
|
|||
return new PageData<>(targetList, total); |
|||
} |
|||
|
|||
protected <T> PageData<T> getPageData(IPage page, Class<T> target){ |
|||
return getPageData(page.getRecords(), page.getTotal(), target); |
|||
} |
|||
|
|||
protected void paramsToLike(Map<String, Object> params, String... likes){ |
|||
for (String like : likes){ |
|||
String val = (String)params.get(like); |
|||
if (StringUtils.isNotBlank(val)){ |
|||
params.put(like, "%" + val + "%"); |
|||
}else { |
|||
params.put(like, null); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* <p> |
|||
* 判断数据库操作是否成功 |
|||
* </p> |
|||
* <p> |
|||
* 注意!! 该方法为 Integer 判断,不可传入 int 基本类型 |
|||
* </p> |
|||
* |
|||
* @param result 数据库操作返回影响条数 |
|||
* @return boolean |
|||
*/ |
|||
protected static boolean retBool(Integer result) { |
|||
return SqlHelper.retBool(result); |
|||
} |
|||
|
|||
protected Class<M> currentMapperClass() { |
|||
return (Class<M>) ReflectionKit.getSuperClassGenericType(getClass(), 0); |
|||
} |
|||
|
|||
@Override |
|||
public Class<T> currentModelClass() { |
|||
return (Class<T>)ReflectionKit.getSuperClassGenericType(getClass(), 1); |
|||
} |
|||
|
|||
protected String getSqlStatement(SqlMethod sqlMethod) { |
|||
return SqlHelper.getSqlStatement(this.currentMapperClass(), sqlMethod); |
|||
} |
|||
|
|||
@Override |
|||
public boolean insert(T entity) { |
|||
return BaseServiceImpl.retBool(baseDao.insert(entity)); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean insertBatch(Collection<T> entityList) { |
|||
return insertBatch(entityList, 100); |
|||
} |
|||
|
|||
/** |
|||
* 批量插入 |
|||
*/ |
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean insertBatch(Collection<T> entityList, int batchSize) { |
|||
String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE); |
|||
return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); |
|||
} |
|||
|
|||
/** |
|||
* 执行批量操作 |
|||
*/ |
|||
protected <E> boolean executeBatch(Collection<E> list, int batchSize, BiConsumer<SqlSession, E> consumer) { |
|||
return SqlHelper.executeBatch(this.currentModelClass(), this.log, list, batchSize, consumer); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public boolean updateById(T entity) { |
|||
return BaseServiceImpl.retBool(baseDao.updateById(entity)); |
|||
} |
|||
|
|||
@Override |
|||
public boolean update(T entity, Wrapper<T> updateWrapper) { |
|||
return BaseServiceImpl.retBool(baseDao.update(entity, updateWrapper)); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean updateBatchById(Collection<T> entityList) { |
|||
return updateBatchById(entityList, 30); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean updateBatchById(Collection<T> entityList, int batchSize) { |
|||
String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID); |
|||
return executeBatch(entityList, batchSize, (sqlSession, entity) -> { |
|||
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); |
|||
param.put(Constants.ENTITY, entity); |
|||
sqlSession.update(sqlStatement, param); |
|||
}); |
|||
} |
|||
|
|||
@Override |
|||
public T selectById(Serializable id) { |
|||
return baseDao.selectById(id); |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteById(Serializable id) { |
|||
return SqlHelper.retBool(baseDao.deleteById(id)); |
|||
} |
|||
|
|||
@Override |
|||
public boolean deleteBatchIds(Collection<? extends Serializable> idList) { |
|||
return SqlHelper.retBool(baseDao.deleteBatchIds(idList)); |
|||
} |
|||
} |
@ -0,0 +1,72 @@ |
|||
package com.zhongyun.common.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.CrudService; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import org.springframework.beans.BeanUtils; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* CRUD基础服务类 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public abstract class CrudServiceImpl<M extends BaseMapper<T>, T, D> extends BaseServiceImpl<M, T> implements CrudService<T, D> { |
|||
|
|||
protected Class<D> currentDtoClass() { |
|||
return (Class<D>)ReflectionKit.getSuperClassGenericType(getClass(), 2); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<D> page(Map<String, Object> params) { |
|||
IPage<T> page = baseDao.selectPage( |
|||
getPage(params, null, false), |
|||
getWrapper(params) |
|||
); |
|||
|
|||
return getPageData(page, currentDtoClass()); |
|||
} |
|||
|
|||
@Override |
|||
public List<D> list(Map<String, Object> params) { |
|||
List<T> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, currentDtoClass()); |
|||
} |
|||
|
|||
public abstract QueryWrapper<T> getWrapper(Map<String, Object> params); |
|||
|
|||
@Override |
|||
public D get(Long id) { |
|||
T entity = baseDao.selectById(id); |
|||
|
|||
return ConvertUtils.sourceToTarget(entity, currentDtoClass()); |
|||
} |
|||
|
|||
@Override |
|||
public void save(D dto) { |
|||
T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); |
|||
insert(entity); |
|||
|
|||
//copy主键值到dto
|
|||
BeanUtils.copyProperties(entity, dto); |
|||
} |
|||
|
|||
@Override |
|||
public void update(D dto) { |
|||
T entity = ConvertUtils.sourceToTarget(dto, currentModelClass()); |
|||
updateById(entity); |
|||
} |
|||
|
|||
@Override |
|||
public void delete(Long[] ids) { |
|||
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|||
} |
|||
} |
@ -0,0 +1,54 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.utils; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.BeanUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 转换工具类 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public class ConvertUtils { |
|||
private static Logger logger = LoggerFactory.getLogger(ConvertUtils.class); |
|||
|
|||
public static <T> T sourceToTarget(Object source, Class<T> target){ |
|||
if(source == null){ |
|||
return null; |
|||
} |
|||
T targetObject = null; |
|||
try { |
|||
targetObject = target.newInstance(); |
|||
BeanUtils.copyProperties(source, targetObject); |
|||
} catch (Exception e) { |
|||
logger.error("convert error ", e); |
|||
} |
|||
|
|||
return targetObject; |
|||
} |
|||
|
|||
public static <T> List<T> sourceToTarget(Collection<?> sourceList, Class<T> target){ |
|||
if(sourceList == null){ |
|||
return null; |
|||
} |
|||
|
|||
List targetList = new ArrayList<>(sourceList.size()); |
|||
try { |
|||
for(Object source : sourceList){ |
|||
T targetObject = target.newInstance(); |
|||
BeanUtils.copyProperties(source, targetObject); |
|||
targetList.add(targetObject); |
|||
} |
|||
}catch (Exception e){ |
|||
logger.error("convert error ", e); |
|||
} |
|||
|
|||
return targetList; |
|||
} |
|||
} |
@ -0,0 +1,176 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.utils; |
|||
|
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.joda.time.DateTime; |
|||
import org.joda.time.LocalDate; |
|||
import org.joda.time.format.DateTimeFormat; |
|||
import org.joda.time.format.DateTimeFormatter; |
|||
|
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 日期处理 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public class DateUtils { |
|||
/** 时间格式(yyyy-MM-dd) */ |
|||
public final static String DATE_PATTERN = "yyyy-MM-dd"; |
|||
/** 时间格式(yyyy-MM-dd HH:mm:ss) */ |
|||
public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; |
|||
|
|||
/** |
|||
* 日期格式化 日期格式为:yyyy-MM-dd |
|||
* @param date 日期 |
|||
* @return 返回yyyy-MM-dd格式日期 |
|||
*/ |
|||
public static String format(Date date) { |
|||
return format(date, DATE_PATTERN); |
|||
} |
|||
|
|||
/** |
|||
* 日期格式化 日期格式为:yyyy-MM-dd |
|||
* @param date 日期 |
|||
* @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN |
|||
* @return 返回yyyy-MM-dd格式日期 |
|||
*/ |
|||
public static String format(Date date, String pattern) { |
|||
if(date != null){ |
|||
SimpleDateFormat df = new SimpleDateFormat(pattern); |
|||
return df.format(date); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 日期解析 |
|||
* @param date 日期 |
|||
* @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN |
|||
* @return 返回Date |
|||
*/ |
|||
public static Date parse(String date, String pattern) { |
|||
try { |
|||
return new SimpleDateFormat(pattern).parse(date); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 字符串转换成日期 |
|||
* @param strDate 日期字符串 |
|||
* @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN |
|||
*/ |
|||
public static Date stringToDate(String strDate, String pattern) { |
|||
if (StringUtils.isBlank(strDate)){ |
|||
return null; |
|||
} |
|||
|
|||
DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); |
|||
return fmt.parseLocalDateTime(strDate).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 根据周数,获取开始日期、结束日期 |
|||
* @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周 |
|||
* @return 返回date[0]开始日期、date[1]结束日期 |
|||
*/ |
|||
public static Date[] getWeekStartAndEnd(int week) { |
|||
DateTime dateTime = new DateTime(); |
|||
LocalDate date = new LocalDate(dateTime.plusWeeks(week)); |
|||
|
|||
date = date.dayOfWeek().withMinimumValue(); |
|||
Date beginDate = date.toDate(); |
|||
Date endDate = date.plusDays(6).toDate(); |
|||
return new Date[]{beginDate, endDate}; |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【秒】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param seconds 秒数,负数为减 |
|||
* @return 加/减几秒后的日期 |
|||
*/ |
|||
public static Date addDateSeconds(Date date, int seconds) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusSeconds(seconds).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【分钟】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param minutes 分钟数,负数为减 |
|||
* @return 加/减几分钟后的日期 |
|||
*/ |
|||
public static Date addDateMinutes(Date date, int minutes) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusMinutes(minutes).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【小时】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param hours 小时数,负数为减 |
|||
* @return 加/减几小时后的日期 |
|||
*/ |
|||
public static Date addDateHours(Date date, int hours) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusHours(hours).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【天】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param days 天数,负数为减 |
|||
* @return 加/减几天后的日期 |
|||
*/ |
|||
public static Date addDateDays(Date date, int days) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusDays(days).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【周】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param weeks 周数,负数为减 |
|||
* @return 加/减几周后的日期 |
|||
*/ |
|||
public static Date addDateWeeks(Date date, int weeks) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusWeeks(weeks).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【月】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param months 月数,负数为减 |
|||
* @return 加/减几月后的日期 |
|||
*/ |
|||
public static Date addDateMonths(Date date, int months) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusMonths(months).toDate(); |
|||
} |
|||
|
|||
/** |
|||
* 对日期的【年】进行加/减 |
|||
* |
|||
* @param date 日期 |
|||
* @param years 年数,负数为减 |
|||
* @return 加/减几年后的日期 |
|||
*/ |
|||
public static Date addDateYears(Date date, int years) { |
|||
DateTime dateTime = new DateTime(date); |
|||
return dateTime.plusYears(years).toDate(); |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.utils; |
|||
|
|||
import org.springframework.context.MessageSource; |
|||
import org.springframework.context.i18n.LocaleContextHolder; |
|||
|
|||
/** |
|||
* 国际化 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class MessageUtils { |
|||
private static MessageSource messageSource; |
|||
static { |
|||
messageSource = (MessageSource)SpringContextUtils.getBean("messageSource"); |
|||
} |
|||
|
|||
public static String getMessage(int code){ |
|||
return getMessage(code, new String[0]); |
|||
} |
|||
|
|||
public static String getMessage(int code, String... params){ |
|||
return messageSource.getMessage(code+"", params, LocaleContextHolder.getLocale()); |
|||
} |
|||
} |
@ -0,0 +1,92 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.utils; |
|||
|
|||
import com.zhongyun.common.exception.ErrorCode; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 响应数据 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@ApiModel(value = "响应") |
|||
public class Result<T> implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
/** |
|||
* 编码:0表示成功,其他值表示失败 |
|||
*/ |
|||
@ApiModelProperty(value = "编码:0表示成功,其他值表示失败") |
|||
private int code = 0; |
|||
/** |
|||
* 消息内容 |
|||
*/ |
|||
@ApiModelProperty(value = "消息内容") |
|||
private String msg = "success"; |
|||
/** |
|||
* 响应数据 |
|||
*/ |
|||
@ApiModelProperty(value = "响应数据") |
|||
private T data; |
|||
|
|||
public Result<T> ok(T data) { |
|||
this.setData(data); |
|||
return this; |
|||
} |
|||
|
|||
public boolean success(){ |
|||
return code == 0 ? true : false; |
|||
} |
|||
|
|||
public Result<T> error() { |
|||
this.code = ErrorCode.INTERNAL_SERVER_ERROR; |
|||
this.msg = MessageUtils.getMessage(this.code); |
|||
return this; |
|||
} |
|||
|
|||
public Result<T> error(int code) { |
|||
this.code = code; |
|||
this.msg = MessageUtils.getMessage(this.code); |
|||
return this; |
|||
} |
|||
|
|||
public Result<T> error(int code, String msg) { |
|||
this.code = code; |
|||
this.msg = msg; |
|||
return this; |
|||
} |
|||
|
|||
public Result<T> error(String msg) { |
|||
this.code = ErrorCode.INTERNAL_SERVER_ERROR; |
|||
this.msg = msg; |
|||
return this; |
|||
} |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(int code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
|
|||
public void setMsg(String msg) { |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public T getData() { |
|||
return data; |
|||
} |
|||
|
|||
public void setData(T data) { |
|||
this.data = data; |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.utils; |
|||
|
|||
import org.springframework.beans.BeansException; |
|||
import org.springframework.context.ApplicationContext; |
|||
import org.springframework.context.ApplicationContextAware; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* Spring Context 工具类 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Component |
|||
public class SpringContextUtils implements ApplicationContextAware { |
|||
public static ApplicationContext applicationContext; |
|||
|
|||
@Override |
|||
public void setApplicationContext(ApplicationContext applicationContext) |
|||
throws BeansException { |
|||
SpringContextUtils.applicationContext = applicationContext; |
|||
} |
|||
|
|||
public static Object getBean(String name) { |
|||
return applicationContext.getBean(name); |
|||
} |
|||
|
|||
public static <T> T getBean(Class<T> requiredType) { |
|||
return applicationContext.getBean(requiredType); |
|||
} |
|||
|
|||
public static <T> T getBean(String name, Class<T> requiredType) { |
|||
return applicationContext.getBean(name, requiredType); |
|||
} |
|||
|
|||
public static boolean containsBean(String name) { |
|||
return applicationContext.containsBean(name); |
|||
} |
|||
|
|||
public static boolean isSingleton(String name) { |
|||
return applicationContext.isSingleton(name); |
|||
} |
|||
|
|||
public static Class<? extends Object> getType(String name) { |
|||
return applicationContext.getType(name); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,92 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
import cn.hutool.core.map.MapUtil; |
|||
import cn.hutool.core.util.ArrayUtil; |
|||
import com.zhongyun.common.exception.ErrorCode; |
|||
import com.zhongyun.common.exception.RenException; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 校验工具类 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class AssertUtils { |
|||
|
|||
public static void isBlank(String str, String... params) { |
|||
isBlank(str, ErrorCode.NOT_NULL, params); |
|||
} |
|||
|
|||
public static void isBlank(String str, Integer code, String... params) { |
|||
if(code == null){ |
|||
throw new RenException(ErrorCode.NOT_NULL, "code"); |
|||
} |
|||
|
|||
if (StringUtils.isBlank(str)) { |
|||
throw new RenException(code, params); |
|||
} |
|||
} |
|||
|
|||
public static void isNull(Object object, String... params) { |
|||
isNull(object, ErrorCode.NOT_NULL, params); |
|||
} |
|||
|
|||
public static void isNull(Object object, Integer code, String... params) { |
|||
if(code == null){ |
|||
throw new RenException(ErrorCode.NOT_NULL, "code"); |
|||
} |
|||
|
|||
if (object == null) { |
|||
throw new RenException(code, params); |
|||
} |
|||
} |
|||
|
|||
public static void isArrayEmpty(Object[] array, String... params) { |
|||
isArrayEmpty(array, ErrorCode.NOT_NULL, params); |
|||
} |
|||
|
|||
public static void isArrayEmpty(Object[] array, Integer code, String... params) { |
|||
if(code == null){ |
|||
throw new RenException(ErrorCode.NOT_NULL, "code"); |
|||
} |
|||
|
|||
if(ArrayUtil.isEmpty(array)){ |
|||
throw new RenException(code, params); |
|||
} |
|||
} |
|||
|
|||
public static void isListEmpty(List<?> list, String... params) { |
|||
isListEmpty(list, ErrorCode.NOT_NULL, params); |
|||
} |
|||
|
|||
public static void isListEmpty(List<?> list, Integer code, String... params) { |
|||
if(code == null){ |
|||
throw new RenException(ErrorCode.NOT_NULL, "code"); |
|||
} |
|||
|
|||
if(CollUtil.isEmpty(list)){ |
|||
throw new RenException(code, params); |
|||
} |
|||
} |
|||
|
|||
public static void isMapEmpty(Map map, String... params) { |
|||
isMapEmpty(map, ErrorCode.NOT_NULL, params); |
|||
} |
|||
|
|||
public static void isMapEmpty(Map map, Integer code, String... params) { |
|||
if(code == null){ |
|||
throw new RenException(ErrorCode.NOT_NULL, "code"); |
|||
} |
|||
|
|||
if(MapUtil.isEmpty(map)){ |
|||
throw new RenException(code, params); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,51 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator; |
|||
|
|||
import com.zhongyun.common.exception.RenException; |
|||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; |
|||
import org.springframework.context.i18n.LocaleContextHolder; |
|||
import org.springframework.context.support.ResourceBundleMessageSource; |
|||
import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator; |
|||
|
|||
import javax.validation.ConstraintViolation; |
|||
import javax.validation.Validation; |
|||
import javax.validation.Validator; |
|||
import java.util.Locale; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* hibernate-validator校验工具类 |
|||
* 参考文档:http://docs.jboss.org/hibernate/validator/6.0/reference/en-US/html_single/
|
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public class ValidatorUtils { |
|||
|
|||
private static ResourceBundleMessageSource getMessageSource() { |
|||
ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource(); |
|||
bundleMessageSource.setDefaultEncoding("UTF-8"); |
|||
bundleMessageSource.setBasenames("i18n/validation"); |
|||
return bundleMessageSource; |
|||
} |
|||
|
|||
/** |
|||
* 校验对象 |
|||
* @param object 待校验对象 |
|||
* @param groups 待校验的组 |
|||
*/ |
|||
public static void validateEntity(Object object, Class<?>... groups) |
|||
throws RenException { |
|||
Locale.setDefault(LocaleContextHolder.getLocale()); |
|||
Validator validator = Validation.byDefaultProvider().configure().messageInterpolator( |
|||
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource()))) |
|||
.buildValidatorFactory().getValidator(); |
|||
|
|||
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); |
|||
if (!constraintViolations.isEmpty()) { |
|||
ConstraintViolation<Object> constraint = constraintViolations.iterator().next(); |
|||
throw new RenException(constraint.getMessage()); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator.group; |
|||
|
|||
/** |
|||
* 新增 Group |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface AddGroup { |
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator.group; |
|||
|
|||
/** |
|||
* 默认 Group |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface DefaultGroup { |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator.group; |
|||
|
|||
import javax.validation.GroupSequence; |
|||
|
|||
/** |
|||
* 定义校验顺序,如果AddGroup组失败,则UpdateGroup组不会再校验 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@GroupSequence({AddGroup.class, UpdateGroup.class}) |
|||
public interface Group { |
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.validator.group; |
|||
|
|||
/** |
|||
* 修改 Group |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface UpdateGroup { |
|||
|
|||
} |
@ -0,0 +1,197 @@ |
|||
<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"> |
|||
<parent> |
|||
<groupId>com.zhongyun</groupId> |
|||
<artifactId>zhongyun-points</artifactId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<artifactId>zhongyun-points-admin</artifactId> |
|||
<packaging>jar</packaging> |
|||
<description>zhongyun-points-admin</description> |
|||
|
|||
<properties> |
|||
<shiro.version>1.10.1</shiro.version> |
|||
<captcha.version>1.6.2</captcha.version> |
|||
<easyexcel.version>3.0.5</easyexcel.version> |
|||
<qiniu.version>7.2.27</qiniu.version> |
|||
<aliyun.oss.version>2.8.3</aliyun.oss.version> |
|||
<aliyun.core.version>3.2.2</aliyun.core.version> |
|||
<aliyun.dysmsapi.version>1.1.0</aliyun.dysmsapi.version> |
|||
<qcloud.cos.version>5.4.4</qcloud.cos.version> |
|||
<qcloud.qcloudsms.version>1.0.5</qcloud.qcloudsms.version> |
|||
<fastdfs.version>1.26.2</fastdfs.version> |
|||
<minio.version>8.4.5</minio.version> |
|||
<mail.version>1.6.2</mail.version> |
|||
<freemarker.version>2.3.31</freemarker.version> |
|||
<ureport2.version>2.2.9</ureport2.version> |
|||
<IJPay.version>2.8.2</IJPay.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.zhongyun</groupId> |
|||
<artifactId>zhongyun-common</artifactId> |
|||
<version>1.0.0</version> |
|||
</dependency> |
|||
|
|||
|
|||
<dependency> |
|||
<groupId>org.apache.shiro</groupId> |
|||
<artifactId>shiro-core</artifactId> |
|||
<version>${shiro.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.apache.shiro</groupId> |
|||
<artifactId>shiro-spring</artifactId> |
|||
<version>${shiro.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.whvcse</groupId> |
|||
<artifactId>easy-captcha</artifactId> |
|||
<version>${captcha.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>easyexcel</artifactId> |
|||
<version>${easyexcel.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.qiniu</groupId> |
|||
<artifactId>qiniu-java-sdk</artifactId> |
|||
<version>${qiniu.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.aliyun.oss</groupId> |
|||
<artifactId>aliyun-sdk-oss</artifactId> |
|||
<version>${aliyun.oss.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.qcloud</groupId> |
|||
<artifactId>cos_api</artifactId> |
|||
<version>${qcloud.cos.version}</version> |
|||
<exclusions> |
|||
<exclusion> |
|||
<groupId>org.slf4j</groupId> |
|||
<artifactId>slf4j-log4j12</artifactId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.aliyun</groupId> |
|||
<artifactId>aliyun-java-sdk-core</artifactId> |
|||
<version>${aliyun.core.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|||
<version>2.1.0.RELEASE</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> |
|||
<version>2.1.0.RELEASE</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.aliyun</groupId> |
|||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId> |
|||
<version>${aliyun.dysmsapi.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.qcloudsms</groupId> |
|||
<artifactId>qcloudsms</artifactId> |
|||
<version>${qcloud.qcloudsms.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.sun.mail</groupId> |
|||
<artifactId>javax.mail</artifactId> |
|||
<version>${mail.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.freemarker</groupId> |
|||
<artifactId>freemarker</artifactId> |
|||
<version>${freemarker.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.tobato</groupId> |
|||
<artifactId>fastdfs-client</artifactId> |
|||
<version>${fastdfs.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.minio</groupId> |
|||
<artifactId>minio</artifactId> |
|||
<version>${minio.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-websocket</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.bstek.ureport</groupId> |
|||
<artifactId>ureport2-console</artifactId> |
|||
<version>${ureport2.version}</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.javen205</groupId> |
|||
<artifactId>IJPay-AliPay</artifactId> |
|||
<version>${IJPay.version}</version> |
|||
<exclusions> |
|||
<exclusion> |
|||
<artifactId>fastjson</artifactId> |
|||
<groupId>com.alibaba</groupId> |
|||
</exclusion> |
|||
</exclusions> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.github.binarywang</groupId> |
|||
<artifactId>weixin-java-mp</artifactId> |
|||
<version>4.2.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.thoughtworks.xstream</groupId> |
|||
<artifactId>xstream</artifactId> |
|||
<version>1.4.20</version> |
|||
</dependency> |
|||
|
|||
<!-- 积木报表 --> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>org.jeecgframework.jimureport</groupId>--> |
|||
<!-- <artifactId>jimureport-spring-boot-starter</artifactId>--> |
|||
<!-- <version>1.5.0</version>--> |
|||
<!-- </dependency>--> |
|||
|
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<configuration> |
|||
<skipTests>true</skipTests> |
|||
</configuration> |
|||
</plugin> |
|||
<plugin> |
|||
<groupId>com.spotify</groupId> |
|||
<artifactId>docker-maven-plugin</artifactId> |
|||
<version>${docker.plugin.version}</version> |
|||
<configuration> |
|||
<imageName>zhongyun/${project.artifactId}</imageName> |
|||
<dockerDirectory>${project.basedir}/</dockerDirectory> |
|||
<resources> |
|||
<resource> |
|||
<targetPath>/</targetPath> |
|||
<directory>${project.build.directory}</directory> |
|||
<include>${project.build.finalName}.jar</include> |
|||
</resource> |
|||
</resources> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
</project> |
@ -0,0 +1,23 @@ |
|||
|
|||
|
|||
package com.zhongyun; |
|||
|
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
import org.springframework.boot.builder.SpringApplicationBuilder; |
|||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
|||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
|||
|
|||
@SpringBootApplication |
|||
@EnableDiscoveryClient |
|||
public class PointsAdminApplication extends SpringBootServletInitializer { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(PointsAdminApplication.class, args); |
|||
} |
|||
|
|||
@Override |
|||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { |
|||
return application.sources(PointsAdminApplication.class); |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
|
|||
|
|||
package com.zhongyun.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 操作日志注解 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface LogOperation { |
|||
|
|||
String value() default ""; |
|||
} |
@ -0,0 +1,66 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.cloud; |
|||
|
|||
import com.zhongyun.common.config.LocalCloudStorageConfig; |
|||
import com.zhongyun.common.exception.ErrorCode; |
|||
import com.zhongyun.common.exception.RenException; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import org.apache.commons.io.FileUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.util.Date; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* 本地上传 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Component |
|||
public class LocalCloudStorageService{ |
|||
|
|||
@Autowired |
|||
LocalCloudStorageConfig config; |
|||
|
|||
public String upload(byte[] data, String path) { |
|||
return upload(new ByteArrayInputStream(data), path); |
|||
} |
|||
|
|||
public String upload(InputStream inputStream, String path) { |
|||
File file = new File(config.getLocalPath() + File.separator + path); |
|||
try { |
|||
FileUtils.copyToFile(inputStream, file); |
|||
} catch (IOException e) { |
|||
throw new RenException(ErrorCode.OSS_UPLOAD_FILE_ERROR, e, ""); |
|||
} |
|||
return config.getLocalDomain() + "/" + path; |
|||
} |
|||
|
|||
public String uploadSuffix(byte[] data, String suffix) { |
|||
return upload(data, getPath(config.getLocalPrefix(), suffix)); |
|||
} |
|||
|
|||
public String uploadSuffix(InputStream inputStream, String suffix) { |
|||
return upload(inputStream, getPath(config.getLocalPrefix(), suffix)); |
|||
} |
|||
|
|||
public String getPath(String prefix, String suffix) { |
|||
//生成uuid
|
|||
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); |
|||
//文件路径
|
|||
String path = DateUtils.format(new Date(), "yyyyMMdd") + "/" + uuid; |
|||
|
|||
if(StringUtils.isNotBlank(prefix)){ |
|||
path = prefix + "/" + path; |
|||
} |
|||
|
|||
return path + "." + suffix; |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.zhongyun.common.config; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
@Configuration |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class LocalCloudStorageConfig { |
|||
|
|||
@Value("${local.localDomain}") |
|||
private String localDomain; |
|||
|
|||
@Value("${local.localPrefix}") |
|||
private String localPrefix; |
|||
|
|||
@Value("${local.localPath}") |
|||
private String localPath; |
|||
} |
@ -0,0 +1,37 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.config; |
|||
|
|||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
|||
//import com.zhongyun.common.interceptor.DataFilterInterceptor;
|
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* mybatis-plus配置 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
public class MybatisPlusConfig { |
|||
|
|||
@Bean |
|||
public MybatisPlusInterceptor mybatisPlusInterceptor() { |
|||
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); |
|||
// 数据权限
|
|||
// mybatisPlusInterceptor.addInnerInterceptor(new DataFilterInterceptor());
|
|||
// 分页插件
|
|||
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); |
|||
// 乐观锁
|
|||
mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); |
|||
// 防止全表更新与删除
|
|||
// mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
|||
|
|||
return mybatisPlusInterceptor; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,65 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.config; |
|||
|
|||
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.AllArgsConstructor; |
|||
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.service.ApiInfo; |
|||
import springfox.documentation.service.ApiKey; |
|||
import springfox.documentation.spi.DocumentationType; |
|||
import springfox.documentation.spring.web.plugins.Docket; |
|||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; |
|||
|
|||
import java.util.List; |
|||
import static com.google.common.collect.Lists.newArrayList; |
|||
|
|||
|
|||
/** |
|||
* Swagger配置 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Configuration |
|||
@EnableSwagger2WebMvc |
|||
@AllArgsConstructor |
|||
public class SwaggerConfig { |
|||
private final OpenApiExtensionResolver openApiExtensionResolver; |
|||
|
|||
@Bean |
|||
public Docket createRestApi() { |
|||
return new Docket(DocumentationType.SWAGGER_2) |
|||
.apiInfo(apiInfo()) |
|||
.select() |
|||
//加了ApiOperation注解的类,生成接口文档
|
|||
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
|||
//包下的类,生成接口文档
|
|||
//.apis(RequestHandlerSelectors.basePackage("com.zhongyun.modules.job.controller"))
|
|||
.paths(PathSelectors.any()) |
|||
.build() |
|||
.extensions(openApiExtensionResolver.buildExtensions("Zhongyun")) |
|||
.directModelSubstitute(java.util.Date.class, String.class) |
|||
.securitySchemes(security()); |
|||
} |
|||
|
|||
private ApiInfo apiInfo() { |
|||
return new ApiInfoBuilder() |
|||
.title("积分管理") |
|||
.description("points-admin文档") |
|||
.termsOfServiceUrl("") |
|||
.version("1.x") |
|||
.build(); |
|||
} |
|||
|
|||
private List<ApiKey> security() { |
|||
return newArrayList( |
|||
new ApiKey(Constant.TOKEN_HEADER, Constant.TOKEN_HEADER, "header") |
|||
); |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.group; |
|||
|
|||
/** |
|||
* 本地上传 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface LocalGroup { |
|||
} |
@ -0,0 +1,36 @@ |
|||
|
|||
|
|||
package com.zhongyun.common.handler; |
|||
|
|||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
|||
import org.apache.ibatis.reflection.MetaObject; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 公共字段,自动填充值 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Component |
|||
public class FieldMetaObjectHandler implements MetaObjectHandler { |
|||
private final static String CREATE_DATE = "createDate"; |
|||
private final static String UPDATE_DATE = "updateDate"; |
|||
|
|||
@Override |
|||
public void insertFill(MetaObject metaObject) { |
|||
Date date = new Date(); |
|||
|
|||
//创建时间
|
|||
strictInsertFill(metaObject, CREATE_DATE, Date.class, date); |
|||
//更新时间
|
|||
strictInsertFill(metaObject, UPDATE_DATE, Date.class, date); |
|||
} |
|||
|
|||
@Override |
|||
public void updateFill(MetaObject metaObject) { |
|||
//更新时间
|
|||
strictUpdateFill(metaObject, UPDATE_DATE, Date.class, new Date()); |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
package com.zhongyun.controller; |
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.common.validator.AssertUtils; |
|||
import com.zhongyun.common.validator.ValidatorUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import com.zhongyun.dto.DetailDTO; |
|||
import com.zhongyun.dto.EarnDTO; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.service.DetailService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("points/detail") |
|||
@Api(tags="积分明细") |
|||
public class DetailController { |
|||
@Autowired |
|||
private DetailService detailService; |
|||
|
|||
@GetMapping("page") |
|||
@ApiOperation("分页") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , |
|||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , |
|||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , |
|||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "startTime", value = "开始时间,格式2021-01-01", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "endTime", value = "结束时间,格式2021-01-01", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "id", value = "用户id", paramType = "query", dataType="Long") |
|||
|
|||
}) |
|||
public Result<PageData<DetailDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){ |
|||
PageData<DetailDTO> page = detailService.page(params); |
|||
|
|||
return new Result<PageData<DetailDTO>>().ok(page); |
|||
} |
|||
|
|||
|
|||
|
|||
@PostMapping("/earn") |
|||
@ApiOperation("获得积分") |
|||
@LogOperation("获得积分") |
|||
public Result earn(@RequestBody EarnDTO dto){ |
|||
|
|||
detailService.earn(dto); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,58 @@ |
|||
|
|||
|
|||
package com.zhongyun.controller; |
|||
|
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.dto.LevelDTO; |
|||
import com.zhongyun.service.LevelService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 等级 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@RestController |
|||
@RefreshScope |
|||
@RequestMapping("points/level") |
|||
@Api(tags="等级管理") |
|||
public class LevelController { |
|||
@Autowired |
|||
private LevelService levelService; |
|||
|
|||
@GetMapping("list") |
|||
@ApiOperation("列表") |
|||
public Result<List<LevelDTO>> list(){ |
|||
List<LevelDTO> list = levelService.list(); |
|||
|
|||
return new Result<List<LevelDTO>>().ok(list); |
|||
} |
|||
|
|||
@PostMapping |
|||
@ApiOperation("保存并生效") |
|||
@LogOperation("保存并生效") |
|||
public Result save(@RequestBody List<LevelDTO> dto){ |
|||
|
|||
levelService.updateBatch(dto); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,61 @@ |
|||
package com.zhongyun.controller; |
|||
|
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.common.validator.ValidatorUtils; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.service.RuleService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 规则 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@RestController |
|||
@RefreshScope |
|||
@RequestMapping("points/rule") |
|||
@Api(tags="规则管理") |
|||
public class RuleController { |
|||
@Autowired |
|||
private RuleService ruleService; |
|||
|
|||
@GetMapping("list") |
|||
@ApiOperation("列表") |
|||
@ApiImplicitParams({ |
|||
}) |
|||
public Result<List<RuleDTO>> list(@ApiIgnore @RequestParam Map<String, Object> params){ |
|||
List<RuleDTO> list = ruleService.list(params); |
|||
|
|||
return new Result<List<RuleDTO>>().ok(list); |
|||
} |
|||
|
|||
@PutMapping |
|||
@ApiOperation("修改") |
|||
@LogOperation("修改") |
|||
public Result update(RuleDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
|
|||
ruleService.update(dto); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,64 @@ |
|||
package com.zhongyun.controller; |
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.common.validator.AssertUtils; |
|||
import com.zhongyun.common.validator.ValidatorUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import com.zhongyun.dto.*; |
|||
import com.zhongyun.service.DetailService; |
|||
import com.zhongyun.service.StatisticsService; |
|||
import io.swagger.annotations.*; |
|||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 数据概况 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("points/statistics") |
|||
@Api(tags="数据概况") |
|||
public class StatisticsController { |
|||
@Autowired |
|||
private StatisticsService statisticsService; |
|||
|
|||
@GetMapping("month") |
|||
@ApiOperation("积分趋势") |
|||
public Result<List<MonthDTO>> page(){ |
|||
List<MonthDTO> list = statisticsService.month(); |
|||
|
|||
return new Result<List<MonthDTO>>().ok(list); |
|||
} |
|||
|
|||
@GetMapping("statistics") |
|||
@ApiOperation("数据总况") |
|||
public Result<StatisticsDTO> statistics(){ |
|||
StatisticsDTO list = statisticsService.statistics(); |
|||
|
|||
return new Result<StatisticsDTO>().ok(list); |
|||
} |
|||
|
|||
|
|||
@GetMapping("transform/{period}") |
|||
@ApiOperation("转化概况") |
|||
@ApiImplicitParam(name = "period", value = "统计周期可以取值all.year,month,day,week", paramType = "query", dataType="string") |
|||
public Result<TransformDTO> transform(@PathVariable("period") String period){ |
|||
TransformDTO transform = statisticsService.transform(period); |
|||
return new Result<TransformDTO>().ok(transform); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,54 @@ |
|||
|
|||
|
|||
package com.zhongyun.controller; |
|||
|
|||
import com.zhongyun.common.cloud.LocalCloudStorageService; |
|||
import com.zhongyun.common.exception.ErrorCode; |
|||
import com.zhongyun.common.utils.Result; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.commons.io.FilenameUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 文件上传 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@RestController |
|||
@RefreshScope |
|||
@RequestMapping("sys/oss") |
|||
@Api(tags="文件上传") |
|||
public class SysOssController { |
|||
|
|||
|
|||
@Autowired |
|||
private LocalCloudStorageService localCloudStorageService; |
|||
|
|||
@PostMapping("upload") |
|||
@ApiOperation(value = "上传文件") |
|||
public Result<Map<String, Object>> upload(@RequestParam("file") MultipartFile file) throws Exception { |
|||
if (file.isEmpty()) { |
|||
return new Result<Map<String, Object>>().error(ErrorCode.UPLOAD_FILE_EMPTY); |
|||
} |
|||
|
|||
//上传文件
|
|||
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
|||
String url = localCloudStorageService.uploadSuffix(file.getBytes(), extension); |
|||
|
|||
Map<String, Object> data = new HashMap<>(1); |
|||
data.put("src", url); |
|||
|
|||
return new Result<Map<String, Object>>().ok(data); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,90 @@ |
|||
package com.zhongyun.controller; |
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.common.validator.AssertUtils; |
|||
import com.zhongyun.common.validator.ValidatorUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.service.UserService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("points/user") |
|||
@Api(tags="积分用户") |
|||
public class UserController { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@GetMapping("page") |
|||
@ApiOperation("分页") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") , |
|||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") , |
|||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") , |
|||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "startTime", value = "开始时间,格式2021-01-01", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "endTime", value = "结束时间,格式2021-01-01", paramType = "query", dataType="String"), |
|||
@ApiImplicitParam(name = "mobile", value = "手机号", paramType = "query", dataType="String") |
|||
|
|||
}) |
|||
public Result<PageData<UserDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){ |
|||
PageData<UserDTO> page = userService.page(params); |
|||
|
|||
return new Result<PageData<UserDTO>>().ok(page); |
|||
} |
|||
@GetMapping("total-top") |
|||
@ApiOperation("获取积分top") |
|||
public Result<List<UserDTO>> totalTop(){ |
|||
List<UserDTO> list = userService.top("total"); |
|||
|
|||
return new Result<List<UserDTO>>().ok(list); |
|||
} |
|||
@GetMapping("used-top") |
|||
@ApiOperation("使用积分top") |
|||
public Result<List<UserDTO>> useTop(){ |
|||
List<UserDTO> list = userService.top("used"); |
|||
|
|||
return new Result< List<UserDTO>>().ok(list); |
|||
} |
|||
|
|||
@PostMapping("list") |
|||
@ApiOperation("通过id获取用户信息") |
|||
@LogOperation("通过id获取用户信息") |
|||
public Result<List<UserDTO>> list(@RequestBody Long[] ids){ |
|||
//效验数据
|
|||
AssertUtils.isArrayEmpty(ids, "id"); |
|||
|
|||
List<UserDTO> list = userService.getInfobyIds(ids); |
|||
|
|||
return new Result< List<UserDTO>>().ok(list); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,59 @@ |
|||
package com.zhongyun.controller; |
|||
|
|||
import com.zhongyun.annotation.LogOperation; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.utils.Result; |
|||
import com.zhongyun.common.validator.AssertUtils; |
|||
import com.zhongyun.common.validator.ValidatorUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import com.zhongyun.dto.ValidityDTO; |
|||
import com.zhongyun.service.ValidityService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.shiro.authz.annotation.RequiresPermissions; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("points/validity") |
|||
@Api(tags="积分有效期") |
|||
public class ValidityController { |
|||
@Autowired |
|||
private ValidityService validityService; |
|||
|
|||
@GetMapping("") |
|||
@ApiOperation("信息") |
|||
public Result<ValidityDTO> get(){ |
|||
ValidityDTO data = validityService.getInfo(); |
|||
|
|||
return new Result<ValidityDTO>().ok(data); |
|||
} |
|||
|
|||
@PutMapping |
|||
@ApiOperation("修改") |
|||
@LogOperation("修改") |
|||
public Result update(@RequestBody ValidityDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
|
|||
validityService.update(dto); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.entity.DetailEntity; |
|||
import com.zhongyun.entity.UserEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Mapper |
|||
public interface DetailDao extends BaseDao<DetailEntity> { |
|||
List<DetailEntity> getList(Map<String, Object> params); |
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
|
|||
|
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.entity.LevelEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Mapper |
|||
public interface LevelDao extends BaseDao<LevelEntity> { |
|||
|
|||
List<LevelEntity> getList(); |
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
|
|||
|
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Mapper |
|||
public interface RuleDao extends BaseDao<RuleEntity> { |
|||
|
|||
List<RuleEntity> getList(Map<String, Object> params); |
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.dto.MonthDTO; |
|||
import com.zhongyun.dto.StatisticsDTO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Mapper |
|||
public interface StatisticsDao extends BaseDao<MonthDTO> { |
|||
|
|||
|
|||
List<MonthDTO> month(); |
|||
StatisticsDTO getStatistics(); |
|||
|
|||
int getEarnPeople(String period); |
|||
int getUsedPeople(String period); |
|||
int getEarnNum(String period); |
|||
int getUsedNum(String period); |
|||
|
|||
|
|||
} |
@ -0,0 +1,18 @@ |
|||
|
|||
|
|||
package com.zhongyun.dao; |
|||
|
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.entity.SysOssEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 文件上传 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Mapper |
|||
public interface SysOssDao extends BaseDao<SysOssEntity> { |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.entity.UserEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
@Mapper |
|||
public interface UserDao extends BaseDao<UserEntity> { |
|||
|
|||
List<UserEntity> getList(Map<String, Object> params); |
|||
|
|||
List<UserEntity> getTop(String orderField); |
|||
|
|||
List<UserEntity> getInfobyIds(Long[] ids); |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.zhongyun.dao; |
|||
|
|||
import com.zhongyun.common.dao.BaseDao; |
|||
import com.zhongyun.entity.ValidityEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Mapper |
|||
public interface ValidityDao extends BaseDao<ValidityEntity> { |
|||
|
|||
|
|||
void updateUserPoints(); |
|||
|
|||
} |
@ -0,0 +1,48 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.time.LocalDateTime; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "积分明细") |
|||
public class DetailDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "id") |
|||
private Long id; |
|||
@ApiModelProperty(value = "规则id") |
|||
private Long ruleId; |
|||
@ApiModelProperty(value = "时间") |
|||
private Date createDate; |
|||
@ApiModelProperty(value = "积分变化") |
|||
private Integer num; |
|||
@ApiModelProperty(value = "可用积分") |
|||
private Integer availability; |
|||
@ApiModelProperty(value = "积分用户id") |
|||
private Long pointsId; |
|||
@ApiModelProperty(value = "0消耗1获得") |
|||
private Integer flag; |
|||
@ApiModelProperty(value = "有效时间") |
|||
private Date validityDate; |
|||
@ApiModelProperty(value = "有效期(月)") |
|||
private Integer validityMonth; |
|||
@ApiModelProperty(value = "有效标志0无效1有效") |
|||
private Integer validityFlag; |
|||
@ApiModelProperty(value = "活动名称") |
|||
private String ruleName; |
|||
|
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "获得积分") |
|||
public class EarnDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
|
|||
@ApiModelProperty(value = "规则id") |
|||
private Long ruleId; |
|||
@ApiModelProperty(value = "user_wechat_h5的id") |
|||
private String wechatH5Id; |
|||
} |
@ -0,0 +1,50 @@ |
|||
|
|||
|
|||
package com.zhongyun.dto; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.DefaultGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.Null; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
*等级管理 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "等级管理") |
|||
public class LevelDTO implements Serializable { |
|||
|
|||
|
|||
|
|||
@ApiModelProperty(value = "等级名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value = "等级勋章") |
|||
private String icon; |
|||
|
|||
@ApiModelProperty(value = "所需积分") |
|||
private int points; |
|||
|
|||
@ApiModelProperty(value = "排序") |
|||
private int sort; |
|||
|
|||
|
|||
@ApiModelProperty(value = "创建时间") |
|||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
|||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) |
|||
private Date updateDate; |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "积分趋势") |
|||
public class MonthDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "发放文明币数") |
|||
private Integer total; |
|||
@ApiModelProperty(value = "使用文明币数") |
|||
private Integer used; |
|||
@ApiModelProperty(value = "年月") |
|||
private String month; |
|||
|
|||
} |
@ -0,0 +1,54 @@ |
|||
|
|||
|
|||
package com.zhongyun.dto; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import com.zhongyun.common.validator.group.AddGroup; |
|||
import com.zhongyun.common.validator.group.UpdateGroup; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.Null; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
*规则管理 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "规则管理") |
|||
public class RuleDTO implements Serializable { |
|||
|
|||
|
|||
@ApiModelProperty(value = "id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value = "活动名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value = "规则类型(0:具体值,1:按公式计算)") |
|||
private int flag; |
|||
|
|||
@ApiModelProperty(value = "获得积分") |
|||
private int points; |
|||
|
|||
@ApiModelProperty(value = "启用状态(0:不启用,1:启用)") |
|||
private int status; |
|||
|
|||
@ApiModelProperty(value = "更新时间") |
|||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
|||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) |
|||
private Date updateDate; |
|||
|
|||
|
|||
@ApiModelProperty(value = "更新者") |
|||
private Long updater; |
|||
|
|||
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "数据总况") |
|||
public class StatisticsDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "可用文明币") |
|||
private Integer availability; |
|||
@ApiModelProperty(value = "冻结文明币") |
|||
private Integer blocked; |
|||
@ApiModelProperty(value = "发放文明币") |
|||
private Integer total; |
|||
@ApiModelProperty(value = "使用文明币") |
|||
private Integer used; |
|||
|
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "转化概况") |
|||
public class TransformDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "平台访客总数") |
|||
private int userNum; |
|||
@ApiModelProperty(value = "获取人数") |
|||
private int earnPeople; |
|||
@ApiModelProperty(value = "使用人数") |
|||
private int usedPeople; |
|||
@ApiModelProperty(value = "累计发放数") |
|||
private int earnNum; |
|||
@ApiModelProperty(value = "累计使用数") |
|||
private int usedNum; |
|||
@ApiModelProperty(value = "人均使用数") |
|||
private String avgUsed; |
|||
@ApiModelProperty(value = "访客获取转化率") |
|||
private String earnPercent; |
|||
@ApiModelProperty(value = "获取使用转化率") |
|||
private String usedPercent; |
|||
@ApiModelProperty(value = "访客使用转化率") |
|||
private String userUsedPercent; |
|||
|
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "积分用户") |
|||
public class UserDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "积分用户id") |
|||
private Long id; |
|||
@ApiModelProperty(value = "user_wechat_h5的id") |
|||
private String wechatH5Id; |
|||
@ApiModelProperty(value = "总积分") |
|||
private Integer total; |
|||
@ApiModelProperty(value = "可用积分") |
|||
private Integer availability; |
|||
@ApiModelProperty(value = "冻结积分") |
|||
private Integer blocked; |
|||
@ApiModelProperty(value = "首次时间") |
|||
private Date firstDate; |
|||
@ApiModelProperty(value = "活动次数") |
|||
private Integer actNum; |
|||
@ApiModelProperty(value = "等级id") |
|||
private Long levelId; |
|||
@ApiModelProperty(value = "等级名称") |
|||
private String levelName; |
|||
@ApiModelProperty(value = "手机号") |
|||
private String mobile; |
|||
@ApiModelProperty(value = "昵称") |
|||
private String nickname; |
|||
@ApiModelProperty(value = "使用总积分") |
|||
private Integer used; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.zhongyun.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import java.io.Serializable; |
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "积分有效期") |
|||
public class ValidityDTO implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "id") |
|||
private Long id; |
|||
@ApiModelProperty(value = "有效期月份") |
|||
private Integer month; |
|||
@ApiModelProperty(value = "有效期类型0:具体值,1:永久有效") |
|||
private Integer flag; |
|||
|
|||
} |
@ -0,0 +1,73 @@ |
|||
package com.zhongyun.entity; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.zhongyun.common.entity.BaseEntity; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("points_detail") |
|||
public class DetailEntity { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
|
|||
/** |
|||
* 规则id |
|||
*/ |
|||
private Long ruleId; |
|||
/** |
|||
* 积分变化 |
|||
*/ |
|||
private Integer num; |
|||
/** |
|||
* 可用积分 |
|||
*/ |
|||
private Integer availability; |
|||
/** |
|||
* 积分用户id |
|||
*/ |
|||
private Long pointsId; |
|||
/** |
|||
* 0消耗1获得 |
|||
*/ |
|||
private Integer flag; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
private Date createDate; |
|||
/** |
|||
* 有效时间 |
|||
*/ |
|||
private Date validityDate; |
|||
/** |
|||
* 有效期(月) |
|||
*/ |
|||
private Integer validityMonth; |
|||
/** |
|||
* 有效标志0无效1有效 |
|||
*/ |
|||
private Integer validityFlag; |
|||
/** |
|||
* 活动名称 |
|||
*/ |
|||
@TableField(exist=false) |
|||
private String ruleName; |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,63 @@ |
|||
|
|||
|
|||
package com.zhongyun.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import com.zhongyun.common.entity.BaseEntity; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("points_level") |
|||
public class LevelEntity implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
|
|||
/** |
|||
* 等级名称 |
|||
*/ |
|||
private String name; |
|||
|
|||
/** |
|||
* 等级勋章 |
|||
*/ |
|||
private String icon; |
|||
|
|||
/** |
|||
* 所需积分 |
|||
*/ |
|||
private int points; |
|||
|
|||
/** |
|||
* 排序 |
|||
*/ |
|||
private int sort; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private Date updateDate; |
|||
|
|||
} |
@ -0,0 +1,62 @@ |
|||
|
|||
|
|||
package com.zhongyun.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("points_rule") |
|||
public class RuleEntity implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
private Long id; |
|||
/** |
|||
* 活动名称 |
|||
*/ |
|||
private String name; |
|||
/** |
|||
* 规则类型(0:具体值,1:按公式计算) |
|||
*/ |
|||
private int flag; |
|||
/** |
|||
* 获得积分 |
|||
*/ |
|||
private int points; |
|||
/** |
|||
* 启用状态(0:不启用,1:启用) |
|||
*/ |
|||
private int status; |
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT_UPDATE) |
|||
private Date updateDate; |
|||
|
|||
/** |
|||
* 更新者 |
|||
*/ |
|||
private Long updater; |
|||
|
|||
|
|||
} |
@ -0,0 +1,43 @@ |
|||
|
|||
|
|||
package com.zhongyun.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.zhongyun.common.utils.DateUtils; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 文件上传 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
@Data |
|||
@TableName("points_oss") |
|||
public class SysOssEntity { |
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
/** |
|||
* URL地址 |
|||
*/ |
|||
private String url; |
|||
/** |
|||
* 创建者 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Long creator; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN) |
|||
private Date createDate; |
|||
} |
@ -0,0 +1,75 @@ |
|||
package com.zhongyun.entity; |
|||
|
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import java.util.Date; |
|||
import com.zhongyun.common.entity.BaseEntity; |
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("points_user") |
|||
public class UserEntity { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
|
|||
/** |
|||
* 总积分 |
|||
*/ |
|||
private Integer total; |
|||
/** |
|||
* 使用总积分 |
|||
*/ |
|||
private Integer used; |
|||
/** |
|||
* 可用积分 |
|||
*/ |
|||
private Integer availability; |
|||
/** |
|||
* 冻结积分 |
|||
*/ |
|||
private Integer blocked; |
|||
/** |
|||
* 首次时间 |
|||
*/ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private Date createDate; /** |
|||
* 活动次数 |
|||
*/ |
|||
private Integer actNum; |
|||
/** |
|||
* 等级id |
|||
*/ |
|||
private Long levelId; |
|||
|
|||
|
|||
private String wechatH5Id; |
|||
/** |
|||
* 等级名称 |
|||
*/ |
|||
@TableField(exist=false) |
|||
private String levelName; |
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
@TableField(exist=false) |
|||
private String mobile; |
|||
/** |
|||
* 昵称 |
|||
*/ |
|||
@TableField(exist=false) |
|||
private String nickname; |
|||
|
|||
} |
@ -0,0 +1,39 @@ |
|||
package com.zhongyun.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("points_validity") |
|||
public class ValidityEntity { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
|
|||
/** |
|||
* 有效期月份 |
|||
*/ |
|||
private Integer month; |
|||
/** |
|||
* 有效期类型(0:具体值,1:永久有效) |
|||
*/ |
|||
private Integer flag; |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.zhongyun.scheduler; |
|||
|
|||
import com.zhongyun.service.DetailService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.EnableScheduling; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import java.util.concurrent.ScheduledExecutorService; |
|||
|
|||
|
|||
@Component |
|||
@EnableScheduling |
|||
@Slf4j |
|||
public class PointExpirationScheduler { |
|||
private ScheduledExecutorService scheduler; |
|||
@Autowired |
|||
private DetailService detailService; |
|||
|
|||
@Scheduled(cron = "0 0 23 * * ?") |
|||
public void start() { |
|||
detailService.PointExpiration(); |
|||
log.info("开始释放积分"); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.zhongyun.service; |
|||
|
|||
|
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.CrudService; |
|||
import com.zhongyun.dto.DetailDTO; |
|||
import com.zhongyun.dto.EarnDTO; |
|||
import com.zhongyun.dto.LevelDTO; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.entity.DetailEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
public interface DetailService extends CrudService<DetailEntity, DetailDTO> { |
|||
|
|||
void earn(EarnDTO dto); |
|||
|
|||
void PointExpiration() ; |
|||
|
|||
PageData<DetailDTO> page(Map<String, Object> params); |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,25 @@ |
|||
|
|||
|
|||
package com.zhongyun.service; |
|||
|
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.BaseService; |
|||
import com.zhongyun.dto.LevelDTO; |
|||
import com.zhongyun.entity.LevelEntity; |
|||
|
|||
import java.util.Collection; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface LevelService extends BaseService<LevelEntity> { |
|||
|
|||
List<LevelDTO> list(); |
|||
void updateBatch(List<LevelDTO> dtoList); |
|||
|
|||
} |
|||
|
@ -0,0 +1,28 @@ |
|||
|
|||
|
|||
package com.zhongyun.service; |
|||
|
|||
import com.zhongyun.common.service.BaseService; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 新闻 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
*/ |
|||
public interface RuleService extends BaseService<RuleEntity> { |
|||
|
|||
List<RuleDTO> list(Map<String, Object> params); |
|||
|
|||
void update(RuleDTO dto); |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,30 @@ |
|||
package com.zhongyun.service; |
|||
|
|||
|
|||
import com.zhongyun.common.service.BaseService; |
|||
import com.zhongyun.common.service.CrudService; |
|||
import com.zhongyun.dto.MonthDTO; |
|||
import com.zhongyun.dto.StatisticsDTO; |
|||
import com.zhongyun.dto.TransformDTO; |
|||
import com.zhongyun.dto.ValidityDTO; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import com.zhongyun.entity.ValidityEntity; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
public interface StatisticsService extends BaseService<MonthDTO> { |
|||
|
|||
List<MonthDTO> month(); |
|||
StatisticsDTO statistics(); |
|||
TransformDTO transform(String period); |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.zhongyun.service; |
|||
|
|||
|
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.CrudService; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.entity.UserEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
public interface UserService extends CrudService<UserEntity, UserDTO> { |
|||
|
|||
PageData<UserDTO> page(Map<String, Object> params); |
|||
|
|||
List<UserDTO> top(String orderField); |
|||
|
|||
List<UserDTO> getInfobyIds(Long[] ids); |
|||
|
|||
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.zhongyun.service; |
|||
|
|||
|
|||
import com.zhongyun.common.service.CrudService; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.ValidityDTO; |
|||
import com.zhongyun.entity.ValidityEntity; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
public interface ValidityService extends CrudService<ValidityEntity, ValidityDTO> { |
|||
|
|||
ValidityDTO getInfo(); |
|||
|
|||
} |
@ -0,0 +1,202 @@ |
|||
package com.zhongyun.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.zhongyun.common.exception.RenException; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.impl.CrudServiceImpl; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import com.zhongyun.dao.*; |
|||
import com.zhongyun.dto.*; |
|||
import com.zhongyun.entity.DetailEntity; |
|||
import com.zhongyun.entity.LevelEntity; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import com.zhongyun.entity.UserEntity; |
|||
import com.zhongyun.service.DetailService; |
|||
import com.zhongyun.service.LevelService; |
|||
import com.zhongyun.service.UserService; |
|||
import com.zhongyun.service.ValidityService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.text.DateFormat; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 积分明细 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Service |
|||
public class DetailServiceImpl extends CrudServiceImpl<DetailDao, DetailEntity, DetailDTO> implements DetailService { |
|||
@Autowired |
|||
private UserDao userDao; |
|||
@Autowired |
|||
private UserService userService; |
|||
@Autowired |
|||
private RuleDao ruleDao; |
|||
@Autowired |
|||
private ValidityService validityService; |
|||
@Autowired |
|||
private LevelDao levelDao; |
|||
@Autowired |
|||
private ValidityDao validityDao; |
|||
|
|||
|
|||
|
|||
@Override |
|||
public QueryWrapper<DetailEntity> getWrapper(Map<String, Object> params){ |
|||
QueryWrapper<DetailEntity> wrapper = new QueryWrapper<>(); |
|||
|
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
@Override |
|||
public PageData<DetailDTO> page(Map<String, Object> params) { |
|||
//转换成like
|
|||
IPage<DetailEntity> page = getPage(params, "create_date", false); |
|||
|
|||
List<DetailEntity> list = baseDao.getList(params); |
|||
getPageData(list, page.getTotal(), DetailDTO.class); |
|||
|
|||
return getPageData(list, page.getTotal(), DetailDTO.class); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public void PointExpiration() { |
|||
|
|||
QueryWrapper<DetailEntity> wrapper = new QueryWrapper<>(); |
|||
wrapper.le("validity_date",new Date()); |
|||
wrapper.eq("validity_flag",1); |
|||
DetailEntity detail = new DetailEntity(); |
|||
detail.setValidityFlag(0); |
|||
update(detail,wrapper); |
|||
validityDao.updateUserPoints(); |
|||
} |
|||
|
|||
|
|||
|
|||
@Override |
|||
@Transactional |
|||
public void earn(EarnDTO dto) { |
|||
// 获得积分规则
|
|||
QueryWrapper<RuleEntity> roleWrapper = new QueryWrapper<>(); |
|||
Long ruleId = dto.getRuleId(); |
|||
roleWrapper.eq("id", ruleId); |
|||
RuleEntity ruleEntity = ruleDao.selectOne(roleWrapper); |
|||
UserDTO userDTO = new UserDTO(); |
|||
DetailDTO detailDTO = new DetailDTO(); |
|||
ValidityDTO validity = validityService.getInfo(); |
|||
// 获得积分规则是否关闭
|
|||
if (ruleEntity.getStatus()==1){ |
|||
if(ruleEntity.getFlag()==0){ |
|||
// 检查是否存在用户,不存在则插入,存在则更新
|
|||
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>(); |
|||
String wechatH5Id = dto.getWechatH5Id(); |
|||
wrapper.eq(StringUtils.isNotBlank(wechatH5Id), "wechat_h5_id", wechatH5Id); |
|||
UserEntity userEntity = userDao.selectOne(wrapper); |
|||
if (userEntity == null){ |
|||
userDTO.setActNum(1); |
|||
userDTO.setAvailability(ruleEntity.getPoints()); |
|||
userDTO.setBlocked(0); |
|||
userDTO.setTotal(ruleEntity.getPoints()); |
|||
userDTO.setLevelId(getLevel(userDTO.getTotal())); |
|||
userDTO.setWechatH5Id(wechatH5Id); |
|||
userService.save(userDTO); |
|||
userEntity = userDao.selectOne(wrapper); |
|||
}else { |
|||
userDTO.setId(userEntity.getId()); |
|||
userDTO.setActNum(userEntity.getActNum()+1); |
|||
userDTO.setAvailability(ruleEntity.getPoints()+userEntity.getTotal()); |
|||
userDTO.setTotal(ruleEntity.getPoints()+userEntity.getAvailability()); |
|||
userDTO.setLevelId(getLevel(userDTO.getTotal())); |
|||
userDTO.setWechatH5Id(wechatH5Id); |
|||
userService.update(userDTO); |
|||
} |
|||
if (validity.getFlag()==0){ |
|||
detailDTO.setValidityDate(getValidityDate(validity.getMonth(),0)); |
|||
detailDTO.setValidityMonth(validity.getMonth()); |
|||
}else { |
|||
//长期有效去最大时间
|
|||
detailDTO.setValidityDate(getValidityDate(0,1)); |
|||
} |
|||
|
|||
detailDTO.setRuleId(ruleId); |
|||
detailDTO.setAvailability(userDTO.getAvailability()); |
|||
detailDTO.setNum(ruleEntity.getPoints()); |
|||
detailDTO.setFlag(1); |
|||
detailDTO.setPointsId(userEntity.getId()); |
|||
detailDTO.setCreateDate(new Date()); |
|||
detailDTO.setValidityFlag(1); |
|||
save(detailDTO); |
|||
|
|||
}else { |
|||
//积分规则flag=1,也就是计算公式方式,如何处理???
|
|||
} |
|||
}else { |
|||
//积分规则status !=1 说明规则关闭
|
|||
throw new RenException(ruleEntity.getName() + "已关闭"); |
|||
} |
|||
|
|||
} |
|||
|
|||
// 根据数值测算积分等级
|
|||
private Long getLevel(int points){ |
|||
List<LevelEntity> list = levelDao.getList(); |
|||
Long level =null; |
|||
if (points<list.get(0).getPoints()){ |
|||
return level; |
|||
|
|||
}else if (points>=list.get(list.size()-1).getPoints()){ |
|||
return list.get(list.size()-1).getId(); |
|||
}else { |
|||
for (int i = 0; i < list.size(); i++) { |
|||
if (points>=list.get(i).getPoints() && points<list.get(i+1).getPoints()){ |
|||
level=list.get(i).getId(); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return level; |
|||
|
|||
} |
|||
|
|||
private Date getValidityDate(int month,int flag){ |
|||
|
|||
Date currentDate = new Date(); |
|||
|
|||
if (flag==0){ |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(currentDate); |
|||
calendar.add(Calendar.MONTH, month); |
|||
return calendar.getTime(); |
|||
}else { |
|||
String dateString = "5000-12-31 23:59:59"; |
|||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS"); |
|||
dateFormat.setTimeZone(TimeZone.getDefault()); |
|||
Date date = null; |
|||
try { |
|||
date = dateFormat.parse(dateString); |
|||
} catch (ParseException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return date; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
|
|||
|
|||
package com.zhongyun.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.zhongyun.common.constant.Constant; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.impl.BaseServiceImpl; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import com.zhongyun.dao.LevelDao; |
|||
import com.zhongyun.dto.LevelDTO; |
|||
import com.zhongyun.entity.LevelEntity; |
|||
import com.zhongyun.service.LevelService; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
@Service |
|||
public class LevelServiceImpl extends BaseServiceImpl<LevelDao, LevelEntity> implements LevelService { |
|||
|
|||
|
|||
|
|||
@Override |
|||
public List<LevelDTO> list() { |
|||
|
|||
List<LevelEntity> list = baseDao.getList(); |
|||
|
|||
|
|||
return ConvertUtils.sourceToTarget(list,LevelDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional |
|||
public void updateBatch(List<LevelDTO> dtoList) { |
|||
List<LevelEntity> levelEntities = ConvertUtils.sourceToTarget(dtoList, LevelEntity.class); |
|||
QueryWrapper<LevelEntity> wrapper = new QueryWrapper<>(); |
|||
baseDao.delete(wrapper); |
|||
insertBatch(levelEntities); |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
|
|||
|
|||
package com.zhongyun.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.zhongyun.common.service.impl.BaseServiceImpl; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import com.zhongyun.dao.RuleDao; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.dto.RuleDTO; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import com.zhongyun.entity.RuleEntity; |
|||
import com.zhongyun.service.RuleService; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
@Service |
|||
public class RulelServiceImpl extends BaseServiceImpl<RuleDao, RuleEntity> implements RuleService { |
|||
|
|||
|
|||
|
|||
@Override |
|||
public List<RuleDTO> list(Map<String, Object> params) { |
|||
|
|||
List<RuleEntity> list = baseDao.getList(params); |
|||
|
|||
return ConvertUtils.sourceToTarget(list,RuleDTO.class); |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void update(RuleDTO dto) { |
|||
RuleEntity entity = ConvertUtils.sourceToTarget(dto, RuleEntity.class); |
|||
|
|||
updateById(entity); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,62 @@ |
|||
package com.zhongyun.service.impl; |
|||
|
|||
|
|||
import com.zhongyun.common.service.impl.BaseServiceImpl; |
|||
import com.zhongyun.dao.StatisticsDao; |
|||
import com.zhongyun.dto.MonthDTO; |
|||
import com.zhongyun.dto.StatisticsDTO; |
|||
import com.zhongyun.dto.TransformDTO; |
|||
import com.zhongyun.service.StatisticsService; |
|||
import org.springframework.stereotype.Service; |
|||
import cn.hutool.core.util.NumberUtil; |
|||
|
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Service |
|||
public class StatisticsServiceImpl extends BaseServiceImpl<StatisticsDao, MonthDTO> implements StatisticsService { |
|||
|
|||
@Override |
|||
public List<MonthDTO> month() { |
|||
return baseDao.month(); |
|||
} |
|||
|
|||
@Override |
|||
public StatisticsDTO statistics() { |
|||
return baseDao.getStatistics(); |
|||
} |
|||
|
|||
@Override |
|||
public TransformDTO transform(String period) { |
|||
|
|||
TransformDTO transformDTO = new TransformDTO(); |
|||
|
|||
int earnPeople = baseDao.getEarnPeople(period); |
|||
int usedPeople = baseDao.getUsedPeople(period); |
|||
int earnNum = baseDao.getEarnNum(period); |
|||
int usedNum = baseDao.getUsedNum(period); |
|||
int totalPeople = 10000;//怎么获取平台访客总数,先定义10000
|
|||
|
|||
transformDTO.setUserNum(totalPeople); |
|||
transformDTO.setEarnPeople(earnPeople); |
|||
transformDTO.setUsedPeople(usedPeople); |
|||
transformDTO.setEarnNum(earnNum); |
|||
transformDTO.setUsedNum(usedNum); |
|||
|
|||
transformDTO.setAvgUsed(NumberUtil.decimalFormat("0.00",(double)usedNum/usedPeople) ); |
|||
transformDTO.setEarnPercent(NumberUtil.decimalFormat("0.00",(double)earnPeople/totalPeople)); |
|||
transformDTO.setUsedPercent(NumberUtil.decimalFormat("0.00",(double)usedPeople/earnPeople)); |
|||
transformDTO.setUserUsedPercent(NumberUtil.decimalFormat("0.00",(double)usedPeople/totalPeople) ); |
|||
|
|||
return transformDTO; |
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
package com.zhongyun.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.zhongyun.common.page.PageData; |
|||
import com.zhongyun.common.service.impl.CrudServiceImpl; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import com.zhongyun.dao.UserDao; |
|||
import com.zhongyun.dto.UserDTO; |
|||
import com.zhongyun.dto.ValidityDTO; |
|||
import com.zhongyun.entity.UserEntity; |
|||
import com.zhongyun.service.UserService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分用户 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 1.0 2024-11-20 |
|||
*/ |
|||
@Service |
|||
public class UserServiceImpl extends CrudServiceImpl<UserDao, UserEntity, UserDTO> implements UserService { |
|||
|
|||
@Override |
|||
public QueryWrapper<UserEntity> getWrapper(Map<String, Object> params){ |
|||
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>(); |
|||
|
|||
|
|||
return wrapper; |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public PageData<UserDTO> page(Map<String, Object> params) { |
|||
//转换成like
|
|||
paramsToLike(params, "mobile"); |
|||
|
|||
IPage<UserEntity> page = getPage(params, "u.create_date", false); |
|||
|
|||
List<UserEntity> list = baseDao.getList(params); |
|||
getPageData(list, page.getTotal(), UserDTO.class); |
|||
|
|||
return getPageData(list, page.getTotal(), UserDTO.class); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public List<UserDTO> top(String orderField) { |
|||
|
|||
List<UserEntity> list = baseDao.getTop(orderField); |
|||
|
|||
return ConvertUtils.sourceToTarget(list, UserDTO.class); |
|||
|
|||
} |
|||
@Override |
|||
public List<UserDTO> getInfobyIds(Long[] ids) { |
|||
|
|||
List<UserEntity> list = baseDao.getInfobyIds(ids); |
|||
|
|||
return ConvertUtils.sourceToTarget(list, UserDTO.class); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.zhongyun.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.zhongyun.common.service.impl.CrudServiceImpl; |
|||
import com.zhongyun.common.utils.ConvertUtils; |
|||
import com.zhongyun.dao.ValidityDao; |
|||
import com.zhongyun.dto.ValidityDTO; |
|||
import com.zhongyun.entity.ValidityEntity; |
|||
import com.zhongyun.service.ValidityService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 积分有效期 |
|||
* |
|||
* @author Gaoming fangaoming0208@aliyun.com |
|||
* @since 3.0 2024-11-20 |
|||
*/ |
|||
@Service |
|||
public class ValidityServiceImpl extends CrudServiceImpl<ValidityDao, ValidityEntity, ValidityDTO> implements ValidityService { |
|||
|
|||
|
|||
|
|||
@Override |
|||
public QueryWrapper<ValidityEntity> getWrapper(Map<String, Object> params){ |
|||
QueryWrapper<ValidityEntity> wrapper = new QueryWrapper<>(); |
|||
|
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
@Override |
|||
public ValidityDTO getInfo() { |
|||
QueryWrapper<ValidityEntity> wrapper = new QueryWrapper<>(); |
|||
ValidityEntity validityEntity = baseDao.selectOne(wrapper); |
|||
return ConvertUtils.sourceToTarget(validityEntity, ValidityDTO.class); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,108 @@ |
|||
spring: |
|||
messages: |
|||
encoding: UTF-8 |
|||
basename: i18n/messages |
|||
mvc: |
|||
pathmatch: |
|||
matching-strategy: ANT_PATH_MATCHER |
|||
servlet: |
|||
multipart: |
|||
max-file-size: 100MB |
|||
max-request-size: 100MB |
|||
enabled: true |
|||
application: |
|||
name: epmet-points-plugin |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
server-addr: 192.168.1.140:8848 |
|||
#nacos的命名空间ID,默认是public |
|||
namespace: epmet_saas_dev |
|||
#不把自己注册到注册中心的地址 |
|||
register-enabled: true |
|||
config: |
|||
server-addr: 192.168.1.140:8848 #nacos地址 |
|||
file-extension: yml # 文件后缀名 |
|||
enabled: false |
|||
main: |
|||
allow-bean-definition-overriding: true |
|||
datasource: |
|||
druid: |
|||
#MySQL |
|||
driver-class-name: com.mysql.cj.jdbc.Driver |
|||
url: jdbc:mysql://192.168.1.140:3306/epmet_user?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true |
|||
username: epmet |
|||
password: EpmEt_UsEr@sAAs |
|||
initial-size: 10 |
|||
max-active: 100 |
|||
min-idle: 10 |
|||
max-wait: 6000 |
|||
pool-prepared-statements: true |
|||
max-pool-prepared-statement-per-connection-size: 20 |
|||
time-between-eviction-runs-millis: 60000 |
|||
min-evictable-idle-time-millis: 300000 |
|||
test-while-idle: true |
|||
test-on-borrow: false |
|||
test-on-return: false |
|||
stat-view-servlet: |
|||
enabled: true |
|||
url-pattern: /druid/* |
|||
filter: |
|||
stat: |
|||
log-slow-sql: true |
|||
slow-sql-millis: 1000 |
|||
merge-sql: false |
|||
wall: |
|||
config: |
|||
multi-statement-allow: true |
|||
|
|||
logging: |
|||
level: |
|||
org.flowable.engine.impl.persistence.entity.*: debug |
|||
org.flowable.task.service.impl.persistence.entity.*: debug |
|||
|
|||
|
|||
knife4j: |
|||
enable: true |
|||
basic: |
|||
enable: false |
|||
username: admin |
|||
password: admin |
|||
setting: |
|||
enableFooter: false |
|||
|
|||
fdfs: |
|||
so-timeout: 600000 |
|||
connect-timeout: 6000 |
|||
tracker-list: #TrackerList参数,支持多个 |
|||
- 192.168.10.10:22122 |
|||
|
|||
|
|||
#mybatis |
|||
mybatis-plus: |
|||
mapper-locations: classpath*:/mapper/*.xml |
|||
#实体扫描,多个package用逗号或者分号分隔 |
|||
typeAliasesPackage: com.zhongyun.entity |
|||
global-config: |
|||
#数据库相关配置 |
|||
db-config: |
|||
#主键类型 |
|||
id-type: ASSIGN_ID |
|||
banner: false |
|||
#原生配置 |
|||
configuration: |
|||
map-underscore-to-camel-case: true |
|||
cache-enabled: false |
|||
call-setters-on-nulls: true |
|||
jdbc-type-for-null: 'null' |
|||
configuration-properties: |
|||
prefix: |
|||
blobType: BLOB |
|||
boolValue: TRUE |
|||
# 本地上传路径 |
|||
local: |
|||
localDomain: 127.0.0.1 |
|||
localPrefix: |
|||
localPath: D:/upload |
|||
|
|||
|
@ -0,0 +1,16 @@ |
|||
server: |
|||
tomcat: |
|||
uri-encoding: UTF-8 |
|||
threads: |
|||
max: 1000 |
|||
min-spare: 30 |
|||
port: 8121 |
|||
servlet: |
|||
context-path: /points |
|||
session: |
|||
cookie: |
|||
http-only: true |
|||
|
|||
spring: |
|||
profiles: |
|||
active: dev |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<configuration> |
|||
<include resource="org/springframework/boot/logging/logback/base.xml" /> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="TRACE" /> |
|||
|
|||
<!-- 开发、测试环境 --> |
|||
<springProfile name="dev,test"> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="INFO" /> |
|||
<logger name="com.zhongyun" level="DEBUG" /> |
|||
</springProfile> |
|||
|
|||
<!-- 生产环境 --> |
|||
<springProfile name="prod"> |
|||
<logger name="org.springframework.web" level="ERROR"/> |
|||
<logger name="org.springboot.sample" level="ERROR" /> |
|||
<logger name="com.zhongyun" level="ERROR" /> |
|||
</springProfile> |
|||
|
|||
</configuration> |
@ -0,0 +1,20 @@ |
|||
<?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.zhongyun.dao.DetailDao"> |
|||
|
|||
<select id="getList" resultType="com.zhongyun.entity.DetailEntity"> |
|||
|
|||
SELECT d.*, r.name as rule_name FROM `points_detail` d |
|||
LEFT JOIN points_rule r on d.rule_id=r.id where 1=1 |
|||
<if test="id != null and id.trim() != ''"> |
|||
and d.points_id = #{id} |
|||
</if> |
|||
<if test="startTime != null and startTime.trim() != '' and endTime != null and endTime.trim() != ''"> |
|||
and d.create_date BETWEEN CONCAT(#{startTime} ," 00:00:00") and CONCAT(#{endTime} ," 23:59:59") |
|||
</if> |
|||
|
|||
</select> |
|||
|
|||
|
|||
</mapper> |
@ -0,0 +1,13 @@ |
|||
<?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.zhongyun.dao.LevelDao"> |
|||
|
|||
<select id="getList" resultType="com.zhongyun.entity.LevelEntity"> |
|||
select * from points_level where 1=1 order by points asc |
|||
</select> |
|||
<delete id="delete" > |
|||
delete from points_level |
|||
</delete> |
|||
|
|||
</mapper> |
@ -0,0 +1,10 @@ |
|||
<?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.zhongyun.dao.RuleDao"> |
|||
|
|||
<select id="getList" resultType="com.zhongyun.entity.RuleEntity"> |
|||
select * from points_rule where 1=1 |
|||
</select> |
|||
|
|||
</mapper> |
@ -0,0 +1,97 @@ |
|||
<?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.zhongyun.dao.StatisticsDao"> |
|||
|
|||
<select id="month" resultType="com.zhongyun.dto.MonthDTO"> |
|||
|
|||
SELECT |
|||
SUM(CASE WHEN flag = 1 THEN num ELSE 0 END) AS total, |
|||
SUM(CASE WHEN flag = 0 THEN num ELSE 0 END) AS used , |
|||
DATE_FORMAT(create_date, '%Y-%m') as month |
|||
FROM points_detail as motnth |
|||
GROUP BY DATE_FORMAT(create_date, '%Y-%m') |
|||
ORDER BY DATE_FORMAT(create_date, '%Y-%m') DESC |
|||
</select> |
|||
|
|||
<select id="getStatistics" resultType="com.zhongyun.dto.StatisticsDTO"> |
|||
SELECT |
|||
SUM(total) as total, |
|||
SUM(availability) as availability, |
|||
SUM(blocked) as blocked, |
|||
SUM(used) as used |
|||
FROM `points_user` |
|||
</select> |
|||
|
|||
|
|||
<select id="getEarnPeople" resultType="int"> |
|||
SELECT count( 1 ) FROM |
|||
( SELECT points_id FROM `points_detail` WHERE flag = 1 |
|||
<if test="period != null and period== 'year'"> |
|||
and DATE_FORMAT(create_date, '%Y')=DATE_FORMAT(now(), '%Y') |
|||
</if> |
|||
<if test="period != null and period== 'month'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m')=DATE_FORMAT(now(), '%Y-%m') |
|||
</if> |
|||
<if test="period != null and period== 'day'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m-%d')=DATE_FORMAT(now(), '%Y-%m-%d') |
|||
</if> |
|||
<if test="period != null and period== 'week'"> |
|||
and YEARWEEK(create_date, 1) = YEARWEEK(CURDATE(), 1) |
|||
</if> |
|||
|
|||
GROUP BY points_id ) t |
|||
</select> |
|||
|
|||
<select id="getUsedPeople" resultType="int"> |
|||
SELECT count( 1 ) FROM |
|||
( SELECT points_id FROM `points_detail` WHERE flag = 0 |
|||
<if test="period != null and period== 'year'"> |
|||
and DATE_FORMAT(create_date, '%Y')=DATE_FORMAT(now(), '%Y') |
|||
</if> |
|||
<if test="period != null and period== 'month'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m')=DATE_FORMAT(now(), '%Y-%m') |
|||
</if> |
|||
<if test="period != null and period== 'day'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m-%d')=DATE_FORMAT(now(), '%Y-%m-%d') |
|||
</if> |
|||
<if test="period != null and period== 'week'"> |
|||
and YEARWEEK(create_date, 1) = YEARWEEK(CURDATE(), 1) |
|||
</if> |
|||
|
|||
GROUP BY points_id ) t |
|||
</select> |
|||
|
|||
<select id="getEarnNum" resultType="int"> |
|||
SELECT SUM( num ) FROM `points_detail` WHERE flag =1 |
|||
<if test="period != null and period== 'year'"> |
|||
and DATE_FORMAT(create_date, '%Y')=DATE_FORMAT(now(), '%Y') |
|||
</if> |
|||
<if test="period != null and period== 'month'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m')=DATE_FORMAT(now(),'%Y-%m') |
|||
</if> |
|||
<if test="period != null and period== 'day'"> |
|||
and DATE_FORMAT(create_date,'%Y-%m-%d')=DATE_FORMAT(now(),'%Y-%m-%d') |
|||
</if> |
|||
<if test="period != null and period== 'week'"> |
|||
and YEARWEEK(create_date, 1) = YEARWEEK(CURDATE(), 1) |
|||
</if> |
|||
</select> |
|||
|
|||
<select id="getUsedNum" resultType="int"> |
|||
SELECT SUM( num ) FROM `points_detail` WHERE flag =0 |
|||
<if test="period != null and period== 'year'"> |
|||
and DATE_FORMAT(create_date, '%Y')=DATE_FORMAT(now(), '%Y') |
|||
</if> |
|||
<if test="period != null and period== 'month'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m')=DATE_FORMAT(now(), '%Y-%m') |
|||
</if> |
|||
<if test="period != null and period== 'day'"> |
|||
and DATE_FORMAT(create_date, '%Y-%m-%d')=DATE_FORMAT(now(), '%Y-%m-%d') |
|||
</if> |
|||
<if test="period != null and period== 'week'"> |
|||
and YEARWEEK(create_date, 1) = YEARWEEK(CURDATE(), 1) |
|||
</if> |
|||
</select> |
|||
|
|||
</mapper> |
@ -0,0 +1,39 @@ |
|||
<?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.zhongyun.dao.UserDao"> |
|||
|
|||
<select id="getList" resultType="com.zhongyun.entity.UserEntity"> |
|||
|
|||
SELECT u.*,h.MOBILE,h.NICKNAME,l.`name` as level_name FROM `points_user` u |
|||
LEFT JOIN user_wechat_h5 h on u.wechat_h5_id=h.ID |
|||
LEFT JOIN points_level l on u.level_id=l.id where 1=1 |
|||
<if test="mobile != null and mobile.trim() != ''"> |
|||
and h.mobile like #{mobile} |
|||
</if> |
|||
<if test="startTime != null and startTime.trim() != '' and endTime != null and endTime.trim() != ''"> |
|||
and u.create_date BETWEEN CONCAT(#{startTime} ," 00:00:00") and CONCAT(#{endTime} ," 23:59:59") |
|||
</if> |
|||
</select> |
|||
|
|||
<select id="getTop" resultType="com.zhongyun.entity.UserEntity"> |
|||
|
|||
SELECT u.*,h.MOBILE,h.NICKNAME FROM `points_user` u |
|||
LEFT JOIN user_wechat_h5 h on u.wechat_h5_id=h.ID |
|||
order by #{value} desc limit 10 |
|||
|
|||
</select> |
|||
<select id="getInfobyIds" resultType="com.zhongyun.entity.UserEntity"> |
|||
SELECT u.*,h.MOBILE,h.NICKNAME FROM `points_user` u |
|||
LEFT JOIN user_wechat_h5 h on u.wechat_h5_id=h.ID |
|||
where 1=1 |
|||
<if test="ids != null"> |
|||
and u.wechat_h5_id in |
|||
<foreach item="id" collection="ids" open="(" separator="," close=")"> |
|||
#{id} |
|||
</foreach> |
|||
</if> |
|||
|
|||
|
|||
</select> |
|||
</mapper> |
@ -0,0 +1,19 @@ |
|||
<?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.zhongyun.dao.ValidityDao"> |
|||
|
|||
<update id="updateUserPoints"> |
|||
UPDATE points_user u LEFT JOIN (SELECT |
|||
sum( CASE WHEN flag = 1 THEN num ELSE 0 END ) total, |
|||
sum( CASE WHEN flag = 1 AND validity_flag = 1 THEN num ELSE 0 END ) availability, |
|||
sum( CASE WHEN flag = 1 AND validity_flag = 0 THEN num ELSE 0 END ) blocked, |
|||
points_id |
|||
FROM |
|||
points_detail |
|||
GROUP BY |
|||
points_id |
|||
) d on u.id= d.points_id SET u.total=d.total,u.availability=d.availability,u.blocked=d.blocked |
|||
</update> |
|||
|
|||
</mapper> |
Loading…
Reference in new issue