diff --git a/start/src/main/resources/sdk-prod-gwj.yml b/start/src/main/resources/sdk-prod-gwj.yml index 217336c..6888ba2 100644 --- a/start/src/main/resources/sdk-prod-gwj.yml +++ b/start/src/main/resources/sdk-prod-gwj.yml @@ -71,3 +71,5 @@ sg: message: code: forward: MS000116 +file: + url: http://192.168.192.201:8991/file/uploadFiles2/ \ No newline at end of file diff --git a/start/src/main/resources/sdk-prod.yml b/start/src/main/resources/sdk-prod.yml index 6ac96e3..377abaf 100644 --- a/start/src/main/resources/sdk-prod.yml +++ b/start/src/main/resources/sdk-prod.yml @@ -71,3 +71,5 @@ sg: message: code: forward: MS000145 +file: + url: https://jpfz.qhdsafety.com/gbsFileTest/ \ No newline at end of file diff --git a/web-adapter/src/main/java/com/zcloud/safety/receive/BusCalendarController.java b/web-adapter/src/main/java/com/zcloud/safety/receive/BusCalendarController.java index 6398cad..913b6b8 100644 --- a/web-adapter/src/main/java/com/zcloud/safety/receive/BusCalendarController.java +++ b/web-adapter/src/main/java/com/zcloud/safety/receive/BusCalendarController.java @@ -4,7 +4,8 @@ import com.alibaba.fastjson.JSON; import com.zcloud.safety.api.SgCalendarServiceI; import com.zcloud.safety.domain.utils.EncryptAndDecryptUtil; import com.zcloud.safety.domain.utils.Result; -import com.zcloud.safety.dto.receive.SgCalendarAuditDTO; +import com.zcloud.safety.dto.receive.SgCalendarReceiveBodyDTO; +import com.zcloud.safety.dto.receive.SgCalendarReceiveNoticeDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -38,56 +39,64 @@ public class BusCalendarController { private final SgCalendarServiceI sgCalendarService; /** - * 接收数港回传的审核结果,并更新本地审核状态。 + * 接收集团下发的安全月历数据并批量保存。 */ @PostMapping("/release") - @ApiOperation(value = "接收数港安全月历审核结果", notes = "用于接收数港统计审核后的状态回传") + @ApiOperation(value = "接收数港安全月历", notes = "用于接收集团下发的安全月历数据") @ApiResponses({ @ApiResponse(code = 0, message = "成功"), @ApiResponse(code = 500, message = "服务器内部错误"), }) public Result release(@RequestParam(value = "key") String key, - @RequestParam(value = "value") String value) throws Exception { + @RequestParam(value = "value") String value) { try { - log.info("开始接收数港安全月历审核结果,key={},value={}", key,value); + log.info("开始接收数港安全月历,key长度:{},value长度:{}", key == null ? 0 : key.length(), value == null ? 0 : value.length()); if (!StringUtils.hasText(key) || !StringUtils.hasText(value)) { - log.warn("接收数港安全月历审核结果失败,请求参数缺失,key是否为空:{},value是否为空:{}", !StringUtils.hasText(key), !StringUtils.hasText(value)); + log.warn("接收数港安全月历失败,请求参数缺失,key是否为空:{},value是否为空:{}", !StringUtils.hasText(key), !StringUtils.hasText(value)); return new Result(400, "请求参数不能为空", null); } String decryptValue = EncryptAndDecryptUtil.decryptSm4(EncryptAndDecryptUtil.decryptSm2(key), value); - log.info("接收数港安全月历审核结果成功,解密报文:{}", decryptValue); - SgCalendarAuditDTO auditDTO = JSON.parseObject(decryptValue, SgCalendarAuditDTO.class); - String validateMessage = validateAudit(auditDTO); + log.info("数港安全月历报文解密成功,解密后内容:{}", decryptValue); + SgCalendarReceiveBodyDTO receiveBodyDTO = JSON.parseObject(decryptValue, SgCalendarReceiveBodyDTO.class); + String validateMessage = validateReceiveBody(receiveBodyDTO); if (validateMessage != null) { - log.warn("接收数港安全月历审核结果失败,报文校验未通过,原因:{},解密报文:{}", validateMessage, decryptValue); + log.warn("接收数港安全月历失败,报文校验未通过,原因:{},解密报文:{}", validateMessage, decryptValue); return new Result(400, validateMessage, null); } - log.info("开始接收数港安全月历审核结果,本地主键:{},审核状态:{}", auditDTO.getNoticeId(), auditDTO.getAuditType()); - sgCalendarService.receiveAudit(auditDTO); - log.info("接收数港安全月历审核结果成功,本地主键:{},审核状态:{}", auditDTO.getNoticeId(), auditDTO.getAuditType()); + sgCalendarService.receiveBatch(receiveBodyDTO); + log.info("接收数港安全月历成功,保存数量:{}", receiveBodyDTO.getNoticeList().size()); return Result.ok("成功"); } catch (Exception e) { - log.error("接收数港安全月历审核结果失败,key长度:{}", key == null ? 0 : key.length(), e); + log.error("接收数港安全月历失败,key长度:{}", key == null ? 0 : key.length(), e); return new Result(500, "数据传输失败", null); } } - private String validateAudit(SgCalendarAuditDTO auditDTO) { - if (auditDTO == null) { - return "安全月历审核报文不能为空"; + private String validateReceiveBody(SgCalendarReceiveBodyDTO receiveBodyDTO) { + if (receiveBodyDTO == null) { + return "安全月历报文不能为空"; } - if (auditDTO.getNoticeId() == null) { - return "通知id不能为空"; + if (receiveBodyDTO.getNoticeList() == null || receiveBodyDTO.getNoticeList().isEmpty()) { + return "安全月历数据列表不能为空"; } - if (!StringUtils.hasText(auditDTO.getAuditType())) { - return "审核状态不能为空"; - } - if (!"1".equals(auditDTO.getAuditType()) && !"2".equals(auditDTO.getAuditType())) { - return "审核状态不正确"; + for (SgCalendarReceiveNoticeDTO notice : receiveBodyDTO.getNoticeList()) { + String validateMessage = validateNotice(notice); + if (validateMessage != null) { + return validateMessage; + } } + return null; + } + private String validateNotice(SgCalendarReceiveNoticeDTO notice) { + if (notice == null) { + return "安全月历数据不能为空"; + } + if (notice.getId() == null) { + return "安全月历id不能为空"; + } return null; } } diff --git a/web-adapter/src/main/java/com/zcloud/safety/web/ImgFilesController.java b/web-adapter/src/main/java/com/zcloud/safety/web/ImgFilesController.java index 759b31e..595c7b8 100644 --- a/web-adapter/src/main/java/com/zcloud/safety/web/ImgFilesController.java +++ b/web-adapter/src/main/java/com/zcloud/safety/web/ImgFilesController.java @@ -53,13 +53,13 @@ public class ImgFilesController { } @ApiOperation("详情") - @GetMapping("/{id}") + @GetMapping("/getInfoById/{id}") public SingleResponse getInfoById(@PathVariable("id") Long id) { return SingleResponse.of(new ImgFilesCO()); } @ApiOperation("删除") - @DeleteMapping("/{id}") + @GetMapping("/remove/{id}") public Response remove(@PathVariable("id") Long id) { imgFilesService.remove(id); return SingleResponse.buildSuccess(); diff --git a/web-adapter/src/main/java/com/zcloud/safety/web/SgCalendarController.java b/web-adapter/src/main/java/com/zcloud/safety/web/SgCalendarController.java index addfa8d..aec619d 100644 --- a/web-adapter/src/main/java/com/zcloud/safety/web/SgCalendarController.java +++ b/web-adapter/src/main/java/com/zcloud/safety/web/SgCalendarController.java @@ -1,17 +1,13 @@ package com.zcloud.safety.web; import com.alibaba.cola.dto.PageResponse; -import com.alibaba.cola.dto.Response; import com.alibaba.cola.dto.SingleResponse; import com.zcloud.safety.api.SgCalendarServiceI; -import com.zcloud.safety.dto.SgCalendarAddCmd; import com.zcloud.safety.dto.SgCalendarPageQry; -import com.zcloud.safety.dto.SgCalendarUpdateCmd; import com.zcloud.safety.dto.clientobject.SgCalendarCO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** @@ -25,12 +21,6 @@ public class SgCalendarController { private final SgCalendarServiceI sgCalendarService; - @ApiOperation("新增") - @PostMapping("/save") - public SingleResponse add(@Validated SgCalendarAddCmd cmd) { - return sgCalendarService.add(cmd); - } - @ApiOperation("分页") @PostMapping("/list") public PageResponse page(@RequestBody SgCalendarPageQry qry) { @@ -42,25 +32,4 @@ public class SgCalendarController { public SingleResponse getInfoById(@PathVariable("id") Long id) { return sgCalendarService.getInfoById(id); } - - @ApiOperation("删除") - @PostMapping("/{id}") - public Response remove(@PathVariable("id") Long id) { - sgCalendarService.remove(id); - return SingleResponse.buildSuccess(); - } -/* - @ApiOperation("删除多个") - @DeleteMapping("/ids") - public Response removeBatch(@RequestParam Long[] ids) { - sgCalendarService.removeBatch(ids); - return SingleResponse.buildSuccess(); - }*/ - - @ApiOperation("修改") - @PostMapping("/edit") - public SingleResponse edit(@Validated SgCalendarUpdateCmd cmd) { - sgCalendarService.edit(cmd); - return SingleResponse.buildSuccess(); - } } diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgAccidentPushSupport.java b/web-app/src/main/java/com/zcloud/safety/command/SgAccidentPushSupport.java index 332b7fe..744cd6c 100644 --- a/web-app/src/main/java/com/zcloud/safety/command/SgAccidentPushSupport.java +++ b/web-app/src/main/java/com/zcloud/safety/command/SgAccidentPushSupport.java @@ -1,20 +1,37 @@ package com.zcloud.safety.command; import com.alibaba.cola.exception.BizException; +import com.zcloud.safety.config.FileUrlConfig; import com.zcloud.safety.domain.config.SgProperties; import com.zcloud.safety.domain.enums.PushOperationTypeEnum; import com.zcloud.safety.domain.enums.PushSourceEnum; import com.zcloud.safety.domain.utils.TokenUtils; +import com.zcloud.safety.persistence.dataobject.ImgFilesDO; import com.zcloud.safety.persistence.dataobject.SgAccidentDO; +import com.zcloud.safety.persistence.repository.ImgFilesRepository; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.util.StreamUtils; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 事故上报数港推送支持。 @@ -28,9 +45,36 @@ public class SgAccidentPushSupport { private static final PushSourceEnum DEFAULT_SOURCE = PushSourceEnum.QINGANG_GUFEN; private final SgProperties sgProperties; + private final ImgFilesRepository imgFilesRepository; + private final FileUrlConfig fileUrlConfig; /** - * 事故上报即使文档未显式声明附件,也按照真实协议透传多附件到数港。 + * 默认从附件表回查附件后推送,适用于修改、删除等需要基于当前库内附件状态推送的场景。 + */ + public void pushAccident(SgAccidentDO sgAccidentDO, PushOperationTypeEnum operationType) { + if (sgAccidentDO == null || sgAccidentDO.getId() == null) { + throw new BizException("事故上报数据不存在,无法推送数港"); + } + if (operationType == null) { + throw new BizException("事故上报推送操作类型不能为空"); + } + + try { + List imgFilesDOList = imgFilesRepository.listByForeignKey(sgAccidentDO.getAccidentId()); + MultipartFile[] pushFiles = buildPushFiles(imgFilesDOList); + Map requestData = buildRequestData(sgAccidentDO, operationType); + doPush(sgAccidentDO, operationType, requestData, pushFiles); + } catch (BizException e) { + throw e; + } catch (Exception e) { + log.error("推送事故上报到数港失败,操作类型:{}-{},本地主键:{}", + operationType.getCode(), operationType.getValue(), sgAccidentDO.getId(), e); + throw new BizException("推送数港失败"); + } + } + + /** + * 新增场景直接使用本次接收到的附件进行推送。 */ public void pushAccident(SgAccidentDO sgAccidentDO, PushOperationTypeEnum operationType, MultipartFile... files) { if (sgAccidentDO == null || sgAccidentDO.getId() == null) { @@ -41,18 +85,9 @@ public class SgAccidentPushSupport { } try { - String token = resolveToken(); + MultipartFile[] pushFiles = sanitizeFiles(files); Map requestData = buildRequestData(sgAccidentDO, operationType); - log.info("开始推送事故上报到数港,操作类型:{}-{},来源:{}-{},本地主键:{},请求数据:{}", - operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), sgAccidentDO.getId(), requestData); - if (sgProperties.getEnabled() == null || !sgProperties.getEnabled()) { - log.info("模拟真实推送事故上报到数港,操作类型:{}-{},来源:{}-{},本地主键:{},url:{},附件数量:{}", - operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), sgAccidentDO.getId(), sgProperties.getAccidentUrl(), files == null ? 0 : files.length); - } else { - TokenUtils.sendDataToThirdParty(sgProperties.getAccidentUrl(), requestData, token, files); - } - log.info("推送事故上报到数港成功,操作类型:{}-{},本地主键:{}", - operationType.getCode(), operationType.getValue(), sgAccidentDO.getId()); + doPush(sgAccidentDO, operationType, requestData, pushFiles); } catch (BizException e) { throw e; } catch (Exception e) { @@ -62,6 +97,23 @@ public class SgAccidentPushSupport { } } + private void doPush(SgAccidentDO sgAccidentDO, PushOperationTypeEnum operationType, + Map requestData, MultipartFile[] pushFiles) throws Exception { + String token = resolveToken(); + log.info("开始推送事故上报到数港,操作类型:{}-{},来源:{}-{},本地主键:{},附件数量:{},请求数据:{}", + operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), + sgAccidentDO.getId(), pushFiles.length, requestData); + if (sgProperties.getEnabled() == null || !sgProperties.getEnabled()) { + log.info("模拟真实推送事故上报到数港,操作类型:{}-{},来源:{}-{},本地主键:{},url:{},附件数量:{}", + operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), + sgAccidentDO.getId(), sgProperties.getAccidentUrl(), pushFiles.length); + } else { + TokenUtils.sendDataToThirdParty(sgProperties.getAccidentUrl(), requestData, token, pushFiles); + } + log.info("推送事故上报到数港成功,操作类型:{}-{},本地主键:{}", + operationType.getCode(), operationType.getValue(), sgAccidentDO.getId()); + } + private String resolveToken() throws Exception { String token; if (sgProperties.getEnabled() == null || !sgProperties.getEnabled()) { @@ -69,7 +121,7 @@ public class SgAccidentPushSupport { } else { token = TokenUtils.getTokenFromThirdParty(sgProperties.getTokenUrl()); } - if (token == null || token.isEmpty()) { + if (!StringUtils.hasText(token)) { throw new BizException("获取数港token失败"); } return token; @@ -89,11 +141,82 @@ public class SgAccidentPushSupport { return requestData; } + /** + * 修改时统一按库内附件重组上传文件,文件真实访问路径使用 file.url 前缀拼接附件表 file_path。 + */ + private MultipartFile[] buildPushFiles(List imgFilesDOList) throws IOException { + if (imgFilesDOList == null || imgFilesDOList.isEmpty()) { + return new MultipartFile[0]; + } + + List multipartFileList = new ArrayList<>(); + for (ImgFilesDO imgFilesDO : imgFilesDOList) { + if (imgFilesDO == null || !StringUtils.hasText(imgFilesDO.getFilePath()) || !StringUtils.hasText(imgFilesDO.getFileName())) { + continue; + } + String accessPath = buildAccessPath(imgFilesDO.getFilePath()); + byte[] fileBytes = readFileBytes(accessPath); + multipartFileList.add(new StoredMultipartFile(imgFilesDO.getFileName(), fileBytes)); + } + return multipartFileList.toArray(new MultipartFile[0]); + } + + private MultipartFile[] sanitizeFiles(MultipartFile[] files) { + if (files == null || files.length == 0) { + return new MultipartFile[0]; + } + List result = new ArrayList<>(); + for (MultipartFile file : files) { + if (file != null && !file.isEmpty()) { + result.add(file); + } + } + return result.toArray(new MultipartFile[0]); + } + + private String buildAccessPath(String filePath) { + if (!StringUtils.hasText(filePath)) { + return filePath; + } + String trimFilePath = filePath.trim(); + if (trimFilePath.startsWith("http://") || trimFilePath.startsWith("https://")) { + return trimFilePath; + } + String prefixUrl = fileUrlConfig.getPrefixUrl(); + if (!StringUtils.hasText(prefixUrl)) { + return trimFilePath; + } + if (prefixUrl.endsWith("/") && trimFilePath.startsWith("/")) { + return prefixUrl + trimFilePath.substring(1); + } + if (!prefixUrl.endsWith("/") && !trimFilePath.startsWith("/")) { + return prefixUrl + "/" + trimFilePath; + } + return prefixUrl + trimFilePath; + } + + private byte[] readFileBytes(String accessPath) throws IOException { + try { + Path localPath = Paths.get(accessPath); + if (Files.exists(localPath)) { + return Files.readAllBytes(localPath); + } + } catch (Exception e) { + log.debug("事故上报附件路径不是本地文件,尝试按远程地址读取,路径:{}", accessPath); + } + + try (InputStream inputStream = new URL(accessPath).openStream()) { + return StreamUtils.copyToByteArray(inputStream); + } catch (Exception e) { + throw new BizException("读取事故上报附件失败,路径:" + accessPath); + } + } + private String resolveCreateBy(SgAccidentDO sgAccidentDO) { - if (sgAccidentDO.getCreateName() != null && !sgAccidentDO.getCreateName().isEmpty()) { + if (StringUtils.hasText(sgAccidentDO.getCreateName())) { return sgAccidentDO.getCreateName(); } - if (sgAccidentDO.getUpdateName() != null && !sgAccidentDO.getUpdateName().isEmpty()) { + if (StringUtils.hasText(sgAccidentDO.getUpdateName())) { return sgAccidentDO.getUpdateName(); } return "系统"; @@ -107,4 +230,58 @@ public class SgAccidentPushSupport { private String defaultString(String value) { return value == null ? "" : value; } + + /** + * 仅在事故上报推送链路中使用的内存文件对象。 + */ + private static class StoredMultipartFile implements MultipartFile { + + private final String originalFilename; + private final byte[] bytes; + + private StoredMultipartFile(String originalFilename, byte[] bytes) { + this.originalFilename = originalFilename; + this.bytes = bytes == null ? new byte[0] : bytes; + } + + @Override + public String getName() { + return "file"; + } + + @Override + public String getOriginalFilename() { + return originalFilename; + } + + @Override + public String getContentType() { + return URLConnection.guessContentTypeFromName(originalFilename); + } + + @Override + public boolean isEmpty() { + return bytes.length == 0; + } + + @Override + public long getSize() { + return bytes.length; + } + + @Override + public byte[] getBytes() { + return bytes; + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(bytes); + } + + @Override + public void transferTo(File dest) throws IOException { + Files.write(dest.toPath(), bytes); + } + } } diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgAccidentUpdateExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgAccidentUpdateExe.java index cfd9c48..9a3c6e8 100644 --- a/web-app/src/main/java/com/zcloud/safety/command/SgAccidentUpdateExe.java +++ b/web-app/src/main/java/com/zcloud/safety/command/SgAccidentUpdateExe.java @@ -13,7 +13,6 @@ import com.zcloud.safety.persistence.repository.ImgFilesRepository; import com.zcloud.safety.persistence.repository.SgAccidentRepository; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; @@ -50,6 +49,9 @@ public class SgAccidentUpdateExe { try { SgAccidentE sgAccidentE = new SgAccidentE(); + if (cmd.getAccidentTime() != null && cmd.getAccidentTime().length() == 10) { + cmd.setAccidentTime(cmd.getAccidentTime() + " 00:00:00"); + } BeanUtils.copyProperties(cmd, sgAccidentE); boolean res = sgAccidentGateway.update(sgAccidentE); @@ -57,14 +59,16 @@ public class SgAccidentUpdateExe { throw new BizException("修改失败"); } - replaceAccidentFiles(cmd.getAccidentId(), cmd.getFiles()); + // 修改时附件仅做新增补充,不再先删后增。 + saveAccidentFiles(cmd.getAccidentId(), cmd.getFiles()); SgAccidentDO latestAccident = sgAccidentRepository.getById(cmd.getId()); if (latestAccident == null) { throw new BizException("修改后未查询到事故上报数据"); } - sgAccidentPushSupport.pushAccident(latestAccident, PushOperationTypeEnum.UPDATE, cmd.getFiles()); - log.info("事故上报修改完成,本地主键:{},附件数量:{}", cmd.getId(), cmd.getFiles() == null ? 0 : cmd.getFiles().length); + // 推送前统一按业务外键回查当前有效附件,保证页面先删图再编辑时也能推送最新附件集合。 + sgAccidentPushSupport.pushAccident(latestAccident, PushOperationTypeEnum.UPDATE); + log.info("事故上报修改完成,本地主键:{},本次新增附件数量:{}", cmd.getId(), countValidFiles(cmd.getFiles())); } catch (BizException e) { log.error("修改事故上报失败,主键:{},原因:{}", cmd.getId(), e.getMessage(), e); throw e; @@ -75,36 +79,49 @@ public class SgAccidentUpdateExe { } /** - * 新附件重传时先删除旧附件,再保存新附件。 + * 修改时如果前端补传新附件,则直接追加保存;删除动作由图片删除接口单独维护。 */ - private void replaceAccidentFiles(String accidentId, MultipartFile[] files) throws Exception { + private void saveAccidentFiles(String accidentId, MultipartFile[] files) throws Exception { if (files == null || files.length == 0) { return; } - imgFilesRepository.deletedImgFilesByForeignId(accidentId); - saveAccidentFiles(accidentId, files); - } - private void saveAccidentFiles(String accidentId, MultipartFile[] files) throws Exception { List imgFilesDOList = new ArrayList<>(); for (MultipartFile file : files) { if (file == null || file.isEmpty()) { continue; } - String fileName = Tools.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + String originalFilename = file.getOriginalFilename(); + if (originalFilename == null || !originalFilename.contains(".")) { + throw new BizException("附件名称不合法"); + } + String fileName = Tools.get32UUID() + originalFilename.substring(originalFilename.lastIndexOf(".")); String filePath = zcloudImgFilesFacade.saveFileNoCorpinfoId(file.getBytes(), fileName, "accident"); ImgFilesDO imgFilesDO = new ImgFilesDO(); imgFilesDO.setImgFilesId(Tools.get32UUID()); imgFilesDO.setFilePath(filePath); imgFilesDO.setForeignKey(accidentId); - imgFilesDO.setFileName(file.getOriginalFilename()); + imgFilesDO.setFileName(originalFilename); imgFilesDO.setType(ACCIDENT_FILE_TYPE); imgFilesDOList.add(imgFilesDO); } if (!imgFilesDOList.isEmpty()) { imgFilesRepository.saveBatch(imgFilesDOList); - log.info("事故上报附件保存完成,本地主键:{},附件数量:{}", accidentId, imgFilesDOList.size()); + log.info("事故上报附件追加保存完成,业务外键:{},新增附件数量:{}", accidentId, imgFilesDOList.size()); } } + + private int countValidFiles(MultipartFile[] files) { + if (files == null || files.length == 0) { + return 0; + } + int count = 0; + for (MultipartFile file : files) { + if (file != null && !file.isEmpty()) { + count++; + } + } + return count; + } } diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarAddExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarAddExe.java deleted file mode 100644 index 192952c..0000000 --- a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarAddExe.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.zcloud.safety.command; - -import com.alibaba.cola.exception.BizException; -import com.zcloud.gbscommon.utils.Tools; -import com.zcloud.gbscommon.zcloudimgfiles.facade.ZcloudImgFilesFacade; -import com.zcloud.safety.domain.enums.PushOperationTypeEnum; -import com.zcloud.safety.domain.gateway.SgCalendarGateway; -import com.zcloud.safety.domain.model.SgCalendarE; -import com.zcloud.safety.dto.SgCalendarAddCmd; -import com.zcloud.safety.persistence.dataobject.ImgFilesDO; -import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import com.zcloud.safety.persistence.repository.ImgFilesRepository; -import com.zcloud.safety.persistence.repository.SgCalendarRepository; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -import java.util.ArrayList; -import java.util.List; - -/** - * 安全月历新增执行器。 - */ -@Slf4j -@Component -@AllArgsConstructor -public class SgCalendarAddExe { - - private static final String PENDING_AUDIT_TYPE = "0"; - private static final int CALENDAR_FILE_TYPE = 4; - - private final SgCalendarGateway sgCalendarGateway; - private final SgCalendarRepository sgCalendarRepository; - private final ImgFilesRepository imgFilesRepository; - private final SgCalendarPushSupport sgCalendarPushSupport; - - @DubboReference - private ZcloudImgFilesFacade zcloudImgFilesFacade; - - @Transactional(rollbackFor = Exception.class) - public boolean execute(SgCalendarAddCmd cmd) { - SgCalendarE sgCalendarE = new SgCalendarE(); - BeanUtils.copyProperties(cmd, sgCalendarE); - initAuditStatus(sgCalendarE); - - try { - boolean res = sgCalendarGateway.add(sgCalendarE); - if (!res) { - throw new BizException("保存失败"); - } - if (sgCalendarE.getId() == null) { - throw new BizException("新增安全月历后未获取到主键"); - } - - saveCalendarFiles(sgCalendarE.getCalendarId(), cmd.getFiles()); - SgCalendarDO latestCalendar = sgCalendarRepository.getById(sgCalendarE.getId()); - if (latestCalendar == null) { - throw new BizException("新增安全月历后未查询到数据"); - } - - sgCalendarPushSupport.pushCalendar(latestCalendar, PushOperationTypeEnum.ADD, cmd.getFiles()); - return true; - } catch (BizException e) { - log.error("新增安全月历失败,原因:{}", e.getMessage(), e); - throw e; - } catch (Exception e) { - log.error("新增安全月历失败", e); - throw new BizException("保存失败"); - } - } - - private void initAuditStatus(SgCalendarE sgCalendarE) { - sgCalendarE.setAuditType(PENDING_AUDIT_TYPE); - sgCalendarE.setAuditContent(""); - } - - private void saveCalendarFiles(String calendarId, MultipartFile[] files) throws Exception { - if (files == null || files.length == 0) { - return; - } - - List imgFilesDOList = new ArrayList<>(); - for (MultipartFile file : files) { - if (file == null || file.isEmpty()) { - continue; - } - String fileName = Tools.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); - String filePath = zcloudImgFilesFacade.saveFileNoCorpinfoId(file.getBytes(), fileName, "calendar"); - ImgFilesDO imgFilesDO = new ImgFilesDO(); - imgFilesDO.setImgFilesId(Tools.get32UUID()); - imgFilesDO.setFilePath(filePath); - imgFilesDO.setForeignKey(calendarId); - imgFilesDO.setFileName(file.getOriginalFilename()); - imgFilesDO.setType(CALENDAR_FILE_TYPE); - imgFilesDOList.add(imgFilesDO); - } - - if (!imgFilesDOList.isEmpty()) { - imgFilesRepository.saveBatch(imgFilesDOList); - log.info("安全月历附件保存完成,本地主键:{},附件数量:{}", calendarId, imgFilesDOList.size()); - } - } -} diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarPushSupport.java b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarPushSupport.java deleted file mode 100644 index dc57fe6..0000000 --- a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarPushSupport.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.zcloud.safety.command; - -import com.alibaba.cola.exception.BizException; -import com.zcloud.safety.domain.config.SgProperties; -import com.zcloud.safety.domain.enums.PushOperationTypeEnum; -import com.zcloud.safety.domain.enums.PushSourceEnum; -import com.zcloud.safety.domain.utils.TokenUtils; -import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; -import org.springframework.web.multipart.MultipartFile; - -import java.util.HashMap; -import java.util.Map; - -/** - * 安全月历数港推送支持。 - */ -@Slf4j -@Component -@AllArgsConstructor -public class SgCalendarPushSupport { - - private static final PushSourceEnum DEFAULT_SOURCE = PushSourceEnum.QINGANG_GUFEN; - - private final SgProperties sgProperties; - - /** - * 安全月历推送统一走枚举,便于后续扩展来源映射和操作类型字典。 - */ - public void pushCalendar(SgCalendarDO sgCalendarDO, PushOperationTypeEnum operationType, MultipartFile... files) { - if (sgCalendarDO == null || sgCalendarDO.getId() == null) { - throw new BizException("安全月历数据不存在,无法推送数港"); - } - if (operationType == null) { - throw new BizException("安全月历推送操作类型不能为空"); - } - - try { - String token = resolveToken(); - Map requestData = buildRequestData(sgCalendarDO, operationType); - log.info("开始推送安全月历到数港,操作类型:{}-{},来源:{}-{},本地主键:{},请求数据:{}", - operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), sgCalendarDO.getId(), requestData); - if (sgProperties.getEnabled() == null || !sgProperties.getEnabled()) { - log.info("模拟真实推送安全月历到数港,操作类型:{}-{},来源:{}-{},本地主键:{},url:{},请求数据:{}", - operationType.getCode(), operationType.getValue(), DEFAULT_SOURCE.getCode(), DEFAULT_SOURCE.getValue(), sgCalendarDO.getId(), sgProperties.getCalendarUrl(), requestData); - } else { - TokenUtils.sendDataToThirdParty(sgProperties.getCalendarUrl(), requestData, token, files); - } - log.info("推送安全月历到数港成功,操作类型:{}-{},本地主键:{}", - operationType.getCode(), operationType.getValue(), sgCalendarDO.getId()); - } catch (BizException e) { - throw e; - } catch (Exception e) { - log.error("推送安全月历到数港失败,操作类型:{}-{},本地主键:{}", - operationType.getCode(), operationType.getValue(), sgCalendarDO.getId(), e); - throw new BizException("推送数港失败"); - } - } - - private String resolveToken() throws Exception { - String token; - if (sgProperties.getEnabled() == null || !sgProperties.getEnabled()) { - token = "tokenAAAA"; - } else { - token = TokenUtils.getTokenFromThirdParty(sgProperties.getTokenUrl()); - } - if (token == null || token.isEmpty()) { - throw new BizException("获取数港token失败"); - } - return token; - } - - private Map buildRequestData(SgCalendarDO sgCalendarDO, PushOperationTypeEnum operationType) { - Map requestData = new HashMap<>(); - requestData.put("operationType", operationType.getCode()); - requestData.put("noticeId", sgCalendarDO.getId()); - requestData.put("noticeTitle", defaultString(sgCalendarDO.getNoticeTitle())); - requestData.put("noticeType", defaultString(sgCalendarDO.getNoticeType())); - requestData.put("noticeContent", defaultString(sgCalendarDO.getNoticeContent())); - requestData.put("noticeDate", defaultString(sgCalendarDO.getNoticeDate())); - requestData.put("companyId", defaultString(sgCalendarDO.getCompanyId())); - requestData.put("companyName", defaultString(sgCalendarDO.getCompanyName())); - requestData.put("source", DEFAULT_SOURCE.getCode()); - requestData.put("createBy", resolveCreateBy(sgCalendarDO)); - return requestData; - } - - private String resolveCreateBy(SgCalendarDO sgCalendarDO) { - if (sgCalendarDO.getCreateName() != null && !sgCalendarDO.getCreateName().isEmpty()) { - return sgCalendarDO.getCreateName(); - } - if (sgCalendarDO.getUpdateName() != null && !sgCalendarDO.getUpdateName().isEmpty()) { - return sgCalendarDO.getUpdateName(); - } - return "系统"; - } - - private String defaultString(String value) { - return value == null ? "" : value; - } -} diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarReceiveExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarReceiveExe.java new file mode 100644 index 0000000..646ea09 --- /dev/null +++ b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarReceiveExe.java @@ -0,0 +1,76 @@ +package com.zcloud.safety.command; + +import com.alibaba.cola.exception.BizException; +import com.zcloud.safety.dto.receive.SgCalendarReceiveNoticeDTO; +import com.zcloud.safety.persistence.dataobject.SgCalendarDO; +import com.zcloud.safety.persistence.repository.SgCalendarRepository; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + * 安全月历批量接收执行器。 + */ +@Slf4j +@Component +@AllArgsConstructor +public class SgCalendarReceiveExe { + + private final SgCalendarRepository sgCalendarRepository; + + /** + * 接收集团下发的安全月历数据并批量落库。 + */ + @Transactional(rollbackFor = Exception.class) + public void execute(List noticeList, String token) { + if (CollectionUtils.isEmpty(noticeList)) { + log.warn("接收安全月历批量数据为空,未执行保存,token长度:{}", token == null ? 0 : token.length()); + return; + } + + log.info("开始批量保存安全月历,数量:{},token长度:{}", noticeList.size(), token == null ? 0 : token.length()); + for (SgCalendarReceiveNoticeDTO notice : noticeList) { + saveOrUpdate(notice); + } + log.info("批量保存安全月历完成,数量:{}", noticeList.size()); + } + + private void saveOrUpdate(SgCalendarReceiveNoticeDTO notice) { + if (notice == null || notice.getId() == null) { + throw new BizException("安全月历id不能为空"); + } + + SgCalendarDO calendarDO = sgCalendarRepository.getById(notice.getId()); + boolean isNew = calendarDO == null; + if (isNew) { + calendarDO = new SgCalendarDO(); + calendarDO.setId(notice.getId()); + } + + calendarDO.setCalendarId(String.valueOf(notice.getId())); + calendarDO.setAccidentTime(trim(notice.getAccidentTime())); + calendarDO.setAccidentUnit(trim(notice.getAccidentUnit())); + calendarDO.setAccidentProject(trim(notice.getAccidentProject())); + calendarDO.setAccidentDescription(trim(notice.getAccidentDescription())); + calendarDO.setAccidentLost(trim(notice.getAccidentLost())); + calendarDO.setAccidentLevel(trim(notice.getAccidentLevel())); + + if (isNew) { + sgCalendarRepository.save(calendarDO); + log.info("新增安全月历成功,id:{}", notice.getId()); + return; + } + + sgCalendarRepository.updateById(calendarDO); + log.info("更新安全月历成功,id:{}", notice.getId()); + } + + private String trim(String value) { + return StringUtils.hasText(value) ? value.trim() : value; + } +} diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarRemoveExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarRemoveExe.java deleted file mode 100644 index 176985c..0000000 --- a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarRemoveExe.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.zcloud.safety.command; - -import com.alibaba.cola.exception.BizException; -import com.zcloud.safety.domain.enums.PushOperationTypeEnum; -import com.zcloud.safety.domain.gateway.SgCalendarGateway; -import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import com.zcloud.safety.persistence.repository.ImgFilesRepository; -import com.zcloud.safety.persistence.repository.SgCalendarRepository; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -/** - * 安全月历删除执行器。 - */ -@Slf4j -@Component -@AllArgsConstructor -public class SgCalendarRemoveExe { - - private final SgCalendarGateway sgCalendarGateway; - private final SgCalendarRepository sgCalendarRepository; - private final ImgFilesRepository imgFilesRepository; - private final SgCalendarPushSupport sgCalendarPushSupport; - - @Transactional(rollbackFor = Exception.class) - public boolean execute(Long id) { - SgCalendarDO sgCalendarDO = sgCalendarRepository.getById(id); - if (sgCalendarDO == null) { - throw new BizException("该数据不存在"); - } - - boolean res = sgCalendarGateway.deletedSgCalendarById(id); - if (!res) { - throw new BizException("删除失败"); - } - - imgFilesRepository.deletedImgFilesByForeignId(String.valueOf(id)); - sgCalendarPushSupport.pushCalendar(sgCalendarDO, PushOperationTypeEnum.DELETE); - return true; - } - - @Transactional(rollbackFor = Exception.class) - public boolean execute(Long[] ids) { - boolean res = sgCalendarGateway.deletedSgCalendarByIds(ids); - if (!res) { - throw new BizException("删除失败"); - } - return true; - } -} diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarUpdateExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgCalendarUpdateExe.java deleted file mode 100644 index e466315..0000000 --- a/web-app/src/main/java/com/zcloud/safety/command/SgCalendarUpdateExe.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.zcloud.safety.command; - -import com.alibaba.cola.exception.BizException; -import com.zcloud.gbscommon.utils.Tools; -import com.zcloud.gbscommon.zcloudimgfiles.facade.ZcloudImgFilesFacade; -import com.zcloud.safety.domain.enums.PushOperationTypeEnum; -import com.zcloud.safety.domain.gateway.SgCalendarGateway; -import com.zcloud.safety.domain.model.SgCalendarE; -import com.zcloud.safety.dto.SgCalendarUpdateCmd; -import com.zcloud.safety.dto.receive.SgCalendarAuditDTO; -import com.zcloud.safety.persistence.dataobject.ImgFilesDO; -import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import com.zcloud.safety.persistence.repository.ImgFilesRepository; -import com.zcloud.safety.persistence.repository.SgCalendarRepository; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.config.annotation.DubboReference; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -import java.util.ArrayList; -import java.util.List; - -/** - * 安全月历修改执行器。 - */ -@Slf4j -@Component -@AllArgsConstructor -public class SgCalendarUpdateExe { - - private static final int CALENDAR_FILE_TYPE = 4; - - private final SgCalendarGateway sgCalendarGateway; - private final SgCalendarRepository sgCalendarRepository; - private final ImgFilesRepository imgFilesRepository; - private final SgCalendarPushSupport sgCalendarPushSupport; - - @DubboReference - private ZcloudImgFilesFacade zcloudImgFilesFacade; - - @Transactional(rollbackFor = Exception.class) - public void execute(SgCalendarUpdateCmd cmd) { - SgCalendarDO oldCalendar = sgCalendarRepository.getById(cmd.getId()); - if (oldCalendar == null) { - throw new BizException("该数据不存在"); - } - - try { - SgCalendarE sgCalendarE = new SgCalendarE(); - BeanUtils.copyProperties(cmd, sgCalendarE); - if ((sgCalendarE.getCalendarId() == null || sgCalendarE.getCalendarId().isEmpty()) - && oldCalendar.getCalendarId() != null && !oldCalendar.getCalendarId().isEmpty()) { - sgCalendarE.setCalendarId(oldCalendar.getCalendarId()); - } - - boolean res = sgCalendarGateway.update(sgCalendarE); - if (!res) { - throw new BizException("修改失败"); - } - - replaceCalendarFiles(cmd.getCalendarId(), cmd.getFiles()); - SgCalendarDO latestCalendar = sgCalendarRepository.getById(cmd.getId()); - if (latestCalendar == null) { - throw new BizException("修改后未查询到安全月历数据"); - } - - sgCalendarPushSupport.pushCalendar(latestCalendar, PushOperationTypeEnum.UPDATE, cmd.getFiles()); - } catch (BizException e) { - log.error("修改安全月历失败,主键:{},原因:{}", cmd.getId(), e.getMessage(), e); - throw e; - } catch (Exception e) { - log.error("修改安全月历失败,主键:{}", cmd.getId(), e); - throw new BizException("修改失败"); - } - } - - @Transactional(rollbackFor = Exception.class) - public void receiveAudit(SgCalendarAuditDTO auditDTO) { - SgCalendarDO oldCalendar = sgCalendarRepository.getById(auditDTO.getNoticeId()); - if (oldCalendar == null) { - throw new BizException("该数据不存在"); - } - - try { - SgCalendarE sgCalendarE = new SgCalendarE(); - sgCalendarE.setId(auditDTO.getNoticeId()); - sgCalendarE.setNoticeDate(auditDTO.getNoticeDate()); - sgCalendarE.setAuditType(auditDTO.getAuditType()); - sgCalendarE.setAuditContent(auditDTO.getAuditContent()); - boolean res = sgCalendarGateway.update(sgCalendarE); - if (!res) { - throw new BizException("审核状态更新失败"); - } - log.info("接收数港安全月历审核结果完成,本地主键:{},审核状态:{}", auditDTO.getNoticeId(), auditDTO.getAuditType()); - } catch (BizException e) { - log.error("接收数港安全月历审核结果失败,主键:{},原因:{}", auditDTO.getNoticeId(), e.getMessage(), e); - throw e; - } catch (Exception e) { - log.error("接收数港安全月历审核结果失败,主键:{}", auditDTO.getNoticeId(), e); - throw new BizException("审核状态更新失败"); - } - } - - private void replaceCalendarFiles(String calendarId, MultipartFile[] files) throws Exception { - if (files == null || files.length == 0) { - return; - } - imgFilesRepository.deletedImgFilesByForeignId(calendarId); - saveCalendarFiles(calendarId, files); - } - - private void saveCalendarFiles(String calendarId, MultipartFile[] files) throws Exception { - List imgFilesDOList = new ArrayList<>(); - for (MultipartFile file : files) { - if (file == null || file.isEmpty()) { - continue; - } - String fileName = Tools.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); - String filePath = zcloudImgFilesFacade.saveFileNoCorpinfoId(file.getBytes(), fileName, "calendar"); - ImgFilesDO imgFilesDO = new ImgFilesDO(); - imgFilesDO.setImgFilesId(Tools.get32UUID()); - imgFilesDO.setFilePath(filePath); - imgFilesDO.setForeignKey(calendarId); - imgFilesDO.setFileName(file.getOriginalFilename()); - imgFilesDO.setType(CALENDAR_FILE_TYPE); - imgFilesDOList.add(imgFilesDO); - } - - if (!imgFilesDOList.isEmpty()) { - imgFilesRepository.saveBatch(imgFilesDOList); - log.info("安全月历附件保存完成,本地主键:{},附件数量:{}", calendarId, imgFilesDOList.size()); - } - } -} diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgReferencePushSupport.java b/web-app/src/main/java/com/zcloud/safety/command/SgReferencePushSupport.java index 8bc4693..6697c1d 100644 --- a/web-app/src/main/java/com/zcloud/safety/command/SgReferencePushSupport.java +++ b/web-app/src/main/java/com/zcloud/safety/command/SgReferencePushSupport.java @@ -1,6 +1,7 @@ package com.zcloud.safety.command; import com.alibaba.cola.exception.BizException; +import com.zcloud.safety.config.FileUrlConfig; import com.zcloud.safety.domain.config.SgProperties; import com.zcloud.safety.domain.enums.PushOperationTypeEnum; import com.zcloud.safety.domain.enums.PushSourceEnum; @@ -45,6 +46,7 @@ public class SgReferencePushSupport { private final SgProperties sgProperties; private final ImgFilesRepository imgFilesRepository; + private final FileUrlConfig fileUrlConfig; /** * 默认从附件表回读附件后推送,适用于需要基于已落库附件推送的场景。 @@ -72,9 +74,7 @@ public class SgReferencePushSupport { } /** - * 直接使用本次请求收到的附件进行推送。 - * 适用于新增,或修改时前端明确上传了新附件的场景。 - * 当 files 为空时,只推送主数据,不给三方传附件。 + * 新增场景直接使用本次请求收到的附件进行推送。 */ public void pushReference(SgReferenceDO sgReferenceDO, PushOperationTypeEnum operationType, MultipartFile[] files) { if (sgReferenceDO == null || sgReferenceDO.getId() == null) { @@ -138,6 +138,9 @@ public class SgReferencePushSupport { return requestData; } + /** + * 修改时统一按库内附件重组上传文件,文件真实访问路径使用 file.url 前缀拼接附件表 file_path。 + */ private MultipartFile[] buildPushFiles(List imgFilesDOList) throws IOException { if (imgFilesDOList == null || imgFilesDOList.isEmpty()) { return new MultipartFile[0]; @@ -148,7 +151,8 @@ public class SgReferencePushSupport { if (imgFilesDO == null || !StringUtils.hasText(imgFilesDO.getFilePath()) || !StringUtils.hasText(imgFilesDO.getFileName())) { continue; } - byte[] fileBytes = readFileBytes(imgFilesDO.getFilePath()); + String accessPath = buildAccessPath(imgFilesDO.getFilePath()); + byte[] fileBytes = readFileBytes(accessPath); multipartFileList.add(new StoredMultipartFile(imgFilesDO.getFileName(), fileBytes)); } return multipartFileList.toArray(new MultipartFile[0]); @@ -167,20 +171,41 @@ public class SgReferencePushSupport { return result.toArray(new MultipartFile[0]); } - private byte[] readFileBytes(String filePath) throws IOException { + private String buildAccessPath(String filePath) { + if (!StringUtils.hasText(filePath)) { + return filePath; + } + String trimFilePath = filePath.trim(); + if (trimFilePath.startsWith("http://") || trimFilePath.startsWith("https://")) { + return trimFilePath; + } + String prefixUrl = fileUrlConfig.getPrefixUrl(); + if (!StringUtils.hasText(prefixUrl)) { + return trimFilePath; + } + if (prefixUrl.endsWith("/") && trimFilePath.startsWith("/")) { + return prefixUrl + trimFilePath.substring(1); + } + if (!prefixUrl.endsWith("/") && !trimFilePath.startsWith("/")) { + return prefixUrl + "/" + trimFilePath; + } + return prefixUrl + trimFilePath; + } + + private byte[] readFileBytes(String accessPath) throws IOException { try { - Path localPath = Paths.get(filePath); + Path localPath = Paths.get(accessPath); if (Files.exists(localPath)) { return Files.readAllBytes(localPath); } } catch (Exception e) { - log.debug("互学互鉴附件路径不是本地文件,尝试按远程地址读取,路径:{}", filePath); + log.debug("互学互鉴附件路径不是本地文件,尝试按远程地址读取,路径:{}", accessPath); } - try (InputStream inputStream = new URL(filePath).openStream()) { + try (InputStream inputStream = new URL(accessPath).openStream()) { return StreamUtils.copyToByteArray(inputStream); } catch (Exception e) { - throw new BizException("读取互学互鉴附件失败,路径:" + filePath); + throw new BizException("读取互学互鉴附件失败,路径:" + accessPath); } } @@ -228,7 +253,7 @@ public class SgReferencePushSupport { } /** - * 仅在互学互鉴推送链路中使用的内存文件对象,用于把附件表中的文件重新组装成上传参数。 + * 仅在互学互鉴推送链路中使用的内存文件对象。 */ private static class StoredMultipartFile implements MultipartFile { diff --git a/web-app/src/main/java/com/zcloud/safety/command/SgReferenceUpdateExe.java b/web-app/src/main/java/com/zcloud/safety/command/SgReferenceUpdateExe.java index a93f83c..ddf9ac3 100644 --- a/web-app/src/main/java/com/zcloud/safety/command/SgReferenceUpdateExe.java +++ b/web-app/src/main/java/com/zcloud/safety/command/SgReferenceUpdateExe.java @@ -13,7 +13,6 @@ import com.zcloud.safety.persistence.repository.ImgFilesRepository; import com.zcloud.safety.persistence.repository.SgReferenceRepository; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; @@ -56,19 +55,16 @@ public class SgReferenceUpdateExe { throw new BizException("修改失败"); } - replaceReferenceFiles(cmd.getReferenceId(), cmd.getFiles()); + // 修改时附件仅做新增补充,不再先删后增;页面删除由图片删除接口单独维护。 + saveReferenceFiles(cmd.getReferenceId(), cmd.getFiles()); SgReferenceDO latestReference = sgReferenceRepository.getById(cmd.getId()); if (latestReference == null) { throw new BizException("修改后未查询到互学互鉴数据"); } - // 修改时如果前端没传新附件,则不改附件,也不给三方传附件;有新附件时直接用本次附件推送。 - if (cmd.getFiles() != null && cmd.getFiles().length > 0) { - sgReferencePushSupport.pushReference(latestReference, PushOperationTypeEnum.UPDATE, cmd.getFiles()); - } else { - sgReferencePushSupport.pushReference(latestReference, PushOperationTypeEnum.UPDATE, null); - } - log.info("互学互鉴修改完成,本地主键:{},附件数量:{}", cmd.getId(), cmd.getFiles() == null ? 0 : cmd.getFiles().length); + // 推送前统一按业务外键回查当前有效附件,保证页面删图后再次编辑时三方接收到最新附件集合。 + sgReferencePushSupport.pushReference(latestReference, PushOperationTypeEnum.UPDATE); + log.info("互学互鉴修改完成,本地主键:{},本次新增附件数量:{}", cmd.getId(), countValidFiles(cmd.getFiles())); } catch (BizException e) { log.error("修改互学互鉴失败,主键:{},原因:{}", cmd.getId(), e.getMessage(), e); throw e; @@ -78,35 +74,50 @@ public class SgReferenceUpdateExe { } } - /** - * 新附件上传时只维护附件表,不再回写业务表冗余字段。 + * 修改时如果前端补传新附件,则直接追加保存。 */ - private void replaceReferenceFiles(String referenceId, MultipartFile[] files) throws Exception { + private void saveReferenceFiles(String referenceId, MultipartFile[] files) throws Exception { if (files == null || files.length == 0) { return; } - imgFilesRepository.deletedImgFilesByForeignId(referenceId); List imgFilesDOList = new ArrayList<>(); for (MultipartFile file : files) { if (file == null || file.isEmpty()) { continue; } - String fileName = Tools.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + String originalFilename = file.getOriginalFilename(); + if (originalFilename == null || !originalFilename.contains(".")) { + throw new BizException("附件名称不合法"); + } + String fileName = Tools.get32UUID() + originalFilename.substring(originalFilename.lastIndexOf(".")); String filePath = zcloudImgFilesFacade.saveFileNoCorpinfoId(file.getBytes(), fileName, "reference"); ImgFilesDO imgFilesDO = new ImgFilesDO(); imgFilesDO.setImgFilesId(Tools.get32UUID()); imgFilesDO.setFilePath(filePath); imgFilesDO.setForeignKey(referenceId); - imgFilesDO.setFileName(file.getOriginalFilename()); + imgFilesDO.setFileName(originalFilename); imgFilesDO.setType(REFERENCE_FILE_TYPE); imgFilesDOList.add(imgFilesDO); } if (!imgFilesDOList.isEmpty()) { imgFilesRepository.saveBatch(imgFilesDOList); - log.info("互学互鉴附件保存完成,本地主键:{},附件数量:{}", referenceId, imgFilesDOList.size()); + log.info("互学互鉴附件追加保存完成,业务外键:{},新增附件数量:{}", referenceId, imgFilesDOList.size()); } } + + private int countValidFiles(MultipartFile[] files) { + if (files == null || files.length == 0) { + return 0; + } + int count = 0; + for (MultipartFile file : files) { + if (file != null && !file.isEmpty()) { + count++; + } + } + return count; + } } diff --git a/web-app/src/main/java/com/zcloud/safety/command/query/SgCalendarQueryExe.java b/web-app/src/main/java/com/zcloud/safety/command/query/SgCalendarQueryExe.java index c2ec2a8..70f6eee 100644 --- a/web-app/src/main/java/com/zcloud/safety/command/query/SgCalendarQueryExe.java +++ b/web-app/src/main/java/com/zcloud/safety/command/query/SgCalendarQueryExe.java @@ -2,19 +2,14 @@ package com.zcloud.safety.command.query; import com.alibaba.cola.dto.PageResponse; import com.zcloud.gbscommon.utils.PageQueryHelper; -import com.zcloud.safety.command.convertor.ImgFilesCoConvertor; import com.zcloud.safety.command.convertor.SgCalendarCoConvertor; import com.zcloud.safety.dto.SgCalendarPageQry; -import com.zcloud.safety.dto.clientobject.ImgFilesCO; import com.zcloud.safety.dto.clientobject.SgCalendarCO; -import com.zcloud.safety.persistence.dataobject.ImgFilesDO; import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import com.zcloud.safety.persistence.repository.ImgFilesRepository; import com.zcloud.safety.persistence.repository.SgCalendarRepository; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,9 +21,7 @@ import java.util.Map; public class SgCalendarQueryExe { private final SgCalendarRepository sgCalendarRepository; - private final ImgFilesRepository imgFilesRepository; private final SgCalendarCoConvertor sgCalendarCoConvertor; - private final ImgFilesCoConvertor imgFilesCoConvertor; /** * 分页查询。 @@ -41,23 +34,13 @@ public class SgCalendarQueryExe { } /** - * 按主键查询详情,并回填附件列表。 + * 查询详情。 */ public SgCalendarCO getInfoById(Long id) { SgCalendarDO sgCalendarDO = sgCalendarRepository.getInfoById(id); if (sgCalendarDO == null) { return null; } - - SgCalendarCO sgCalendarCO = sgCalendarCoConvertor.converDOToCO(sgCalendarDO); - List imgFilesDOList = imgFilesRepository.listByForeignKey(String.valueOf(sgCalendarDO.getId())); - if (imgFilesDOList == null || imgFilesDOList.isEmpty()) { - sgCalendarCO.setImgFilesList(Collections.emptyList()); - return sgCalendarCO; - } - - List imgFilesCOList = imgFilesCoConvertor.converDOsToCOs(imgFilesDOList); - sgCalendarCO.setImgFilesList(imgFilesCOList); - return sgCalendarCO; + return sgCalendarCoConvertor.converDOToCO(sgCalendarDO); } } diff --git a/web-app/src/main/java/com/zcloud/safety/service/SgCalendarServiceImpl.java b/web-app/src/main/java/com/zcloud/safety/service/SgCalendarServiceImpl.java index 6539aad..76f532e 100644 --- a/web-app/src/main/java/com/zcloud/safety/service/SgCalendarServiceImpl.java +++ b/web-app/src/main/java/com/zcloud/safety/service/SgCalendarServiceImpl.java @@ -3,15 +3,11 @@ package com.zcloud.safety.service; import com.alibaba.cola.dto.PageResponse; import com.alibaba.cola.dto.SingleResponse; import com.zcloud.safety.api.SgCalendarServiceI; -import com.zcloud.safety.command.SgCalendarAddExe; -import com.zcloud.safety.command.SgCalendarRemoveExe; -import com.zcloud.safety.command.SgCalendarUpdateExe; +import com.zcloud.safety.command.SgCalendarReceiveExe; import com.zcloud.safety.command.query.SgCalendarQueryExe; -import com.zcloud.safety.dto.SgCalendarAddCmd; import com.zcloud.safety.dto.SgCalendarPageQry; -import com.zcloud.safety.dto.SgCalendarUpdateCmd; import com.zcloud.safety.dto.clientobject.SgCalendarCO; -import com.zcloud.safety.dto.receive.SgCalendarAuditDTO; +import com.zcloud.safety.dto.receive.SgCalendarReceiveBodyDTO; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @@ -22,9 +18,7 @@ import org.springframework.stereotype.Service; @AllArgsConstructor public class SgCalendarServiceImpl implements SgCalendarServiceI { - private final SgCalendarAddExe sgCalendarAddExe; - private final SgCalendarUpdateExe sgCalendarUpdateExe; - private final SgCalendarRemoveExe sgCalendarRemoveExe; + private final SgCalendarReceiveExe sgCalendarReceiveExe; private final SgCalendarQueryExe sgCalendarQueryExe; @Override @@ -38,28 +32,7 @@ public class SgCalendarServiceImpl implements SgCalendarServiceI { } @Override - public SingleResponse add(SgCalendarAddCmd cmd) { - sgCalendarAddExe.execute(cmd); - return SingleResponse.buildSuccess(); - } - - @Override - public void edit(SgCalendarUpdateCmd cmd) { - sgCalendarUpdateExe.execute(cmd); - } - - @Override - public void remove(Long id) { - sgCalendarRemoveExe.execute(id); - } - - @Override - public void removeBatch(Long[] ids) { - sgCalendarRemoveExe.execute(ids); - } - - @Override - public void receiveAudit(SgCalendarAuditDTO auditDTO) { - sgCalendarUpdateExe.receiveAudit(auditDTO); + public void receiveBatch(SgCalendarReceiveBodyDTO receiveBodyDTO) { + sgCalendarReceiveExe.execute(receiveBodyDTO.getNoticeList(), receiveBodyDTO.getToken()); } } diff --git a/web-client/src/main/java/com/zcloud/safety/api/SgCalendarServiceI.java b/web-client/src/main/java/com/zcloud/safety/api/SgCalendarServiceI.java index 8f0dc87..c2bdeb0 100644 --- a/web-client/src/main/java/com/zcloud/safety/api/SgCalendarServiceI.java +++ b/web-client/src/main/java/com/zcloud/safety/api/SgCalendarServiceI.java @@ -2,27 +2,18 @@ package com.zcloud.safety.api; import com.alibaba.cola.dto.PageResponse; import com.alibaba.cola.dto.SingleResponse; -import com.zcloud.safety.dto.SgCalendarAddCmd; import com.zcloud.safety.dto.SgCalendarPageQry; -import com.zcloud.safety.dto.SgCalendarUpdateCmd; import com.zcloud.safety.dto.clientobject.SgCalendarCO; -import com.zcloud.safety.dto.receive.SgCalendarAuditDTO; +import com.zcloud.safety.dto.receive.SgCalendarReceiveBodyDTO; /** * 安全月历服务接口。 */ public interface SgCalendarServiceI { + PageResponse listPage(SgCalendarPageQry qry); SingleResponse getInfoById(Long id); - SingleResponse add(SgCalendarAddCmd cmd); - - void edit(SgCalendarUpdateCmd cmd); - - void remove(Long id); - - void removeBatch(Long[] ids); - - void receiveAudit(SgCalendarAuditDTO auditDTO); + void receiveBatch(SgCalendarReceiveBodyDTO receiveBodyDTO); } diff --git a/web-client/src/main/java/com/zcloud/safety/config/FileUrlConfig.java b/web-client/src/main/java/com/zcloud/safety/config/FileUrlConfig.java new file mode 100644 index 0000000..62d359a --- /dev/null +++ b/web-client/src/main/java/com/zcloud/safety/config/FileUrlConfig.java @@ -0,0 +1,22 @@ +package com.zcloud.safety.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +/** + * @author zhangyue + * @date 2026/2/11 10:05 + */ +@Configuration +public class FileUrlConfig { + private String prefixUrl; + @Value("${file.url}") + public void setPrefixUrl(String prefixUrlProperties) { + prefixUrl = prefixUrlProperties; + } + public String getPrefixUrl() { + // 正式环境 +// return "http://192.168.192.201:8991/file/uploadFiles2/"; + return prefixUrl; + } +} diff --git a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarAddCmd.java b/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarAddCmd.java deleted file mode 100644 index 86f82ae..0000000 --- a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarAddCmd.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.zcloud.safety.dto; - -import com.alibaba.cola.dto.Command; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import org.springframework.web.multipart.MultipartFile; - -import javax.validation.constraints.NotEmpty; - -/** - * 安全月历新增命令。 - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -public class SgCalendarAddCmd extends Command { - - @ApiModelProperty(value = "通知标题", name = "noticeTitle", required = true) - @NotEmpty(message = "通知标题不能为空") - private String noticeTitle; - - @ApiModelProperty(value = "通知类型,1 注意事项,2 巡视检查", name = "noticeType", required = true) - @NotEmpty(message = "通知类型不能为空") - private String noticeType; - - @ApiModelProperty(value = "通知内容", name = "noticeContent", required = true) - @NotEmpty(message = "通知内容不能为空") - private String noticeContent; - - @ApiModelProperty(value = "通知时间,格式 yyyy-MM-dd", name = "noticeDate", required = true) - @NotEmpty(message = "通知时间不能为空") - private String noticeDate; - - @ApiModelProperty(value = "公司id", name = "companyId", required = true) - @NotEmpty(message = "公司id不能为空") - private String companyId; - - @ApiModelProperty(value = "公司名称", name = "companyName", required = true) - @NotEmpty(message = "公司名称不能为空") - private String companyName; - - @ApiModelProperty(value = "附件", name = "files") - private MultipartFile[] files; -} diff --git a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarPageQry.java b/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarPageQry.java index 189aa0a..66e1627 100644 --- a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarPageQry.java +++ b/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarPageQry.java @@ -10,15 +10,15 @@ import lombok.Data; @Data public class SgCalendarPageQry extends PageQuery { - @ApiModelProperty(value = "通知标题", name = "noticeTitle") - private String noticeTitle; + @ApiModelProperty(value = "事故发生单位", name = "accidentUnit") + private String accidentUnit; - @ApiModelProperty(value = "通知类型", name = "noticeType") - private String noticeType; + @ApiModelProperty(value = "事故类型", name = "accidentProject") + private String accidentProject; - @ApiModelProperty(value = "开始通知时间", name = "startNoticeDate") - private String startNoticeDate; + @ApiModelProperty(value = "开始事故发生时间", name = "startAccidentTime") + private String startAccidentTime; - @ApiModelProperty(value = "结束通知时间", name = "endNoticeDate") - private String endNoticeDate; + @ApiModelProperty(value = "结束事故发生时间", name = "endAccidentTime") + private String endAccidentTime; } diff --git a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarUpdateCmd.java b/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarUpdateCmd.java deleted file mode 100644 index 1c7a549..0000000 --- a/web-client/src/main/java/com/zcloud/safety/dto/SgCalendarUpdateCmd.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.zcloud.safety.dto; - -import com.alibaba.cola.dto.Command; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import org.springframework.web.multipart.MultipartFile; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -/** - * 安全月历修改命令。 - */ -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -public class SgCalendarUpdateCmd extends Command { - - @ApiModelProperty(value = "主键", name = "id", required = true) - @NotNull(message = "主键不能为空") - private Long id; - - @ApiModelProperty(value = "业务主键id", name = "calendarId") - private String calendarId; - - @ApiModelProperty(value = "通知标题", name = "noticeTitle", required = true) - @NotEmpty(message = "通知标题不能为空") - private String noticeTitle; - - @ApiModelProperty(value = "通知类型,1 注意事项,2 巡视检查", name = "noticeType", required = true) - @NotEmpty(message = "通知类型不能为空") - private String noticeType; - - @ApiModelProperty(value = "通知内容", name = "noticeContent", required = true) - @NotEmpty(message = "通知内容不能为空") - private String noticeContent; - - @ApiModelProperty(value = "通知时间,格式 yyyy-MM-dd", name = "noticeDate", required = true) - @NotEmpty(message = "通知时间不能为空") - private String noticeDate; - - @ApiModelProperty(value = "公司id", name = "companyId", required = true) - @NotEmpty(message = "公司id不能为空") - private String companyId; - - @ApiModelProperty(value = "公司名称", name = "companyName", required = true) - @NotEmpty(message = "公司名称不能为空") - private String companyName; - - @ApiModelProperty(value = "附件", name = "files") - private MultipartFile[] files; -} diff --git a/web-client/src/main/java/com/zcloud/safety/dto/clientobject/SgCalendarCO.java b/web-client/src/main/java/com/zcloud/safety/dto/clientobject/SgCalendarCO.java index 54b0209..ce5ea23 100644 --- a/web-client/src/main/java/com/zcloud/safety/dto/clientobject/SgCalendarCO.java +++ b/web-client/src/main/java/com/zcloud/safety/dto/clientobject/SgCalendarCO.java @@ -1,13 +1,9 @@ package com.zcloud.safety.dto.clientobject; import com.alibaba.cola.dto.ClientObject; -import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.time.LocalDateTime; -import java.util.List; - /** * 安全月历返回对象。 */ @@ -20,68 +16,21 @@ public class SgCalendarCO extends ClientObject { @ApiModelProperty(value = "业务主键id") private String calendarId; - @ApiModelProperty(value = "通知标题") - private String noticeTitle; + @ApiModelProperty(value = "事故发生时间") + private String accidentTime; - @ApiModelProperty(value = "通知类型,1 注意事项,2 巡视检查") - private String noticeType; + @ApiModelProperty(value = "事故发生单位") + private String accidentUnit; - @ApiModelProperty(value = "通知内容") - private String noticeContent; + @ApiModelProperty(value = "事故类型") + private String accidentProject; - @ApiModelProperty(value = "通知时间") - private String noticeDate; + @ApiModelProperty(value = "事故经过简要描述") + private String accidentDescription; - @ApiModelProperty(value = "公司id") - private String companyId; + @ApiModelProperty(value = "死亡人数(事故直接经济损失)") + private String accidentLost; - @ApiModelProperty(value = "公司名称") - private String companyName; - - @ApiModelProperty(value = "审核状态") - private String auditType; - - @ApiModelProperty(value = "审核意见") - private String auditContent; - - @ApiModelProperty(value = "乐观锁") - private Integer version; - - @ApiModelProperty(value = "创建人") - private Long createId; - - @ApiModelProperty(value = "创建人姓名") - private String createName; - - @ApiModelProperty(value = "创建时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime createTime; - - @ApiModelProperty(value = "更新人") - private Long updateId; - - @ApiModelProperty(value = "修改人名称") - private String updateName; - - @ApiModelProperty(value = "更新时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private LocalDateTime updateTime; - - @ApiModelProperty(value = "描述") - private String remarks; - - @ApiModelProperty(value = "是否删除") - private String deleteEnum; - - @ApiModelProperty(value = "租户ID") - private Long tenantId; - - @ApiModelProperty(value = "机构ID") - private Long orgId; - - @ApiModelProperty(value = "环境") - private String env; - - @ApiModelProperty(value = "附件列表") - private List imgFilesList; + @ApiModelProperty(value = "事故等级") + private String accidentLevel; } diff --git a/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarAuditDTO.java b/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarAuditDTO.java deleted file mode 100644 index c9f23f6..0000000 --- a/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarAuditDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.zcloud.safety.dto.receive; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * 数港安全月历审核回传报文。 - */ -@Data -public class SgCalendarAuditDTO { - - @ApiModelProperty(value = "通知id", name = "noticeId") - private Long noticeId; - - @ApiModelProperty(value = "通知时间", name = "noticeDate") - private String noticeDate; - - @ApiModelProperty(value = "审核状态,1 同意,2 不同意", name = "auditType") - private String auditType; - - @ApiModelProperty(value = "审核意见", name = "auditContent") - private String auditContent; -} diff --git a/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveBodyDTO.java b/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveBodyDTO.java new file mode 100644 index 0000000..8aafcec --- /dev/null +++ b/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveBodyDTO.java @@ -0,0 +1,20 @@ +package com.zcloud.safety.dto.receive; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 安全月历批量接收对象。 + */ +@Data +public class SgCalendarReceiveBodyDTO implements Serializable { + + @ApiModelProperty(value = "下发的安全月历数据", name = "noticeList") + private List noticeList; + + @ApiModelProperty(value = "各港区 token", name = "token") + private String token; +} diff --git a/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveNoticeDTO.java b/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveNoticeDTO.java new file mode 100644 index 0000000..e7dcf5c --- /dev/null +++ b/web-client/src/main/java/com/zcloud/safety/dto/receive/SgCalendarReceiveNoticeDTO.java @@ -0,0 +1,34 @@ +package com.zcloud.safety.dto.receive; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 安全月历单条接收对象。 + */ +@Data +public class SgCalendarReceiveNoticeDTO implements Serializable { + + @ApiModelProperty(value = "安全月历id", name = "id") + private Long id; + + @ApiModelProperty(value = "事故发生时间,格式:yyyy-MM-dd", name = "accidentTime") + private String accidentTime; + + @ApiModelProperty(value = "事故发生单位", name = "accidentUnit") + private String accidentUnit; + + @ApiModelProperty(value = "事故类型", name = "accidentProject") + private String accidentProject; + + @ApiModelProperty(value = "事故经过简要描述", name = "accidentDescription") + private String accidentDescription; + + @ApiModelProperty(value = "死亡人数(事故直接经济损失)", name = "accidentLost") + private String accidentLost; + + @ApiModelProperty(value = "事故等级", name = "accidentLevel") + private String accidentLevel; +} diff --git a/web-domain/src/main/java/com/zcloud/safety/domain/gateway/SgCalendarGateway.java b/web-domain/src/main/java/com/zcloud/safety/domain/gateway/SgCalendarGateway.java deleted file mode 100644 index 3f1df1b..0000000 --- a/web-domain/src/main/java/com/zcloud/safety/domain/gateway/SgCalendarGateway.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.zcloud.safety.domain.gateway; - -import com.zcloud.safety.domain.model.SgCalendarE; - -/** - * web-domain - * - * @Author zhaokai - * @Date 2026-06-02 08:43:20 - */ -public interface SgCalendarGateway { - - /** - * 新增 - */ - Boolean add(SgCalendarE sgCalendarE); - - /** - * 修改 - */ - Boolean update(SgCalendarE sgCalendarE); - - /** - * 删除 - */ - Boolean deletedSgCalendarById(Long id); - - Boolean deletedSgCalendarByIds(Long[] id); -} - diff --git a/web-domain/src/main/java/com/zcloud/safety/domain/model/SgCalendarE.java b/web-domain/src/main/java/com/zcloud/safety/domain/model/SgCalendarE.java index 6baf4f8..d7035f1 100644 --- a/web-domain/src/main/java/com/zcloud/safety/domain/model/SgCalendarE.java +++ b/web-domain/src/main/java/com/zcloud/safety/domain/model/SgCalendarE.java @@ -6,56 +6,29 @@ import lombok.Data; import java.time.LocalDateTime; /** - * web-domain - * - * @Author zhaokai - * @Date 2026-06-02 08:43:20 + * 安全月历领域对象。 */ @Data public class SgCalendarE extends BaseE { - //主键 + private Long id; - //业务主键id private String calendarId; - //通知标题 - private String noticeTitle; - //通知类型| 1 注意事项, 2 巡视检查 - private String noticeType; - //通知内容 - private String noticeContent; - //通知时间 - private String noticeDate; - //公司id - private String companyId; - //公司名称 - private String companyName; - //审核状态 | 1 同意 , 2 不同意 - private String auditType; - //审核意见 - private String auditContent; - //乐观锁 + private String accidentTime; + private String accidentUnit; + private String accidentProject; + private String accidentDescription; + private String accidentLost; + private String accidentLevel; private Integer version; - //创建人 private Long createId; - //创建人姓名 private String createName; - //创建时间 private LocalDateTime createTime; - //更新人 private Long updateId; - //修改人名称 private String updateName; - //更新时间 private LocalDateTime updateTime; - //描述 private String remarks; - //是否删除 private String deleteEnum; - //租户ID private Long tenantId; - //机构ID private Long orgId; - //环境 private String env; } - diff --git a/web-domain/src/main/java/com/zcloud/safety/domain/utils/EncryptTestUtil.java b/web-domain/src/main/java/com/zcloud/safety/domain/utils/EncryptTestUtil.java index d22d42d..097d39d 100644 --- a/web-domain/src/main/java/com/zcloud/safety/domain/utils/EncryptTestUtil.java +++ b/web-domain/src/main/java/com/zcloud/safety/domain/utils/EncryptTestUtil.java @@ -21,17 +21,17 @@ public class EncryptTestUtil { private static final String PRIVATE_KEY = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgHnH3HOprVgU8ipdM6Mxp5Oyx87BlHva96f2CVCkVOBygCgYIKoEcz1UBgi2hRANCAASbjGgPBnqF4zSPMcY0esBBcJo6zRvDHk383M4D+gbKu+ZM+GQFyb50gCEIPEQgYRGNEwp8pH8jKCSBbwrhINGs"; public static void main(String[] args) { - // 测试数据(对应 SgCalendarAuditDTO 的 JSON 格式) + // 测试数据 //公告 -// String jsonData = "{\"noticeTitle\":\"测试标题\",\"noticeContent\":\"测试后没人内容\",\"createBy\":\"张三\",\"createTime\":\"2026-06-03 15:00:00\"}"; + String jsonData = "{\"noticeTitle\":\"测试标题\",\"noticeContent\":\"测试后没人内容\",\"createBy\":\"张三\",\"createTime\":\"2026-06-03 15:00:00\"}"; //通知 // String jsonData = "{\"informTitle\":\"测试通知标题\",\"informContent\":\"测试通知内容\",\"createBy\":\"张三1\",\"createTime\":\"2026-06-05 10:00:00\"}"; //督办 // String jsonData = "{\"superviseId\":123,\"superviseTitle\":\"测试督办标题\",\"superviseContent\":\"测试督办内容\",\"superviseStartTime\":\"2026-06-05 10:00:00\",\"superviseFinishTime\":\"2026-06-10 10:00:00\",\"createBy\":\"张三1\",\"createTime\":\"2026-06-05 10:00:00\"}"; //安全月历 -// String jsonData = "{\"noticeId\":2062779670919237633,\"auditType\":\"1\",\"auditContent\":\"同意了吧\",\"noticeDate\":\"2026-06-05 10:00:00\"}"; +// String jsonData = "{\"token\":\"tokenAAAA\",\"noticeList\":[{\"id\":2062779670919237633,\"accidentTime\":\"2026-06-05\",\"accidentUnit\":\"测试单位\",\"accidentProject\":\"火灾\",\"accidentDescription\":\"测试描述\",\"accidentLost\":\"1人\",\"accidentLevel\":\"一级\"}]}"; //互学互鉴 - String jsonData = "{\"accidentId\":1122,\"title\":\"标题虎穴\",\"fileName\":\"同意了吧\",\"createBy\":\"张三1\",\"createTime\":\"2026-06-05 15:00:00\"}"; +// String jsonData = "{\"accidentId\":1122,\"title\":\"标题虎穴\",\"fileName\":\"同意了吧\",\"createBy\":\"张三1\",\"createTime\":\"2026-06-05 15:00:00\"}"; // 1. 生成随机 SM4 密钥(16字节) byte[] sm4Key = generateRandomSM4Key(); System.out.println("SM4密钥(十六进制): " + bytesToHex(sm4Key)); diff --git a/web-infrastructure/src/main/java/com/zcloud/safety/gatewayimpl/SgCalendarGatewayImpl.java b/web-infrastructure/src/main/java/com/zcloud/safety/gatewayimpl/SgCalendarGatewayImpl.java deleted file mode 100644 index 6f9018f..0000000 --- a/web-infrastructure/src/main/java/com/zcloud/safety/gatewayimpl/SgCalendarGatewayImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.zcloud.safety.gatewayimpl; - -import com.zcloud.safety.domain.gateway.SgCalendarGateway; -import com.zcloud.safety.domain.model.SgCalendarE; -import com.zcloud.safety.persistence.dataobject.SgCalendarDO; -import com.zcloud.safety.persistence.repository.SgCalendarRepository; -import lombok.AllArgsConstructor; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Service; - -import java.util.Arrays; - -/** - * 安全月历网关实现。 - */ -@Service -@AllArgsConstructor -public class SgCalendarGatewayImpl implements SgCalendarGateway { - - private final SgCalendarRepository sgCalendarRepository; - - @Override - public Boolean add(SgCalendarE sgCalendarE) { - SgCalendarDO d = new SgCalendarDO(); - BeanUtils.copyProperties(sgCalendarE, d); - sgCalendarRepository.save(d); - sgCalendarE.setId(d.getId()); - if (d.getId() != null && (d.getCalendarId() == null || d.getCalendarId().isEmpty())) { - d.setCalendarId(String.valueOf(d.getId())); - sgCalendarRepository.updateById(d); - sgCalendarE.setCalendarId(d.getCalendarId()); - } - return true; - } - - @Override - public Boolean update(SgCalendarE sgCalendarE) { - SgCalendarDO d = new SgCalendarDO(); - BeanUtils.copyProperties(sgCalendarE, d); - sgCalendarRepository.updateById(d); - return true; - } - - @Override - public Boolean deletedSgCalendarById(Long id) { - return sgCalendarRepository.removeById(id); - } - - @Override - public Boolean deletedSgCalendarByIds(Long[] ids) { - return sgCalendarRepository.removeByIds(Arrays.asList(ids)); - } -} diff --git a/web-infrastructure/src/main/java/com/zcloud/safety/persistence/dataobject/SgCalendarDO.java b/web-infrastructure/src/main/java/com/zcloud/safety/persistence/dataobject/SgCalendarDO.java index ee611bd..c1533e6 100644 --- a/web-infrastructure/src/main/java/com/zcloud/safety/persistence/dataobject/SgCalendarDO.java +++ b/web-infrastructure/src/main/java/com/zcloud/safety/persistence/dataobject/SgCalendarDO.java @@ -8,47 +8,36 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; /** - * web-infrastructure - * - * @Author zhaokai - * @Date 2026-06-02 08:43:20 + * 安全月历持久化对象。 */ @Data @TableName("sg_calendar") @NoArgsConstructor @EqualsAndHashCode(callSuper = true) public class SgCalendarDO extends BaseDO { - //业务主键id + @ApiModelProperty(value = "业务主键id") private String calendarId; - //通知标题 - @ApiModelProperty(value = "通知标题") - private String noticeTitle; - //通知类型| 1 注意事项, 2 巡视检查 - @ApiModelProperty(value = "通知类型| 1 注意事项, 2 巡视检查") - private String noticeType; - //通知内容 - @ApiModelProperty(value = "通知内容") - private String noticeContent; - //通知时间 - @ApiModelProperty(value = "通知时间") - private String noticeDate; - //公司id - @ApiModelProperty(value = "公司id") - private String companyId; - //公司名称 - @ApiModelProperty(value = "公司名称") - private String companyName; - //审核状态 | 1 同意 , 2 不同意 - @ApiModelProperty(value = "审核状态 | 1 同意 , 2 不同意") - private String auditType; - //审核意见 - @ApiModelProperty(value = "审核意见") - private String auditContent; + + @ApiModelProperty(value = "事故发生时间") + private String accidentTime; + + @ApiModelProperty(value = "事故发生单位") + private String accidentUnit; + + @ApiModelProperty(value = "事故类型") + private String accidentProject; + + @ApiModelProperty(value = "事故经过简要描述") + private String accidentDescription; + + @ApiModelProperty(value = "死亡人数(事故直接经济损失)") + private String accidentLost; + + @ApiModelProperty(value = "事故等级") + private String accidentLevel; public SgCalendarDO(String calendarId) { this.calendarId = calendarId; } - } - diff --git a/web-infrastructure/src/main/resources/mapper/SgCalendarMapper.xml b/web-infrastructure/src/main/resources/mapper/SgCalendarMapper.xml index c1eba47..0a79489 100644 --- a/web-infrastructure/src/main/resources/mapper/SgCalendarMapper.xml +++ b/web-infrastructure/src/main/resources/mapper/SgCalendarMapper.xml @@ -7,14 +7,12 @@ id, calendar_id AS calendarId, - notice_title AS noticeTitle, - notice_type AS noticeType, - notice_content AS noticeContent, - notice_date AS noticeDate, - company_id AS companyId, - company_name AS companyName, - audit_type AS auditType, - audit_content AS auditContent, + accident_time AS accidentTime, + accident_unit AS accidentUnit, + accident_project AS accidentProject, + accident_description AS accidentDescription, + accident_lost AS accidentLost, + accident_level AS accidentLevel, version, create_id AS createId, create_name AS createName, @@ -35,20 +33,20 @@ FROM sg_calendar delete_enum = 'FALSE' - - AND notice_title LIKE CONCAT('%', #{params.noticeTitle}, '%') + + AND accident_unit LIKE CONCAT('%', #{params.accidentUnit}, '%') - - AND notice_type = #{params.noticeType} + + AND accident_project = #{params.accidentProject} - - AND notice_date >= #{params.startNoticeDate} + + AND accident_time >= #{params.startAccidentTime} - - AND notice_date <= #{params.endNoticeDate} + + AND accident_time <= #{params.endAccidentTime} - ORDER BY create_time DESC + ORDER BY accident_time DESC, id DESC