Browse Source

业绩对标管理功能开发

hlf 9 months ago
parent
commit
8cf15b8f88

+ 2 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/NoticeManagementController.java

@@ -15,6 +15,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
@@ -205,6 +206,7 @@ public class NoticeManagementController {
 							 @RequestParam(value = "beginDataTime", required = false) String beginDataTime,
 							 @RequestParam(value = "endDataTime", required = false) String endDataTime) {
 		List<EvaluationNotice> list = evaluationNoticeService.circularDisplay(deptId, noticeTitle, beginDataTime, endDataTime);
+		Collections.sort(list);
 		return R.ok().data(list);
 	}
 }

+ 60 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/PerformanceBenchmarkingManageController.java

@@ -5,10 +5,18 @@ import com.ims.eval.config.CustomException;
 import com.ims.eval.entity.PerformanceBenchmarkInfo;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IPerformanceBenchmarkInfoService;
+import com.ims.eval.util.ExcelUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 业绩对标管理
@@ -69,4 +77,56 @@ public class PerformanceBenchmarkingManageController {
 			return R.customError(e.getMessage()).data("失败!");
 		}
 	}
+
+	/**
+	 * 导出
+	 */
+	@GetMapping(value = "/exportExcel", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+	public void exportExcel(@RequestParam(value = "toolCategory") String toolCategory,
+							@RequestParam(value = "manageCategory") String manageCategory,
+							@RequestParam(value = "checkCycle") String checkCycle,
+							@RequestParam(value = "degreeYear") Integer degreeYear,
+							@RequestParam(value = "quarterlyMonth", required = false) Integer quarterlyMonth,
+							HttpServletResponse response) throws IOException {
+		performanceBenchmarkInfoService.exportExcel(toolCategory, manageCategory, checkCycle, degreeYear, quarterlyMonth, response);
+	}
+
+	/**
+	 * 导入
+	 */
+	@PostMapping(value = "/importExcel")
+	public R importExcel(@RequestParam("file") MultipartFile file) {
+		if (!file.isEmpty()) {
+			try {
+				//获取原始的文件名
+				String originalFilename = file.getOriginalFilename();
+				//获取文件类型
+				String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
+				//默认从第一行开始读取
+				int startRows = 1;
+				//获取输入流
+				InputStream is = file.getInputStream();
+				List<PerformanceBenchmarkInfo> performanceBenchmarkInfoList = new ArrayList<>();
+				//Excel导入导出的单元类
+				List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
+				//遍历Excel表每一行的数据
+				for (String[] str : strings) {
+					PerformanceBenchmarkInfo performanceBenchmarkInfo = new PerformanceBenchmarkInfo();
+					performanceBenchmarkInfo.setId(str[0]);
+					performanceBenchmarkInfo.setScalingValue(Double.valueOf(str[8]));
+					performanceBenchmarkInfoList.add(performanceBenchmarkInfo);
+				}
+				boolean b = performanceBenchmarkInfoService.updateBatchById(performanceBenchmarkInfoList);
+				if (b) {
+					return R.ok().data(b);
+				} else {
+					return R.error("导入失败!");
+				}
+			} catch (Exception e) {
+				log.error("错误", e);
+				return R.customError(e.getMessage()).data("失败!");
+			}
+		}
+		return R.error("上传文件为空!");
+	}
 }

+ 8 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/PerformanceBenchmarkInfoMapper.java

@@ -24,6 +24,14 @@ public interface PerformanceBenchmarkInfoMapper extends BaseMapper<PerformanceBe
 												   @Param("isDb") Integer isDb,
 												   @Param("isCb") Integer isCb);
 
