定时任务修改状态 增加解密方式

master
bynt 3 years ago
parent 5a865e7db6
commit 209f8074e5

@ -62,7 +62,7 @@ trade:
service: service:
source: source:
url: http://39.100.226.133:80 url: http://39.100.226.133:80
# url: http://localhost:80
taobao: taobao:
Synchronize: Synchronize:
amount: 0.001 amount: 0.001

@ -5,7 +5,6 @@ import com.hchbox.service.TaoBaoSaleService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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.RequestParam; import org.springframework.web.bind.annotation.RequestParam;

@ -59,9 +59,12 @@ public class TaskMessageController {
@GetMapping("/getMessageContent") @GetMapping("/getMessageContent")
@ApiOperation("查询实时发送详情") @ApiOperation("查询实时发送详情")
public CommonResult<List<Map<String, String>>> getMessageContent( public CommonResult<Map<String, String>> getMessageContent(@SellerUser SellerAccountDTO sellerAccountDTO,
@RequestParam("date") @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date date) { @RequestParam("date") @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date date) {
return taskSendMessageService.getRedisMessage(date); if (sellerAccountDTO == null) {
return new CommonResult<Map<String, String>>().accountException();
}
return taskSendMessageService.getRedisMessage(sellerAccountDTO,date);
} }
@GetMapping("/putMessage") @GetMapping("/putMessage")

@ -146,6 +146,10 @@ hchbox:
#serverUrl: https://gw.api.tbsandbox.com/router/rest #serverUrl: https://gw.api.tbsandbox.com/router/rest
# 正式地址 # 正式地址
serverUrl: https://eco.taobao.com/router/rest serverUrl: https://eco.taobao.com/router/rest
randomString: oILloVtaz1oRpGY10s3oYBFTUnS6Hgcbqi23MPBILX4=
file: file:
root: root:
path: E:\upload path: E:\upload
system:
flag: false

@ -145,6 +145,9 @@ hchbox:
#serverUrl: https://gw.api.tbsandbox.com/router/rest #serverUrl: https://gw.api.tbsandbox.com/router/rest
# 正式地址 # 正式地址
serverUrl: https://eco.taobao.com/router/rest serverUrl: https://eco.taobao.com/router/rest
randomString: oILloVtaz1oRpGY10s3oYBFTUnS6Hgcbqi23MPBILX4=
file: file:
root: root:
path: E:\upload path: E:\upload
system:
flag: true

@ -1,14 +1,25 @@
package com.hchbox; package com.hchbox;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import com.hchbox.config.MiProperties;
import com.hchbox.constant.TaoBaoDataMethodConstants;
import com.hchbox.entity.master.Blacklist; import com.hchbox.entity.master.Blacklist;
import com.hchbox.entity.master.User; import com.hchbox.entity.master.User;
import com.hchbox.entity.slaver.JdpTrade;
import com.hchbox.repository.master.BlacklistRepository; import com.hchbox.repository.master.BlacklistRepository;
import com.hchbox.repository.master.MemberRepository; import com.hchbox.repository.master.MemberRepository;
import com.hchbox.repository.master.SellerAccountRepository; import com.hchbox.repository.master.SellerAccountRepository;
import com.hchbox.repository.master.TopTradeRepository; import com.hchbox.repository.master.TopTradeRepository;
import com.hchbox.service.*; import com.hchbox.service.*;
import com.hchbox.uitl.TaoBaoEncryption;
import com.hchbox.util.CacheManagerUtil; import com.hchbox.util.CacheManagerUtil;
import com.taobao.api.ApiException;
import com.taobao.api.SecretException;
import com.taobao.api.domain.Trade;
import com.taobao.api.internal.util.TaobaoUtils;
import com.taobao.api.response.TradeFullinfoGetResponse;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -67,21 +78,45 @@ public class SlaverTest {
@Resource @Resource
private TaoBaoMessageService taoBaoMessageService; private TaoBaoMessageService taoBaoMessageService;
@Resource @Resource
private BlacklistRepository blacklistRepository; private BlacklistRepository blacklistRepository;
@Resource @Resource
private TaoBaoSaleService taoBaoSaleService; private TaoBaoSaleService taoBaoSaleService;
@Resource
private MiProperties miProperties;
@Test @Test
public void getSaleSize(){ public void getSaleSize() throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
String dateStr = "2021-10-21 01:02:03";
String dateStr2 = "2021-10-22 15:09:15"; List<JdpTrade> jdpOrderByTime = jdpTradeService.findJdpOrderByTime(DateUtil.parse("2021-11-17 09:23:15"), DateUtil.parse("2021-11-18 09:23:27"));
List<Trade> list = new ArrayList<>();
Integer integer = taoBaoSaleService.saleSize(DateUtil.parse(dateStr), DateUtil.parse(dateStr2), "50008500502Uyr1928c116beQHQChHN4Pv9A3kwHLPCuxfWCcx7tUtEKGghsN8Jaf0"); for (JdpTrade jdpTrade : jdpOrderByTime) {
System.out.println(integer); if (jdpTrade != null && jdpTrade.getJdpResponse() != null) {
// 淘宝用此方式转换为trade
TradeFullinfoGetResponse rsp = TaobaoUtils.parseResponse(jdpTrade.getJdpResponse(),
TradeFullinfoGetResponse.class);
list.add(rsp.getTrade());
}
}
List<String> fieldName = Lists.newArrayList
(TaoBaoDataMethodConstants.BUYER_NICK,
TaoBaoDataMethodConstants.BUYER_EMAIL,
TaoBaoDataMethodConstants.RECEIVER_NAME,
TaoBaoDataMethodConstants.RECEIVER_PHONE,
TaoBaoDataMethodConstants.BUYER_ALIPAY_NO,
TaoBaoDataMethodConstants.RECEIVER_ADDRESS,
TaoBaoDataMethodConstants.ENCRYPT_ALI_PAY_ID);
// 字段解密
TaoBaoEncryption.decrypt(miProperties, "50008400241xjDTcDePNGtjMCsvtS9byhUEIpESqjccFrgkxXi6Fe16809637nng5v", list, fieldName);
// 手机号码单独解密
TaoBaoEncryption.decrypt(miProperties,"50008400241xjDTcDePNGtjMCsvtS9byhUEIpESqjccFrgkxXi6Fe16809637nng5v", list, TaoBaoDataMethodConstants.PHONE,
Trade.class.getDeclaredField(TaoBaoDataMethodConstants.RECEIVER_MOBILE));
System.out.println(JSONUtil.toJsonStr(list));
} }
@Test @Test

@ -28,6 +28,8 @@ public class MiProperties {
private String serverUrl; private String serverUrl;
private String randomString;
} }

