|
@@ -1,12 +1,43 @@
|
|
|
package com.ims.eval.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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.config.ImaConfig;
|
|
|
import com.ims.eval.dao.EvaluationNoticeMapper;
|
|
|
import com.ims.eval.entity.EvaluationNotice;
|
|
|
+import com.ims.eval.entity.OrganizationStructure;
|
|
|
+import com.ims.eval.entity.custom.Path;
|
|
|
+import com.ims.eval.entity.dto.result.ResultInfo;
|
|
|
import com.ims.eval.service.IEvaluationNoticeService;
|
|
|
+import com.ims.eval.service.IOrganizationStructureService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author hlf
|
|
@@ -14,8 +45,18 @@ import org.springframework.stereotype.Service;
|
|
|
* 文件说明:
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMapper, EvaluationNotice> implements IEvaluationNoticeService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IOrganizationStructureService organizationStructureService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ImaConfig imaConfig;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<EvaluationNotice> listPage(Integer pageNum, Integer pageSize, String noticeTitle) {
|
|
|
if (null == pageNum || null == pageSize) {
|
|
@@ -25,4 +66,170 @@ public class EvaluationNoticeServiceImpl extends ServiceImpl<EvaluationNoticeMap
|
|
|
Page<EvaluationNotice> page = new Page<>(pageNum, pageSize);
|
|
|
return baseMapper.selectListPage(page, noticeTitle);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean uploadAttachment(String id, MultipartFile[] files, HttpServletRequest request) {
|
|
|
+ EvaluationNotice evaluationNotice = baseMapper.selectById(id);
|
|
|
+ if (null != evaluationNotice) {
|
|
|
+ StringBuilder docPaths = new StringBuilder();
|
|
|
+ StringBuilder docFileNames = new StringBuilder();
|
|
|
+ if (files.length > 0) {
|
|
|
+ for (MultipartFile multipartFile : files) {
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ file = new File(multipartFile.getOriginalFilename());
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
|
+ FileCopyUtils.copy(multipartFile.getInputStream(), fileOutputStream);
|
|
|
+ fileOutputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ FileSystemResource fileStream = new FileSystemResource(file);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Blade-Auth", "bearer " + request.getHeader("Blade-Auth"));
|
|
|
+ headers.add("Content-Type", "multipart/form-data");
|
|
|
+ MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
|
|
+ map.add("folder", "AsApplication");
|
|
|
+ map.add("objType", "xxxt/image");
|
|
|
+ map.add("objKey", "");
|
|
|
+ map.add("file", fileStream);
|
|
|
+ map.add("bucketName", "dbkp");
|
|
|
+ HttpEntity<Map> param = new HttpEntity<>(map, headers);
|
|
|
+ ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "f-center/dm/dmDoc/save", HttpMethod.POST, param, String.class);
|
|
|
+ log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
+ //删除临时文件
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
+ ResultInfo resultInfo = JSON.parseObject(responseEntity2.getBody(), ResultInfo.class);
|
|
|
+ if ("保存成功!".equals(resultInfo.getMessage())) {
|
|
|
+ Map<String, Object> fileInfo = (Map<String, Object>) resultInfo.getData();
|
|
|
+ if (fileInfo.size() > 0) {
|
|
|
+ String docPath = (String) fileInfo.get("docPath");
|
|
|
+ docPaths.append(docPath).append(",");
|
|
|
+ String docFileName = (String) fileInfo.get("docFileName");
|
|
|
+ docFileNames.append(docFileName).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String docPathStr = docPaths.toString().substring(0, docPaths.toString().length() - 1);
|
|
|
+ String docFileNameStr = docFileNames.toString().substring(0, docFileNames.toString().length() - 1);
|
|
|
+ if (StringUtils.isNotEmpty(evaluationNotice.getNoticeAnnex())) {//true:非空串
|
|
|
+ String noticeAnnex = evaluationNotice.getNoticeAnnex() + "," + docPathStr;
|
|
|
+ evaluationNotice.setNoticeAnnex(noticeAnnex);
|
|
|
+ String memo4 = evaluationNotice.getMemo4() + "," + docFileNameStr;
|
|
|
+ evaluationNotice.setMemo4(memo4);
|
|
|
+ } else {
|
|
|
+ evaluationNotice.setNoticeAnnex(docPathStr);
|
|
|
+ evaluationNotice.setMemo4(docFileNameStr);
|
|
|
+ }
|
|
|
+ baseMapper.updateById(evaluationNotice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteAttachment(String id, String docPath, HttpServletRequest request) {
|
|
|
+ EvaluationNotice evaluationNotice = baseMapper.selectById(id);
|
|
|
+ if (null != evaluationNotice) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("iamAccessToken", request.getHeader("Blade-Auth"));
|
|
|
+ headers.add("iamCode", request.getHeader("code"));
|
|
|
+ HttpEntity<Map> param = new HttpEntity<>(null, headers);
|
|
|
+ ResponseEntity<String> responseEntity2 = restTemplate.exchange(imaConfig.getGatewayUrl() + "f-center/dm/dmDoc/remove?docPath={1}", HttpMethod.GET, param, String.class, docPath);
|
|
|
+ log.info("\n code:{}\n header:{}\n body:{}\n", responseEntity2.getStatusCodeValue(), responseEntity2.getHeaders(), responseEntity2.getBody());
|
|
|
+ if (200 == responseEntity2.getStatusCodeValue()) {
|
|
|
+ ResultInfo resultInfo = JSON.parseObject(responseEntity2.getBody(), ResultInfo.class);
|
|
|
+ if ("删除成功".equals(resultInfo.getMessage())) {
|
|
|
+ String[] noticeAnnexStr = evaluationNotice.getNoticeAnnex().split(",");
|
|
|
+ String[] memo4Str = evaluationNotice.getMemo4().split(",");
|
|
|
+ StringBuilder docPaths = new StringBuilder();
|
|
|
+ StringBuilder docFileNames = new StringBuilder();
|
|
|
+ for (int i = 0; i < noticeAnnexStr.length; i++) {
|
|
|
+ if (!noticeAnnexStr[i].equals(docPath)) {
|
|
|
+ docPaths.append(noticeAnnexStr[i]).append(",");
|
|
|
+ docFileNames.append(memo4Str[i]).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String docPathStr = docPaths.toString().substring(0, docPaths.toString().length() - 1);
|
|
|
+ evaluationNotice.setNoticeAnnex(docPathStr);
|
|
|
+ String docFileNameStr = docFileNames.toString().substring(0, docFileNames.toString().length() - 1);
|
|
|
+ evaluationNotice.setMemo4(docFileNameStr);
|
|
|
+ baseMapper.updateById(evaluationNotice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EvaluationNotice> circularDisplay(String deptId, String noticeTitle, String beginDataTime, 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 = baseMapper.selectList(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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|