Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
f4b8c777
提交
f4b8c777
authored
1月 14, 2020
作者:
luojie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改商品加购物车
上级
584f4b14
隐藏空白字符变更
内嵌
并排
正在显示
20 个修改的文件
包含
607 行增加
和
186 行删除
+607
-186
TbCfItemDetailController.java
.../zion/chinafrica/controller/TbCfItemDetailController.java
+2
-1
TbCfCartRecordRDao.java
...a/com/diaoyun/zion/chinafrica/dao/TbCfCartRecordRDao.java
+5
-2
TbCfExchangeDao.java
...java/com/diaoyun/zion/chinafrica/dao/TbCfExchangeDao.java
+3
-0
TbCfItemDetailDao.java
...va/com/diaoyun/zion/chinafrica/dao/TbCfItemDetailDao.java
+1
-0
OrderEntity.java
.../java/com/diaoyun/zion/chinafrica/entity/OrderEntity.java
+12
-0
TbCfExchangeService.java
.../diaoyun/zion/chinafrica/service/TbCfExchangeService.java
+3
-0
TbCfItemDetailService.java
...iaoyun/zion/chinafrica/service/TbCfItemDetailService.java
+1
-0
TbCfExchangeServiceImpl.java
...zion/chinafrica/service/impl/TbCfExchangeServiceImpl.java
+6
-0
TbCfItemDetailServiceImpl.java
...on/chinafrica/service/impl/TbCfItemDetailServiceImpl.java
+40
-21
TbCfOrderServiceImpl.java
...un/zion/chinafrica/service/impl/TbCfOrderServiceImpl.java
+1
-0
TbCfUserInfoServiceImpl.java
...zion/chinafrica/service/impl/TbCfUserInfoServiceImpl.java
+1
-1
DcloudDto.java
src/main/java/com/diaoyun/zion/master/entity/DcloudDto.java
+220
-0
QuartzMethod.java
...ain/java/com/diaoyun/zion/master/quartz/QuartzMethod.java
+1
-3
RentUtil.java
src/main/java/com/diaoyun/zion/master/util/RentUtil.java
+0
-20
SpiderUtil.java
src/main/java/com/diaoyun/zion/master/util/SpiderUtil.java
+32
-3
TbCfCartRecordRDao.xml
src/main/resources/mapper/TbCfCartRecordRDao.xml
+38
-18
TbCfExchangeDao.xml
src/main/resources/mapper/TbCfExchangeDao.xml
+4
-0
TbCfItemDetailDao.xml
src/main/resources/mapper/TbCfItemDetailDao.xml
+117
-103
TbCfOrderDao.xml
src/main/resources/mapper/TbCfOrderDao.xml
+2
-1
Test.java
src/test/java/com/diaoyun/zion/Test.java
+118
-13
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/controller/TbCfItemDetailController.java
浏览文件 @
f4b8c777
...
...
@@ -34,12 +34,13 @@ public class TbCfItemDetailController {
private
TbCfCartRecordRService
tbCfCartRecordRService
;
@ApiOperation
(
"加入到购物车"
)
@ApiOperation
(
"
爬虫数据
加入到购物车"
)
@PostMapping
(
"/cart"
)
public
Result
addToCart
(
@ApiParam
(
"商品详情"
)
@RequestBody
TbCfItemDetailVo
tbCfItemDetailVo
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
return
tbCfItemDetailService
.
addToCart
(
tbCfItemDetailVo
);
}
@ApiOperation
(
"改变购物车的商品勾选状态"
)
@PutMapping
(
"/state/{cartRecordId}/{checkFlag}"
)
public
Result
changeItemState
(
@ApiParam
(
"购物车记录id"
)
@PathVariable
(
"cartRecordId"
)
String
cartRecordId
,
...
...
src/main/java/com/diaoyun/zion/chinafrica/dao/TbCfCartRecordRDao.java
浏览文件 @
f4b8c777
...
...
@@ -22,7 +22,10 @@ public interface TbCfCartRecordRDao extends BaseDao<TbCfCartRecordREntity> {
*/
int
deleteItems
(
String
[]
cartRecordIds
);
TbCfCartRecordREntity
queryByItemId
(
String
itemId
);
TbCfCartRecordREntity
queryByItemId
(
@Param
(
"itemId"
)
String
itemId
,
@Param
(
"userId"
)
String
userId
,
@Param
(
"itemSku"
)
String
itemSku
);
TbCfCartRecordREntity
querySkuAndUrl
(
@Param
(
"itemSku"
)
String
itemSku
,
@Param
(
"itemId"
)
String
itemId
,
@Param
(
"sourceItemId"
)
String
sourceItemId
,
@Param
(
"userId"
)
String
userId
);
int
queryItemNum
(
String
userId
);
TbCfCartRecordREntity
querySkuAndUrl
(
@Param
(
"itemSku"
)
String
itemSku
,
@Param
(
"sourceItemId"
)
String
sourceItemId
);
}
src/main/java/com/diaoyun/zion/chinafrica/dao/TbCfExchangeDao.java
浏览文件 @
f4b8c777
...
...
@@ -2,6 +2,7 @@ package com.diaoyun.zion.chinafrica.dao;
import
com.diaoyun.zion.chinafrica.entity.TbCfExchangeEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity
;
import
com.diaoyun.zion.master.dao.BaseDao
;
import
java.math.BigDecimal
;
...
...
@@ -15,4 +16,6 @@ import java.math.BigDecimal;
public
interface
TbCfExchangeDao
extends
BaseDao
<
TbCfExchangeEntity
>
{
void
updateByType
(
String
type
,
BigDecimal
rate
);
TbCfExchangeEntity
getRateFee
(
String
exchangeCurrency
);
}
src/main/java/com/diaoyun/zion/chinafrica/dao/TbCfItemDetailDao.java
浏览文件 @
f4b8c777
...
...
@@ -33,5 +33,6 @@ public interface TbCfItemDetailDao extends BaseDao<TbCfItemDetailEntity> {
*/
int
changeItemState
(
String
cartRecordId
,
Integer
checkFlag
);
int
queryItemNum
(
String
userId
);
int
changeState
(
@Param
(
"ids"
)
String
[]
ids
,
@Param
(
"checkFlag"
)
String
checkFlag
);
}
src/main/java/com/diaoyun/zion/chinafrica/entity/OrderEntity.java
浏览文件 @
f4b8c777
...
...
@@ -33,6 +33,10 @@ public class OrderEntity implements Serializable {
* 收货人手机
*/
private
String
deliveryPhone
;
/**
* 订单备注
*/
private
String
remarkInfo
;
/**
* 商品明细集合
*/
...
...
@@ -94,4 +98,12 @@ public class OrderEntity implements Serializable {
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
public
String
getRemarkInfo
()
{
return
remarkInfo
;
}
public
void
setRemarkInfo
(
String
remarkInfo
)
{
this
.
remarkInfo
=
remarkInfo
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/TbCfExchangeService.java
浏览文件 @
f4b8c777
...
...
@@ -2,6 +2,7 @@ package com.diaoyun.zion.chinafrica.service;
import
com.diaoyun.zion.chinafrica.entity.TbCfExchangeEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity
;
import
java.math.BigDecimal
;
import
java.util.List
;
...
...
@@ -72,4 +73,6 @@ public interface TbCfExchangeService {
int
deleteBatch
(
String
[]
ids
);
void
updateByType
(
String
type
,
BigDecimal
rate
);
TbCfExchangeEntity
getRateFee
(
String
exchangeCurrency
);
}
src/main/java/com/diaoyun/zion/chinafrica/service/TbCfItemDetailService.java
浏览文件 @
f4b8c777
...
...
@@ -104,4 +104,5 @@ public interface TbCfItemDetailService {
* @return
*/
Result
changeItemState
(
String
cartRecordId
,
Integer
enableFlag
);
}
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfExchangeServiceImpl.java
浏览文件 @
f4b8c777
...
...
@@ -3,6 +3,7 @@ package com.diaoyun.zion.chinafrica.service.impl;
import
com.diaoyun.zion.chinafrica.dao.TbCfExchangeDao
;
import
com.diaoyun.zion.chinafrica.entity.TbCfExchangeEntity
;
import
com.diaoyun.zion.chinafrica.entity.TbCfFeeEntity
;
import
com.diaoyun.zion.chinafrica.service.TbCfExchangeService
;
import
com.diaoyun.zion.master.util.IdUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -69,4 +70,9 @@ public class TbCfExchangeServiceImpl implements TbCfExchangeService {
tbCfExchangeDao
.
updateByType
(
type
,
rate
);
}
@Override
public
TbCfExchangeEntity
getRateFee
(
String
exchangeCurrency
)
{
return
tbCfExchangeDao
.
getRateFee
(
exchangeCurrency
);
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfItemDetailServiceImpl.java
浏览文件 @
f4b8c777
...
...
@@ -21,6 +21,7 @@ import com.diaoyun.zion.master.util.ValidateUtils;
import
com.diaoyun.zion.master.util.WordposHelper
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.logging.log4j.spi.LoggerRegistry
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -99,6 +100,11 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
public
Result
addToCart
(
TbCfItemDetailVo
tbCfItemDetailVo
)
throws
InterruptedException
,
ExecutionException
,
TimeoutException
{
String
token
=
jwtTokenProvider
.
resolveToken
(
request
);
TbCfUserInfoVo
tbCfUserInfoVo
=
tokenManager
.
validate
(
token
);
int
itemCount
=
tbCfItemDetailDao
.
queryItemNum
(
tbCfUserInfoVo
.
getUserId
());
System
.
out
.
println
(
itemCount
);
if
(
itemCount
>=
99
){
return
new
Result
(
ResultCodeEnum
.
ERROR
.
getCode
()).
setMessage
(
"The shopping cart is full and needs to be cleaned!"
);
}
boolean
flag
=
false
;
if
(
tbCfItemDetailVo
.
getItemPrice
()
!=
null
)
{
int
compare
=
tbCfItemDetailVo
.
getItemPrice
().
compareTo
(
BigDecimal
.
ZERO
);
...
...
@@ -108,14 +114,26 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
}
if
(
flag
)
{
//填充新商品必要信息
TbCfCartRecordREntity
tbCfCartRecord
=
tbCfCartRecordRDao
.
querySkuAndUrl
(
tbCfItemDetailVo
.
getItemSku
(),
tbCfItemDetailVo
.
getSourceItemId
());
if
(
tbCfCartRecord
!=
null
)
{
tbCfItemDetailVo
.
setItemId
(
tbCfCartRecord
.
getItemId
());
tbCfItemDetailVo
.
setItemNum
(
tbCfCartRecord
.
getItemNum
()
+
tbCfItemDetailVo
.
getItemNum
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
else
{
tbCfItemDetailVo
.
setItemId
(
IdUtil
.
createIdbyUUID
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
TbCfCartRecordREntity
tbCfCartRecord
=
tbCfCartRecordRDao
.
querySkuAndUrl
(
tbCfItemDetailVo
.
getItemSku
(),
tbCfItemDetailVo
.
getItemId
(),
tbCfItemDetailVo
.
getSourceItemId
(),
tbCfUserInfoVo
.
getUserId
());
if
(
tbCfItemDetailVo
.
getSourceItemId
().
equals
(
"www.afrieshop.com"
))
{
if
(
tbCfCartRecord
!=
null
)
{
tbCfItemDetailVo
.
setItemId
(
tbCfCartRecord
.
getItemId
());
tbCfItemDetailVo
.
setItemNum
(
tbCfCartRecord
.
getItemNum
()
+
tbCfItemDetailVo
.
getItemNum
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
else
{
tbCfItemDetailVo
.
setItemId
(
tbCfItemDetailVo
.
getItemId
());
tbCfItemDetailVo
.
setItemNum
(
tbCfItemDetailVo
.
getItemNum
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
}
else
{
if
(
tbCfCartRecord
!=
null
)
{
tbCfItemDetailVo
.
setItemId
(
tbCfCartRecord
.
getItemId
());
tbCfItemDetailVo
.
setItemNum
(
tbCfCartRecord
.
getItemNum
()
+
tbCfItemDetailVo
.
getItemNum
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
else
{
tbCfItemDetailVo
.
setItemId
(
IdUtil
.
createIdbyUUID
());
tbCfItemDetailVo
.
setCreateTime
(
new
Date
());
}
}
//为商品分类,后面计算运费
TbCfExpressTemplateEntity
expressTemplate
=
recognizeItemCategory
(
tbCfItemDetailVo
.
getItemTitle
());
...
...
@@ -124,31 +142,32 @@ public class TbCfItemDetailServiceImpl implements TbCfItemDetailService {
TbCfItemDetailEntity
tbCfItemDetail
=
new
TbCfItemDetailEntity
();
BeanUtils
.
copyProperties
(
tbCfItemDetailVo
,
tbCfItemDetail
);
//将商品加入购物车表
TbCfCartRecordREntity
tbCfCartRecordREntity1
=
tbCfCartRecordRDao
.
queryByItemId
(
tbCfItemDetailVo
.
getItemId
());
if
(
tbCfCartRecordREntity1
==
null
)
{
tbCfItemDetailDao
.
save
(
tbCfItemDetail
);
TbCfCartRecordREntity
tbCfCartRecordREntity1
=
tbCfCartRecordRDao
.
queryByItemId
(
tbCfItemDetailVo
.
getItemId
(),
tbCfUserInfoVo
.
getUserId
(),
tbCfItemDetailVo
.
getItemSku
());
if
(
tbCfCartRecordREntity1
!=
null
)
{
TbCfCartRecordREntity
tbCfCartRecordREntity
=
new
TbCfCartRecordREntity
();
tbCfCartRecordREntity
.
setCartRecordId
(
IdUtil
.
createIdbyUUID
());
tbCfCartRecordREntity
.
setCartRecordId
(
tbCfCartRecordREntity1
.
getCartRecordId
());
tbCfCartRecordREntity
.
setItemId
(
tbCfItemDetailVo
.
getItemId
());
tbCfCartRecordREntity
.
setCheckFlag
(
StateConstant
.
VALID
);
tbCfCartRecordREntity
.
setEnableFlag
(
StateConstant
.
VALID
);
tbCfCartRecordREntity
.
setItemId
(
tbCfItemDetailVo
.
getItemId
());
tbCfCartRecordREntity
.
setUserId
(
tbCfUserInfoVo
.
getUserId
());
tbCfCartRecordREntity
.
setUserId
(
tbCfCartRecordREntity1
.
getUserId
());
tbCfCartRecordREntity
.
setCreateTime
(
new
Date
());
tbCfCartRecordREntity
.
setItemNum
(
tbCfItemDetailVo
.
getItemNum
());
tbCfCartRecordREntity
.
setItemSku
(
tbCfItemDetailVo
.
getItemSku
());
tbCfCartRecordREntity
.
setSourceItemId
(
tbCfItemDetailVo
.
getSourceItemId
());
tbCfCartRecordRDao
.
save
(
tbCfCartRecordREntity
);
}
else
{
tbCfCartRecordRDao
.
update
(
tbCfCartRecordREntity
);
tbCfItemDetailDao
.
update
(
tbCfItemDetail
);
}
else
{
tbCfItemDetailDao
.
save
(
tbCfItemDetail
);
TbCfCartRecordREntity
tbCfCartRecordREntity
=
new
TbCfCartRecordREntity
();
tbCfCartRecordREntity
.
setCartRecordId
(
tbCfCartRecordREntity1
.
getCartRecordId
());
tbCfCartRecordREntity
.
setItemId
(
tbCfItemDetailVo
.
getItemId
());
tbCfCartRecordREntity
.
setCartRecordId
(
IdUtil
.
createIdbyUUID
());
tbCfCartRecordREntity
.
setCheckFlag
(
StateConstant
.
VALID
);
tbCfCartRecordREntity
.
setEnableFlag
(
StateConstant
.
VALID
);
tbCfCartRecordREntity
.
setItemId
(
tbCfItemDetailVo
.
getItemId
());
tbCfCartRecordREntity
.
setUserId
(
tbCfUserInfoVo
.
getUserId
());
tbCfCartRecordREntity
.
setCreateTime
(
new
Date
());
tbCfCartRecordREntity
.
setItemNum
(
tbCfItemDetailVo
.
getItemNum
());
tbCfCartRecordRDao
.
update
(
tbCfCartRecordREntity
);
tbCfCartRecordREntity
.
setItemSku
(
tbCfItemDetailVo
.
getItemSku
());
tbCfCartRecordREntity
.
setSourceItemId
(
tbCfItemDetailVo
.
getSourceItemId
());
tbCfCartRecordRDao
.
save
(
tbCfCartRecordREntity
);
}
return
new
Result
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
}
else
{
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfOrderServiceImpl.java
浏览文件 @
f4b8c777
...
...
@@ -424,6 +424,7 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
orderEntity
.
setDeliveryPhone
(
order
.
getDeliveryPhone
());
orderEntity
.
setDeliveryName
(
order
.
getDeliveryName
());
orderEntity
.
setDeliveryAddress
(
order
.
getDeliveryAddress
());
orderEntity
.
setRemarkInfo
(
order
.
getRemarkInfo
());
orderEntity
.
setOrderNo
(
order
.
getOrderNo
());
orderEntity
.
setUserName
(
order
.
getUserName
());
//获取订单内商品
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/TbCfUserInfoServiceImpl.java
浏览文件 @
f4b8c777
...
...
@@ -136,7 +136,7 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
emailTemplateBo
.
setNick
(
nick
);
emailTemplateBo
.
setIdentifyCode
(
randomCode
);
Integer
identifyCode
=
emailHelper
.
sendIdentifyEmail
(
email
,
EmailTemplateConstant
.
REGISTER
,
emailTemplateBo
);
captchaRedisCache
.
set
(
KeyConstant
.
CAPTCHA
+
email
,
identifyCode
,
1
8
00
);
captchaRedisCache
.
set
(
KeyConstant
.
CAPTCHA
+
email
,
identifyCode
,
100
);
return
identifyCode
;
}
...
...
src/main/java/com/diaoyun/zion/master/entity/DcloudDto.java
0 → 100644
浏览文件 @
f4b8c777
package
com
.
diaoyun
.
zion
.
master
.
entity
;
/**
* Dcloud 返回数据的实体类
*/
public
class
DcloudDto
{
private
String
appid
;
private
String
appname
;
private
String
today_active_user_android
;
private
String
today_active_user_ios
;
private
String
today_active_user
;
private
String
total_active_count_android
;
private
String
total_active_count_ios
;
private
String
total_active_count
;
private
String
total_user_android
;
private
String
total_user_ios
;
private
String
total_user
;
private
String
new_user_android
;
private
String
new_user_ios
;
private
String
new_user
;
private
String
next_day_retention_android
;
private
String
next_day_retention_ios
;
private
String
next_day_retention
;
private
String
week_retention_android
;
private
String
week_retention_ios
;
private
String
week_retention
;
private
String
day
;
public
DcloudDto
(
String
appid
,
String
appname
,
String
today_active_user_android
,
String
today_active_user_ios
,
String
today_active_user
,
String
total_active_count_android
,
String
total_active_count_ios
,
String
total_active_count
,
String
total_user_android
,
String
total_user_ios
,
String
total_user
,
String
new_user_android
,
String
new_user_ios
,
String
new_user
,
String
next_day_retention_android
,
String
next_day_retention_ios
,
String
next_day_retention
,
String
week_retention_android
,
String
week_retention_ios
,
String
week_retention
,
String
day
)
{
this
.
appid
=
appid
;
this
.
appname
=
appname
;
this
.
today_active_user_android
=
today_active_user_android
;
this
.
today_active_user_ios
=
today_active_user_ios
;
this
.
today_active_user
=
today_active_user
;
this
.
total_active_count_android
=
total_active_count_android
;
this
.
total_active_count_ios
=
total_active_count_ios
;
this
.
total_active_count
=
total_active_count
;
this
.
total_user_android
=
total_user_android
;
this
.
total_user_ios
=
total_user_ios
;
this
.
total_user
=
total_user
;
this
.
new_user_android
=
new_user_android
;
this
.
new_user_ios
=
new_user_ios
;
this
.
new_user
=
new_user
;
this
.
next_day_retention_android
=
next_day_retention_android
;
this
.
next_day_retention_ios
=
next_day_retention_ios
;
this
.
next_day_retention
=
next_day_retention
;
this
.
week_retention_android
=
week_retention_android
;
this
.
week_retention_ios
=
week_retention_ios
;
this
.
week_retention
=
week_retention
;
this
.
day
=
day
;
}
public
String
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
String
appid
)
{
this
.
appid
=
appid
;
}
public
String
getAppname
()
{
return
appname
;
}
public
void
setAppname
(
String
appname
)
{
this
.
appname
=
appname
;
}
public
String
getToday_active_user_android
()
{
return
today_active_user_android
;
}
public
void
setToday_active_user_android
(
String
today_active_user_android
)
{
this
.
today_active_user_android
=
today_active_user_android
;
}
public
String
getToday_active_user_ios
()
{
return
today_active_user_ios
;
}
public
void
setToday_active_user_ios
(
String
today_active_user_ios
)
{
this
.
today_active_user_ios
=
today_active_user_ios
;
}
public
String
getToday_active_user
()
{
return
today_active_user
;
}
public
void
setToday_active_user
(
String
today_active_user
)
{
this
.
today_active_user
=
today_active_user
;
}
public
String
getTotal_active_count_android
()
{
return
total_active_count_android
;
}
public
void
setTotal_active_count_android
(
String
total_active_count_android
)
{
this
.
total_active_count_android
=
total_active_count_android
;
}
public
String
getTotal_active_count_ios
()
{
return
total_active_count_ios
;
}
public
void
setTotal_active_count_ios
(
String
total_active_count_ios
)
{
this
.
total_active_count_ios
=
total_active_count_ios
;
}
public
String
getTotal_active_count
()
{
return
total_active_count
;
}
public
void
setTotal_active_count
(
String
total_active_count
)
{
this
.
total_active_count
=
total_active_count
;
}
public
String
getTotal_user_android
()
{
return
total_user_android
;
}
public
void
setTotal_user_android
(
String
total_user_android
)
{
this
.
total_user_android
=
total_user_android
;
}
public
String
getTotal_user_ios
()
{
return
total_user_ios
;
}
public
void
setTotal_user_ios
(
String
total_user_ios
)
{
this
.
total_user_ios
=
total_user_ios
;
}
public
String
getTotal_user
()
{
return
total_user
;
}
public
void
setTotal_user
(
String
total_user
)
{
this
.
total_user
=
total_user
;
}
public
String
getNew_user_android
()
{
return
new_user_android
;
}
public
void
setNew_user_android
(
String
new_user_android
)
{
this
.
new_user_android
=
new_user_android
;
}
public
String
getNew_user_ios
()
{
return
new_user_ios
;
}
public
void
setNew_user_ios
(
String
new_user_ios
)
{
this
.
new_user_ios
=
new_user_ios
;
}
public
String
getNew_user
()
{
return
new_user
;
}
public
void
setNew_user
(
String
new_user
)
{
this
.
new_user
=
new_user
;
}
public
String
getNext_day_retention_android
()
{
return
next_day_retention_android
;
}
public
void
setNext_day_retention_android
(
String
next_day_retention_android
)
{
this
.
next_day_retention_android
=
next_day_retention_android
;
}
public
String
getNext_day_retention_ios
()
{
return
next_day_retention_ios
;
}
public
void
setNext_day_retention_ios
(
String
next_day_retention_ios
)
{
this
.
next_day_retention_ios
=
next_day_retention_ios
;
}
public
String
getNext_day_retention
()
{
return
next_day_retention
;
}
public
void
setNext_day_retention
(
String
next_day_retention
)
{
this
.
next_day_retention
=
next_day_retention
;
}
public
String
getWeek_retention_android
()
{
return
week_retention_android
;
}
public
void
setWeek_retention_android
(
String
week_retention_android
)
{
this
.
week_retention_android
=
week_retention_android
;
}
public
String
getWeek_retention_ios
()
{
return
week_retention_ios
;
}
public
void
setWeek_retention_ios
(
String
week_retention_ios
)
{
this
.
week_retention_ios
=
week_retention_ios
;
}
public
String
getWeek_retention
()
{
return
week_retention
;
}
public
void
setWeek_retention
(
String
week_retention
)
{
this
.
week_retention
=
week_retention
;
}
public
String
getDay
()
{
return
day
;
}
public
void
setDay
(
String
day
)
{
this
.
day
=
day
;
}
}
src/main/java/com/diaoyun/zion/master/quartz/QuartzMethod.java
浏览文件 @
f4b8c777
...
...
@@ -44,14 +44,13 @@ public class QuartzMethod {
* @throws IOException
* @throws URISyntaxException
*/
@Scheduled
(
cron
=
"0 0/
2
* * * ? "
)
@Scheduled
(
cron
=
"0 0/
3
* * * ? "
)
public
void
getRent
()
throws
IOException
,
URISyntaxException
{
String
content
=
HttpClientUtil
.
getContentByUrl
(
"https://cn.valutafx.com/USD-ZMW.htm?amount=1"
,
"rent"
);
// 解析为 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
String
rent
=
document
.
select
(
"div[class=rate-value]"
).
text
();
BigDecimal
rate
=
new
BigDecimal
(
rent
);
System
.
err
.
println
(
rate
);
String
type
=
"USD-ZMW"
;
tbCfExchangeService
.
updateByType
(
type
,
rate
);
}
...
...
@@ -68,7 +67,6 @@ public class QuartzMethod {
Document
document
=
Jsoup
.
parse
(
content
);
String
rent
=
document
.
select
(
"div[class=rate-value]"
).
text
();
BigDecimal
rate
=
new
BigDecimal
(
rent
);
System
.
err
.
println
(
rate
);
String
type
=
"USD-CNY"
;
tbCfExchangeService
.
updateByType
(
type
,
rate
);
}
...
...
src/main/java/com/diaoyun/zion/master/util/RentUtil.java
deleted
100644 → 0
浏览文件 @
584f4b14
package
com
.
diaoyun
.
zion
.
master
.
util
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
public
class
RentUtil
{
public
static
String
getRent
()
throws
IOException
,
URISyntaxException
{
String
content
=
HttpClientUtil
.
getContentByUrl
(
"https://cn.valutafx.com/USD-ZMW.htm?amount=1"
,
"rent"
);
// 解析为 Document 对象
Document
document
=
Jsoup
.
parse
(
content
);
String
rent
=
document
.
select
(
"div[class=rate-value]"
).
text
();
System
.
err
.
println
(
rent
);
return
rent
;
}
}
src/main/java/com/diaoyun/zion/master/util/SpiderUtil.java
浏览文件 @
f4b8c777
package
com
.
diaoyun
.
zion
.
master
.
util
;
import
com.diaoyun.zion.chinafrica.service.TbCfExchangeService
;
import
com.diaoyun.zion.chinafrica.service.TbCfFeeService
;
import
com.diaoyun.zion.master.entity.DcloudDto
;
import
com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer
;
import
io.lettuce.core.ConnectionEvents
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.net.URISyntaxException
;
import
java.util.List
;
import
java.util.regex.Pattern
;
/**
...
...
@@ -13,15 +20,17 @@ import java.util.regex.Pattern;
public
class
SpiderUtil
{
private
static
BigDecimal
rate
;
private
static
final
String
DCLOUD_APPID
=
"H52FE1175"
;
static
{
TbCfFeeService
tbCfFeeService
=
(
TbCfFeeService
)
SpringContextUtil
.
getBean
(
"tbCfFeeService"
);
rate
=
tbCfFeeService
.
getRateFee
().
getFeeRate
();
TbCfExchangeService
tbCfExchangeService
=
(
TbCfExchangeService
)
SpringContextUtil
.
getBean
(
"tbCfExchangeService"
);
String
exchangeCurrency
=
"CNY"
;
rate
=
tbCfExchangeService
.
getRateFee
(
exchangeCurrency
).
getExchangeRate
();
System
.
out
.
println
(
rate
);
}
/**
* 转换汇率--由人民币转换为美元
* TODO 同步汇率问题
* 注意:暂时从后台获取人工设置的汇率,还未是动态获取
* @param fullPrice 原始价格
* @return 汇率计算的价格
...
...
@@ -41,5 +50,25 @@ public class SpiderUtil {
return
str
;
}
/**
*
* @param appid
* @param start_date
* @param end_date
* @param item
* @param channel
* @return
*/
public
static
List
<
DcloudDto
>
spiderByDcloud
(
String
appid
,
String
start_date
,
String
end_date
,
String
item
,
String
channel
)
throws
IOException
,
URISyntaxException
{
String
targetUrl
=
"https://dev.dcloud.net.cn/statistics/fpat?appid="
+
appid
+
"&start_date="
+
start_date
+
"&end_date="
+
end_date
+
"&item="
+
item
+
"&channel="
+
channel
;
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
"Dcloud"
);
return
null
;
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
URISyntaxException
{
String
targetUrl
=
"https://dev.dcloud.net.cn/statistics/fpat?appid=H5014FF11&start_date=2019-12-31&end_date=2020-01-06&item=today_active_user&channel="
;
String
content
=
HttpClientUtil
.
getContentByUrl
(
targetUrl
,
"Dcloud"
);
System
.
out
.
println
(
content
);
}
}
src/main/resources/mapper/TbCfCartRecordRDao.xml
浏览文件 @
f4b8c777
...
...
@@ -124,27 +124,47 @@
</delete>
<select
id=
"querySkuAndUrl"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity"
>
select
`cart_record_id`,
`item_id`,
`user_id`,
`check_flag`,
`enable_flag`,
`create_time`,
`source_item_id`,
`item_sku`,
`item_num`
`cart_record_id`,
`item_id`,
`user_id`,
`check_flag`,
`enable_flag`,
`create_time`,
`source_item_id`,
`item_sku`,
`item_num`
from tb_cf_cart_record_r
where item_sku =#{itemSku} and source_item_id=#{sourceItemId} and enable_flag=1
where 1=1
and user_id=#{userId}
and enable_flag=1
<if
test=
"itemSku != null and itemSku.trim() != ''"
>
and item_sku =#{itemSku}
</if>
<if
test=
"sourceItemId != null and sourceItemId.trim() != ''"
>
and source_item_id=#{sourceItemId}
</if>
<if
test=
"itemId != null and itemId.trim() != ''"
>
and item_id=#{itemId}
</if>
</select>
<select
id=
"queryByItemId"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfCartRecordREntity"
>
select `cart_record_id`,
`item_id`,
`user_id`,
`check_flag`,
`enable_flag`,
`create_time`,
`source_item_id`,
`item_sku`,
`item_num` from tb_cf_cart_record_r where item_id =#{itemId} and enable_flag=1
`item_id`,
`user_id`,
`check_flag`,
`enable_flag`,
`create_time`,
`source_item_id`,
`item_sku`,
`item_num` from tb_cf_cart_record_r where 1=1
and enable_flag=1
and user_id=#{userId}
and item_id =#{itemId}
<if
test=
"itemSku != null and itemSku.trim() != ''"
>
and item_sku =#{itemSku}
</if>
</select>
</mapper>
\ No newline at end of file
src/main/resources/mapper/TbCfExchangeDao.xml
浏览文件 @
f4b8c777
...
...
@@ -113,4 +113,8 @@
<update
id=
"updateByType"
>
update tb_cf_exchange set exchange_rate = #{rate} where type=#{type};
</update>
<select
id=
"getRateFee"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfExchangeEntity"
>
select * from tb_cf_exchange where exchange_currency=#{exchangeCurrency}
</select>
</mapper>
\ No newline at end of file
src/main/resources/mapper/TbCfItemDetailDao.xml
浏览文件 @
f4b8c777
...
...
@@ -3,24 +3,24 @@
<mapper
namespace=
"com.diaoyun.zion.chinafrica.dao.TbCfItemDetailDao"
>
<resultMap
type=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
id=
"tbCfItemDetailMap"
>
<result
property=
"itemId"
column=
"item_id"
/>
<result
property=
"sourceItemId"
column=
"source_item_id"
/>
<result
property=
"stationId"
column=
"station_id"
/>
<result
property=
"stationType"
column=
"station_type"
/>
<result
property=
"itemTitle"
column=
"item_title"
/>
<result
property=
"itemNum"
column=
"item_num"
/>
<result
property=
"itemImg"
column=
"item_img"
/>
<result
property=
"itemPrice"
column=
"item_price"
/>
<result
property=
"itemCategory"
column=
"item_category"
/>
<result
property=
"itemSku"
column=
"item_sku"
/>
<result
property=
"shopId"
column=
"shop_id"
/>
<result
property=
"shopName"
column=
"shop_name"
/>
<result
property=
"shopUrl"
column=
"shop_url"
/>
<result
property=
"createTime"
column=
"create_time"
/>
</resultMap>
<resultMap
type=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
id=
"tbCfItemDetailMap"
>
<result
property=
"itemId"
column=
"item_id"
/>
<result
property=
"sourceItemId"
column=
"source_item_id"
/>
<result
property=
"stationId"
column=
"station_id"
/>
<result
property=
"stationType"
column=
"station_type"
/>
<result
property=
"itemTitle"
column=
"item_title"
/>
<result
property=
"itemNum"
column=
"item_num"
/>
<result
property=
"itemImg"
column=
"item_img"
/>
<result
property=
"itemPrice"
column=
"item_price"
/>
<result
property=
"itemCategory"
column=
"item_category"
/>
<result
property=
"itemSku"
column=
"item_sku"
/>
<result
property=
"shopId"
column=
"shop_id"
/>
<result
property=
"shopName"
column=
"shop_name"
/>
<result
property=
"shopUrl"
column=
"shop_url"
/>
<result
property=
"createTime"
column=
"create_time"
/>
</resultMap>
<select
id=
"queryObject"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
<select
id=
"queryObject"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
select
`item_id`,
`source_item_id`,
...
...
@@ -39,7 +39,7 @@
from tb_cf_item_detail
where item_id = #{id}
</select>
<select
id=
"queryByTitle"
resultType=
"com.diaoyun.zion.chinafrica.vo.TbCfItemDetailVo"
>
<select
id=
"queryByTitle"
resultType=
"com.diaoyun.zion.chinafrica.vo.TbCfItemDetailVo"
>
select
`item_id`,
`source_item_id`,
...
...
@@ -58,48 +58,48 @@
from tb_cf_item_detail
where item_title = #{itemTitle}
</select>
<select
id=
"queryList"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
select
`item_id`,
`source_item_id`,
`station_id`,
`station_type`,
`item_title`,
`item_num`,
`item_img`,
`item_price`,
`item_category`,
`item_sku`,
`shop_id`,
`shop_name`,
`shop_url`,
`create_time`
from tb_cf_item_detail
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when
test=
"sidx != null and sidx.trim() != ''"
>
order by ${sidx} ${order}
</when>
<otherwise>
order by item_id desc
</otherwise>
</choose>
<if
test=
"offset != null and limit != null"
>
limit #{offset}, #{limit}
</if>
</select>
<select
id=
"queryList"
resultType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
select
`item_id`,
`source_item_id`,
`station_id`,
`station_type`,
`item_title`,
`item_num`,
`item_img`,
`item_price`,
`item_category`,
`item_sku`,
`shop_id`,
`shop_name`,
`shop_url`,
`create_time`
from tb_cf_item_detail
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when
test=
"sidx != null and sidx.trim() != ''"
>
order by ${sidx} ${order}
</when>
<otherwise>
order by item_id desc
</otherwise>
</choose>
<if
test=
"offset != null and limit != null"
>
limit #{offset}, #{limit}
</if>
</select>
<select
id=
"queryTotal"
resultType=
"int"
>
select count(*) from tb_cf_item_detail
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert
id=
"save"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
<select
id=
"queryTotal"
resultType=
"int"
>
select count(*) from tb_cf_item_detail
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert
id=
"save"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
insert into tb_cf_item_detail(
`item_id`,
`source_item_id`,
...
...
@@ -132,57 +132,71 @@
#{createTime})
</insert>
<update
id=
"update"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
update tb_cf_item_detail
<set>
<if
test=
"sourceItemId != null"
>
`source_item_id` = #{sourceItemId},
</if>
<if
test=
"stationId != null"
>
`station_id` = #{stationId},
</if>
<if
test=
"stationType != null"
>
`station_type` = #{stationType},
</if>
<if
test=
"itemTitle != null"
>
`item_title` = #{itemTitle},
</if>
<if
test=
"itemNum != null"
>
`item_num` = #{itemNum},
</if>
<if
test=
"itemImg != null"
>
`item_img` = #{itemImg},
</if>
<if
test=
"itemPrice != null"
>
`item_price` = #{itemPrice},
</if>
<if
test=
"itemCategory != null"
>
`item_category` = #{itemCategory},
</if>
<if
test=
"itemSku != null"
>
`item_sku` = #{itemSku},
</if>
<if
test=
"shopId != null"
>
`shop_id` = #{shopId},
</if>
<if
test=
"shopName != null"
>
`shop_name` = #{shopName},
</if>
<if
test=
"shopUrl != null"
>
`shop_url` = #{shopUrl},
</if>
<if
test=
"createTime != null"
>
`create_time` = #{createTime}
</if>
</set>
where item_id = #{itemId
}
</update>
<update
id=
"update"
parameterType=
"com.diaoyun.zion.chinafrica.entity.TbCfItemDetailEntity"
>
update tb_cf_item_detail
<set>
<if
test=
"sourceItemId != null"
>
`source_item_id` = #{sourceItemId},
</if>
<if
test=
"stationId != null"
>
`station_id` = #{stationId},
</if>
<if
test=
"stationType != null"
>
`station_type` = #{stationType},
</if>
<if
test=
"itemTitle != null"
>
`item_title` = #{itemTitle},
</if>
<if
test=
"itemNum != null"
>
`item_num` = #{itemNum},
</if>
<if
test=
"itemImg != null"
>
`item_img` = #{itemImg},
</if>
<if
test=
"itemPrice != null"
>
`item_price` = #{itemPrice},
</if>
<if
test=
"itemCategory != null"
>
`item_category` = #{itemCategory},
</if>
<if
test=
"itemSku != null"
>
`item_sku` = #{itemSku},
</if>
<if
test=
"shopId != null"
>
`shop_id` = #{shopId},
</if>
<if
test=
"shopName != null"
>
`shop_name` = #{shopName},
</if>
<if
test=
"shopUrl != null"
>
`shop_url` = #{shopUrl},
</if>
<if
test=
"createTime != null"
>
`create_time` = #{createTime}
</if>
</set>
where item_id = #{itemId} and item_sku=#{itemSku
}
</update>
<delete
id=
"delete"
>
<delete
id=
"delete"
>
delete from tb_cf_item_detail where item_id = #{value}
</delete>
<delete
id=
"deleteBatch"
>
delete from tb_cf_item_detail where item_id in
<foreach
item=
"itemId"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{itemId}
</foreach>
</delete>
<delete
id=
"deleteBatch"
>
delete from tb_cf_item_detail where item_id in
<foreach
item=
"itemId"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{itemId}
</foreach>
</delete>
<!--获取用户购物车内商品-->
<select
id=
"getCartItemList"
resultType=
"com.diaoyun.zion.chinafrica.vo.TbCfCartItemDetailVo"
>
select t1.cart_record_id,t1.check_flag,t2.* from tb_cf_cart_record_r t1,tb_cf_item_detail t2 where
t1.item_id=t2.item_id
and t1.user_id=#{userId} and t2.item_price is not null
<if
test=
"checkFlag != null"
>
and t1.check_flag = #{checkFlag}
</if>
and t1.enable_flag=1 order by t2.create_time desc
</select>
<!--获取用户购物车内商品-->
<select
id=
"getCartItemList"
resultType=
"com.diaoyun.zion.chinafrica.vo.TbCfCartItemDetailVo"
>
select
t1.cart_record_id,
t1.check_flag,
t2.item_id,
t2.source_item_id,
t2.station_id,
t2.station_type,
t2.item_title,
t2.item_num,
t2.item_img,
t2.item_price,
t2.item_category,
t2.item_sku,
t2.shop_id,
t2.shop_name,
t2.shop_url,
t2.create_time
from
tb_cf_cart_record_r t1 left join tb_cf_item_detail t2 on t1.item_id=t2.item_id and t1.item_sku=t2.item_sku
where 1=1
and t1.user_id=#{userId}
and t2.item_price is not null
and t1.enable_flag=1 order by t2.create_time desc
<if
test=
"checkFlag != null"
>
and t1.check_flag = #{checkFlag}
</if>
</select>
<!--改变购物车的商品勾选状态(旧版)
-->
<update
id=
"changeItemState"
>
<!--改变购物车的商品勾选状态
-->
<update
id=
"changeItemState"
>
update tb_cf_cart_record_r set check_flag=#{checkFlag} where cart_record_id=#{cartRecordId}
</update>
<!--改变购物车商品勾选状态(新版)-->
<update
id=
"changeState"
>
update tb_cf_cart_record_r set check_flag=#{checkFlag} where cart_record_id in
<foreach
item=
"id"
collection=
"ids"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
</update>
<select
id=
"queryItemNum"
resultType=
"int"
>
select count(*) from tb_cf_cart_record_r where 1=1 and user_id=#{userId} and enable_flag=1
</select>
</mapper>
\ No newline at end of file
src/main/resources/mapper/TbCfOrderDao.xml
浏览文件 @
f4b8c777
...
...
@@ -85,7 +85,8 @@
o.user_name,
o.delivery_address,
o.delivery_name,
o.delivery_phone
o.delivery_phone,
o.remark_info
from tb_cf_order o left join tb_cf_item_order_r r on r.order_id=o.order_id
where r.order_item_id = #{id}
</select>
...
...
src/test/java/com/diaoyun/zion/Test.java
浏览文件 @
f4b8c777
package
com
.
diaoyun
.
zion
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.InvalidKeyException
;
import
java.security.Key
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SecureRandom
;
import
java.security.spec.InvalidKeySpecException
;
import
java.util.Properties
;
import
javax.crypto.*
;
import
javax.crypto.spec.DESKeySpec
;
import
javax.crypto.spec.DESedeKeySpec
;
import
javax.mail.Address
;
import
javax.mail.Message
;
import
javax.mail.MessagingException
;
...
...
@@ -10,9 +20,20 @@ import javax.mail.Transport;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeMessage
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.egzosn.pay.common.util.sign.encrypt.Base64
;
import
com.sun.mail.util.MailSSLSocketFactory
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
public
class
Test
{
// 向量
private
final
static
String
DES
=
"DES"
;
public
final
static
String
KEY
=
"111111111111111111111111111111111111111"
;
public
final
static
String
encode
=
"UTF-8"
;
/**
/**
* @Title: sendEmail
* @Description: 发送邮件工具类方法
* @param sendEmail
...
...
@@ -97,18 +118,102 @@ public class Test {
* @throws Exception
* @return: void
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
/**
* @param sendEmail 发件人地址
* @param sendEmailPwd
* 授权码代替密码(更安全)
* @param title
* 邮件标题
* @param content
* 邮件内容
* @param toEmilAddress
* 收件人地址
*/
Test
.
sendEmail
(
"1203063316@qq.com"
,
"mkwugpvzbafpjfdc"
,
"testEmail"
,
"testcontent"
,
new
String
[]{
"pure091529@163.com"
});
/**
* @param sendEmail 发件人地址
* @param sendEmailPwd
* 授权码代替密码(更安全)
* @param title
* 邮件标题
* @param content
* 邮件内容
* @param toEmilAddress
* 收件人地址
*/
// Test.sendEmail("1203063316@qq.com", "mkwugpvzbafpjfdc", "testEmail", "testcontent",new String[]{"pure091529@163.com"});
/* String targetUrl = "https://dev.dcloud.net.cn/statistics/fpat?appid=H5014FF11&start_date=2019-12-31&end_date=2020-01-06&item=today_active_user&channel=";
String content = HttpClientUtil.getContentByUrl(targetUrl, "Dcloud");
System.out.println(content);*/
/**
* Description 根据键值进行加密
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
public
static
String
encrypt
(
String
data
,
String
key
)
throws
Exception
{
byte
[]
bt
=
encrypt
(
data
.
getBytes
(),
key
.
getBytes
());
String
strs
=
new
BASE64Encoder
().
encode
(
bt
);
return
strs
;
}
/**
* Description 根据键值进行解密
* @param data
* @param key 加密键byte数组
* @return
* @throws IOException
* @throws Exception
*/
public
static
String
decrypt
(
String
data
,
String
key
)
throws
IOException
,
Exception
{
if
(
data
==
null
)
return
null
;
BASE64Decoder
decoder
=
new
BASE64Decoder
();
byte
[]
buf
=
decoder
.
decodeBuffer
(
data
);
byte
[]
bt
=
decrypt
(
buf
,
key
.
getBytes
());
return
new
String
(
bt
);
}
/**
* Description 根据键值进行加密
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
private
static
byte
[]
encrypt
(
byte
[]
data
,
byte
[]
key
)
throws
Exception
{
// 生成一个可信任的随机数源
SecureRandom
sr
=
new
SecureRandom
();
// 从原始密钥数据创建DESKeySpec对象
DESKeySpec
dks
=
new
DESKeySpec
(
key
);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
DES
);
SecretKey
securekey
=
keyFactory
.
generateSecret
(
dks
);
// Cipher对象实际完成加密操作
Cipher
cipher
=
Cipher
.
getInstance
(
DES
);
// 用密钥初始化Cipher对象
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
securekey
,
sr
);
return
cipher
.
doFinal
(
data
);
}
/**
* Description 根据键值进行解密
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
private
static
byte
[]
decrypt
(
byte
[]
data
,
byte
[]
key
)
throws
Exception
{
// 生成一个可信任的随机数源
SecureRandom
sr
=
new
SecureRandom
();
// 从原始密钥数据创建DESKeySpec对象
DESKeySpec
dks
=
new
DESKeySpec
(
key
);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
SecretKeyFactory
keyFactory
=
SecretKeyFactory
.
getInstance
(
DES
);
SecretKey
securekey
=
keyFactory
.
generateSecret
(
dks
);
// Cipher对象实际完成解密操作
Cipher
cipher
=
Cipher
.
getInstance
(
DES
);
// 用密钥初始化Cipher对象
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
securekey
,
sr
);
return
cipher
.
doFinal
(
data
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//加密
System
.
out
.
println
(
Test
.
encrypt
(
"12"
,
Test
.
KEY
));
//解密
System
.
out
.
println
(
Test
.
decrypt
(
"XX2s27k8G6Q="
,
Test
.
KEY
));
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论