Browse Source

目标考评修改

wangchangsheng 1 year ago
parent
commit
1584295737

+ 0 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/controller/OrganizationEvaluationInfoController.java

@@ -122,7 +122,6 @@ public class OrganizationEvaluationInfoController {
 		} else {
 			return R.error().data("上传失败");
 		}
-
 	}
 
 

+ 37 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/ResponsibilityIndicatorInfoController.java

@@ -13,6 +13,9 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -245,4 +248,38 @@ public class ResponsibilityIndicatorInfoController {
 		}
 	}
 
+
+
+	@GetMapping("/download-excel")
+	public ResponseEntity<byte[]> downloadExcel(
+		@RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
+		@RequestParam(value = "indicatorId", required = false) String indicatorId,
+		@RequestParam(value = "binSection", required = false) String binSection,
+		@RequestParam(value = "binStage", required = false) String binStage) throws Exception {
+
+
+		byte[] excelBytes = responsibilityIndicatorInfoService.downloadExcel(organizationEvaluationId, indicatorId,binSection,binStage, request);
+		HttpHeaders headers = new HttpHeaders();
+		headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+		headers.setContentDispositionFormData("attachment", "example.xlsx");
+
+		return ResponseEntity.ok().headers(headers).body(excelBytes);
+
+	}
+
+	@PostMapping("/import-excel")
+	public R importExcel(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws Exception {
+
+		boolean b = responsibilityIndicatorInfoService.importExcel(file,request);
+
+		if (b) {
+			return R.ok().data(b);
+		} else {
+			return R.error().data("上传失败");
+		}
+	}
+
+
+
+
 }

+ 7 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IResponsibilityIndicatorInfoService.java

@@ -5,8 +5,10 @@ import com.ims.eval.entity.ResponsibilityIndicatorInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ims.eval.entity.dto.request.ResponsibilityIndicatorInfoUpdateDTO;
 import com.ims.eval.entity.dto.response.ResponsibilityIndicatorInfoResDTO;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -47,4 +49,9 @@ public interface IResponsibilityIndicatorInfoService extends IService<Responsibi
 
 	boolean updateResponsibilityIndicatorInfo(List<JSONObject> jsonObjects);
 
+
+	byte[] downloadExcel(String responsibilityId, String indicatorId, String binSection, String binStage, HttpServletRequest request)throws Exception;
+
+	boolean importExcel(MultipartFile file, HttpServletRequest request) throws Exception;
+
 }

+ 0 - 8
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationInfoServiceImpl.java

@@ -556,8 +556,6 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 							continue;
 						}
 						titlemap.put(d.getChildCode()+"_"+d.getOptionCode(), d.getOptionName());//名称
-//						titlemap.put("ID_" +d.getChildCode()+"_"+d.getOptionCode(), "ID隐藏");//id
-//						titlemap.put("IS_LH_" +d.getChildCode()+"_"+d.getOptionCode(), "是否量化隐藏");//是否量化
 					}
 					titleArray.add(titlemap);
 					title.put(childCodeEntry.getKey().split(",")[1], titleArray);
@@ -590,10 +588,6 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 					}
 					//指标属性
 					indicatormap.put(d.getChildCode() + "_" + d.getOptionCode(), null == resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getNonQuantifiedValue() ? "" : resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getNonQuantifiedValue());
-					//指标id
-//					indicatormap.put("ID_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId());
-					//是否量化
-//					indicatormap.put("IS_LH_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getIsQuantified2()?"1":"2");
 				}
 			}
 			indicatormap.put("state",state);//状态
@@ -689,7 +683,6 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 						sheet.setColumnHidden(optioncols, true);
 					}
 					optioncols++;
-					System.out.println(key2.get(key3)+"="+key3);
 				}
 			}
 		}
@@ -725,7 +718,6 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 			rowdate++;
 		}
 
-
 		//隐藏行
 		sheet.getRow(3).setZeroHeight(true);
 		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, colsize));

