Commit 857a2a86 by zhangkb

提交短板筛选规则代码

parent cf54b542
...@@ -35,4 +35,6 @@ public interface DriveIndCalResultRepository extends MongoRepository<DriveIndCal ...@@ -35,4 +35,6 @@ public interface DriveIndCalResultRepository extends MongoRepository<DriveIndCal
public List<DriveIndCalResult> findByCompareObjAndDateAndIndIdIn(String compareObj,int date,List<String> indIds); public List<DriveIndCalResult> findByCompareObjAndDateAndIndIdIn(String compareObj,int date,List<String> indIds);
public Optional<DriveIndCalResult> findByCompareIdAndCompareObjAndIndIdAndDate(String compareId,String compareObj,String indId,int date); public Optional<DriveIndCalResult> findByCompareIdAndCompareObjAndIndIdAndDate(String compareId,String compareObj,String indId,int date);
public List<DriveIndCalResult> findByIndIdAndDateAndCompareObjIn(String indId,int date,List<String> compareObjs);
} }
package com.keymobile.indicators.service.hytobacco; package com.keymobile.indicators.service.hytobacco;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -11,8 +14,15 @@ import org.springframework.data.domain.PageRequest; ...@@ -11,8 +14,15 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.DriveIndCalResult;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.shortboard.ShortboardDriveIndRel;
import com.keymobile.indicators.model.entity.shortboard.ShortboardItem;
import com.keymobile.indicators.model.entity.shortboard.ShortboardRule; import com.keymobile.indicators.model.entity.shortboard.ShortboardRule;
import com.keymobile.indicators.persistence.hyindicators.DriveIndCalResultRepository;
import com.keymobile.indicators.persistence.hyindicators.ShortboardDriveIndRelRepository;
import com.keymobile.indicators.persistence.hyindicators.ShortboardRuleRepository; import com.keymobile.indicators.persistence.hyindicators.ShortboardRuleRepository;
import com.keymobile.indicators.utils.CalculateUtils;
@Service @Service
public class ShortboardRuleService { public class ShortboardRuleService {
...@@ -20,6 +30,12 @@ public class ShortboardRuleService { ...@@ -20,6 +30,12 @@ public class ShortboardRuleService {
@Autowired @Autowired
private ShortboardRuleRepository shortboardRuleRepo; private ShortboardRuleRepository shortboardRuleRepo;
@Autowired
private ShortboardDriveIndRelRepository shortboardDriveIndRelRepo;
@Autowired
private DriveIndCalResultRepository driveIndCalResultRepo;
@Autowired
private DriveIndDefService driveIndDefService;
public String saveOrUpdate(ShortboardRule shortboardRule,String catalogId, public String saveOrUpdate(ShortboardRule shortboardRule,String catalogId,
String catalogIdPath,String user) { String catalogIdPath,String user) {
...@@ -46,4 +62,157 @@ public class ShortboardRuleService { ...@@ -46,4 +62,157 @@ public class ShortboardRuleService {
} }
return null; return null;
} }
//根据短板规则筛选短板单位
public List<Map<String,String>> getObjShortboard(String compareId,int date,
List<String> compareObjs,List<String> driveIds){
List<Map<String,String>> result = new ArrayList<>();
for(String driveId : driveIds) {
//根据考核指标id获取关联的短板筛选规则id
List<ShortboardDriveIndRel> relations = shortboardDriveIndRelRepo.
findByDriveIndDefId(driveId);
for(ShortboardDriveIndRel rel : relations) {
ShortboardRule shortboardRule = this.getById(rel.getShortboardRuleId());
if(shortboardRule!=null) {
List<ShortboardItem> shortboardItems = shortboardRule.getShortboardItem();
for(ShortboardItem item : shortboardItems) {
}
}
}
}
return result;
}
private void selectShortboardObj(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) {
String type = shortboardItem.getType();
}
//短板筛选规则为均值
private List<DriveIndCalResult> selectAverageShortboard(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) {
List<DriveIndCalResult> calResults = driveIndCalResultRepo.
findByIndIdAndDateAndCompareObjIn(driveId, date, compareObjs);
List<DriveIndCalResult> filterCalResults = new ArrayList<>();//用于保存符合过滤条件的指标结果
List<DriveIndCalResult> realCalResults = new ArrayList<>();//用于保存符合过滤条件的指标结果
for(DriveIndCalResult calResult : calResults) {
//判断规则选择是大于还是小于
if("0".equals(shortboardItem.getCalType())) {//大于
if(!"NaN".equals(calResult.getValue()) && !"0(Error)".equals(calResult.getValue())
&& !"0.0000".equals(calResult.getValue()) && !"0".equals(calResult.getValue())) {
//判断有没有实际的平均值
if(!"0.0".equals(calResult.getActualAverage())) {
if(Double.parseDouble(calResult.getValue()) >
Double.parseDouble(calResult.getActualAverage())) {
filterCalResults.add(calResult);
}
}else {//没有比较组内平均值
if(Double.parseDouble(calResult.getValue()) >
Double.parseDouble(calResult.getAverage())) {
filterCalResults.add(calResult);
}
}
}
}else {//小于
if(!"NaN".equals(calResult.getValue()) && !"0(Error)".equals(calResult.getValue())
&& !"0.0000".equals(calResult.getValue()) && !"0".equals(calResult.getValue())) {
//判断有没有实际的平均值
if(!"0.0".equals(calResult.getActualAverage())) {
if(Double.parseDouble(calResult.getValue()) <
Double.parseDouble(calResult.getActualAverage())) {
filterCalResults.add(calResult);
}
}else {//没有比较组内平均值
if(Double.parseDouble(calResult.getValue()) <
Double.parseDouble(calResult.getAverage())) {
filterCalResults.add(calResult);
}
}
}
}
}
//分析filterCalResults
for(DriveIndCalResult filterCalResult : filterCalResults) {
//判断是比较差还是百分比
if("0".equals(shortboardItem.getAnalysisType())) {//绝对值
//判断有没有实际的平均值
if(!"0.0".equals(filterCalResult.getActualAverage())) {
//获取差值绝对值
Double differ = Math.abs(Double.parseDouble(filterCalResult.getActualAverage())
-Double.parseDouble(filterCalResult.getValue()));
if(differ > Double.parseDouble(shortboardItem.getValue())) {
realCalResults.add(filterCalResult);
}
}else {
//获取差值绝对值
Double differ = Math.abs(Double.parseDouble(filterCalResult.getAverage())
-Double.parseDouble(filterCalResult.getValue()));
if(differ > Double.parseDouble(shortboardItem.getValue())) {
realCalResults.add(filterCalResult);
}
}
}else {//百分比
//判断有没有实际的平均值
if(!"0.0".equals(filterCalResult.getActualAverage())) {
Double percentage = Math.abs(Double.parseDouble(CalculateUtils.calGowth("%",
filterCalResult.getValue(), filterCalResult.getActualAverage(), "1")));
if(percentage > Double.parseDouble(shortboardItem.getValue())) {
realCalResults.add(filterCalResult);
}
}else {
Double percentage = Math.abs(Double.parseDouble(CalculateUtils.calGowth("%",
filterCalResult.getValue(), filterCalResult.getAverage(), "1")));
if(percentage > Double.parseDouble(shortboardItem.getValue())) {
realCalResults.add(filterCalResult);
}
}
}
}
return realCalResults;
}
//短板筛选规则为最大值
private List<DriveIndCalResult> selectMaxShortboard(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) throws Exception{
List<DriveIndCalResult> calResults = driveIndCalResultRepo.
findByIndIdAndDateAndCompareObjIn(driveId, date, compareObjs);
List<DriveIndCalResult> realCalResults = new ArrayList<>();//用于保存符合过滤条件的指标结果
//获取排名第一的最大值
String maxValue = null;
for(DriveIndCalResult calResult : calResults) {
if(calResult.getRank()==1) {
maxValue = calResult.getValue();
}
}
if(maxValue!=null) {
for(DriveIndCalResult calResult : calResults) {
//判断是比较差还是百分比
if("0".equals(shortboardItem.getAnalysisType())) {//绝对值
}else {//百分比
}
}
}
return realCalResults;
}
//短板筛选规则为最小值
private void selectMinShortboard(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) {
}
//短板筛选规则为排名
private void selectRankShortboard(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) {
}
//短板筛选规则为历史同期
private void selectSametimeShortboard(ShortboardItem shortboardItem,
List<String> compareObjs,String driveId,int date) {
}
} }
...@@ -214,23 +214,25 @@ public class CalculateUtils { ...@@ -214,23 +214,25 @@ public class CalculateUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
Map<String,String> map = new HashMap<>(); // Map<String,String> map = new HashMap<>();
map.put("1001", "1"); // map.put("1001", "1");
map.put("1002", "3"); // map.put("1002", "3");
map.put("1003", "2"); // map.put("1003", "2");
map.put("1004", "4"); // map.put("1004", "4");
map.put("1005", "8"); // map.put("1005", "8");
map.put("1006", "6"); // map.put("1006", "6");
map.put("1007", "7"); // map.put("1007", "7");
map.put("1008", "5"); // map.put("1008", "5");
CalculateUtils cal = new CalculateUtils(); // CalculateUtils cal = new CalculateUtils();
Map<String,Integer> result = cal.rankValue(map, "1"); // Map<String,Integer> result = cal.rankValue(map, "1");
System.out.println(result); // System.out.println(result);
//
String formula = "([1001]+[1002])/2"; // String formula = "([1001]+[1002])/2";
formula = formula.replace("[1001]", "3"); // formula = formula.replace("[1001]", "3");
formula = formula.replace("[1002]", "5"); // formula = formula.replace("[1002]", "5");
String result1 = AviatorEvaluator.execute(formula).toString(); // String result1 = AviatorEvaluator.execute(formula).toString();
System.out.println(result1); // System.out.println(result1);
Double b = (double) Math.abs(34-50);
System.out.println(b);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment