feat(accident): 新增事故统计及导出功能优化

- 在 AccidentController 中增加根据企业 ID 和事故类型的统计接口- 修改事故导出接口为 GET 请求,并调整参数传递方式
-优化事故分页查询逻辑,自动填充当前租户 ID
- 调整 Excel 导出字段的时间格式注解位置以兼容解析
- 更新 AccidentGateway 和实现类,支持按类型筛选统计- 移除无用的测试接口和 RocketMQ 依赖配置- 设置服务端口为 8085 并启用消息绑定相关注解
- 调整查询 DTO 类型,使用 LocalDate 替代 LocalDateTime
- 补充缺失的认证上下文工具类导入并移除冗余工具类引用
- 更新 Mapper XML 文件,增加对事故类型的条件判断
- 升级 pom.xml 中 jjb-saas-system-client 版本至 1.7.0-SNAPSHOT
master
fangjiakai 2025-11-14 08:35:49 +08:00
parent 21a7364a36
commit 835b51f034
16 changed files with 68 additions and 42 deletions

View File

@ -20,9 +20,18 @@
<artifactId>zcloud_gbscommon</artifactId> <artifactId>zcloud_gbscommon</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>com.jjb.saas</groupId>
<artifactId>jjb-saas-system-client</artifactId>
<version>1.7.0-SNAPSHOT</version>
</dependency>
<!--Project modules--> <!--Project modules-->
<dependency> <dependency>
<groupId>com.zcloud.accident</groupId> <groupId>com.zcloud.accident</groupId>

View File

@ -1,7 +1,11 @@
package com.zcloud.accident; package com.zcloud.accident;
import com.jjb.saas.base.starter.bootstart.JJBSpringbootApplication; import com.jjb.saas.base.starter.bootstart.JJBSpringbootApplication;
import com.jjb.saas.framework.event.consumer.EnableConsumer;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
/** /**
* Spring Boot Starter * Spring Boot Starter

View File

@ -4,3 +4,5 @@ spring:
- classpath:nacos.yml - classpath:nacos.yml
- classpath:sdk.yml - classpath:sdk.yml
- classpath:swagger.yml - classpath:swagger.yml
server:
port: 8085

View File

@ -20,7 +20,7 @@ spring:
file-extension: yml file-extension: yml
shared-configs: shared-configs:
- config-common.yml - config-common.yml
- config-port.yml # - config-port.yml
- config-mq.yml - config-mq.yml
- config-log.yml - config-log.yml
- config-sdk-server.yml - config-sdk-server.yml

View File

@ -17,10 +17,6 @@
<groupId>com.jjb.saas</groupId> <groupId>com.jjb.saas</groupId>
<artifactId>jjb-saas-framework-adapter</artifactId> <artifactId>jjb-saas-framework-adapter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.zcloud.accident</groupId> <groupId>com.zcloud.accident</groupId>

View File

@ -1,6 +1,7 @@
package com.zcloud.accident.web; package com.zcloud.accident.web;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.cola.dto.MultiResponse; import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse; import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response; import com.alibaba.cola.dto.Response;
@ -50,13 +51,15 @@ public class AccidentController {
@ApiOperation("新增") @ApiOperation("新增")
@PostMapping("/save") @PostMapping("/save")
public SingleResponse<AccidentCO> add(@Validated @RequestBody AccidentAddCmd cmd) { public SingleResponse<AccidentCO> add(@Validated @RequestBody AccidentAddCmd cmd) {
SSOUser ssoUser = AuthContext.getCurrentUser();
return accidentService.add(cmd); return accidentService.add(cmd);
} }
@ApiOperation("分页") @ApiOperation("分页")
@PostMapping("/list") @PostMapping("/list")
public PageResponse<AccidentCO> page(@RequestBody AccidentPageQry qry) { public PageResponse<AccidentCO> page(@RequestBody AccidentPageQry qry) {
if(ObjectUtil.isNull(qry.getEqCorpinfoId())){
qry.setEqCorpinfoId(AuthContext.getTenantId());
}
return accidentService.listPage(qry); return accidentService.listPage(qry);
} }
@ -94,8 +97,8 @@ public class AccidentController {
} }
@ApiOperation("导出Excel") @ApiOperation("导出Excel")
@PostMapping("/export") @GetMapping("/export")
public void export(@RequestBody AccidentPageQry qry, HttpServletResponse response) throws IOException { public void export(AccidentPageQry qry, HttpServletResponse response) throws IOException {
// 使用listAll方法获取所有符合条件的数据 // 使用listAll方法获取所有符合条件的数据
List<AccidentCO> accidentCOList = accidentService.listAll(qry); List<AccidentCO> accidentCOList = accidentService.listAll(qry);
// 转换为导出CO // 转换为导出CO
@ -111,12 +114,5 @@ public class AccidentController {
public MultiResponse<AccidentCountStatCO> countByCorpinfoIdAndIncidentType(@RequestBody AccidentCountQry accidentCountQry) { public MultiResponse<AccidentCountStatCO> countByCorpinfoIdAndIncidentType(@RequestBody AccidentCountQry accidentCountQry) {
return accidentService.countByCorpinfoIdAndIncidentType(accidentCountQry); return accidentService.countByCorpinfoIdAndIncidentType(accidentCountQry);
} }
@GetMapping("/test")
public void test() {
ZcUserEvent zcUserEvent = new ZcUserEvent();
zcUserEvent.setName("hello world");
remoteEventPublisher.sendMessage(zcUserEvent,"zcloud:user:ev2" );
}
} }

View File

@ -71,7 +71,7 @@ public class AccidentQueryExe {
* @return * @return
*/ */
public MultiResponse<AccidentCountStatCO> countByCorpinfoIdAndIncidentType(AccidentCountQry accidentCountQry) { public MultiResponse<AccidentCountStatCO> countByCorpinfoIdAndIncidentType(AccidentCountQry accidentCountQry) {
List<com.zcloud.accident.domain.model.AccidentCountStat> resultList = accidentGateway.countByCorpinfoIdAndIncidentType(accidentCountQry.getCorpinfoIds()); List<com.zcloud.accident.domain.model.AccidentCountStat> resultList = accidentGateway.countByCorpinfoIdAndIncidentType(accidentCountQry.getCorpinfoIds(),accidentCountQry.getEqAccidentType());
List<AccidentCountStatCO> coList = accidentCountStatConvertor.convertToCOList(resultList); List<AccidentCountStatCO> coList = accidentCountStatConvertor.convertToCOList(resultList);
return MultiResponse.of(coList); return MultiResponse.of(coList);
} }

View File

@ -17,4 +17,6 @@ public class AccidentCountQry extends Query {
@ApiModelProperty(value = "公司ID列表") @ApiModelProperty(value = "公司ID列表")
private List<String> corpinfoIds; private List<String> corpinfoIds;
@ApiModelProperty(value = "类型")
private Integer eqAccidentType;
} }

View File

@ -4,8 +4,10 @@ import com.alibaba.cola.dto.PageQuery;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.sql.Date; import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -27,6 +29,8 @@ public class AccidentPageQry extends PageQuery {
* - `le`: * - `le`:
* - `ne`: SQL!= * - `ne`: SQL!=
*/ */
@ApiModelProperty(value = "所属企业", name = "eqCorpinfoId")
private Long eqCorpinfoId;
@ApiModelProperty(value = "事故名称", name = "likeIncidentName") @ApiModelProperty(value = "事故名称", name = "likeIncidentName")
private String likeIncidentName; private String likeIncidentName;
@ApiModelProperty(value = "事故地点", name = "likeLocation") @ApiModelProperty(value = "事故地点", name = "likeLocation")
@ -36,11 +40,13 @@ public class AccidentPageQry extends PageQuery {
@ApiModelProperty(value = "事故级别", name = "likeIncidentLevel") @ApiModelProperty(value = "事故级别", name = "likeIncidentLevel")
private String eqIncidentLevel; private String eqIncidentLevel;
@ApiModelProperty(value = "开始时间", name = "geIncidentDate") @ApiModelProperty(value = "开始时间", name = "geIncidentDate")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDateTime geIncidentDate; @JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate geIncidentDate;
@ApiModelProperty(value = "结束时间", name = "leIncidentDate") @ApiModelProperty(value = "结束时间", name = "leIncidentDate")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDateTime leIncidentDate; @JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate leIncidentDate;
@ApiModelProperty(value = "类型1事件2事故", name = "eqType") @ApiModelProperty(value = "类型1事件2事故", name = "eqType")
private Integer eqType; private Integer eqType;
} }

View File

@ -45,7 +45,7 @@ public class AccidentExportCO {
@ApiModelProperty(value = "事故发生时间") @ApiModelProperty(value = "事故发生时间")
@DateTimeFormat("yyyy-MM-dd HH:mm:ss") @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
@ExcelProperty(value = "事故发生时间", index = 7,format = "yyyy-MM-dd HH:mm:ss") @ExcelProperty(value = "事故发生时间", index = 7)
private LocalDateTime incidentDate; private LocalDateTime incidentDate;
@ApiModelProperty(value = "直接经济损失(万元)") @ApiModelProperty(value = "直接经济损失(万元)")
@ -85,7 +85,8 @@ public class AccidentExportCO {
private String measures; private String measures;
@ApiModelProperty(value = "报出日期") @ApiModelProperty(value = "报出日期")
@ExcelProperty(value = "报出日期", index = 17,format = "yyyy-MM-dd HH:mm:ss") @ExcelProperty(value = "报出日期", index = 17)
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private LocalDateTime reportDate; private LocalDateTime reportDate;
} }

