tempCode
package com.cmbchina.monitor.service.imp;
import com.alibaba.fastjson.JSON;
import com.cmbchina.monitor.entity.kanban.detail.CardDetailDTO;
import org.apache.xmlbeans.impl.jam.provider.ResourcePath;
import org.springframework.util.StringUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static com.cmbchina.monitor.service.imp.KanBanCheckServiceImpl.recordCardIssue;
/**
* @Author IT006915
* @Date 2023/11/28 16:01
*/
public class KanbanCheckRulesImpl {
public static Map<String, List<String>> METHOD_CHECK_CONFIG = new HashMap<>();
public static void main(String[] args) {
setMethodCheckConfig();
CardDetailDTO cardDetailDTO = JSON.parseObject("", CardDetailDTO.class);
checkWorkHours(cardDetailDTO);
}
// 检查卡片工时是否超过35
public static void checkWorkHours(CardDetailDTO cardDetailDTO) {
//判断当前卡片是否需要执行此检查方法
if (!isExecCheck(cardDetailDTO,"checkWorkHours")){
return;
}
System.out.println();
if (cardDetailDTO.getTotalWorkingHours() >= 30){
recordCardIssue(cardDetailDTO.getId(), "提醒", "卡片公共工时已达到30小时");
}
if (cardDetailDTO.getTotalWorkingHours() > 35){
recordCardIssue(cardDetailDTO.getId(), "错误", "卡片公共工时已超过到35小时");
}
}
/**
* 根据执行方法和卡片信息,判断卡片是否需要执行当前检查方法
* @param cardDetailDTO
* @param methodName
* @return
*/
public static boolean isExecCheck(CardDetailDTO cardDetailDTO, String methodName) {
if (METHOD_CHECK_CONFIG.isEmpty() || METHOD_CHECK_CONFIG.get(methodName) == null) {
return false;
}
if (METHOD_CHECK_CONFIG.get(methodName).contains(cardDetailDTO.getCardType().getName()) ||
METHOD_CHECK_CONFIG.get(methodName).contains(cardDetailDTO.getTitle())) {
return true;
}
return false;
}
public static void setMethodCheckConfig() {
Properties configProperties = getConfigProperties();
if (configProperties == null) {
return;
}
Object methodCheckJson = configProperties.get("kanban.method.check");
if (!StringUtils.isEmpty(methodCheckJson)) {
METHOD_CHECK_CONFIG = JSON.parseObject((String)methodCheckJson, Map.class);
}
}
public static Properties getConfigProperties() {
Properties properties = new Properties();
try {
URL resource = ResourcePath.class.getClassLoader().getResource("checkruler.properties");
FileInputStream fileInputStream = new FileInputStream(resource.getPath());
properties.load(new InputStreamReader(fileInputStream, "UTF-8"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
return properties.isEmpty() ? null : properties;
}
}
最轻松的学习方式莫过于在学习中找到属于自己的乐趣,与诸君共勉
浙公网安备 33010602011771号