wangchangsheng vor 1 Jahr
Ursprung
Commit
82934c55cc

+ 24 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/controller/OrganizationEvaluationInfoController.java

@@ -10,6 +10,9 @@ import com.ims.eval.util.ExcelUtil;
 import io.swagger.annotations.ApiOperation;
 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;
 
@@ -83,12 +86,31 @@ public class OrganizationEvaluationInfoController {
 	@GetMapping(value = "getEvaluationInfoList")
 	public R getEvaluationInfoList(
 		@RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
-		@RequestParam(value = "indicatorId", required = false) String indicatorId) {
-		Map list = organizationEvaluationInfoService.getEvaluationInfoList(organizationEvaluationId, indicatorId, request);
+		@RequestParam(value = "indicatorId", required = false) String indicatorId,
+		@RequestParam(value = "binSection", required = false) String binSection,
+		@RequestParam(value = "binStage", required = false) String binStage) {
+		Map list = organizationEvaluationInfoService.getEvaluationInfoList(organizationEvaluationId, indicatorId,binSection,binStage, request);
 		return R.ok().data(list);
 	}
 
+	@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 = organizationEvaluationInfoService.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);
+
+
+
+	}
 
 
 	/**

+ 3 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/dao/OrganizationEvaluationInfoMapper.java

@@ -59,7 +59,9 @@ public interface OrganizationEvaluationInfoMapper extends BaseMapper<Organizatio
 
 
 	List<OrganizationEvaluationInfoResDTO> selectEvaluationInfoList(@Param("organizationEvaluationId") String organizationEvaluationId,
-											@Param("indicatorId") String indicatorId);
+											@Param("indicatorId") String indicatorId,
+											@Param("binSection") String binSection,
+											@Param("binStage") String binStage);
 
 
 

+ 3 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/service/IOrganizationEvaluationInfoService.java

@@ -34,8 +34,10 @@ public interface IOrganizationEvaluationInfoService extends IService<Organizatio
 
 	List<Map> getEvaluationIndicatorList(String organizationEvaluationId, String binSection, String binStage, HttpServletRequest request);
 
-	Map getEvaluationInfoList(String organizationEvaluationId, String indicatorId,HttpServletRequest request);
+	Map getEvaluationInfoList(String organizationEvaluationId, String indicatorId, String binSection, String binStage,HttpServletRequest request);
 
 	boolean updateEvaluationInfo(List<JSONObject> jsonObjects);
 
+	byte[] downloadExcel(String organizationEvaluationId, String indicatorId, String binSection, String binStage, HttpServletRequest request)throws Exception;
+
 }

+ 190 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationInfoServiceImpl.java

@@ -11,6 +11,10 @@ import com.ims.eval.entity.dto.response.OrganizationEvaluationInfoResDTO;
 import com.ims.eval.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+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;
@@ -331,11 +335,11 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 	}
 
 	@Override
-	public Map getEvaluationInfoList(String organizationEvaluationId, String indicatorId, HttpServletRequest request) {
+	public Map getEvaluationInfoList(String organizationEvaluationId, String indicatorId, String binSection, String binStage, HttpServletRequest request) {
 
 		Map data = new HashMap();
 		boolean titlemark = true;//标记生成标题
-		List<OrganizationEvaluationInfoResDTO> infoResDTOList = baseMapper.selectEvaluationInfoList(organizationEvaluationId, indicatorId);
+		List<OrganizationEvaluationInfoResDTO> infoResDTOList = baseMapper.selectEvaluationInfoList(organizationEvaluationId, indicatorId,binSection,binStage);
 		List<IndicatorDictionary> dictionaryList = indicatorDictionaryService.list("", indicatorId, "", "");
 
 		//根据组织(公司)id分组
@@ -399,7 +403,7 @@ 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());
 			}
 			mapList.add(indicatormap);
@@ -409,6 +413,189 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 		return data;
 	}
 
+	@Override
+	public byte[] downloadExcel(String organizationEvaluationId, String indicatorId, String binSection, String binStage,HttpServletRequest request) throws Exception{
+
+
+		Map<String ,List<Map<String,String>>> title = new LinkedHashMap();//标题
+		List<Map<String,String>> mapList = new ArrayList<>();//数据list
+		boolean titlemark = true;//标记生成标题
+		List<OrganizationEvaluationInfoResDTO> infoResDTOList = baseMapper.selectEvaluationInfoList(organizationEvaluationId, indicatorId,binSection,binStage);
+		List<IndicatorDictionary> dictionaryList = indicatorDictionaryService.list("", indicatorId, "", "");
+
+		//根据组织(公司)id分组
+		Map<String, List<OrganizationEvaluationInfoResDTO>> groupedData = infoResDTOList.stream()
+			.collect(Collectors.groupingBy(OrganizationEvaluationInfoResDTO::getOrganizationId));
+
+		//遍历按照公司分组后的数据
+		for (Map.Entry<String, List<OrganizationEvaluationInfoResDTO>> entry : groupedData.entrySet()) {
+
+			Map indicatormap = new LinkedHashMap();
+			List<OrganizationEvaluationInfoResDTO> dtoList = entry.getValue();
+
+			Map<String, OrganizationEvaluationInfoResDTO> resultMap = dtoList.stream()
+				.collect(Collectors.toMap(
+					dto -> dto.getChildCode() + "_" + dto.getOptionCode(),
+					dto -> dto,
+					(oldValue, newValue) -> oldValue)); // 解决键重复的情况
+			boolean mark = true;//标记给公司名赋值
+
+			//将子指标分组
+			Map<String, List<IndicatorDictionary>> groupedChildCode = dictionaryList.stream()
+				.collect(Collectors.groupingBy(d -> d.getChildCode() + "," + d.getChildName()));
+
+			if (titlemark) {
+				for (Map.Entry<String, List<IndicatorDictionary>> childCodeEntry : groupedChildCode.entrySet()) {
+
+
+					List<Map<String,String>> titleArray = new ArrayList<>();
+					Map titlemap = new LinkedHashMap();
+					for (IndicatorDictionary d : childCodeEntry.getValue()) {
+						if (!d.getIsShow()) {
+							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);
+
+				}
+				titlemark = false;
+			}
+
+
+
+			for (IndicatorDictionary d : dictionaryList) {
+				if (!d.getIsShow()) {
+					continue;
+				}
+				if (mark) {
+					indicatormap.put("organizationShortName", resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getOrganizationShortName());//公司名
+					mark = false;
+				}
+
+				System.out.println(resultMap.get(d.getChildCode()+"_"+d.getOptionCode()).getId());
+				//指标属性
+				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().toString());
+			}
+			mapList.add(indicatormap);
+		}
+
+
+		// 创建Workbook对象
+		Workbook workbook = new XSSFWorkbook();
+
+		// 创建工作表
+		Sheet sheet = workbook.createSheet(infoResDTOList.get(0).getIndicatorName());
+
+		// 创建单元格样式
+		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(infoResDTOList.get(0).getIndicatorName());
+
+
+		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));
+
+
+        Integer colsize = 1;
+		Integer optioncols = 2;
+		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) {
+				sheet.addMergedRegion(new CellRangeAddress(1, 1, colsize+1, colsize + key2.size()));
+				colsize = colsize + key2.size();
+				for (String  key3 : key2.keySet()) {
+
+					Cell header3Cell2 = headerRow3.createCell(optioncols);
+					header3Cell2.setCellValue(key3);
+					header3Cell2.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++;
+					System.out.println(key2.get(key3)+"="+key3);
+				}
+			}
+		}
+
+		Integer rowdate = 4;
+		for (Map<String,String >  datamaps  : mapList) {
+			Integer colsdata = 1;
+			Row headerRowdate = sheet.createRow(rowdate);
+			Cell dataCell0 = headerRowdate.createCell(0);
+			dataCell0.setCellValue(rowdate-3);
+			dataCell0.setCellStyle(cellStyle);
+			for (String datakey: datamaps.keySet()) {
+
+				Cell dataCell1 = headerRowdate.createCell(colsdata);
+				dataCell1.setCellValue(datamaps.get(datakey).toString());
+				dataCell1.setCellStyle(cellStyle);
+				colsdata++;
+			}
+			rowdate++;
+		}
+
+		//隐藏行
+		sheet.getRow(3).setZeroHeight(true);
+		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, colsize));
+		header0Cell0.setCellStyle(cellStyle);
+
+		// 将Workbook写入字节数组输出流
+		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+		workbook.write(outputStream);
+
+
+		// 将字节数组作为响应体返回,并设置响应头
+		byte[] excelBytes = outputStream.toByteArray();
+		return excelBytes;
+	}
+
 	@Transactional
 	@Override
 	public boolean updateEvaluationInfo(List<JSONObject> jsonObjects) {
@@ -425,7 +612,6 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 				}
 			}
 
-
 			List<OrganizationEvaluationInfo> evaluationInfos =new ArrayList<>();
 			for (Map.Entry<String,Object > entry : idMap.entrySet()) {
 				OrganizationEvaluationInfo info = new OrganizationEvaluationInfo();

+ 6 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationServiceImpl.java

@@ -335,10 +335,11 @@ public class OrganizationEvaluationServiceImpl extends ServiceImpl<OrganizationE
 			//查询当前周期下对应的考评权重(需要考评的单位)
 			List<OrganizationEvaluationRule> evaluationRules = organizationEvaluationRuleService.getOrganizationEvaluationRuleByYearAndCycle(organizationType,checkCycle,year);
 
-			//规则集合
-			List<EvaluateRule> evaluateRuleList = new ArrayList<>();
+
 			//遍历考核的单位
 			for(OrganizationEvaluationRule evaluationRule : evaluationRules){
+				//规则集合
+				List<EvaluateRule> evaluateRuleList = new ArrayList<>();
 				//根据权重获取对应的考评规则
 				//生产经营
 				double scjyWeight = evaluationRule.getScjyWeight();
@@ -367,6 +368,9 @@ public class OrganizationEvaluationServiceImpl extends ServiceImpl<OrganizationE
 				//获取考评规则的id
 				List<String> ruleIds = evaluateRuleList.stream().map(EvaluateRule::getId).collect(Collectors.toList());
 				//通过规则id获取对应的规则明细
+				if(ruleIds.size()<=0){
+					continue;
+				}
 				List<EvaluateRuleInfo> ruleInfos = evaluateRuleInfoService.list(ruleIds);
 				if (null == ruleInfos || ruleInfos.size() <= 0) {
 					continue;

+ 10 - 0
ims-service/ims-eval/src/main/resources/mappers/OrganizationEvaluationInfoMapper.xml

@@ -335,6 +335,16 @@
                 and  ei.indicator_id = #{indicatorId}
             </if>
 
+
+            <if test="binSection !=null and binSection !=''">
+                and bn.id = #{binSection}
+            </if>
+
+
+            <if test="binStage !=null and binStage !=''">
+                and  be.id = #{binStage}
+            </if>
+
             and id.option_code not in ('CZMAX','CZMIN','LRGXKLMAX','LRGXKLMIN','DWQWLRMAX','DWQWLRMIN','WCLDF','LRGXKHMAX','LRGXKHMIN')
         </where>