+ 220 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/ResponsibilityIndicatorInfoServiceImpl.java

@@ -7,6 +7,7 @@ import com.ims.common.utils.Constant;
 import com.ims.eval.cache.CacheContext;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.dao.ResponsibilityIndicatorInfoMapper;
+import com.ims.eval.entity.DeptResponsibility;
 import com.ims.eval.entity.Indicator;
 import com.ims.eval.entity.OrganizationEvaluationInfo;
 import com.ims.eval.entity.ResponsibilityIndicatorInfo;
@@ -15,13 +16,18 @@ import com.ims.eval.entity.dto.response.IndicatorResDTO;
 import com.ims.eval.entity.dto.response.MyuserResDTO;
 import com.ims.eval.entity.dto.response.OrganizationEvaluationInfoResDTO;
 import com.ims.eval.entity.dto.response.ResponsibilityIndicatorInfoResDTO;
+import com.ims.eval.service.IDeptResponsibilityService;
 import com.ims.eval.service.IIndicatorService;
 import com.ims.eval.service.IResponsibilityIndicatorInfoService;
 import com.ims.eval.service.IUserService;
 import com.ims.eval.util.MathCalculatorUtil;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
@@ -47,6 +53,10 @@ public class ResponsibilityIndicatorInfoServiceImpl extends ServiceImpl<Responsi
 	@Autowired
 	private IIndicatorService indicatorService;
 
+
+	@Autowired
+	private IDeptResponsibilityService deptResponsibilityService;
+
 	@Override
 	public Map<Object, List<ResponsibilityIndicatorInfoResDTO>> planValueList(List<String> deptResponsibilityIds, String dept, HttpServletRequest request) {
 
@@ -316,6 +326,7 @@ public class ResponsibilityIndicatorInfoServiceImpl extends ServiceImpl<Responsi
 				ResponsibilityIndicatorInfo info = new ResponsibilityIndicatorInfo();
 				info.setId(entry.getValue().toString());
 				String quantified = valueMap.get(entry.getKey().replace("ID_","IS_LH_")).toString();
+
 				if ("1".equals(quantified)) {
 
 					if (MathCalculatorUtil.isNumber(String.valueOf(valueMap.get(entry.getKey().replace("ID_", "")).toString()))) {
@@ -325,13 +336,221 @@ public class ResponsibilityIndicatorInfoServiceImpl extends ServiceImpl<Responsi
 					}
 				}
 
+
 				info.setNonQuantifiedValue(valueMap.get(entry.getKey().replace("ID_","")).toString());
 				info.setState(valueMap.get("state").toString());//
 				responsibilityInfos.add(info);
 			}
