|
@@ -2,13 +2,31 @@ package com.ims.eval.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.ims.common.utils.StringUtils;
|
|
import com.ims.eval.config.CustomException;
|
|
import com.ims.eval.config.CustomException;
|
|
import com.ims.eval.dao.EvaluateRuleInfoMapper;
|
|
import com.ims.eval.dao.EvaluateRuleInfoMapper;
|
|
import com.ims.eval.entity.EvaluateRuleInfo;
|
|
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.response.EvaluateRuleInfoIndicatorDTO;
|
|
|
|
+import com.ims.eval.entity.dto.result.R;
|
|
import com.ims.eval.service.IEvaluateRuleInfoService;
|
|
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.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.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -23,10 +41,13 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMapper, EvaluateRuleInfo> implements IEvaluateRuleInfoService {
|
|
public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMapper, EvaluateRuleInfo> implements IEvaluateRuleInfoService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IIndicatorService indicatorService;
|
|
|
|
+
|
|
@Override
|
|
@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;
|
|
return list;
|
|
}
|
|
}
|
|
@@ -73,6 +94,143 @@ public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMap
|
|
return true;
|
|
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
|
|
@Override
|
|
public boolean saveOrUpdate(EvaluateRuleInfo entity) {
|
|
public boolean saveOrUpdate(EvaluateRuleInfo entity) {
|
|
@@ -84,16 +242,16 @@ public class EvaluateRuleInfoServiceImpl extends ServiceImpl<EvaluateRuleInfoMap
|
|
List<EvaluateRuleInfo> list = baseMapper.selectList(qw);
|
|
List<EvaluateRuleInfo> list = baseMapper.selectList(qw);
|
|
|
|
|
|
if (null != list && list.size() > 0) {
|
|
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);
|
|
upinfo.setDeleteTime(null);
|
|
- int i = baseMapper.updateById(upinfo);
|
|
|
|
- if(i<=0){
|
|
|
|
|
|
+ int i = baseMapper.updateById(upinfo);
|
|
|
|
+ if (i <= 0) {
|
|
return false;
|
|
return false;
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
throw new CustomException("该指标已存在");
|
|
throw new CustomException("该指标已存在");
|
|
}
|
|
}
|
|
|
|
|