|
@@ -15,6 +15,8 @@ import com.fdkankan.manage.service.IRtkAccountService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.manage.service.IRtkUseLogService;
|
|
|
import com.fdkankan.manage.service.ISysUserService;
|
|
|
+import com.fdkankan.manage.task.DingdingService;
|
|
|
+import com.fdkankan.manage.task.TaskService;
|
|
|
import com.fdkankan.manage.util.SendMailUtils;
|
|
|
import com.fdkankan.manage.vo.request.RtkInfoParam;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
@@ -52,6 +54,10 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
IRtkUseLogService rtkUseLogService;
|
|
|
@Autowired
|
|
|
ISysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ DingdingService dingdingService;
|
|
|
+ @Autowired
|
|
|
+ TaskService taskService;
|
|
|
|
|
|
@Override
|
|
|
public RtkAccount getOneNotUseAccount(String rtkSnCode) {
|
|
@@ -62,16 +68,17 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
return JSONObject.parseObject(jsonStr, RtkAccount.class);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.in(RtkAccount::getStatus,0,1);
|
|
|
wrapper.orderByAsc(RtkAccount::getUpdateTime);
|
|
|
List<RtkAccount> list = this.list(wrapper);
|
|
|
if(list == null || list.isEmpty()){
|
|
|
//账号库存不足,钉钉通知
|
|
|
- sendDingDingMsg(0);
|
|
|
+ dingdingService.sendDingDingMsg(0);
|
|
|
throw new BusinessException(ResultCode.RTK_ACCOUNT_NOT_EXIT);
|
|
|
}
|
|
|
- modelThreshold(list.size() -1);
|
|
|
+ dingdingService.modelThreshold(list.size() -1,this.count());
|
|
|
|
|
|
RtkAccount rtkAccount = null;
|
|
|
RtkUseLog rtkUseLog = rtkUseLogService.getByRtkSn(rtkSnCode);
|
|
@@ -109,73 +116,13 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void modelThreshold(int size) {
|
|
|
- if(size == 0){
|
|
|
- sendDingDingMsg(size);
|
|
|
- return;
|
|
|
- }
|
|
|
- BigDecimal totalCount = new BigDecimal(this.count());
|
|
|
- BigDecimal dbCount = new BigDecimal(size);
|
|
|
|
|
|
- BigDecimal divideCount = totalCount.divide(dbCount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
- BigDecimal thresholdCount = new BigDecimal(this.threshold);
|
|
|
- if(divideCount.compareTo(thresholdCount) >= 0 ){
|
|
|
- sendDingDingMsg(size);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60)
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("正在使用的rtk账号-map:{}",map);
|
|
|
- LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(RtkAccount::getStatus,2);
|
|
|
- List<RtkAccount> list = this.list(wrapper);
|
|
|
- for (RtkAccount rtkAccount : list) {
|
|
|
- if(map.containsKey(rtkAccount.getUserName())){
|
|
|
- continue;
|
|
|
- }
|
|
|
- updateAccountStatus(rtkAccount.getId(),1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- DingTalkSendUtils dingTalkSendUtils;
|
|
|
|
|
|
|
|
|
- private static String msgPattern =
|
|
|
- "**域名**: %s\n\n" +
|
|
|
- "**库存数量**: %s\n\n" ;
|
|
|
|
|
|
|
|
|
- @Value("${main.url}")
|
|
|
- String mainUrl;
|
|
|
- @Value("${dingtalk.threshold:80}")
|
|
|
- String threshold;
|
|
|
-
|
|
|
- private void sendDingDingMsg(Integer count){
|
|
|
- try {
|
|
|
- String format = String.format(msgPattern, mainUrl, count);
|
|
|
- dingTalkSendUtils.sendActioncardMsgToDingRobot(format,"RTK账号库存预警");
|
|
|
- }catch (Exception e){
|
|
|
- log.info("发送钉钉消息失败:{}",e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public Object pageList(RtkInfoParam param) {
|