增加子账号操作

master
bynt 3 years ago
parent b7e633a087
commit 8ba6d06eb5

1
.gitignore vendored

@ -5,6 +5,7 @@ log/
logs/
### JetBrains template
.idea
*.iml

@ -75,6 +75,11 @@ public class SellerAccountController {
}
/**
* id
* @param accountId
* @return
*/
@GetMapping("/subAccount")
@ApiOperation("父类查找子类集合")
public CommonResult<List<SubAccountsVo>> getSubAccount(@RequestParam Long accountId) {
@ -109,4 +114,14 @@ public class SellerAccountController {
return sellerAccountService.marketOrderTime(sellerAccountDTO);
}
@GetMapping("/getSubAccount")
@ApiOperation("获取子账号列表")
public CommonResult<SubAccountsVo> getSubAccount(@SellerUser SellerAccountDTO sellerAccountDTO) {
if (sellerAccountDTO == null) {
return new CommonResult<SubAccountsVo>().accountException();
}
return new CommonResult<SubAccountsVo>().success
(sellerAccountService.queryAccountByParentIdAndStatus(sellerAccountDTO.getParentId()));
}
}

@ -2,10 +2,8 @@ package com.hchbox.controller;
import cn.hutool.core.date.DateUtil;
import com.hchbox.entity.slaver.JdpTrade;
import com.hchbox.hander.TaoBaoHandler;
import com.hchbox.service.JdpTradeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -13,7 +11,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* @author Enzo