@ -1,5 +1,6 @@
package com.hchbox.repository.master; package com.hchbox.repository.master;
import cn.hutool.core.date.DateTime;
import com.hchbox.entity.master.TopTrade; import com.hchbox.entity.master.TopTrade;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@ -38,5 +39,33 @@ public interface TopTradeRepository extends JpaRepository<TopTrade, Long>, JpaSp
void updateOrderStatus(String status, Long tid); void updateOrderStatus(String status, Long tid);
/**
*
* @param orderStatus
* @param tid
* @param date
*/
@Modifying
@Query(value = "update TopTrade t set t.status = ?1,t.payTime = ?3 where t.tid = ?2")
void updateOrderStatusPaySuccess(String orderStatus, Long tid, DateTime date);
/**
*
* @param orderStatus
* @param tid
* @param date
*/
@Modifying
@Query(value = "update TopTrade t set t.status = ?1,t.consignTime = ?3 where t.tid = ?2")
void updateOrderStatusByShipDate(String orderStatus, Long tid, DateTime date);
/**
*
* @param orderStatus
* @param tid
* @param date
*/
@Modifying
@Query(value = "update TopTrade t set t.status = ?1,t.endTime = ?3 where t.tid = ?2")
void updateOrderStatusSuccessfulTransaction(String orderStatus, Long tid, DateTime date);
} }

