1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.fdkankan.manage.task;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.dingtalk.DingTalkSendUtils;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.entity.RtkAccount;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.service.IRtkAccountService;
- import com.fdkankan.redis.util.RedisUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- @Service
- @Slf4j
- public class TaskService {
- @Autowired
- RedisUtil redisUtil;
- @Autowired
- IRtkAccountService rtkAccountService;
- @Autowired
- DingdingService dingdingService;
- @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60 )
- public void task() {
- try {
- checkAccount();
- }catch (Exception e){
- log.info("定时任务checkAccount出错:",e);
- }
- }
- @Scheduled(initialDelay = 3500, fixedDelay = 1000 * 60 * 60 )
- public void task2() {
- try {
- checkAccountDb();
- }catch (Exception e){
- log.info("定时任务checkAccountDb出错:",e);
- }
- }
- /**
- * 检查账号
- */
- public void checkAccount() {
- HashMap<String, RtkAccount> map = new HashMap<>();
- String redisKey = "4dkankan:rtk:snCode:*";
- Set<String> keys = redisUtil.keys(redisKey);
- if(keys!= null && !keys.isEmpty()){
- for (String key : keys) {
- String jsonStr = redisUtil.get(key);
- RtkAccount rtkAccount = JSONObject.parseObject(jsonStr, RtkAccount.class);
- map.put(rtkAccount.getUserName(),rtkAccount);
- }
- }
- LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(RtkAccount::getStatus,2);
- List<RtkAccount> list = rtkAccountService.list(wrapper);
- for (RtkAccount rtkAccount : list) {
- if(map.containsKey(rtkAccount.getUserName())){
- continue;
- }
- rtkAccountService.updateAccountStatus(rtkAccount.getId(),1);
- }
- }
- /**
- * 检查账号 账号库存不足,钉钉通知
- */
- public void checkAccountDb() {
- LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(RtkAccount::getStatus,0,1);
- wrapper.orderByAsc(RtkAccount::getUpdateTime);
- List<RtkAccount> list = rtkAccountService.list(wrapper);
- if(list == null || list.isEmpty()){
- dingdingService.sendDingDingMsg(0);
- return;
- }
- dingdingService.modelThreshold(list.size(),rtkAccountService.count());
- }
- }
|