Browse Source

考评修订弹框数据修改、导出功能、通告管理在线预览

hlf 2 years ago
parent
commit
89cdf907c9

+ 5 - 0
ims-service/ims-eval/pom.xml

@@ -75,6 +75,11 @@
             <artifactId>freemarker</artifactId>
             <version>2.3.28</version>
         </dependency>
+        <dependency>
+            <groupId>com.artofsolving</groupId>
+            <artifactId>jodconverter</artifactId>
+            <version>2.2.1</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 1 - 7
ims-service/ims-eval/src/main/java/com/ims/eval/controller/DepartmentPerformanceAppraisalRatingController.java

@@ -2,26 +2,21 @@ package com.ims.eval.controller;
 
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.common.utils.StringUtils;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.entity.DataDictionary;
-import com.ims.eval.entity.EvaluationDeptBusinessContent;
 import com.ims.eval.entity.EvaluationDeptRating;
-import com.ims.eval.entity.YearOperatingCoefficient;
 import com.ims.eval.entity.dto.result.R;
 import com.ims.eval.service.IDataDictionaryService;
 import com.ims.eval.service.IEvaluationDeptRatingService;
 import com.ims.eval.util.ExcelUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.formula.functions.T;
 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.Arrays;
@@ -116,11 +111,10 @@ public class DepartmentPerformanceAppraisalRatingController {
 	 * 导入
 	 *
 	 * @param file
-	 * @param request
 	 * @return
 	 */
 	@PostMapping(value = "/import")
-	public R importData(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
+	public R importData(@RequestParam("file") MultipartFile file) {
 		if (!file.isEmpty()) {
 			try {
 				//获取原始的文件名

+ 6 - 5
ims-service/ims-eval/src/main/java/com/ims/eval/controller/DepartmentalPerformanceIndicatorPlanController.java

@@ -3,10 +3,13 @@ package com.ims.eval.controller;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.eval.config.CustomException;
-import com.ims.eval.entity.*;
+import com.ims.eval.entity.EvaluationDept;
+import com.ims.eval.entity.EvaluationDeptBusinessContent;
+import com.ims.eval.entity.EvaluationDeptBusinessPlan;
 import com.ims.eval.entity.custom.Path;
 import com.ims.eval.entity.dto.result.R;
-import com.ims.eval.service.*;
+import com.ims.eval.service.IEvaluationDeptBusinessContentService;
+import com.ims.eval.service.IEvaluationDeptBusinessPlanService;
 import com.ims.eval.util.ExcelUtil;
 import com.ims.eval.util.WordUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -14,7 +17,6 @@ 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.*;
 
@@ -175,11 +177,10 @@ public class DepartmentalPerformanceIndicatorPlanController {
 	 * 导入
 	 *
 	 * @param file
-	 * @param request
 	 * @return
 	 */
 	@PostMapping(value = "/import")
-	public R importData(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
+	public R importData(@RequestParam("file") MultipartFile file) {
 		if (!file.isEmpty()) {
 			try {
 				//获取原始的文件名

+ 1 - 3
ims-service/ims-eval/src/main/java/com/ims/eval/controller/EvaluationRevisionController.java

@@ -15,7 +15,6 @@ 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;
@@ -157,11 +156,10 @@ public class EvaluationRevisionController {
 	 *
 	 * @param file 文件
 	 * @param isQuantified 是否量化
-	 * @param request request
 	 * @return 结果
 	 */
 	@PostMapping(value = "/import")
-	public R importData(@RequestParam("file") MultipartFile file, @RequestParam(value = "isQuantified") String isQuantified, HttpServletRequest request) {
+	public R importData(@RequestParam("file") MultipartFile file, @RequestParam("isQuantified") String isQuantified) {
 		if (!file.isEmpty()) {
 			try {
 				//获取原始的文件名

+ 39 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/NoticeManagementController.java

@@ -10,14 +10,18 @@ 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.FileConvertUtil;
 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 javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -242,4 +246,39 @@ public class NoticeManagementController {
 		}
 		return R.ok().data(list);
 	}
+
+	/**
+	 * 文件预览
+	 *
+	 * @param url      url
+	 * @param response response
+	 * @return 结果
+	 * @throws Exception
+	 */
+	@GetMapping(value = "/filePreview")
+	public void filePreview(@RequestParam(value = "url") String url, HttpServletResponse response) throws Exception {
+		InputStream in = null;
+		try {
+			in = FileConvertUtil.convertLocaleFile(url, "pdf");
+			OutputStream outputStream = response.getOutputStream();
+			//创建存放文件内容的数组
+			byte[] buff = new byte[1024];
+			//所读取的内容使用n来接收
+			int n;
+			//当没有读取完时,继续读取,循环
+			while ((n = in.read(buff)) != -1) {
+				//将字节数组的数据全部写入到输出流中
+				outputStream.write(buff, 0, n);
+			}
+			//强制将缓存区的数据进行输出
+			outputStream.flush();
+			//关流
+			outputStream.close();
+			in.close();
+			//return R.ok();
+		} catch (Exception e) {
+			log.error("错误", e);
+		}
+		//evaluationNoticeService.onlinePreview(Path.getNoticePath() + url, response);
+	}
 }

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

@@ -163,7 +163,7 @@ public class EvaluationRevision extends Model {
 	/**
 	 * 创建人组织id
 	 */
-	private String  createOrgId;
+	private String createOrgId;
 
 	/**
 	 * 创建人组织name

+ 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/";
 	}
 }

+ 2 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IEvaluationNoticeService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.ims.eval.entity.EvaluationNotice;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
 /**
@@ -18,4 +19,5 @@ public interface IEvaluationNoticeService extends IService<EvaluationNotice> {
 
 	boolean saveOrUpdate(EvaluationNotice evaluationNotice, MultipartFile[] files) throws IOException;
 
+	void onlinePreview(String url, HttpServletResponse response) throws Exception;
 }

+ 43 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/EvaluationNoticeServiceImpl.java

@@ -7,11 +7,15 @@ import com.ims.eval.dao.EvaluationNoticeMapper;
 import com.ims.eval.entity.EvaluationNotice;
 import com.ims.eval.entity.custom.Path;
 import com.ims.eval.service.IEvaluationNoticeService;
+import com.ims.eval.util.FileConvertUtil;
 import com.ims.eval.util.FileUploadUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Date;
 
 /**
@@ -64,4 +68,43 @@ public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMap
 		}
 		return super.saveOrUpdate(evaluationNotice);
 	}
+
+	/**
+	 * @Description:文件在线预览接口
+	 */
+	@Override
+	public void onlinePreview(String url, HttpServletResponse response) throws Exception {
+		/*//获取文件类型
+		String[] str = StringUtils.split(url, "\\.");
+
+		if (str.length == 0) {
+			throw new Exception("文件格式不正确");
+		}
+		String suffix = str[str.length - 1];
+		if (!suffix.equals("txt") && !suffix.equals("doc") && !suffix.equals("docx") && !suffix.equals("xls") && !suffix.equals("xlsx") && !suffix.equals("ppt") && !suffix.equals("pptx")) {
+			throw new Exception("文件格式不支持预览");
+		}
+		InputStream in = FileConvertUtil.convertNetFile(url, suffix);*/
+		InputStream in = null;
+		try {
+			in = FileConvertUtil.convertLocaleFile(url, "pdf");
+			OutputStream outputStream = response.getOutputStream();
+			//创建存放文件内容的数组
+			byte[] buff = new byte[1024];
+			//所读取的内容使用n来接收
+			int n;
+			//当没有读取完时,继续读取,循环
+			while ((n = in.read(buff)) != -1) {
+				//将字节数组的数据全部写入到输出流中
+				outputStream.write(buff, 0, n);
+			}
+			//强制将缓存区的数据进行输出
+			outputStream.flush();
+			//关流
+			outputStream.close();
+			in.close();
+		} catch (Exception e) {
+			log.error("错误", e);
+		}
+	}
 }

+ 23 - 6
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/ResponsibilityIndicatorInfoServiceImpl.java

@@ -160,12 +160,29 @@ public class ResponsibilityIndicatorInfoServiceImpl extends ServiceImpl<Responsi
 	@Override
 	public boolean saveOrUpdateBatch(List<ResponsibilityIndicatorInfo> responsibilityIndicatorInfoList) {
 		boolean b = false;
-		for (ResponsibilityIndicatorInfo responsibilityIndicatorInfo : responsibilityIndicatorInfoList) {
-			responsibilityIndicatorInfo.setDataState("失效");
-			b = super.updateById(responsibilityIndicatorInfo);
-			if (b) {
-				responsibilityIndicatorInfo.setDataState("有效");
-				b = super.save(responsibilityIndicatorInfo);
+		for (ResponsibilityIndicatorInfo obj : responsibilityIndicatorInfoList) {
+			ResponsibilityIndicatorInfo responsibilityIndicatorInfo = super.getById(obj.getId());
+			if (!"失效".equals(responsibilityIndicatorInfo.getDataState())) {
+				obj.setDataState("失效");
+				b = super.updateById(obj);
+				if (b) {
+					ResponsibilityIndicatorInfo info = new ResponsibilityIndicatorInfo();
+					info.setDeptResponsibilityId(responsibilityIndicatorInfo.getDeptResponsibilityId());
+					info.setOrganizationEvaluationRuleId(responsibilityIndicatorInfo.getOrganizationEvaluationRuleId());
+					info.setIndicatorId(responsibilityIndicatorInfo.getIndicatorId());
+					info.setIndicatorDictionaryId(responsibilityIndicatorInfo.getIndicatorDictionaryId());
+					info.setOptionCode(responsibilityIndicatorInfo.getOptionCode());
+					info.setIsQuantified(obj.getIsQuantified());
+					info.setQuantifiedValue(obj.getQuantifiedValue());
+					info.setNonQuantifiedValue(obj.getNonQuantifiedValue());
+					info.setCreateTime(new Date());
+					info.setState(obj.getState());
+					info.setDataState("有效");
+					b = super.save(info);
+				}
+			} else {
+				obj.setUpdateTime(new Date());
+				b = super.updateById(obj);
 			}
 		}
 		return b;

+ 94 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/util/FileConvertUtil.java

@@ -0,0 +1,94 @@
+package com.ims.eval.util;
+
+import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
+import com.artofsolving.jodconverter.DocumentConverter;
+import com.artofsolving.jodconverter.DocumentFormat;
+import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
+import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
+import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+
+/**
+ * @author hlf
+ * @date 2023/5/25 14:22
+ * 文件说明:文件格式转换工具类
+ */
+public class FileConvertUtil {
+
+	/**
+	 * 默认转换后文件后缀
+	 */
+	private static final String DEFAULT_SUFFIX = "pdf";
+	/**
+	 * openoffice_port
+	 */
+	private static final Integer OPENOFFICE_PORT = 8100;
+
+	/**
+	 * 方法描述 office文档转换为PDF(处理本地文件)
+	 *
+	 * @param sourcePath 源文件路径
+	 * @param suffix     源文件后缀
+	 * @return InputStream 转换后文件输入流
+	 */
+	public static InputStream convertLocaleFile(String sourcePath, String suffix) throws Exception {
+		File inputFile = new File(sourcePath);
+		InputStream inputStream = Files.newInputStream(inputFile.toPath());
+		return covertCommonByStream(inputStream, suffix);
+	}
+
+	/**
+	 * 方法描述  office文档转换为PDF(处理网络文件)
+	 *
+	 * @param netFileUrl 网络文件路径
+	 * @param suffix     文件后缀
+	 * @return InputStream 转换后文件输入流
+	 */
+	public static InputStream convertNetFile(String netFileUrl, String suffix) throws Exception {
+		// 创建URL
+		URL url = new URL(netFileUrl);
+		// 试图连接并取得返回状态码
+		URLConnection urlconn = url.openConnection();
+		urlconn.connect();
+		HttpURLConnection httpconn = (HttpURLConnection) urlconn;
+		int httpResult = httpconn.getResponseCode();
+		if (httpResult == HttpURLConnection.HTTP_OK) {
+			InputStream inputStream = urlconn.getInputStream();
+			return covertCommonByStream(inputStream, suffix);
+		}
+		return null;
+	}
+
+	/**
+	 * 方法描述  将文件以流的形式转换
+	 *
+	 * @param inputStream 源文件输入流
+	 * @param suffix      源文件后缀
+	 * @return InputStream 转换后文件输入流
+	 */
+	public static InputStream covertCommonByStream(InputStream inputStream, String suffix) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		OpenOfficeConnection connection = new SocketOpenOfficeConnection(OPENOFFICE_PORT);
+		connection.connect();
+		DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
+		DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();
+		DocumentFormat targetFormat = formatReg.getFormatByFileExtension(DEFAULT_SUFFIX);
+		DocumentFormat sourceFormat = formatReg.getFormatByFileExtension(suffix);
+		converter.convert(inputStream, sourceFormat, out, targetFormat);
+		connection.disconnect();
+		return outputStreamConvertInputStream(out);
+	}
+
+	/**
+	 * 方法描述 outputStream转inputStream
+	 */
+	public static ByteArrayInputStream outputStreamConvertInputStream(final OutputStream out) throws Exception {
+		ByteArrayOutputStream baos = (ByteArrayOutputStream) out;
+		return new ByteArrayInputStream(baos.toByteArray());
+	}
+}