Browse Source

业绩计划、业绩考核报表生成问题修改

hlf 1 year ago
parent
commit
ff5a1e5975

+ 46 - 27
ims-service/ims-eval/src/main/java/com/ims/eval/controller/DepartmentalPerformanceIndicatorAssessmentController.java

@@ -1,5 +1,8 @@
 package com.ims.eval.controller;
 
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.poi.word.Word07Writer;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.entity.EvaluationDept;
@@ -11,6 +14,7 @@ import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IEvaluationDeptBusinessAssessmentService;
 import com.ims.eval.service.IEvaluationDeptBusinessContentService;
 import com.ims.eval.util.WordUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -29,6 +33,7 @@ import java.util.*;
  * @date 2023/4/28 10:09
  * 文件说明:
  */
+@Slf4j
 @RestController
 @RequestMapping("//evaluation-dept-assessment")
 public class DepartmentalPerformanceIndicatorAssessmentController {
@@ -103,37 +108,51 @@ public class DepartmentalPerformanceIndicatorAssessmentController {
 	/**
 	 * 下载报表
 	 *
-	 * @param request
-	 * @param response
-	 * @param reportName
-	 * @throws IOException
+	 * @param request request
+	 * @param response response
+	 * @param reportName 文件名
+	 * @throws IOException 异常
 	 */
 	@GetMapping(value = "/downloadReport/{reportName}")
 	public void downloadReport(HttpServletRequest request, HttpServletResponse response, @PathVariable("reportName") String reportName) throws IOException {
-		InputStream inputStream = null;
-		ServletOutputStream outputStream = null;
-		try {
-			File file = new File(Path.getStatementPath() + 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);
+		//设置文件路径
+		File file = new File(Path.getStatementPath() + reportName);
+		//判断文件是否存在
+		if (file.exists()) {
+			//设置强制下载不打开
+			response.setContentType("application/force-download");
+			//设置文件名
+			response.addHeader("Content-Disposition", "attachment;fileName=".concat(String.valueOf(URLEncoder.encode(reportName, "UTF-8"))));
+			byte[] buffer = new byte[1024];
+			FileInputStream fis = null;
+			BufferedInputStream bis = null;
+			try {
+				fis = new FileInputStream(file);
+				bis = new BufferedInputStream(fis);
+				OutputStream os = response.getOutputStream();
+				int i = bis.read(buffer);
+				while (i != -1) {
+					os.write(buffer, 0, i);
+					i = bis.read(buffer);
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
+			} finally {
+				if (bis != null) {
+					try {
+						bis.close();
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+				}
+				if (fis != null) {
+					try {
+						fis.close();
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+				}
 			}
-		} finally {
-			if (inputStream != null) inputStream.close();
-			if (outputStream != null) outputStream.close();
 		}
 	}
 

+ 115 - 8
ims-service/ims-eval/src/main/java/com/ims/eval/controller/NoticeManagementController.java

@@ -2,15 +2,19 @@ package com.ims.eval.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.eval.config.CustomException;
-import com.ims.eval.entity.EvaluationDeptRating;
+import com.ims.eval.entity.DataDictionary;
 import com.ims.eval.entity.EvaluationNotice;
+import com.ims.eval.entity.custom.Path;
 import com.ims.eval.entity.dto.result.R;
+import com.ims.eval.service.IDataDictionaryService;
 import com.ims.eval.service.IEvaluationNoticeService;
+import com.ims.eval.util.FileUploadUtil;
 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 java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
@@ -30,6 +34,9 @@ public class NoticeManagementController {
 	@Autowired
 	private IEvaluationNoticeService evaluationNoticeService;
 
+	@Autowired
+	private IDataDictionaryService dataDictionaryService;
+
 	/**
 	 * 通告管理列表信息(分页)
 	 *
@@ -44,6 +51,18 @@ public class NoticeManagementController {
 		@RequestParam(value = "pageSize") Integer pageSize,
 		@RequestParam(value = "noticeTitle", required = false) String noticeTitle) {
 		IPage<EvaluationNotice> list = evaluationNoticeService.listPage(pageNum, pageSize, noticeTitle);
+		List<EvaluationNotice> evaluationNoticeList = list.getRecords();
+		for (EvaluationNotice obj : evaluationNoticeList) {
+			StringBuilder names = new StringBuilder();
+			if (!"".equals(obj.getSendToContent()) && null != obj.getSendToContent()) {
+				String[] strings = obj.getSendToContent().split(",");
+				for (String str : strings) {
+					DataDictionary dataDictionary = dataDictionaryService.getById(str);
+					names.append(dataDictionary.getKeyName()).append(",");
+				}
+				obj.setDeptNames(names.toString().substring(0, names.toString().length() - 1));
+			}
+		}
 		return R.ok().data(list);
 	}
 
@@ -65,7 +84,7 @@ public class NoticeManagementController {
 	 * @return 结果
 	 */
 	@PostMapping(value = "/save")
-	public R addAll(EvaluationNotice evaluationNotice, @RequestParam(value ="files", required = false) MultipartFile[] files) throws IOException {
+	public R addAll(EvaluationNotice evaluationNotice, @RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
 		try {
 			boolean b = evaluationNoticeService.saveOrUpdate(evaluationNotice, files);
 			if (b) {
@@ -96,15 +115,15 @@ public class NoticeManagementController {
 	}
 
 	/**
-	 * 发布通告
+	 * 修改状态
 	 *
 	 * @param id           主键
-	 * @param releaseState 发布状态
+	 * @param releaseState 状态(未发布或已发布)
 	 * @return 结果
 	 */
-	@PostMapping(value = "/issueNotice")
-	public R issueNotice(@RequestParam(value = "id") String id,
-						 @RequestParam(value = "releaseState") String releaseState) {
+	@PostMapping(value = "/modifiedState")
+	public R modifiedState(@RequestParam(value = "id") String id,
+						   @RequestParam(value = "releaseState") String releaseState) {
 		EvaluationNotice evaluationNotice = new EvaluationNotice();
 		evaluationNotice.setId(id);
 		evaluationNotice.setReleaseState(releaseState);
@@ -112,7 +131,95 @@ public class NoticeManagementController {
 		if (b) {
 			return R.ok().data(b);
 		} else {
-			return R.error().data("发布失败!");
+			return R.error().data("失败!");
+		}
+	}
+
+	/**
+	 * 上传附件
+	 *
+	 * @param id    主键
+	 * @param files 附件集
+	 * @return 结果
+	 * @throws IOException 异常
+	 */
+	@PostMapping(value = "/uploadAttachment")
+	public R uploadAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
+		try {
+			boolean b = false;
+			EvaluationNotice evaluationNotice = evaluationNoticeService.getById(id);
+			StringBuilder fileNames = new StringBuilder();
+			if (files.length > 0) {
+				for (MultipartFile file : files) {
+					// 上传文件路径
+					String filePath = Path.getNoticePath();
+					// 上传并返回新文件名称
+					String fileName = null;
+					fileName = FileUploadUtil.upload(filePath, file);
+					fileNames.append(fileName).append(",");
+				}
+				String noticeAnnex = evaluationNotice.getNoticeAnnex() + "," + fileNames.toString().substring(0, fileNames.toString().length() - 1);
+				evaluationNotice.setNoticeAnnex(noticeAnnex);
+				b = evaluationNoticeService.updateById(evaluationNotice);
+			}
+			if (b) {
+				return R.ok().data(b);
+			} else {
+				return R.error().data("上传附件失败!");
+			}
+		} catch (CustomException e) {
+			return R.customError(e.getMessage()).data("失败!");
+		}
+	}
+
+	/**
+	 * 删除附件
+	 *
+	 * @param id          主键
+	 * @param noticeAnnex 附件名称
+	 * @return 结果
+	 */
+	@PostMapping(value = "/deleteAttachment")
+	public R deleteAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "noticeAnnex") String noticeAnnex) {
+		try {
+			boolean b;
+			EvaluationNotice evaluationNotice = evaluationNoticeService.getById(id);
+			String[] strings = evaluationNotice.getNoticeAnnex().split(",");
+			StringBuilder fileNames = new StringBuilder();
+			for (String str : strings) {
+				if (str.substring(str.lastIndexOf("/") + 1, str.length()).equals(noticeAnnex)) {
+					String filePath = Path.getStatementPath() + str;
+					File file = new File(filePath);
+					b = file.delete();
+				} else {
+					fileNames.append(str).append(",");
+				}
+			}
+			evaluationNotice.setNoticeAnnex(fileNames.toString().substring(0, fileNames.toString().length() - 1));
+			b = evaluationNoticeService.updateById(evaluationNotice);
+			if (b) {
+				return R.ok().data(b);
+			} else {
+				return R.error().data("删除附件失败!");
+			}
+		} catch (CustomException e) {
+			return R.customError(e.getMessage()).data("失败!");
+		}
+	}
+
+	/**
+	 * 通告展示
+	 *
+	 * @return 结果
+	 */
+	@GetMapping(value = "/deptId")
+	public R circularDisplay(@RequestParam(value = "id") String deptId) {
+		List<EvaluationNotice> evaluationNoticeList = evaluationNoticeService.list();
+		for (EvaluationNotice evaluationNotice : evaluationNoticeList) {
+			if ("All".equals(evaluationNotice.getSendTo())){
+
+			}
 		}
+		return R.ok().data(evaluationNoticeList);
 	}
 }

+ 5 - 6
ims-service/ims-eval/src/main/java/com/ims/eval/entity/EvaluationNotice.java

@@ -31,12 +31,8 @@ public class EvaluationNotice extends Model {
 	private String sendTo;
 	//个别部门
 	private String sendToContent;
-	//发布部门主键
-	private String releaseDeptId;
-	//发布部门名称
-	private String releaseDeptName;
-	//发布部门编码
-	private String releaseDeptCode;
+	//发布部门
+	private String releaseDept;
 	//发布人
 	private String releasePeople;
 	//发布时间
@@ -55,4 +51,7 @@ public class EvaluationNotice extends Model {
 	private Date updateTime;
 	//更新者
 	private String updateBy;
+	//列表回显部门名称
+	@TableField(exist = false)
+	private String deptNames;
 }

+ 1 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/entity/custom/Path.java

@@ -40,6 +40,6 @@ public class Path {
 	 * 获取通告路径
 	 */
 	public static String getNoticePath() {
-		return getPrefix() + "/attachment/";
+		return getPrefix() + "/attachment";
 	}
 }

+ 13 - 17
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/EvaluationNoticeServiceImpl.java

@@ -1,18 +1,13 @@
 package com.ims.eval.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ims.common.utils.StringUtils;
 import com.ims.eval.dao.EvaluationNoticeMapper;
-import com.ims.eval.entity.DataDictionary;
 import com.ims.eval.entity.EvaluationNotice;
 import com.ims.eval.entity.custom.Path;
-import com.ims.eval.service.IDataDictionaryService;
 import com.ims.eval.service.IEvaluationNoticeService;
 import com.ims.eval.util.FileUploadUtil;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -27,9 +22,6 @@ import java.util.Date;
 @Service
 public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMapper, EvaluationNotice> implements IEvaluationNoticeService {
 
-	@Autowired
-	private IDataDictionaryService dataDictionaryService;
-
 	@Override
 	public IPage<EvaluationNotice> listPage(Integer pageNum, Integer pageSize, String noticeTitle) {
 		if (null == pageNum || null == pageSize) {
@@ -43,6 +35,7 @@ public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMap
 	@Override
 	public boolean saveOrUpdate(EvaluationNotice evaluationNotice, MultipartFile[] files) throws IOException {
 		StringBuilder fileNames = new StringBuilder();
+		String str = "";
 		if (files.length > 0) {
 			for (MultipartFile file : files) {
 				// 上传文件路径
@@ -52,19 +45,22 @@ public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMap
 				fileName = FileUploadUtil.upload(filePath, file);
 				fileNames.append(fileName).append(",");
 			}
+			str = fileNames.toString().substring(0, fileNames.toString().length() - 1);
 		}
-		if (fileNames.toString().length() > 0) {
-			evaluationNotice.setNoticeAnnex(fileNames.toString().substring(0, fileNames.toString().length() - 1));
-		}
-		DataDictionary dataDictionary = dataDictionaryService.getById(evaluationNotice.getReleaseDeptId());
-		if (null != dataDictionary) {
-			evaluationNotice.setReleaseDeptName(dataDictionary.getKeyName());
-			evaluationNotice.setReleaseDeptCode(dataDictionary.getDataKey());
-		}
-		if ("".equals(evaluationNotice.getId()) || null == evaluationNotice.getId()) {
+		if ("".equals(evaluationNotice.getId()) && null == evaluationNotice.getId()) {
 			evaluationNotice.setCreateTime(new Date());
+			if (str.length() > 0) {
+				evaluationNotice.setNoticeAnnex(str);
+			}
 		} else {
 			evaluationNotice.setUpdateTime(new Date());
+			if (str.length() > 0) {
+				EvaluationNotice obj = super.getById(evaluationNotice.getId());
+				if (!"".equals(obj.getNoticeAnnex()) && null != obj.getNoticeAnnex()) {
+					String noticeAnnex = obj.getNoticeAnnex() + "," + str;
+					evaluationNotice.setNoticeAnnex(noticeAnnex);
+				}
+			}
 		}
 		return super.saveOrUpdate(evaluationNotice);
 	}

+ 1 - 15
ims-service/ims-eval/src/main/java/com/ims/eval/util/FileUploadUtil.java

@@ -94,15 +94,11 @@ public class FileUploadUtil {
 		if (fileNamelength > FileUploadUtil.DEFAULT_FILE_NAME_LENGTH) {
 			throw new FileNameLengthLimitExceededException(FileUploadUtil.DEFAULT_FILE_NAME_LENGTH);
 		}
-
 		assertAllowed(file, allowedExtension);
-
 		String fileName = extractFilename(file);
-
 		File desc = getAbsoluteFile(baseDir, fileName);
 		file.transferTo(desc);
-		String pathFileName = getPathFileName(baseDir, fileName);
-		return pathFileName;
+		return fileName;
 	}
 
 	/**
@@ -118,7 +114,6 @@ public class FileUploadUtil {
 
 	private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException {
 		File desc = new File(uploadDir + File.separator + fileName);
-
 		if (!desc.exists()) {
 			if (!desc.getParentFile().exists()) {
 				desc.getParentFile().mkdirs();
@@ -127,13 +122,6 @@ public class FileUploadUtil {
 		return desc;
 	}
 
-	private static final String getPathFileName(String uploadDir, String fileName) throws IOException {
-		int dirLastIndex = Path.getPrefix().length() + 1;
-		String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
-		String pathFileName = "/prefix" + "/" + currentDir + "/" + fileName;
-		return pathFileName;
-	}
-
 	/**
 	 * 文件大小校验
 	 *
@@ -148,7 +136,6 @@ public class FileUploadUtil {
 		if (DEFAULT_MAX_SIZE != -1 && size > DEFAULT_MAX_SIZE) {
 			throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
 		}
-
 		String fileName = file.getOriginalFilename();
 		String extension = getExtension(file);
 		if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) {
@@ -168,7 +155,6 @@ public class FileUploadUtil {
 				throw new InvalidExtensionException(allowedExtension, extension, fileName);
 			}
 		}
-
 	}
 
 	/**

+ 2 - 6
ims-service/ims-eval/src/main/resources/mappers/EvaluationNoticeMapper.xml

@@ -10,9 +10,7 @@
         <result column="notice_content" property="noticeContent"/>
         <result column="send_to" property="sendTo"/>
         <result column="send_to_content" property="sendToContent"/>
-        <result column="release_dept_id" property="releaseDeptId"/>
-        <result column="release_dept_name" property="releaseDeptName"/>
-        <result column="release_dept_code" property="releaseDeptCode"/>
+        <result column="release_dept" property="releaseDept"/>
         <result column="release_people" property="releasePeople"/>
         <result column="release_date" property="releaseDate"/>
         <result column="release_state" property="releaseState"/>
@@ -32,9 +30,7 @@
                notice_content,
                send_to,
                send_to_content,
-               release_dept_id,
-               release_dept_name,
-               release_dept_code,
+               release_dept,
                release_people,
                release_date,
                release_state,