12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package com.fdkankan.manage.task;
- import com.fdkankan.dingtalk.DingTalkSendUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- @Service
- @Slf4j
- public class DingdingService {
- @Autowired
- DingTalkSendUtils dingTalkSendUtils;
- private static String msgPattern =
- "**域名**: %s\n\n" +
- "**库存数量**: %s\n\n" ;
- @Value("${main.url}")
- String mainUrl;
- @Value("${dingtalk.threshold:80}")
- String threshold;
- 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 = totalCount.divide(dbCount).setScale(2, RoundingMode.HALF_DOWN);
- BigDecimal thresholdCount = new BigDecimal(this.threshold);
- if(divideCount.compareTo(thresholdCount) >= 0 ){
- this.sendDingDingMsg(size);
- }
- }catch (Exception e){
- log.info("modelThreshold--error",e);
- }
- }
- }
|