|
@@ -2,17 +2,22 @@ package com.ims.eval.controller;
|
|
|
|
|
|
|
|
|
import com.ims.eval.config.CustomException;
|
|
|
+import com.ims.eval.entity.OrganizationEvaluationInfo;
|
|
|
import com.ims.eval.entity.ResponsibilityIndicatorInfo;
|
|
|
import com.ims.eval.entity.dto.request.ResponsibilityIndicatorInfoUpdateDTO;
|
|
|
import com.ims.eval.entity.dto.result.R;
|
|
|
import com.ims.eval.service.IResponsibilityIndicatorInfoService;
|
|
|
+import com.ims.eval.util.ExcelUtil;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -149,4 +154,42 @@ public class ResponsibilityIndicatorInfoController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @PostMapping(value = "/import")
|
|
|
+ @ResponseBody
|
|
|
+ public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
|
|
+
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ try {
|
|
|
+ //获取原始的文件名
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ //获取文件类型
|
|
|
+ String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
|
|
|
+ //默认从第一行开始读取
|
|
|
+ Integer startRows = 1;
|
|
|
+ //获取输入流
|
|
|
+ InputStream is = file.getInputStream();
|
|
|
+ List<ResponsibilityIndicatorInfoUpdateDTO> bindingList = new ArrayList<>();
|
|
|
+ //Excel导入导出的单元类
|
|
|
+ List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
|
|
|
+ //遍历Excel表每一行的数据
|
|
|
+ for (String[] str : strings) {
|
|
|
+ ResponsibilityIndicatorInfoUpdateDTO responsibilityIndicatorInfoUpdateDTO = new ResponsibilityIndicatorInfoUpdateDTO();
|
|
|
+ responsibilityIndicatorInfoUpdateDTO.setId(str[0]);
|
|
|
+ responsibilityIndicatorInfoUpdateDTO.setQuantifiedValue(Double.parseDouble(str[8]));
|
|
|
+ bindingList.add(responsibilityIndicatorInfoUpdateDTO);
|
|
|
+ }
|
|
|
+ boolean b = responsibilityIndicatorInfoService.saveBatchDto(bindingList);
|
|
|
+ if (b) {
|
|
|
+ return R.ok().data(b);
|
|
|
+ } else {
|
|
|
+ return R.error().data("保存失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("错误", e);
|
|
|
+ return R.customError(e.getMessage()).data("失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.customError("上传文件为空!");
|
|
|
+ }
|
|
|
}
|