|
@@ -2,23 +2,27 @@ package com.ims.eval.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
-import com.ims.eval.cache.CacheContext;
|
|
|
|
import com.ims.eval.config.CustomException;
|
|
import com.ims.eval.config.CustomException;
|
|
-import com.ims.eval.entity.BinStage;
|
|
|
|
-import com.ims.eval.entity.Indicator;
|
|
|
|
import com.ims.eval.entity.PartyBuildingMultiplier;
|
|
import com.ims.eval.entity.PartyBuildingMultiplier;
|
|
import com.ims.eval.entity.dto.result.R;
|
|
import com.ims.eval.entity.dto.result.R;
|
|
-import com.ims.eval.service.IBinStageService;
|
|
|
|
import com.ims.eval.service.IPartyBuildingMultiplierService;
|
|
import com.ims.eval.service.IPartyBuildingMultiplierService;
|
|
|
|
+import com.ims.eval.util.ExcelUtil;
|
|
|
|
+import com.ims.eval.util.ExcelUtils;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.beans.IntrospectionException;
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -60,6 +64,111 @@ public class PartyBuildingMultiplierController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询
|
|
|
|
+ *
|
|
|
|
+ * @param id 主键ID
|
|
|
|
+ * @param departId 部门id
|
|
|
|
+ * @param sectionId 板块id
|
|
|
|
+ * @param year 年度
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @GetMapping(value = "/export1")
|
|
|
|
+ public void export1(HttpServletResponse response,
|
|
|
|
+ @RequestParam(value = "id", required = false) String id,
|
|
|
|
+ @RequestParam(value = "departId", required = false) String departId,
|
|
|
|
+ @RequestParam(value = "sectionId", required = false) String sectionId,
|
|
|
|
+ @RequestParam(value = "year", required = false) String year) throws IOException, IllegalAccessException, IntrospectionException, InvocationTargetException {
|
|
|
|
+
|
|
|
|
+ List<PartyBuildingMultiplier> list = iPartyBuildingMultiplierService.listByParam(id, departId, sectionId, year);
|
|
|
|
+ if (list.size() > 0){
|
|
|
|
+ OutputStream out = response.getOutputStream();
|
|
|
|
+ List<String> titleList = new ArrayList<>();
|
|
|
|
+ titleList.add("id");
|
|
|
|
+ titleList.add("单位名称");
|
|
|
|
+ titleList.add("板块名称");
|
|
|
|
+ titleList.add("党建乘数");
|
|
|
|
+ titleList.add("年度");
|
|
|
|
+ titleList.add("备注");
|
|
|
|
+ HSSFWorkbook workBook = ExcelUtils.getWorkBook(titleList, list);
|
|
|
|
+ //响应到客户端
|
|
|
|
+ try {
|
|
|
|
+ this.setResponseHeader(response, "党建乘数.xls");
|
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
|
+ BufferedOutputStream bufferOutput =new BufferedOutputStream(os);
|
|
|
|
+ bufferOutput.flush();
|
|
|
|
+ workBook.write(bufferOutput);
|
|
|
|
+ bufferOutput.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ throw new CustomException("党建乘数数据为空!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发送响应流方法
|
|
|
|
+ */
|
|
|
|
+ public void setResponseHeader(HttpServletResponse response, String fileName) {
|
|
|
|
+ try {
|
|
|
|
+ try {
|
|
|
|
+ fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
+ response.addHeader("Pargam", "no-cache");
|
|
|
|
+ response.addHeader("Cache-Control", "no-cache");
|
|
|
|
+ response.setHeader("Expires", " 0");
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @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<PartyBuildingMultiplier> bindingList = new ArrayList<>();
|
|
|
|
+ //Excel导入导出的单元类
|
|
|
|
+ List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
|
|
|
|
+ //遍历Excel表每一行的数据
|
|
|
|
+ for (String[] str : strings) {
|
|
|
|
+ PartyBuildingMultiplier partyBuildingMultiplier = new PartyBuildingMultiplier();
|
|
|
|
+ partyBuildingMultiplier.setId(str[0]);
|
|
|
|
+ partyBuildingMultiplier.setMultiplier(str[3]);
|
|
|
|
+ partyBuildingMultiplier.setYear(str[4]);
|
|
|
|
+ partyBuildingMultiplier.setRemarks(str[5]);
|
|
|
|
+ bindingList.add(partyBuildingMultiplier);
|
|
|
|
+ }
|
|
|
|
+ boolean b = iPartyBuildingMultiplierService.saveOrUpdateBatch(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("上传文件为空!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 添加
|
|
* 添加
|