|
@@ -4,6 +4,10 @@ import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.ims.common.utils.StringUtils;
|
|
import com.ims.common.utils.StringUtils;
|
|
@@ -13,18 +17,25 @@ import com.ims.eval.entity.EvaluationNotice;
|
|
import com.ims.eval.entity.OrganizationStructure;
|
|
import com.ims.eval.entity.OrganizationStructure;
|
|
import com.ims.eval.entity.custom.Path;
|
|
import com.ims.eval.entity.custom.Path;
|
|
import com.ims.eval.entity.dto.result.R;
|
|
import com.ims.eval.entity.dto.result.R;
|
|
|
|
+import com.ims.eval.entity.dto.result.ResultInfo;
|
|
import com.ims.eval.service.IEvaluationNoticeService;
|
|
import com.ims.eval.service.IEvaluationNoticeService;
|
|
import com.ims.eval.service.IOrganizationStructureService;
|
|
import com.ims.eval.service.IOrganizationStructureService;
|
|
|
|
+import com.ims.eval.util.FileUploadUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
import org.springframework.core.io.InputStreamResource;
|
|
import org.springframework.core.io.InputStreamResource;
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
@@ -38,7 +49,6 @@ import java.util.*;
|
|
* @date 2023/5/17 14:48
|
|
* @date 2023/5/17 14:48
|
|
* 文件说明:
|
|
* 文件说明:
|
|
*/
|
|
*/
|
|
-@Slf4j
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("//evaluation-dept-notice")
|
|
@RequestMapping("//evaluation-dept-notice")
|
|
public class NoticeManagementController {
|
|
public class NoticeManagementController {
|
|
@@ -52,12 +62,6 @@ public class NoticeManagementController {
|
|
@Autowired
|
|
@Autowired
|
|
HttpServletRequest request;
|
|
HttpServletRequest request;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private RestTemplate restTemplate;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ImaConfig imaConfig;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 通告管理列表信息(分页)
|
|
* 通告管理列表信息(分页)
|
|
*
|
|
*
|
|
@@ -198,48 +202,9 @@ public class NoticeManagementController {
|
|
* @throws IOException 异常
|
|
* @throws IOException 异常
|
|
*/
|
|
*/
|
|
@PostMapping(value = "/uploadAttachment")
|
|
@PostMapping(value = "/uploadAttachment")
|
|
- public R uploadAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
|
|
|
|
|
|
+ public R uploadAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "files", required = false) MultipartFile[] files) {
|
|
try {
|
|
try {
|
|
- boolean b = false;
|
|
|
|
- EvaluationNotice evaluationNotice = evaluationNoticeService.getById(id);
|
|
|
|
- if (null != evaluationNotice) {
|
|
|
|
- for (MultipartFile file : files) {
|
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
|
- headers.add("Blade-Auth", "bearer " + request.getHeader("Blade-Auth"));
|
|
|
|
- headers.add("code", request.getHeader("code"));
|
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
- map.put("folder", "AsApplication");
|
|
|
|
- map.put("objType", "xxxt/image");
|
|
|
|
- map.put("objKey", "");
|
|
|
|
- map.put("file", file);
|
|
|
|
- map.put("docPath", "dbkp");
|
|
|
|
- HttpEntity<Map> param = new HttpEntity<>(map, headers);
|
|
|
|
- ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() +"f-center/dm/dmDoc/saveA", HttpMethod.POST, param, String.class);
|
|
|
|
- log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
|
- if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /*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);
|
|
|
|
- }*/
|
|
|
|
- }
|
|
|
|
|
|
+ boolean b = evaluationNoticeService.uploadAttachment(id, files, request);
|
|
if (b) {
|
|
if (b) {
|
|
return R.ok().data(b);
|
|
return R.ok().data(b);
|
|
} else {
|
|
} else {
|
|
@@ -253,30 +218,14 @@ public class NoticeManagementController {
|
|
/**
|
|
/**
|
|
* 删除附件
|
|
* 删除附件
|
|
*
|
|
*
|
|
- * @param id 主键
|
|
|
|
- * @param noticeAnnex 附件名称
|
|
|
|
|
|
+ * @param id 主键
|
|
|
|
+ * @param docPath 附件路径
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@PostMapping(value = "/deleteAttachment")
|
|
@PostMapping(value = "/deleteAttachment")
|
|
- public R deleteAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "noticeAnnex") String noticeAnnex) {
|
|
|
|
|
|
+ public R deleteAttachment(@RequestParam(value = "id") String id, @RequestParam(value = "docPath") String docPath) {
|
|
try {
|
|
try {
|
|
- boolean b;
|
|
|
|
- EvaluationNotice evaluationNotice = evaluationNoticeService.getById(id);
|
|
|
|
- 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));
|
|
|
|
- }
|
|
|
|
- b = evaluationNoticeService.updateById(evaluationNotice);
|
|
|
|
|
|
+ boolean b = evaluationNoticeService.deleteAttachment(id, docPath, request);
|
|
if (b) {
|
|
if (b) {
|
|
return R.ok().data(b);
|
|
return R.ok().data(b);
|
|
} else {
|
|
} else {
|
|
@@ -299,67 +248,7 @@ public class NoticeManagementController {
|
|
@RequestParam(value = "noticeTitle") String noticeTitle,
|
|
@RequestParam(value = "noticeTitle") String noticeTitle,
|
|
@RequestParam(value = "beginDataTime", required = false) String beginDataTime,
|
|
@RequestParam(value = "beginDataTime", required = false) String beginDataTime,
|
|
@RequestParam(value = "endDataTime", required = false) String endDataTime) {
|
|
@RequestParam(value = "endDataTime", required = false) String endDataTime) {
|
|
- QueryWrapper<EvaluationNotice> qw = new QueryWrapper<>();
|
|
|
|
- qw.lambda().eq(EvaluationNotice::getReleaseState, "已发布");
|
|
|
|
- if (StringUtils.isNotEmpty(noticeTitle)) {
|
|
|
|
- qw.lambda().eq(EvaluationNotice::getNoticeTitle, noticeTitle);
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isNotEmpty(beginDataTime) && StringUtils.isNotEmpty(endDataTime)) {
|
|
|
|
- qw.lambda().between(EvaluationNotice::getReleaseDate, DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
|
|
|
|
- }
|
|
|
|
- List<EvaluationNotice> evaluationNoticeList = evaluationNoticeService.list(qw);
|
|
|
|
- List<EvaluationNotice> list = new ArrayList<>();
|
|
|
|
- for (EvaluationNotice evaluationNotice : evaluationNoticeList) {
|
|
|
|
- if ("所有单位".equals(evaluationNotice.getSendTo())) {
|
|
|
|
- if (null != evaluationNotice.getNoticeAnnex()) {
|
|
|
|
- if (evaluationNotice.getNoticeAnnex().length() > 0) {
|
|
|
|
- String[] noticeAnnexList = evaluationNotice.getNoticeAnnex().split(",");
|
|
|
|
- StringBuilder noticeAnnex = new StringBuilder();
|
|
|
|
- for (String str : noticeAnnexList) {
|
|
|
|
- if (str.contains("All")) {
|
|
|
|
- noticeAnnex.append(str).append(",");
|
|
|
|
- } else if (str.contains(deptId)) {
|
|
|
|
- noticeAnnex.append(str).append(",");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (noticeAnnex.toString().length() > 0) {
|
|
|
|
- evaluationNotice.setNoticeAnnex(noticeAnnex.toString().substring(0, noticeAnnex.toString().length() - 1));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- list.add(evaluationNotice);
|
|
|
|
- } else if ("个别部门".equals(evaluationNotice.getSendTo())) {
|
|
|
|
- String[] sendToContentList = evaluationNotice.getSendToContent().split(",");
|
|
|
|
- for (String str : sendToContentList) {
|
|
|
|
- if (str.equals(deptId)) {
|
|
|
|
- if (evaluationNotice.getNoticeAnnex().length() > 0) {
|
|
|
|
- String[] noticeAnnexList = evaluationNotice.getNoticeAnnex().split(",");
|
|
|
|
- StringBuilder noticeAnnex = new StringBuilder();
|
|
|
|
- for (String str1 : noticeAnnexList) {
|
|
|
|
- if (str1.contains("All")) {
|
|
|
|
- noticeAnnex.append(str1).append(",");
|
|
|
|
- } else if (str1.contains(deptId)) {
|
|
|
|
- noticeAnnex.append(str1).append(",");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (noticeAnnex.toString().length() > 0) {
|
|
|
|
- evaluationNotice.setNoticeAnnex(noticeAnnex.toString().substring(0, noticeAnnex.toString().length() - 1));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- list.add(evaluationNotice);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else if ("本部部门".equals(evaluationNotice.getSendTo())) {
|
|
|
|
- List<OrganizationStructure> deptList = organizationStructureService.getTree("23031001", 1, "140");
|
|
|
|
- if (deptList.size() > 0) {
|
|
|
|
- OrganizationStructure organizationStructure = deptList.stream().filter(item -> item.getId().equals(deptId)).findFirst().orElse(null);
|
|
|
|
- if (ObjectUtil.isNotNull(organizationStructure)) {
|
|
|
|
- list.add(evaluationNotice);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<EvaluationNotice> list = evaluationNoticeService.circularDisplay(deptId, noticeTitle, beginDataTime, endDataTime);
|
|
return R.ok().data(list);
|
|
return R.ok().data(list);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -376,44 +265,4 @@ public class NoticeManagementController {
|
|
String httpUrl = "http://" + ip + ":28900/file/" + url;
|
|
String httpUrl = "http://" + ip + ":28900/file/" + url;
|
|
return R.ok().data(httpUrl);
|
|
return R.ok().data(httpUrl);
|
|
}
|
|
}
|
|
-
|
|
|
|
- static class CommonInputStreamResource extends InputStreamResource {
|
|
|
|
- private long length;
|
|
|
|
- private String fileName;
|
|
|
|
-
|
|
|
|
- public CommonInputStreamResource(InputStream inputStream, long length, String fileName) {
|
|
|
|
- super(inputStream);
|
|
|
|
- this.length = length;
|
|
|
|
- this.fileName = fileName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 覆写父类方法
|
|
|
|
- * 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
|
|
|
|
- * {@code The multi-part request contained parameter data (excluding uploaded files) that exceeded}
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public String getFilename() {
|
|
|
|
- return fileName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 覆写父类 contentLength 方法
|
|
|
|
- * 因为 {@link org.springframework.core.io.AbstractResource#contentLength()}方法会重新读取一遍文件,
|
|
|
|
- * 而上传文件时,restTemplate 会通过这个方法获取大小。然后当真正需要读取内容的时候,发现已经读完,会报如下错误。
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public long contentLength() {
|
|
|
|
- long estimate = length;
|
|
|
|
- return estimate == 0 ? 1 : estimate;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setLength(long length) {
|
|
|
|
- this.length = length;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setFileName(String fileName) {
|
|
|
|
- this.fileName = fileName;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|