Merge remote-tracking branch 'origin/dev' into dev

master
bynt 3 years ago
commit 72ca9d738b

@ -20,7 +20,7 @@ import javax.annotation.Resource;
*/
@Slf4j
@ElasticSimpleJob(
jobName = "ConfirmReceiptJob", cron = "0 0/1 * * * ?", shardingTotalCount = 1, overwrite = true, jobEvent = false)
jobName = "ConfirmReceiptJob", cron = "0 0/30 * * * ?", shardingTotalCount = 1, overwrite = true, jobEvent = false)
@Component
public class ConfirmReceiptJob implements SimpleJob {

@ -0,0 +1,36 @@
package com.hchbox.job;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.example.autoconfig.ElasticSimpleJob;
import com.hchbox.module.service.TimerTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
* @author wjt
* @date 2021/11/26
*/
@Slf4j
@ElasticSimpleJob(
jobName = "DeleteExpiredMessageJob", cron = "0 0 0/1 * * ?", shardingTotalCount = 1, overwrite = true, jobEvent = false)
@Component
public class DeleteExpiredMessageJob implements SimpleJob {
@Resource
private TimerTaskService timerTaskService;
private static DeleteExpiredMessageJob deleteExpiredMessageJob;
@PostConstruct
public void init() {
deleteExpiredMessageJob = this;
}
@Override
public void execute(ShardingContext shardingContext) {
deleteExpiredMessageJob.timerTaskService.deleteNotSendMessage();
}
}

@ -16,26 +16,26 @@ import javax.annotation.Resource;
* @date 2021/10/15
*
*/
@Slf4j
@ElasticSimpleJob(
//0 0 5 1 1/1 ? * -------每月1日5点
jobName = "ObtainInfoExportDelJob", cron = "0 0 5 1 1/1 ? *", shardingTotalCount = 1, overwrite = true, jobEvent = false)
@Component
public class ObtainInfoExportDelJob implements SimpleJob {
@Resource
private ObtainInfoService obtainInfoService;
private static ObtainInfoExportDelJob obtainInfoExportDelJob;
@PostConstruct
public void init() {
obtainInfoExportDelJob = this;
}
@Override
public void execute(ShardingContext shardingContext) {
log.info("===============ObtainInfoExportDelJob备份数据到本地开始,{}================", DateUtil.date());
//@Slf4j
//@ElasticSimpleJob(
// //0 0 5 1 1/1 ? * -------每月1日5点
// jobName = "ObtainInfoExportDelJob", cron = "0 0 5 1 1/1 ? *", shardingTotalCount = 1, overwrite = true, jobEvent = false)
//@Component
//public class ObtainInfoExportDelJob implements SimpleJob {
//
// @Resource
// private ObtainInfoService obtainInfoService;
//
// private static ObtainInfoExportDelJob obtainInfoExportDelJob;
//
// @PostConstruct
// public void init() {
// obtainInfoExportDelJob = this;
// }
//
// @Override
// public void execute(ShardingContext shardingContext) {
// log.info("===============ObtainInfoExportDelJob备份数据到本地开始,{}================", DateUtil.date());
// obtainInfoExportDelJob.obtainInfoService.selectExportDel();
}
}
// }
//}

@ -15,26 +15,26 @@ import javax.annotation.Resource;
* @date 2021/10/14
*
*/
@Slf4j
@ElasticSimpleJob(
//每天一点执行0 0 1 * * ?
jobName = "ObtainInfoJob", cron = "0 0 1 * * ?", shardingTotalCount = 1, overwrite = true, jobEvent = false)
@Component
public class ObtainInfoJob implements SimpleJob {
@Resource
private ObtainInfoService obtainInfoService;
private static ObtainInfoJob obtainInfoJob;
@PostConstruct
public void init() {
obtainInfoJob = this;
}
@Override
public void execute(ShardingContext shardingContext) {
log.info("===============ObtainInfoJob同步前一天数据开始,{}================", DateUtil.date());
//@Slf4j
//@ElasticSimpleJob(
// //每天一点执行0 0 1 * * ?
// jobName = "ObtainInfoJob", cron = "0 0 1 * * ?", shardingTotalCount = 1, overwrite = true, jobEvent = false)
//@Component
//public class ObtainInfoJob implements SimpleJob {
//
// @Resource
// private ObtainInfoService obtainInfoService;
//
// private static ObtainInfoJob obtainInfoJob;
//
// @PostConstruct
// public void init() {
// obtainInfoJob = this;
// }
//
// @Override
// public void execute(ShardingContext shardingContext) {
// log.info("===============ObtainInfoJob同步前一天数据开始,{}================", DateUtil.date());
// obtainInfoJob.obtainInfoService.selectAllSave();
}
}
// }
//}

@ -1,44 +0,0 @@
package com.hchbox.module.controller;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
* @author Enzo
* @date : 2021/6/17
*/
@Slf4j
@RestController
@RequestMapping("/wwsend")
public class TestController {
@GetMapping("/test")
public String test(HttpServletRequest request) {
log.info("请求路径:" + request.getRequestURL().toString());
log.info("请求ip" + request.getRemoteAddr());
Enumeration pNames = request.getParameterNames();
Map<String, Object> map = new HashMap<String, Object>(16);
while (pNames.hasMoreElements()) {
String key = pNames.nextElement().toString();
String result = request.getParameter(key);
map.put(key, result);
}
log.info("请求参数:" + new Gson().toJson(map));
return request.getParameter("TAO_MI_TOKEN");
}
@GetMapping("/helloWorld")
public String test(){
return "Hello World Wwsend";
}
}

@ -3,6 +3,7 @@ package com.hchbox.module.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.hchbox.constant.AuthConstants;
import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.dto.BathSendMessageDTO;
@ -56,6 +57,9 @@ public class WwRemindController {
@ApiOperation("接受消息")
public CommonResult<Object> wwDelayRemindController(HttpServletRequest request) {
String token = request.getParameter("TAO_MI_TOKEN");
if (StrUtil.isBlank(token)) {
return new CommonResult<>().error("查詢消息時店鋪token不能為空");
}
SellerAccount sellerAccount = sellerAccountService.findSellerAccountByAccessToken(token);
String sellerNick;
if (ObjectUtil.isEmpty(sellerAccount)) {
@ -67,12 +71,7 @@ public class WwRemindController {
long parentId = sellerAccount.getParentId();
sellerNick = sellerAccountService.findSellerAccountById(parentId).getNickname();
}
log.info("===========sellerNick:{} 查询消息======", sellerNick);
return new CommonResult<>().success(delayRemindService.selectDelayRemind(sellerNick));
}
@GetMapping("/test")
@ApiOperation("接受消息")
public String test() {
return "测试成功";
}
}

@ -17,13 +17,14 @@ public interface AutoTaskMessageRepository extends JpaRepository<AutoTaskMessage
/**
*
*
*
* @param type
* @param startTime
* @param endTime
* @param sellerNick
* @return
*/
@Query("select m from AutoTaskMessage m where m.sendType = ?1 and m.createTime between ?2 and ?3")
AutoTaskMessage findAutoTaskMessageTypeBetweenTime(Integer type, Date startTime, Date endTime);
@Query("select m from AutoTaskMessage m where m.sendType = ?1 and m.sellerNick = ?3 and m.createTime between ?2 and ?3")
AutoTaskMessage findAutoTaskMessageTypeBetweenTime(Integer type, Date startTime, Date endTime, String sellerNick);
}

@ -1,8 +1,10 @@
package com.hchbox.module.dao;
import cn.hutool.core.date.DateTime;
import com.hchbox.module.entity.AutoWaitMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -17,7 +19,18 @@ public interface AutoWaitForMessageRepository extends JpaRepository<AutoWaitMess
*
*
* @param sellerNick
* @param num
* @return
*/
List<AutoWaitMessage> findAllBySender(String sellerNick);
@Query(value = "select * from auto_wait_for_message where sender = ?1 limit 0 , ?2", nativeQuery = true)
List<AutoWaitMessage> findAllBySender(String sellerNick, Integer num);
/**
*
*
* @param creatTime
* @return
*/
@Query(value = "select a.id from AutoWaitMessage as a where a.createTime < ?1")
List<Long> findIdByCreatTime(DateTime creatTime);
}

