|
@@ -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));
|
|
|
}
|
|
|
}
|