Bladeren bron

功能完善

hlf 5 maanden geleden
bovenliggende
commit
527feb8754

+ 33 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/EvaluateRuleInfoController.java

@@ -7,8 +7,12 @@ import com.ims.eval.entity.EvaluateRuleInfo;
 import com.ims.eval.service.IEvaluateRuleInfoService;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -93,4 +97,33 @@ public class EvaluateRuleInfoController {
 		}
 	}
 
+	/**
+	 * 导出-考评规则信息
+	 */
+	@GetMapping(value = "/exportExcel", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+	public void exportExcel(@RequestParam("id") String id,
+							@RequestParam(value = "indicatorName", required = false) String indicatorName,
+							HttpServletResponse response) throws IOException {
+		evaluateRuleInfoService.exportExcel(id, indicatorName, response);
+	}
+
+	/**
+	 * 导入模板
+	 */
+	@GetMapping(value = "/importTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+	public void importTemplate(HttpServletResponse response) throws IOException {
+		evaluateRuleInfoService.importTemplate(response);
+	}
+
+	/**
+	 * 导入
+	 */
+	@PostMapping(value = "/importExcel")
+	public R importExcel(@RequestParam("file") MultipartFile file,
+							   @RequestParam("id") String id,
+							   @RequestParam("userId") String userId,
+							   @RequestParam("userName") String userName) {
+		return evaluateRuleInfoService.importExcel(file, id, userId, userName);
+	}
+
 }

+ 2 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/EvaluateRuleInfoMapper.java

@@ -27,4 +27,6 @@ public interface EvaluateRuleInfoMapper extends BaseMapper<EvaluateRuleInfo> {
 	List<EvaluateRuleInfoIndicatorDTO> selectlistByIndicatorInfo(@Param("ruleInfoIds") List<String> ruleInfoIds);
 
     List<EvaluateRuleInfo> getEvaluateRuleInfoByEvaluateRuleId(@Param("evaluateRuleId") String evaluateRuleId);
+
+	List<EvaluateRuleInfo> selectListByEvaluateRuleId(@Param("evaluateRuleId") String evaluateRuleId, @Param("indicatorName") String indicatorName);
 }

+ 8 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/entity/EvaluateRuleInfo.java

