Browse Source

修改公告管理公告内容长度过长报错问题

hlf 1 year ago
parent
commit
d0d30b77f6

+ 49 - 29
ims-service/ims-eval/src/main/java/com/ims/eval/controller/NoticeManagementController.java

@@ -1,6 +1,8 @@
 package com.ims.eval.controller;
 
+import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -97,11 +99,20 @@ public class NoticeManagementController {
 	 * @return 结果
 	 */
 	@PostMapping(value = "/save")
-	public R addAll(EvaluationNotice evaluationNotice, @RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
+	public R addAll(@RequestBody EvaluationNotice evaluationNotice) {
 		try {
-			boolean b = evaluationNoticeService.saveOrUpdate(evaluationNotice, files);
+			String id;
+			if (StringUtils.isEmpty(evaluationNotice.getId())) {//true:为空
+				id = Convert.toStr(IdUtil.getSnowflake(1, 1).nextId());
+				evaluationNotice.setId(id);
+				evaluationNotice.setCreateTime(new Date());
+			} else {
+				id = evaluationNotice.getId();
+				evaluationNotice.setUpdateTime(new Date());
+			}
+			boolean b = evaluationNoticeService.saveOrUpdate(evaluationNotice);
 			if (b) {
-				return R.ok().data(b);
+				return R.ok().data(id);
 			} else {
 				return R.error("保存失败!");
 			}
@@ -180,18 +191,25 @@ public class NoticeManagementController {
 		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 = FileUploadUtil.upload(filePath, file);
-					fileNames.append(fileName).append(",");
+			if (null != evaluationNotice) {
+				StringBuilder fileNames = new StringBuilder();
+				if (files.length > 0) {
+					for (MultipartFile file : files) {
+						// 上传文件路径
+						String filePath = Path.getNoticePath();
+						// 上传并返回新文件名称
+						String fileName = FileUploadUtil.upload(filePath, file);
+						fileNames.append(fileName).append(",");
+					}
+					String newNoticeAnnex = fileNames.toString().substring(0, fileNames.toString().length() - 1);
+					if (StringUtils.isNotEmpty(evaluationNotice.getNoticeAnnex())) {//true:非空串
+						String noticeAnnex = evaluationNotice.getNoticeAnnex() + "," + newNoticeAnnex;
+						evaluationNotice.setNoticeAnnex(noticeAnnex);
+					} else {
+						evaluationNotice.setNoticeAnnex(newNoticeAnnex);
+					}
+					b = evaluationNoticeService.updateById(evaluationNotice);
 				}
-				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);
@@ -215,18 +233,20 @@ public class NoticeManagementController {
 		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(",");
+			if (null != evaluationNotice) {
+				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));
 			}
-			evaluationNotice.setNoticeAnnex(fileNames.toString().substring(0, fileNames.toString().length() - 1));
 			b = evaluationNoticeService.updateById(evaluationNotice);
 			if (b) {
 				return R.ok().data(b);
@@ -262,8 +282,8 @@ public class NoticeManagementController {
 		List<EvaluationNotice> list = new ArrayList<>();
 		for (EvaluationNotice evaluationNotice : evaluationNoticeList) {
 			if ("所有单位".equals(evaluationNotice.getSendTo())) {
-				if (null != evaluationNotice.getNoticeAnnex()){
-					if (evaluationNotice.getNoticeAnnex().length() > 0){
+				if (null != evaluationNotice.getNoticeAnnex()) {
+					if (evaluationNotice.getNoticeAnnex().length() > 0) {
 						String[] noticeAnnexList = evaluationNotice.getNoticeAnnex().split(",");
 						StringBuilder noticeAnnex = new StringBuilder();
 						for (String str : noticeAnnexList) {
@@ -273,7 +293,7 @@ public class NoticeManagementController {
 								noticeAnnex.append(str).append(",");
 							}
 						}
-						if (noticeAnnex.toString().length() > 0){
+						if (noticeAnnex.toString().length() > 0) {
 							evaluationNotice.setNoticeAnnex(noticeAnnex.toString().substring(0, noticeAnnex.toString().length() - 1));
 						}
 					}
@@ -283,7 +303,7 @@ public class NoticeManagementController {
 				String[] sendToContentList = evaluationNotice.getSendToContent().split(",");
 				for (String str : sendToContentList) {
 					if (str.equals(deptId)) {
-						if (evaluationNotice.getNoticeAnnex().length() > 0){
+						if (evaluationNotice.getNoticeAnnex().length() > 0) {
 							String[] noticeAnnexList = evaluationNotice.getNoticeAnnex().split(",");
 							StringBuilder noticeAnnex = new StringBuilder();
 							for (String str1 : noticeAnnexList) {
@@ -293,7 +313,7 @@ public class NoticeManagementController {
 									noticeAnnex.append(str1).append(",");
 								}
 							}
-							if (noticeAnnex.toString().length() > 0){
+							if (noticeAnnex.toString().length() > 0) {
 								evaluationNotice.setNoticeAnnex(noticeAnnex.toString().substring(0, noticeAnnex.toString().length() - 1));
 							}
 						}

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

@@ -3,9 +3,6 @@ package com.ims.eval.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ims.eval.entity.EvaluationNotice;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.IOException;
 
 /**
  * @author hlf
@@ -15,6 +12,4 @@ import java.io.IOException;
 public interface IEvaluationNoticeService extends IService<EvaluationNotice> {
 
 	IPage<EvaluationNotice> listPage(Integer pageNum, Integer pageSize, String noticeTitle);
-
-	boolean saveOrUpdate(EvaluationNotice evaluationNotice, MultipartFile[] files) throws IOException;
 }

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

@@ -5,14 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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.FileUploadUtil;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.IOException;
-import java.util.Date;
 
 /**
  * @author hlf
@@ -31,36 +25,4 @@ public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMap
 		Page<EvaluationNotice> page = new Page<>(pageNum, pageSize);
 		return baseMapper.selectListPage(page, noticeTitle);
 	}
-
-	@Override
-	public boolean saveOrUpdate(EvaluationNotice evaluationNotice, MultipartFile[] files) throws IOException {
-		StringBuilder fileNames = new StringBuilder();
-		String str = "";
-		if (files.length > 0) {
-			for (MultipartFile file : files) {
-				// 上传文件路径
-				String filePath = Path.getNoticePath();
-				// 上传并返回新文件名称
-				String fileName = FileUploadUtil.upload(filePath, file);
-				fileNames.append(fileName).append(",");
-			}
-			str = fileNames.toString().substring(0, fileNames.toString().length() - 1);
-		}
-		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);
-	}
 }