慧麦商城
This commit is contained in:
51
mall-common/pom.xml
Normal file
51
mall-common/pom.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.buy507.mall</groupId>
|
||||
<artifactId>mall-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>mall-common</name>
|
||||
<description>mall-common project for mall</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>5.1.8</version>
|
||||
</dependency>
|
||||
<!--Swagger-UI API文档生产工具-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
<version>2.1.5.RELEASE</version>
|
||||
</dependency>
|
||||
<!--Hutool Java工具包-->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>4.5.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.buy507.mall.common.api;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页数据封装类
|
||||
*/
|
||||
public class CommonPage<T> {
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
private Integer totalPage;
|
||||
private Long total;
|
||||
private List<T> list;
|
||||
|
||||
/**
|
||||
* 将PageHelper分页后的list转为分页信息
|
||||
*/
|
||||
public static <T> CommonPage<T> restPage(List<T> list) {
|
||||
CommonPage<T> result = new CommonPage<T>();
|
||||
PageInfo<T> pageInfo = new PageInfo<T>(list);
|
||||
result.setTotalPage(pageInfo.getPages());
|
||||
result.setPageNum(pageInfo.getPageNum());
|
||||
result.setPageSize(pageInfo.getPageSize());
|
||||
result.setTotal(pageInfo.getTotal());
|
||||
result.setList(pageInfo.getList());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将SpringData分页后的list转为分页信息
|
||||
*/
|
||||
public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
|
||||
CommonPage<T> result = new CommonPage<T>();
|
||||
result.setTotalPage(pageInfo.getTotalPages());
|
||||
result.setPageNum(pageInfo.getNumber());
|
||||
result.setPageSize(pageInfo.getSize());
|
||||
result.setTotal(pageInfo.getTotalElements());
|
||||
result.setList(pageInfo.getContent());
|
||||
return result;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(Integer totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.buy507.mall.common.api;
|
||||
|
||||
/**
|
||||
* 通用返回对象
|
||||
*/
|
||||
public class CommonResult<T> {
|
||||
private long code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
protected CommonResult() {
|
||||
}
|
||||
|
||||
protected CommonResult(long code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功返回结果
|
||||
*
|
||||
* @param data 获取的数据
|
||||
*/
|
||||
public static <T> CommonResult<T> success(T data) {
|
||||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功返回结果
|
||||
*
|
||||
* @param data 获取的数据
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> success(T data, String message) {
|
||||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
* @param errorCode 错误码
|
||||
*/
|
||||
public static <T> CommonResult<T> failed(IErrorCode errorCode) {
|
||||
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> failed(String message) {
|
||||
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> failed() {
|
||||
return failed(ResultCode.FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数验证失败返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> validateFailed() {
|
||||
return failed(ResultCode.VALIDATE_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数验证失败返回结果
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> validateFailed(String message) {
|
||||
return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 未登录返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> unauthorized(T data) {
|
||||
return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 未授权返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> forbidden(T data) {
|
||||
return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
|
||||
}
|
||||
|
||||
public long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(long code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.buy507.mall.common.api;
|
||||
|
||||
/**
|
||||
* 封装API的错误码
|
||||
*/
|
||||
public interface IErrorCode {
|
||||
long getCode();
|
||||
|
||||
String getMessage();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.buy507.mall.common.api;
|
||||
|
||||
/**
|
||||
* 枚举了一些常用API操作码
|
||||
*/
|
||||
public enum ResultCode implements IErrorCode {
|
||||
SUCCESS(200, "操作成功"),
|
||||
FAILED(500, "操作失败"),
|
||||
VALIDATE_FAILED(404, "参数检验失败"),
|
||||
UNAUTHORIZED(401, "暂未登录或token已经过期"),
|
||||
FORBIDDEN(403, "没有相关权限");
|
||||
private long code;
|
||||
private String message;
|
||||
|
||||
private ResultCode(long code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.buy507.mall.common.util;
|
||||
|
||||
public class Constants {
|
||||
|
||||
/**
|
||||
* 地区代码redis key
|
||||
*/
|
||||
public static final String AREA_CODE = "area_code";
|
||||
|
||||
/**
|
||||
* 团队会员数量锁
|
||||
*/
|
||||
public static final String LOCK_TEAM_MEMBER_NUM = "team_member_num";
|
||||
|
||||
/**
|
||||
* 分销字典redis key
|
||||
*/
|
||||
public static final String DISTRIBUTION_DICTIONARY = "distribution_dictionary";
|
||||
|
||||
/**
|
||||
* 成为消费商须购买商品的金额-1
|
||||
*/
|
||||
public static final String D_BECOME_CONSUMER = "become_consumer";
|
||||
|
||||
/**
|
||||
* 成为合伙人须购买商品的金额-2
|
||||
*/
|
||||
public static final String D_BECOME_PARTNER = "become_partner";
|
||||
|
||||
/**
|
||||
* 成为一钻合伙人须购买商品的金额-3
|
||||
*/
|
||||
public static final String D_BECOME_ONE_DIAMOND_ONE = "become_one_diamond_one";
|
||||
|
||||
/**
|
||||
* 成为一钻合伙人须分享合伙人的市场数量-4
|
||||
*/
|
||||
public static final String D_BECOME_ONE_DIAMOND_TWO = "become_one_diamond_two";
|
||||
|
||||
/**
|
||||
* 成为二钻合伙人须培养出一钻合伙人的市场数量-5
|
||||
*/
|
||||
public static final String D_BECOME_TWO_DIAMOND = "become_two_diamond";
|
||||
|
||||
/**
|
||||
* 成为三钻合伙人须培养出二钻合伙人的市场数量-6
|
||||
*/
|
||||
public static final String D_BECOME_THREE_DIAMOND = "become_three_diamond";
|
||||
|
||||
/**
|
||||
* 成为四钻合伙人须培养出三钻合伙人的市场数量-7
|
||||
*/
|
||||
public static final String D_BECOME_FOUR_DIAMOND = "become_four_diamond";
|
||||
|
||||
/**
|
||||
* 消费商获得分享劳务费的百分比-8
|
||||
*/
|
||||
public static final String D_CONSUMER_DIRECT_INCOME = "consumer_direct_income";
|
||||
|
||||
/**
|
||||
* 消费商获得服务劳务费的百分比-9
|
||||
*/
|
||||
public static final String D_CONSUMER_INDIRECT_INCOME = "consumer_indirect_income";
|
||||
|
||||
/**
|
||||
* 成为消费商后再次购买的折扣-10
|
||||
*/
|
||||
public static final String D_CONSUMER_BUY_AGAIN = "consumer_buy_again";
|
||||
|
||||
/**
|
||||
* 合伙人获得分享劳务费的百分比-11
|
||||
*/
|
||||
public static final String D_PARTNER_DIRECT_INCOME = "partner_direct_income";
|
||||
|
||||
/**
|
||||
* 合伙人获得服务劳务费的百分比-12
|
||||
*/
|
||||
public static final String D_PARTNER_INDIRECT_INCOME = "partner_indirect_income";
|
||||
|
||||
/**
|
||||
* 成为合伙人后再次购买的折扣-13
|
||||
*/
|
||||
public static final String D_PARTNER_BUY_AGAIN = "partner_buy_again";
|
||||
|
||||
/**
|
||||
* 成为合伙人并开店后获得店补的百分比-14
|
||||
*/
|
||||
public static final String D_PARTNER_STORE_SUBSIDY = "partner_store_subsidy";
|
||||
|
||||
/**
|
||||
* 钻石合伙人获得分享劳务费的百分比-15
|
||||
*/
|
||||
public static final String D_DIAMOND_DIRECT_INCOME = "diamond_direct_income";
|
||||
|
||||
/**
|
||||
* 钻石合伙人获得服务劳务费的百分比-16
|
||||
*/
|
||||
public static final String D_DIAMOND_INDIRECT_INCOME = "diamond_indirect_income";
|
||||
|
||||
/**
|
||||
* 成为钻石合伙人后再次购买的折扣-17
|
||||
*/
|
||||
public static final String D_DIAMOND_BUY_AGAIN = "diamond_buy_again";
|
||||
|
||||
/**
|
||||
* 成为钻石合伙人并开店后获得店补的百分比-18
|
||||
*/
|
||||
public static final String D_DIAMOND_STORE_SUBSIDY = "diamond_store_subsidy";
|
||||
|
||||
/**
|
||||
* 一钻合伙人获得团队服务劳务费的百分比-19
|
||||
*/
|
||||
public static final String D_ONE_DIAMOND_TEAM_INCOME = "one_diamond_team_income";
|
||||
|
||||
/**
|
||||
* 二钻合伙人获得团队服务劳务费的百分比-20
|
||||
*/
|
||||
public static final String D_TWO_DIAMOND_TEAM_INCOME = "two_diamond_team_income";
|
||||
|
||||
/**
|
||||
* 三钻合伙人获得团队服务劳务费的百分比-21
|
||||
*/
|
||||
public static final String D_THREE_DIAMOND_TEAM_INCOME = "three_diamond_team_income";
|
||||
|
||||
/**
|
||||
* 四钻合伙人获得平台月度加权平均奖励的百分比-22
|
||||
*/
|
||||
public static final String D_FOUR_DIAMOND_PLATFORM_INCOME = "four_diamond_platform_income";
|
||||
|
||||
/**
|
||||
* 提现手续费的百分比-24
|
||||
*/
|
||||
public static final String D_WITHDRAW_POUNDAGE = "withdraw_poundage";
|
||||
|
||||
/**
|
||||
* 提现金额的整数倍数-25
|
||||
*/
|
||||
public static final String D_WITHDRAW_MULTIPLE = "withdraw_multiple";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.buy507.mall.common.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class MD5Util {
|
||||
|
||||
private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
|
||||
|
||||
public static String MD5Encode(String origin, String charsetname) {
|
||||
String resultString = null;
|
||||
try {
|
||||
resultString = new String(origin);
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
if (charsetname == null || "".equals(charsetname))
|
||||
resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
|
||||
else
|
||||
resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));
|
||||
} catch (Exception exception) {
|
||||
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
private static String byteArrayToHexString(byte b[]) {
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for (int i = 0; i < b.length; i++)
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
|
||||
return resultSb.toString();
|
||||
}
|
||||
|
||||
private static String byteToHexString(byte b) {
|
||||
int n = b;
|
||||
if (n < 0)
|
||||
n += 256;
|
||||
int d1 = n / 16;
|
||||
int d2 = n % 16;
|
||||
return hexDigits[d1] + hexDigits[d2];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user