@@ -3,11 +3,11 @@ package com.ims.eval.entity;
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
-import java.util.Date;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.util.Date;
+
 /**
  * <p>
  * 考评规则信息
@@ -38,6 +38,12 @@ public class EvaluateRuleInfo extends Model {
 	@TableField(exist = false)
 	private String indicatorName;
 
+	/**
+	 * 指标code
+	 */
+	@TableField(exist = false)
+	private String indicatorCode;
+
 
 	/**
 	 * 考评规则ID

+ 10 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IEvaluateRuleInfoService.java

@@ -3,7 +3,11 @@ package com.ims.eval.service;
 import com.ims.eval.entity.EvaluateRuleInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ims.eval.entity.dto.response.EvaluateRuleInfoIndicatorDTO;
+import com.ims.eval.entity.dto.result.R;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -27,4 +31,10 @@ public interface IEvaluateRuleInfoService extends IService<EvaluateRuleInfo> {
 	List<EvaluateRuleInfo> getEvaluateRuleInfoByEvaluateRuleId(String evaluateRuleId);
 
 	boolean updateDeleteTime(List<String> ids);
+
+	void exportExcel(String id, String indicatorName, HttpServletResponse response) throws IOException;
+
+	void importTemplate(HttpServletResponse response) throws IOException;
+
+	R importExcel(MultipartFile file, String id, String userId, String userName);
 }

+ 166 - 8
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/EvaluateRuleInfoServiceImpl.java

@@ -2,13 +2,31 @@ package com.ims.eval.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ims.common.utils.StringUtils;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.dao.EvaluateRuleInfoMapper;
 import com.ims.eval.entity.EvaluateRuleInfo;
+import com.ims.eval.entity.Indicator;
 import com.ims.eval.entity.dto.response.EvaluateRuleInfoIndicatorDTO;
+import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IEvaluateRuleInfoService;
+import com.ims.eval.service.IIndicatorService;
+import com.ims.eval.util.ExcelUtil;
+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.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
@@ -23,10 +41,13 @@ import java.util.List;
 @Service
 public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMapper, EvaluateRuleInfo> implements IEvaluateRuleInfoService {
 
+	@Autowired
+	private IIndicatorService indicatorService;
+
 	@Override
-	public List<EvaluateRuleInfo> list(String id, String des, String indicatorId, String evaluateRuleId,String indicatorName) {
+	public List<EvaluateRuleInfo> list(String id, String des, String indicatorId, String evaluateRuleId, String indicatorName) {
 
-		List<EvaluateRuleInfo> list =  baseMapper.selectListAll(id, des, indicatorId, evaluateRuleId,indicatorName);
+		List<EvaluateRuleInfo> list = baseMapper.selectListAll(id, des, indicatorId, evaluateRuleId, indicatorName);
 
 		return list;
 	}
@@ -73,6 +94,143 @@ public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMap
 		return true;
 	}
 
+	@Override
+	public void exportExcel(String id, String indicatorName, HttpServletResponse response) throws IOException {
+		// 设置响应头信息,以附件形式下载
+		response.setHeader("Content-Disposition", "attachment; filename=evaluate_rule.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("序号", "指标编码", "指标名称", "最高分", "最低分", "基准分", "描述");
+		for (int i = 0; i < headers.size(); i++) {
+			Cell cell = headerRow.createCell(i);
+			cell.setCellValue(headers.get(i));
+		}
+
+		//行数据
+		List<EvaluateRuleInfo> evaluateRuleInfoList = baseMapper.selectListByEvaluateRuleId(id, indicatorName);
+
+		// 填充数据到工作表
+		int rowIndex = 1; // 从第二行开始填充数据(第一行是表头)
+		for (EvaluateRuleInfo evaluateRuleInfo : evaluateRuleInfoList) {
+			Row row = sheet.createRow(rowIndex++);
+
+			// 设置数据
+			row.createCell(0).setCellValue(evaluateRuleInfo.getOrderNum());
+			row.createCell(1).setCellValue(evaluateRuleInfo.getIndicatorCode());
+			row.createCell(2).setCellValue(evaluateRuleInfo.getIndicatorName());
+			row.createCell(3).setCellValue(evaluateRuleInfo.getMaxScore());
+			row.createCell(4).setCellValue(evaluateRuleInfo.getMinScore());
+			row.createCell(5).setCellValue(evaluateRuleInfo.getStandardScore());
+			if (null != evaluateRuleInfo.getDes()) {
+				row.createCell(6).setCellValue(evaluateRuleInfo.getDes());
+			}
+		}
+
+		// 自动调整列宽
+		for (int i = 0; i < headers.size(); i++) {
+			sheet.autoSizeColumn(i);
+		}
+
+		// 将工作簿写入到输出流
+		try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+			workbook.write(outputStream);
+			response.getOutputStream().write(outputStream.toByteArray());
+			response.getOutputStream().flush();
+		}
+
+		// 关闭工作簿
+		workbook.close();
+	}
+
+	@Override
+	public void importTemplate(HttpServletResponse response) throws IOException {
+		// 设置响应头信息,以附件形式下载
+		response.setHeader("Content-Disposition", "attachment; filename=evaluate_rule.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("序号", "指标编码", "指标名称", "最高分", "最低分", "基准分", "描述");
+		for (int i = 0; i < headers.size(); i++) {
+			Cell cell = headerRow.createCell(i);
+			cell.setCellValue(headers.get(i));
+		}
+
+		// 将工作簿写入到输出流
+		try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+			workbook.write(outputStream);
+			response.getOutputStream().write(outputStream.toByteArray());
+			response.getOutputStream().flush();
+		}
+
+		// 关闭工作簿
+		workbook.close();
+	}
+
+	@Override
+	public R importExcel(MultipartFile file, String id, String userId, String userName) {
+		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<EvaluateRuleInfo> evaluateRuleInfoList = new ArrayList<>();
+				//Excel导入导出的单元类
+				List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
+				//遍历Excel表每一行的数据
+				for (String[] str : strings) {
+					EvaluateRuleInfo evaluateRuleInfo = new EvaluateRuleInfo();
+					QueryWrapper<Indicator> qw = new QueryWrapper<>();
+					if (StringUtils.isNotEmpty(str[1])) {
+						qw.lambda().eq(Indicator::getIndicatorCode, str[1]);
+					}
+					List<Indicator> indicatorList = indicatorService.list(qw);
+					if (indicatorList.size() > 0){
+						evaluateRuleInfo.setIndicatorId(indicatorList.get(0).getId());
+						evaluateRuleInfo.setEvaluateRuleId(id);
+						evaluateRuleInfo.setDes(str[5]);
+						evaluateRuleInfo.setCreateTime(new Date());
+						evaluateRuleInfo.setCreateBy(userId);
+						evaluateRuleInfo.setCreateName(userName);
+						evaluateRuleInfo.setOrderNum(Integer.valueOf(str[0]));
+						evaluateRuleInfo.setMinScore(Double.valueOf(str[3]));
+						evaluateRuleInfo.setMaxScore(Double.valueOf(str[2]));
+						evaluateRuleInfo.setStandardScore(Double.valueOf(str[4]));
+						evaluateRuleInfoList.add(evaluateRuleInfo);
+					}
+				}
+				boolean b = super.saveOrUpdateBatch(evaluateRuleInfoList);
+				if (b) {
+					return R.ok().data(b);
+				} else {
+					return R.error("导入失败!");
+				}
+			} catch (Exception e) {
+				return R.customError(e.getMessage()).data("失败!");
+			}
+		}
+		return R.error("上传文件为空!");
+	}
+
 
 	@Override
 	public boolean saveOrUpdate(EvaluateRuleInfo entity) {
@@ -84,16 +242,16 @@ public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMap
 			List<EvaluateRuleInfo> list = baseMapper.selectList(qw);
 
 			if (null != list && list.size() > 0) {
-				for(EvaluateRuleInfo upinfo:list){
-					if(null != upinfo.getDeleteTime()){
+				for (EvaluateRuleInfo upinfo : list) {
+					if (null != upinfo.getDeleteTime()) {
 						upinfo.setDeleteTime(null);
-						int i =  baseMapper.updateById(upinfo);
-						if(i<=0){
+						int i = baseMapper.updateById(upinfo);
+						if (i <= 0) {
 							return false;
-						}else {
+						} else {
 							return true;
 						}
-					}else {
+					} else {
 						throw new CustomException("该指标已存在");
 					}
 

+ 15 - 0
ims-service/ims-eval/src/main/resources/mappers/EvaluateRuleInfoMapper.xml

@@ -91,4 +91,19 @@
         where eri.evaluate_rule_id = #{evaluateRuleId} and i.is_quantified = '是'
     </select>
 
+    <select id="selectListByEvaluateRuleId" resultType="com.ims.eval.entity.EvaluateRuleInfo">
+        select eri.*, i.indicator_name indicatorName, i.indicator_code indicatorCode from evaluate_rule_info eri
+        left join indicator i on i.id = eri.indicator_id
+        <where>
+            i.is_quantified = '是'
+            <if test="evaluateRuleId != null and evaluateRuleId != ''">
+                AND eri.evaluate_rule_id = #{evaluateRuleId}
+            </if>
+            <if test="indicatorName != null and indicatorName != ''">
+                AND i.indicator_name like CONCAT('%',#{indicatorName},'%')
+            </if>
+        </where>
+        order by order_num asc
+    </select>
+
 </mapper>