+	List<PerformanceBenchmarkInfo> getExportExcelData(@Param("manageCategory") String manageCategory,
+													  @Param("checkCycle") String checkCycle,
+													  @Param("degreeYear") Integer degreeYear,
+													  @Param("quarterlyMonth") Integer quarterlyMonth,
+													  @Param("isBg") Integer isBg,
+													  @Param("isDb") Integer isDb,
+													  @Param("isCb") Integer isCb);
+
 	List<PerformanceBenchmarkInfo> selectList(@Param("manageCategory") String manageCategory,
 											  @Param("checkCycle") String checkCycle,
 											  @Param("degreeYear") Integer degreeYear,

+ 7 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/entity/EvaluationNotice.java

@@ -13,7 +13,7 @@ import java.util.Date;
  */
 @Data
 @EqualsAndHashCode(callSuper = true)
-public class EvaluationNotice extends Model {
+public class EvaluationNotice extends Model implements Comparable<EvaluationNotice> {
 
 	private static final long serialVersionUID = 1L;
 
@@ -61,4 +61,10 @@ public class EvaluationNotice extends Model {
 	private String memo3;
 	//预留字段
 	private String memo4;
+
+	@Override
+	public int compareTo(EvaluationNotice evaluationNotice) {
+		// 按照时间降序排列,所以返回evaluationNotice.createTime - this.createTime的结果
+		return evaluationNotice.getCreateTime().compareTo(this.getCreateTime());
+	}
 }

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

@@ -1,6 +1,8 @@
 package com.ims.eval.entity;
 
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.NullSerializer;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -58,6 +60,7 @@ public class PerformanceBenchmarkInfo extends Model {
 	/**
 	 * 装机容量
 	 */
+	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private Double installCapacity;
 
 	/**
@@ -68,21 +71,25 @@ public class PerformanceBenchmarkInfo extends Model {
 	/**
 	 * 计划值
 	 */
+	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private Double plannedValue;
 
 	/**
 	 * 实际完成值
 	 */
+	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private Double completeValue;
 
 	/**
 	 * 推荐值
 	 */
+	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private Double recommendedValue;
 
 	/**
 	 * 定标值
 	 */
+	@JsonSerialize(nullsUsing = NullSerializer.class)
 	private Double scalingValue;
 
 	/**

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

@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ims.eval.entity.PerformanceBenchmarkInfo;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
 /**
  * @author hlf
  * @date 2024/3/28 14:06
@@ -13,4 +16,5 @@ public interface IPerformanceBenchmarkInfoService extends IService<PerformanceBe
 
 	IPage<PerformanceBenchmarkInfo> listPage(Integer pageNum, Integer pageSize, String toolCategory, String manageCategory, String checkCycle, Integer degreeYear, Integer quarterlyMonth);
 
+	void exportExcel(String toolCategory, String manageCategory, String checkCycle, Integer degreeYear, Integer quarterlyMonth, HttpServletResponse response) throws IOException;
 }

+ 92 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/PerformanceBenchmarkInfoServiceImpl.java

@@ -9,13 +9,18 @@ import com.ims.eval.dao.PerformanceBenchmarkInfoMapper;
 import com.ims.eval.entity.*;
 import com.ims.eval.service.*;
 import lombok.Data;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -68,6 +73,89 @@ public class PerformanceBenchmarkInfoServiceImpl extends ServiceImpl<Performance
 		return baseMapper.selectListPage(page, manageCategory, checkCycle, degreeYear, quarterlyMonth, isBg, isDb, isCb);
 	}
 
+	@Override
+	public void exportExcel(String toolCategory, String manageCategory, String checkCycle, Integer degreeYear, Integer quarterlyMonth, HttpServletResponse response) throws IOException {
+		// 设置响应头信息,以附件形式下载
+		response.setHeader("Content-Disposition", "attachment; filename=performance_benchmark_data.xlsx");
+		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+
+		// 创建新的Excel工作簿
+		Workbook workbook = new XSSFWorkbook();
+
+		// 创建新的工作表
+		Sheet sheet = workbook.createSheet("Sheet1");
+
+		// 创建表头
+		Row headerRow = sheet.createRow(0);
+		List<String> headers = Arrays.asList("ID", "序号", "单位", "装机容量", "指标", "计划值", "实际完成值", "推荐值", "定标值", "是否标杆");
+		for (int i = 0; i < headers.size(); i++) {
+			Cell cell = headerRow.createCell(i);
+			cell.setCellValue(headers.get(i));
+		}
+
+		//行数据
+		int isBg = 0;
+		int isDb = 0;
+		int isCb = 0;
+		if ("标杆".equals(toolCategory)) {
+			isBg = 1;
+		} else if ("达标".equals(toolCategory)) {
+			isDb = 2;
+		} else if ("超标".equals(toolCategory)) {
+			isCb = 3;
+		}
+		List<PerformanceBenchmarkInfo> performanceBenchmarkInfoList = baseMapper.getExportExcelData(manageCategory, checkCycle, degreeYear, quarterlyMonth, isBg, isDb, isCb);
+
+		// 填充数据到工作表
+		int rowIndex = 1; // 从第二行开始填充数据(第一行是表头)
+		for (PerformanceBenchmarkInfo performanceBenchmarkInfo : performanceBenchmarkInfoList) {
+			Row row = sheet.createRow(rowIndex++);
+
+			// 设置ID
+			row.createCell(0).setCellValue(performanceBenchmarkInfo.getId());
+
+			// 设置序号
+			row.createCell(1).setCellValue(rowIndex - 1);
+
+			// 设置其他数据
+			row.createCell(2).setCellValue(performanceBenchmarkInfo.getCompanyShort());
+			if (null != performanceBenchmarkInfo.getInstallCapacity()) {
+				row.createCell(3).setCellValue(performanceBenchmarkInfo.getInstallCapacity());
+			}
+			row.createCell(4).setCellValue(performanceBenchmarkInfo.getIndexName());
+			if (null != performanceBenchmarkInfo.getPlannedValue()) {
+				row.createCell(5).setCellValue(performanceBenchmarkInfo.getPlannedValue());
+			}
+			if (null != performanceBenchmarkInfo.getCompleteValue()) {
+				row.createCell(6).setCellValue(performanceBenchmarkInfo.getCompleteValue());
+			}
+			if (null != performanceBenchmarkInfo.getRecommendedValue()) {
+				row.createCell(7).setCellValue(performanceBenchmarkInfo.getRecommendedValue());
+			}
+			if (null != performanceBenchmarkInfo.getScalingValue()) {
+				row.createCell(8).setCellValue(performanceBenchmarkInfo.getScalingValue());
+			}
+			if (1 == performanceBenchmarkInfo.getIsBg()) {
+				row.createCell(9).setCellValue("是");
+			} else if (0 == performanceBenchmarkInfo.getIsBg()) {
+				row.createCell(9).setCellValue("否");
+			}
+		}
+
+		// 隐藏第一列(ID列)
+		sheet.setColumnHidden(0, true);
+
+		// 将工作簿写入到输出流
+		try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+			workbook.write(outputStream);
+			response.getOutputStream().write(outputStream.toByteArray());
+			response.getOutputStream().flush();
+		}
+
+		// 关闭工作簿
+		workbook.close();
+	}
+
 	/**
 	 * 寻标
 	 *

+ 27 - 0
ims-service/ims-eval/src/main/resources/mappers/PerformanceBenchmarkInfoMapper.xml

@@ -117,4 +117,31 @@
         </where>
     </select>
 
+    <select id="getExportExcelData" resultType="com.ims.eval.entity.PerformanceBenchmarkInfo">
+        select * from performance_benchmark_info
+        <where>
+            <if test="manageCategory != null and manageCategory != ''">
+                AND manage_category = #{manageCategory}
+            </if>
+            <if test="checkCycle != null and checkCycle != ''">
+                AND check_cycle = #{checkCycle}
+            </if>
+            <if test="degreeYear != null and degreeYear != ''">
+                AND degree_year = #{degreeYear}
+            </if>
+            <if test="quarterlyMonth != null and quarterlyMonth != ''">
+                AND quarterly_month = #{quarterlyMonth}
+            </if>
+            <if test="isBg == 1">
+                AND is_bg = 1 order by bg_val desc
+            </if>
+            <if test="isDb == 2">
+                AND is_db = 1 AND is_cb = 1 order by cb_val, db_val desc
+            </if>
+            <if test="isCb == 3">
+                AND is_cb = 1 order by cb_val desc
+            </if>
+        </where>
+    </select>
+
 </mapper>