Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
560aea49
提交
560aea49
authored
9月 20, 2019
作者:
zhengfg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1、去除session和cookie后,加入spring security使用token登录
2、实现第三方接口业务流程
上级
b9458b12
隐藏空白字符变更
内嵌
并排
正在显示
46 个修改的文件
包含
1128 行增加
和
435 行删除
+1128
-435
pom.xml
pom.xml
+28
-3
ThirdPartyController.java
...com/diaoyun/zion/chinafrica/api/ThirdPartyController.java
+38
-43
TokenVerification.java
...com/diaoyun/zion/chinafrica/client/TokenVerification.java
+5
-3
KeyConstant.java
...ava/com/diaoyun/zion/chinafrica/constant/KeyConstant.java
+3
-0
LoginController.java
...m/diaoyun/zion/chinafrica/controller/LoginController.java
+10
-75
LogoutController.java
.../diaoyun/zion/chinafrica/controller/LogoutController.java
+1
-9
TbCfContactController.java
...yun/zion/chinafrica/controller/TbCfContactController.java
+1
-1
TbCfItemDetailController.java
.../zion/chinafrica/controller/TbCfItemDetailController.java
+3
-1
TbCfOrderController.java
...aoyun/zion/chinafrica/controller/TbCfOrderController.java
+4
-5
TbCfPlatformController.java
...un/zion/chinafrica/controller/TbCfPlatformController.java
+1
-1
TbCfProblemController.java
...yun/zion/chinafrica/controller/TbCfProblemController.java
+1
-1
TbCfStationItemController.java
...zion/chinafrica/controller/TbCfStationItemController.java
+1
-1
TbCfUserInfoController.java
...un/zion/chinafrica/controller/TbCfUserInfoController.java
+8
-5
TbCfOrderDao.java
...in/java/com/diaoyun/zion/chinafrica/dao/TbCfOrderDao.java
+18
-0
TbCfFinanceEntity.java
...com/diaoyun/zion/chinafrica/entity/TbCfFinanceEntity.java
+12
-0
TbCfItemShippedEntity.java
...diaoyun/zion/chinafrica/entity/TbCfItemShippedEntity.java
+85
-0
TbCfItemDetailService.java
...iaoyun/zion/chinafrica/service/TbCfItemDetailService.java
+3
-1
TbCfOrderService.java
...com/diaoyun/zion/chinafrica/service/TbCfOrderService.java
+28
-1
TbCfUserInfoService.java
.../diaoyun/zion/chinafrica/service/TbCfUserInfoService.java
+7
-0
TbCfAddressServiceImpl.java
.../zion/chinafrica/service/impl/TbCfAddressServiceImpl.java
+7
-5
TbCfCouponServiceImpl.java
...n/zion/chinafrica/service/impl/TbCfCouponServiceImpl.java
+5
-2
TbCfFeedbackServiceImpl.java
...zion/chinafrica/service/impl/TbCfFeedbackServiceImpl.java
+4
-2
TbCfItemDetailServiceImpl.java
...on/chinafrica/service/impl/TbCfItemDetailServiceImpl.java
+75
-7
TbCfOrderServiceImpl.java
...un/zion/chinafrica/service/impl/TbCfOrderServiceImpl.java
+94
-69
TbCfUserInfoServiceImpl.java
...zion/chinafrica/service/impl/TbCfUserInfoServiceImpl.java
+82
-101
TbCfUserInfoVo.java
...n/java/com/diaoyun/zion/chinafrica/vo/TbCfUserInfoVo.java
+13
-0
SwaggerConfig.java
...in/java/com/diaoyun/zion/master/config/SwaggerConfig.java
+21
-6
ExceptionResolver.java
.../com/diaoyun/zion/master/exception/ExceptionResolver.java
+2
-1
GlobalExceptionHandlerController.java
...on/master/exception/GlobalExceptionHandlerController.java
+101
-0
JwtTokenFilter.java
...java/com/diaoyun/zion/master/security/JwtTokenFilter.java
+42
-0
JwtTokenFilterConfigurer.java
...iaoyun/zion/master/security/JwtTokenFilterConfigurer.java
+22
-0
JwtTokenProvider.java
...va/com/diaoyun/zion/master/security/JwtTokenProvider.java
+94
-0
MyUserDetails.java
.../java/com/diaoyun/zion/master/security/MyUserDetails.java
+36
-0
WebSecurityConfig.java
...a/com/diaoyun/zion/master/security/WebSecurityConfig.java
+89
-0
CookieUtils.java
src/main/java/com/diaoyun/zion/master/util/CookieUtils.java
+0
-63
GsonUtil.java
src/main/java/com/diaoyun/zion/master/util/GsonUtil.java
+103
-0
HttpClientUtil.java
...ain/java/com/diaoyun/zion/master/util/HttpClientUtil.java
+9
-6
PasswordProvider.java
...n/java/com/diaoyun/zion/master/util/PasswordProvider.java
+1
-0
application.properties
src/main/resources/application.properties
+0
-1
application.yml
src/main/resources/application.yml
+7
-1
TbCfFinanceDao.xml
src/main/resources/mapper/TbCfFinanceDao.xml
+10
-4
TbCfOrderDao.xml
src/main/resources/mapper/TbCfOrderDao.xml
+14
-0
TbCfUserInfoDao.xml
src/main/resources/mapper/TbCfUserInfoDao.xml
+3
-2
domain.properties
src/main/resources/properties/domain.properties
+12
-3
LoginController.js
...resources/static/js/angularjs/js/login/LoginController.js
+5
-5
ZionApplicationTests.java
src/test/java/com/diaoyun/zion/ZionApplicationTests.java
+20
-7
没有找到文件。
pom.xml
浏览文件 @
560aea49
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
</parent>
</parent>
<groupId>
com.diaoyun
</groupId>
<groupId>
com.diaoyun
</groupId>
<artifactId>
zion
</artifactId>
<artifactId>
zion
</artifactId>
<version>
0.1.1-SNAPSHOT
</version>
<version>
2.0.0
</version>
<name>
zion
</name>
<name>
zion
</name>
<description>
逐渐把项目完善
</description>
<description>
逐渐把项目完善
</description>
<packaging>
war
</packaging>
<packaging>
war
</packaging>
...
@@ -39,10 +39,35 @@
...
@@ -39,10 +39,35 @@
</exclusions>-->
</exclusions>-->
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
<!--
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>-->
</dependency>
<dependency>
<!-- Make method based security testing easier -->
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<!-- Automatically restart whenever files on the classpath change -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-autoconfigure
</artifactId>
</dependency>
<dependency>
<!-- JSON Web Token Support -->
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
0.9.0
</version>
</dependency>
<!--aop-->
<!--aop-->
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
...
src/main/java/com/diaoyun/zion/chinafrica/api/ThirdPartyController.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
chinafrica
.
api
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
api
;
import
com.alibaba.druid.support.json.JSONUtils
;
import
com.alibaba.druid.support.json.JSONUtils
;
import
com.diaoyun.zion.chinafrica.service.TbCfOrderService
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.util.JodaDateUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -23,19 +29,26 @@ import java.util.Map;
...
@@ -23,19 +29,26 @@ import java.util.Map;
public
class
ThirdPartyController
{
public
class
ThirdPartyController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ThirdPartyController
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ThirdPartyController
.
class
);
@Autowired
private
TbCfOrderService
tbCfOrderService
;
/**
/**
*获取某段时间的
下
单数据
*获取某段时间的
付款订
单数据
*/
*/
@ApiOperation
(
value
=
"获取某段时间的
下
单数据"
)
@ApiOperation
(
value
=
"获取某段时间的
付款订
单数据"
)
@GetMapping
(
value
=
"/order"
)
@GetMapping
(
value
=
"/order"
)
public
String
getOrderList
(
@RequestParam
(
"beginTime"
)
String
beginTime
,
@RequestParam
(
"endTime"
)
String
endTime
)
{
public
Result
getOrderList
(
@ApiParam
(
value
=
"开始时间"
)
@RequestParam
(
"beginTime"
)
long
beginTime
,
List
<
Map
<
String
,
Object
>>
returnList
=
new
ArrayList
<>();
@ApiParam
(
value
=
"结束时间"
)
@RequestParam
(
"endTime"
)
long
endTime
,
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
@ApiParam
(
value
=
"页数"
)
@RequestParam
(
required
=
false
)
Integer
pageNum
,
map
.
put
(
"orderId"
,
"orderId8848"
);
@ApiParam
(
value
=
"每页大小 默认100"
)
@RequestParam
(
required
=
false
)
Integer
pageSize
)
{
map
.
put
(
"userId"
,
"userId2019"
);
if
(
pageNum
==
null
)
{
map
.
put
(
"dealTime"
,
"订单成交时间时间戳1564558584"
);
pageNum
=
1
;
returnList
.
add
(
map
);
}
return
JSONUtils
.
toJSONString
(
returnList
);
if
(
pageSize
==
null
)
{
pageSize
=
100
;
}
return
tbCfOrderService
.
getOrderListByTime
(
beginTime
,
endTime
,
pageNum
,
pageSize
);
}
}
/**
/**
...
@@ -43,44 +56,26 @@ public class ThirdPartyController {
...
@@ -43,44 +56,26 @@ public class ThirdPartyController {
*/
*/
@ApiOperation
(
value
=
"获取某段时间已发货订单数据"
)
@ApiOperation
(
value
=
"获取某段时间已发货订单数据"
)
@GetMapping
(
value
=
"/delivery"
)
@GetMapping
(
value
=
"/delivery"
)
public
String
getDeliveryList
(
@RequestParam
(
"beginTime"
)
String
beginTime
,
@RequestParam
(
"endTime"
)
String
endTime
)
{
public
Result
getDeliveryList
(
@ApiParam
(
value
=
"开始时间"
)
@RequestParam
(
"beginTime"
)
long
beginTime
,
List
<
Map
<
String
,
Object
>>
returnList
=
new
ArrayList
<>();
@ApiParam
(
value
=
"结束时间"
)
@RequestParam
(
"endTime"
)
long
endTime
,
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
@ApiParam
(
value
=
"页数"
)
@RequestParam
(
required
=
false
)
Integer
pageNum
,
map
.
put
(
"orderId"
,
"orderId8848"
);
@ApiParam
(
value
=
"每页大小 默认100"
)
@RequestParam
(
required
=
false
)
Integer
pageSize
)
{
map
.
put
(
"userId"
,
"userId2019"
);
if
(
pageNum
==
null
)
{
map
.
put
(
"deliveryAddress"
,
"收货人地址"
);
pageNum
=
1
;
map
.
put
(
"deliveryTime"
,
"发货时间戳1564558584"
);
}
map
.
put
(
"itemType"
,
"货物类别Id"
);
if
(
pageSize
==
null
)
{
map
.
put
(
"expressId"
,
"快递单号"
);
pageSize
=
100
;
returnList
.
add
(
map
);
}
returnList
.
add
(
map
);
return
tbCfOrderService
.
getDeliveryList
(
beginTime
,
endTime
,
pageNum
,
pageSize
);
return
JSONUtils
.
toJSONString
(
returnList
);
}
}
/**
/**
*根据订单号获取详细订单数据
*
根据订单号获取详细订单数据
*/
*/
@ApiOperation
(
value
=
"
获取某段时间已发货
订单数据"
)
@ApiOperation
(
value
=
"
根据订单号获取详细
订单数据"
)
@GetMapping
(
value
=
"/order/detail/{orderId}"
)
@GetMapping
(
value
=
"/order/detail/{orderId}"
)
public
String
getOrderDetailById
(
@PathVariable
(
"orderId"
)
String
orderId
)
{
public
Result
getOrderDetail
(
@PathVariable
(
"orderId"
)
String
orderId
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
return
tbCfOrderService
.
getOrderDetail
(
orderId
);
map
.
put
(
"orderId"
,
"订单Id8848"
);
map
.
put
(
"deliveryName"
,
"收货人"
);
map
.
put
(
"deliveryPhone"
,
"收货人手机"
);
map
.
put
(
"deliveryAddress"
,
"收货人地址"
);
List
<
Map
<
String
,
Object
>>
itemList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
itemMap
=
new
HashMap
<>();
itemMap
.
put
(
"itemCategory"
,
"品名"
);
itemMap
.
put
(
"itemPrice"
,
"单价"
);
itemMap
.
put
(
"itemNum"
,
"数量"
);
Map
<
String
,
Object
>
itemMap2
=
new
HashMap
<>();
itemMap2
.
put
(
"itemCategory"
,
"品名2"
);
itemMap2
.
put
(
"itemPrice"
,
"单价2"
);
itemMap2
.
put
(
"itemNum"
,
"数量2"
);
itemList
.
add
(
itemMap
);
itemList
.
add
(
itemMap2
);
map
.
put
(
"itemList"
,
itemList
);
return
JSONUtils
.
toJSONString
(
map
);
}
}
...
...
src/main/java/com/diaoyun/zion/chinafrica/client/TokenVerification.java
浏览文件 @
560aea49
...
@@ -3,8 +3,7 @@ package com.diaoyun.zion.chinafrica.client;
...
@@ -3,8 +3,7 @@ package com.diaoyun.zion.chinafrica.client;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.exception.ValidateException
;
import
com.diaoyun.zion.master.security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.CookieUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
...
@@ -27,6 +26,8 @@ public class TokenVerification {
...
@@ -27,6 +26,8 @@ public class TokenVerification {
private
HttpServletRequest
request
;
private
HttpServletRequest
request
;
@Resource
(
name
=
"redisTokenManager"
)
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
//验证是否登录
//验证是否登录
//@Pointcut("!execution(* com.diaoyun.zion.chinafrica.controller.LoginController*.*(..))&&within(com.diaoyun.zion.chinafrica.controller.*)")
//@Pointcut("!execution(* com.diaoyun.zion.chinafrica.controller.LoginController*.*(..))&&within(com.diaoyun.zion.chinafrica.controller.*)")
...
@@ -46,7 +47,8 @@ public class TokenVerification {
...
@@ -46,7 +47,8 @@ public class TokenVerification {
@Around
(
"controllerAspect()"
)
@Around
(
"controllerAspect()"
)
public
Object
validateLogin
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
public
Object
validateLogin
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
Result
result
;
Result
result
;
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
//获取用户
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
//不需要登录
//不需要登录
if
(
StringUtils
.
isNotBlank
(
token
)
&&
tokenManager
.
validate
(
token
)
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
token
)
&&
tokenManager
.
validate
(
token
)
!=
null
)
{
return
pjp
.
proceed
();
return
pjp
.
proceed
();
...
...
src/main/java/com/diaoyun/zion/chinafrica/constant/KeyConstant.java
浏览文件 @
560aea49
...
@@ -21,4 +21,7 @@ public class KeyConstant {
...
@@ -21,4 +21,7 @@ public class KeyConstant {
public
final
static
String
ORDER_EXP
=
"order_exp"
;
public
final
static
String
ORDER_EXP
=
"order_exp"
;
//订单详情前缀
//订单详情前缀
public
final
static
String
ORDER_DET
=
"order_det"
;
public
final
static
String
ORDER_DET
=
"order_det"
;
/////////////////订单 END////////////////
//验证码前缀
public
final
static
String
CAPTCHA
=
"captcha_"
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/controller/LoginController.java
浏览文件 @
560aea49
...
@@ -28,104 +28,39 @@ import java.io.UnsupportedEncodingException;
...
@@ -28,104 +28,39 @@ import java.io.UnsupportedEncodingException;
public
class
LoginController
extends
BaseController
{
public
class
LoginController
extends
BaseController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
LoginController
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
LoginController
.
class
);
// 登录页 TODO 改为配置
private
static
final
String
LOGIN_PATH
=
"page/login.html"
;
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
@Autowired
@Autowired
private
HttpServletRequest
request
;
//自动注入request
private
HttpServletRequest
request
;
//自动注入request
@Autowired
private
HttpServletResponse
response
;
@Autowired
@Autowired
private
TbCfUserInfoService
tbCfUserInfoService
;
private
TbCfUserInfoService
tbCfUserInfoService
;
@ApiOperation
(
value
=
"注册并登录"
)
@ApiOperation
(
value
=
"注册并登录"
)
@PostMapping
(
value
=
"/register"
)
@PostMapping
(
value
=
"/register"
)
public
Result
<
TbCfUserInfoVo
>
registerAndLogin
(
@ApiParam
(
"用户信息"
)
@RequestBody
TbCfUserInfoVo
tbCfUserInfoVo
)
{
public
Result
<
TbCfUserInfoVo
>
registerAndLogin
(
@ApiParam
(
"用户信息"
)
@RequestBody
TbCfUserInfoVo
tbCfUserInfoVo
)
{
Result
result
=
tbCfUserInfoService
.
registerAndLogin
(
tbCfUserInfoVo
);
return
tbCfUserInfoService
.
registerAndLogin
(
tbCfUserInfoVo
);
return
result
;
}
}
/*@ApiOperation("登录页")
@RequestMapping(method = RequestMethod.GET)
public void login(
@ApiParam(value = "返回链接", required = true) @ValidateParam({ Validator.NOT_BLANK }) String backUrl,
HttpServletRequest request) throws IOException {
String token = CookieUtils.getCookie(request, TokenManager.TOKEN);
if (StringUtils.isNotBlank(token) && tokenManager.validate(token) != null) {
response.sendRedirect(authBackUrl(backUrl, token));
//return "redirect:" + authBackUrl(backUrl, token);
}
else {
response.sendRedirect(goLoginPath(backUrl, request));
//return goLoginPath(backUrl, request);
}
}
*/
@ApiOperation
(
"登录"
)
@ApiOperation
(
"登录"
)
@PostMapping
@PostMapping
public
Result
<
TbCfUserInfoVo
>
login
(
@ApiParam
(
value
=
"登录名"
)
@RequestParam
(
required
=
false
)
String
account
,
public
Result
<
TbCfUserInfoVo
>
login
(
@ApiParam
(
value
=
"登录名"
)
String
account
,
@ApiParam
(
value
=
"密码"
)
@RequestParam
(
required
=
false
)
String
password
)
{
@ApiParam
(
value
=
"密码"
)
String
password
)
{
Result
result
=
tbCfUserInfoService
.
login
(
getIpAddr
(
request
),
account
,
password
);
return
tbCfUserInfoService
.
login
(
getIpAddr
(
request
),
account
,
password
);
return
result
;
}
}
@ApiOperation
(
"使用token登录"
)
@GetMapping
(
"/token"
)
public
Result
<
TbCfUserInfoVo
>
loginByToken
()
{
return
tbCfUserInfoService
.
loginByToken
(
getIpAddr
(
request
));
}
/*@ApiOperation(value = "登录")
@GetMapping("/form")
public Result login(@ApiParam(value = "登录名") @RequestParam(required = false) String account,
@ApiParam(value = "密码") @RequestParam(required = false) String password) {
Result result;
String token = CookieUtils.getCookie(request, TokenManager.TOKEN);
if (StringUtils.isNotBlank(token)) {// 有cookies的情况
TbCfUserInfoVo tbCfUserInfoVo = tokenManager.validate(token);
if (tbCfUserInfoVo == null) {
CookieUtils.removeCookie(response, TokenManager.TOKEN, "/", null);
result = new Result().setCode(ResultCode.ERROR).setMessage("请重新登录");
} else {
result = tbCfUserInfoService.login(getIpAddr(request), tbCfUserInfoVo.getAccount(), tbCfUserInfoVo.getPassword());
SessionUtils.setSessionUser(request, new SessionUser(token, tbCfUserInfoVo.getAccount()));
}
} else {
Validator.NOT_BLANK.validate("登录名", account);
Validator.NOT_BLANK.validate("密码", password);
result = tbCfUserInfoService.login(getIpAddr(request), account, PasswordProvider.encrypt(password));
}
return result;
}
*/
@ApiOperation
(
"第三方登录"
)
@ApiOperation
(
"第三方登录"
)
@PostMapping
(
"/thirdParty"
)
@PostMapping
(
"/thirdParty"
)
public
Result
<
TbCfUserInfoVo
>
loginByThirdParty
(
@ApiParam
(
"第三方账号"
)
@RequestParam
(
required
=
false
)
String
amount
,
public
Result
<
TbCfUserInfoVo
>
loginByThirdParty
(
@ApiParam
(
"第三方账号"
)
@RequestParam
(
required
=
false
)
String
amount
,
@ApiParam
(
"用户昵称 url编码"
)
@RequestParam
(
required
=
false
)
String
nick
,
@ApiParam
(
"用户昵称 url编码"
)
@RequestParam
(
required
=
false
)
String
nick
,
@ApiParam
(
"账号类型"
)
@RequestParam
(
required
=
false
)
String
userType
)
throws
UnsupportedEncodingException
{
@ApiParam
(
"账号类型"
)
@RequestParam
(
required
=
false
)
String
userType
)
throws
UnsupportedEncodingException
{
Result
result
=
tbCfUserInfoService
.
loginByThirdParty
(
getIpAddr
(
request
),
amount
,
nick
,
userType
);
return
tbCfUserInfoService
.
loginByThirdParty
(
getIpAddr
(
request
),
amount
,
nick
,
userType
);
return
result
;
}
/*private String authBackUrl(String backUrl, String token) {
StringBuilder sbf = new StringBuilder(backUrl);
if (backUrl.indexOf("?") > 0) {
sbf.append("&");
} else {
sbf.append("?");
}
sbf.append(SsoFilter.SSO_TOKEN_NAME).append("=").append(token);
return sbf.toString();
}
}
private String goLoginPath(String backUrl, HttpServletRequest request) {
request.setAttribute("backUrl", backUrl);
return LOGIN_PATH;
}*/
}
}
src/main/java/com/diaoyun/zion/chinafrica/controller/LogoutController.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
chinafrica
.
controller
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
controller
;
import
com.diaoyun.zion.chinafrica.client.SessionUtils
;
import
com.diaoyun.zion.chinafrica.service.TbCfUserInfoService
;
import
com.diaoyun.zion.chinafrica.service.TbCfUserInfoService
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.util.CookieUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
...
@@ -33,7 +26,6 @@ public class LogoutController {
...
@@ -33,7 +26,6 @@ public class LogoutController {
@ApiOperation
(
"登出"
)
@ApiOperation
(
"登出"
)
@GetMapping
@GetMapping
public
Result
logout
()
{
public
Result
logout
()
{
Result
result
=
tbCfUserInfoService
.
logout
();
return
tbCfUserInfoService
.
logout
();
return
result
;
}
}
}
}
\ No newline at end of file
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfContactController.java
浏览文件 @
560aea49
...
@@ -20,7 +20,7 @@ import java.util.Map;
...
@@ -20,7 +20,7 @@ import java.util.Map;
*/
*/
@Api
(
tags
=
"联系方式"
)
@Api
(
tags
=
"联系方式"
)
@RestController
@RestController
@RequestMapping
(
"contact"
)
@RequestMapping
(
"
/
contact"
)
public
class
TbCfContactController
{
public
class
TbCfContactController
{
@Autowired
@Autowired
private
TbCfContactService
tbCfContactService
;
private
TbCfContactService
tbCfContactService
;
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfItemDetailController.java
浏览文件 @
560aea49
...
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
/**
* 商品详情Controller
* 商品详情Controller
...
@@ -34,7 +36,7 @@ public class TbCfItemDetailController {
...
@@ -34,7 +36,7 @@ public class TbCfItemDetailController {
@ApiOperation
(
"加入到购物车"
)
@ApiOperation
(
"加入到购物车"
)
@PostMapping
(
"/cart"
)
@PostMapping
(
"/cart"
)
public
Result
addToCart
(
@ApiParam
(
"商品详情"
)
@RequestBody
TbCfItemDetailVo
tbCfItemDetailVo
)
{
public
Result
addToCart
(
@ApiParam
(
"商品详情"
)
@RequestBody
TbCfItemDetailVo
tbCfItemDetailVo
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
return
tbCfItemDetailService
.
addToCart
(
tbCfItemDetailVo
);
return
tbCfItemDetailService
.
addToCart
(
tbCfItemDetailVo
);
}
}
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfOrderController.java
浏览文件 @
560aea49
...
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeoutException;
...
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeoutException;
*/
*/
@Api
(
tags
=
"订单"
)
@Api
(
tags
=
"订单"
)
@RestController
@RestController
@RequestMapping
(
"order"
)
@RequestMapping
(
"
/
order"
)
public
class
TbCfOrderController
{
public
class
TbCfOrderController
{
@Autowired
@Autowired
private
TbCfOrderService
tbCfOrderService
;
private
TbCfOrderService
tbCfOrderService
;
...
@@ -71,13 +71,12 @@ public class TbCfOrderController {
...
@@ -71,13 +71,12 @@ public class TbCfOrderController {
}
}
@ApiOperation
(
"根据订单id,查询物流详情"
)
@ApiOperation
(
"根据订单id,查询物流详情"
)
@GetMapping
(
"/
logistic
s/{orderId}"
)
@GetMapping
(
"/
expres
s/{orderId}"
)
public
Result
queryOrder
Logistics
(
@ApiParam
(
"订单id"
)
@PathVariable
String
orderId
)
{
public
Result
queryOrder
ExpressInfo
(
@ApiParam
(
"订单id"
)
@PathVariable
String
orderId
)
throws
IOException
{
return
tbCfOrderService
.
queryOrder
Logistics
(
orderId
);
return
tbCfOrderService
.
queryOrder
ExpressInfo
(
orderId
);
}
}
/*
/*
@ApiOperation("取消订单")
@ApiOperation("取消订单")
@DeleteMapping
@DeleteMapping
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfPlatformController.java
浏览文件 @
560aea49
...
@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
*/
@Api
(
tags
=
"独立站"
)
@Api
(
tags
=
"独立站"
)
@RestController
@RestController
@RequestMapping
(
"platform"
)
@RequestMapping
(
"
/
platform"
)
public
class
TbCfPlatformController
{
public
class
TbCfPlatformController
{
@Autowired
@Autowired
private
TbCfPlatformService
tbCfPlatformService
;
private
TbCfPlatformService
tbCfPlatformService
;
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfProblemController.java
浏览文件 @
560aea49
...
@@ -22,7 +22,7 @@ import java.util.List;
...
@@ -22,7 +22,7 @@ import java.util.List;
*/
*/
@Api
(
tags
=
"常见问题"
)
@Api
(
tags
=
"常见问题"
)
@RestController
@RestController
@RequestMapping
(
"problem"
)
@RequestMapping
(
"
/
problem"
)
public
class
TbCfProblemController
{
public
class
TbCfProblemController
{
@Autowired
@Autowired
private
TbCfProblemService
tbCfProblemService
;
private
TbCfProblemService
tbCfProblemService
;
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfStationItemController.java
浏览文件 @
560aea49
...
@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
*/
@Api
(
tags
=
"商品独立站"
)
@Api
(
tags
=
"商品独立站"
)
@RestController
@RestController
@RequestMapping
(
"itemStation"
)
@RequestMapping
(
"
/
itemStation"
)
public
class
TbCfStationItemController
{
public
class
TbCfStationItemController
{
@Autowired
@Autowired
private
TbCfStationItemService
tbCfStationItemService
;
private
TbCfStationItemService
tbCfStationItemService
;
...
...
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfUserInfoController.java
浏览文件 @
560aea49
...
@@ -6,7 +6,6 @@ import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
...
@@ -6,7 +6,6 @@ import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
import
com.diaoyun.zion.master.base.BaseController
;
import
com.diaoyun.zion.master.base.BaseController
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.util.PasswordProvider
;
import
com.diaoyun.zion.master.validator.Validator
;
import
com.diaoyun.zion.master.validator.Validator
;
import
com.diaoyun.zion.master.validator.annotation.ValidateParam
;
import
com.diaoyun.zion.master.validator.annotation.ValidateParam
;
import
freemarker.template.TemplateException
;
import
freemarker.template.TemplateException
;
...
@@ -18,6 +17,7 @@ import org.apache.http.Consts;
...
@@ -18,6 +17,7 @@ import org.apache.http.Consts;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -30,7 +30,7 @@ import java.net.URLDecoder;
...
@@ -30,7 +30,7 @@ import java.net.URLDecoder;
*/
*/
@Api
(
tags
=
"用户相关"
)
@Api
(
tags
=
"用户相关"
)
@RestController
@RestController
@RequestMapping
(
"user"
)
@RequestMapping
(
"
/
user"
)
public
class
TbCfUserInfoController
extends
BaseController
{
public
class
TbCfUserInfoController
extends
BaseController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TbCfUserInfoController
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TbCfUserInfoController
.
class
);
...
@@ -40,6 +40,8 @@ public class TbCfUserInfoController extends BaseController {
...
@@ -40,6 +40,8 @@ public class TbCfUserInfoController extends BaseController {
@Autowired
@Autowired
private
TbCfUserInfoService
tbCfUserInfoService
;
private
TbCfUserInfoService
tbCfUserInfoService
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
/**
/**
* 获取邮箱验证码
* 获取邮箱验证码
...
@@ -49,8 +51,9 @@ public class TbCfUserInfoController extends BaseController {
...
@@ -49,8 +51,9 @@ public class TbCfUserInfoController extends BaseController {
public
Result
getUserIdentifyCode
(
@ApiParam
(
"用户邮箱"
)
@PathVariable
(
"email"
)
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
email
,
public
Result
getUserIdentifyCode
(
@ApiParam
(
"用户邮箱"
)
@PathVariable
(
"email"
)
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
email
,
@ApiParam
(
"用户昵称 url编码"
)
@PathVariable
(
"nick"
)
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
nick
)
throws
EmailException
,
TemplateException
,
IOException
{
@ApiParam
(
"用户昵称 url编码"
)
@PathVariable
(
"nick"
)
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
nick
)
throws
EmailException
,
TemplateException
,
IOException
{
nick
=
URLDecoder
.
decode
(
nick
,
Consts
.
UTF_8
.
name
());
nick
=
URLDecoder
.
decode
(
nick
,
Consts
.
UTF_8
.
name
());
Integer
identifyCode
=
tbCfUserInfoService
.
sendRegisterIdentifyCode
(
email
,
nick
);
tbCfUserInfoService
.
sendRegisterIdentifyCode
(
email
,
nick
);
request
.
getSession
().
setAttribute
(
KeyConstant
.
IDENTIFY_CODE
,
identifyCode
);
//request.getSession().setAttribute(KeyConstant.IDENTIFY_CODE, identifyCode);
// TODO 不能返回验证码,先做测试 identifyCode.toString(),
// TODO 不能返回验证码,先做测试 identifyCode.toString(),
return
new
Result
(
"Verification code has been sent"
);
return
new
Result
(
"Verification code has been sent"
);
}
}
...
@@ -77,7 +80,7 @@ public class TbCfUserInfoController extends BaseController {
...
@@ -77,7 +80,7 @@ public class TbCfUserInfoController extends BaseController {
@PutMapping
(
value
=
"/password/{newPassword}/{oldPassword}"
)
@PutMapping
(
value
=
"/password/{newPassword}/{oldPassword}"
)
public
Result
updatePassWord
(
@ApiParam
(
"新密码"
)
@PathVariable
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
newPassword
public
Result
updatePassWord
(
@ApiParam
(
"新密码"
)
@PathVariable
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
newPassword
,
@ApiParam
(
"旧密码"
)
@PathVariable
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
oldPassword
)
{
,
@ApiParam
(
"旧密码"
)
@PathVariable
@ValidateParam
({
Validator
.
NOT_BLANK
})
String
oldPassword
)
{
return
tbCfUserInfoService
.
updatePassWord
(
PasswordProvider
.
encrypt
(
newPassword
),
PasswordProvider
.
encrypt
(
oldPassword
));
return
tbCfUserInfoService
.
updatePassWord
(
passwordEncoder
.
encode
(
newPassword
),
passwordEncoder
.
encode
(
oldPassword
));
}
}
...
...
src/main/java/com/diaoyun/zion/chinafrica/dao/TbCfOrderDao.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
chinafrica
.
dao
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
dao
;
import
com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfItemShippedEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity
;
import
com.diaoyun.zion.master.dao.BaseDao
;
import
com.diaoyun.zion.master.dao.BaseDao
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -27,4 +29,20 @@ public interface TbCfOrderDao extends BaseDao<TbCfOrderEntity> {
...
@@ -27,4 +29,20 @@ public interface TbCfOrderDao extends BaseDao<TbCfOrderEntity> {
* @return
* @return
*/
*/
List
<
TbCfItemDetailEntity
>
getOrderItemList
(
String
orderId
);
List
<
TbCfItemDetailEntity
>
getOrderItemList
(
String
orderId
);
/**
* 获取付款订单
* @param beginDate
* @param endDate
* @return
*/
List
<
TbCfOrderEntity
>
getOrderListByTime
(
Date
beginDate
,
Date
endDate
);
/**
* 获取某段时间已发货订单数据
* @param beginDate
* @param endDate
* @return
*/
List
<
TbCfItemShippedEntity
>
getDeliveryList
(
Date
beginDate
,
Date
endDate
);
}
}
src/main/java/com/diaoyun/zion/chinafrica/entity/TbCfFinanceEntity.java
浏览文件 @
560aea49
...
@@ -42,6 +42,10 @@ public class TbCfFinanceEntity implements Serializable {
...
@@ -42,6 +42,10 @@ public class TbCfFinanceEntity implements Serializable {
* 支付时间
* 支付时间
*/
*/
private
Date
payTime
;
private
Date
payTime
;
/**
* 支付结果页面
*/
private
String
receiptUrl
;
/**
/**
* 设置:财务报表id
* 设置:财务报表id
...
@@ -134,4 +138,12 @@ public class TbCfFinanceEntity implements Serializable {
...
@@ -134,4 +138,12 @@ public class TbCfFinanceEntity implements Serializable {
public
Date
getPayTime
()
{
public
Date
getPayTime
()
{
return
payTime
;
return
payTime
;
}
}
public
String
getReceiptUrl
()
{
return
receiptUrl
;
}
public
void
setReceiptUrl
(
String
receiptUrl
)
{
this
.
receiptUrl
=
receiptUrl
;
}
}
}
src/main/java/com/diaoyun/zion/chinafrica/entity/TbCfItemShippedEntity.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
chinafrica
.
entity
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
import
java.util.Date
;
/**
* 已发货订单
*
* @author G
* @date 2019-08-14 09:11:48
*/
public
class
TbCfItemShippedEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 订单id
*/
private
String
orderId
;
/**
* 发货时间
*/
private
Date
deliveryTime
;
/**
* 收货地址
*/
private
String
deliveryAddress
;
/**
* 用户id
*/
private
String
userId
;
/**
* 快递单号
*/
private
String
expressId
;
/**
* 设置:订单id
*/
public
void
setOrderId
(
String
orderId
)
{
this
.
orderId
=
orderId
;
}
/**
* 获取:订单id
*/
public
String
getOrderId
()
{
return
orderId
;
}
public
Date
getDeliveryTime
()
{
return
deliveryTime
;
}
public
void
setDeliveryTime
(
Date
deliveryTime
)
{
this
.
deliveryTime
=
deliveryTime
;
}
public
String
getDeliveryAddress
()
{
return
deliveryAddress
;
}
public
void
setDeliveryAddress
(
String
deliveryAddress
)
{
this
.
deliveryAddress
=
deliveryAddress
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getExpressId
()
{
return
expressId
;
}
public
void
setExpressId
(
String
expressId
)
{
this
.
expressId
=
expressId
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/TbCfItemDetailService.java
浏览文件 @
560aea49
...
@@ -8,6 +8,8 @@ import com.diaoyun.zion.master.base.Result;
...
@@ -8,6 +8,8 @@ import com.diaoyun.zion.master.base.Result;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeoutException
;
/**
/**
* 商品详情Service接口
* 商品详情Service接口
...
@@ -78,7 +80,7 @@ public interface TbCfItemDetailService {
...
@@ -78,7 +80,7 @@ public interface TbCfItemDetailService {
* @param tbCfItemDetailVo
* @param tbCfItemDetailVo
* @return
* @return
*/
*/
Result
addToCart
(
TbCfItemDetailVo
tbCfItemDetailVo
);
Result
addToCart
(
TbCfItemDetailVo
tbCfItemDetailVo
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
;
/**
/**
* 更改购物车商品数量
* 更改购物车商品数量
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/TbCfOrderService.java
浏览文件 @
560aea49
...
@@ -127,5 +127,32 @@ public interface TbCfOrderService {
...
@@ -127,5 +127,32 @@ public interface TbCfOrderService {
* @param orderId
* @param orderId
* @return
* @return
*/
*/
Result
queryOrderLogistics
(
String
orderId
);
Result
queryOrderExpressInfo
(
String
orderId
)
throws
IOException
;
/**
* 获取某段时间内的付款订单
* @param beginTime
* @param endTime
* @param pageNum
* @param pageSize
* @return
*/
Result
getOrderListByTime
(
long
beginTime
,
long
endTime
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 获取某段时间已发货订单数据
* @param beginTime
* @param endTime
* @param pageNum
* @param pageSize
* @return
*/
Result
getDeliveryList
(
long
beginTime
,
long
endTime
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 根据订单号获取详细订单数据
* @param orderId
* @return
*/
Result
getOrderDetail
(
String
orderId
);
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/TbCfUserInfoService.java
浏览文件 @
560aea49
...
@@ -136,4 +136,11 @@ public interface TbCfUserInfoService {
...
@@ -136,4 +136,11 @@ public interface TbCfUserInfoService {
* @return
* @return
*/
*/
Result
loginByThirdParty
(
String
ip
,
String
amount
,
String
nick
,
String
userType
)
throws
UnsupportedEncodingException
;
Result
loginByThirdParty
(
String
ip
,
String
amount
,
String
nick
,
String
userType
)
throws
UnsupportedEncodingException
;
/**
* 使用token登录
* @param ipAddr
* @return
*/
Result
loginByToken
(
String
ipAddr
);
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfAddressServiceImpl.java
浏览文件 @
560aea49
...
@@ -10,7 +10,7 @@ import com.diaoyun.zion.chinafrica.vo.TbCfAddressVo;
...
@@ -10,7 +10,7 @@ import com.diaoyun.zion.chinafrica.vo.TbCfAddressVo;
import
com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo
;
import
com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.
util.CookieUtils
;
import
com.diaoyun.zion.master.
security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -38,6 +38,8 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
...
@@ -38,6 +38,8 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
@Resource
(
name
=
"redisTokenManager"
)
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
@Autowired
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
private
HttpServletRequest
request
;
//自动注入request
private
HttpServletRequest
request
;
//自动注入request
@Override
@Override
...
@@ -78,7 +80,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
...
@@ -78,7 +80,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
@Override
@Override
public
TbCfAddressVo
saveAddress
(
TbCfAddressVo
tbCfAddressVo
)
{
public
TbCfAddressVo
saveAddress
(
TbCfAddressVo
tbCfAddressVo
)
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
String
userId
=
tbCfUserInfoVo
.
getUserId
();
String
userId
=
tbCfUserInfoVo
.
getUserId
();
tbCfAddressVo
.
setUserId
(
userId
);
tbCfAddressVo
.
setUserId
(
userId
);
...
@@ -94,7 +96,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
...
@@ -94,7 +96,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
@Override
@Override
public
TbCfAddressVo
updateAddress
(
TbCfAddressVo
tbCfAddressVo
)
{
public
TbCfAddressVo
updateAddress
(
TbCfAddressVo
tbCfAddressVo
)
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
String
userId
=
tbCfUserInfoVo
.
getUserId
();
String
userId
=
tbCfUserInfoVo
.
getUserId
();
tbCfAddressVo
.
setUserId
(
userId
);
tbCfAddressVo
.
setUserId
(
userId
);
...
@@ -110,7 +112,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
...
@@ -110,7 +112,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
@Override
@Override
public
List
<
TbCfAddressVo
>
getUserInfoList
()
{
public
List
<
TbCfAddressVo
>
getUserInfoList
()
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
String
userId
=
tbCfUserInfoVo
.
getUserId
();
String
userId
=
tbCfUserInfoVo
.
getUserId
();
List
<
TbCfAddressEntity
>
tbCfAddressList
=
tbCfAddressDao
.
queryListByUserId
(
userId
);
List
<
TbCfAddressEntity
>
tbCfAddressList
=
tbCfAddressDao
.
queryListByUserId
(
userId
);
...
@@ -127,7 +129,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
...
@@ -127,7 +129,7 @@ public class TbCfAddressServiceImpl implements TbCfAddressService {
@Override
@Override
public
int
configDefaultAddress
(
String
addressId
)
{
public
int
configDefaultAddress
(
String
addressId
)
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
String
userId
=
tbCfUserInfoVo
.
getUserId
();
String
userId
=
tbCfUserInfoVo
.
getUserId
();
//更新用户默认地址
//更新用户默认地址
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfCouponServiceImpl.java
浏览文件 @
560aea49
...
@@ -12,7 +12,7 @@ import com.diaoyun.zion.master.base.StateConstant;
...
@@ -12,7 +12,7 @@ import com.diaoyun.zion.master.base.StateConstant;
import
com.diaoyun.zion.master.common.RedisCache
;
import
com.diaoyun.zion.master.common.RedisCache
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.
util.CookieUtils
;
import
com.diaoyun.zion.master.
security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -48,6 +48,9 @@ public class TbCfCouponServiceImpl implements TbCfCouponService {
...
@@ -48,6 +48,9 @@ public class TbCfCouponServiceImpl implements TbCfCouponService {
@Resource
(
name
=
"redisTokenManager"
)
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
@Autowired
private
HttpServletRequest
request
;
//自动注入request
private
HttpServletRequest
request
;
//自动注入request
@Resource
@Resource
...
@@ -93,7 +96,7 @@ public class TbCfCouponServiceImpl implements TbCfCouponService {
...
@@ -93,7 +96,7 @@ public class TbCfCouponServiceImpl implements TbCfCouponService {
public
Result
takeCoupon
(
String
couponId
)
{
public
Result
takeCoupon
(
String
couponId
)
{
Result
<
TbCfCouponEntity
>
result
=
new
Result
<>();
Result
<
TbCfCouponEntity
>
result
=
new
Result
<>();
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
//判断用户是否已经领取
//判断用户是否已经领取
boolean
takeFlag
=
repeatTakeCoupon
(
tbCfUserInfoVo
.
getUserId
(),
couponId
);
boolean
takeFlag
=
repeatTakeCoupon
(
tbCfUserInfoVo
.
getUserId
(),
couponId
);
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfFeedbackServiceImpl.java
浏览文件 @
560aea49
...
@@ -8,7 +8,7 @@ import com.diaoyun.zion.master.base.Result;
...
@@ -8,7 +8,7 @@ import com.diaoyun.zion.master.base.Result;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.
util.CookieUtils
;
import
com.diaoyun.zion.master.
security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
...
@@ -33,6 +33,8 @@ public class TbCfFeedbackServiceImpl implements TbCfFeedbackService {
...
@@ -33,6 +33,8 @@ public class TbCfFeedbackServiceImpl implements TbCfFeedbackService {
@Autowired
@Autowired
@Qualifier
(
"redisTokenManager"
)
@Qualifier
(
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
@Autowired
private
HttpServletRequest
request
;
//自动注入request
private
HttpServletRequest
request
;
//自动注入request
...
@@ -77,7 +79,7 @@ public class TbCfFeedbackServiceImpl implements TbCfFeedbackService {
...
@@ -77,7 +79,7 @@ public class TbCfFeedbackServiceImpl implements TbCfFeedbackService {
public
Result
saveFeedback
(
TbCfFeedbackEntity
tbCfFeedbackEntity
)
{
public
Result
saveFeedback
(
TbCfFeedbackEntity
tbCfFeedbackEntity
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
tbCfFeedbackEntity
.
setFeedbackId
(
IdUtil
.
createIdbyUUID
());
tbCfFeedbackEntity
.
setFeedbackId
(
IdUtil
.
createIdbyUUID
());
tbCfFeedbackEntity
.
setUserId
(
tbCfUserInfoVo
.
getUserId
());
tbCfFeedbackEntity
.
setUserId
(
tbCfUserInfoVo
.
getUserId
());
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfItemDetailServiceImpl.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
import
com.diaoyun.zion.chinafrica.dao.TbCfCartRecordRDao
;
import
com.diaoyun.zion.chinafrica.dao.TbCfCartRecordRDao
;
import
com.diaoyun.zion.chinafrica.dao.TbCfExpTemKeywordDao
;
import
com.diaoyun.zion.chinafrica.dao.TbCfItemDetailDao
;
import
com.diaoyun.zion.chinafrica.dao.TbCfItemDetailDao
;
import
com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfExpressTemplateEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity
;
import
com.diaoyun.zion.chinafrica.service.TbCfItemDetailService
;
import
com.diaoyun.zion.chinafrica.service.TbCfItemDetailService
;
import
com.diaoyun.zion.chinafrica.vo.TbCfCartItemDetailVo
;
import
com.diaoyun.zion.chinafrica.vo.TbCfCartItemDetailVo
;
...
@@ -12,17 +14,20 @@ import com.diaoyun.zion.master.base.Result;
...
@@ -12,17 +14,20 @@ import com.diaoyun.zion.master.base.Result;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.
util.CookieUtils
;
import
com.diaoyun.zion.master.
security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.WordposHelper
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.
Date
;
import
java.util.
*
;
import
java.util.
List
;
import
java.util.
concurrent.ExecutionException
;
import
java.util.
Map
;
import
java.util.
concurrent.TimeoutException
;
/**
/**
* 商品详情Service实现类
* 商品详情Service实现类
...
@@ -37,10 +42,15 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
...
@@ -37,10 +42,15 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
@Autowired
@Autowired
private
TbCfCartRecordRDao
tbCfCartRecordRDao
;
private
TbCfCartRecordRDao
tbCfCartRecordRDao
;
@Autowired
private
TbCfExpTemKeywordDao
tbCfExpTemKeywordDao
;
@Resource
(
name
=
"redisTokenManager"
)
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
@Autowired
private
HttpServletRequest
request
;
//自动注入request
private
HttpServletRequest
request
;
//自动注入request
...
@@ -82,11 +92,14 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
...
@@ -82,11 +92,14 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
}
}
@Override
@Override
public
Result
addToCart
(
TbCfItemDetailVo
tbCfItemDetailVo
)
{
public
Result
addToCart
(
TbCfItemDetailVo
tbCfItemDetailVo
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
//填充新商品必要信息
//填充新商品必要信息
fillItemInfo
(
tbCfItemDetailVo
);
fillItemInfo
(
tbCfItemDetailVo
);
//为商品分类,后面计算运费
TbCfExpressTemplateEntity
expressTemplate
=
recognizeItemCategory
(
tbCfItemDetailVo
.
getItemTitle
());
tbCfItemDetailVo
.
setItemCategory
(
expressTemplate
.
getTemplateId
());
//加入商品详情
//加入商品详情
TbCfItemDetailEntity
tbCfItemDetail
=
new
TbCfItemDetailEntity
();
TbCfItemDetailEntity
tbCfItemDetail
=
new
TbCfItemDetailEntity
();
BeanUtils
.
copyProperties
(
tbCfItemDetailVo
,
tbCfItemDetail
);
BeanUtils
.
copyProperties
(
tbCfItemDetailVo
,
tbCfItemDetail
);
...
@@ -120,7 +133,7 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
...
@@ -120,7 +133,7 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
@Override
@Override
public
List
<
TbCfCartItemDetailVo
>
getCartItemList
()
{
public
List
<
TbCfCartItemDetailVo
>
getCartItemList
()
{
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
String
userId
=
tbCfUserInfoVo
.
getUserId
();
String
userId
=
tbCfUserInfoVo
.
getUserId
();
return
tbCfItemDetailDao
.
getCartItemList
(
userId
,
null
);
return
tbCfItemDetailDao
.
getCartItemList
(
userId
,
null
);
...
@@ -144,4 +157,59 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
...
@@ -144,4 +157,59 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
tbCfItemDetailVo
.
setItemId
(
IdUtil
.
createIdbyUUID
());
tbCfItemDetailVo
.
setItemId
(
IdUtil
.
createIdbyUUID
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
}
/**
* 获取运费模板(包含分类)
*
* @param itemTitle
* @return
*/
private
TbCfExpressTemplateEntity
recognizeItemCategory
(
String
itemTitle
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
Map
<
String
,
Object
>
wordResult
=
separateText
(
itemTitle
);
//pos_code 16为名词,用名词去匹配; 23非汉字串
JSONArray
baseTokens
=
(
JSONArray
)
wordResult
.
get
(
"base_tokens"
);
List
<
String
>
keywordList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
baseTokens
.
size
();
i
++)
{
JSONObject
jsonObject
=
(
JSONObject
)
baseTokens
.
get
(
i
);
if
(
16
==
(
Integer
)
jsonObject
.
get
(
"pos_code"
))
{
keywordList
.
add
((
String
)
jsonObject
.
get
(
"word"
));
}
if
(
23
==
(
Integer
)
jsonObject
.
get
(
"pos_code"
))
{
keywordList
.
add
((
String
)
jsonObject
.
get
(
"word"
));
}
}
//总的可能适用的运费模板
Set
<
TbCfExpressTemplateEntity
>
totalTemplateSet
=
new
HashSet
<>();
if
(!
keywordList
.
isEmpty
())
{
for
(
String
keyword
:
keywordList
)
{
//根据keyword获取运费模板
List
<
TbCfExpressTemplateEntity
>
tbCfExpressTemplateList
=
tbCfExpTemKeywordDao
.
getTemplateByKeyword
(
keyword
);
totalTemplateSet
.
addAll
(
tbCfExpressTemplateList
);
}
}
//没有的话就设置 其他
if
(
totalTemplateSet
.
isEmpty
())
{
//根据keyword获取运费模板
List
<
TbCfExpressTemplateEntity
>
tbCfExpressTemplateList
=
tbCfExpTemKeywordDao
.
getTemplateByKeyword
(
"其他"
);
totalTemplateSet
.
addAll
(
tbCfExpressTemplateList
);
}
//取第一个运费
Iterator
<
TbCfExpressTemplateEntity
>
iterator
=
totalTemplateSet
.
iterator
();
TbCfExpressTemplateEntity
useTemplate
=
iterator
.
next
();
return
useTemplate
;
}
/**
* 分词
* @param text
* @return
*/
private
Map
<
String
,
Object
>
separateText
(
String
text
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
List
<
Map
<
String
,
Object
>>
futureList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
titleMap
=
new
HashMap
<>();
titleMap
.
put
(
"text"
,
text
);
WordposHelper
.
separeteText
(
futureList
,
titleMap
,
text
);
WordposHelper
.
waitForResult
(
futureList
);
return
titleMap
;
}
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfOrderServiceImpl.java
浏览文件 @
560aea49
...
@@ -18,16 +18,12 @@ import com.diaoyun.zion.master.common.RedisCache;
...
@@ -18,16 +18,12 @@ import com.diaoyun.zion.master.common.RedisCache;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.config.DomainProperties
;
import
com.diaoyun.zion.master.config.DomainProperties
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.util.AESUtils
;
import
com.diaoyun.zion.master.security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.CookieUtils
;
import
com.diaoyun.zion.master.util.*
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
com.diaoyun.zion.master.util.WordposHelper
;
import
com.diaoyun.zion.master.validator.Validator
;
import
com.diaoyun.zion.master.validator.Validator
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.stripe.exception.StripeException
;
import
com.stripe.exception.StripeException
;
import
com.stripe.model.Charge
;
import
com.stripe.model.Charge
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -77,7 +73,9 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -77,7 +73,9 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Autowired
@Autowired
private
TbCfFinanceDao
tbCfFinanceDao
;
private
TbCfFinanceDao
tbCfFinanceDao
;
@Autowired
@Autowired
private
TbCfExpTemKeywordDao
tbCfExpTemKeywordDao
;
private
TbCfExpressTemplateDao
tbCfExpressTemplateDao
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
@Autowired
private
TbCfFeeService
tbCfFeeService
;
private
TbCfFeeService
tbCfFeeService
;
...
@@ -137,7 +135,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -137,7 +135,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
public
Result
settleAccount
()
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
public
Result
settleAccount
()
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
Result
<
TbCfOrderVo
>
result
=
new
Result
<>();
Result
<
TbCfOrderVo
>
result
=
new
Result
<>();
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
//获取购物车已勾选 商品
//获取购物车已勾选 商品
List
<
TbCfCartItemDetailVo
>
tbCfCartItemDetailList
=
tbCfItemDetailDao
.
getCartItemList
(
tbCfUserInfoVo
.
getUserId
(),
StateConstant
.
VALID
);
List
<
TbCfCartItemDetailVo
>
tbCfCartItemDetailList
=
tbCfItemDetailDao
.
getCartItemList
(
tbCfUserInfoVo
.
getUserId
(),
StateConstant
.
VALID
);
...
@@ -156,7 +154,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -156,7 +154,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
public
Result
placeOrder
(
TbCfOrderVo
pageOrder
)
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
public
Result
placeOrder
(
TbCfOrderVo
pageOrder
)
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
Result
<
TbCfOrderVo
>
result
=
new
Result
<>();
Result
<
TbCfOrderVo
>
result
=
new
Result
<>();
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
//获取购物车已勾选 商品
//获取购物车已勾选 商品
List
<
TbCfCartItemDetailVo
>
tbCfCartItemDetailList
=
tbCfItemDetailDao
.
getCartItemList
(
tbCfUserInfoVo
.
getUserId
(),
StateConstant
.
VALID
);
List
<
TbCfCartItemDetailVo
>
tbCfCartItemDetailList
=
tbCfItemDetailDao
.
getCartItemList
(
tbCfUserInfoVo
.
getUserId
(),
StateConstant
.
VALID
);
...
@@ -182,7 +180,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -182,7 +180,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
public
Result
getUserOrderList
(
Integer
pageNum
,
Integer
pageSize
)
{
public
Result
getUserOrderList
(
Integer
pageNum
,
Integer
pageSize
)
{
Result
<
PageInfo
<
TbCfOrderVo
>>
result
=
new
Result
<>();
Result
<
PageInfo
<
TbCfOrderVo
>>
result
=
new
Result
<>();
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
//订单数据
//订单数据
List
<
TbCfOrderEntity
>
orderList
=
tbCfOrderDao
.
getUserOrderList
(
tbCfUserInfoVo
.
getUserId
());
List
<
TbCfOrderEntity
>
orderList
=
tbCfOrderDao
.
getUserOrderList
(
tbCfUserInfoVo
.
getUserId
());
...
@@ -240,7 +238,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -240,7 +238,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
@Override
@Override
public
Result
payForOrder
(
String
orderId
,
String
token
)
{
public
Result
payForOrder
(
String
orderId
,
String
token
)
{
Result
result
=
new
Result
();
Result
<
TbCfFinanceEntity
>
result
=
new
Result
<>
();
TbCfOrderVo
tbCfOrderVo
=
(
TbCfOrderVo
)
orderRedisCache
.
get
(
KeyConstant
.
ORDER_DET
+
orderId
);
TbCfOrderVo
tbCfOrderVo
=
(
TbCfOrderVo
)
orderRedisCache
.
get
(
KeyConstant
.
ORDER_DET
+
orderId
);
if
(
tbCfOrderVo
!=
null
)
{
if
(
tbCfOrderVo
!=
null
)
{
BigDecimal
realityPay
=
tbCfOrderVo
.
getRealityPay
();
BigDecimal
realityPay
=
tbCfOrderVo
.
getRealityPay
();
...
@@ -257,7 +255,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -257,7 +255,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
//更改订单状态
//更改订单状态
changeOrderState
(
charge
.
getId
(),
tbCfOrderVo
);
changeOrderState
(
charge
.
getId
(),
tbCfOrderVo
);
//生成流水记录
//生成流水记录
createFinance
(
charge
,
tbCfOrderVo
);
TbCfFinanceEntity
tbCfFinance
=
createFinance
(
charge
,
tbCfOrderVo
);
result
.
setData
(
tbCfFinance
);
}
else
{
}
else
{
result
.
setCode
(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
()).
setMessage
(
"Payment failed!"
);
result
.
setCode
(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
()).
setMessage
(
"Payment failed!"
);
}
}
...
@@ -275,9 +274,80 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -275,9 +274,80 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}
}
@Override
@Override
public
Result
queryOrderLogistics
(
String
orderId
)
{
public
Result
queryOrderExpressInfo
(
String
orderId
)
throws
IOException
{
String
expressUrl
=
domainProperties
.
getProperty
(
"express.info.api"
);
String
userNo
=
domainProperties
.
getProperty
(
"express.info.user_no"
);
String
token
=
domainProperties
.
getProperty
(
"express.info.token"
);
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
List
<
Map
<
String
,
String
>>
data
=
new
ArrayList
<>();
Map
<
String
,
String
>
dataMap
=
new
HashMap
<>();
dataMap
.
put
(
"order_no"
,
orderId
);
data
.
add
(
dataMap
);
paramMap
.
put
(
"user_no"
,
userNo
);
paramMap
.
put
(
"token"
,
token
);
paramMap
.
put
(
"data"
,
data
);
String
resultStr
=
HttpClientUtil
.
sendPostWithBodyParameter
(
expressUrl
,
paramMap
);
Map
resultMap
=
GsonUtil
.
GsonToMaps
(
resultStr
);
return
new
Result
<>(
resultMap
);
}
@Override
public
Result
getOrderListByTime
(
long
beginTime
,
long
endTime
,
Integer
pageNum
,
Integer
pageSize
)
{
Result
result
=
new
Result
<>();
if
((
endTime
-
beginTime
)>
31
*
24
*
60
*
60
)
{
result
.
setCode
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"Time interval is too long"
);
}
else
{
startPage
(
pageNum
,
pageSize
);
Date
beginDate
=
new
Date
(
beginTime
*
1000
);
Date
endDate
=
new
Date
(
endTime
*
1000
);
List
<
TbCfOrderEntity
>
orderList
=
tbCfOrderDao
.
getOrderListByTime
(
beginDate
,
endDate
);
PageInfo
<
TbCfOrderEntity
>
pageInfo
=
new
PageInfo
<>(
orderList
);
result
.
setData
(
pageInfo
);
}
return
result
;
}
return
null
;
@Override
public
Result
getDeliveryList
(
long
beginTime
,
long
endTime
,
Integer
pageNum
,
Integer
pageSize
)
{
Result
result
=
new
Result
<>();
if
((
endTime
-
beginTime
)>
31
*
24
*
60
*
60
)
{
result
.
setCode
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"Time interval is too long"
);
}
else
{
startPage
(
pageNum
,
pageSize
);
Date
beginDate
=
new
Date
(
beginTime
*
1000
);
Date
endDate
=
new
Date
(
endTime
*
1000
);
List
<
TbCfItemShippedEntity
>
orderList
=
tbCfOrderDao
.
getDeliveryList
(
beginDate
,
endDate
);
PageInfo
<
TbCfItemShippedEntity
>
pageInfo
=
new
PageInfo
<>(
orderList
);
result
.
setData
(
pageInfo
);
}
return
result
;
}
@Override
public
Result
getOrderDetail
(
String
orderId
)
{
Result
<
TbCfOrderVo
>
result
=
new
Result
<>();
TbCfOrderEntity
tbCfOrderEntity
=
tbCfOrderDao
.
queryObject
(
orderId
);
TbCfOrderVo
tbCfOrderVo
=
new
TbCfOrderVo
();
tbCfOrderVo
.
setOrderId
(
tbCfOrderEntity
.
getOrderId
());
tbCfOrderVo
.
setDeliveryPhone
(
tbCfOrderEntity
.
getDeliveryPhone
());
tbCfOrderVo
.
setDeliveryName
(
tbCfOrderEntity
.
getDeliveryName
());
tbCfOrderVo
.
setDeliveryAddress
(
tbCfOrderEntity
.
getDeliveryAddress
());
//获取订单内商品
List
<
TbCfItemDetailEntity
>
tbCfItemDetailList
=
tbCfOrderDao
.
getOrderItemList
(
orderId
);
//返回的订单商品详情
List
<
TbCfCartItemDetailVo
>
itemDetailVoList
=
new
ArrayList
<>();
for
(
TbCfItemDetailEntity
tbCfItemDetail
:
tbCfItemDetailList
)
{
TbCfCartItemDetailVo
tbCfCartItemDetailVo
=
new
TbCfCartItemDetailVo
();
tbCfCartItemDetailVo
.
setItemNum
(
tbCfItemDetail
.
getItemNum
());
tbCfCartItemDetailVo
.
setItemCategory
(
tbCfItemDetail
.
getItemCategory
());
tbCfCartItemDetailVo
.
setItemPrice
(
tbCfItemDetail
.
getItemPrice
());
tbCfCartItemDetailVo
.
setItemTitle
(
tbCfItemDetail
.
getItemTitle
());
itemDetailVoList
.
add
(
tbCfCartItemDetailVo
);
}
tbCfOrderVo
.
setItemDetailList
(
itemDetailVoList
);
result
.
setData
(
tbCfOrderVo
);
return
result
;
}
}
/**
/**
...
@@ -286,17 +356,19 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -286,17 +356,19 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
* @param charge
* @param charge
* @param tbCfOrderVo
* @param tbCfOrderVo
*/
*/
private
void
createFinance
(
Charge
charge
,
TbCfOrderVo
tbCfOrderVo
)
{
private
TbCfFinanceEntity
createFinance
(
Charge
charge
,
TbCfOrderVo
tbCfOrderVo
)
{
TbCfFinanceEntity
tbCfFinance
=
new
TbCfFinanceEntity
();
TbCfFinanceEntity
tbCfFinance
=
new
TbCfFinanceEntity
();
tbCfFinance
.
setOrderId
(
tbCfOrderVo
.
getOrderId
());
tbCfFinance
.
setOrderId
(
tbCfOrderVo
.
getOrderId
());
tbCfFinance
.
setFinaceId
(
IdUtil
.
createIdbyUUID
());
tbCfFinance
.
setFinaceId
(
IdUtil
.
createIdbyUUID
());
tbCfFinance
.
setPayAccount
(
tbCfOrderVo
.
getRealityPay
());
tbCfFinance
.
setPayAccount
(
tbCfOrderVo
.
getRealityPay
());
tbCfFinance
.
setPayId
(
charge
.
getId
());
tbCfFinance
.
setPayId
(
charge
.
getId
());
tbCfFinance
.
setPayTime
(
new
Date
());
tbCfFinance
.
setPayTime
(
new
Date
());
tbCfFinance
.
setReceiptUrl
(
charge
.
getReceiptUrl
());
//暂时用 stripe
//暂时用 stripe
tbCfFinance
.
setPayWayCode
(
"stripe"
);
tbCfFinance
.
setPayWayCode
(
"stripe"
);
tbCfFinance
.
setUserId
(
tbCfOrderVo
.
getUserId
());
tbCfFinance
.
setUserId
(
tbCfOrderVo
.
getUserId
());
tbCfFinanceDao
.
save
(
tbCfFinance
);
tbCfFinanceDao
.
save
(
tbCfFinance
);
return
tbCfFinance
;
}
}
/**
/**
...
@@ -314,7 +386,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -314,7 +386,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
tbCfOrder
.
setOrderStatus
(
OrderStatusEnum
.
PAID
.
getValue
());
tbCfOrder
.
setOrderStatus
(
OrderStatusEnum
.
PAID
.
getValue
());
tbCfOrder
.
setDeliveryFlag
(
DeliveryStatusEnum
.
PROCESSING
.
getValue
());
tbCfOrder
.
setDeliveryFlag
(
DeliveryStatusEnum
.
PROCESSING
.
getValue
());
tbCfOrder
.
setPayId
(
payId
);
tbCfOrder
.
setPayId
(
payId
);
tbCfOrder
.
setPayStatus
(
StateConstant
.
VALID
);
tbCfOrder
.
setPayStatus
(
OrderStatusEnum
.
PAID
.
getValue
()
);
tbCfOrderDao
.
update
(
tbCfOrder
);
tbCfOrderDao
.
update
(
tbCfOrder
);
}
}
...
@@ -503,7 +575,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -503,7 +575,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
BigDecimal
itemNum
=
BigDecimal
.
valueOf
(
tbCfCartItemDetailVo
.
getItemNum
());
BigDecimal
itemNum
=
BigDecimal
.
valueOf
(
tbCfCartItemDetailVo
.
getItemNum
());
itemsPrice
=
itemsPrice
.
add
(
tbCfCartItemDetailVo
.
getItemPrice
().
multiply
(
itemNum
));
itemsPrice
=
itemsPrice
.
add
(
tbCfCartItemDetailVo
.
getItemPrice
().
multiply
(
itemNum
));
//计算运费
//计算运费
BigDecimal
expressCost
=
countExpressCost
(
tbCfCartItemDetailVo
.
getItemTitle
());
BigDecimal
expressCost
=
getExpressTemplate
(
tbCfCartItemDetailVo
.
getItemCategory
());
expressCost
=
expressCost
.
multiply
(
itemNum
);
expressCost
=
expressCost
.
multiply
(
itemNum
);
totalExpressCost
=
totalExpressCost
.
add
(
expressCost
);
totalExpressCost
=
totalExpressCost
.
add
(
expressCost
);
}
}
...
@@ -525,62 +597,15 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
...
@@ -525,62 +597,15 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
}
}
/**
/**
* 计算运费
* 获取运费 TODO 运费模板可改为缓存
*
* @param templateId
* @param itemTitle
* @return
* @return
*/
*/
private
BigDecimal
countExpressCost
(
String
itemTitle
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
private
BigDecimal
getExpressTemplate
(
String
templateId
)
{
BigDecimal
itemExpressFee
;
TbCfExpressTemplateEntity
tbCfExpressTemplateEntity
=
tbCfExpressTemplateDao
.
queryObject
(
templateId
);
Map
<
String
,
Object
>
wordResult
=
separateText
(
itemTitle
);
return
tbCfExpressTemplateEntity
.
getExpressFee
();
//pos_code 16为名词,用名词去匹配; 23非汉字串
JSONArray
baseTokens
=
(
JSONArray
)
wordResult
.
get
(
"base_tokens"
);
List
<
String
>
keywordList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
baseTokens
.
size
();
i
++)
{
JSONObject
jsonObject
=
(
JSONObject
)
baseTokens
.
get
(
i
);
if
(
16
==
(
Integer
)
jsonObject
.
get
(
"pos_code"
))
{
keywordList
.
add
((
String
)
jsonObject
.
get
(
"word"
));
}
if
(
23
==
(
Integer
)
jsonObject
.
get
(
"pos_code"
))
{
keywordList
.
add
((
String
)
jsonObject
.
get
(
"word"
));
}
}
//总的可能适用的运费模板
Set
<
TbCfExpressTemplateEntity
>
totalTemplateSet
=
new
HashSet
<>();
if
(!
keywordList
.
isEmpty
())
{
for
(
String
keyword
:
keywordList
)
{
//根据keyword获取运费模板
List
<
TbCfExpressTemplateEntity
>
tbCfExpressTemplateList
=
tbCfExpTemKeywordDao
.
getTemplateByKeyword
(
keyword
);
totalTemplateSet
.
addAll
(
tbCfExpressTemplateList
);
}
}
//没有的话就设置 其他
if
(
totalTemplateSet
.
isEmpty
())
{
//根据keyword获取运费模板
List
<
TbCfExpressTemplateEntity
>
tbCfExpressTemplateList
=
tbCfExpTemKeywordDao
.
getTemplateByKeyword
(
"其他"
);
totalTemplateSet
.
addAll
(
tbCfExpressTemplateList
);
}
//取第一个运费
Iterator
<
TbCfExpressTemplateEntity
>
iterator
=
totalTemplateSet
.
iterator
();
TbCfExpressTemplateEntity
useTemplate
=
iterator
.
next
();
itemExpressFee
=
useTemplate
.
getExpressFee
();
return
itemExpressFee
;
}
}
/**
* 分词
*
* @param text
* @return
*/
public
Map
<
String
,
Object
>
separateText
(
String
text
)
throws
ExecutionException
,
InterruptedException
,
TimeoutException
{
List
<
Map
<
String
,
Object
>>
futureList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
titleMap
=
new
HashMap
<>();
titleMap
.
put
(
"text"
,
text
);
WordposHelper
.
separeteText
(
futureList
,
titleMap
,
text
);
WordposHelper
.
waitForResult
(
futureList
);
return
titleMap
;
}
/**
/**
* 验证订单优惠券
* 验证订单优惠券
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfUserInfoServiceImpl.java
浏览文件 @
560aea49
...
@@ -11,13 +11,16 @@ import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
...
@@ -11,13 +11,16 @@ import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.base.StateConstant
;
import
com.diaoyun.zion.master.bo.EmailTemplateBo
;
import
com.diaoyun.zion.master.bo.EmailTemplateBo
;
import
com.diaoyun.zion.master.common.RedisCache
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.config.DomainProperties
;
import
com.diaoyun.zion.master.config.DomainProperties
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.SexEnum
;
import
com.diaoyun.zion.master.enums.SexEnum
;
import
com.diaoyun.zion.master.enums.TrueFalseEnum
;
import
com.diaoyun.zion.master.enums.TrueFalseEnum
;
import
com.diaoyun.zion.master.enums.UserTypeEnum
;
import
com.diaoyun.zion.master.enums.UserTypeEnum
;
import
com.diaoyun.zion.master.exception.ApplicationException
;
import
com.diaoyun.zion.master.exception.ValidateException
;
import
com.diaoyun.zion.master.exception.ValidateException
;
import
com.diaoyun.zion.master.security.JwtTokenProvider
;
import
com.diaoyun.zion.master.util.*
;
import
com.diaoyun.zion.master.util.*
;
import
com.diaoyun.zion.master.validator.Validator
;
import
com.diaoyun.zion.master.validator.Validator
;
import
freemarker.template.TemplateException
;
import
freemarker.template.TemplateException
;
...
@@ -26,6 +29,11 @@ import org.apache.commons.mail.EmailException;
...
@@ -26,6 +29,11 @@ import org.apache.commons.mail.EmailException;
import
org.apache.http.Consts
;
import
org.apache.http.Consts
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -50,6 +58,15 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -50,6 +58,15 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
@Autowired
@Autowired
private
TbCfUserInfoDao
tbCfUserInfoDao
;
private
TbCfUserInfoDao
tbCfUserInfoDao
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Autowired
private
AuthenticationManager
authenticationManager
;
@Resource
(
name
=
"redisTokenManager"
)
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
private
TokenManager
tokenManager
;
...
@@ -65,6 +82,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -65,6 +82,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
@Autowired
@Autowired
private
HttpServletResponse
response
;
private
HttpServletResponse
response
;
@Autowired
private
RedisCache
<
Object
>
captchaRedisCache
;
@Override
@Override
public
TbCfUserInfoEntity
queryObject
(
String
userId
)
{
public
TbCfUserInfoEntity
queryObject
(
String
userId
)
{
return
tbCfUserInfoDao
.
queryObject
(
userId
);
return
tbCfUserInfoDao
.
queryObject
(
userId
);
...
@@ -108,13 +128,15 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -108,13 +128,15 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
emailTemplateBo
.
setNick
(
nick
);
emailTemplateBo
.
setNick
(
nick
);
emailTemplateBo
.
setIdentifyCode
(
randomCode
);
emailTemplateBo
.
setIdentifyCode
(
randomCode
);
Integer
identifyCode
=
emailHelper
.
sendIdentifyEmail
(
email
,
EmailTemplateConstant
.
REGISTER
,
emailTemplateBo
);
Integer
identifyCode
=
emailHelper
.
sendIdentifyEmail
(
email
,
EmailTemplateConstant
.
REGISTER
,
emailTemplateBo
);
captchaRedisCache
.
set
(
KeyConstant
.
CAPTCHA
+
email
,
identifyCode
,
1800
);
return
identifyCode
;
return
identifyCode
;
}
}
@Override
@Override
public
Result
registerAndLogin
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
public
Result
registerAndLogin
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
Integer
identifyCode
=
(
Integer
)
request
.
getSession
().
getAttribute
(
KeyConstant
.
IDENTIFY_CODE
);
Integer
identifyCode
=
(
Integer
)
captchaRedisCache
.
get
(
KeyConstant
.
CAPTCHA
+
tbCfUserInfoVo
.
getAccount
());
;
if
(
identifyCode
==
null
||
identifyCode
.
intValue
()
!=
tbCfUserInfoVo
.
getCaptcha
().
intValue
())
{
if
(
identifyCode
==
null
||
identifyCode
.
intValue
()
!=
tbCfUserInfoVo
.
getCaptcha
().
intValue
())
{
result
.
setCode
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
());
result
.
setCode
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
());
result
.
setMessage
(
"Verification code error"
);
result
.
setMessage
(
"Verification code error"
);
...
@@ -122,8 +144,6 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -122,8 +144,6 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
//验证邮箱有没有被注册
//验证邮箱有没有被注册
TbCfUserInfoEntity
existUser
=
findByAccount
(
tbCfUserInfoVo
.
getEmail
());
TbCfUserInfoEntity
existUser
=
findByAccount
(
tbCfUserInfoVo
.
getEmail
());
if
(
existUser
==
null
)
{
if
(
existUser
==
null
)
{
//验证邮箱格式
Validator
.
NOT_BLANK
.
validate
(
"email"
,
tbCfUserInfoVo
.
getEmail
());
TbCfUserInfoEntity
tbCfUserInfoEntity
=
new
TbCfUserInfoEntity
();
TbCfUserInfoEntity
tbCfUserInfoEntity
=
new
TbCfUserInfoEntity
();
/**
/**
...
@@ -134,110 +154,63 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -134,110 +154,63 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
tbCfUserInfoVo
.
setEmailFlag
(
StateConstant
.
VALID
);
tbCfUserInfoVo
.
setEmailFlag
(
StateConstant
.
VALID
);
fillUserNecessayInfo
(
tbCfUserInfoVo
);
fillUserNecessayInfo
(
tbCfUserInfoVo
);
//加密密码
//加密密码
String
password
=
PasswordProvider
.
encrypt
(
tbCfUserInfoVo
.
getPassword
());
String
password
=
passwordEncoder
.
encode
(
tbCfUserInfoVo
.
getPassword
());
tbCfUserInfoVo
.
setPassword
(
password
);
tbCfUserInfoVo
.
setPassword
(
password
);
BeanUtils
.
copyProperties
(
tbCfUserInfoVo
,
tbCfUserInfoEntity
);
BeanUtils
.
copyProperties
(
tbCfUserInfoVo
,
tbCfUserInfoEntity
);
tbCfUserInfoDao
.
save
(
tbCfUserInfoEntity
);
tbCfUserInfoDao
.
save
(
tbCfUserInfoEntity
);
//注册成功 创建token
//注册成功 创建token
String
token
=
createToken
(
tbCfUserInfoVo
);
String
token
=
jwtTokenProvider
.
createToken
(
tbCfUserInfoVo
.
getAccount
());
addTokenInCookie
(
token
,
request
,
response
);
tbCfUserInfoVo
.
setToken
(
token
);
SessionUtils
.
setSessionUser
(
request
,
new
SessionUser
(
token
,
tbCfUserInfoVo
.
getAccount
()));
//保存在redis
tokenManager
.
addToken
(
token
,
tbCfUserInfoVo
);
result
.
setMessage
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
result
.
setMessage
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
result
.
setData
(
tbCfUserInfoVo
);
result
.
setData
(
tbCfUserInfoVo
);
}
else
{
}
else
{
result
.
setCode
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
());
result
.
setCode
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
());
result
.
setMessage
(
"The mailbox has been registered"
);
result
.
setMessage
(
"The mailbox
or nick
has been registered"
);
}
}
tbCfUserInfoVo
.
setEnableFlag
(
StateConstant
.
VALID
);
tbCfUserInfoVo
.
setEnableFlag
(
StateConstant
.
VALID
);
}
}
return
result
;
return
result
;
}
}
@Override
@Override
public
Result
login
(
String
ip
,
String
account
,
String
password
)
{
public
Result
login
(
String
ip
,
String
account
,
String
password
)
{
try
{
Result
result
=
new
Result
();
authenticationManager
.
authenticate
(
new
UsernamePasswordAuthenticationToken
(
account
,
password
));
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
createToken
(
account
);
if
(
StringUtils
.
isNotBlank
(
token
))
{
//password = passwordEncoder.encode(password);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
return
loginOfficial
(
ip
,
account
,
token
);
if
(
tbCfUserInfoVo
==
null
)
{
}
catch
(
AuthenticationException
e
)
{
if
(
StringUtils
.
isBlank
(
account
)||
StringUtils
.
isBlank
(
password
))
{
throw
new
ApplicationException
(
ResultCodeEnum
.
NEED_LOGIN
.
getCode
(),
"Invalid username/password supplied or account is disable"
);
tokenManager
.
remove
(
token
);
CookieUtils
.
removeCookie
(
response
,
TokenManager
.
TOKEN
,
"/"
,
null
);
result
.
setCode
(
ResultCodeEnum
.
NEED_LOGIN
.
getCode
()).
setMessage
(
ResultCodeEnum
.
NEED_LOGIN
.
getDesc
());
}
else
{
password
=
PasswordProvider
.
encrypt
(
password
);
result
=
loginOfficial
(
ip
,
account
,
password
,
token
);
}
}
else
{
if
(
StringUtils
.
isBlank
(
account
))
{
account
=
tbCfUserInfoVo
.
getAccount
();
}
if
(
StringUtils
.
isBlank
(
password
))
{
password
=
tbCfUserInfoVo
.
getPassword
();
}
else
{
password
=
PasswordProvider
.
encrypt
(
password
);
}
result
=
loginOfficial
(
ip
,
account
,
password
,
token
);
}
}
else
{
Validator
.
NOT_BLANK
.
validate
(
"account"
,
account
);
Validator
.
NOT_BLANK
.
validate
(
"password"
,
password
);
password
=
PasswordProvider
.
encrypt
(
password
);
result
=
loginOfficial
(
ip
,
account
,
password
,
null
);
}
}
return
result
;
}
}
/**
/**
* 登录
* 登录
*
* @param ip
* @param ip
* @param account
* @param account
* @param password
* @param token
* @param token
* @return
* @return
*/
*/
private
Result
loginOfficial
(
String
ip
,
String
account
,
String
password
,
String
token
)
{
private
Result
loginOfficial
(
String
ip
,
String
account
,
String
token
)
{
Result
<
TbCfUserInfoVo
>
result
=
new
Result
<>();
Result
result
=
new
Result
();
TbCfUserInfoEntity
user
=
findByAccount
(
account
);
TbCfUserInfoEntity
user
=
findByAccount
(
account
);
if
(
user
==
null
)
{
user
.
setLastLoginIp
(
ip
);
result
.
setCode
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"Account does not exist"
);
user
.
setLoginCount
(
user
.
getLoginCount
()
+
1
);
}
else
if
(
user
.
getPassword
()!=
null
&&!
user
.
getPassword
().
equals
(
password
))
{
user
.
setLastLoginTime
(
new
Date
());
result
.
setCode
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"The password is incorrect"
);
tbCfUserInfoDao
.
update
(
user
);
}
else
if
(
TrueFalseEnum
.
FALSE
.
getValue
().
equals
(
user
.
getEnableFlag
()))
{
TbCfUserInfoVo
loginUser
=
new
TbCfUserInfoVo
();
result
.
setCode
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"User is disabled"
);
BeanUtils
.
copyProperties
(
user
,
loginUser
);
CookieUtils
.
removeCookie
(
response
,
TokenManager
.
TOKEN
,
"/"
,
null
);
loginUser
.
setToken
(
token
);
}
else
{
//更新用户
user
.
setLastLoginIp
(
ip
);
tokenManager
.
addToken
(
token
,
loginUser
);
user
.
setLoginCount
(
user
.
getLoginCount
()
+
1
);
result
.
setData
(
loginUser
).
setMessage
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
user
.
setLastLoginTime
(
new
Date
());
tbCfUserInfoDao
.
update
(
user
);
//登录成功
TbCfUserInfoVo
loginUser
=
new
TbCfUserInfoVo
();
BeanUtils
.
copyProperties
(
user
,
loginUser
);
if
(
StringUtils
.
isBlank
(
token
))
{
//用户密码登录成功 创建token
token
=
createToken
(
loginUser
);
addTokenInCookie
(
token
,
request
,
response
);
}
else
{
//更新用户
tokenManager
.
addToken
(
token
,
loginUser
);
}
SessionUtils
.
setSessionUser
(
request
,
new
SessionUser
(
token
,
loginUser
.
getAccount
()));
result
.
setData
(
loginUser
).
setMessage
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
}
return
result
;
return
result
;
}
}
@Override
@Override
public
TbCfUserInfoEntity
findByAccount
(
String
account
)
{
public
TbCfUserInfoEntity
findByAccount
(
String
account
)
{
...
@@ -248,7 +221,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -248,7 +221,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
@Override
@Override
public
Result
updatePassWord
(
String
newPassword
,
String
oldPassword
)
{
public
Result
updatePassWord
(
String
newPassword
,
String
oldPassword
)
{
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
loginUser
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
loginUser
=
tokenManager
.
validate
(
token
);
String
userId
=
loginUser
.
getUserId
();
String
userId
=
loginUser
.
getUserId
();
Result
result
=
new
Result
();
Result
result
=
new
Result
();
...
@@ -264,18 +237,17 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -264,18 +237,17 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
@Override
@Override
public
Result
logout
()
{
public
Result
logout
()
{
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
if
(
StringUtils
.
isNotBlank
(
token
))
{
if
(
StringUtils
.
isNotBlank
(
token
))
{
tokenManager
.
remove
(
token
);
tokenManager
.
remove
(
token
);
}
}
SessionUtils
.
invalidate
(
request
);
return
new
Result
(
"login out"
);
return
new
Result
(
"login out"
);
}
}
@Override
@Override
public
int
updateUserInfo
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
public
int
updateUserInfo
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
//获取用户
//获取用户
String
token
=
CookieUtils
.
getCookie
(
request
,
TokenManager
.
TOKEN
);
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
loginUser
=
tokenManager
.
validate
(
token
);
TbCfUserInfoVo
loginUser
=
tokenManager
.
validate
(
token
);
String
userId
=
loginUser
.
getUserId
();
String
userId
=
loginUser
.
getUserId
();
tbCfUserInfoVo
.
setUserId
(
userId
);
tbCfUserInfoVo
.
setUserId
(
userId
);
...
@@ -286,8 +258,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -286,8 +258,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
}
@Override
@Override
// TODO
public
Result
loginByThirdParty
(
String
ip
,
String
account
,
String
nick
,
String
userType
)
throws
UnsupportedEncodingException
{
public
Result
loginByThirdParty
(
String
ip
,
String
account
,
String
nick
,
String
userType
)
throws
UnsupportedEncodingException
{
Result
result
=
new
Result
();
/*
Result result = new Result();
String token = CookieUtils.getCookie(request, TokenManager.TOKEN);
String token = CookieUtils.getCookie(request, TokenManager.TOKEN);
if (StringUtils.isNotBlank(token) && tokenManager.validate(token) != null) {
if (StringUtils.isNotBlank(token) && tokenManager.validate(token) != null) {
...
@@ -296,13 +269,13 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -296,13 +269,13 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
CookieUtils.removeCookie(response, TokenManager.TOKEN, "/", null);
CookieUtils.removeCookie(response, TokenManager.TOKEN, "/", null);
result.setCode(ResultCodeEnum.ERROR.getCode()).setMessage("please login again");
result.setCode(ResultCodeEnum.ERROR.getCode()).setMessage("please login again");
} else {
} else {
if
(
StringUtils
.
isBlank
(
account
))
{
if
(StringUtils.isBlank(account)) {
account
=
tbCfUserInfoVo
.
getAccount
();
account
=
tbCfUserInfoVo.getAccount();
}
}
if
(
StringUtils
.
isBlank
(
nick
))
{
if
(StringUtils.isBlank(nick)) {
nick
=
tbCfUserInfoVo
.
getNick
();
nick
=
tbCfUserInfoVo.getNick();
}
}
loginByThirdPartyOfficial
(
token
,
ip
,
account
,
nick
,
result
);
loginByThirdPartyOfficial(token, ip,
account, nick
, result);
}
}
} else {
} else {
Validator.NOT_BLANK.validate("account", account);
Validator.NOT_BLANK.validate("account", account);
...
@@ -320,9 +293,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -320,9 +293,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
tbCfUserInfoVo.setNick(nick);
tbCfUserInfoVo.setNick(nick);
tbCfUserInfoVo.setLastLoginIp(ip);
tbCfUserInfoVo.setLastLoginIp(ip);
TbCfUserInfoEntity tbCfUserInfoEntity = new TbCfUserInfoEntity();
TbCfUserInfoEntity tbCfUserInfoEntity = new TbCfUserInfoEntity();
/**
*/
/**
* 填充必要信息
* 填充必要信息
*/
*/
/*
fillUserNecessayInfo(tbCfUserInfoVo);
fillUserNecessayInfo(tbCfUserInfoVo);
BeanUtils.copyProperties(tbCfUserInfoVo, tbCfUserInfoEntity);
BeanUtils.copyProperties(tbCfUserInfoVo, tbCfUserInfoEntity);
...
@@ -332,7 +305,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -332,7 +305,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
buildUserToken(tbCfUserInfoEntity);
buildUserToken(tbCfUserInfoEntity);
result.setMessage("登录成功").setData(tbCfUserInfoVo);
result.setMessage("登录成功").setData(tbCfUserInfoVo);
} else {
} else {
if
(
nick
.
equals
(
oldUser
.
getNick
()))
{
if
(nick.equals(oldUser.getNick())) {
oldUser.setLastLoginIp(ip);
oldUser.setLastLoginIp(ip);
oldUser.setLoginCount(oldUser.getLoginCount() + 1);
oldUser.setLoginCount(oldUser.getLoginCount() + 1);
oldUser.setLastLoginTime(new Date());
oldUser.setLastLoginTime(new Date());
...
@@ -345,13 +318,21 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -345,13 +318,21 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
}
}
}
}
}*/
return
result
;
return
null
;
}
@Override
public
Result
loginByToken
(
String
ip
)
{
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
String
account
=
jwtTokenProvider
.
getUsername
(
token
);
return
loginOfficial
(
ip
,
account
,
token
);
}
}
/**
/**
* 获取用户类型
* 获取用户类型
*
* @param userType
* @param userType
* @return
* @return
*/
*/
...
@@ -387,13 +368,13 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -387,13 +368,13 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
*
*
* @param oldUser
* @param oldUser
*/
*/
private
void
buildUserToken
(
TbCfUserInfoEntity
oldUser
)
{
/*
private void buildUserToken(TbCfUserInfoEntity oldUser) {
TbCfUserInfoVo loginUser = new TbCfUserInfoVo();
TbCfUserInfoVo loginUser = new TbCfUserInfoVo();
BeanUtils.copyProperties(oldUser, loginUser);
BeanUtils.copyProperties(oldUser, loginUser);
String newToken = createToken(loginUser);
String newToken = createToken(loginUser);
addTokenInCookie(newToken, request, response);
addTokenInCookie(newToken, request, response);
SessionUtils.setSessionUser(request, new SessionUser(newToken, loginUser.getAccount()));
SessionUtils.setSessionUser(request, new SessionUser(newToken, loginUser.getAccount()));
}
}
*/
/**
/**
* 第三方登录
* 第三方登录
...
@@ -402,9 +383,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -402,9 +383,9 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
* @param nick
* @param nick
* @return
* @return
*/
*/
private
void
loginByThirdPartyOfficial
(
String
token
,
String
ip
,
String
account
,
String
nick
,
Result
result
)
{
/*
private void loginByThirdPartyOfficial(String token, String ip, String account, String nick, Result result) {
TbCfUserInfoEntity user = findByAccount(account);
TbCfUserInfoEntity user = findByAccount(account);
if
(
user
!=
null
&&
nick
.
equals
(
user
.
getNick
()))
{
if (user != null
&&
nick.equals(user.getNick())) {
user.setLastLoginIp(ip);
user.setLastLoginIp(ip);
user.setLoginCount(user.getLoginCount() + 1);
user.setLoginCount(user.getLoginCount() + 1);
user.setLastLoginTime(new Date());
user.setLastLoginTime(new Date());
...
@@ -419,7 +400,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -419,7 +400,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
CookieUtils.removeCookie(response, TokenManager.TOKEN, "/", null);
CookieUtils.removeCookie(response, TokenManager.TOKEN, "/", null);
result.setCode(ResultCodeEnum.NEED_LOGIN.getCode()).setMessage("please login again");
result.setCode(ResultCodeEnum.NEED_LOGIN.getCode()).setMessage("please login again");
}
}
}
}
*/
private
void
fillUserNecessayInfo
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
private
void
fillUserNecessayInfo
(
TbCfUserInfoVo
tbCfUserInfoVo
)
{
...
@@ -435,16 +416,16 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -435,16 +416,16 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
}
//创建token
//创建token
private
String
createToken
(
TbCfUserInfoVo
loginUser
)
{
/*
private String createToken(TbCfUserInfoVo loginUser) {
// 生成token
// 生成token
String token = IdUtil.createIdbyUUID();
String token = IdUtil.createIdbyUUID();
// 缓存中添加token对应User
// 缓存中添加token对应User
tokenManager.addToken(token, loginUser);
tokenManager.addToken(token, loginUser);
return token;
return token;
}
}
*/
//添加cookie
//添加cookie
private
void
addTokenInCookie
(
String
token
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
/*
private void addTokenInCookie(String token, HttpServletRequest request, HttpServletResponse response) {
// Cookie添加token
// Cookie添加token
Cookie cookie = new Cookie(TokenManager.TOKEN, token);
Cookie cookie = new Cookie(TokenManager.TOKEN, token);
cookie.setPath("/");
cookie.setPath("/");
...
@@ -453,6 +434,6 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
...
@@ -453,6 +434,6 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
}
}
cookie.setHttpOnly(true);
cookie.setHttpOnly(true);
response.addCookie(cookie);
response.addCookie(cookie);
}
}
*/
}
}
src/main/java/com/diaoyun/zion/chinafrica/vo/TbCfUserInfoVo.java
浏览文件 @
560aea49
...
@@ -129,6 +129,11 @@ public class TbCfUserInfoVo implements Serializable {
...
@@ -129,6 +129,11 @@ public class TbCfUserInfoVo implements Serializable {
@ApiModelProperty
(
value
=
"验证码"
,
required
=
true
)
@ApiModelProperty
(
value
=
"验证码"
,
required
=
true
)
private
Integer
captcha
;
private
Integer
captcha
;
/**
* token
*/
@ApiModelProperty
(
value
=
"用户token"
)
private
String
token
;
/**
/**
...
@@ -407,4 +412,12 @@ public class TbCfUserInfoVo implements Serializable {
...
@@ -407,4 +412,12 @@ public class TbCfUserInfoVo implements Serializable {
public
void
setEmailFlag
(
Integer
emailFlag
)
{
public
void
setEmailFlag
(
Integer
emailFlag
)
{
this
.
emailFlag
=
emailFlag
;
this
.
emailFlag
=
emailFlag
;
}
}
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
}
}
src/main/java/com/diaoyun/zion/master/config/SwaggerConfig.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
config
;
package
com
.
diaoyun
.
zion
.
master
.
config
;
import
com.google.common.base.Predicates
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -8,10 +9,17 @@ import springfox.documentation.builders.ApiInfoBuilder;
...
@@ -8,10 +9,17 @@ import springfox.documentation.builders.ApiInfoBuilder;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.service.ApiKey
;
import
springfox.documentation.service.Contact
;
import
springfox.documentation.service.Tag
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Optional
;
@Configuration
@Configuration
@EnableSwagger2
@EnableSwagger2
@EnableWebMvc
@EnableWebMvc
...
@@ -20,16 +28,23 @@ public class SwaggerConfig {
...
@@ -20,16 +28,23 @@ public class SwaggerConfig {
@Bean
@Bean
public
Docket
createRestApi
()
{
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
//
.
select
()
.
apis
(
RequestHandlerSelectors
.
any
())
//
.
apis
(
RequestHandlerSelectors
.
withClassAnnotation
(
Api
.
class
))
.
paths
(
Predicates
.
not
(
PathSelectors
.
regex
(
"/error"
)))
//
.
paths
(
PathSelectors
.
any
())
.
build
()
//
.
build
();
.
apiInfo
(
apiInfo
())
//
.
useDefaultResponseMessages
(
false
)
//
.
securitySchemes
(
new
ArrayList
<>(
Arrays
.
asList
(
new
ApiKey
(
"Bearer %token"
,
"Authorization"
,
"Header"
))))
//
.
genericModelSubstitutes
(
Optional
.
class
);
}
}
private
ApiInfo
apiInfo
()
{
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
return
new
ApiInfoBuilder
()
.
title
(
"Chinafrica api文档"
)
.
title
(
"Chinafrica api文档"
)
.
version
(
"1.0"
)
.
description
(
"This is description"
)
//
.
version
(
"1.0.0"
)
//
.
license
(
"MIT License"
).
licenseUrl
(
"http://opensource.org/licenses/MIT"
)
//
.
contact
(
new
Contact
(
null
,
null
,
"xxxx@gmail.com"
))
//
.
build
();
.
build
();
}
}
...
...
src/main/java/com/diaoyun/zion/master/exception/ExceptionResolver.java
浏览文件 @
560aea49
...
@@ -20,7 +20,8 @@ import java.io.PrintWriter;
...
@@ -20,7 +20,8 @@ import java.io.PrintWriter;
*
*
* @author Joe
* @author Joe
*/
*/
@Component
(
"exceptionResolver"
)
//@Component("exceptionResolver")
@Deprecated
public
class
ExceptionResolver
implements
HandlerExceptionResolver
{
public
class
ExceptionResolver
implements
HandlerExceptionResolver
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
...
...
src/main/java/com/diaoyun/zion/master/exception/GlobalExceptionHandlerController.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
exception
;
import
com.alibaba.fastjson.JSON
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.web.servlet.error.DefaultErrorAttributes
;
import
org.springframework.boot.web.servlet.error.ErrorAttributes
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
org.springframework.web.context.request.WebRequest
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.Map
;
/**
*
*/
@RestControllerAdvice
public
class
GlobalExceptionHandlerController
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Bean
public
ErrorAttributes
errorAttributes
()
{
// Hide exception field in the return object
return
new
DefaultErrorAttributes
()
{
@Override
public
Map
<
String
,
Object
>
getErrorAttributes
(
WebRequest
requestAttributes
,
boolean
includeStackTrace
)
{
Map
<
String
,
Object
>
errorAttributes
=
super
.
getErrorAttributes
(
requestAttributes
,
includeStackTrace
);
errorAttributes
.
remove
(
"exception"
);
errorAttributes
.
put
(
"code"
,
errorAttributes
.
get
(
"status"
));
//处理403禁止访问
if
(
403
==(
int
)
errorAttributes
.
get
(
"status"
))
{
errorAttributes
.
put
(
"code"
,
ResultCodeEnum
.
NEED_LOGIN
.
getCode
());
errorAttributes
.
put
(
"message"
,
ResultCodeEnum
.
NEED_LOGIN
.
getDesc
());
}
return
errorAttributes
;
}
@Override
public
ModelAndView
resolveException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
exception
)
{
Result
result
;
if
(
exception
instanceof
ApplicationException
)
{
ApplicationException
ae
=
(
ApplicationException
)
exception
;
result
=
new
Result
(
ae
.
getCode
(),
ae
.
getMessage
());
}
else
{
result
=
new
Result
(
ResultCodeEnum
.
ERROR
.
getCode
(),
exception
.
getMessage
());
logger
.
error
(
exception
.
getMessage
(),
exception
);
}
response
.
setContentType
(
"application/json;charset=UTF-8"
);
response
.
setStatus
(
HttpStatus
.
OK
.
value
());
PrintWriter
writer
=
null
;
try
{
writer
=
response
.
getWriter
();
writer
.
write
(
JSON
.
toJSONString
(
result
));
}
catch
(
IOException
ie
)
{
logger
.
error
(
"Failed to serialize the object to json for exception resolver!"
,
ie
);
}
finally
{
writer
.
flush
();
writer
.
close
();
}
return
new
ModelAndView
();
}
};
}
/*@ExceptionHandler(ApplicationException.class)
public void handleCustomException(HttpServletResponse res, ApplicationException ex) throws IOException {
res.sendError(ex.getCode(), ex.getMessage());
}
@ExceptionHandler(AccessDeniedException.class)
public void handleAccessDeniedException(HttpServletResponse res,Exception ex) throws IOException {
res.sendError(HttpStatus.FORBIDDEN.value(), ex.getMessage());
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public void handleException(HttpServletResponse res,Exception ex) throws IOException {
res.sendError(HttpStatus.BAD_REQUEST.value(), ex.getMessage());
}*/
}
src/main/java/com/diaoyun/zion/master/security/JwtTokenFilter.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
security
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.exception.ApplicationException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
// We should use OncePerRequestFilter since we are doing a database call, there is no point in doing this more than once
public
class
JwtTokenFilter
extends
OncePerRequestFilter
{
private
JwtTokenProvider
jwtTokenProvider
;
public
JwtTokenFilter
(
JwtTokenProvider
jwtTokenProvider
)
{
this
.
jwtTokenProvider
=
jwtTokenProvider
;
}
@Override
protected
void
doFilterInternal
(
HttpServletRequest
httpServletRequest
,
HttpServletResponse
httpServletResponse
,
FilterChain
filterChain
)
throws
ServletException
,
IOException
{
String
token
=
jwtTokenProvider
.
resolveToken
(
httpServletRequest
);
try
{
if
(
token
!=
null
&&
jwtTokenProvider
.
validateToken
(
token
))
{
Authentication
auth
=
jwtTokenProvider
.
getAuthentication
(
token
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
auth
);
}
}
catch
(
ApplicationException
ex
)
{
//this is very important, since it guarantees the user is not authenticated at all
SecurityContextHolder
.
clearContext
();
httpServletResponse
.
sendError
(
ex
.
getCode
(),
ex
.
getMessage
());
return
;
}
filterChain
.
doFilter
(
httpServletRequest
,
httpServletResponse
);
}
}
src/main/java/com/diaoyun/zion/master/security/JwtTokenFilterConfigurer.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
security
;
import
org.springframework.security.config.annotation.SecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.web.DefaultSecurityFilterChain
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
public
class
JwtTokenFilterConfigurer
extends
SecurityConfigurerAdapter
<
DefaultSecurityFilterChain
,
HttpSecurity
>
{
private
JwtTokenProvider
jwtTokenProvider
;
public
JwtTokenFilterConfigurer
(
JwtTokenProvider
jwtTokenProvider
)
{
this
.
jwtTokenProvider
=
jwtTokenProvider
;
}
@Override
public
void
configure
(
HttpSecurity
http
)
throws
Exception
{
JwtTokenFilter
customFilter
=
new
JwtTokenFilter
(
jwtTokenProvider
);
http
.
addFilterBefore
(
customFilter
,
UsernamePasswordAuthenticationFilter
.
class
);
}
}
src/main/java/com/diaoyun/zion/master/security/JwtTokenProvider.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
security
;
import
com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo
;
import
com.diaoyun.zion.master.common.TokenManager
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.exception.ApplicationException
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.JwtException
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Base64
;
import
java.util.Date
;
@Component
public
class
JwtTokenProvider
{
/**
* THIS IS NOT A SECURE PRACTICE! For simplicity, we are storing a static key here. Ideally, in a
* microservices environment, this key would be kept on a config-server.
*/
@Value
(
"${security.jwt.token.secret-key:secret-key}"
)
private
String
secretKey
;
@Value
(
"${security.jwt.token.expire-length:3600000}"
)
private
long
validityInMilliseconds
=
3600000
;
// 1h
@Autowired
private
MyUserDetails
myUserDetails
;
@Resource
(
name
=
"redisTokenManager"
)
private
TokenManager
tokenManager
;
@PostConstruct
protected
void
init
()
{
secretKey
=
Base64
.
getEncoder
().
encodeToString
(
secretKey
.
getBytes
());
}
public
String
createToken
(
String
username
)
{
Claims
claims
=
Jwts
.
claims
().
setSubject
(
username
);
//claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
Date
now
=
new
Date
();
Date
validity
=
new
Date
(
now
.
getTime
()
+
validityInMilliseconds
);
return
Jwts
.
builder
()
//
.
setClaims
(
claims
)
//
.
setIssuedAt
(
now
)
//
.
setExpiration
(
validity
)
//
.
signWith
(
SignatureAlgorithm
.
HS256
,
secretKey
)
//
.
compact
();
}
public
Authentication
getAuthentication
(
String
token
)
{
UserDetails
userDetails
=
myUserDetails
.
loadUserByUsername
(
getUsername
(
token
));
return
new
UsernamePasswordAuthenticationToken
(
userDetails
,
""
,
userDetails
.
getAuthorities
());
}
public
String
getUsername
(
String
token
)
{
return
Jwts
.
parser
().
setSigningKey
(
secretKey
).
parseClaimsJws
(
token
).
getBody
().
getSubject
();
}
public
String
resolveToken
(
HttpServletRequest
req
)
{
String
bearerToken
=
req
.
getHeader
(
"Authorization"
);
if
(
bearerToken
!=
null
&&
bearerToken
.
startsWith
(
"Bearer "
))
{
return
bearerToken
.
substring
(
7
);
}
return
null
;
}
public
boolean
validateToken
(
String
token
)
{
try
{
Jwts
.
parser
().
setSigningKey
(
secretKey
).
parseClaimsJws
(
token
);
TbCfUserInfoVo
loginUser
=
tokenManager
.
validate
(
token
);
if
(
loginUser
==
null
)
{
throw
new
ApplicationException
(
ResultCodeEnum
.
NEED_LOGIN
.
getCode
(),
"Expired or invalid JWT token"
);
}
return
true
;
}
catch
(
JwtException
|
IllegalArgumentException
e
)
{
throw
new
ApplicationException
(
ResultCodeEnum
.
NEED_LOGIN
.
getCode
(),
"Expired or invalid JWT token"
);
}
}
}
src/main/java/com/diaoyun/zion/master/security/MyUserDetails.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
security
;
import
com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity
;
import
com.diaoyun.zion.chinafrica.service.impl.TbCfUserInfoServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
@Service
public
class
MyUserDetails
implements
UserDetailsService
{
@Autowired
private
TbCfUserInfoServiceImpl
tbCfUserInfoService
;
@Override
public
UserDetails
loadUserByUsername
(
String
username
)
throws
UsernameNotFoundException
{
final
TbCfUserInfoEntity
user
=
tbCfUserInfoService
.
findByAccount
(
username
);
if
(
user
==
null
)
{
throw
new
UsernameNotFoundException
(
"User '"
+
username
+
"' not found or disable"
);
}
return
org
.
springframework
.
security
.
core
.
userdetails
.
User
//
.
withUsername
(
username
)
//
.
password
(
user
.
getPassword
())
//
.
authorities
(
"ROLE_ADMIN"
)
//
.
accountExpired
(
false
)
//
.
accountLocked
(
false
)
//
.
credentialsExpired
(
false
)
//
.
disabled
(
false
)
//
.
build
();
}
}
src/main/java/com/diaoyun/zion/master/security/WebSecurityConfig.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
security
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.WebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.http.SessionCreationPolicy
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
WebSecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Autowired
private
JwtTokenProvider
jwtTokenProvider
;
@Override
@Bean
public
AuthenticationManager
authenticationManagerBean
()
throws
Exception
{
return
super
.
authenticationManagerBean
();
}
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
// Disable CSRF (cross site request forgery)
http
.
csrf
().
disable
();
// No session will be created or used by spring security
http
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
);
// Entry points
http
.
authorizeRequests
()
//
/*.antMatchers("/spider/**").permitAll()//
.antMatchers("/platform/**").permitAll()//
.antMatchers("/itemStation/**").permitAll()//
.antMatchers("/login/**").permitAll()//
.antMatchers("/problem/**").permitAll()//
.antMatchers("/contact/**").permitAll()//
.antMatchers("/page/**").permitAll()//
.antMatchers("/css/**").permitAll()//
.antMatchers("/js/**").permitAll()//
.antMatchers("/user/register/identifyCode/**").permitAll()//*/
//.antMatchers("/h2-console/**/**").permitAll()//
.
antMatchers
(
"/**/**"
).
permitAll
()
//
// Disallow everything else..
.
anyRequest
().
authenticated
();
// If a user try to access a resource without having enough permissions
http
.
exceptionHandling
().
accessDeniedPage
(
"/login"
);
// Apply JWT
http
.
apply
(
new
JwtTokenFilterConfigurer
(
jwtTokenProvider
));
// Optional, if you want to test the API from a browser
// http.httpBasic();
}
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
// Allow swagger to be accessed without authentication
web
.
ignoring
().
antMatchers
(
"/v2/api-docs"
)
//
.
antMatchers
(
"/swagger-resources/**"
)
//
.
antMatchers
(
"/swagger-ui.html"
)
//
.
antMatchers
(
"/configuration/**"
)
//
.
antMatchers
(
"/webjars/**"
)
//
.
antMatchers
(
"/public"
)
// Un-secure H2 Database (for testing purposes, H2 console shouldn't be unprotected in production)
.
and
()
.
ignoring
()
.
antMatchers
(
"/h2-console/**/**"
);;
}
@Bean
public
PasswordEncoder
passwordEncoder
()
{
return
new
BCryptPasswordEncoder
(
12
);
}
}
src/main/java/com/diaoyun/zion/master/util/CookieUtils.java
deleted
100644 → 0
浏览文件 @
b9458b12
package
com
.
diaoyun
.
zion
.
master
.
util
;
import
org.apache.commons.lang3.StringUtils
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* cookie操作工具
*
* @author Joe
*/
public
class
CookieUtils
{
private
CookieUtils
()
{
}
/**
* 按名称获取cookie
*
* @param request
* @param name
* @return
*/
public
static
String
getCookie
(
HttpServletRequest
request
,
String
name
)
{
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
==
null
||
StringUtils
.
isBlank
(
name
))
{
return
null
;
}
for
(
Cookie
cookie
:
cookies
)
{
if
(
name
.
equals
(
cookie
.
getName
()))
{
return
cookie
.
getValue
();
}
}
return
null
;
}
/**
* 清除cookie
* @param response
* @param name
* @param path
* @param domain
*/
public
static
void
removeCookie
(
HttpServletResponse
response
,
String
name
,
String
path
,
String
domain
)
{
Cookie
cookie
=
new
Cookie
(
name
,
null
);
if
(
path
!=
null
)
{
cookie
.
setPath
(
path
);
}
if
(
domain
!=
null
)
{
cookie
.
setDomain
(
domain
);
}
cookie
.
setMaxAge
(
0
);
response
.
addCookie
(
cookie
);
}
}
src/main/java/com/diaoyun/zion/master/util/GsonUtil.java
0 → 100644
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
.
master
.
util
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.reflect.TypeToken
;
import
java.util.List
;
import
java.util.Map
;
public
class
GsonUtil
{
//不用创建对象,直接使用Gson.就可以调用方法
private
static
Gson
gson
=
null
;
//判断gson对象是否存在了,不存在则创建对象
static
{
if
(
gson
==
null
)
{
//gson = new Gson(); //当使用GsonBuilder方式时属性为空的时候输出来的json字符串是有键值key的,显示形式是"key":null,而直接new出来的就没有"key":null的
gson
=
new
GsonBuilder
().
setDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
create
();
}
}
//无参的私有构造方法
private
GsonUtil
()
{
}
/**
* 将对象转成json格式
*
* @param object
* @return String
*/
public
static
String
GsonString
(
Object
object
)
{
String
gsonString
=
null
;
if
(
gson
!=
null
)
{
gsonString
=
gson
.
toJson
(
object
);
}
return
gsonString
;
}
/**
* 将json转成特定的cls的对象
*
* @param gsonString
* @param cls
* @return
*/
public
static
<
T
>
T
GsonToBean
(
String
gsonString
,
Class
<
T
>
cls
)
{
T
t
=
null
;
if
(
gson
!=
null
)
{
//传入json对象和对象类型,将json转成对象
t
=
gson
.
fromJson
(
gsonString
,
cls
);
}
return
t
;
}
/**
* json字符串转成list
*
* @param gsonString
* @param cls
* @return
*/
public
static
<
T
>
List
<
T
>
GsonToList
(
String
gsonString
,
Class
<
T
>
cls
)
{
List
<
T
>
list
=
null
;
if
(
gson
!=
null
)
{
//根据泛型返回解析指定的类型,TypeToken<List<T>>{}.getType()获取返回类型
list
=
gson
.
fromJson
(
gsonString
,
new
TypeToken
<
List
<
T
>>()
{
}.
getType
());
}
return
list
;
}
/**
* json字符串转成list中有map的
*
* @param gsonString
* @return
*/
public
static
<
T
>
List
<
Map
<
String
,
T
>>
GsonToListMaps
(
String
gsonString
)
{
List
<
Map
<
String
,
T
>>
list
=
null
;
if
(
gson
!=
null
)
{
list
=
gson
.
fromJson
(
gsonString
,
new
TypeToken
<
List
<
Map
<
String
,
T
>>>()
{
}.
getType
());
}
return
list
;
}
/**
* json字符串转成map的
*
* @param gsonString
* @return
*/
public
static
<
T
>
Map
<
String
,
T
>
GsonToMaps
(
String
gsonString
)
{
Map
<
String
,
T
>
map
=
null
;
if
(
gson
!=
null
)
{
map
=
gson
.
fromJson
(
gsonString
,
new
TypeToken
<
Map
<
String
,
T
>>()
{
}.
getType
());
}
return
map
;
}
}
src/main/java/com/diaoyun/zion/master/util/HttpClientUtil.java
浏览文件 @
560aea49
...
@@ -2,7 +2,6 @@ package com.diaoyun.zion.master.util;
...
@@ -2,7 +2,6 @@ package com.diaoyun.zion.master.util;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
net.sf.json.JSONObject
;
import
org.apache.http.*
;
import
org.apache.http.*
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
...
@@ -11,6 +10,8 @@ import org.apache.http.client.methods.HttpUriRequest;
...
@@ -11,6 +10,8 @@ import org.apache.http.client.methods.HttpUriRequest;
import
org.apache.http.client.methods.RequestBuilder
;
import
org.apache.http.client.methods.RequestBuilder
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.client.utils.URLEncodedUtils
;
import
org.apache.http.client.utils.URLEncodedUtils
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.BasicCookieStore
;
import
org.apache.http.impl.client.BasicCookieStore
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.client.HttpClients
;
...
@@ -208,18 +209,20 @@ public class HttpClientUtil {
...
@@ -208,18 +209,20 @@ public class HttpClientUtil {
}
}
/**
/**
*
获取商品物流信息 TODO 还需验证
*
发送带body参数的post请求
* @param url
* @param url
* @param paramMap
* @param paramMap
* @return
* @return
* @throws URISyntaxException
* @throws URISyntaxException
* @throws IOException
* @throws IOException
*/
*/
public
static
String
getItemTrack
(
String
url
,
Map
<
String
,
Object
>
paramMap
)
throws
URISyntaxException
,
IOException
{
public
static
String
sendPostWithBodyParameter
(
String
url
,
Map
<
String
,
Object
>
paramMap
)
throws
IOException
{
List
<
NameValuePair
>
formparams
=
setHttpParams
(
paramMap
);
String
param
=
URLEncodedUtils
.
format
(
formparams
,
Consts
.
UTF_8
.
name
());
HttpPost
httpPost
=
new
HttpPost
();
//构建一个Post请求
HttpPost
httpPost
=
new
HttpPost
();
//构建一个Post请求
httpPost
.
setURI
(
URI
.
create
(
url
+
"?"
+
param
));
httpPost
.
setURI
(
URI
.
create
(
url
));
httpPost
.
setHeader
(
"Content-Type"
,
"application/json"
);
//放参数
StringEntity
entity
=
new
StringEntity
(
GsonUtil
.
GsonString
(
paramMap
),
ContentType
.
APPLICATION_JSON
);
httpPost
.
setEntity
(
entity
);
//构造自定义的HttpClient对象
//构造自定义的HttpClient对象
CloseableHttpClient
sibClient
=
HttpClients
.
custom
().
build
();
CloseableHttpClient
sibClient
=
HttpClients
.
custom
().
build
();
//执行请求,传入HttpContext,将会得到请求结果的信息
//执行请求,传入HttpContext,将会得到请求结果的信息
...
...
src/main/java/com/diaoyun/zion/master/util/PasswordProvider.java
浏览文件 @
560aea49
...
@@ -13,6 +13,7 @@ import java.security.NoSuchAlgorithmException;
...
@@ -13,6 +13,7 @@ import java.security.NoSuchAlgorithmException;
*
*
* @author Joe
* @author Joe
*/
*/
@Deprecated
public
class
PasswordProvider
{
public
class
PasswordProvider
{
private
static
final
String
SUFFIX
=
"`1qazx"
;
private
static
final
String
SUFFIX
=
"`1qazx"
;
...
...
src/main/resources/application.properties
deleted
100644 → 0
浏览文件 @
b9458b12
src/main/resources/application.yml
浏览文件 @
560aea49
...
@@ -94,5 +94,11 @@ spring:
...
@@ -94,5 +94,11 @@ spring:
# 配置StatFilter
# 配置StatFilter
filter
:
filter
:
stat
:
stat
:
log-slow-sql
:
true
log-slow-sql
:
true
security
:
jwt
:
token
:
secret-key
:
secret-key
expire-length
:
604800000
# one week or 300000 5 minutes duration by default: 5 minutes * 60 seconds * 1000 miliseconds
src/main/resources/mapper/TbCfFinanceDao.xml
浏览文件 @
560aea49
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
<result
property=
"payId"
column=
"pay_id"
/>
<result
property=
"payId"
column=
"pay_id"
/>
<result
property=
"payWayCode"
column=
"pay_way_code"
/>
<result
property=
"payWayCode"
column=
"pay_way_code"
/>
<result
property=
"payTime"
column=
"pay_Time"
/>
<result
property=
"payTime"
column=
"pay_Time"
/>
<result
property=
"receiptUrl"
column=
"receipt_url"
/>
</resultMap>
</resultMap>
<select
id=
"queryObject"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity"
>
<select
id=
"queryObject"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity"
>
...
@@ -21,7 +22,8 @@
...
@@ -21,7 +22,8 @@
`pay_account`,
`pay_account`,
`pay_id`,
`pay_id`,
`pay_way_code`,
`pay_way_code`,
`pay_Time`
`pay_Time`,
`receipt_url`
from tb_cf_finance
from tb_cf_finance
where finace_id = #{id}
where finace_id = #{id}
</select>
</select>
...
@@ -34,7 +36,8 @@
...
@@ -34,7 +36,8 @@
`pay_account`,
`pay_account`,
`pay_id`,
`pay_id`,
`pay_way_code`,
`pay_way_code`,
`pay_Time`
`pay_Time`,
`receipt_url`
from tb_cf_finance
from tb_cf_finance
WHERE 1=1
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
<if
test=
"name != null and name.trim() != ''"
>
...
@@ -69,7 +72,8 @@
...
@@ -69,7 +72,8 @@
`pay_account`,
`pay_account`,
`pay_id`,
`pay_id`,
`pay_way_code`,
`pay_way_code`,
`pay_Time`)
`pay_Time`,
`receipt_url`)
values(
values(
#{finaceId},
#{finaceId},
#{orderId},
#{orderId},
...
@@ -77,7 +81,8 @@
...
@@ -77,7 +81,8 @@
#{payAccount},
#{payAccount},
#{payId},
#{payId},
#{payWayCode},
#{payWayCode},
#{payTime})
#{payTime},
#{receiptUrl})
</insert>
</insert>
<update
id=
"update"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity"
>
<update
id=
"update"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfFinanceEntity"
>
...
@@ -89,6 +94,7 @@
...
@@ -89,6 +94,7 @@
<if
test=
"payId != null"
>
`pay_id` = #{payId},
</if>
<if
test=
"payId != null"
>
`pay_id` = #{payId},
</if>
<if
test=
"payWayCode != null"
>
`pay_way_code` = #{payWayCode},
</if>
<if
test=
"payWayCode != null"
>
`pay_way_code` = #{payWayCode},
</if>
<if
test=
"payTime != null"
>
`pay_Time` = #{payTime}
</if>
<if
test=
"payTime != null"
>
`pay_Time` = #{payTime}
</if>
<if
test=
"receiptUrl != null"
>
`receipt_url` = #{receiptUrl}
</if>
</set>
</set>
where finace_id = #{finaceId}
where finace_id = #{finaceId}
</update>
</update>
...
...
src/main/resources/mapper/TbCfOrderDao.xml
浏览文件 @
560aea49
...
@@ -235,4 +235,18 @@
...
@@ -235,4 +235,18 @@
and t1.enable_flag=1 and t2.item_id=t1.item_id
and t1.enable_flag=1 and t2.item_id=t1.item_id
</select>
</select>
<!--获取付款订单-->
<select
id=
"getOrderListByTime"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfOrderEntity"
>
select user_id,order_id,deal_time from tb_cf_order where pay_status=20 and
deal_time
<![CDATA[ >= ]]>
#{beginDate} and deal_time
<![CDATA[ < ]]>
#{endDate}
</select>
<!--获取某段时间已发货订单数据-->
<select
id=
"getDeliveryList"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemShippedEntity"
>
select t1.user_id,t1.order_id,t2.create_time "deliveryTime",t1.delivery_address,
t2.p_express_number "expressId" from tb_cf_order t1,tb_cf_platform_order t2 where t1.pay_status=40
and t1.order_id=t2.order_id
and t2.create_time
<![CDATA[ >= ]]>
#{beginDate} and t2.create_time
<![CDATA[ < ]]>
#{endDate}
</select>
</mapper>
</mapper>
\ No newline at end of file
src/main/resources/mapper/TbCfUserInfoDao.xml
浏览文件 @
560aea49
...
@@ -188,9 +188,10 @@
...
@@ -188,9 +188,10 @@
select * from tb_cf_user_info where nickname=#{nickname}
select * from tb_cf_user_info where nickname=#{nickname}
</select>
</select>
<!--根据userId 账号
手机
email nick 查找用户-->
<!--根据userId 账号 email nick 查找用户-->
<select
id=
"findByAccount"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity"
>
<select
id=
"findByAccount"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity"
>
select * from tb_cf_user_info where user_id=#{userId} or account=#{account} or phone=#{account} or email =#{account} or nick =#{account};
select * from tb_cf_user_info where enable_flag=1 and user_id=#{userId} or account=#{account}
or email =#{account} or nick =#{account};
</select>
</select>
<!--修改密码-->
<!--修改密码-->
...
...
src/main/resources/properties/domain.properties
浏览文件 @
560aea49
...
@@ -35,7 +35,16 @@ tencent.wordpos.app_url=https://api.ai.qq.com/fcgi-bin/nlp/nlp_wordpos
...
@@ -35,7 +35,16 @@ tencent.wordpos.app_url=https://api.ai.qq.com/fcgi-bin/nlp/nlp_wordpos
################腾讯翻译配置 END###################
################腾讯翻译配置 END###################
##################stripe公钥(不加密)和私钥(已加密)################################
##################stripe公钥(不加密)和私钥(已用 AESUtils 加密)################################
stripe.pk
=
pk_test_uljWJWUuD8fzZXPlGtDZ1fxx00o1ZKr7QL
stripe.pk
=
pk_test_rXUSgU8Kw7DLhDzMbHM0r55O00JAzVBBJR
stripe.sk
=
BbLXgo+ohgrAP7p3tB52YTqNwhAiTYzYWAX0W+/1PES6kOupxwc/7xpAR8QsG6gP
stripe.sk
=
3ff57yz9S5INBexBOnzi/ZaxClXkXlJ+FZ6XLc/f2vpESScG7YOaQaG2YNRic3HF
######################outlook的账户公钥密钥#####################
#stripe.pk=pk_test_uljWJWUuD8fzZXPlGtDZ1fxx00o1ZKr7QL
#stripe.sk=BbLXgo+ohgrAP7p3tB52YTqNwhAiTYzYWAX0W+/1PES6kOupxwc/7xpAR8QsG6gP
######################outlook的账户公钥密钥 END#####################
##################stripe公钥和私钥 END###############################
##################stripe公钥和私钥 END###############################
#############################第三方物流公司接口#################################
express.info.api
=
http://shd.kjwlxt.com/api/track.php
express.info.user_no
=
shd806
express.info.token
=
d44426bd5b64dd2
######################################################################
src/main/resources/static/js/angularjs/js/login/LoginController.js
浏览文件 @
560aea49
...
@@ -85,14 +85,14 @@ loginApp.controller('loginController', function ($scope, $q, $http) {
...
@@ -85,14 +85,14 @@ loginApp.controller('loginController', function ($scope, $q, $http) {
var
handler
=
function
(
d
)
{
var
handler
=
function
(
d
)
{
console
.
log
(
d
);
console
.
log
(
d
);
}
}
/*
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest();
var url = 'https://africa.gzdazt.com/zion/login';//?account=1244612031@qq.com&password=123456
var url = 'https://africa.gzdazt.com/zion/login';//?account=1244612031@qq.com&password=123456
xhr.open('POST', url, true);
xhr.open('POST', url, true);
xhr.withCredentials = true;
xhr.withCredentials = true;
xhr.onreadystatechange = handler;
xhr.onreadystatechange = handler;
xhr
.
send
();
xhr.send();
*/
/*var dataParam ={
/*var dataParam ={
targetUrl:"https://h5.m.taobao.com/awp/core/detail.htm?spm=a2141.9304519.0.0&id=9679381011&pvid=9e42d83a-82c7-43ac-a89f-199a74d48c2f&scene=3489&scm=1007.13489.98648.tab%3A0_id%3A9679381011_reason%3Ashoal_ranklist_rn%3A9e42d83a-82c7-43ac-a89f-199a74d48c2f"
targetUrl:"https://h5.m.taobao.com/awp/core/detail.htm?spm=a2141.9304519.0.0&id=9679381011&pvid=9e42d83a-82c7-43ac-a89f-199a74d48c2f&scene=3489&scm=1007.13489.98648.tab%3A0_id%3A9679381011_reason%3Ashoal_ranklist_rn%3A9e42d83a-82c7-43ac-a89f-199a74d48c2f"
...
@@ -119,13 +119,13 @@ loginApp.controller('loginController', function ($scope, $q, $http) {
...
@@ -119,13 +119,13 @@ loginApp.controller('loginController', function ($scope, $q, $http) {
}
}
})*/
})*/
/*
var xhr = new XMLHttpRequest();
var
xhr
=
new
XMLHttpRequest
();
var url = '
http://159.138.33.0/zion/address/default/1c0dd6fcefb64b4ebe5febb8e42adfc0
';
var
url
=
'
https://africa.gzdazt.com/zion/user/register/identifyCode/1262837396@qq.com/123456
'
;
xhr
.
open
(
'PUT'
,
url
,
true
);
xhr
.
open
(
'PUT'
,
url
,
true
);
xhr
.
withCredentials
=
true
;
xhr
.
withCredentials
=
true
;
xhr
.
onreadystatechange
=
handler
;
xhr
.
onreadystatechange
=
handler
;
xhr.send();
*/
xhr
.
send
();
...
...
src/test/java/com/diaoyun/zion/ZionApplicationTests.java
浏览文件 @
560aea49
package
com
.
diaoyun
.
zion
;
package
com
.
diaoyun
.
zion
;
import
com.diaoyun.zion.chinafrica.constant.KeyConstant
;
import
com.diaoyun.zion.chinafrica.service.SpiderService
;
import
com.diaoyun.zion.chinafrica.service.SpiderService
;
import
com.diaoyun.zion.chinafrica.service.TbCfCouponService
;
import
com.diaoyun.zion.chinafrica.service.TbCfCouponService
;
import
com.diaoyun.zion.chinafrica.service.impl.TbCfOrderServiceImpl
;
import
com.diaoyun.zion.chinafrica.service.impl.TbCfOrderServiceImpl
;
import
com.diaoyun.zion.master.thread.TaskLimitSemaphore
;
import
com.diaoyun.zion.master.thread.TaskLimitSemaphore
;
import
com.diaoyun.zion.master.util.AESUtils
;
import
com.diaoyun.zion.master.util.GsonUtil
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.WordposHelper
;
import
com.diaoyun.zion.master.util.WordposHelper
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.stripe.exception.StripeException
;
import
com.stripe.exception.StripeException
;
...
@@ -283,14 +287,23 @@ public class ZionApplicationTests {
...
@@ -283,14 +287,23 @@ public class ZionApplicationTests {
}*/
}*/
/*分词 END*****************8***/
/*分词 END*****************8***/
/*String url="http://shd.kjwlxt.com/api/track.php";
Map<String,Object> paramMap= new HashMap<>();
List<Map<String,String>> data=new ArrayList<>();
Map<String,String> dataMap=new HashMap<>();
dataMap.put("order_no","ceshi20190917");
data.add(dataMap);
paramMap.put("user_no","shd806");
paramMap.put("token","d44426bd5b64dd2");
paramMap.put("data",data);
String res=HttpClientUtil.sendPostWithBodyParameter(url,paramMap);
Map map=GsonUtil.GsonToMaps(res);*/
String
a
=
"sk_test_yHGCVyKVI0soO8UQR9oivpB200s0lHEOFy"
;
String
b
=
AESUtils
.
encrypt
(
KeyConstant
.
AES_KEY
,
a
);
System
.
out
.
println
(
b
);
List
<
String
>
cartRecordIdArray
=
new
ArrayList
<>();
cartRecordIdArray
.
add
(
"a"
);
cartRecordIdArray
.
add
(
"b"
);
cartRecordIdArray
.
add
(
"c"
);
cartRecordIdArray
.
add
(
"d"
);
String
[]
cartRecordIds
=
cartRecordIdArray
.
toArray
(
new
String
[
0
]);
System
.
out
.
println
(
cartRecordIds
[
0
]+
cartRecordIds
[
1
]+
cartRecordIds
[
2
]+
cartRecordIds
[
3
]);
}
}
/*private void translateProp(Map<String, Object> propMap) throws ExecutionException, InterruptedException {
/*private void translateProp(Map<String, Object> propMap) throws ExecutionException, InterruptedException {
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论