910 changed files with 68324 additions and 88 deletions
@ -0,0 +1,17 @@ |
|||||||
|
package cn.iocoder.yudao.module.member.controller.app.weixin; |
||||||
|
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService; |
||||||
|
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class TestConfigure { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public WxMpService wxMpService(){ |
||||||
|
WxMpService wxMpService = new WxMpServiceImpl(); |
||||||
|
return wxMpService; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1 +1 @@ |
|||||||
Subproject commit c9d2e1910ab71bd78bf56c4ffe04f9bf86845ee4 |
Subproject commit 05fdb1d9e71965bbb19e9e35b8732c861d7eab94 |
@ -0,0 +1,160 @@ |
|||||||
|
<?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"> |
||||||
|
<parent> |
||||||
|
<artifactId>yudao</artifactId> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<version>${revision}</version> |
||||||
|
</parent> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
|
||||||
|
<packaging>jar</packaging> |
||||||
|
<artifactId>zsw-bxg</artifactId> |
||||||
|
<name>${project.artifactId}</name> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<jjwt.version>0.10.6</jjwt.version> |
||||||
|
<mail.version>1.4.7</mail.version> |
||||||
|
<qiniu.version>7.9.5</qiniu.version> |
||||||
|
<jjwt.version>0.10.6</jjwt.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-module-system-impl</artifactId> |
||||||
|
<version>1.6.2-snapshot</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-biz-weixin</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-common</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-biz-pay</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-mybatis</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-web</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-redis</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-security</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>cn.iocoder.boot</groupId> |
||||||
|
<artifactId>yudao-spring-boot-starter-extension</artifactId> |
||||||
|
<version>${revision}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId> |
||||||
|
<version>2.5.10</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--jwt--> |
||||||
|
<dependency> |
||||||
|
<groupId>io.jsonwebtoken</groupId> |
||||||
|
<artifactId>jjwt</artifactId> |
||||||
|
<version>0.9.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--weixinpay--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.auth0</groupId> |
||||||
|
<artifactId>java-jwt</artifactId> |
||||||
|
<version>3.8.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.aliyun</groupId> |
||||||
|
<artifactId>aliyun-java-sdk-core</artifactId> |
||||||
|
<version>4.0.3</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.vdurmont</groupId> |
||||||
|
<artifactId>emoji-java</artifactId> |
||||||
|
<version>4.0.0</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--邮件依赖--> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.mail</groupId> |
||||||
|
<artifactId>mail</artifactId> |
||||||
|
<version>${mail.version}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!--七牛云存储--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.qiniu</groupId> |
||||||
|
<artifactId>qiniu-java-sdk</artifactId> |
||||||
|
<version>${qiniu.version}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter --> |
||||||
|
<dependency> |
||||||
|
<groupId>com.github.pagehelper</groupId> |
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId> |
||||||
|
<version>1.4.2</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>net.sf.dozer</groupId> |
||||||
|
<artifactId>dozer-spring</artifactId> |
||||||
|
<version>5.5.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>net.sf.dozer</groupId> |
||||||
|
<artifactId>dozer</artifactId> |
||||||
|
<version>5.5.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.google.zxing</groupId> |
||||||
|
<artifactId>core</artifactId> |
||||||
|
<version>3.2.1</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>com.alibaba</groupId> |
||||||
|
<artifactId>fastjson</artifactId> |
||||||
|
<version>1.2.50</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,21 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
|
||||||
|
*/ |
||||||
|
package co.yixiang.annotation; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jacky |
||||||
|
* 用于标记匿名访问方法 |
||||||
|
*/ |
||||||
|
@Target(ElementType.METHOD) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface AnonymousAccess { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
|
||||||
|
*/ |
||||||
|
package co.yixiang.annotation; |
||||||
|
|
||||||
|
import co.yixiang.aspect.LimitType; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jacky |
||||||
|
*/ |
||||||
|
@Target(ElementType.METHOD) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface Limit { |
||||||
|
|
||||||
|
// 资源名称,用于描述接口功能
|
||||||
|
String name() default ""; |
||||||
|
|
||||||
|
// 资源 key
|
||||||
|
String key() default ""; |
||||||
|
|
||||||
|
// key prefix
|
||||||
|
String prefix() default ""; |
||||||
|
|
||||||
|
// 时间的,单位秒
|
||||||
|
int period(); |
||||||
|
|
||||||
|
// 限制访问次数
|
||||||
|
int count(); |
||||||
|
|
||||||
|
// 限制类型
|
||||||
|
LimitType limitType() default LimitType.CUSTOMER; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
|
||||||
|
*/ |
||||||
|
package co.yixiang.annotation; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Zheng Jie |
||||||
|
* @date 2019-6-4 13:52:30 |
||||||
|
*/ |
||||||
|
@Target(ElementType.FIELD) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface Query { |
||||||
|
|
||||||
|
// Dong ZhaoYang 2017/8/7 基本对象的属性名
|
||||||
|
String propName() default ""; |
||||||
|
// Dong ZhaoYang 2017/8/7 查询方式
|
||||||
|
Type type() default Type.EQUAL; |
||||||
|
|
||||||
|
/** |
||||||
|
* 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username") |
||||||
|
*/ |
||||||
|
String blurry() default ""; |
||||||
|
|
||||||
|
enum Type { |
||||||
|
// jie 2019/6/4 相等
|
||||||
|
EQUAL |
||||||
|
// Dong ZhaoYang 2017/8/7 大于等于
|
||||||
|
, GREATER_THAN |
||||||
|
//大于
|
||||||
|
, GREATER_THAN_NQ |
||||||
|
// Dong ZhaoYang 2017/8/7 小于等于
|
||||||
|
, LESS_THAN |
||||||
|
// Dong ZhaoYang 2017/8/7 中模糊查询
|
||||||
|
, INNER_LIKE |
||||||
|
// Dong ZhaoYang 2017/8/7 左模糊查询
|
||||||
|
, LEFT_LIKE |
||||||
|
// Dong ZhaoYang 2017/8/7 右模糊查询
|
||||||
|
, RIGHT_LIKE |
||||||
|
// Dong ZhaoYang 2017/8/7 小于
|
||||||
|
, LESS_THAN_NQ |
||||||
|
// jie 2019/6/4 包含
|
||||||
|
, IN |
||||||
|
// 不等于
|
||||||
|
,NOT_EQUAL |
||||||
|
// between
|
||||||
|
,BETWEEN |
||||||
|
// 不为空
|
||||||
|
,NOT_NULL |
||||||
|
// 查询时间
|
||||||
|
,UNIX_TIMESTAMP |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,126 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* API 响应码 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public enum ApiCode { |
||||||
|
|
||||||
|
/** |
||||||
|
* 操作成功 |
||||||
|
**/ |
||||||
|
SUCCESS(200, "操作成功"), |
||||||
|
/** |
||||||
|
* 非法访问 |
||||||
|
**/ |
||||||
|
UNAUTHORIZED(401, "非法访问"), |
||||||
|
/** |
||||||
|
* 没有权限 |
||||||
|
**/ |
||||||
|
NOT_PERMISSION(403, "没有权限"), |
||||||
|
/** |
||||||
|
* 你请求的资源不存在 |
||||||
|
**/ |
||||||
|
NOT_FOUND(404, "你请求的资源不存在"), |
||||||
|
/** |
||||||
|
* 操作失败 |
||||||
|
**/ |
||||||
|
FAIL(500, "操作失败"), |
||||||
|
/** |
||||||
|
* 登录失败 |
||||||
|
**/ |
||||||
|
LOGIN_EXCEPTION(4000, "登录失败"), |
||||||
|
/** |
||||||
|
* 系统异常 |
||||||
|
**/ |
||||||
|
SYSTEM_EXCEPTION(5000, "系统异常"), |
||||||
|
/** |
||||||
|
* 请求参数校验异常 |
||||||
|
**/ |
||||||
|
PARAMETER_EXCEPTION(5001, "请求参数校验异常"), |
||||||
|
/** |
||||||
|
* 请求参数解析异常 |
||||||
|
**/ |
||||||
|
PARAMETER_PARSE_EXCEPTION(5002, "请求参数解析异常"), |
||||||
|
/** |
||||||
|
* HTTP内容类型异常 |
||||||
|
**/ |
||||||
|
HTTP_MEDIA_TYPE_EXCEPTION(5003, "HTTP内容类型异常"), |
||||||
|
/** |
||||||
|
* 系统处理异常 |
||||||
|
**/ |
||||||
|
YSHOP_SYSTEM_EXCEPTION(5100, "系统处理异常"), |
||||||
|
/** |
||||||
|
* 业务处理异常 |
||||||
|
**/ |
||||||
|
BUSINESS_EXCEPTION(5101, "业务处理异常"), |
||||||
|
/** |
||||||
|
* 数据库处理异常 |
||||||
|
**/ |
||||||
|
DAO_EXCEPTION(5102, "数据库处理异常"), |
||||||
|
/** |
||||||
|
* 验证码校验异常 |
||||||
|
**/ |
||||||
|
VERIFICATION_CODE_EXCEPTION(5103, "验证码校验异常"), |
||||||
|
/** |
||||||
|
* 登录授权异常 |
||||||
|
**/ |
||||||
|
AUTHENTICATION_EXCEPTION(5104, "登录授权异常"), |
||||||
|
/** |
||||||
|
* 没有访问权限 |
||||||
|
**/ |
||||||
|
UNAUTHENTICATED_EXCEPTION(5105, "没有访问权限"), |
||||||
|
/** |
||||||
|
* 没有访问权限 |
||||||
|
**/ |
||||||
|
UNAUTHORIZED_EXCEPTION(5106, "没有访问权限"), |
||||||
|
/** |
||||||
|
* JWT Token解析异常 |
||||||
|
**/ |
||||||
|
JWTDECODE_EXCEPTION(5107, "Token解析异常"), |
||||||
|
|
||||||
|
HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION(5108, "METHOD NOT SUPPORTED"), |
||||||
|
|
||||||
|
/** |
||||||
|
* 访问次数受限制 |
||||||
|
**/ |
||||||
|
BAD_LIMIT_EXCEPTION(5109, "访问次数受限制"), |
||||||
|
; |
||||||
|
|
||||||
|
private final int code; |
||||||
|
private final String message; |
||||||
|
|
||||||
|
ApiCode(final int code, final String message) { |
||||||
|
this.code = code; |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiCode getApiCode(int code) { |
||||||
|
ApiCode[] ecs = ApiCode.values(); |
||||||
|
for (ApiCode ec : ecs) { |
||||||
|
if (ec.getCode() == code) { |
||||||
|
return ec; |
||||||
|
} |
||||||
|
} |
||||||
|
return SUCCESS; |
||||||
|
} |
||||||
|
|
||||||
|
public int getCode() { |
||||||
|
return code; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMessage() { |
||||||
|
return message; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,231 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.experimental.Accessors; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* API 返回结果 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@Accessors(chain = true) |
||||||
|
@Builder |
||||||
|
@AllArgsConstructor |
||||||
|
public class ApiResult<T> implements Serializable { |
||||||
|
private static final long serialVersionUID = 8004487252556526569L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应码 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "响应码") |
||||||
|
private int status; |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否成功 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "是否成功:成功true,失败false") |
||||||
|
private boolean success; |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应消息 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "响应消息") |
||||||
|
private String msg; |
||||||
|
|
||||||
|
/** |
||||||
|
* 总条数 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "总条数") |
||||||
|
private Integer total; |
||||||
|
|
||||||
|
/** |
||||||
|
* 总页数 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "总页数") |
||||||
|
private Integer totalPage; |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应数据 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "响应数据") |
||||||
|
private T data; |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应时间 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "响应时间") |
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss") |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") |
||||||
|
private Date time; |
||||||
|
|
||||||
|
public ApiResult() { |
||||||
|
time = new Date(); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Boolean> result(boolean flag){ |
||||||
|
if (flag){ |
||||||
|
return ok(); |
||||||
|
} |
||||||
|
return fail(); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Boolean> result(ApiCode apiCode){ |
||||||
|
return result(apiCode,null); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> result(ApiCode apiCode, T data){ |
||||||
|
return result(apiCode,null,data); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> resultPage(Integer total, Integer totalPage, T data){ |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.total(total) |
||||||
|
.totalPage(totalPage) |
||||||
|
.status(200) |
||||||
|
.msg(null) |
||||||
|
.data(data) |
||||||
|
.success(true) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static <T> ApiResult<T> result(ApiCode apiCode, String message, T data){ |
||||||
|
boolean success = false; |
||||||
|
if (apiCode.getCode() == ApiCode.SUCCESS.getCode()){ |
||||||
|
success = true; |
||||||
|
} |
||||||
|
if (StringUtils.isBlank(message)){ |
||||||
|
message = apiCode.getMessage(); |
||||||
|
} |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.status(apiCode.getCode()) |
||||||
|
.msg(message) |
||||||
|
.data(data) |
||||||
|
.success(success) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Boolean> ok(){ |
||||||
|
return ok(null); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> ok(T data){ |
||||||
|
return result(ApiCode.SUCCESS,data); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> ok(T data, String message){ |
||||||
|
return result(ApiCode.SUCCESS,message,data); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Map<String,Object>> okMap(String key, Object value){ |
||||||
|
Map<String,Object> map = new HashMap<>(1); |
||||||
|
map.put(key,value); |
||||||
|
return ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Boolean> fail(ApiCode apiCode){ |
||||||
|
return result(apiCode,null); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<String> fail(String message){ |
||||||
|
return result(ApiCode.FAIL,message,null); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> fail(ApiCode apiCode, T data){ |
||||||
|
if (ApiCode.SUCCESS == apiCode){ |
||||||
|
throw new RuntimeException("失败结果状态码不能为" + ApiCode.SUCCESS.getCode()); |
||||||
|
} |
||||||
|
return result(apiCode,data); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<String> fail(Integer errorCode, String message){ |
||||||
|
return new ApiResult<String>() |
||||||
|
.setSuccess(false) |
||||||
|
.setStatus(errorCode) |
||||||
|
.setMsg(message); |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Map<String,Object>> fail(String key, Object value){ |
||||||
|
Map<String,Object> map = new HashMap<>(1); |
||||||
|
map.put(key,value); |
||||||
|
return result(ApiCode.FAIL,map); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> ApiResult<T> resultPage(T t, int limit){ |
||||||
|
List<Object> list = (List<Object>) t; |
||||||
|
int count = list.size() / limit; |
||||||
|
if (list.size() == 0) { |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.total(0) |
||||||
|
.totalPage(0) |
||||||
|
.status(200) |
||||||
|
.msg(null) |
||||||
|
.data(list) |
||||||
|
.success(true) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
if (list.size() <= limit) { |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.total(list.size()) |
||||||
|
.totalPage(1) |
||||||
|
.status(200) |
||||||
|
.msg(null) |
||||||
|
.data(list) |
||||||
|
.success(true) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} else if (count % limit == 0) { |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.total(list.size()) |
||||||
|
.totalPage(count) |
||||||
|
.status(200) |
||||||
|
.msg(null) |
||||||
|
.data(list) |
||||||
|
.success(true) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} else { |
||||||
|
return (ApiResult<T>) ApiResult.builder() |
||||||
|
.total(list.size()) |
||||||
|
.totalPage(count+1) |
||||||
|
.status(200) |
||||||
|
.msg(null) |
||||||
|
.data(list) |
||||||
|
.success(true) |
||||||
|
.time(new Date()) |
||||||
|
.build(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static ApiResult<Boolean> fail() { |
||||||
|
return fail(ApiCode.FAIL); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 业务异常 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class BusinessException extends YshopException { |
||||||
|
private static final long serialVersionUID = -2303357122330162359L; |
||||||
|
|
||||||
|
public BusinessException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
|
||||||
|
public BusinessException(Integer errorCode, String message) { |
||||||
|
super(errorCode, message); |
||||||
|
} |
||||||
|
|
||||||
|
public BusinessException(ApiCode apiCode) { |
||||||
|
super(apiCode); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* DAO异常 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class DaoException extends YshopException { |
||||||
|
private static final long serialVersionUID = -6912618737345878854L; |
||||||
|
|
||||||
|
public DaoException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
|
||||||
|
public DaoException(Integer errorCode, String message) { |
||||||
|
super(errorCode, message); |
||||||
|
} |
||||||
|
|
||||||
|
public DaoException(ApiCode apiCode) { |
||||||
|
super(apiCode); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
/** |
||||||
|
* 认证异常 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class UnAuthenticatedException extends YshopException { |
||||||
|
public UnAuthenticatedException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
|
||||||
|
public UnAuthenticatedException(Integer errorCode, String message) { |
||||||
|
super(errorCode, message); |
||||||
|
} |
||||||
|
|
||||||
|
public UnAuthenticatedException(ApiCode apiCode) { |
||||||
|
super(apiCode); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.api; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义异常 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class YshopException extends RuntimeException{ |
||||||
|
|
||||||
|
private static final long serialVersionUID = -2470461654663264392L; |
||||||
|
|
||||||
|
private Integer errorCode; |
||||||
|
private String message; |
||||||
|
|
||||||
|
public YshopException() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public YshopException(String message) { |
||||||
|
super(message); |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
public YshopException(Integer errorCode, String message) { |
||||||
|
super(message); |
||||||
|
this.errorCode = errorCode; |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
public YshopException(ApiCode apiCode) { |
||||||
|
super(apiCode.getMessage()); |
||||||
|
this.errorCode = apiCode.getCode(); |
||||||
|
this.message = apiCode.getMessage(); |
||||||
|
} |
||||||
|
|
||||||
|
public YshopException(String message, Throwable cause) { |
||||||
|
super(message, cause); |
||||||
|
} |
||||||
|
|
||||||
|
public YshopException(Throwable cause) { |
||||||
|
super(cause); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.aop; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
@Target(ElementType.METHOD) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface NoRepeatSubmit { |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置请求锁定时间 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
int lockTime() default 10; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,101 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
|
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.aspect; |
||||||
|
|
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.logging.domain.Log; |
||||||
|
import co.yixiang.logging.service.LogService; |
||||||
|
import co.yixiang.utils.RequestHolder; |
||||||
|
import co.yixiang.utils.StringUtils; |
||||||
|
import co.yixiang.utils.ThrowableUtil; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.aspectj.lang.JoinPoint; |
||||||
|
import org.aspectj.lang.ProceedingJoinPoint; |
||||||
|
import org.aspectj.lang.annotation.AfterThrowing; |
||||||
|
import org.aspectj.lang.annotation.Around; |
||||||
|
import org.aspectj.lang.annotation.Aspect; |
||||||
|
import org.aspectj.lang.annotation.Pointcut; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author hupeng |
||||||
|
* @date 2018-11-24 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
@Aspect |
||||||
|
@Slf4j |
||||||
|
public class AppLogAspect { |
||||||
|
|
||||||
|
private final LogService logService; |
||||||
|
|
||||||
|
ThreadLocal<Long> currentTime = new ThreadLocal<>(); |
||||||
|
|
||||||
|
public AppLogAspect(LogService logService) { |
||||||
|
this.logService = logService; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 配置切入点 |
||||||
|
*/ |
||||||
|
@Pointcut("@annotation(co.yixiang.logging.aop.log.AppLog)") |
||||||
|
public void logPointcut() { |
||||||
|
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 配置环绕通知,使用在方法logPointcut()上注册的切入点 |
||||||
|
* |
||||||
|
* @param joinPoint join point for advice |
||||||
|
*/ |
||||||
|
@Around("logPointcut()") |
||||||
|
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { |
||||||
|
Object result; |
||||||
|
currentTime.set(System.currentTimeMillis()); |
||||||
|
result = joinPoint.proceed(); |
||||||
|
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get()); |
||||||
|
currentTime.remove(); |
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest(); |
||||||
|
logService.saveApp(getUsername(), |
||||||
|
StringUtils.getIp(RequestHolder.getHttpServletRequest()),joinPoint, |
||||||
|
log,getUid()); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 配置异常通知 |
||||||
|
* |
||||||
|
* @param joinPoint join point for advice |
||||||
|
* @param e exception |
||||||
|
*/ |
||||||
|
@AfterThrowing(pointcut = "logPointcut()", throwing = "e") |
||||||
|
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { |
||||||
|
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); |
||||||
|
currentTime.remove(); |
||||||
|
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); |
||||||
|
HttpServletRequest request = RequestHolder.getHttpServletRequest(); |
||||||
|
logService.save(getUsername(), |
||||||
|
StringUtils.getIp(RequestHolder.getHttpServletRequest()), |
||||||
|
(ProceedingJoinPoint)joinPoint, log,getUid()); |
||||||
|
} |
||||||
|
|
||||||
|
public String getUsername() { |
||||||
|
try { |
||||||
|
return LocalUser.getUser().getUsername(); |
||||||
|
}catch (Exception e){ |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Long getUid(){ |
||||||
|
try { |
||||||
|
return LocalUser.getUser().getUid(); |
||||||
|
}catch (Exception e){ |
||||||
|
return 0L; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.bean; |
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.api.ApiCode; |
||||||
|
import co.yixiang.api.UnAuthenticatedException; |
||||||
|
import co.yixiang.app.common.util.JwtToken; |
||||||
|
import co.yixiang.app.common.util.RequestUtils; |
||||||
|
import co.yixiang.modules.user.domain.YxUser; |
||||||
|
import com.auth0.jwt.interfaces.Claim; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** |
||||||
|
* 全局user |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class LocalUser { |
||||||
|
private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>(); |
||||||
|
|
||||||
|
public static void set(YxUser user, Integer scope) { |
||||||
|
Map<String, Object> map = new HashMap<>(); |
||||||
|
map.put("user", user); |
||||||
|
map.put("scope", scope); |
||||||
|
LocalUser.threadLocal.set(map); |
||||||
|
} |
||||||
|
|
||||||
|
public static void clear() { |
||||||
|
LocalUser.threadLocal.remove(); |
||||||
|
} |
||||||
|
|
||||||
|
public static YxUser getUser() { |
||||||
|
Map<String, Object> map = LocalUser.threadLocal.get(); |
||||||
|
YxUser user = (YxUser)map.get("user"); |
||||||
|
return user; |
||||||
|
} |
||||||
|
|
||||||
|
public static Integer getScope() { |
||||||
|
Map<String, Object> map = LocalUser.threadLocal.get(); |
||||||
|
Integer scope = (Integer)map.get("scope"); |
||||||
|
return scope; |
||||||
|
} |
||||||
|
|
||||||
|
public static Long getUidByToken(){ |
||||||
|
String bearerToken = RequestUtils.getRequest().getHeader("Authorization"); |
||||||
|
if (StringUtils.isEmpty(bearerToken)) { |
||||||
|
return 0L; |
||||||
|
} |
||||||
|
|
||||||
|
if (!bearerToken.startsWith("Bearer")) { |
||||||
|
return 0L; |
||||||
|
} |
||||||
|
String[] tokens = bearerToken.split(" "); |
||||||
|
if (!(tokens.length == 2)) { |
||||||
|
return 0L; |
||||||
|
} |
||||||
|
String token = tokens[1]; |
||||||
|
|
||||||
|
Optional<Map<String, Claim>> optionalMap = JwtToken.getClaims(token); |
||||||
|
Map<String, Claim> map = optionalMap |
||||||
|
.orElseThrow(() -> new UnAuthenticatedException(ApiCode.UNAUTHORIZED)); |
||||||
|
|
||||||
|
return map.get("uid").asLong(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.bean; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import lombok.experimental.Accessors; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 请求详情信息 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@Accessors(chain = true) |
||||||
|
public class RequestDetail implements Serializable { |
||||||
|
private static final long serialVersionUID = 2543641512850125440L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 请求ip地址 |
||||||
|
*/ |
||||||
|
private String ip; |
||||||
|
|
||||||
|
/** |
||||||
|
* 请求路径 |
||||||
|
*/ |
||||||
|
private String path; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
package co.yixiang.app.common.constant; |
||||||
|
|
||||||
|
|
||||||
|
public interface CommonConstant { |
||||||
|
|
||||||
|
/** |
||||||
|
* 默认页码为1 |
||||||
|
*/ |
||||||
|
Integer DEFAULT_PAGE_INDEX = 1; |
||||||
|
|
||||||
|
/** |
||||||
|
* 默认页大小为10 |
||||||
|
*/ |
||||||
|
Integer DEFAULT_PAGE_SIZE = 10; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录用户 |
||||||
|
*/ |
||||||
|
String LOGIN_SYS_USER = "loginSysUser"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登陆token |
||||||
|
*/ |
||||||
|
String TOKEN = "token"; |
||||||
|
/** |
||||||
|
* 刷新token |
||||||
|
*/ |
||||||
|
String REFRESH_TOKEN = "refresh_token"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始密码 |
||||||
|
*/ |
||||||
|
String INIT_PWD = "123456"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 默认头像 |
||||||
|
*/ |
||||||
|
String DEFAULT_HEAD_URL = ""; |
||||||
|
|
||||||
|
/** |
||||||
|
* 管理员角色名称 |
||||||
|
*/ |
||||||
|
String ADMIN_ROLE_NAME = "管理员"; |
||||||
|
|
||||||
|
String ADMIN_LOGIN = "adminLogin"; |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.enums; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Getter; |
||||||
|
|
||||||
|
import java.util.stream.Stream; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author hupeng |
||||||
|
* 短信类型枚举 |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@AllArgsConstructor |
||||||
|
public enum SmsTypeEnum { |
||||||
|
BIND("bind","绑定手机短信"), |
||||||
|
LOGIN("login","登陆短信"), |
||||||
|
REGISTER("register","注册短信"); |
||||||
|
|
||||||
|
private String value; |
||||||
|
private String desc; |
||||||
|
|
||||||
|
public static SmsTypeEnum toType(String value) { |
||||||
|
return Stream.of(SmsTypeEnum.values()) |
||||||
|
.filter(c -> c.value == value) |
||||||
|
.findAny() |
||||||
|
.orElse(null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
///**
|
||||||
|
// * Copyright (C) 2018-2022
|
||||||
|
// * All rights reserved, Designed By www.yixiang.co
|
||||||
|
// * 注意:
|
||||||
|
// * 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||||
|
// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||||
|
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||||
|
// */
|
||||||
|
//package co.yixiang.common.exception;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 业务异常
|
||||||
|
// * @author hupeng
|
||||||
|
// * @date 2020-04-30
|
||||||
|
// */
|
||||||
|
//public class BusinessException extends YshopException {
|
||||||
|
// private static final long serialVersionUID = -2303357122330162359L;
|
||||||
|
//
|
||||||
|
// public BusinessException(String message) {
|
||||||
|
// super(message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public BusinessException(Integer errorCode, String message) {
|
||||||
|
// super(errorCode, message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public BusinessException(ApiCode apiCode) {
|
||||||
|
// super(apiCode);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,34 @@ |
|||||||
|
///**
|
||||||
|
// * Copyright (C) 2018-2022
|
||||||
|
// * All rights reserved, Designed By www.yixiang.co
|
||||||
|
// * 注意:
|
||||||
|
// * 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||||
|
// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||||
|
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||||
|
// */
|
||||||
|
//package co.yixiang.common.exception;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import co.yixiang.common.api.ApiCode;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * DAO异常
|
||||||
|
// * @author hupeng
|
||||||
|
// * @date 2020-04-30
|
||||||
|
// */
|
||||||
|
//public class DaoException extends YshopException {
|
||||||
|
// private static final long serialVersionUID = -6912618737345878854L;
|
||||||
|
//
|
||||||
|
// public DaoException(String message) {
|
||||||
|
// super(message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public DaoException(Integer errorCode, String message) {
|
||||||
|
// super(errorCode, message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public DaoException(ApiCode apiCode) {
|
||||||
|
// super(apiCode);
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,30 @@ |
|||||||
|
///**
|
||||||
|
// * Copyright (C) 2018-2022
|
||||||
|
// * All rights reserved, Designed By www.yixiang.co
|
||||||
|
// * 注意:
|
||||||
|
// * 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||||
|
// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||||
|
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||||
|
// */
|
||||||
|
//package co.yixiang.common.exception;
|
||||||
|
//
|
||||||
|
//import co.yixiang.common.api.ApiCode;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 认证异常
|
||||||
|
// * @author hupeng
|
||||||
|
// * @date 2020-04-30
|
||||||
|
// */
|
||||||
|
//public class UnAuthenticatedException extends YshopException {
|
||||||
|
// public UnAuthenticatedException(String message) {
|
||||||
|
// super(message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public UnAuthenticatedException(Integer errorCode, String message) {
|
||||||
|
// super(errorCode, message);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public UnAuthenticatedException(ApiCode apiCode) {
|
||||||
|
// super(apiCode);
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,60 @@ |
|||||||
|
///**
|
||||||
|
// * Copyright (C) 2018-2022
|
||||||
|
// * All rights reserved, Designed By www.yixiang.co
|
||||||
|
// * 注意:
|
||||||
|
// * 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||||
|
// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||||
|
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||||
|
// */
|
||||||
|
//package co.yixiang.common.exception;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import co.yixiang.common.api.ApiCode;
|
||||||
|
//import lombok.Data;
|
||||||
|
//import lombok.EqualsAndHashCode;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 自定义异常
|
||||||
|
// * @author hupeng
|
||||||
|
// * @date 2020-04-30
|
||||||
|
// */
|
||||||
|
//@Data
|
||||||
|
//@EqualsAndHashCode(callSuper = true)
|
||||||
|
//public class YshopException extends RuntimeException{
|
||||||
|
//
|
||||||
|
// private static final long serialVersionUID = -2470461654663264392L;
|
||||||
|
//
|
||||||
|
// private Integer errorCode;
|
||||||
|
// private String message;
|
||||||
|
//
|
||||||
|
// public YshopException() {
|
||||||
|
// super();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public YshopException(String message) {
|
||||||
|
// super(message);
|
||||||
|
// this.message = message;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public YshopException(Integer errorCode, String message) {
|
||||||
|
// super(message);
|
||||||
|
// this.errorCode = errorCode;
|
||||||
|
// this.message = message;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public YshopException(ApiCode apiCode) {
|
||||||
|
// super(apiCode.getMessage());
|
||||||
|
// this.errorCode = apiCode.getCode();
|
||||||
|
// this.message = apiCode.getMessage();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public YshopException(String message, Throwable cause) {
|
||||||
|
// super(message, cause);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public YshopException(Throwable cause) {
|
||||||
|
// super(cause);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,186 @@ |
|||||||
|
///**
|
||||||
|
// * Copyright (C) 2018-2022
|
||||||
|
// * All rights reserved, Designed By www.yixiang.co
|
||||||
|
// * 注意:
|
||||||
|
// * 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||||
|
// * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||||
|
// * 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||||
|
// */
|
||||||
|
//package co.yixiang.app.common.handler;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import co.yixiang.api.ApiCode;
|
||||||
|
//import co.yixiang.api.ApiResult;
|
||||||
|
//import co.yixiang.api.BusinessException;
|
||||||
|
//import co.yixiang.api.DaoException;
|
||||||
|
//import co.yixiang.api.UnAuthenticatedException;
|
||||||
|
//import co.yixiang.api.YshopException;
|
||||||
|
//import co.yixiang.app.common.bean.RequestDetail;
|
||||||
|
//import co.yixiang.app.common.util.RequestDetailThreadLocal;
|
||||||
|
//import co.yixiang.exception.BadLimitRequestException;
|
||||||
|
//import com.alibaba.fastjson.JSON;
|
||||||
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
|
//import org.springframework.http.HttpStatus;
|
||||||
|
//import org.springframework.validation.BindingResult;
|
||||||
|
//import org.springframework.validation.FieldError;
|
||||||
|
//import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
|
//import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
//import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
//import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
//import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
//import org.springframework.web.bind.annotation.RestController;
|
||||||
|
//
|
||||||
|
//import java.util.ArrayList;
|
||||||
|
//import java.util.Collections;
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 全局异常
|
||||||
|
// * @author hupeng
|
||||||
|
// * @date 2020-04-30
|
||||||
|
// */
|
||||||
|
//@ControllerAdvice
|
||||||
|
//@RestController
|
||||||
|
//@Slf4j
|
||||||
|
//public class GlobalExceptionHandler {
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 非法参数验证异常
|
||||||
|
// *
|
||||||
|
// * @param ex
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// @ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
// @ResponseStatus(value = HttpStatus.OK)
|
||||||
|
// public ApiResult<String> handleMethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException ex) {
|
||||||
|
// printRequestDetail();
|
||||||
|
// BindingResult bindingResult = ex.getBindingResult();
|
||||||
|
// List<String> list = new ArrayList<>();
|
||||||
|
// List<FieldError> fieldErrors = bindingResult.getFieldErrors();
|
||||||
|
// for (FieldError fieldError : fieldErrors) {
|
||||||
|
// list.add(fieldError.getDefaultMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Collections.sort(list);
|
||||||
|
// String msg = "不能为空";
|
||||||
|
// if(!list.isEmpty()) {
|
||||||
|
// msg = list.get(0);
|
||||||
|
// }
|
||||||
|
// log.error(getApiCodeString(ApiCode.PARAMETER_EXCEPTION) + ":" + JSON.toJSONString(list));
|
||||||
|
// return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION.getCode(), msg);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @ExceptionHandler(value = BadLimitRequestException.class)
|
||||||
|
// @ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
// public ApiResult<Boolean> badLimitRequestException(BadLimitRequestException exception) {
|
||||||
|
// printRequestDetail();
|
||||||
|
// printApiCodeException(ApiCode.SYSTEM_EXCEPTION, exception);
|
||||||
|
// return new ApiResult<Boolean>()
|
||||||
|
// .setStatus(ApiCode.BAD_LIMIT_EXCEPTION.getCode())
|
||||||
|
// .setMsg(exception.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 自定义业务/数据异常处理
|
||||||
|
// *
|
||||||
|
// * @param exception
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// @ExceptionHandler(value = {YshopException.class})
|
||||||
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
|
// public ApiResult<Boolean> YshopException(YshopException exception) {
|
||||||
|
// printRequestDetail();
|
||||||
|
// log.error("YshopException:", exception);
|
||||||
|
// int errorCode;
|
||||||
|
// if (exception instanceof BusinessException) {
|
||||||
|
// errorCode = ApiCode.BUSINESS_EXCEPTION.getCode();
|
||||||
|
// } else if (exception instanceof DaoException) {
|
||||||
|
// errorCode = ApiCode.DAO_EXCEPTION.getCode();
|
||||||
|
// } else if (exception instanceof UnAuthenticatedException) {
|
||||||
|
// errorCode = ApiCode.UNAUTHORIZED.getCode();
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// errorCode = ApiCode.BUSINESS_EXCEPTION.getCode();
|
||||||
|
// }
|
||||||
|
// System.out.println("=======");
|
||||||
|
// return new ApiResult<Boolean>()
|
||||||
|
// .setStatus(errorCode)
|
||||||
|
// .setMsg(exception.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 默认的异常处理
|
||||||
|
// *
|
||||||
|
// * @param exception
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
|
||||||
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
|
// public ApiResult<String> httpRequestMethodNotSupportedExceptionHandler(Exception exception) {
|
||||||
|
// printRequestDetail();
|
||||||
|
// printApiCodeException(ApiCode.HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION, exception);
|
||||||
|
// return ApiResult.fail(ApiCode.HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION.getCode(), exception.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 默认的异常处理
|
||||||
|
// *
|
||||||
|
// * @param exception
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// @ExceptionHandler(value = Exception.class)
|
||||||
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
|
// public ApiResult<Boolean> exceptionHandler(Exception exception) {
|
||||||
|
// printRequestDetail();
|
||||||
|
// printApiCodeException(ApiCode.SYSTEM_EXCEPTION, exception);
|
||||||
|
// // return ApiResult.fail(ApiCode.SYSTEM_EXCEPTION);
|
||||||
|
//
|
||||||
|
// return new ApiResult<Boolean>()
|
||||||
|
// .setStatus(ApiCode.FAIL.getCode())
|
||||||
|
// .setMsg(exception.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 打印请求详情
|
||||||
|
// */
|
||||||
|
// private void printRequestDetail() {
|
||||||
|
// RequestDetail requestDetail = RequestDetailThreadLocal.getRequestDetail();
|
||||||
|
// if (requestDetail != null) {
|
||||||
|
// log.error("异常来源:ip: {}, path: {}", requestDetail.getIp(), requestDetail.getPath());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 获取ApiCode格式化字符串
|
||||||
|
// *
|
||||||
|
// * @param apiCode
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// private String getApiCodeString(ApiCode apiCode) {
|
||||||
|
// if (apiCode != null) {
|
||||||
|
// return String.format("errorCode: %s, errorMessage: %s", apiCode.getCode(), apiCode.getMessage());
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 打印错误码及异常
|
||||||
|
// *
|
||||||
|
// * @param apiCode
|
||||||
|
// * @param exception
|
||||||
|
// */
|
||||||
|
// private void printApiCodeException(ApiCode apiCode, Exception exception) {
|
||||||
|
// log.error(getApiCodeString(apiCode), exception);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,26 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.interceptor; |
||||||
|
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 自定义权限注解 |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/4/30 |
||||||
|
**/ |
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE}) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface AuthCheck { |
||||||
|
int value() default 4; |
||||||
|
} |
@ -0,0 +1,130 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.interceptor; |
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import co.yixiang.api.ApiCode; |
||||||
|
import co.yixiang.api.UnAuthenticatedException; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.common.util.JwtToken; |
||||||
|
import co.yixiang.constant.ShopConstants; |
||||||
|
import co.yixiang.modules.user.domain.YxUser; |
||||||
|
import co.yixiang.modules.user.service.YxUserService; |
||||||
|
import co.yixiang.utils.RedisUtils; |
||||||
|
import com.auth0.jwt.interfaces.Claim; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.util.StringUtils; |
||||||
|
import org.springframework.web.method.HandlerMethod; |
||||||
|
import org.springframework.web.servlet.ModelAndView; |
||||||
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** |
||||||
|
* 权限拦截器 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class PermissionInterceptor extends HandlerInterceptorAdapter { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private YxUserService userService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private RedisUtils redisUtils; |
||||||
|
|
||||||
|
public PermissionInterceptor() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||||
|
Optional<AuthCheck> authCheck = this.getAuthCheck(handler); |
||||||
|
if (!authCheck.isPresent()) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
String bearerToken = request.getHeader("Authorization"); |
||||||
|
if (StrUtil.isEmpty(bearerToken)) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED); |
||||||
|
} |
||||||
|
|
||||||
|
if (!bearerToken.startsWith("Bearer")) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED); |
||||||
|
} |
||||||
|
String[] tokens = bearerToken.split(" "); |
||||||
|
if (!(tokens.length == 2)) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED); |
||||||
|
} |
||||||
|
String token = tokens[1]; |
||||||
|
|
||||||
|
Optional<Map<String, Claim>> optionalMap = JwtToken.getClaims(token); |
||||||
|
Map<String, Claim> map = optionalMap |
||||||
|
.orElseThrow(() -> new UnAuthenticatedException(ApiCode.UNAUTHORIZED)); |
||||||
|
|
||||||
|
String uName = map.get("uName").asString(); |
||||||
|
|
||||||
|
//检测用户是否被踢出
|
||||||
|
if (redisUtils.get(ShopConstants.YSHOP_APP_LOGIN_USER + uName + ":" + token) == null) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.UNAUTHORIZED); |
||||||
|
} |
||||||
|
boolean valid = this.hasPermission(authCheck.get(), map); |
||||||
|
if(valid){ |
||||||
|
this.setToThreadLocal(map); |
||||||
|
} |
||||||
|
return valid; |
||||||
|
} |
||||||
|
|
||||||
|
private void setToThreadLocal(Map<String,Claim> map) { |
||||||
|
Integer uid = map.get("uid").asInt(); |
||||||
|
Integer scope = map.get("scope").asInt(); |
||||||
|
YxUser user = userService.getById(uid); |
||||||
|
if(user == null) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.NOT_PERMISSION); |
||||||
|
} |
||||||
|
LocalUser.set(user, scope); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean hasPermission(AuthCheck authCheck, Map<String, Claim> map) { |
||||||
|
Integer level = authCheck.value(); |
||||||
|
Integer scope = map.get("scope").asInt(); |
||||||
|
if (level > scope) { |
||||||
|
throw new UnAuthenticatedException(ApiCode.NOT_PERMISSION); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
||||||
|
super.postHandle(request, response, handler, modelAndView); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
||||||
|
LocalUser.clear(); |
||||||
|
super.afterCompletion(request, response, handler, ex); |
||||||
|
} |
||||||
|
|
||||||
|
private Optional<AuthCheck> getAuthCheck(Object handler) { |
||||||
|
if (handler instanceof HandlerMethod) { |
||||||
|
HandlerMethod handlerMethod = (HandlerMethod) handler; |
||||||
|
AuthCheck authCheck = handlerMethod.getMethod().getAnnotation(AuthCheck.class); |
||||||
|
if (authCheck == null) { |
||||||
|
return Optional.empty(); |
||||||
|
} |
||||||
|
return Optional.of(authCheck); |
||||||
|
} |
||||||
|
return Optional.empty(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.param; |
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.app.common.constant.CommonConstant; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
@Data |
||||||
|
@ApiModel("查询参数对象") |
||||||
|
public abstract class QueryParam implements Serializable{ |
||||||
|
private static final long serialVersionUID = -3263921252635611410L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "页码,默认为1") |
||||||
|
private Integer page = CommonConstant.DEFAULT_PAGE_INDEX; |
||||||
|
@ApiModelProperty(value = "页大小,默认为10") |
||||||
|
private Integer limit = CommonConstant.DEFAULT_PAGE_SIZE; |
||||||
|
@ApiModelProperty(value = "搜索字符串") |
||||||
|
private String keyword; |
||||||
|
|
||||||
|
public void setPage(Integer page) { |
||||||
|
if (page == null || page <= 0){ |
||||||
|
this.page = CommonConstant.DEFAULT_PAGE_INDEX; |
||||||
|
}else{ |
||||||
|
this.page = page; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void setLimit(Integer limit) { |
||||||
|
if (limit == null || limit <= 0){ |
||||||
|
this.limit = CommonConstant.DEFAULT_PAGE_SIZE; |
||||||
|
}else{ |
||||||
|
this.limit = limit; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 浏览器工具类 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public final class BrowserUtil { |
||||||
|
public static final String IE = "msie"; |
||||||
|
public static final String FIREFOX = "firefox"; |
||||||
|
public static final String CHROME = "chrome"; |
||||||
|
|
||||||
|
private BrowserUtil() { |
||||||
|
throw new AssertionError(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前浏览器名称 |
||||||
|
* |
||||||
|
* @param request |
||||||
|
* @return 返回浏览器名称 |
||||||
|
*/ |
||||||
|
public static String getCurrent(HttpServletRequest request) { |
||||||
|
String userAgent = request.getHeader("USER-AGENT").toLowerCase(); |
||||||
|
if (userAgent != null && !("".equals(userAgent.trim()))) { |
||||||
|
if (userAgent.indexOf(CHROME) >= 0) { |
||||||
|
return CHROME; |
||||||
|
} else if (userAgent.indexOf(FIREFOX) >= 0) { |
||||||
|
return FIREFOX; |
||||||
|
} else if (userAgent.indexOf(IE) >= 0) { |
||||||
|
return IE; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否是IE浏览器 |
||||||
|
* |
||||||
|
* @param request |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isIe(HttpServletRequest request) { |
||||||
|
return IE.equals(getCurrent(request)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否是Firefox浏览器 |
||||||
|
* |
||||||
|
* @param request |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isFirefox(HttpServletRequest request) { |
||||||
|
return FIREFOX.equals(getCurrent(request)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否是Chrome浏览器 |
||||||
|
* |
||||||
|
* @param request |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean isChrome(HttpServletRequest request) { |
||||||
|
return CHROME.equals(getCurrent(request)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.modules.user.vo.CityVo; |
||||||
|
import org.springframework.util.CollectionUtils; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 树形工具类 |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/10/22 |
||||||
|
**/ |
||||||
|
public class CityTreeUtil { |
||||||
|
/** |
||||||
|
* 获得指定节点下所有归档 |
||||||
|
* |
||||||
|
* @param list |
||||||
|
* @param parentId |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static List<CityVo> list2TreeConverter(List<CityVo> list, int parentId) { |
||||||
|
List<CityVo> returnList = new ArrayList<>(); |
||||||
|
|
||||||
|
for (CityVo res : list) { |
||||||
|
//判断对象是否为根节点
|
||||||
|
|
||||||
|
if (res.getPid() == parentId) { |
||||||
|
//该节点为根节点,开始递归
|
||||||
|
|
||||||
|
//通过递归为节点设置childList
|
||||||
|
recursionFn(list, res); |
||||||
|
|
||||||
|
returnList.add(res); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return returnList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 递归列表 |
||||||
|
* 通过递归,给指定t节点设置childList |
||||||
|
* |
||||||
|
* @param list |
||||||
|
* @param t |
||||||
|
*/ |
||||||
|
public static void recursionFn(List<CityVo> list, CityVo t) { |
||||||
|
//只能获取当前t节点的子节点集,并不是所有子节点集
|
||||||
|
List<CityVo> childsList = getChildList(list, t); |
||||||
|
|
||||||
|
//设置他的子集对象集
|
||||||
|
t.setC(childsList); |
||||||
|
|
||||||
|
//迭代子集对象集
|
||||||
|
|
||||||
|
//遍历完,则退出递归
|
||||||
|
for (CityVo nextChild : childsList) { |
||||||
|
|
||||||
|
//判断子集对象是否还有子节点
|
||||||
|
if (!CollectionUtils.isEmpty(childsList)) { |
||||||
|
//有下一个子节点,继续递归
|
||||||
|
recursionFn(list, nextChild); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获得指定节点下的所有子节点 |
||||||
|
* |
||||||
|
* @param list |
||||||
|
* @param t |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static List<CityVo> getChildList(List<CityVo> list, CityVo t) { |
||||||
|
List<CityVo> childsList = new ArrayList<>(); |
||||||
|
//遍历集合元素,如果元素的Parentid==指定元素的id,则说明是该元素的子节点
|
||||||
|
for (CityVo t1 : list) { |
||||||
|
if (t1.getPid().equals(t.getV())) { |
||||||
|
childsList.add(t1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return childsList; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.net.InetAddress; |
||||||
|
import java.net.UnknownHostException; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取IP地址工具类 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public final class IpUtil { |
||||||
|
|
||||||
|
private static final String UNKNOWN = "unknown"; |
||||||
|
private static final String IPV6_LOCAL = "0:0:0:0:0:0:0:1"; |
||||||
|
|
||||||
|
private IpUtil(){ |
||||||
|
throw new AssertionError(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取请求用户的IP地址 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getRequestIp() { |
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||||
|
HttpServletRequest request = attributes.getRequest(); |
||||||
|
return getRequestIp(request); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取请求用户的IP地址 |
||||||
|
* @param request |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getRequestIp(HttpServletRequest request) { |
||||||
|
String ip = request.getHeader("x-forwarded-for"); |
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { |
||||||
|
ip = request.getHeader("Proxy-Client-IP"); |
||||||
|
} |
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { |
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP"); |
||||||
|
} |
||||||
|
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { |
||||||
|
ip = request.getRemoteAddr(); |
||||||
|
} |
||||||
|
|
||||||
|
if (IPV6_LOCAL.equals(ip)){ |
||||||
|
ip = getLocalhostIp(); |
||||||
|
} |
||||||
|
return ip; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getLocalhostIp(){ |
||||||
|
try { |
||||||
|
return InetAddress.getLocalHost().getHostAddress(); |
||||||
|
} catch (UnknownHostException e) { |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,184 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
|
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException; |
||||||
|
import com.fasterxml.jackson.core.type.TypeReference; |
||||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import org.apache.commons.logging.Log; |
||||||
|
import org.apache.commons.logging.LogFactory; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class JacksonUtil { |
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(JacksonUtil.class); |
||||||
|
|
||||||
|
public static String parseString(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
if (leaf != null) { |
||||||
|
return leaf.asText(); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static List<String> parseStringList(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
|
||||||
|
if (leaf != null) { |
||||||
|
return mapper.convertValue(leaf, new TypeReference<List<String>>() { |
||||||
|
}); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static Integer parseInteger(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
if (leaf != null) { |
||||||
|
return leaf.asInt(); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static List<Integer> parseIntegerList(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
|
||||||
|
if (leaf != null) { |
||||||
|
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() { |
||||||
|
}); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static Boolean parseBoolean(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
if (leaf != null) { |
||||||
|
return leaf.asBoolean(); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static Short parseShort(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
if (leaf != null) { |
||||||
|
Integer value = leaf.asInt(); |
||||||
|
return value.shortValue(); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static Byte parseByte(String body, String field) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
JsonNode leaf = node.get(field); |
||||||
|
if (leaf != null) { |
||||||
|
Integer value = leaf.asInt(); |
||||||
|
return value.byteValue(); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> T parseObject(String body, String field, Class<T> clazz) { |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
JsonNode node; |
||||||
|
try { |
||||||
|
node = mapper.readTree(body); |
||||||
|
node = node.get(field); |
||||||
|
return mapper.treeToValue(node, clazz); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static Object toNode(String json) { |
||||||
|
if (json == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
ObjectMapper mapper = new ObjectMapper(); |
||||||
|
try { |
||||||
|
|
||||||
|
return mapper.readTree(json); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static Map<String, String> toMap(String data) { |
||||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||||
|
try { |
||||||
|
return objectMapper.readValue(data, new TypeReference<Map<String, String>>() { |
||||||
|
}); |
||||||
|
} catch (IOException e) { |
||||||
|
logger.error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public static String toJson(Object data) { |
||||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||||
|
try { |
||||||
|
return objectMapper.writeValueAsString(data); |
||||||
|
} catch (JsonProcessingException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,107 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil; |
||||||
|
import com.auth0.jwt.JWT; |
||||||
|
import com.auth0.jwt.JWTVerifier; |
||||||
|
import com.auth0.jwt.algorithms.Algorithm; |
||||||
|
import com.auth0.jwt.exceptions.JWTVerificationException; |
||||||
|
import com.auth0.jwt.interfaces.Claim; |
||||||
|
import com.auth0.jwt.interfaces.DecodedJWT; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName JwtToken |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/4/30 |
||||||
|
**/ |
||||||
|
@Component |
||||||
|
public class JwtToken { |
||||||
|
|
||||||
|
private static String jwtKey; |
||||||
|
private static Integer expiredTimeIn; |
||||||
|
private static Integer defaultScope = 8; |
||||||
|
|
||||||
|
@Value("${yshop.security.jwt-key}") |
||||||
|
public void setJwtKey(String jwtKey) { |
||||||
|
JwtToken.jwtKey = jwtKey; |
||||||
|
} |
||||||
|
|
||||||
|
@Value("${yshop.security.token-expired-in}") |
||||||
|
public void setExpiredTimeIn(Integer expiredTimeIn) { |
||||||
|
JwtToken.expiredTimeIn = expiredTimeIn; |
||||||
|
} |
||||||
|
|
||||||
|
public static Optional<Map<String, Claim>> getClaims(String token) { |
||||||
|
DecodedJWT decodedJWT; |
||||||
|
Algorithm algorithm = Algorithm.HMAC256(JwtToken.jwtKey); |
||||||
|
JWTVerifier jwtVerifier = JWT.require(algorithm).build(); |
||||||
|
try { |
||||||
|
decodedJWT = jwtVerifier.verify(token); |
||||||
|
} catch (JWTVerificationException e) { |
||||||
|
return Optional.empty(); |
||||||
|
} |
||||||
|
return Optional.of(decodedJWT.getClaims()); |
||||||
|
} |
||||||
|
|
||||||
|
public static Boolean verifyToken(String token) { |
||||||
|
try { |
||||||
|
Algorithm algorithm = Algorithm.HMAC256(JwtToken.jwtKey); |
||||||
|
JWTVerifier verifier = JWT.require(algorithm).build(); |
||||||
|
verifier.verify(token); |
||||||
|
} catch (JWTVerificationException e) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public static String getExpireTime(String token){ |
||||||
|
return DateUtil.formatDateTime(JWT.decode(token).getExpiresAt()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static String makeToken(Long uid,String uName, Integer scope) { |
||||||
|
return JwtToken.getToken(uid,uName, scope); |
||||||
|
} |
||||||
|
|
||||||
|
public static String makeToken(Long uid,String uName) { |
||||||
|
return JwtToken.getToken(uid,uName, JwtToken.defaultScope); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getToken(Long uid,String uName, Integer scope) { |
||||||
|
Algorithm algorithm = Algorithm.HMAC256(JwtToken.jwtKey); |
||||||
|
Map<String,Date> map = JwtToken.calculateExpiredIssues(); |
||||||
|
|
||||||
|
return JWT.create() |
||||||
|
.withClaim("uid", uid) |
||||||
|
.withClaim("scope", scope) |
||||||
|
.withClaim("uName", uName) |
||||||
|
.withExpiresAt(map.get("expiredTime")) |
||||||
|
.withIssuedAt(map.get("now")) |
||||||
|
.sign(algorithm); |
||||||
|
} |
||||||
|
|
||||||
|
private static Map<String, Date> calculateExpiredIssues() { |
||||||
|
Map<String, Date> map = new HashMap<>(); |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
Date now = calendar.getTime(); |
||||||
|
calendar.add(Calendar.SECOND, JwtToken.expiredTimeIn); |
||||||
|
map.put("now", now); |
||||||
|
map.put("expiredTime", calendar.getTime()); |
||||||
|
return map; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 手机号码工具类 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
public class PhoneUtil { |
||||||
|
|
||||||
|
/** |
||||||
|
* 手机号码长度 |
||||||
|
*/ |
||||||
|
private static final int PHONE_LENGTH = 11; |
||||||
|
|
||||||
|
/** |
||||||
|
* 脱敏*号 |
||||||
|
*/ |
||||||
|
private static final String ASTERISK = "****"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 手机号码脱敏 |
||||||
|
* 截取手机号码前三位,后4为,中间4位使用*号代替 |
||||||
|
* 18812345678 |
||||||
|
* 188****5678 |
||||||
|
* |
||||||
|
* @param phone |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String desensitize(String phone) { |
||||||
|
// 校验手机号码
|
||||||
|
if (StringUtils.isBlank(phone)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
if (phone.length() != PHONE_LENGTH) { |
||||||
|
log.error("手机号码不合法:" + phone); |
||||||
|
return phone; |
||||||
|
} |
||||||
|
|
||||||
|
String before = phone.substring(0,3); |
||||||
|
String after = phone.substring(7,11); |
||||||
|
String desensitizePhone = before + "****" + after; |
||||||
|
return desensitizePhone; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import co.yixiang.app.common.bean.RequestDetail; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 记录请求详情信息到当前线程中 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
public class RequestDetailThreadLocal { |
||||||
|
|
||||||
|
private static ThreadLocal<RequestDetail> threadLocal = new ThreadLocal<>(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置请求信息到当前线程中 |
||||||
|
* |
||||||
|
* @param requestDetail |
||||||
|
*/ |
||||||
|
public static void setRequestDetail(RequestDetail requestDetail) { |
||||||
|
threadLocal.set(requestDetail); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从当前线程中获取请求信息 |
||||||
|
*/ |
||||||
|
public static RequestDetail getRequestDetail() { |
||||||
|
return threadLocal.get(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 销毁 |
||||||
|
*/ |
||||||
|
public static void remove() { |
||||||
|
threadLocal.remove(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 获取Request工具类 |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/26 |
||||||
|
**/ |
||||||
|
public class RequestUtils { |
||||||
|
|
||||||
|
public static HttpServletRequest getRequest() { |
||||||
|
ServletRequestAttributes ra= (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||||
|
return ra.getRequest(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.utils.RedisUtils; |
||||||
|
import com.aliyuncs.CommonRequest; |
||||||
|
import com.aliyuncs.CommonResponse; |
||||||
|
import com.aliyuncs.DefaultAcsClient; |
||||||
|
import com.aliyuncs.IAcsClient; |
||||||
|
import com.aliyuncs.exceptions.ClientException; |
||||||
|
import com.aliyuncs.http.MethodType; |
||||||
|
import com.aliyuncs.profile.DefaultProfile; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 阿里云短信 |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/26 |
||||||
|
**/ |
||||||
|
@Slf4j |
||||||
|
@Configuration(proxyBeanMethods = false) |
||||||
|
public class SmsUtils { |
||||||
|
|
||||||
|
private static RedisUtils redisUtils; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
public SmsUtils(RedisUtils redisUtils){ |
||||||
|
SmsUtils.redisUtils = redisUtils; |
||||||
|
} |
||||||
|
/** |
||||||
|
* 发送短信 |
||||||
|
* @param phoneNumbers 手机号 |
||||||
|
* @param templateParam 短信模板变量对应的实际值,JSON格式 |
||||||
|
*/ |
||||||
|
public static void sendSms(String phoneNumbers, String templateParam) throws ClientException { |
||||||
|
String regionId = redisUtils.getY("sms_region"); |
||||||
|
String accessKeyId = redisUtils.getY("sms_access_key"); |
||||||
|
String accessKeySecret = redisUtils.getY("sms_access_secret"); |
||||||
|
String sign = redisUtils.getY("sms_sign"); |
||||||
|
String templateId = redisUtils.getY("sms_templateId"); |
||||||
|
DefaultProfile profile = DefaultProfile.getProfile( |
||||||
|
regionId, |
||||||
|
accessKeyId, |
||||||
|
accessKeySecret); |
||||||
|
IAcsClient client = new DefaultAcsClient(profile); |
||||||
|
|
||||||
|
CommonRequest request = new CommonRequest(); |
||||||
|
|
||||||
|
request.setMethod(MethodType.POST); |
||||||
|
request.setDomain("dysmsapi.aliyuncs.com"); |
||||||
|
request.setVersion("2017-05-25"); |
||||||
|
request.setAction("SendSms"); |
||||||
|
request.putQueryParameter("RegionId", regionId); |
||||||
|
request.putQueryParameter("PhoneNumbers", phoneNumbers); |
||||||
|
request.putQueryParameter("SignName", sign); |
||||||
|
request.putQueryParameter("TemplateCode", templateId); |
||||||
|
request.putQueryParameter("TemplateParam", templateParam); |
||||||
|
CommonResponse response = client.getCommonResponse(request); |
||||||
|
System.out.println(response.getData()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package co.yixiang.app.common.util; |
||||||
|
|
||||||
|
import org.springframework.beans.BeansException; |
||||||
|
import org.springframework.context.ApplicationContext; |
||||||
|
import org.springframework.context.ApplicationContextAware; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Spring工具类,获取Spring上下文对象等 |
||||||
|
* @author hupeng |
||||||
|
* @date 2020-04-30 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
public class SpringContextUtil implements ApplicationContextAware { |
||||||
|
|
||||||
|
private static ApplicationContext applicationContext = null; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
||||||
|
if(SpringContextUtil.applicationContext == null){ |
||||||
|
SpringContextUtil.applicationContext = applicationContext; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static ApplicationContext getApplicationContext() { |
||||||
|
return applicationContext; |
||||||
|
} |
||||||
|
|
||||||
|
public static Object getBean(String name){ |
||||||
|
return getApplicationContext().getBean(name); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> T getBean(Class<T> clazz){ |
||||||
|
return getApplicationContext().getBean(clazz); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> T getBean(String name,Class<T> clazz){ |
||||||
|
return getApplicationContext().getBean(name, clazz); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package co.yixiang.app.common.web.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
@Data |
||||||
|
@ApiModel("ID参数") |
||||||
|
public class IdParam implements Serializable { |
||||||
|
private static final long serialVersionUID = -5353973980674510450L; |
||||||
|
|
||||||
|
@NotBlank(message="ID不能为空") |
||||||
|
@ApiModelProperty(value = "地址ID") |
||||||
|
private String id; |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package co.yixiang.app.common.web.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
@ApiModel("主键状态VO") |
||||||
|
public class IdStatusParam implements Serializable { |
||||||
|
private static final long serialVersionUID = -7581307955242965701L; |
||||||
|
|
||||||
|
@ApiModelProperty("主键ID") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@ApiModelProperty("状态,1:启用 0:禁用") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
public String getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(String id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public Integer getStatus() { |
||||||
|
return status; |
||||||
|
} |
||||||
|
|
||||||
|
public void setStatus(Integer status) { |
||||||
|
this.status = status; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "IdStatusVo{" + |
||||||
|
"id='" + id + '\'' + |
||||||
|
", status=" + status + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package co.yixiang.app.common.web.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
@ApiModel("名称参数") |
||||||
|
public class NameParam implements Serializable { |
||||||
|
private static final long serialVersionUID = -3710501706034574149L; |
||||||
|
|
||||||
|
@ApiModelProperty("名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "NameParam{" + |
||||||
|
"name='" + name + '\'' + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
package co.yixiang.app.common.web.param; |
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.OrderItem; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel("可排序查询参数对象") |
||||||
|
public abstract class OrderQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 57714391204790143L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "排序") |
||||||
|
private List<OrderItem> orders; |
||||||
|
|
||||||
|
public void defaultOrder(OrderItem orderItem){ |
||||||
|
this.defaultOrders(Arrays.asList(orderItem)); |
||||||
|
} |
||||||
|
|
||||||
|
public void defaultOrders(List<OrderItem> orderItems){ |
||||||
|
if (CollectionUtil.isEmpty(orderItems)){ |
||||||
|
return; |
||||||
|
} |
||||||
|
this.orders = orderItems; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
package co.yixiang.app.common.web.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
|
||||||
|
@ApiModel("ID-NAME-VO") |
||||||
|
public class CommonIdName { |
||||||
|
|
||||||
|
@ApiModelProperty("id") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@ApiModelProperty("名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
|
||||||
|
public String getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void setId(String id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public CommonIdName(String id, String name) { |
||||||
|
super(); |
||||||
|
this.id = id; |
||||||
|
this.name = name; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public CommonIdName() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "CommonIdName [id=" + id + ", name=" + name + "]"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
package co.yixiang.app.common.web.vo; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
@ApiModel("分页") |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public class Paging<T> implements Serializable { |
||||||
|
private static final long serialVersionUID = -1683800405530086022L; |
||||||
|
|
||||||
|
@ApiModelProperty("总行数") |
||||||
|
@JSONField(name = "total") |
||||||
|
@JsonProperty("total") |
||||||
|
private long total = 0; |
||||||
|
|
||||||
|
@ApiModelProperty("数据列表") |
||||||
|
@JSONField(name = "records") |
||||||
|
@JsonProperty("records") |
||||||
|
private List<T> records = Collections.emptyList(); |
||||||
|
|
||||||
|
public Paging() { |
||||||
|
} |
||||||
|
|
||||||
|
public Paging(IPage page) { |
||||||
|
this.total = page.getTotal(); |
||||||
|
this.records = page.getRecords(); |
||||||
|
} |
||||||
|
|
||||||
|
public long getTotal() { |
||||||
|
return total; |
||||||
|
} |
||||||
|
|
||||||
|
public void setTotal(long total) { |
||||||
|
this.total = total; |
||||||
|
} |
||||||
|
|
||||||
|
public List<T> getRecords() { |
||||||
|
return records; |
||||||
|
} |
||||||
|
|
||||||
|
public void setRecords(List<T> records) { |
||||||
|
this.records = records; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "Paging{" + |
||||||
|
"total=" + total + |
||||||
|
", records=" + records + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName BargainShareParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/20 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class BargainShareParam { |
||||||
|
|
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "砍价产品ID") |
||||||
|
private String bargainId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "来源") |
||||||
|
private String from; |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName PinkCancelParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/23 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class PinkCancelParam { |
||||||
|
|
||||||
|
@NotBlank(message = "参数错误") |
||||||
|
@ApiModelProperty(value = "拼团产品ID") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@NotBlank(message = "参数错误") |
||||||
|
@ApiModelProperty(value = "团购产品id") |
||||||
|
private String cid; |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName BargainShareParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/20 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class PinkShareParam { |
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
private String id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "来源") |
||||||
|
private String from; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 砍价表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-21 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="砍价表查询参数", description="砍价表查询参数") |
||||||
|
public class YxStoreBargainQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 砍价用户帮助表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-21 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="砍价用户帮助表查询参数", description="砍价用户帮助表查询参数") |
||||||
|
public class YxStoreBargainUserHelpQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "砍价产品ID") |
||||||
|
private String bargainId; |
||||||
|
|
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "砍价用户id") |
||||||
|
private String bargainUserUid; |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 用户参与砍价表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-21 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="用户参与砍价表查询参数", description="用户参与砍价表查询参数") |
||||||
|
public class YxStoreBargainUserQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@NotBlank(message = "参数错误") |
||||||
|
@ApiModelProperty(value = "砍价用户ID") |
||||||
|
private String bargainUserUid; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "砍价产品ID") |
||||||
|
private String bargainId; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 拼团产品表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-11-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="拼团产品表查询参数", description="拼团产品表查询参数") |
||||||
|
public class YxStoreCombinationQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 拼团表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-11-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="拼团表查询参数", description="拼团表查询参数") |
||||||
|
public class YxStorePinkQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.activity.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 商品秒杀产品表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-14 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="商品秒杀产品表查询参数", description="商品秒杀产品表查询参数") |
||||||
|
public class YxStoreSeckillQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,310 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.activity.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil; |
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.app.common.aop.NoRepeatSubmit; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.modules.activity.param.BargainShareParam; |
||||||
|
import co.yixiang.app.modules.activity.param.YxStoreBargainUserHelpQueryParam; |
||||||
|
import co.yixiang.app.modules.activity.param.YxStoreBargainUserQueryParam; |
||||||
|
import co.yixiang.app.modules.services.CreatShareProductService; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.constant.SystemConfigConstants; |
||||||
|
import co.yixiang.modules.activity.domain.YxStoreBargainUser; |
||||||
|
import co.yixiang.modules.activity.domain.YxStoreBargainUserHelp; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreBargainService; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreBargainUserHelpService; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreBargainUserService; |
||||||
|
import co.yixiang.modules.activity.vo.BargainCountVo; |
||||||
|
import co.yixiang.modules.activity.vo.BargainVo; |
||||||
|
import co.yixiang.modules.activity.vo.TopCountVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreBargainQueryVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreBargainUserHelpQueryVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreBargainUserQueryVo; |
||||||
|
import co.yixiang.modules.shop.service.YxSystemConfigService; |
||||||
|
import co.yixiang.modules.user.domain.YxUser; |
||||||
|
import co.yixiang.modules.user.service.YxUserService; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.google.common.collect.Maps; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 砍价 前端控制器 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-12-21 |
||||||
|
*/ |
||||||
|
|
||||||
|
@RestController |
||||||
|
@RequestMapping |
||||||
|
@Api(value = "砍价商品", tags = "营销:砍价商品") |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public class AppStoreBargainController { |
||||||
|
|
||||||
|
private final YxStoreBargainService storeBargainService; |
||||||
|
private final YxStoreBargainUserService storeBargainUserService; |
||||||
|
private final YxStoreBargainUserHelpService storeBargainUserHelpService; |
||||||
|
private final YxUserService userService; |
||||||
|
private final YxSystemConfigService systemConfigService; |
||||||
|
private final CreatShareProductService creatShareProductService; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价产品列表 |
||||||
|
*/ |
||||||
|
@GetMapping("/bargain/list") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "page", value = "页码,默认为1", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "limit", value = "页大小,默认为10", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "砍价产品列表",notes = "砍价产品列表") |
||||||
|
public ApiResult<Object> getYxStoreBargainPageList(@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit){ |
||||||
|
|
||||||
|
return ApiResult.resultPage(storeBargainService.getList(page, limit),limit); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价详情 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看砍价产品", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/bargain/detail/{id}") |
||||||
|
@ApiOperation(value = "砍价详情",notes = "砍价详情",response = YxStoreBargainQueryVo.class) |
||||||
|
public ApiResult<BargainVo> getYxStoreBargain(@PathVariable Long id){ |
||||||
|
if(ObjectUtil.isNull(id)) { |
||||||
|
throw new YshopException("参数错误"); |
||||||
|
} |
||||||
|
YxUser yxUser = LocalUser.getUser(); |
||||||
|
return ApiResult.ok(storeBargainService.getDetail(id,yxUser)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价详情统计 |
||||||
|
*/ |
||||||
|
@AppLog(value = "砍价详情统计", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/help/count") |
||||||
|
@ApiOperation(value = "砍价详情统计",notes = "砍价详情统计") |
||||||
|
public ApiResult<BargainCountVo> helpCount(@Validated @RequestBody YxStoreBargainUserHelpQueryParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
Long bargainUserUid = Long.valueOf(param.getBargainUserUid()); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
return ApiResult.ok(storeBargainService.helpCount(bargainId,bargainUserUid,uid)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价顶部统计 |
||||||
|
*/ |
||||||
|
@PostMapping("/bargain/share") |
||||||
|
@ApiOperation(value = "砍价顶部统计",notes = "砍价顶部统计") |
||||||
|
public ApiResult<TopCountVo> topCount(@Validated @RequestBody BargainShareParam param){ |
||||||
|
Long bargainId = null; |
||||||
|
if(NumberUtil.isNumber(param.getBargainId())) { |
||||||
|
bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
} |
||||||
|
return ApiResult.ok(storeBargainService.topCount(bargainId)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 参与砍价 |
||||||
|
*/ |
||||||
|
@AppLog(value = "参与砍价", type = 1) |
||||||
|
@NoRepeatSubmit |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/start") |
||||||
|
@ApiOperation(value = "参与砍价",notes = "参与砍价") |
||||||
|
public ApiResult<Boolean> start(@Validated @RequestBody BargainShareParam param){ |
||||||
|
Long bargainId = null; |
||||||
|
if(NumberUtil.isNumber(param.getBargainId())) { |
||||||
|
bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
} |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
storeBargainUserService.setBargain(bargainId,uid); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 帮助好友砍价 |
||||||
|
*/ |
||||||
|
@AppLog(value = "帮助好友砍价", type = 1) |
||||||
|
@NoRepeatSubmit |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/help") |
||||||
|
@ApiOperation(value = "帮助好友砍价",notes = "帮助好友砍价") |
||||||
|
public ApiResult<Map<String,Object>> help(@Validated @RequestBody YxStoreBargainUserHelpQueryParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
Long bargainUserUid = Long.valueOf(param.getBargainUserUid()); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
Map<String,Object> map = Maps.newHashMap(); |
||||||
|
boolean isBargainUserHelp = storeBargainUserService |
||||||
|
.isBargainUserHelp(bargainId,bargainUserUid,uid); |
||||||
|
if(!isBargainUserHelp){ |
||||||
|
map.put("status","SUCCESSFUL"); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
storeBargainService.doHelp(bargainId,bargainUserUid,uid); |
||||||
|
map.put("status","SUCCESS"); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取砍掉金额 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/help/price") |
||||||
|
@ApiOperation(value = "获取砍掉金额",notes = "获取砍掉金额") |
||||||
|
public ApiResult<Map<String,Object>> price(@Validated @RequestBody YxStoreBargainUserHelpQueryParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
Long bargainUserUid = Long.valueOf(param.getBargainUserUid()); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
Map<String,Object> map = Maps.newHashMap(); |
||||||
|
YxStoreBargainUser storeBargainUser = storeBargainUserService |
||||||
|
.getBargainUserInfo(bargainId,bargainUserUid); |
||||||
|
if(ObjectUtil.isNull(storeBargainUser)){ |
||||||
|
map.put("price",0); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
YxStoreBargainUserHelp storeBargainUserHelp = storeBargainUserHelpService |
||||||
|
.getOne(new LambdaQueryWrapper<YxStoreBargainUserHelp>() |
||||||
|
.eq(YxStoreBargainUserHelp::getBargainId,bargainId) |
||||||
|
.eq(YxStoreBargainUserHelp::getBargainUserId,storeBargainUser.getId()) |
||||||
|
.eq(YxStoreBargainUserHelp::getUid,uid).last("limit 1")); |
||||||
|
if(ObjectUtil.isNull(storeBargainUserHelp)){ |
||||||
|
map.put("price",0); |
||||||
|
}else{ |
||||||
|
map.put("price",storeBargainUserHelp.getPrice()); |
||||||
|
} |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 好友帮 |
||||||
|
*/ |
||||||
|
@PostMapping("/bargain/help/list") |
||||||
|
@ApiOperation(value = "好友帮",notes = "好友帮") |
||||||
|
public ApiResult<List<YxStoreBargainUserHelpQueryVo>> helpList(@Validated @RequestBody YxStoreBargainUserHelpQueryParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
Long bargainUserUid = Long.valueOf(param.getBargainUserUid()); |
||||||
|
return ApiResult.ok(storeBargainUserHelpService.getList(bargainId,bargainUserUid |
||||||
|
,param.getPage(),param.getLimit())); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取开启砍价用户信息 |
||||||
|
*/ |
||||||
|
@PostMapping("/bargain/start/user") |
||||||
|
@ApiOperation(value = "获取开启砍价用户信息",notes = "获取开启砍价用户信息") |
||||||
|
public ApiResult<Object> startUser(@Validated @RequestBody YxStoreBargainUserQueryParam param){ |
||||||
|
Long bargainUserUid = Long.valueOf(param.getBargainUserUid()); |
||||||
|
return ApiResult.ok(userService.getYxUserById(bargainUserUid)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价海报 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/poster") |
||||||
|
@ApiOperation(value = "砍价海报",notes = "砍价海报") |
||||||
|
public ApiResult<Map<String,Object>> poster(@Validated @RequestBody BargainShareParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
String siteUrl = systemConfigService.getData(SystemConfigConstants.SITE_URL); |
||||||
|
if(StrUtil.isBlank(siteUrl)){ |
||||||
|
throw new YshopException("未配置h5地址"); |
||||||
|
} |
||||||
|
String apiUrl = systemConfigService.getData(SystemConfigConstants.API_URL); |
||||||
|
if(StrUtil.isBlank(apiUrl)){ |
||||||
|
throw new YshopException("未配置api地址"); |
||||||
|
} |
||||||
|
YxUser userInfo = LocalUser.getUser(); |
||||||
|
Map<String,Object> map = Maps.newHashMap(); |
||||||
|
String url = creatShareProductService.getBargainPosterUrl(bargainId,userInfo,siteUrl,apiUrl,"",param.getFrom()); |
||||||
|
map.put("url",url); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价列表(已参与) |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/bargain/user/list") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "page", value = "页码,默认为1", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "limit", value = "页大小,默认为10", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "砍价列表(已参与)",notes = "砍价列表(已参与)") |
||||||
|
public ApiResult<List<YxStoreBargainUserQueryVo>> bargainUserList( |
||||||
|
@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
List<YxStoreBargainUserQueryVo> yxStoreBargainUserQueryVos = storeBargainUserService |
||||||
|
.bargainUserList(uid,page,limit); |
||||||
|
if(yxStoreBargainUserQueryVos.isEmpty()) { |
||||||
|
throw new YshopException("暂无参与砍价"); |
||||||
|
} |
||||||
|
return ApiResult.ok(yxStoreBargainUserQueryVos); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 砍价取消 |
||||||
|
*/ |
||||||
|
@AppLog(value = "取消砍价", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/bargain/user/cancel") |
||||||
|
@ApiOperation(value = "砍价取消",notes = "砍价取消") |
||||||
|
public ApiResult<Boolean> bargainCancel(@Validated @RequestBody BargainShareParam param){ |
||||||
|
Long bargainId = Long.valueOf(param.getBargainId()); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
storeBargainUserService.bargainCancel(bargainId,uid); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,162 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.activity.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.modules.activity.param.PinkCancelParam; |
||||||
|
import co.yixiang.app.modules.activity.param.PinkShareParam; |
||||||
|
import co.yixiang.app.modules.services.CreatShareProductService; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.constant.SystemConfigConstants; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreCombinationService; |
||||||
|
import co.yixiang.modules.activity.service.YxStorePinkService; |
||||||
|
import co.yixiang.modules.activity.vo.CombinationQueryVo; |
||||||
|
import co.yixiang.modules.activity.vo.PinkInfoVo; |
||||||
|
import co.yixiang.modules.activity.vo.StoreCombinationVo; |
||||||
|
import co.yixiang.modules.product.service.YxStoreProductRelationService; |
||||||
|
import co.yixiang.modules.shop.service.YxSystemConfigService; |
||||||
|
import co.yixiang.modules.user.domain.YxUser; |
||||||
|
import com.google.common.collect.Maps; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 拼团前端控制器 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-11-19 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
@Api(value = "拼团", tags = "营销:拼团") |
||||||
|
public class AppStoreCombinationController { |
||||||
|
|
||||||
|
private final YxStoreCombinationService storeCombinationService; |
||||||
|
private final YxStorePinkService storePinkService; |
||||||
|
private final YxSystemConfigService systemConfigService; |
||||||
|
private final YxStoreProductRelationService relationService; |
||||||
|
private final CreatShareProductService creatShareProductService; |
||||||
|
|
||||||
|
private String path = ""; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 拼团产品列表 |
||||||
|
*/ |
||||||
|
@GetMapping("/combination/list") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "page", value = "页码,默认为1", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "limit", value = "页大小,默认为10", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "拼团产品列表",notes = "拼团产品列表") |
||||||
|
public ApiResult<CombinationQueryVo> getList(@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit){ |
||||||
|
return ApiResult.ok(storeCombinationService.getList(page, limit)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 拼团产品详情 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看拼团产品详情", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/combination/detail/{id}") |
||||||
|
@ApiOperation(value = "拼团产品详情",notes = "拼团产品详情") |
||||||
|
public ApiResult<StoreCombinationVo> detail(@PathVariable Long id){ |
||||||
|
if(ObjectUtil.isNull(id)) { |
||||||
|
throw new YshopException("参数错误"); |
||||||
|
} |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
StoreCombinationVo storeCombinationVo = storeCombinationService.getDetail(id,uid); |
||||||
|
storeCombinationVo.setUserCollect(relationService |
||||||
|
.isProductRelation(storeCombinationVo.getStoreInfo().getProductId(),uid)); |
||||||
|
return ApiResult.ok(storeCombinationVo); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 拼团明细 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看拼团明细", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/combination/pink/{id}") |
||||||
|
@ApiOperation(value = "拼团明细",notes = "拼团明细") |
||||||
|
public ApiResult<PinkInfoVo> pink(@PathVariable Long id){ |
||||||
|
if(ObjectUtil.isNull(id)) { |
||||||
|
throw new YshopException("参数错误"); |
||||||
|
} |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
return ApiResult.ok(storePinkService.pinkInfo(id,uid)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 拼团海报 |
||||||
|
*/ |
||||||
|
@AppLog(value = "生成拼团海报", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/combination/poster") |
||||||
|
@ApiOperation(value = "拼团海报",notes = "拼团海报") |
||||||
|
public ApiResult<Object> poster(@Validated @RequestBody PinkShareParam param){ |
||||||
|
String siteUrl = systemConfigService.getData(SystemConfigConstants.SITE_URL); |
||||||
|
if(StrUtil.isEmpty(siteUrl)){ |
||||||
|
throw new YshopException("未配置h5地址"); |
||||||
|
} |
||||||
|
String apiUrl = systemConfigService.getData(SystemConfigConstants.API_URL); |
||||||
|
if(StrUtil.isEmpty(apiUrl)){ |
||||||
|
throw new YshopException("未配置api地址"); |
||||||
|
} |
||||||
|
YxUser userInfo = LocalUser.getUser(); |
||||||
|
Map<String,Object> map = Maps.newHashMap(); |
||||||
|
String spreadUrl = creatShareProductService.getPinkPosterUrl(Long.valueOf(param.getId()),userInfo, |
||||||
|
siteUrl,apiUrl,path,param.getFrom()); |
||||||
|
map.put("url",spreadUrl); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 取消开团 |
||||||
|
*/ |
||||||
|
@AppLog(value = "取消开团", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/combination/remove") |
||||||
|
@ApiOperation(value = "取消开团",notes = "取消开团") |
||||||
|
public ApiResult<Boolean> remove(@Validated @RequestBody PinkCancelParam param){ |
||||||
|
Long pinkId = Long.valueOf(param.getId()); |
||||||
|
Long cId = Long.valueOf(param.getCid()); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
storePinkService.removePink(uid,cId,pinkId); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,161 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.activity.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil; |
||||||
|
import cn.hutool.core.util.NumberUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.constant.ShopConstants; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreSeckillService; |
||||||
|
import co.yixiang.modules.activity.service.dto.SeckillTimeDto; |
||||||
|
import co.yixiang.modules.activity.vo.SeckillConfigVo; |
||||||
|
import co.yixiang.modules.activity.vo.StoreSeckillVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreSeckillQueryVo; |
||||||
|
import co.yixiang.modules.product.service.YxStoreProductRelationService; |
||||||
|
import co.yixiang.modules.shop.domain.YxSystemGroupData; |
||||||
|
import co.yixiang.modules.shop.service.YxSystemGroupDataService; |
||||||
|
import co.yixiang.modules.shop.service.dto.YxSystemGroupDataQueryCriteria; |
||||||
|
import co.yixiang.utils.OrderUtil; |
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 商品秒杀产品前端控制器 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-12-14 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@RequestMapping |
||||||
|
@Api(value = "商品秒杀", tags = "营销:商品秒杀") |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
public class AppStoreSeckillController { |
||||||
|
|
||||||
|
private final YxStoreSeckillService yxStoreSeckillService; |
||||||
|
private final YxSystemGroupDataService yxSystemGroupDataService; |
||||||
|
private final YxStoreProductRelationService relationService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 秒杀产品列表 |
||||||
|
*/ |
||||||
|
@GetMapping("/seckill/list/{time}") |
||||||
|
@ApiOperation(value = "秒杀产品列表", notes = "秒杀产品列表") |
||||||
|
public ApiResult<List<YxStoreSeckillQueryVo>> getYxStoreSeckillPageList(@PathVariable String time, |
||||||
|
@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit){ |
||||||
|
if (StrUtil.isBlank(time) || !NumberUtil.isNumber(time)){ |
||||||
|
throw new YshopException("参数错误"); |
||||||
|
} |
||||||
|
return ApiResult.resultPage(yxStoreSeckillService.getList(page, limit, Integer.valueOf(time)),limit); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 根据id获取商品秒杀产品详情 |
||||||
|
*/ |
||||||
|
@AppLog(value = "根据id获取商品秒杀产品详情", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/seckill/detail/{id}") |
||||||
|
@ApiOperation(value = "秒杀产品详情", notes = "秒杀产品详情") |
||||||
|
public ApiResult<StoreSeckillVo> getYxStoreSeckill(@PathVariable Long id){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
StoreSeckillVo storeSeckillVo = yxStoreSeckillService.getDetail(id); |
||||||
|
storeSeckillVo.setUserCollect(relationService |
||||||
|
.isProductRelation(storeSeckillVo.getStoreInfo().getProductId(),uid)); |
||||||
|
return ApiResult.ok(storeSeckillVo); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 秒杀产品时间区间 |
||||||
|
*/ |
||||||
|
@GetMapping("/seckill/index") |
||||||
|
@ApiOperation(value = "秒杀产品时间区间", notes = "秒杀产品时间区间") |
||||||
|
public ApiResult<SeckillConfigVo> getYxStoreSeckillIndex() { |
||||||
|
//获取秒杀配置
|
||||||
|
AtomicInteger seckillTimeIndex = new AtomicInteger(); |
||||||
|
SeckillConfigVo seckillConfigVo = new SeckillConfigVo(); |
||||||
|
|
||||||
|
YxSystemGroupDataQueryCriteria queryCriteria = new YxSystemGroupDataQueryCriteria(); |
||||||
|
queryCriteria.setGroupName(ShopConstants.YSHOP_SECKILL_TIME); |
||||||
|
queryCriteria.setStatus(1); |
||||||
|
List<YxSystemGroupData> yxSystemGroupDataList = yxSystemGroupDataService.queryAll(queryCriteria); |
||||||
|
|
||||||
|
List<SeckillTimeDto> list = new ArrayList<>(); |
||||||
|
int today = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(new Date())); |
||||||
|
yxSystemGroupDataList.forEach(i -> { |
||||||
|
String jsonStr = i.getValue(); |
||||||
|
JSONObject jsonObject = JSON.parseObject(jsonStr); |
||||||
|
int time = Integer.valueOf(jsonObject.get("time").toString());//时间 5
|
||||||
|
int continued = Integer.valueOf(jsonObject.get("continued").toString());//活动持续事件 3
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("HH"); |
||||||
|
String nowTime = sdf.format(new Date()); |
||||||
|
String index = nowTime.substring(0, 1); |
||||||
|
int currentHour = "0".equals(index) ? Integer.valueOf(nowTime.substring(1, 2)) : Integer.valueOf(nowTime); |
||||||
|
SeckillTimeDto seckillTimeDto = new SeckillTimeDto(); |
||||||
|
seckillTimeDto.setId(i.getId()); |
||||||
|
//活动结束时间
|
||||||
|
int activityEndHour = time + continued; |
||||||
|
if (activityEndHour > 24) { |
||||||
|
seckillTimeDto.setState("即将开始"); |
||||||
|
seckillTimeDto.setTime(jsonObject.get("time").toString().length() > 1 ? jsonObject.get("time").toString() + ":00" : "0" + jsonObject.get("time").toString() + ":00"); |
||||||
|
seckillTimeDto.setStatus(2); |
||||||
|
seckillTimeDto.setStop(today + activityEndHour * 3600); |
||||||
|
} else { |
||||||
|
if (currentHour >= time && currentHour < activityEndHour) { |
||||||
|
seckillTimeDto.setState("抢购中"); |
||||||
|
seckillTimeDto.setTime(jsonObject.get("time").toString().length() > 1 ? jsonObject.get("time").toString() + ":00" : "0" + jsonObject.get("time").toString() + ":00"); |
||||||
|
seckillTimeDto.setStatus(1); |
||||||
|
seckillTimeDto.setStop(today + activityEndHour * 3600); |
||||||
|
seckillTimeIndex.set(yxSystemGroupDataList.indexOf(i)); |
||||||
|
} else if (currentHour < time) { |
||||||
|
seckillTimeDto.setState("即将开始"); |
||||||
|
seckillTimeDto.setTime(jsonObject.get("time").toString().length() > 1 ? jsonObject.get("time").toString() + ":00" : "0" + jsonObject.get("time").toString() + ":00"); |
||||||
|
seckillTimeDto.setStatus(2); |
||||||
|
seckillTimeDto.setStop(OrderUtil.dateToTimestamp(new Date()) + activityEndHour * 3600); |
||||||
|
} else if (currentHour >= activityEndHour) { |
||||||
|
seckillTimeDto.setState("已结束"); |
||||||
|
seckillTimeDto.setTime(jsonObject.get("time").toString().length() > 1 ? jsonObject.get("time").toString() + ":00" : "0" + jsonObject.get("time").toString() + ":00"); |
||||||
|
seckillTimeDto.setStatus(0); |
||||||
|
seckillTimeDto.setStop(today + activityEndHour * 3600); |
||||||
|
} |
||||||
|
} |
||||||
|
list.add(seckillTimeDto); |
||||||
|
}); |
||||||
|
seckillConfigVo.setSeckillTimeIndex(seckillTimeIndex.get()); |
||||||
|
seckillConfigVo.setSeckillTime(list); |
||||||
|
return ApiResult.ok(seckillConfigVo); |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,39 @@ |
|||||||
|
package co.yixiang.app.modules.activity.rest; |
||||||
|
|
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.modules.product.param.YxStoreProductQueryParam; |
||||||
|
import co.yixiang.modules.product.service.YxStoreProductService; |
||||||
|
import co.yixiang.modules.product.vo.YxStoreProductQueryVo; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 积分兑换前端控制器 |
||||||
|
* @author yshop |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@RequestMapping |
||||||
|
@Api(value = "积分兑换", tags = "营销:积分兑换") |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
public class StoreIntegralController { |
||||||
|
|
||||||
|
private final YxStoreProductService storeProductService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取积分产品列表 |
||||||
|
*/ |
||||||
|
@GetMapping("/products/integral") |
||||||
|
@ApiOperation(value = "获取积分产品列表",notes = "获取积分产品列表") |
||||||
|
public ApiResult<List<YxStoreProductQueryVo>> goodsList(YxStoreProductQueryParam productQueryParam){ |
||||||
|
return ApiResult.ok(storeProductService.getGoodsList(productQueryParam)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 登陆LoginDTO |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/05/02 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class HLoginParam { |
||||||
|
|
||||||
|
@NotBlank(message = "用户名必填") |
||||||
|
@ApiModelProperty(value = "用户名") |
||||||
|
private String username; |
||||||
|
|
||||||
|
@NotBlank(message = "密码必填") |
||||||
|
@ApiModelProperty(value = "密码") |
||||||
|
private String password; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "分销绑定关系的ID") |
||||||
|
private String spread; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName LoginParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/01/15 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class LoginParam { |
||||||
|
|
||||||
|
@NotBlank(message = "code参数缺失") |
||||||
|
@ApiModelProperty(value = "小程序登陆code") |
||||||
|
private String code; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "分销绑定关系的ID") |
||||||
|
private String spread; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "小程序完整用户信息的加密数据") |
||||||
|
private String encryptedData; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "小程序加密算法的初始向量") |
||||||
|
private String iv; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author : gzlv 2021/7/20 15:09 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class LoginVerifyParam { |
||||||
|
|
||||||
|
@NotBlank(message = "手机号必填") |
||||||
|
@ApiModelProperty(value = "手机号码") |
||||||
|
private String account; |
||||||
|
|
||||||
|
@NotBlank(message = "验证码必填") |
||||||
|
@ApiModelProperty(value = "验证码") |
||||||
|
private String captcha; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "分销绑定关系的ID") |
||||||
|
private String spread; |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName RegParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/25 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class RegParam { |
||||||
|
|
||||||
|
@NotBlank(message = "手机号必填") |
||||||
|
@ApiModelProperty(value = "手机号码") |
||||||
|
private String account; |
||||||
|
|
||||||
|
@NotBlank(message = "验证码必填") |
||||||
|
@ApiModelProperty(value = "验证码") |
||||||
|
private String captcha; |
||||||
|
|
||||||
|
@NotBlank(message = "密码必填") |
||||||
|
@ApiModelProperty(value = "密码") |
||||||
|
private String password; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "分销绑定关系的ID") |
||||||
|
private String spread; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "邀请码") |
||||||
|
private String inviteCode; |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author : gzlv 2021/7/20 17:27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class UpdatePasswordParam { |
||||||
|
|
||||||
|
@NotBlank(message = "手机号必填") |
||||||
|
@ApiModelProperty(value = "手机号码") |
||||||
|
private String account; |
||||||
|
|
||||||
|
@NotBlank(message = "验证码必填") |
||||||
|
@ApiModelProperty(value = "验证码") |
||||||
|
private String captcha; |
||||||
|
|
||||||
|
@NotBlank(message = "密码必填") |
||||||
|
@ApiModelProperty(value = "密码") |
||||||
|
private String password; |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package co.yixiang.app.modules.auth.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName VerityParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/10/25 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class VerityParam { |
||||||
|
|
||||||
|
@NotBlank(message = "手机号必填") |
||||||
|
@ApiModelProperty(value = "手机号码") |
||||||
|
private String phone; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "短信类型 bind绑定手机短信 login登陆短信 register注册短信") |
||||||
|
private String type; |
||||||
|
} |
@ -0,0 +1,326 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.auth.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.RandomUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import cn.hutool.crypto.SecureUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.app.common.enums.SmsTypeEnum; |
||||||
|
import co.yixiang.app.common.util.JwtToken; |
||||||
|
import co.yixiang.app.common.util.SmsUtils; |
||||||
|
import co.yixiang.app.modules.auth.param.*; |
||||||
|
import co.yixiang.app.modules.services.AppAuthService; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.constant.ShopConstants; |
||||||
|
import co.yixiang.enums.ShopCommonEnum; |
||||||
|
import co.yixiang.modules.user.domain.YxUser; |
||||||
|
import co.yixiang.modules.user.service.YxUserService; |
||||||
|
|
||||||
|
import co.yixiang.utils.RedisUtils; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.aliyuncs.exceptions.ClientException; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 认证服务 |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/4/30 |
||||||
|
**/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
@Api(value = "认证模块", tags = "商城:认证") |
||||||
|
public class LetterAppAuthController { |
||||||
|
|
||||||
|
private final YxUserService userService; |
||||||
|
private final RedisUtils redisUtil; |
||||||
|
private final AppAuthService authService; |
||||||
|
private Boolean singleLogin = false; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 小程序登陆接口 |
||||||
|
*/ |
||||||
|
@PostMapping("/wxapp/auth") |
||||||
|
@ApiOperation(value = "小程序登陆", notes = "小程序登陆") |
||||||
|
public ApiResult<Map<String, Object>> login(@Validated @RequestBody LoginParam loginParam, |
||||||
|
HttpServletRequest request) { |
||||||
|
|
||||||
|
YxUser yxUser = authService.wxappLogin(loginParam); |
||||||
|
String token = JwtToken.makeToken(yxUser.getUid(), yxUser.getUsername()); |
||||||
|
String expiresTimeStr = JwtToken.getExpireTime(token); |
||||||
|
|
||||||
|
// 返回 token
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>(2); |
||||||
|
|
||||||
|
map.put("token", token); |
||||||
|
map.put("expires_time", expiresTimeStr); |
||||||
|
|
||||||
|
// 保存在线信息
|
||||||
|
authService.save(yxUser, token, request); |
||||||
|
if (singleLogin) { |
||||||
|
authService.checkLoginOnUser(yxUser.getUsername(), token); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
return ApiResult.ok(map).setMsg("登陆成功"); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据手机号查询用户状态 |
||||||
|
*/ |
||||||
|
@GetMapping("/wxapp/authPhone/{phone}") |
||||||
|
@ApiOperation(value = "根据手机号查询用户状态", notes = "根据手机号查询用户状态") |
||||||
|
public ApiResult<YxUser> authPhone(@PathVariable String phone) { |
||||||
|
return ApiResult.ok(authService.authPhone(phone)).setMsg("获取成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/wxapp/loginAuth") |
||||||
|
@ApiOperation(value = "小程序获取用户信息", notes = "小程序获取用户信息") |
||||||
|
public ApiResult<YxUser> loginAuth(@Validated @RequestBody LoginParam loginParam) { |
||||||
|
Long uid = LocalUser.getUidByToken(); |
||||||
|
String sessionKey = redisUtil.get(ShopConstants.YSHOP_MINI_SESSION_KET+ uid).toString(); |
||||||
|
YxUser yxUser = authService.loginAuth(loginParam, uid, sessionKey); |
||||||
|
return ApiResult.ok(yxUser).setMsg("获取成功"); |
||||||
|
|
||||||
|
} |
||||||
|
/** |
||||||
|
* 微信公众号授权 |
||||||
|
*/ |
||||||
|
@GetMapping("/wechat/auth") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "code", value = "微信授权code", paramType = "query", dataType = "string"), |
||||||
|
@ApiImplicitParam(name = "spread", value = "分销绑定关系的ID", paramType = "query", dataType = "string") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "微信公众号授权", notes = "微信公众号授权") |
||||||
|
public ApiResult<Map<String, Object>> authLogin(@RequestParam(value = "code") String code, |
||||||
|
@RequestParam(value = "spread") String spread, |
||||||
|
HttpServletRequest request) { |
||||||
|
|
||||||
|
YxUser yxUser = authService.wechatLogin(code,spread); |
||||||
|
String token = JwtToken.makeToken(yxUser.getUid(),yxUser.getUsername()); |
||||||
|
String expiresTimeStr = JwtToken.getExpireTime(token); |
||||||
|
|
||||||
|
// 返回 token
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>(2) {{ |
||||||
|
put("token", token); |
||||||
|
put("expires_time", expiresTimeStr); |
||||||
|
}}; |
||||||
|
|
||||||
|
// 保存在线信息
|
||||||
|
authService.save(yxUser, token, request); |
||||||
|
if(singleLogin){ |
||||||
|
authService.checkLoginOnUser(yxUser.getUsername(),token); |
||||||
|
} |
||||||
|
|
||||||
|
return ApiResult.ok(map).setMsg("登陆成功"); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("H5登录授权") |
||||||
|
@PostMapping(value = "/login") |
||||||
|
public ApiResult<Map<String, Object>> login(@Validated @RequestBody HLoginParam loginDTO, HttpServletRequest request) { |
||||||
|
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() |
||||||
|
.eq(YxUser::getUsername,loginDTO.getUsername()) |
||||||
|
.eq(YxUser::getPassword,SecureUtil.md5(loginDTO.getPassword())),false); |
||||||
|
|
||||||
|
if(yxUser == null) { |
||||||
|
throw new YshopException("账号或者密码不正确"); |
||||||
|
} |
||||||
|
|
||||||
|
String token = JwtToken.makeToken(yxUser.getUid(),yxUser.getUsername()); |
||||||
|
String expiresTimeStr = JwtToken.getExpireTime(token); |
||||||
|
|
||||||
|
// 保存在线信息
|
||||||
|
authService.save(yxUser, token, request); |
||||||
|
// 返回 token
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>(2) {{ |
||||||
|
put("token", token); |
||||||
|
put("expires_time", expiresTimeStr); |
||||||
|
}}; |
||||||
|
|
||||||
|
userService.setSpread(loginDTO.getSpread(),yxUser.getUid()); |
||||||
|
|
||||||
|
if(singleLogin){ |
||||||
|
//踢掉之前已经登录的token
|
||||||
|
authService.checkLoginOnUser(yxUser.getUsername(),token); |
||||||
|
} |
||||||
|
|
||||||
|
return ApiResult.ok(map).setMsg("登陆成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("H5验证码登录授权") |
||||||
|
@PostMapping(value = "/login/mobile") |
||||||
|
public ApiResult<Map<String, Object>> loginVerify(@Validated @RequestBody LoginVerifyParam loginVerifyParam, HttpServletRequest request) { |
||||||
|
Object codeObj = redisUtil.get("code_" + loginVerifyParam.getAccount()); |
||||||
|
if(codeObj == null){ |
||||||
|
throw new YshopException("请先获取验证码"); |
||||||
|
} |
||||||
|
String code = codeObj.toString(); |
||||||
|
if (!StrUtil.equals(code, loginVerifyParam.getCaptcha())) { |
||||||
|
throw new YshopException("验证码错误"); |
||||||
|
} |
||||||
|
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() |
||||||
|
.eq(YxUser::getUsername,loginVerifyParam.getAccount())); |
||||||
|
|
||||||
|
if(yxUser == null) { |
||||||
|
throw new YshopException("账号不存在"); |
||||||
|
} |
||||||
|
|
||||||
|
String token = JwtToken.makeToken(yxUser.getUid(),yxUser.getUsername()); |
||||||
|
String expiresTimeStr = JwtToken.getExpireTime(token); |
||||||
|
|
||||||
|
// 保存在线信息
|
||||||
|
authService.save(yxUser, token, request); |
||||||
|
// 返回 token
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>(2) {{ |
||||||
|
put("token", token); |
||||||
|
put("expires_time", expiresTimeStr); |
||||||
|
}}; |
||||||
|
|
||||||
|
userService.setSpread(loginVerifyParam.getSpread(),yxUser.getUid()); |
||||||
|
|
||||||
|
if(singleLogin){ |
||||||
|
//踢掉之前已经登录的token
|
||||||
|
authService.checkLoginOnUser(yxUser.getUsername(),token); |
||||||
|
} |
||||||
|
|
||||||
|
return ApiResult.ok(map).setMsg("登陆成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@AuthCheck |
||||||
|
@ApiOperation("修改密码") |
||||||
|
@PostMapping(value = "/register/reset") |
||||||
|
public ApiResult<Boolean> updatePassword(@Validated @RequestBody UpdatePasswordParam updatePasswordParam, HttpServletRequest request) { |
||||||
|
Object codeObj = redisUtil.get("code_" + updatePasswordParam.getAccount()); |
||||||
|
if(codeObj == null){ |
||||||
|
throw new YshopException("请先获取验证码"); |
||||||
|
} |
||||||
|
String code = codeObj.toString(); |
||||||
|
if (!StrUtil.equals(code, updatePasswordParam.getCaptcha())) { |
||||||
|
throw new YshopException("验证码错误"); |
||||||
|
} |
||||||
|
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() |
||||||
|
.eq(YxUser::getUsername,updatePasswordParam.getAccount())); |
||||||
|
|
||||||
|
if(yxUser == null) { |
||||||
|
throw new YshopException("账号不存在,数据错误"); |
||||||
|
} |
||||||
|
yxUser.setPassword(SecureUtil.md5(updatePasswordParam.getPassword())); |
||||||
|
boolean b = userService.updateById(yxUser); |
||||||
|
if (!b) { |
||||||
|
throw new YshopException("修改失败"); |
||||||
|
} |
||||||
|
String bearerToken = request.getHeader("Authorization"); |
||||||
|
String[] tokens = bearerToken.split(" "); |
||||||
|
String token = tokens[1]; |
||||||
|
authService.logout(LocalUser.getUser().getUsername(), token); |
||||||
|
|
||||||
|
return ApiResult.ok(true).setMsg("修改成功"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/register") |
||||||
|
@ApiOperation(value = "H5/APP注册新用户", notes = "H5/APP注册新用户") |
||||||
|
public ApiResult<String> register(@Validated @RequestBody RegParam param) { |
||||||
|
Object codeObj = redisUtil.get("code_" + param.getAccount()); |
||||||
|
if(codeObj == null){ |
||||||
|
return ApiResult.fail("请先获取验证码"); |
||||||
|
} |
||||||
|
String code = codeObj.toString(); |
||||||
|
if (!StrUtil.equals(code, param.getCaptcha())) { |
||||||
|
return ApiResult.fail("验证码错误"); |
||||||
|
} |
||||||
|
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() |
||||||
|
.eq(YxUser::getPhone,param.getAccount()),false); |
||||||
|
if (ObjectUtil.isNotNull(yxUser)) { |
||||||
|
return ApiResult.fail("用户已存在"); |
||||||
|
} |
||||||
|
|
||||||
|
authService.register(param); |
||||||
|
return ApiResult.ok("","注册成功"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/register/verify") |
||||||
|
@ApiOperation(value = "短信验证码发送", notes = "短信验证码发送") |
||||||
|
public ApiResult<String> verify(@Validated @RequestBody VerityParam param) { |
||||||
|
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery() |
||||||
|
.eq(YxUser::getPhone,param.getPhone()),false); |
||||||
|
if (SmsTypeEnum.REGISTER.getValue().equals(param.getType()) && ObjectUtil.isNotNull(yxUser)) { |
||||||
|
return ApiResult.fail("手机号已注册"); |
||||||
|
} |
||||||
|
if (SmsTypeEnum.LOGIN.getValue().equals(param.getType()) && ObjectUtil.isNull(yxUser)) { |
||||||
|
return ApiResult.fail("账号不存在"); |
||||||
|
} |
||||||
|
String codeKey = "code_" + param.getPhone(); |
||||||
|
if (ObjectUtil.isNotNull(redisUtil.get(codeKey))) { |
||||||
|
return ApiResult.fail("10分钟内有效:" + redisUtil.get(codeKey).toString()); |
||||||
|
} |
||||||
|
String code = RandomUtil.randomNumbers(ShopConstants.YSHOP_SMS_SIZE); |
||||||
|
|
||||||
|
//redis存储
|
||||||
|
redisUtil.set(codeKey, code, ShopConstants.YSHOP_SMS_REDIS_TIME); |
||||||
|
|
||||||
|
String enable = redisUtil.getY("sms_enable"); |
||||||
|
if (ShopCommonEnum.ENABLE_2.getValue().toString().equals(enable)) { |
||||||
|
return ApiResult.fail("测试阶段验证码:" + code); |
||||||
|
} |
||||||
|
|
||||||
|
//发送阿里云短信
|
||||||
|
JSONObject json = new JSONObject(); |
||||||
|
json.put("code",code); |
||||||
|
try { |
||||||
|
SmsUtils.sendSms(param.getPhone(),json.toJSONString()); |
||||||
|
} catch (ClientException e) { |
||||||
|
redisUtil.del(codeKey); |
||||||
|
e.printStackTrace(); |
||||||
|
return ApiResult.ok("发送失败:"+e.getErrMsg()); |
||||||
|
} |
||||||
|
return ApiResult.ok("发送成功,请注意查收"); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@AuthCheck |
||||||
|
@ApiOperation(value = "退出登录", notes = "退出登录") |
||||||
|
@PostMapping(value = "/auth/logout") |
||||||
|
public ApiResult<String> logout(HttpServletRequest request) { |
||||||
|
String bearerToken = request.getHeader("Authorization"); |
||||||
|
String[] tokens = bearerToken.split(" "); |
||||||
|
String token = tokens[1]; |
||||||
|
authService.logout(LocalUser.getUser().getUsername(), token); |
||||||
|
return ApiResult.ok("退出成功"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package co.yixiang.app.modules.cart.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName CartIds |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/15 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class CartIdsParm { |
||||||
|
|
||||||
|
@NotNull(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "购物车ID,多个用,分隔开") |
||||||
|
List<String> ids; |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package co.yixiang.app.modules.cart.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.Max; |
||||||
|
import javax.validation.constraints.Min; |
||||||
|
import javax.validation.constraints.NotNull; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 购物车数量CartNumParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/19 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class CartNumParam { |
||||||
|
|
||||||
|
@Min(value = 1,message = "数量不在合法范围内") |
||||||
|
@Max(value = 9999,message = "数量不在合法范围内") |
||||||
|
@ApiModelProperty(value = "购物车数量") |
||||||
|
private Integer number; |
||||||
|
|
||||||
|
@NotNull(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "购物车ID") |
||||||
|
private Long id; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
package co.yixiang.app.modules.cart.param; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.Max; |
||||||
|
import javax.validation.constraints.Min; |
||||||
|
import javax.validation.constraints.NotNull; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 添加购物车CartParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/19 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class CartParam { |
||||||
|
|
||||||
|
@Min(value = 1,message = "数量不在合法范围内") |
||||||
|
@Max(value = 9999,message = "数量不在合法范围内") |
||||||
|
@ApiModelProperty(value = "购物车数量") |
||||||
|
private Integer cartNum; |
||||||
|
|
||||||
|
@JsonProperty(value = "new") |
||||||
|
@ApiModelProperty(value = "是否新购买") |
||||||
|
private Integer isNew = 0; |
||||||
|
|
||||||
|
@NotNull(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "产品ID") |
||||||
|
private Long productId; |
||||||
|
|
||||||
|
//@NotBlank(message = "参数有误")
|
||||||
|
@ApiModelProperty(value = "唯一的ID") |
||||||
|
private String uniqueId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "产品拼团ID") |
||||||
|
private Long combinationId = 0L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "产品秒杀ID") |
||||||
|
private Long secKillId = 0L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "产品砍价ID") |
||||||
|
private Long bargainId = 0L; |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package co.yixiang.app.modules.cart.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 购物车表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-10-25 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel(value="YxStoreCartQueryParam对象", description="购物车表查询参数") |
||||||
|
public class YxStoreCartQueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private Integer numType = 0; |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.cart.rest; |
||||||
|
|
||||||
|
import co.yixiang.annotation.Limit; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.app.common.aop.NoRepeatSubmit; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.modules.cart.param.CartIdsParm; |
||||||
|
import co.yixiang.app.modules.cart.param.CartParam; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.app.modules.cart.param.CartNumParam; |
||||||
|
import co.yixiang.modules.cart.service.YxStoreCartService; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 购物车控制器 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-10-25 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@Api(value = "购物车", tags = "商城:购物车") |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
public class StoreCartController { |
||||||
|
|
||||||
|
private final YxStoreCartService storeCartService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 购物车 获取数量 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/cart/count") |
||||||
|
@ApiOperation(value = "获取数量",notes = "获取数量") |
||||||
|
public ApiResult<Map<String,Object>> count(){ |
||||||
|
Map<String,Object> map = new LinkedHashMap<>(); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
map.put("count",storeCartService.getUserCartNum(uid)); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 购物车 添加 |
||||||
|
*/ |
||||||
|
@AppLog(value = "购物车 添加", type = 1) |
||||||
|
@NoRepeatSubmit |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/cart/add") |
||||||
|
@ApiOperation(value = "添加购物车",notes = "添加购物车") |
||||||
|
@Limit(key = "cart_limit", period = 60, count = 30, name = "cartLimit", prefix = "yshop") |
||||||
|
public ApiResult<Map<String,Object>> add(@Validated @RequestBody CartParam cartParam){ |
||||||
|
Map<String,Object> map = new LinkedHashMap<>(); |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
map.put("cartId",storeCartService.addCart(uid,cartParam.getProductId(),cartParam.getCartNum(), |
||||||
|
cartParam.getUniqueId(),cartParam.getIsNew(),cartParam.getCombinationId(), |
||||||
|
cartParam.getSecKillId(),cartParam.getBargainId())); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 购物车列表 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看购物车列表", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/cart/list") |
||||||
|
@ApiOperation(value = "购物车列表",notes = "购物车列表") |
||||||
|
public ApiResult<Map<String,Object>> getList(){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
return ApiResult.ok(storeCartService.getUserProductCartList(uid,"",null)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改产品数量 |
||||||
|
*/ |
||||||
|
@AppLog(value = "修改购物车产品数量", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/cart/num") |
||||||
|
@ApiOperation(value = "修改产品数量",notes = "修改产品数量") |
||||||
|
public ApiResult<Boolean> cartNum(@Validated @RequestBody CartNumParam param){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
storeCartService.changeUserCartNum(param.getId(), param.getNumber(),uid); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 购物车删除产品 |
||||||
|
*/ |
||||||
|
@AppLog(value = "购物车删除产品", type = 1) |
||||||
|
@NoRepeatSubmit |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/cart/del") |
||||||
|
@ApiOperation(value = "购物车删除产品",notes = "购物车删除产品") |
||||||
|
public ApiResult<Boolean> cartDel(@Validated @RequestBody CartIdsParm parm){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
storeCartService.removeUserCart(uid, parm.getIds()); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.coupon.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 优惠券前台领取表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-10-27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="YxStoreCouponIssueQueryParam对象", description="优惠券前台领取表查询参数") |
||||||
|
public class YxStoreCouponIssueQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.coupon.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 优惠券前台用户领取记录表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-10-27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="YxStoreCouponIssueUserQueryParam对象", description="优惠券前台用户领取记录表查询参数") |
||||||
|
public class YxStoreCouponIssueUserQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package co.yixiang.app.modules.coupon.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 优惠券表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-10-27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="YxStoreCouponQueryParam对象", description="优惠券表查询参数") |
||||||
|
public class YxStoreCouponQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "优惠券ID") |
||||||
|
private String couponId; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.coupon.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 优惠券发放记录表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-10-27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="YxStoreCouponUserQueryParam对象", description="优惠券发放记录表查询参数") |
||||||
|
public class YxStoreCouponUserQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,143 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.coupon.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.aop.NoRepeatSubmit; |
||||||
|
import co.yixiang.app.common.bean.LocalUser; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreCouponIssueService; |
||||||
|
import co.yixiang.modules.activity.service.YxStoreCouponUserService; |
||||||
|
import co.yixiang.modules.activity.vo.StoreCouponUserVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreCouponIssueQueryVo; |
||||||
|
import co.yixiang.modules.activity.vo.YxStoreCouponUserQueryVo; |
||||||
|
import co.yixiang.app.modules.coupon.param.YxStoreCouponQueryParam; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 优惠券 todo |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-10-02 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@Api(value = "优惠券", tags = "营销:优惠券") |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
public class CouponController { |
||||||
|
|
||||||
|
private final YxStoreCouponIssueService couponIssueService; |
||||||
|
private final YxStoreCouponUserService storeCouponUserService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 可领取优惠券列表 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/coupons") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "page", value = "页码,默认为1", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "limit", value = "页大小,默认为10", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "productId", value = "产品ID", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "type", value = "优惠券类型 0通用券 1商品券 2内部券", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "可领取优惠券列表",notes = "可领取优惠券列表") |
||||||
|
public ApiResult<List<YxStoreCouponIssueQueryVo>> getList(@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit, |
||||||
|
@RequestParam(value = "productId",required = false) Long productId, |
||||||
|
@RequestParam(value = "type",required = false) Integer type){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
return ApiResult.ok(couponIssueService.getCouponList(page, limit,uid,productId,type)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 领取优惠券 |
||||||
|
*/ |
||||||
|
@AppLog(value = "领取优惠券", type = 1) |
||||||
|
@NoRepeatSubmit |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/coupon/receive") |
||||||
|
@ApiOperation(value = "领取优惠券",notes = "领取优惠券") |
||||||
|
public ApiResult<Boolean> receive(@Validated @RequestBody YxStoreCouponQueryParam param){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
if(!NumberUtil.isNumber(param.getCouponId())){ |
||||||
|
throw new YshopException("参数非法"); |
||||||
|
} |
||||||
|
Integer couponId = Integer.valueOf(param.getCouponId()); |
||||||
|
couponIssueService.issueUserCoupon(couponId,uid); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户已领取优惠券 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看已领取优惠券", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/coupons/user/{type}") |
||||||
|
@ApiOperation(value = "用户已领取优惠券",notes = "用户已领取优惠券") |
||||||
|
public ApiResult<List<YxStoreCouponUserQueryVo>> getUserList(){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
List<YxStoreCouponUserQueryVo> list = storeCouponUserService.getUserCoupon(uid); |
||||||
|
return ApiResult.ok(list); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户已领取优惠券pc |
||||||
|
*/ |
||||||
|
@AppLog(value = "用户已领取优惠券pc", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/coupons/user/pc/{type}") |
||||||
|
@ApiOperation(value = "用户已领取优惠券pc",notes = "用户已领取优惠券pc") |
||||||
|
public ApiResult<Object> getUserPCList( |
||||||
|
@RequestParam(value = "page", defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit", defaultValue = "10") int limit, @PathVariable(value = "type") Integer type){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
Map<String, Object> map = storeCouponUserService.getUserPCCoupon(uid,page,limit,type); |
||||||
|
Long total = (Long) map.get("total"); |
||||||
|
Long totalPage = (Long) map.get("totalPage"); |
||||||
|
return ApiResult.resultPage(total.intValue(), totalPage.intValue(), map.get("list")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 优惠券 订单获取 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/coupons/order/{cartIds}") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "cartIds", value = "购物车ID,多个用,分割", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "优惠券订单获取",notes = "优惠券订单获取") |
||||||
|
public ApiResult<List<StoreCouponUserVo>> orderCoupon(@PathVariable String cartIds){ |
||||||
|
Long uid = LocalUser.getUser().getUid(); |
||||||
|
return ApiResult.ok(storeCouponUserService.beUsableCouponList(uid,cartIds)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,16 @@ |
|||||||
|
package co.yixiang.app.modules.manage.dto; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName ChartDataDto |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/25 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class ChartDataDto implements Serializable { |
||||||
|
private Double num; |
||||||
|
private String time; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package co.yixiang.app.modules.manage.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName OrderPriceParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/26 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class OrderPriceParam implements Serializable { |
||||||
|
|
||||||
|
@NotBlank(message = "订单编号错误") |
||||||
|
@ApiModelProperty(value = "订单ID") |
||||||
|
private String orderId; |
||||||
|
|
||||||
|
@NotBlank(message = "修改价格必填") |
||||||
|
@ApiModelProperty(value = "商品价格") |
||||||
|
private String price; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package co.yixiang.app.modules.manage.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName OrderPriceParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/26 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class OrderRemarkParam implements Serializable { |
||||||
|
|
||||||
|
@NotBlank(message = "订单编号错误") |
||||||
|
@ApiModelProperty(value = "订单ID") |
||||||
|
private String orderId; |
||||||
|
|
||||||
|
@NotBlank(message = "备注必填") |
||||||
|
@ApiModelProperty(value = "备注") |
||||||
|
private String remark; |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package co.yixiang.app.modules.manage.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-02-27 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="商户查询参数", description="商户查询参数") |
||||||
|
public class ShoperQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品状态,默认为0未支付 1待发货 2待收货 3待评价 4已完成 5退款中 6已退款 7退款") |
||||||
|
private Integer status = 0; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "分类") |
||||||
|
private Integer cate = 1; |
||||||
|
|
||||||
|
private Integer type = 1; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.manage.param; |
||||||
|
|
||||||
|
import co.yixiang.common.web.param.QueryParam; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 快递公司表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-13 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@ApiModel(value="YxExpressQueryParam对象", description="快递公司表查询参数") |
||||||
|
public class YxExpressQueryParam extends QueryParam { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
@ -0,0 +1,189 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2018-2022 |
||||||
|
* All rights reserved, Designed By www.yixiang.co |
||||||
|
* 注意: |
||||||
|
* 本软件为www.yixiang.co开发研制,未经购买不得使用 |
||||||
|
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) |
||||||
|
* 一经发现盗用、分享等行为,将追究法律责任,后果自负 |
||||||
|
*/ |
||||||
|
package co.yixiang.app.modules.manage.rest; |
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import co.yixiang.api.ApiResult; |
||||||
|
import co.yixiang.api.YshopException; |
||||||
|
import co.yixiang.app.modules.order.param.OrderDeliveryParam; |
||||||
|
import co.yixiang.app.modules.order.param.OrderRefundParam; |
||||||
|
import co.yixiang.logging.aop.log.AppLog; |
||||||
|
import co.yixiang.app.common.interceptor.AuthCheck; |
||||||
|
import co.yixiang.app.modules.manage.param.OrderPriceParam; |
||||||
|
import co.yixiang.app.modules.manage.param.ShoperQueryParam; |
||||||
|
import co.yixiang.modules.order.service.YxExpressService; |
||||||
|
import co.yixiang.modules.order.service.YxStoreOrderService; |
||||||
|
import co.yixiang.modules.order.vo.OrderDataVo; |
||||||
|
import co.yixiang.modules.order.vo.ShoperOrderTimeDataVo; |
||||||
|
import co.yixiang.modules.order.vo.UserOrderCountVo; |
||||||
|
import co.yixiang.modules.order.vo.YxStoreOrderQueryVo; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.validation.annotation.Validated; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.LinkedHashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName ShoperController |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/25 |
||||||
|
**/ |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) |
||||||
|
@Api(value = "商家管理", tags = "商城:商家管理") |
||||||
|
public class ShoperController { |
||||||
|
|
||||||
|
private final YxStoreOrderService storeOrderService; |
||||||
|
private final YxExpressService expressService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单数据统计 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/admin/order/statistics") |
||||||
|
@ApiOperation(value = "订单数据统计",notes = "订单数据统计") |
||||||
|
public ApiResult<Map<String,Object>> statistics(){ |
||||||
|
UserOrderCountVo userOrderCountVo = storeOrderService.orderData(null); |
||||||
|
ShoperOrderTimeDataVo orderTimeDataVo = storeOrderService.getShoperOrderTimeData(); |
||||||
|
|
||||||
|
Map<String,Object> map = new LinkedHashMap<>(); |
||||||
|
map.put("orderCount",userOrderCountVo); |
||||||
|
map.put("orderTimeCount",orderTimeDataVo); |
||||||
|
return ApiResult.ok(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单每月统计数据 |
||||||
|
*/ |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/admin/order/data") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "page", value = "页码,默认为1", paramType = "query", dataType = "int"), |
||||||
|
@ApiImplicitParam(name = "limit", value = "页大小,默认为10", paramType = "query", dataType = "int") |
||||||
|
}) |
||||||
|
@ApiOperation(value = "订单每月统计数据",notes = "订单每月统计数据") |
||||||
|
public ApiResult<List<OrderDataVo>> data(@RequestParam(value = "page",defaultValue = "1") int page, |
||||||
|
@RequestParam(value = "limit",defaultValue = "10") int limit){ |
||||||
|
return ApiResult.ok(storeOrderService.getOrderDataPriceCount(page,limit)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 订单列表 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看订单列表", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/admin/order/list") |
||||||
|
@ApiOperation(value = "订单列表",notes = "订单列表") |
||||||
|
public ApiResult<Object> orderList(ShoperQueryParam queryParam) { |
||||||
|
Map<String, Object> map = storeOrderService.orderList(null, queryParam.getStatus(), |
||||||
|
queryParam.getPage(), queryParam.getLimit()); |
||||||
|
return ApiResult.ok(map.get("list")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单详情 |
||||||
|
*/ |
||||||
|
@AppLog(value = "查看订单详情", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@GetMapping("/admin/order/detail/{key}") |
||||||
|
@ApiOperation(value = "订单详情",notes = "订单详情") |
||||||
|
public ApiResult<YxStoreOrderQueryVo> orderDetail(@PathVariable String key){ |
||||||
|
if(StrUtil.isEmpty(key)) { |
||||||
|
throw new YshopException("参数错误"); |
||||||
|
} |
||||||
|
YxStoreOrderQueryVo storeOrder = storeOrderService.getOrderInfo(key,null); |
||||||
|
if(ObjectUtil.isNull(storeOrder)){ |
||||||
|
throw new YshopException("订单不存在"); |
||||||
|
} |
||||||
|
return ApiResult.ok(storeOrderService.handleOrder(storeOrder)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单改价 |
||||||
|
*/ |
||||||
|
@AppLog(value = "订单改价", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/admin/order/price") |
||||||
|
@ApiOperation(value = "订单改价",notes = "订单改价") |
||||||
|
public ApiResult<Boolean> orderPrice(@Validated @RequestBody OrderPriceParam param){ |
||||||
|
storeOrderService.editOrderPrice(param.getOrderId(),param.getPrice()); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 快递公司 |
||||||
|
*/ |
||||||
|
@GetMapping("/logistics") |
||||||
|
@ApiOperation(value = "快递公司",notes = "快递公司") |
||||||
|
public ApiResult<Object> express(){ |
||||||
|
return ApiResult.ok(expressService.list()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 订单发货 |
||||||
|
*/ |
||||||
|
@AppLog(value = "订单发货", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/admin/order/delivery/keep") |
||||||
|
@ApiOperation(value = "订单发货",notes = "订单发货") |
||||||
|
public ApiResult<Boolean> orderDelivery(@Validated @RequestBody OrderDeliveryParam param){ |
||||||
|
storeOrderService.orderDelivery(param.getOrderId(),param.getDeliveryId(), |
||||||
|
param.getDeliveryName(),param.getDeliveryType()); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单退款 |
||||||
|
*/ |
||||||
|
@AppLog(value = "订单退款", type = 1) |
||||||
|
@AuthCheck |
||||||
|
@PostMapping("/admin/order/refund") |
||||||
|
@ApiOperation(value = "订单退款",notes = "订单退款") |
||||||
|
public ApiResult<Boolean> orderRefund(@Validated @RequestBody OrderRefundParam param){ |
||||||
|
storeOrderService.orderRefund(param.getOrderId(),new BigDecimal(param.getPrice()),param.getType()); |
||||||
|
return ApiResult.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 订单交易额/订单数量时间chart统计 |
||||||
|
*/ |
||||||
|
@Deprecated |
||||||
|
@GetMapping("/admin/order/time") |
||||||
|
@ApiOperation(value = "chart统计",notes = "chart统计") |
||||||
|
public ApiResult<Object> chartCount(ShoperQueryParam queryParam){ |
||||||
|
// return ApiResult.ok(storeOrderService.chartCount(queryParam.getCate().intValue(),
|
||||||
|
// queryParam.getType().intValue()));
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
package co.yixiang.app.modules.manage.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 快递公司表 查询结果对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @date 2019-12-13 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ApiModel(value="YxExpressQueryVo对象", description="快递公司表查询参数") |
||||||
|
public class YxExpressQueryVo implements Serializable{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "快递公司id") |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "快递公司简称") |
||||||
|
private String code; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "快递公司全称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "排序") |
||||||
|
private Integer sort; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否显示") |
||||||
|
private Boolean isShow; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package co.yixiang.app.modules.order.dto; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Builder; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName OrderExtendDto |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/10/28 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
public class OrderExtendDto implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "唯一的key") |
||||||
|
private String key; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "订单ID") |
||||||
|
private String orderId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "微信相关配置") |
||||||
|
private Map<String,String> jsConfig; |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package co.yixiang.app.modules.order.dto; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName PayDto |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/11/7 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class PayDto implements Serializable { |
||||||
|
private String from; |
||||||
|
private String paytype; |
||||||
|
private String uni; |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package co.yixiang.app.modules.order.param; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
import lombok.ToString; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName ComputeOrderParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/22 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@ToString |
||||||
|
public class ComputeOrderParam { |
||||||
|
//@NotBlank(message = "请选择地址")
|
||||||
|
@ApiModelProperty(value = "地址ID") |
||||||
|
private String addressId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "优惠券ID") |
||||||
|
private String couponId; |
||||||
|
|
||||||
|
//@NotBlank(message = "请选择支付方式")
|
||||||
|
@ApiModelProperty(value = "支付方式") |
||||||
|
private String payType; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "使用积分 1-表示使用") |
||||||
|
private String useIntegral; |
||||||
|
|
||||||
|
@JsonProperty(value = "shipping_type") |
||||||
|
@ApiModelProperty(value = "配送方式 1=快递 ,2=门店自提") |
||||||
|
private String shippingType; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "砍价ID") |
||||||
|
private String bargainId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "拼团ID") |
||||||
|
private String pinkId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "拼团ID") |
||||||
|
private String combinationId; |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package co.yixiang.app.modules.order.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName 确认订单ConfirmOrderDTO |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/21 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class ConfirmOrderParam { |
||||||
|
|
||||||
|
@NotBlank(message = "请提交购买的商品") |
||||||
|
@ApiModelProperty(value = "购物车ID") |
||||||
|
private String cartId; |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package co.yixiang.app.modules.order.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName HandleOrderParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2020/6/23 |
||||||
|
**/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
public class DoOrderParam { |
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "订单ID") |
||||||
|
private String uni; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package co.yixiang.app.modules.order.param; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName ExpressParam |
||||||
|
* @Author hupeng <610796224@qq.com> |
||||||
|
* @Date 2019/12/9 |
||||||
|
**/ |
||||||
|
@Data |
||||||
|
public class ExpressParam implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "订单编号") |
||||||
|
private String orderCode; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "快递公司编码") |
||||||
|
private String shipperCode; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "物流单号") |
||||||
|
private String logisticCode; |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue