1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.fdkankan.manage.task;
- import com.fdkankan.dingtalk.DingTalkSendUtils;
- import com.fdkankan.manage.config.NacosScopeConfig;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.cloud.context.config.annotation.RefreshScope;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- @Service
- @Slf4j
- @RefreshScope
- public class DingdingService {
- @Autowired
- DingTalkSendUtils dingTalkSendUtils;
- private static String msgPattern =
- "**域名**: %s\n\n" +
- "**库存数量**: %s\n\n" ;
- @Value("${main.url}")
- String mainUrl;
- public void sendDingDingMsg(Integer count){
- try {
- String format = String.format(msgPattern, mainUrl, count);
- dingTalkSendUtils.sendActioncardMsgToDingRobot(format,"RTK账号库存预警");
- }catch (Exception e){
- log.info("发送钉钉消息失败:{}",e);
- }
- }
- public void modelThreshold(int size,long total) {
- try {
- if(size == 0){
- this.sendDingDingMsg(size);
- return;
- }
- BigDecimal totalCount = new BigDecimal(total);
- BigDecimal dbCount = new BigDecimal(size);
- BigDecimal divideCount = dbCount.divide(totalCount,2,RoundingMode.HALF_DOWN);
- BigDecimal thresholdCount = new BigDecimal(NacosScopeConfig.threshold).setScale(2,RoundingMode.HALF_DOWN);
- log.info("modelThreshold--{},{},{},{}",NacosScopeConfig.threshold,divideCount,thresholdCount,divideCount.compareTo(thresholdCount));
- if(divideCount.compareTo(thresholdCount) >= 0 ){
- this.sendDingDingMsg(size);
- }
- }catch (Exception e){
- log.info("modelThreshold--error:{},{}",size,total,e);
- }
- }
- }
|