Browse Source

月度、季度、年度导入导出按照要求优化

xujuanning 5 months ago
parent
commit
f8f9666ebc

+ 20 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/controller/OrganizationEvaluationInfoController.java

@@ -104,7 +104,7 @@ public class OrganizationEvaluationInfoController {
 		@RequestParam(value = "indicatorId", required = false) String indicatorId,
 		@RequestParam(value = "binSection", required = false) String binSection,
 		@RequestParam(value = "binStage", required = false) String binStage) {
-		LambdaQueryWrapper<OrganizationEvaluation> qw = new LambdaQueryWrapper<>();
+	/*	LambdaQueryWrapper<OrganizationEvaluation> qw = new LambdaQueryWrapper<>();
 		qw.eq(OrganizationEvaluation::getId, organizationEvaluationId);
 		List<OrganizationEvaluation> orgEva = organizationEvaluationService.list(qw);
 		StringBuilder sb = new StringBuilder();
@@ -123,16 +123,16 @@ public class OrganizationEvaluationInfoController {
 		HttpServletRequest request = Objects.requireNonNull(attributes).getRequest();
 		JSONObject json = postUserService.getSysUser(request.getHeader("code"), request.getHeader("Blade-Auth"), request);
 		MyuserResDTO user = JSONObject.parseObject(json.getJSONObject("data").toJSONString(), MyuserResDTO.class);
-
+*/
 		Map list = organizationEvaluationInfoService.getEvaluationInfoList(organizationEvaluationId, organizationShortName, indicatorId, binSection, binStage, request);
-		List<Map> value2 = (List<Map>) list.get("value");
+		/*List<Map> value2 = (List<Map>) list.get("value");
 		String s = CacheContext.childCompanyId.get(user.getId());
 		if (s != null) {
 			Set<String> childList = CacheContext.getChildList(s, sb.toString());
 			List<Map> value1 = value2.stream().filter(a -> childList.contains(a.get("organizationId"))).collect(Collectors.toList());
 			list.put("value", value1);
 		}
-
+*/
 		return R.ok().data(list);
 	}
 
@@ -167,6 +167,22 @@ public class OrganizationEvaluationInfoController {
 		}
 	}
 