-			return  this.saveOrUpdateBatch(responsibilityInfos);
+			 boolean b =  this.saveOrUpdateBatch(responsibilityInfos);
+			if(!b){
+				return false;
+			}
+		}
+
+		return false;
+	}
+
+	@Override
+	public byte[] downloadExcel(String responsibilityId, String indicatorId, String binSection, String binStage, HttpServletRequest request) throws Exception {
+
+		Map data = new HashMap();
+		//设置数据头
+		//获取指标名称
+
+		boolean titlemark = true;//标记生成标题
+		Map<String ,List<Map<String,String>>> title = new LinkedHashMap();//保存所有的指标名
+		List<Map> indicatorMap  = getResponsibilityIndicatorList(responsibilityId, binSection, binStage,request);
+
+		List<String> idList = indicatorMap.stream()
+			.map(map -> String.valueOf(map.get("id"))) // 提取每个Map中key为"id"的值,并转换成String
+			.collect(Collectors.toList()); // 将提取的值收集到List中
+		if(null == idList || idList.size()<=0){
+			throw  new CustomException("未查询导数据");
+		}
+		List<IndicatorResDTO> indicatorResDTOS = indicatorService.getGroupChildCodeByIds(idList);
+
+		//根据指标id和指标名分组
+		Map<String, List<IndicatorResDTO>> groupedMap = indicatorResDTOS.stream()
+			.collect(Collectors.groupingBy(dto -> dto.getIndicatorId() + "," + dto.getIndicatorName())); // 根据indicatorId和indicatorName进行分组
+
+		if (titlemark) {
+			// 遍历分组后的Map
+			for (Map.Entry<String, List<IndicatorResDTO>> entry : groupedMap.entrySet()) {
+
+				List<IndicatorResDTO> groupedList = entry.getValue(); // 获取分组后的List
+				if(null == groupedList || groupedList.size()<=0){
+					continue;
+				}
+				// 进一步处理每个分组
+				List<Map<String,String>> titleArray = new ArrayList<>();
+				for (IndicatorResDTO dto : groupedList) {
+					// 处理每个分组中的元素
+					Map titlemap = new LinkedHashMap();
+					titlemap.put("childName",dto.getChildName());//子指标名
+					titlemap.put("key", dto.getOptionName());//名称
+					titlemap.put("code",dto.getChildCode()+"_"+dto.getOptionCode());//名称
+					titlemap.put("flag", dto.getIsQuantified());//是否量化
+					titleArray.add(titlemap);
+				}
+				title.put(entry.getKey().split(",")[1], titleArray);
+			}
+
+			data.put("title",title);
+			titlemark = false;
+		}
+
+
+		//获取数据
+		List<Map> datamapList = new ArrayList<>();
+		List<ResponsibilityIndicatorInfoResDTO> dataList = baseMapper.getResponsibilityInfoList(responsibilityId, indicatorId,"", binSection, binStage);
+
+		Map<String, List<ResponsibilityIndicatorInfoResDTO>> groupeddataMap = dataList.stream().collect(Collectors.groupingBy(ResponsibilityIndicatorInfoResDTO::getOrganizationId)); // 根据organizationId进行分组
+
+		// 遍历分组后的Map
+		for (Map.Entry<String, List<ResponsibilityIndicatorInfoResDTO>> entry : groupeddataMap.entrySet()) {
+			List<ResponsibilityIndicatorInfoResDTO> groupedList = entry.getValue(); // 获取分组后的List
+
+
+			Map<String, ResponsibilityIndicatorInfoResDTO> resultMap = groupedList.stream()
+				.collect(Collectors.toMap(
+					dto -> dto.getChildCode() + "_" + dto.getOptionCode(),
+					dto -> dto,
+					(oldValue, newValue) -> oldValue)); // 解决键重复的情况
+
+
+			Map indicatormap = new HashMap();
+			// 进一步处理每个分组
+			for (IndicatorResDTO d : indicatorResDTOS) {
+				boolean mark = true;//标记给公司名赋值
+				if (mark) {
+					indicatormap.put("organizationShortName", resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getOrganizationShortName());//公司名
+					indicatormap.put("organizationId", resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getOrganizationId());//公司id
+					indicatormap.put("state",resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getState());
+					indicatormap.put("IS_LH_state","3");
+					mark = false;
+				}
+				//指标属性
+				indicatormap.put(d.getChildCode() + "_" + d.getOptionCode(), null == resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getNonQuantifiedValue() ? "" : resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getNonQuantifiedValue());
+				//指标id
+				indicatormap.put("ID_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getId());
+				//是否量化
+				indicatormap.put("IS_LH_" +d.getChildCode() + "_" + d.getOptionCode(),resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getIsQuantified()?"1":"2");
+			}
+			datamapList.add(indicatormap);
+		}
+
+		data.put("value", datamapList);
+
+
+
+		//获取主表对象
+
+		DeptResponsibility responsibility = deptResponsibilityService.getById(responsibilityId);
+//		国电电力2023年关键业绩指标一览表(工程公司)
+		StringBuilder sb = new StringBuilder("国电电力").append(responsibility.getYear()).append("年关键业绩指标一览表(");
+		sb.append(CacheContext.bseIdObject.get(binStage).getStageName()).append(")");
+		// 创建Workbook对象
+		Workbook workbook = new XSSFWorkbook();
+
+		// 创建工作表
+		Sheet sheet = workbook.createSheet(CacheContext.bseIdObject.get(binStage).getStageName());
+
+		// 创建单元格样式
+		CellStyle cellStyle = workbook.createCellStyle();
+		cellStyle.setAlignment(HorizontalAlignment.CENTER);
+		cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+
+		// 设置边框样式
+		cellStyle.setBorderTop(BorderStyle.THIN);
+		cellStyle.setBorderBottom(BorderStyle.THIN);
+		cellStyle.setBorderLeft(BorderStyle.THIN);
+		cellStyle.setBorderRight(BorderStyle.THIN);
+
+		// 创建1、2行作为标题行
+		Row headerRow0 = sheet.createRow(0);
+		Row headerRow1 = sheet.createRow(1);
+		Row headerRow2 = sheet.createRow(2);
+		Row headerRow3 = sheet.createRow(3);
+
+
+		// 设置首行的单元格值
+		Cell header0Cell0 = headerRow0.createCell(0);
+		header0Cell0.setCellValue(sb.toString());
+
+		Cell headerCell0 = headerRow1.createCell(0);
+		headerCell0.setCellValue("序号");
+		headerCell0.setCellStyle(cellStyle);
+		headerCell0.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
+
+		Cell headerCell1 = headerRow1.createCell(1);
+		headerCell1.setCellValue("单位名称");
+		headerCell1.setCellStyle(cellStyle);
+		headerCell1.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
+
+		Cell headerCell2 = headerRow1.createCell(2);
+		headerCell2.setCellValue("单位编码");
+		headerCell2.setCellStyle(cellStyle);
+		headerCell2.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 2, 2));
+
+
+		Cell header3Cell0 = headerRow3.createCell(0);
+		header3Cell0.setCellValue("zhidmap,respId="+responsibilityId);
+
+		Cell header3Cell1 = headerRow3.createCell(1);
+		header3Cell1.setCellValue("organizationShortName");
+
+		Cell header3Cell2 = headerRow3.createCell(2);
+		header3Cell2.setCellValue("organizationId");
+
+
+
+		Integer colsize = 2;
+		Integer optioncols = 3;
+		for (String  key : title.keySet()) {//存在多个标题
+			List<Map<String,String>> titleArray2 = title.get(key);
+			Cell headerCellcolsize = headerRow1.createCell(colsize+1);
+			headerCellcolsize.setCellValue(key);
+			headerCellcolsize.setCellStyle(cellStyle);
+			headerCellcolsize.setCellStyle(cellStyle);
+
+			System.out.println("key="+key);
+
+			for (Map<String,String>  key2 : titleArray2) {
+				if(key2.size()>1){
+					sheet.addMergedRegion(new CellRangeAddress(1, 1, colsize+1, colsize + key2.size()));
+				}
+				colsize = colsize + key2.size();
+				for (String  key3 : key2.keySet()) {
+
+					Cell header3Cell3 = headerRow3.createCell(optioncols);
+					header3Cell3.setCellValue(key3);
+					header3Cell3.setCellStyle(cellStyle);
+
+					Cell header2Cell2 = headerRow2.createCell(optioncols);
+					header2Cell2.setCellValue(key2.get(key3));
+					header2Cell2.setCellStyle(cellStyle);
+
+					// 隐藏列
+					if(key3.startsWith("ID_") || key3.startsWith("IS_LH_")){
+						sheet.setColumnHidden(optioncols, true);
+					}
+					optioncols++;
+				}
+			}
 		}
 
+
+
+		return new byte[0];
+	}
+
+	@Override
+	public boolean importExcel(MultipartFile file, HttpServletRequest request) throws Exception {
+
+
 		return false;
 	}
 }