修改定时消息逻辑,限制每次查询条数

master
wujingtao 3 years ago
parent 76ed8721a7
commit db48940346

@ -70,10 +70,4 @@ public class WwRemindController {
log.info("===========sellerNick:{} 查询消息======", sellerNick);
return new CommonResult<>().success(delayRemindService.selectDelayRemind(sellerNick));
}
@GetMapping("/test")
@ApiOperation("接受消息")
public String test() {
return "测试成功";
}
}

@ -19,9 +19,11 @@ 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);
/**
*

@ -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);
}

@ -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;
}
}

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

Loading…
Cancel
Save