View File

@ -30,9 +30,11 @@ public interface AccidentGateway {
/** /**
* corpinfoIdincidentType * corpinfoIdincidentType
* @param corpinfoIds ID *
* @param corpinfoIds ID
* @param eqAccidentType
* @return corpinfoIdincidentTypecount * @return corpinfoIdincidentTypecount
*/ */
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds); List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType);
} }

View File

@ -1,18 +1,17 @@
package com.zcloud.accident.gatewayimpl; package com.zcloud.accident.gatewayimpl;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.accident.domain.gateway.AccidentGateway; import com.zcloud.accident.domain.gateway.AccidentGateway;
import com.zcloud.accident.domain.model.AccidentE; import com.zcloud.accident.domain.model.AccidentE;
import com.zcloud.accident.domain.model.AccidentCountStat; import com.zcloud.accident.domain.model.AccidentCountStat;
import com.zcloud.accident.persistence.dataobject.AccidentDO; import com.zcloud.accident.persistence.dataobject.AccidentDO;
import com.zcloud.accident.persistence.repository.AccidentRepository; import com.zcloud.accident.persistence.repository.AccidentRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* web-infrastructure * web-infrastructure
@ -26,8 +25,10 @@ public class AccidentGatewayImpl implements AccidentGateway {
@Override @Override
public Boolean add(AccidentE accidentE) { public Boolean add(AccidentE accidentE) {
AccidentDO d = new AccidentDO(Tools.get32UUID()); AccidentDO d = new AccidentDO();
BeanUtils.copyProperties(accidentE, d, "accidentId"); BeanUtils.copyProperties(accidentE, d);
d.setCorpinfoId(AuthContext.getTenantId());
d.setCorpinfoName(AuthContext.getCurrentUser().getTenantName());
accidentRepository.save(d); accidentRepository.save(d);
return true; return true;
} }
@ -51,8 +52,8 @@ public class AccidentGatewayImpl implements AccidentGateway {
} }
@Override @Override
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds) { public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType) {
return accidentRepository.countByCorpinfoIdAndIncidentType(corpinfoIds); return accidentRepository.countByCorpinfoIdAndIncidentType(corpinfoIds,eqAccidentType);
} }
} }

View File

@ -18,9 +18,11 @@ public interface AccidentMapper extends BaseMapper<AccidentDO> {
/** /**
* corpinfoIdincidentType * corpinfoIdincidentType
* @param corpinfoIds ID *
* @param corpinfoIds ID
* @param eqAccidentType
* @return corpinfoIdincidentTypecount * @return corpinfoIdincidentTypecount
*/ */
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds); List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds,@Param("eqAccidentType") Integer eqAccidentType);
} }

View File

@ -26,9 +26,11 @@ public interface AccidentRepository extends BaseRepository<AccidentDO> {
/** /**
* corpinfoIdincidentType * corpinfoIdincidentType
* @param corpinfoIds ID *
* @param corpinfoIds ID
* @param eqAccidentType
* @return corpinfoIdincidentTypecount * @return corpinfoIdincidentTypecount
*/ */
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds); List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds,@Param("eqAccidentType") Integer eqAccidentType);
} }

View File

@ -45,8 +45,8 @@ public class AccidentRepositoryImpl extends BaseRepositoryImpl<AccidentMapper, A
} }
@Override @Override
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds) { public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType) {
return accidentMapper.countByCorpinfoIdAndIncidentType(corpinfoIds); return accidentMapper.countByCorpinfoIdAndIncidentType(corpinfoIds,eqAccidentType);
} }
} }

View File

@ -11,6 +11,9 @@
COUNT(*) as count COUNT(*) as count
from accident from accident
<where> <where>
<if test="eqAccidentType != null ">
AND type = #{eqAccidentType}
</if>
<if test="corpinfoIds != null and !corpinfoIds.isEmpty() and corpinfoIds.size()>0"> <if test="corpinfoIds != null and !corpinfoIds.isEmpty() and corpinfoIds.size()>0">
AND corpinfo_id IN AND corpinfo_id IN
<foreach collection="corpinfoIds" item="item" open="(" separator="," close=")"> <foreach collection="corpinfoIds" item="item" open="(" separator="," close=")">