@ -3,6 +3,7 @@ package com.hchbox;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import com.hchbox.api.TaoBaoApiClient;
import com.hchbox.config.MiProperties;
import com.hchbox.constant.TaoBaoDataMethodConstants;
import com.hchbox.entity.slaver.JdpTrade;
@ -13,8 +14,12 @@ import com.hchbox.uitl.TaoBaoEncryption;
import com.hchbox.util.CacheManagerUtil;
import com.taobao.api.ApiException;
import com.taobao.api.SecretException;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.Trade;
import com.taobao.api.internal.util.TaobaoUtils;
import com.taobao.api.request.JushitaJdpUsersGetRequest;
import com.taobao.api.response.JushitaJdpUsersGetResponse;
import com.taobao.api.response.ShopSellerGetResponse;
import com.taobao.api.response.TradeFullinfoGetResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -117,7 +122,9 @@ public class SlaverTest {
@Test
public void getAccount() {
topTradeRepository.countByTid(2148563198943032631L);
JushitaJdpUsersGetRequest req = new JushitaJdpUsersGetRequest();
JushitaJdpUsersGetResponse taoBaoResponse = TaoBaoApiClient.createTaoBaoResponse(req, miProperties, "50008100e30jK5wbSc8ckukKQhTQE6Ejt6l0WCiFQi1c897360XhQXFHMzjyzzpSep");
taoBaoResponse.getTotalResults();
}
@ -144,7 +151,7 @@ public class SlaverTest {
@Test
public void findUserList() {
taoBaoRdsPushService.turnOnPushService("50008400241xjDTcDePNGtjMCsvtS9byhUEIpESqjccFrgkxXi6Fe16809637nng5v",30L);
taoBaoRdsPushService.turnOnPushService("50008501339rkqzU1HKxcsSCZgfw9kvVEFHtLWmTvAj5BrpAWqq11d46634A7sUO8u",2L);
}
@Test

@ -31,6 +31,10 @@ public class SendTemplate implements Serializable {
@ApiModelProperty(value = "用户id")
private Long userId;
@Column(name = "template_name")
@ApiModelProperty(value = "模板名称")
private String templateName;
@CreationTimestamp
@Column(name = "create_time")
@ApiModelProperty(value = "创建时间")

@ -39,9 +39,10 @@ public interface SellerAccountRepository extends JpaRepository<SellerAccount, Lo
/**
* 使
* 使
*
* @param status
* @param parentId
* @return
*/
@Query("from SellerAccount where status = ?1 and parentId = ?2")

@ -35,4 +35,22 @@ public interface JdpTradeRepository extends JpaRepository<JdpTrade, Integer>, Jp
*/
@Query(value = "select j from JdpTrade j where j.sellerNick = ?1 and j.jdpModified between ?2 and ?3")
List<JdpTrade> findJdpTradeByTimeAndNickname(String nickname, Date startTime, DateTime endTime);
/**
*
* @param nickname
* @return
*/
@Query(value = "select count(j) from JdpTrade j where j.sellerNick = ?1")
Integer countSizeBySellerNick(String nickname);
/**
*
* @param nickname
* @param created
* @return
*/
@Query(value = "select count(j) from JdpTrade j where j.sellerNick = ?1 and j.created > ?2")
Integer countSizeBySellerNickAndTime(String nickname,Date created);
}

@ -28,4 +28,19 @@ public interface JdpTradeService {
*/
List<JdpTrade> findJdpOrderByTimeAndNickName(String nickname, Date startTime, DateTime endTime);
/**
*
* @param nickname
* @return
*/
Integer numberQueriesBySellerNick(String nickname);
/**
*
* @param nickname
* @param parse
* @return
*/
Integer numberQueriesBySellerNick(String nickname, DateTime parse);
}

@ -92,10 +92,10 @@ public interface SellerAccountService {
/**
* id
*
* @param parentId
* @return
*/
List<SellerAccount> queryAccountByParentId();
List<SellerAccount> queryAccountByParentIdAndStatus(Long parentId);
/**
* id
@ -180,4 +180,5 @@ public interface SellerAccountService {
* @return
*/
Boolean updateAccountStatusAndExpiration(Long id, int status, DateTime date);
}

@ -76,6 +76,9 @@ public class AppSettingServiceImpl implements AppSettingService {
appSetting.setIsDeliveryRemind(vo.getDeliverRemind());
appSetting.setIsDistribution(vo.getEnableDistribution());
appSetting.setMemoContent(EmojiUtil.toAlias(vo.getSendMessage()));
if (!CollectionUtils.isEmpty(vo.getSendAccountId())) {
appSetting.setSendAccountIds(Joiner.on(StrUtil.COMMA).skipNulls().join(vo.getSendAccountId()));
}
if (!CollectionUtils.isEmpty(vo.getNotSendProduct())) {
appSetting.setNotSendMerchandise(Joiner.on(StrUtil.COMMA).skipNulls().join(vo.getNotSendProduct()));
}
@ -107,6 +110,9 @@ public class AppSettingServiceImpl implements AppSettingService {
if (byUserIdAndType.getNotSendMerchandise() != null) {
appConfigVo.setNotSendProduct(Convert.toList(Long.class, byUserIdAndType.getNotSendMerchandise().split(StrUtil.COMMA)));
}
if (byUserIdAndType.getSendAccountIds() != null) {
appConfigVo.setSendAccountId(Convert.toList(Long.class, byUserIdAndType.getSendAccountIds().split(StrUtil.COMMA)));
}
if (byUserIdAndType.getNotSendFlagStr() != null) {
appConfigVo.setNotSendFlag(Convert.toList(Integer.class, byUserIdAndType.getNotSendFlagStr().split(StrUtil.COMMA)));
}

@ -31,4 +31,15 @@ public class JdpTradeServiceImpl implements JdpTradeService {
public List<JdpTrade> findJdpOrderByTimeAndNickName(String nickname, Date startTime, DateTime endTime) {
return jdpTradeRepository.findJdpTradeByTimeAndNickname(nickname, startTime, endTime);
}
@Override
public Integer numberQueriesBySellerNick(String nickname) {
return jdpTradeRepository.countSizeBySellerNick(nickname);
}
@Override
public Integer numberQueriesBySellerNick(String nickname, DateTime parse) {
return jdpTradeRepository.countSizeBySellerNickAndTime(nickname, parse);
}
}

@ -14,6 +14,7 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import com.hchbox.config.MiProperties;
import com.hchbox.constant.AuthConstants;
import com.hchbox.constant.DefaultNumberConstants;
@ -242,6 +243,7 @@ public class SellerAccountServiceImpl implements SellerAccountService {
account.setIsSubAccount(Boolean.TRUE);
return getSaveMapCommonResult(request, account);
}
subAccount.setShopTitle(shop.getTitle());
subAccount.setIsSubAccount(Boolean.TRUE);
subAccount.setLastLoginTime(DateUtil.date());
subAccount.setSessionKey(loginVo.getAccessToken());
@ -312,9 +314,12 @@ public class SellerAccountServiceImpl implements SellerAccountService {
}
@Override
public List<SellerAccount> queryAccountByParentId() {
return sellerAccountRepository.findByParentIdAndStatus(DefaultNumberConstants.ONE_NUMBER,
(long) DefaultNumberConstants.ZERO_NUMBER);
public List<SellerAccount> queryAccountByParentIdAndStatus(Long parentId) {
List<SellerAccount> byParentIdAndStatus = sellerAccountRepository.findByParentIdAndStatus(DefaultNumberConstants.ONE_NUMBER, parentId);
if (!CollectionUtils.isEmpty(byParentIdAndStatus)){
return Convert.toList(SellerAccount.class, byParentIdAndStatus);
}
return Lists.newArrayList();
}
@Override

@ -1,16 +1,14 @@
package com.hchbox.service.impl;
import cn.hutool.extra.emoji.EmojiUtil;
import cn.hutool.json.JSONUtil;
import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.dto.SellerAccountDTO;
import com.hchbox.entity.master.Blacklist;
import com.hchbox.entity.master.SendTemplate;
import com.hchbox.model.param.CommonResult;
import com.hchbox.repository.master.SendTemplateRepository;
import com.hchbox.service.SendTemplateService;
import com.hchbox.util.PageUtil;
import com.hchbox.util.QueryHelp;
import com.hchbox.vo.taobao.TemplateSearchVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
@ -30,6 +28,7 @@ public class SendTemplateServiceImpl implements SendTemplateService {
@Override
public boolean saveTemplate(SellerAccountDTO sellerAccountDTO, SendTemplate sendTemplate) {
log.info("============= the template as {} ============", JSONUtil.toJsonStr(sendTemplate));
sendTemplate.setUserId(sellerAccountDTO.getParentId()
!= DefaultNumberConstants.ZERO_NUMBER ?
sellerAccountDTO.getParentId() :

@ -60,11 +60,11 @@ public class TaskMessageServiceImpl implements TaskMessageService {
private final BlacklistService blacklistService;
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult<String> createTaskSendMessage(SubmitSendMessageVo submitSendMessageVo, SellerAccountDTO sellerAccount) {
List<String> list = new ArrayList<>();
HashMap<String, Object> hashMap = new HashMap<>(DefaultNumberConstants.SIXTEEN_NUMBER);
// Validated 已做校验
int sendSize = submitSendMessageVo.getBuyerInfoList().size();
// 超出时间范围
@ -113,7 +113,18 @@ public class TaskMessageServiceImpl implements TaskMessageService {
message, submitSendMessageVo.getBuyerInfoList(),
submitSendMessageVo.getOrderTidList());
});
return new CommonResult<String>().success(submitSendMessageVo.getBuyerInfoList());
submitSendMessageVo.getBuyerInfoList().forEach(info -> {
if (submitSendMessageVo.getMessageInfo().contains(RemindTemplates.BUYER_NICK)) {
list.add(RemindTemplates.prepareMsg(submitSendMessageVo.getMessageInfo(), info));
}
if (submitSendMessageVo.getMessageInfo().contains(RemindTemplates.SHOP_NAME)) {
list.add(RemindTemplates.prepareMsg(submitSendMessageVo.getMessageInfo(), sellerAccount.getShopTitle()));
}
});
hashMap.put("sendList", list);
hashMap.put("buyerInfoList", submitSendMessageVo.getBuyerInfoList());
return new CommonResult<String>().success(hashMap);
}
return new CommonResult<String>().
forbidden(ResponseCode.SAVE_INFORMATION_FAILED.getDesc());
@ -202,7 +213,7 @@ public class TaskMessageServiceImpl implements TaskMessageService {
.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)) {
cacheManagerUtil.evictCache(MessageConstants.SEND_MESSAGE_KEY, concat);

@ -6,6 +6,7 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.emoji.EmojiUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
@ -349,7 +350,7 @@ public class TopTradeServiceImpl implements TopTradeService {
}
// 2. 查询可发送子账号
List<String> subNickList = sellerAccountService.findSubAccountBySellerNick(sellerAccount.getId());
if (CollectionUtils.isEmpty(subNickList)) {
if (CollectionUtils.isEmpty(subNickList) || StrUtil.isBlank(setting.getSendAccountIds())) {
log.error("================= the sub-account collection is empty =================");
return Boolean.TRUE;
}
@ -380,12 +381,12 @@ public class TopTradeServiceImpl implements TopTradeService {
private void sendMessageRemind(Integer type, String buyerNick, Long tid, String orderStatus, String template, AppSetting setting, List<String> sendNickList, SellerAccountDTO sellerAccountDTO) {
TopTrade trade = topTradeRepository.findByTid(1434820972683809364L);
TopTrade trade = topTradeRepository.findByTid(tid);
if (trade != null) {
// 修改订单状态
updateOrderStatus(type, buyerNick, orderStatus, trade);
List<TopOrder> orderList = topOrderRegistry.findByTid(1434820972683809364L);
List<TopOrder> orderList = topOrderRegistry.findByTid(tid);
if (!CollectionUtils.isEmpty(orderList)) {
trade.setOrders(orderList);
}
@ -428,8 +429,12 @@ public class TopTradeServiceImpl implements TopTradeService {
// 创建任务详情信息
createTaskMessageInfo(prepareMsg, setting, sendNickList, trade, taskMessageId);
List<Long> longs = Convert.toList(Long.class, setting.getSendAccountIds().split(StrUtil.COMMA));
// 放入缓存
String timeFormat = sellerAccountDTO.getId()
String timeFormat = RandomUtil.randomEle(longs)
.toString()
.concat(StrUtil.DASHED)
.concat(TimeUtil.timeFormat());

@ -2,8 +2,10 @@ package com.hchbox.task;
import cn.hutool.core.date.DateUtil;
import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.constant.TimeConstants;
import com.hchbox.entity.master.SellerAccount;
import com.hchbox.repository.master.SellerAccountRepository;
import com.hchbox.service.JdpTradeService;
import com.hchbox.service.SellerAccountService;
import com.hchbox.service.TaoBaoRdsPushService;
import lombok.RequiredArgsConstructor;
@ -14,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @author Enzo
@ -30,10 +33,13 @@ public class AccountTask {
private final TaoBaoRdsPushService taoBaoRdsPushService;
private final JdpTradeService jdpTradeService;
/**
*
*/
@Scheduled(cron = " 0 1 0 * * ?")
@Scheduled(cron = "0 1 0 * * ?")
@Transactional(rollbackFor = Exception.class)
public void deleteAccountAfterExpirationTime() {
List<SellerAccount> sellerAccounts =
@ -62,4 +68,31 @@ public class AccountTask {
}
}
@Scheduled(cron = "0 0 1 * * ?")
public void updateAccountMassNum() {
List<SellerAccount> sellerAccounts =
sellerAccountRepository.findAllByParentId((long) DefaultNumberConstants.ZERO_NUMBER);
for (SellerAccount account : sellerAccounts) {
Integer countNum = jdpTradeService.numberQueriesBySellerNick(account.getNickname());
if (account.getId().equals(DefaultNumberConstants.COLORFUL_PUZZLE_NUMBER)) {
countNum = jdpTradeService.numberQueriesBySellerNick(account.getNickname(),
DateUtil.parse(TimeConstants.COLORFUL_PUZZLE_DATE));
}
if (countNum > DefaultNumberConstants.ZERO_NUMBER) {
sellerAccountService.updateMessageCount(account.getId(), countNum);
if (account.getMassNum() != null
&& account.getMassNum() > DefaultNumberConstants.ZERO_NUMBER
&& countNum > account.getMassNum()) {
// 删除数据推送
taoBaoRdsPushService.deletePushUser(account.getNickname());
// 修改账号状态
sellerAccountService.updateAccountStatusAndExpiration
(account.getId(), DefaultNumberConstants.MINUS_ONE_NUMBER, DateUtil.date());
}
}
}
}
}

@ -24,6 +24,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
@ -67,6 +68,10 @@ public class SyncTask {
private Date lastUpdateTime;
@Value("${system.flag}")
private Boolean flag;
/**
* 10
*/
@ -74,6 +79,7 @@ public class SyncTask {
@Scheduled(cron = "0 0/10 * * * *")
// @Scheduled(cron = "0 0/1 * * * *")
public void pullOrdersRegularly() throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
if (flag != null && flag) {
long startTime = System.currentTimeMillis();
log.info("====== [ the pull order start the time as {} ] ======", startTime);
DateTime date = DateUtil.date();
@ -90,6 +96,7 @@ public class SyncTask {
long endTime = System.currentTimeMillis();
log.info("====== [ the pull order end time consuming as {} ] ======", endTime - startTime);
}
}
public void syncOrder(Date date) throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
@ -145,22 +152,6 @@ public class SyncTask {
memberService.synMemberByTrade(syncTask);
}
}
// 修改同步数量
int messageCount = sellerAccount.getMessageCount() != null ?
sellerAccount.getMessageCount() : DefaultNumberConstants.ZERO_NUMBER;
int totalAmount = messageCount + trades.size();
sellerAccountService.updateMessageCount(sellerAccount.getId(), totalAmount);
if (sellerAccount.getMassNum() != null
&& sellerAccount.getMassNum() > DefaultNumberConstants.ZERO_NUMBER
&& totalAmount > sellerAccount.getMassNum()) {
log.info("======================== the massNum as {} trades size as {} ==================",
sellerAccount.getMassNum(), trades.size());
// 删除数据推送
taoBaoRdsPushService.deletePushUser(sellerNick);
// 修改账号状态
sellerAccountService.updateAccountStatusAndExpiration
(sellerAccount.getId(), DefaultNumberConstants.MINUS_ONE_NUMBER, DateUtil.date());
}
}
}
}

@ -127,4 +127,24 @@ public class RemindTemplates {
}
/**
* 使
*
* @param template template
* @return
*/
public static String prepareMsg(String template, String replaceString) {
if (StringUtils.isBlank(template)) {
return template;
}
// 订单预付款
template = template.replace(RemindTemplates.BUYER_NICK, replaceString);
// 订单预付款
template = template.replace(RemindTemplates.SHOP_NAME, replaceString);
return template;
}
}

@ -2,11 +2,13 @@ package com.hchbox.module.entity;
import com.hchbox.model.entity.BaseTrade;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**

@ -117,4 +117,11 @@ public class DefaultNumberConstants {
public static final String NAT_DELIM = "%";
/**
*
*/
public static final Long COLORFUL_PUZZLE_NUMBER = 12576L;
}

@ -22,5 +22,14 @@ public class TimeConstants {
public static final String YYYY_MM_DD_HH = "yyyy-MM-dd HH";
/**
*
*/
public static final String COLORFUL_PUZZLE_DATE = "2021-11-23 00:00:00";
}

@ -218,9 +218,9 @@ public class BaseAppSetting implements Serializable {
@ApiModelProperty("好评订单不发送")
private Boolean enableGoodOrder;
@Column(name = "send_account_id")
@Column(name = "send_account_ids")
@ApiModelProperty("发送账号信息")
private Long sendAccountId;
private String sendAccountIds;
}

@ -4,7 +4,6 @@ package com.hchbox.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

@ -113,7 +113,7 @@ public class AppConfigVo {
private List<Integer> notSendFlag;
@ApiModelProperty("发送账号id")
private Long sendAccountId;
private List<Long> sendAccountId;
@ApiModelProperty(value = "发送开始时间小时")
private Integer sendHourStart;

@ -13,6 +13,7 @@ import java.util.Date;
@Data
public class SubAccountsVo {
private Long id;
private Long parentId;
private String nickname;
private Integer status;

@ -33,7 +33,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:172.26.59.86}:${NACOS_PORT:8848}
# server-addr: ${NACOS_HOST:118.178.137.129}:${NACOS_PORT:8848}
#server-addr: ${NACOS_HOST:172.26.59.87}:${NACOS_PORT:8848}
gateway:
#网关动态路由

Loading…
Cancel
Save