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

master
wujingtao 3 years ago
parent 76ed8721a7
commit db48940346

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

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

Loading…
Cancel
Save