+	@PostMapping("/import-excel2")
+	public R importExcel2(@RequestParam("file") MultipartFile file, HttpServletRequest request,
+						 @RequestParam(value = "organizationEvaluationId", required = false) String organizationEvaluationId,
+						 @RequestParam(value = "indicatorId") String indicatorId,
+						 @RequestParam(value = "binSection") String binSection,
+						 @RequestParam(value = "binStage") String binStage) throws Exception {
+
+		boolean b = organizationEvaluationInfoService.importExcel2(file, request,organizationEvaluationId,indicatorId,binSection, binStage);
+
+		if (b) {
+			return R.ok().data(b);
+		} else {
+			return R.error().data("上传失败");
+		}
+	}
+
 
 	/**
 	 * 批量修改

+ 4 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IOrganizationEvaluationInfoService.java

@@ -43,8 +43,12 @@ public interface IOrganizationEvaluationInfoService extends IService<Organizatio
 
 	boolean addEvaluationInfo(List<AddEvaluationInfoDTO> addEvaluationInfoDTOs);
 
+	byte[] downloadExcel2(String organizationEvaluationId, String indicatorId, String binSection, String binStage, HttpServletRequest request) throws Exception;
+
 	byte[] downloadExcel(String organizationEvaluationId, String indicatorId, String binSection, String binStage, HttpServletRequest request) throws Exception;
 
+	boolean importExcel2(MultipartFile file, HttpServletRequest request,String organizationEvaluationId, String indicatorId, String binSection, String binStage) throws IOException;
+
 	boolean importExcel(MultipartFile file, HttpServletRequest request) throws IOException;
 
 

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

@@ -596,8 +596,8 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 				indicatormap.put(d.getChildCode() + "_" + d.getOptionCode(), null == ob ? "" : ob);
 				//指标id
 				Object in = null;
-				if(resultMap.get(d.getChildCode() + "_" + d.getOptionCode())!=null&&resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId()!=null){
-					in=resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId();
+				if (resultMap.get(d.getChildCode() + "_" + d.getOptionCode()) != null && resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId() != null) {
+					in = resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId();
 				}
 				indicatormap.put("ID_" + d.getChildCode() + "_" + d.getOptionCode(), in);
 				//indicatormap.put("ID_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getId());
@@ -606,12 +606,11 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 				Object lh = null;
 				if (resultMap.get(d.getChildCode() + "_" + d.getOptionCode()) != null && resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getIsQuantified2() != null) {
 					indicatormap.put("IS_LH_" + d.getChildCode() + "_" + d.getOptionCode(), resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getIsQuantified2() ? "1" : "2");
-				}else {
+				} else {
 					indicatormap.put("IS_LH_" + d.getChildCode() + "_" + d.getOptionCode(), false ? "1" : "2");
 				}
 
 
-
 				//累计分数
 				if (d.getOptionCode().equals("DF") || d.getOptionCode().equals("DF2") || d.getOptionCode().equals("JHDF")) {
 					score = score + resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getQuantifiedValue();
@@ -877,7 +876,224 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 
 
 	@Override
+	public byte[] downloadExcel2(String organizationEvaluationId, String indicatorId, String binSection, String binStage, HttpServletRequest request) throws Exception {
+		//获取用户信息 23031009
+		boolean deptFlag = false;
+		MyuserResDTO user = userService.getSysUser(request);
+		if (null != user) {
+			String deptId = "23031009";
+			if (deptId.equals(user.getDeptId())) {
+				deptFlag = true;
+			}
+		}
+		String[] values = new String[]{"不合格", "待确认", "已确认"};
+
+		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());//名称
+					}
+					titleArray.add(titlemap);
+					title.put(childCodeEntry.getKey().split(",")[1], titleArray);
+
+				}
+				//状态标题头
+				List<Map<String, String>> titleStateArray = new ArrayList<>();
+				Map titleStateMap = new LinkedHashMap();
+				titleStateMap.put("state", "填报状态");
+				titleStateArray.add(titleStateMap);
+				title.put("状态", titleStateArray);
+
+				titlemark = false;
+			}
+
+			String state = "不合格";
+			for (Map.Entry<String, List<IndicatorDictionary>> childCodeEntry : groupedChildCode.entrySet()) {
+
+				for (IndicatorDictionary d : childCodeEntry.getValue()) {
+					if (!d.getIsShow()) {
+						continue;
+					}
+					if (mark) {
+						indicatormap.put("organizationShortName", resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getOrganizationShortName());//公司名
+						indicatormap.put("organizationId", resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getOrganizationId());//公司编号
+
+						String state2 = resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getState();//(-1:不合格;0:待确认;1:已确认)
+						state = stateConvert(state2, true);
+						mark = false;
+					}
+					//指标属性
+					Object ob = null;
+					if (resultMap.get(d.getChildCode() + "_" + d.getOptionCode()) != null && resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getNonQuantifiedValue() != null) {
+						ob = resultMap.get(d.getChildCode() + "_" + d.getOptionCode()).getNonQuantifiedValue();
+					}
+					indicatormap.put(d.getChildCode() + "_" + d.getOptionCode(), null == ob ? "" : ob);
+				}
+			}
+			indicatormap.put("state", state);//状态
+			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);
+
+		// 设置首行的单元格值
+		Cell header0Cell0 = headerRow0.createCell(0);
+		header0Cell0.setCellValue(infoResDTOList.get(0).getIndicatorName());
+
+		Cell headerCell0 = headerRow1.createCell(0);
+		headerCell0.setCellValue("序号");
+		headerCell0.setCellStyle(cellStyle);
+		headerCell0.setCellStyle(cellStyle);
+		Cell headerCell00 = headerRow2.createCell(0);
+		headerCell00.setCellValue("序号");
+		headerCell00.setCellStyle(cellStyle);
+		headerCell00.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
+
+		Cell headerCell1 = headerRow1.createCell(1);
+		headerCell1.setCellValue("单位名称");
+		headerCell1.setCellStyle(cellStyle);
+		headerCell1.setCellStyle(cellStyle);
+		Cell headerCell11 = headerRow2.createCell(1);
+		headerCell11.setCellValue("单位名称");
+		headerCell11.setCellStyle(cellStyle);
+		headerCell11.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
+
+		Cell headerCell2 = headerRow1.createCell(2);
+		headerCell2.setCellValue("单位编码");
+		headerCell2.setCellStyle(cellStyle);
+		headerCell2.setCellStyle(cellStyle);
+		Cell headerCell22 = headerRow2.createCell(2);
+		headerCell22.setCellValue("单位编码");
+		headerCell22.setCellStyle(cellStyle);
+		headerCell22.setCellStyle(cellStyle);
+		sheet.addMergedRegion(new CellRangeAddress(1, 2, 2, 2));
+
+		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);
+			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 header2Cell2 = headerRow2.createCell(optioncols);
+					header2Cell2.setCellValue(key2.get(key3));
+					header2Cell2.setCellStyle(cellStyle);
+					optioncols++;
+				}
+			}
+		}
+
+		Integer rowdate = 3;
+		for (Map<String, String> datamaps : mapList) {
+			Integer colsdata = 1;
+			Row headerRowdate = sheet.createRow(rowdate);
+			Cell dataCell0 = headerRowdate.createCell(0);
+			dataCell0.setCellValue(rowdate - 2);
+			dataCell0.setCellStyle(cellStyle);
+			for (String datakey : datamaps.keySet()) {
+
+				Cell dataCell1 = headerRowdate.createCell(colsdata);
+				dataCell1.setCellValue(datamaps.get(datakey).toString());
+				dataCell1.setCellStyle(cellStyle);
+
+				if ("state".equals(datakey)) {
+					// 创建一个数据验证对象
+					DataValidationHelper validationHelper = sheet.getDataValidationHelper();
+					DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(values);
+					// 设置下拉列表的位置范围为
+					CellRangeAddressList addressList = new CellRangeAddressList(rowdate, rowdate, colsdata, colsdata); // 行索引和列索引从0开始计数
+					// 创建数据验证对象
+					DataValidation validation = validationHelper.createValidation(constraint, addressList);
+
+					// 将数据验证对象应用于单元格
+					sheet.addValidationData(validation);
+				}
+				colsdata++;
+			}
+			rowdate++;
+		}
+
+		//隐藏行
+//		sheet.getRow(3).setZeroHeight(true);
+		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, colsize));
+		header0Cell0.setCellStyle(cellStyle);
+
+		// 将Workb
+		// ook写入字节数组输出流
+		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+		workbook.write(outputStream);
+
+		// 将字节数组作为响应体返回,并设置响应头
+		byte[] excelBytes = outputStream.toByteArray();
+		return excelBytes;
+	}
+
+
+	@Override
 	public boolean importExcel(MultipartFile file, HttpServletRequest request) throws IOException {
+//	public boolean importExcel2(MultipartFile file, HttpServletRequest request, String organizationEvaluationId, String indicatorId, String binSection, String binStage) throws IOException {
 
 		List<LinkedHashMap<String, Object>> dataList = new ArrayList<>();
 		try {
@@ -1000,6 +1216,118 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 		return true;
 	}
 
+
+	@Override
+	public boolean importExcel2(MultipartFile file, HttpServletRequest request, String organizationEvaluationId, String indicatorId, String binSection, String binStage) throws IOException {
+
+//	public boolean importExcel(MultipartFile file, HttpServletRequest request) throws IOException {
+//		String organizationEvaluationId = "b6100f16f52bb1f295fef30c8c615a6a";
+////		String indicatorId = "72e7f322011f14da236b385dc5b87c4e";
+//		String indicatorId = "e574a80a46dd0b43fbc891e19d3af6bc";
+//		String binSection = "1635164631537012737";
+//		String binStage = "1635160119237140482";
+		List<LinkedHashMap<String, Object>> dataList = new ArrayList<>();
+
+		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));
+
+		try {
+			//获取原始的文件名
+			String originalFilename = file.getOriginalFilename();
+			//获取文件类型
+			String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
+			//获取输入流
+			InputStream is = file.getInputStream();
+			Workbook workbook = readExcel(fileType, is);
+
+			Sheet sheet = workbook.getSheetAt(0);
+
+			// 获取总列数和起始行索引
+			int totalColumns = sheet.getRow(3).getLastCellNum();
+			int startingRowIndex = 3;
+
+			Row headerRow = sheet.getRow(2);
+
+			// 遍历每一行数据
+			for (int i = startingRowIndex; i <= sheet.getLastRowNum(); i++) {
+				Row row = sheet.getRow(i);
+				LinkedHashMap<String, Object> dataMap = new LinkedHashMap<>();
+
+				// 遍历每一列数据
+				for (int j = 0; j < totalColumns; j++) {
+					Cell headerCell = headerRow.getCell(j);
+					Cell cell = row.getCell(j);
+
+					String columnName = headerCell.getStringCellValue();
+					String cellValue = "";
+
+					// 根据单元格类型读取对应内容
+					if (cell != null) {
+						switch (cell.getCellType()) {
+							case HSSFCell.CELL_TYPE_STRING:
+								cellValue = cell.getStringCellValue();
+								break;
+							case HSSFCell.CELL_TYPE_NUMERIC:
+								cellValue = String.valueOf(cell.getNumericCellValue());
+								break;
+							case HSSFCell.CELL_TYPE_BOOLEAN:
+								cellValue = String.valueOf(cell.getBooleanCellValue());
+								break;
+							case HSSFCell.CELL_TYPE_BLANK:
+								cellValue = "";
+								break;
+						}
+					}
+					dataMap.put(columnName, cellValue);
+				}
+
+				dataList.add(dataMap);
+			}
+			workbook.close();
+
+			for (Map<String, Object> data : dataList) {
+				List<OrganizationEvaluationInfo> evaluationInfos = new ArrayList<>();
+				for (Map.Entry<String, List<OrganizationEvaluationInfoResDTO>> entry : groupedData.entrySet()) {
+					try {
+//						List<OrganizationEvaluationInfo> organizationEvaluationInfoList = getEvaluationInfoByOptionCodeList(idMap.get("evalId"), idMap.get("indId"), idMap.get("organizationId"), entry.getKey());
+						if (!data.get("单位编码").equals(entry.getKey()) || !data.get("单位名称").equals(entry.getValue().get(0).getOrganizationShortName())) {
+							continue;
+						}
+						for (OrganizationEvaluationInfoResDTO oei : entry.getValue()) {
+							for (String key : data.keySet()) {
+								if (!key.equals(oei.getOptionName())) {
+									continue;
+								}
+								OrganizationEvaluationInfo info = new OrganizationEvaluationInfo();
+//								MathCalculatorUtil.isNumber(String.valueOf(data.get(key)))
+								info.setId(oei.getId());
+								String s = String.valueOf(data.get(key));
+								info.setQuantifiedValue(Double.parseDouble(s));
+								info.setNonQuantifiedValue(s);
+								String state = stateConvert(data.get("填报状态").toString(), false);
+								info.setState(state);
+								info.setState(state);
+								evaluationInfos.add(info);
+							}
+						}
+					} catch (NumberFormatException e) {
+						e.printStackTrace();
+						log.info("当前行出现异常;继续执行后面的记录");
+					}
+				}
+				this.saveOrUpdateBatch(evaluationInfos);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+
+
 	@Transactional
 	@Override
 	public boolean updateEvaluationInfo(List<JSONObject> jsonObjects) {