Commit ebee3499 by zhangkb

添加导出县得分excel方法

parent 5b998d08
......@@ -91,4 +91,19 @@ public class IndicatorsValueCtrl {
@RequestParam String dateString) throws Exception{
indicatorsValueService.fillExcelFileSix(indIds,dateString);
}
@ApiOperation(value = "填充excel file7数据", notes = "填充excel file7数据")
@PostMapping(value = "/fillExcelFileSeven")
public void fillExcelFileSeven(@RequestBody List<String> indIds,@RequestParam int date,
@RequestParam String compareObjString,@RequestParam int groupNum,
@RequestParam int type) throws Exception{
indicatorsValueService.fillExcelXianJuanYanGroup(indIds, date, compareObjString, groupNum,type);
}
@ApiOperation(value = "填充excel file10数据", notes = "填充excel file10数据")
@PostMapping(value = "/fillExcelFileTen")
public void fillExcelXianScore(@RequestBody List<String> indIds,@RequestParam int date,
@RequestParam String compareObjString,@RequestParam int groupNum,@RequestParam int type) throws Exception{
indicatorsValueService.fillExcelXianJuanYanGroup(indIds, date, compareObjString, groupNum,type);
}
}
......@@ -205,7 +205,7 @@ public class IndAcsScoreInfoService {
if(indIdSize!=0) {
if(indIdSize==1) {
List<String> indDateList = baseIndDataService.getIndData(indIdList.get(0), date, compareObjs);
result = CalculateUtils.averageValue(indDateList);
result = CalculateUtils.averageValue(indDateList,0);
}else {
Map<String, Object> env = Maps.newHashMap();
for(String indId : indIdList) {
......
......@@ -4,6 +4,8 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -57,8 +59,129 @@ public class IndicatorsValueService {
@Value("${mongodb.database}")
private String database;
public void fillExcelXianScore(List<String> indIds,int date,
String compareObjString,int groupNum,int type) throws Exception{
String filePath = "D://indicatorsFile/file10.xlsx";
FileInputStream fs=new FileInputStream(filePath);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fs);
XSSFSheet excelSheet = null;
Map<Integer,Integer> cellMap = new HashMap<>();
Map<String,Integer> rowMap = new HashMap<>();
if(type==0 || type==2) {
rowMap.put("score", 3);rowMap.put("improve", 20);
cellMap.put(1, 1);cellMap.put(2, 3);cellMap.put(3, 5);cellMap.put(4, 7);
cellMap.put(5, 9);cellMap.put(6, 11);cellMap.put(7, 13);
if(type==0) {
excelSheet = xssfWorkbook.getSheet("卷烟营销组得分");
}else {
excelSheet = xssfWorkbook.getSheet("专卖管理组得分");
}
}else if(type==1) {
rowMap.put("score", 3);rowMap.put("improve", 17);
cellMap.put(1, 1);cellMap.put(2, 3);cellMap.put(3, 5);cellMap.put(4, 7);
excelSheet = xssfWorkbook.getSheet("烟叶生产组得分");
}
Map<String,String> scoreMap = new HashMap<>();
Map<String,String> improveMap = new HashMap<>();
String[] compareObjs = compareObjString.split(";");
for(String compareObj:compareObjs) {
List<String> scoreValue = new ArrayList<>();
List<String> improveValue = new ArrayList<>();
for(String indId : indIds) {
//获取本期值
Optional<DriveIndCalResult> driveIndCalResult = driveIndResultRepo
.findByIndIdAndDateAndCompareObj(indId, date, compareObj);
if(driveIndCalResult.isPresent()) {
scoreValue.add(driveIndCalResult.get().getScore());
improveValue.add(driveIndCalResult.get().getImproveScore());
}else {
scoreValue.add("0");
improveValue.add("0");
}
}
//计算考核指标综合评分平均值
String scoreAverage = CalculateUtils.averageValue(scoreValue, 0);
//计算改善提升平均值
String improveAverage = CalculateUtils.averageValue(improveValue, 0);
scoreMap.put(compareObj, scoreAverage);
improveMap.put(compareObj, improveAverage);
}
Map<String,Integer> scoreRank = CalculateUtils.rankValue(scoreMap, "0");
List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(scoreRank.entrySet());
Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {
//升序排序
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
});
Map<String,Integer> improveRank = CalculateUtils.rankValue(improveMap, "0");
List<Map.Entry<String,Integer>> improveList = new ArrayList<Map.Entry<String,Integer>>(improveRank.entrySet());
Collections.sort(improveList,new Comparator<Map.Entry<String,Integer>>() {
//升序排序
public int compare(Entry<String, Integer> o1,
Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
});
int rowNum = rowMap.get("score");
for(Map.Entry<String,Integer> map:list){
XSSFRow row = excelSheet.getRow(rowNum);
int cellNum = cellMap.get(groupNum);
row.getCell(cellNum).setCellValue(map.getKey());
row.getCell(cellNum+1).setCellValue(scoreMap.get(map.getKey()));
rowNum++;
}
int improveRowNum = rowMap.get("improve");
for(Map.Entry<String,Integer> map:improveList){
XSSFRow row = excelSheet.getRow(improveRowNum);
int cellNum = cellMap.get(groupNum);
row.getCell(cellNum).setCellValue(map.getKey());
row.getCell(cellNum+1).setCellValue(improveMap.get(map.getKey()));
improveRowNum++;
}
FileOutputStream out=new FileOutputStream(filePath);
out.flush();
xssfWorkbook.write(out);
out.close();
fs.close();
logger.info("填充完成");
}
//填充县级对标卷烟销量分组表excel
public void fillExcelXianJuanYanGroup(List<String> indIds,int date,String compareObjString) throws Exception{
public void fillExcelXianJuanYanGroup(List<String> indIds,int date,
String compareObjString,int groupNum,int type) throws Exception{
String filePath = null;
if(type==0) {
filePath = "D://indicatorsFile/file7.xlsx";
}else if(type==1) {
filePath = "D://indicatorsFile/file8.xlsx";
}else if(type==2) {
filePath = "D://indicatorsFile/file9.xlsx";
}
FileInputStream fs=new FileInputStream(filePath);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fs);
XSSFSheet excelSheet = xssfWorkbook.getSheet("Sheet1");
Map<Integer,Integer> rowInfo = new HashMap<>();
if(type!=2) {
rowInfo.put(1, 3);rowInfo.put(2, 20);rowInfo.put(3, 37);rowInfo.put(4, 54);
rowInfo.put(5, 71);rowInfo.put(6, 88);rowInfo.put(7, 105);
}else {
rowInfo.put(1, 3);rowInfo.put(2, 17);rowInfo.put(3, 31);rowInfo.put(4, 45);
}
Map<String,Integer> cellInfo = new HashMap<>();
cellInfo.put("FC001", 2);cellInfo.put("FC002", 8);cellInfo.put("FC003", 14);
cellInfo.put("FC004", 20);cellInfo.put("FC005", 26);cellInfo.put("FC0011", 2);
cellInfo.put("FC0012", 8);cellInfo.put("FC0020", 14);cellInfo.put("FC0021", 20);
cellInfo.put("FC007", 2);cellInfo.put("FC008", 8);cellInfo.put("FC009", 14);
cellInfo.put("FC0010", 20);
String[] compareObjs = compareObjString.split(";");
Map<String,Object> result = new HashMap<>();
for(String indId : indIds) {
......@@ -107,6 +230,34 @@ public class IndicatorsValueService {
}
result.put(indId, allComObjDataMap);
}
for(Entry<String,Object> entry : result.entrySet()) {
int rowNum = rowInfo.get(groupNum);
int cellNum = cellInfo.get(entry.getKey());
Map<String,Object> allComObjDataMap = (Map<String,Object>)entry.getValue();
int i = 0;
for(String compareObj : compareObjs) {
Map<String,String> dataMap = (Map<String,String>)allComObjDataMap.get(compareObj);
XSSFRow row = excelSheet.getRow(rowNum);
if(cellNum==2) {
row.getCell(cellNum-2).setCellValue(++i);
row.getCell(cellNum-1).setCellValue(compareObj);
}
row.getCell(cellNum).setCellValue(dataMap.get("currentValue"));
row.getCell(cellNum+1).setCellValue(dataMap.get("currentRank"));
row.getCell(cellNum+2).setCellValue(dataMap.get("sameValue"));
row.getCell(cellNum+3).setCellValue(dataMap.get("sameRank"));
row.getCell(cellNum+4).setCellValue(dataMap.get("calGowth"));
row.getCell(cellNum+5).setCellValue(dataMap.get("gowthRank"));
rowNum++;
}
}
FileOutputStream out=new FileOutputStream(filePath);
out.flush();
xssfWorkbook.write(out);
out.close();
fs.close();
logger.info("填充完成");
}
//填充市对标通报一览表
......@@ -249,7 +400,7 @@ public class IndicatorsValueService {
for(DriveIndCalResult result : currentDriveResult) {
values.add(result.getValue());
}
currentValue = CalculateUtils.averageValue(values);
currentValue = CalculateUtils.averageValue(values,0);
}else {
currentValue = currentDriveResult.get(0).getAverage();
if(!"0.0".equals(currentDriveResult.get(0).getActualAverage())) {
......@@ -266,7 +417,7 @@ public class IndicatorsValueService {
for(DriveIndCalResult result : sameDriveResult) {
values.add(result.getValue());
}
sameValue = CalculateUtils.averageValue(values);
sameValue = CalculateUtils.averageValue(values,0);
}else {
sameValue = sameDriveResult.get(0).getAverage();
if(!"0.0".equals(sameDriveResult.get(0).getActualAverage())) {
......
......@@ -56,7 +56,8 @@ public class CalculateUtils {
//将map中的无效值挑出来
for(Entry<String,String> entry : valueMap.entrySet()) {
if("NaN".equals(entry.getValue())||"0(Error)".equals(entry.getValue())
|| "0.0000".equals(entry.getValue()) || "0".equals(entry.getValue())) {
|| "0.0000".equals(entry.getValue()) || "0".equals(entry.getValue())
|| "".equals(entry.getValue())) {
invalidMap.put(entry.getKey(),entry.getValue());
}else {
compareMap.put(entry.getKey(), Double.valueOf(entry.getValue()));
......@@ -117,17 +118,26 @@ public class CalculateUtils {
}
//计算平均值
public static String averageValue(List<String> values) {
public static String averageValue(List<String> values,int type) {
String calValue = "0.0";
StringBuilder formula = new StringBuilder();
if(!values.isEmpty()) {
int size = values.size();
formula.append("(");
for(int i=0;i<values.size();i++) {
if("NaN".equals(values.get(i)) || "0(Error)".equals(values.get(i))
|| "0.0000".equals(values.get(i)) || "0".equals(values.get(i))) {
size -= 1;
continue;
if(type==0) {
if("NaN".equals(values.get(i)) || "0(Error)".equals(values.get(i))
|| "0.0000".equals(values.get(i)) || "0".equals(values.get(i))
|| "".equals(values.get(i))) {
size -= 1;
continue;
}
}else {
if("NaN".equals(values.get(i)) || "0(Error)".equals(values.get(i))
|| "".equals(values.get(i))) {
size -= 1;
continue;
}
}
if(i==values.size()-1) {//最后一个不加+号
formula.append("(").append(values.get(i)).append(")");
......
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