@ -2,9 +2,12 @@ package com.hchbox.module.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author wujingtao
@ -13,10 +16,13 @@ import java.io.Serializable;
@Data
@Entity
@Table(name = "auto_wait_for_message")
@EntityListeners(AuditingEntityListener.class)
public class AutoWaitMessage implements Serializable {
@Id
@Column(name = "task_id")
@Column(name = "id")
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "taskId")
private Long taskId;
@ApiModelProperty("发送人")
private String sender;
@ -26,4 +32,8 @@ public class AutoWaitMessage implements Serializable {
private String sendMessage;
@ApiModelProperty("接收人")
private String buyer;
@CreationTimestamp
@ApiModelProperty("创建时间")
@Column(name = "create_time")
private Date createTime;
}

@ -1,8 +1,5 @@
package com.hchbox.module.service;
import com.hchbox.module.entity.AutoWaitMessage;
import java.util.List;
import java.util.Map;
/**
* @author wujingtao
@ -15,5 +12,5 @@ public interface DelayRemindService {
* @param sellerNick
* @return
*/
List<AutoWaitMessage> selectDelayRemind(String sellerNick);
Map<String,Object> selectDelayRemind(String sellerNick);
}

@ -12,5 +12,10 @@ public interface TimerTaskService {
* @param settingType
* @param tradeStatus
*/
void sendMessage(Integer settingType,String tradeStatus);
void sendMessage(Integer settingType, String tradeStatus);
/**
*
*/
void deleteNotSendMessage();
}

@ -5,34 +5,56 @@ import com.hchbox.exception.TaoMiCommException;
import com.hchbox.module.dao.AutoWaitForMessageRepository;
import com.hchbox.module.entity.AutoWaitMessage;
import com.hchbox.module.service.DelayRemindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author wujingtao
* @date 2021/09/29
*/
@Service
@Slf4j
public class DelayRemindServiceImpl implements DelayRemindService {
@Resource
private AutoWaitForMessageRepository autoWaitForMessageRepository;
@Value("${timing.task.maxNum}")
private int maxNum;
/**
* 2000falsetrue
*
* @param sellerNick
* @return
*/
@Override
public List<AutoWaitMessage> selectDelayRemind(String sellerNick) {
public Map<String, Object> selectDelayRemind(String sellerNick) {
HashMap<String, Object> map = new HashMap<>(16);
List<AutoWaitMessage> list;
try {
list = autoWaitForMessageRepository.findAllBySender(sellerNick);
list = autoWaitForMessageRepository.findAllBySender(sellerNick, maxNum);
map.put("data", list);
if (CollectionUtil.isNotEmpty(list)) {
for (AutoWaitMessage info : list) {
autoWaitForMessageRepository.deleteById(info.getTaskId());
if (list.size() >= maxNum) {
map.put("isOver", false);
} else {
map.put("isOver", true);
}
autoWaitForMessageRepository.deleteInBatch(list);
} else {
map.put("isOver", true);
}
} catch (Exception e) {
log.error("操作定时任务消息失败.{}", e.getMessage());
throw new TaoMiCommException("请求发送消息失败");
}
return list;
log.info("查询出來的消息条数:{}", list.size());
return map;
}
}

@ -20,6 +20,8 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -71,8 +73,10 @@ public class TimerTaskServiceImpl implements TimerTaskService {
}
// 获取卖家账号信息
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountById(userId);
// 查询可发送子账号
List<String> subNickList = sellerAccountRepository.findByParentId(sellerAccount.getId());
List<String> subNickList = Arrays.asList(as.getSendAccountIds().split(StrUtil.COMMA));
// List<String> subNickList = sellerAccountRepository.findByParentId(sellerAccount.getId());
if (CollectionUtils.isEmpty(subNickList)) {
continue;
}
@ -116,9 +120,10 @@ public class TimerTaskServiceImpl implements TimerTaskService {
return;
}
//创建发送信息
createAutoTaskMessageInfo(templateStr, as, subNickList, info, autoTaskMessage.getId());
long id = createAutoTaskMessageInfo(templateStr, as, subNickList, info, autoTaskMessage.getId());
//创建待发送列表
AutoWaitMessage autoWaitForMessage = new AutoWaitMessage();
autoWaitForMessage.setId(id);
autoWaitForMessage.setTaskId(autoTaskMessage.getId());
autoWaitForMessage.setTaskName(autoTaskMessage.getTaskName());
autoWaitForMessage.setSender(info.getSellerNick());
@ -150,7 +155,7 @@ public class TimerTaskServiceImpl implements TimerTaskService {
}
}
private void createAutoTaskMessageInfo(String templateStr, AppSetting appSetting, List<String> subNickList, TopTrade trade, Long taskId) {
private Long createAutoTaskMessageInfo(String templateStr, AppSetting appSetting, List<String> subNickList, TopTrade trade, Long taskId) {
AutoTaskMessageInfo autoTaskMessageInfo = new AutoTaskMessageInfo();
autoTaskMessageInfo.setTaskId(taskId);
autoTaskMessageInfo.setMessageNick(subNickList.get(DefaultNumberConstants.ZERO_NUMBER));
@ -163,12 +168,12 @@ public class TimerTaskServiceImpl implements TimerTaskService {
String content = RemindTemplates.prepareMsg(templateStr, trade);
// 模板替换
autoTaskMessageInfo.setInfo(content);
autoTaskMessageInfoJpa.save(autoTaskMessageInfo);
return autoTaskMessageInfoJpa.save(autoTaskMessageInfo).getId();
}
private AutoTaskMessage createAutoTaskMessage(AppSetting setting, String template) {
DateTime date = DateUtil.date();
AutoTaskMessage message = autoTaskMessageRepository.findAutoTaskMessageTypeBetweenTime(setting.getType(), DateUtil.beginOfDay(date), DateUtil.endOfDay(date));
AutoTaskMessage message = autoTaskMessageRepository.findAutoTaskMessageTypeBetweenTime(setting.getType(), DateUtil.beginOfDay(date), DateUtil.endOfDay(date), setting.getSellerNick());
if (message != null) {
return message;
}
@ -199,4 +204,19 @@ public class TimerTaskServiceImpl implements TimerTaskService {
}
return list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteNotSendMessage() {
//超过三小时未发送的消息 就被清除
DateTime newDate3 = DateUtil.offsetHour(DateUtil.date(), -3);
List<Long> idList = autoWaitForMessageRepository.findIdByCreatTime(newDate3);
if (CollUtil.isEmpty(idList)) {
return;
}
for (Long id : idList) {
autoWaitForMessageRepository.deleteById(id);
autoTaskMessageInfoJpa.deleteById(id);
}
}
}

@ -47,6 +47,9 @@ hystrix:
snowflake:
workerId: 9
datacenterId: 9
timing:
task:
maxNum: 2000
hchbox:
mi:
appKey: 23042177

Loading…
Cancel
Save