|
@@ -1,16 +1,23 @@
|
|
|
package com.ims.eval.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.ims.eval.entity.EvaluationDept;
|
|
|
import com.ims.eval.entity.EvaluationDeptBusinessAssessment;
|
|
|
+import com.ims.eval.entity.EvaluationDeptBusinessContent;
|
|
|
import com.ims.eval.entity.dto.result.R;
|
|
|
import com.ims.eval.service.IEvaluationDeptBusinessAssessmentService;
|
|
|
import com.ims.eval.service.IEvaluationDeptBusinessContentService;
|
|
|
-import com.ims.eval.service.IEvaluationDeptBusinessPlanService;
|
|
|
+import com.ims.eval.util.WordUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 本部部门业绩指标考核
|
|
@@ -26,6 +33,9 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
|
|
|
@Autowired
|
|
|
private IEvaluationDeptBusinessAssessmentService evaluationDeptBusinessAssessmentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IEvaluationDeptBusinessContentService evaluationDeptBusinessContentService;
|
|
|
+
|
|
|
/**
|
|
|
* 部门考评业务列表信息(分页)
|
|
|
*
|
|
@@ -37,7 +47,7 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
|
|
|
* @param stage 流程状态
|
|
|
* @return 结果
|
|
|
*/
|
|
|
- @GetMapping(value = "list")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
public R list(
|
|
|
@RequestParam(value = "pageNum") Integer pageNum,
|
|
|
@RequestParam(value = "pageSize") Integer pageSize,
|
|
@@ -54,9 +64,87 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
|
|
|
*
|
|
|
* @return 结果
|
|
|
*/
|
|
|
- @GetMapping(value = "listAll")
|
|
|
+ @GetMapping(value = "/listAll")
|
|
|
public R listAll() {
|
|
|
List<EvaluationDeptBusinessAssessment> list = evaluationDeptBusinessAssessmentService.list();
|
|
|
return R.ok().data(list);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成报表
|
|
|
+ *
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/generateReport/{id}")
|
|
|
+ public R generateReport(@PathVariable("id") String id) throws Exception {
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
+ EvaluationDeptBusinessAssessment evaluationDeptBusinessAssessment = evaluationDeptBusinessAssessmentService.getById(id);
|
|
|
+ String[] deptIds = evaluationDeptBusinessAssessment.getDeptId().split(",");
|
|
|
+ String[] deptNames = evaluationDeptBusinessAssessment.getDeptName().split(",");
|
|
|
+ List<EvaluationDept> evaluationDeptList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < deptIds.length; i++) {
|
|
|
+ EvaluationDept evaluationDept = new EvaluationDept();
|
|
|
+ evaluationDept.setDeptId(deptIds[i]);
|
|
|
+ evaluationDept.setDeptName(deptNames[i]);
|
|
|
+ List<EvaluationDeptBusinessContent> evaluationDeptBusinessContentList = evaluationDeptBusinessContentService.selectEvaluationDeptBusinessContentListByBusinessPlanId(id, deptIds[i]);
|
|
|
+ evaluationDept.setList(evaluationDeptBusinessContentList);
|
|
|
+ evaluationDeptList.add(evaluationDept);
|
|
|
+ }
|
|
|
+ dataMap.put("appraisalYear", evaluationDeptBusinessAssessment.getAppraisalYear());
|
|
|
+ dataMap.put("list", evaluationDeptList);
|
|
|
+ String os = System.getProperty("os.name");
|
|
|
+ String path;
|
|
|
+ if (os.toLowerCase().startsWith("win")) { //如果是Windows系统
|
|
|
+ path = "D:/home/statement/" ;
|
|
|
+ } else { //linux和mac
|
|
|
+ path = "/home/dbkp/statement/" ;
|
|
|
+ }
|
|
|
+ String fileName = evaluationDeptBusinessAssessment.getAppraisalYear() + "年度经营业绩完成情况.doc" ;
|
|
|
+ WordUtil.generateWord(dataMap, "template_dbkp.ftl", path + fileName);
|
|
|
+ return R.ok().data(fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载报表
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param reportName
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/downloadReport")
|
|
|
+ public void downloadReport(HttpServletRequest request, HttpServletResponse response, String reportName) throws IOException {
|
|
|
+ String os = System.getProperty("os.name");
|
|
|
+ String path;
|
|
|
+ if (os.toLowerCase().startsWith("win")) { //如果是Windows系统
|
|
|
+ path = "D:/home/statement/" ;
|
|
|
+ } else { //linux和mac
|
|
|
+ path = "/home/dbkp/statement/" ;
|
|
|
+ }
|
|
|
+ InputStream inputStream = null;
|
|
|
+ ServletOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ File file = new File(path + reportName);
|
|
|
+ inputStream = Files.newInputStream(file.toPath());
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/msword");
|
|
|
+ response.addHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
|
|
+ response.addHeader("Access-Control-Expose-Headers", "token, uid, Content-Disposition");
|
|
|
+ response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
|
|
|
+ response.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
|
+ response.addHeader("Access-Control-Allow-Credentials", "true");
|
|
|
+ // 设置浏览器以下载的方式处理该文件名
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(reportName, "UTF-8"))));
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+ byte[] buffer = new byte[512]; // 缓冲区
|
|
|
+ int bytesToRead = -1;
|
|
|
+ // 通过循环将读入的Word文件的内容输出到浏览器中
|
|
|
+ while ((bytesToRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesToRead);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (inputStream != null) inputStream.close();
|
|
|
+ if (outputStream != null) outputStream.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|