@ -6,6 +6,7 @@ import com.hchbox.hander.MessageDispatcher;
import com.hchbox.hander.message.TaoBaoMessage; import com.hchbox.hander.message.TaoBaoMessage;
import com.taobao.api.internal.tmc.TmcClient; import com.taobao.api.internal.tmc.TmcClient;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -17,16 +18,21 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
public class TmcConfig implements CommandLineRunner { public class TmcConfig implements CommandLineRunner {
@Value("${system.flag}")
private Boolean flag;
private final MiProperties miProperties; private final MiProperties miProperties;
private final MessageDispatcher<TaoBaoMessage> messageDispatcher; private final MessageDispatcher<TaoBaoMessage> messageDispatcher;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
if (flag != null && flag) {
TmcClient client = TaoBaoTmcClient.createClient(miProperties); TmcClient client = TaoBaoTmcClient.createClient(miProperties);
client.setMessageHandler(messageDispatcher); client.setMessageHandler(messageDispatcher);
// 设置为30000 // 设置为 5000
client.setQueueSize(DefaultNumberConstants.FIVE_THOUSAND); client.setQueueSize(DefaultNumberConstants.FIVE_THOUSAND);
client.connect(); client.connect();
} }
} }
}

@ -61,10 +61,12 @@ public interface TaskMessageService {
/** /**
* redis * redis
*
* @param sellerAccountDTO
* @param date * @param date
* @return * @return
*/ */
CommonResult<List<Map<String, String>>> getRedisMessage(Date date); CommonResult<Map<String, String>> getRedisMessage(SellerAccountDTO sellerAccountDTO, Date date);
/** /**
* redis * redis

@ -165,6 +165,7 @@ public class SellerAccountServiceImpl implements SellerAccountService {
findSellerAccountById(updateAccountsVo.getId()); findSellerAccountById(updateAccountsVo.getId());
if (account != null) { if (account != null) {
log.info("=============== the account nickname as {} ===============", account.getNickname()); log.info("=============== the account nickname as {} ===============", account.getNickname());
cacheManagerUtil.evictCache("sellerAccountCache", account.getNickname());
account.setStatus(DefaultNumberConstants.ONE_NUMBER); account.setStatus(DefaultNumberConstants.ONE_NUMBER);
account.setAccountBalance(updateAccountsVo.getAccountBalance()); account.setAccountBalance(updateAccountsVo.getAccountBalance());
// Boolean aBoolean = taoBaoRdsPushService.turnOnPushService(account.getSessionKey(), (long) DefaultNumberConstants.NINETY); // Boolean aBoolean = taoBaoRdsPushService.turnOnPushService(account.getSessionKey(), (long) DefaultNumberConstants.NINETY);
@ -198,7 +199,6 @@ public class SellerAccountServiceImpl implements SellerAccountService {
// 子账号登录 // 子账号登录
if (StrUtil.contains(nickname, StrUtil.COLON)) { if (StrUtil.contains(nickname, StrUtil.COLON)) {
String[] split = nickname.split(StrUtil.COLON); String[] split = nickname.split(StrUtil.COLON);
String masterUserName = split[DefaultNumberConstants.ZERO_NUMBER]; String masterUserName = split[DefaultNumberConstants.ZERO_NUMBER];
// 获取店铺名称 // 获取店铺名称
@ -224,7 +224,6 @@ public class SellerAccountServiceImpl implements SellerAccountService {
SellerAccount subAccount = sellerAccountRepository.findSellerAccountByNickname(nickname); SellerAccount subAccount = sellerAccountRepository.findSellerAccountByNickname(nickname);
if (subAccount == null) { if (subAccount == null) {
subAccount = new SellerAccount(); subAccount = new SellerAccount();
// EmojiUtil.toUnicode(); 转义回来 // EmojiUtil.toUnicode(); 转义回来
subAccount.setSessionKey(accessToken); subAccount.setSessionKey(accessToken);
subAccount.setShopTitle(shop.getTitle()); subAccount.setShopTitle(shop.getTitle());
@ -239,7 +238,11 @@ public class SellerAccountServiceImpl implements SellerAccountService {
return getSaveMapCommonResult(request, account); return getSaveMapCommonResult(request, account);
} }
subAccount.setIsSubAccount(Boolean.TRUE); subAccount.setIsSubAccount(Boolean.TRUE);
return getMapCommonResult(loginVo, request, subAccount); subAccount.setLastLoginTime(DateUtil.date());
subAccount.setSessionKey(loginVo.getAccessToken());
subAccount.setNickname(EmojiUtil.toAlias(loginVo.getUserNick()));
SellerAccount account = sellerAccountRepository.save(subAccount);
return getMapCommonResult(request, account);
} }
loginVo.setIsSubAccount(Boolean.FALSE); loginVo.setIsSubAccount(Boolean.FALSE);
@ -267,22 +270,22 @@ public class SellerAccountServiceImpl implements SellerAccountService {
return getSaveMapCommonResult(request, saveAccount); return getSaveMapCommonResult(request, saveAccount);
} }
sellerAccount.setIsSubAccount(Boolean.FALSE); sellerAccount.setIsSubAccount(Boolean.FALSE);
return getMapCommonResult(loginVo, request, sellerAccount); sellerAccount.setLastLoginTime(DateUtil.date());
sellerAccount.setSessionKey(loginVo.getAccessToken());
sellerAccount.setNickname(EmojiUtil.toAlias(loginVo.getUserNick()));
SellerAccount account = sellerAccountRepository.save(sellerAccount);
return getMapCommonResult(request, account);
} }
private CommonResult<Map<Object, Object>> getMapCommonResult(AppletsLoginVo loginVo, HttpServletRequest request, SellerAccount sellerAccount) { private CommonResult<Map<Object, Object>> getMapCommonResult(HttpServletRequest request, SellerAccount sellerAccount) {
cacheManagerUtil.evictCache("sellerAccountCache", sellerAccount.getNickname());
if (sellerAccount.getParentId() == DefaultNumberConstants.ZERO_NUMBER if (sellerAccount.getParentId() == DefaultNumberConstants.ZERO_NUMBER
|| sellerAccount.getAuthorizeEndTime() == null || sellerAccount.getAuthorizeEndTime().before(DateUtil.date())) { || sellerAccount.getAuthorizeEndTime() == null || sellerAccount.getAuthorizeEndTime().before(DateUtil.date())) {
return new CommonResult<Map<Object, Object>>().accountException(); return new CommonResult<Map<Object, Object>>().accountException();
} }
cacheManagerUtil.evictCache("sellerAccountCache", sellerAccount.getNickname());
sellerAccount.setLastLoginTime(DateUtil.date());
sellerAccount.setSessionKey(loginVo.getAccessToken());
sellerAccount.setNickname(EmojiUtil.toAlias(loginVo.getUserNick()));
SellerAccount account = sellerAccountRepository.save(sellerAccount);
request.getSession().setAttribute(AuthConstants.SELLER_ACCOUNT, sellerAccount); request.getSession().setAttribute(AuthConstants.SELLER_ACCOUNT, sellerAccount);
AccountLoginVO accountLoginVO = new AccountLoginVO(); AccountLoginVO accountLoginVO = new AccountLoginVO();
BeanUtil.copyProperties(account, accountLoginVO); BeanUtil.copyProperties(sellerAccount, accountLoginVO);
return new CommonResult<Map<Object, Object>>().success(accountLoginVO); return new CommonResult<Map<Object, Object>>().success(accountLoginVO);
} }

@ -10,7 +10,6 @@ import com.taobao.api.response.JushitaJdpUserAddResponse;
import com.taobao.api.response.JushitaJdpUserDeleteResponse; import com.taobao.api.response.JushitaJdpUserDeleteResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.hibernate.sql.Delete;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**

@ -191,17 +191,23 @@ public class TaskMessageServiceImpl implements TaskMessageService {
} }
@Override @Override
public CommonResult<List<Map<String, String>>> getRedisMessage(Date date) { public CommonResult<Map<String, String>> getRedisMessage(SellerAccountDTO sellerAccountDTO, Date date) {
DateTime dateTime = DateUtil.offsetMinute(date, -DefaultNumberConstants.TEN_NUMBER); DateTime dateTime = DateUtil.offsetMinute(date, -DefaultNumberConstants.TEN_NUMBER);
String format = DateUtil.format(dateTime, TimeConstants.YYYY_MM_DD_HH); String format = DateUtil.format(dateTime, TimeConstants.YYYY_MM_DD_HH);
int minuteInt = (DateUtil.minute(dateTime) / DefaultNumberConstants.TEN_NUMBER) * DefaultNumberConstants.TEN_NUMBER; int minuteInt = (DateUtil.minute(dateTime) / DefaultNumberConstants.TEN_NUMBER) * DefaultNumberConstants.TEN_NUMBER;
String concat = format.concat(StrUtil.DASHED).concat(String.valueOf(minuteInt)); // 拼接参数
String concat = sellerAccountDTO.getId().toString()
.concat(StrUtil.DASHED)
.concat(format
.concat(StrUtil.DASHED)
.concat(String.valueOf(minuteInt)));
Map<String,String> sendMessageCache = cacheManagerUtil.getCache(MessageConstants.SEND_MESSAGE_KEY, concat); Map<String,String> sendMessageCache = cacheManagerUtil.getCache(MessageConstants.SEND_MESSAGE_KEY, concat);
// 删除缓存 // 删除缓存
if (!CollectionUtils.isEmpty(sendMessageCache)) { if (!CollectionUtils.isEmpty(sendMessageCache)) {
cacheManagerUtil.evictCache(MessageConstants.SEND_MESSAGE_KEY, concat); cacheManagerUtil.evictCache(MessageConstants.SEND_MESSAGE_KEY, concat);
} }
return new CommonResult<List<Map<String, String>>>().success(sendMessageCache); return new CommonResult<Map<String, String>>().success(sendMessageCache);
} }
@Override @Override

@ -159,7 +159,6 @@ public class TopTradeServiceImpl implements TopTradeService {
topTradeRepository.updateOrderStatus(message.getStatus(), message.getTid()); topTradeRepository.updateOrderStatus(message.getStatus(), message.getTid());
return Boolean.TRUE; return Boolean.TRUE;
} }
// TODO 修改状态
return Boolean.FALSE; return Boolean.FALSE;
} }
@ -362,17 +361,33 @@ public class TopTradeServiceImpl implements TopTradeService {
} }
// 6.提交旺旺提醒任务 // 6.提交旺旺提醒任务
sendMessageRemind(message.getBuyerNick(), message.getTid(), status, templateStr, setting, subNickList, sellerAccount); sendMessageRemind(appSettingTypeEnum.getType(),message.getBuyerNick(), message.getTid(), status, templateStr, setting, subNickList, sellerAccount);
return Boolean.TRUE; return Boolean.TRUE;
} }
private void sendMessageRemind(String buyerNick, Long tid, String orderStatus, String template, AppSetting setting, List<String> sendNickList, SellerAccountDTO sellerAccountDTO) { private void sendMessageRemind(Integer type, String buyerNick, Long tid, String orderStatus, String template, AppSetting setting, List<String> sendNickList, SellerAccountDTO sellerAccountDTO) {
// TODO 使用本地数据 // TODO 使用本地数据
TopTrade trade = topTradeRepository.findByTid(tid); TopTrade trade = topTradeRepository.findByTid(2148563198943032631L);
if (trade != null) { if (trade != null) {
topTradeRepository.updateOrderStatus(orderStatus, tid); topTradeRepository.updateOrderStatus(orderStatus, tid);
List<TopOrder> orderList = topOrderRegistry.findByTid(tid);
// 订单支付成功
if (type.equals(AppSettingTypeEnum.PAYMENT_SUCCESSFUL.getType())) {
topTradeRepository.updateOrderStatusPaySuccess(orderStatus, tid, DateUtil.date());
}
// 订单发货
if (type.equals(AppSettingTypeEnum.MESSAGE_SHIPMENT_REMINDER.getType())) {
topTradeRepository.updateOrderStatusByShipDate(orderStatus, tid, DateUtil.date());
}
// 交易成功
if (type.equals(AppSettingTypeEnum.SUCCESSFUL_TRANSACTION_REMINDER.getType())) {
topTradeRepository.updateOrderStatusSuccessfulTransaction(orderStatus, tid, DateUtil.date());
}
List<TopOrder> orderList = topOrderRegistry.findByTid(2148563198943032631L);
if (!CollectionUtils.isEmpty(orderList)) { if (!CollectionUtils.isEmpty(orderList)) {
trade.setOrders(orderList); trade.setOrders(orderList);
} }
@ -416,7 +431,10 @@ public class TopTradeServiceImpl implements TopTradeService {
// 创建任务详情信息 // 创建任务详情信息
createTaskMessageInfo(prepareMsg, setting, sendNickList, trade, taskMessageId); createTaskMessageInfo(prepareMsg, setting, sendNickList, trade, taskMessageId);
// 放入缓存 // 放入缓存
String timeFormat = TimeUtil.timeFormat(); String timeFormat = sellerAccountDTO.getId()
.toString()
.concat(StrUtil.DASHED)
.concat(TimeUtil.timeFormat());
Map<String, String> sendMessageCache = cacheManagerUtil.getCache Map<String, String> sendMessageCache = cacheManagerUtil.getCache
(MessageConstants.SEND_MESSAGE_KEY, timeFormat); (MessageConstants.SEND_MESSAGE_KEY, timeFormat);
if (CollectionUtils.isEmpty(sendMessageCache)) { if (CollectionUtils.isEmpty(sendMessageCache)) {

@ -3,16 +3,20 @@ package com.hchbox.task;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import com.hchbox.config.MiProperties; import com.hchbox.config.MiProperties;
import com.hchbox.constant.DefaultNumberConstants; import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.constant.TaoBaoDataMethodConstants;
import com.hchbox.dto.SellerAccountDTO; import com.hchbox.dto.SellerAccountDTO;
import com.hchbox.entity.master.TopOrder; import com.hchbox.entity.master.TopOrder;
import com.hchbox.entity.master.TopTrade; import com.hchbox.entity.master.TopTrade;
import com.hchbox.entity.slaver.JdpTrade; import com.hchbox.entity.slaver.JdpTrade;
import com.hchbox.enums.TradeEnum; import com.hchbox.enums.TradeEnum;
import com.hchbox.service.*; import com.hchbox.service.*;
import com.hchbox.uitl.TaoBaoEncryption;
import com.hchbox.util.CommConverter; import com.hchbox.util.CommConverter;
import com.taobao.api.ApiException; import com.taobao.api.ApiException;
import com.taobao.api.SecretException;
import com.taobao.api.domain.Trade; import com.taobao.api.domain.Trade;
import com.taobao.api.internal.util.TaobaoUtils; import com.taobao.api.internal.util.TaobaoUtils;
import com.taobao.api.response.TradeFullinfoGetResponse; import com.taobao.api.response.TradeFullinfoGetResponse;
@ -69,7 +73,7 @@ public class SyncTask {
@Async("pullOrderTaskExecutor") @Async("pullOrderTaskExecutor")
@Scheduled(cron = "0 0/10 * * * *") @Scheduled(cron = "0 0/10 * * * *")
// @Scheduled(cron = "0 0/1 * * * *") // @Scheduled(cron = "0 0/1 * * * *")
public void pullOrdersRegularly() throws ApiException { public void pullOrdersRegularly() throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
log.info("====== [ the pull order start the time as {} ] ======", startTime); log.info("====== [ the pull order start the time as {} ] ======", startTime);
DateTime date = DateUtil.date(); DateTime date = DateUtil.date();
@ -88,7 +92,7 @@ public class SyncTask {
} }
public void syncOrder(Date date) throws ApiException { public void syncOrder(Date date) throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
count.incrementAndGet(); count.incrementAndGet();
List<Trade> list = new ArrayList<>(); List<Trade> list = new ArrayList<>();
Date startTime; Date startTime;
@ -111,6 +115,14 @@ public class SyncTask {
// 卖家昵称分组 // 卖家昵称分组
Map<String, List<Trade>> tradeListMap = list.stream(). Map<String, List<Trade>> tradeListMap = list.stream().
collect(Collectors.groupingBy(Trade::getSellerNick)); collect(Collectors.groupingBy(Trade::getSellerNick));
List<String> fieldName = Lists.newArrayList(
TaoBaoDataMethodConstants.BUYER_NICK,
TaoBaoDataMethodConstants.BUYER_EMAIL,
TaoBaoDataMethodConstants.RECEIVER_NAME,
TaoBaoDataMethodConstants.RECEIVER_PHONE,
TaoBaoDataMethodConstants.BUYER_ALIPAY_NO,
TaoBaoDataMethodConstants.RECEIVER_ADDRESS,
TaoBaoDataMethodConstants.ENCRYPT_ALI_PAY_ID);
TopTrade syncTask; TopTrade syncTask;
for (Map.Entry<String, List<Trade>> stringListEntry : tradeListMap.entrySet()) { for (Map.Entry<String, List<Trade>> stringListEntry : tradeListMap.entrySet()) {
String sellerNick = stringListEntry.getKey(); String sellerNick = stringListEntry.getKey();
@ -120,6 +132,10 @@ public class SyncTask {
List<Trade> trades = stringListEntry.getValue(); List<Trade> trades = stringListEntry.getValue();
log.info(" ========== the analyze the order quantity size as {} ========== ", trades.size()); log.info(" ========== the analyze the order quantity size as {} ========== ", trades.size());
if (!CollectionUtils.isEmpty(trades)) { if (!CollectionUtils.isEmpty(trades)) {
TaoBaoEncryption.decrypt(miProperties, sellerAccount.getSessionKey(), trades, fieldName);
// 手机号码单独解密
TaoBaoEncryption.decrypt(miProperties, sellerAccount.getSessionKey(), trades, TaoBaoDataMethodConstants.PHONE,
Trade.class.getDeclaredField(TaoBaoDataMethodConstants.RECEIVER_MOBILE));
for (Trade trade : trades) { for (Trade trade : trades) {
syncTask = new TopTrade(); syncTask = new TopTrade();
BeanUtil.copyProperties(trade, syncTask); BeanUtil.copyProperties(trade, syncTask);
@ -134,7 +150,10 @@ public class SyncTask {
sellerAccount.getMessageCount() : DefaultNumberConstants.ZERO_NUMBER; sellerAccount.getMessageCount() : DefaultNumberConstants.ZERO_NUMBER;
int totalAmount = messageCount + trades.size(); int totalAmount = messageCount + trades.size();
sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount); sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount);
// TODO 同步数据发送
if (sellerAccount.getMassNum() != null && totalAmount > sellerAccount.getMassNum()) { if (sellerAccount.getMassNum() != null && totalAmount > sellerAccount.getMassNum()) {
log.info("======================== the massNum as {} trades size as {} ==================",
sellerAccount.getMassNum(), trades.size());
// 删除数据推送 // 删除数据推送
taoBaoRdsPushService.deletePushUser(sellerNick); taoBaoRdsPushService.deletePushUser(sellerNick);
// 修改账号状态 // 修改账号状态

@ -110,12 +110,14 @@ public class TaoBaoEncryption {
if (sc == null) { if (sc == null) {
sc = new SecurityClient sc = new SecurityClient
(TaoBaoApiClient.getTaoBaoClient(miProperties), (TaoBaoApiClient.getTaoBaoClient(miProperties),
miProperties.getAppSecret()); miProperties.getRandomString());
} }
Map<String, String> decryptMap = sc.decrypt(needDecrypt, type, sessionKey); Map<String, String> decryptMap = sc.decrypt(needDecrypt, type, sessionKey);
for (String nick : decryptMap.keySet()) { for (Map.Entry<String, String> nick : decryptMap.entrySet()) {
for (T obj : rsMap.get(nick)) { if (rsMap != null && !CollectionUtils.isEmpty(rsMap.get(nick.getKey()))) {
field.set(obj, decryptMap.get(nick)); for (T obj : rsMap.get(nick.getKey())) {
field.set(obj, nick.getValue());
}
} }
} }
} }
@ -157,9 +159,9 @@ public class TaoBaoEncryption {
miProperties.getAppSecret()); miProperties.getAppSecret());
Map<String, String> decryptMap = sc.decrypt(needDecrypt, type, sessionKey); Map<String, String> decryptMap = sc.decrypt(needDecrypt, type, sessionKey);
for (Map.Entry<String, String> nick : decryptMap.entrySet()) { for (Map.Entry<String, String> nick : decryptMap.entrySet()) {
if (rsMap != null && !CollectionUtils.isEmpty(rsMap.get(nick.getValue()))) { if (rsMap != null && !CollectionUtils.isEmpty(rsMap.get(nick.getKey()))) {
for (T obj : rsMap.get(nick.getValue())) { for (T obj : rsMap.get(nick.getKey())) {
field.set(obj, decryptMap.get(nick.getValue())); field.set(obj, nick.getValue());
} }
} }
} }

@ -27,6 +27,12 @@
<groupId>com.hchbox</groupId> <groupId>com.hchbox</groupId>
<artifactId>trade-common</artifactId> <artifactId>trade-common</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
@ -103,6 +109,8 @@
<groupId>org.apache.shardingsphere</groupId> <groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId> <artifactId>sharding-jdbc-spring-namespace</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

@ -2,7 +2,7 @@ spring:
application: application:
name: @artifactId@ name: @artifactId@
profiles: profiles:
active: prod active: dev
server: server:
port: 8852 port: 8852

Loading…
Cancel
Save