|
@@ -12,18 +12,24 @@ 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.hssf.usermodel.HSSFCell;
|
|
|
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;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.ims.eval.util.ExcelUtil.readExcel;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 考评指标明细
|
|
@@ -590,12 +596,105 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
workbook.write(outputStream);
|
|
|
|
|
|
-
|
|
|
// 将字节数组作为响应体返回,并设置响应头
|
|
|
byte[] excelBytes = outputStream.toByteArray();
|
|
|
return excelBytes;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean importExcel(MultipartFile file) throws IOException {
|
|
|
+
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ 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 = 4;
|
|
|
+
|
|
|
+ Row headerRow = sheet.getRow(3);
|
|
|
+
|
|
|
+
|
|
|
+ // 遍历每一行数据
|
|
|
+ for (int i = startingRowIndex; i <= sheet.getLastRowNum(); i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ Map<String, Object> dataMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ // 遍历每一列数据
|
|
|
+ for (int j = 1; 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> map : dataList){
|
|
|
+
|
|
|
+ Map<String,Object > idMap = new HashMap();
|
|
|
+ Map valueMap = new HashMap();
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ if(key.startsWith("ID_")){
|
|
|
+ idMap.put(key,value);
|
|
|
+ }else {
|
|
|
+ valueMap.put(key,value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrganizationEvaluationInfo> evaluationInfos =new ArrayList<>();
|
|
|
+ for (Map.Entry<String,Object > entry : idMap.entrySet()) {
|
|
|
+ OrganizationEvaluationInfo info = new OrganizationEvaluationInfo();
|
|
|
+ info.setId(entry.getValue().toString());
|
|
|
+ boolean quantified = Boolean.valueOf(valueMap.get(entry.getKey().replace("ID_","IS_LH_")).toString());
|
|
|
+ if(quantified){
|
|
|
+ info.setQuantifiedValue(Double.valueOf(valueMap.get(entry.getKey().replace("ID_","")).toString()));
|
|
|
+ }
|
|
|
+ info.setNonQuantifiedValue(valueMap.get(entry.getKey().replace("ID_","")).toString());
|
|
|
+ evaluationInfos.add(info);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(evaluationInfos);
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public boolean updateEvaluationInfo(List<JSONObject> jsonObjects) {
|