feat(accident): 新增事故统计及导出功能优化
- 在 AccidentController 中增加根据企业 ID 和事故类型的统计接口- 修改事故导出接口为 GET 请求,并调整参数传递方式 -优化事故分页查询逻辑,自动填充当前租户 ID - 调整 Excel 导出字段的时间格式注解位置以兼容解析 - 更新 AccidentGateway 和实现类,支持按类型筛选统计- 移除无用的测试接口和 RocketMQ 依赖配置- 设置服务端口为 8085 并启用消息绑定相关注解 - 调整查询 DTO 类型,使用 LocalDate 替代 LocalDateTime - 补充缺失的认证上下文工具类导入并移除冗余工具类引用 - 更新 Mapper XML 文件,增加对事故类型的条件判断 - 升级 pom.xml 中 jjb-saas-system-client 版本至 1.7.0-SNAPSHOTmaster
parent
21a7364a36
commit
835b51f034
9
pom.xml
9
pom.xml
|
|
@ -20,9 +20,18 @@
|
|||
<artifactId>zcloud_gbscommon</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jjb.saas</groupId>
|
||||
<artifactId>jjb-saas-system-client</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--Project modules-->
|
||||
<dependency>
|
||||
<groupId>com.zcloud.accident</groupId>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package com.zcloud.accident;
|
||||
|
||||
import com.jjb.saas.base.starter.bootstart.JJBSpringbootApplication;
|
||||
import com.jjb.saas.framework.event.consumer.EnableConsumer;
|
||||
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
|
||||
|
|
|
|||
|
|
@ -4,3 +4,5 @@ spring:
|
|||
- classpath:nacos.yml
|
||||
- classpath:sdk.yml
|
||||
- classpath:swagger.yml
|
||||
server:
|
||||
port: 8085
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ spring:
|
|||
file-extension: yml
|
||||
shared-configs:
|
||||
- config-common.yml
|
||||
- config-port.yml
|
||||
# - config-port.yml
|
||||
- config-mq.yml
|
||||
- config-log.yml
|
||||
- config-sdk-server.yml
|
||||
|
|
|
|||
|
|
@ -17,10 +17,6 @@
|
|||
<groupId>com.jjb.saas</groupId>
|
||||
<artifactId>jjb-saas-framework-adapter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zcloud.accident</groupId>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.zcloud.accident.web;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.cola.dto.MultiResponse;
|
||||
import com.alibaba.cola.dto.PageResponse;
|
||||
import com.alibaba.cola.dto.Response;
|
||||
|
|
@ -50,13 +51,15 @@ public class AccidentController {
|
|||
@ApiOperation("新增")
|
||||
@PostMapping("/save")
|
||||
public SingleResponse<AccidentCO> add(@Validated @RequestBody AccidentAddCmd cmd) {
|
||||
SSOUser ssoUser = AuthContext.getCurrentUser();
|
||||
return accidentService.add(cmd);
|
||||
}
|
||||
|
||||
@ApiOperation("分页")
|
||||
@PostMapping("/list")
|
||||
public PageResponse<AccidentCO> page(@RequestBody AccidentPageQry qry) {
|
||||
if(ObjectUtil.isNull(qry.getEqCorpinfoId())){
|
||||
qry.setEqCorpinfoId(AuthContext.getTenantId());
|
||||
}
|
||||
return accidentService.listPage(qry);
|
||||
}
|
||||
|
||||
|
|
@ -94,8 +97,8 @@ public class AccidentController {
|
|||
}
|
||||
|
||||
@ApiOperation("导出Excel")
|
||||
@PostMapping("/export")
|
||||
public void export(@RequestBody AccidentPageQry qry, HttpServletResponse response) throws IOException {
|
||||
@GetMapping("/export")
|
||||
public void export(AccidentPageQry qry, HttpServletResponse response) throws IOException {
|
||||
// 使用listAll方法获取所有符合条件的数据
|
||||
List<AccidentCO> accidentCOList = accidentService.listAll(qry);
|
||||
// 转换为导出CO
|
||||
|
|
@ -111,12 +114,5 @@ public class AccidentController {
|
|||
public MultiResponse<AccidentCountStatCO> countByCorpinfoIdAndIncidentType(@RequestBody AccidentCountQry accidentCountQry) {
|
||||
return accidentService.countByCorpinfoIdAndIncidentType(accidentCountQry);
|
||||
}
|
||||
|
||||
@GetMapping("/test")
|
||||
public void test() {
|
||||
ZcUserEvent zcUserEvent = new ZcUserEvent();
|
||||
zcUserEvent.setName("hello world");
|
||||
remoteEventPublisher.sendMessage(zcUserEvent,"zcloud:user:ev2" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class AccidentQueryExe {
|
|||
* @return 统计结果列表
|
||||
*/
|
||||
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);
|
||||
return MultiResponse.of(coList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,15 @@ import java.util.List;
|
|||
/**
|
||||
* 事故统计查询命令
|
||||
* 用于按照公司ID列表和事故类型统计事故数量
|
||||
*
|
||||
*
|
||||
* @Author
|
||||
* @Date
|
||||
*/
|
||||
@Data
|
||||
public class AccidentCountQry extends Query {
|
||||
|
||||
|
||||
@ApiModelProperty(value = "公司ID列表")
|
||||
private List<String> corpinfoIds;
|
||||
}
|
||||
@ApiModelProperty(value = "类型")
|
||||
private Integer eqAccidentType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import com.alibaba.cola.dto.PageQuery;
|
|||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
|
|
@ -27,6 +29,8 @@ public class AccidentPageQry extends PageQuery {
|
|||
* - `le`: 小于等于比较查询
|
||||
* - `ne`: 不等比较查询,对应SQL的!=操作符
|
||||
*/
|
||||
@ApiModelProperty(value = "所属企业", name = "eqCorpinfoId")
|
||||
private Long eqCorpinfoId;
|
||||
@ApiModelProperty(value = "事故名称", name = "likeIncidentName")
|
||||
private String likeIncidentName;
|
||||
@ApiModelProperty(value = "事故地点", name = "likeLocation")
|
||||
|
|
@ -36,11 +40,13 @@ public class AccidentPageQry extends PageQuery {
|
|||
@ApiModelProperty(value = "事故级别", name = "likeIncidentLevel")
|
||||
private String eqIncidentLevel;
|
||||
@ApiModelProperty(value = "开始时间", name = "geIncidentDate")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime geIncidentDate;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate geIncidentDate;
|
||||
@ApiModelProperty(value = "结束时间", name = "leIncidentDate")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime leIncidentDate;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate leIncidentDate;
|
||||
@ApiModelProperty(value = "类型1事件2事故", name = "eqType")
|
||||
private Integer eqType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class AccidentExportCO {
|
|||
|
||||
@ApiModelProperty(value = "事故发生时间")
|
||||
@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;
|
||||
|
||||
@ApiModelProperty(value = "直接经济损失(万元)")
|
||||
|
|
@ -85,7 +85,8 @@ public class AccidentExportCO {
|
|||
private String measures;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,14 @@ public interface AccidentGateway {
|
|||
*/
|
||||
Boolean deletedAccidentById(Long id);
|
||||
Boolean deletedAccidentByIds(Long[] id);
|
||||
|
||||
|
||||
/**
|
||||
* 按照corpinfoId和incidentType统计个数
|
||||
* @param corpinfoIds 公司ID列表
|
||||
*
|
||||
* @param corpinfoIds 公司ID列表
|
||||
* @param eqAccidentType
|
||||
* @return 统计结果列表,包含corpinfoId、incidentType和count字段
|
||||
*/
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds);
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
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.model.AccidentE;
|
||||
import com.zcloud.accident.domain.model.AccidentCountStat;
|
||||
import com.zcloud.accident.persistence.dataobject.AccidentDO;
|
||||
import com.zcloud.accident.persistence.repository.AccidentRepository;
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* web-infrastructure
|
||||
|
|
@ -26,8 +25,10 @@ public class AccidentGatewayImpl implements AccidentGateway {
|
|||
|
||||
@Override
|
||||
public Boolean add(AccidentE accidentE) {
|
||||
AccidentDO d = new AccidentDO(Tools.get32UUID());
|
||||
BeanUtils.copyProperties(accidentE, d, "accidentId");
|
||||
AccidentDO d = new AccidentDO();
|
||||
BeanUtils.copyProperties(accidentE, d);
|
||||
d.setCorpinfoId(AuthContext.getTenantId());
|
||||
d.setCorpinfoName(AuthContext.getCurrentUser().getTenantName());
|
||||
accidentRepository.save(d);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -51,8 +52,8 @@ public class AccidentGatewayImpl implements AccidentGateway {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds) {
|
||||
return accidentRepository.countByCorpinfoIdAndIncidentType(corpinfoIds);
|
||||
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType) {
|
||||
return accidentRepository.countByCorpinfoIdAndIncidentType(corpinfoIds,eqAccidentType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ public interface AccidentMapper extends BaseMapper<AccidentDO> {
|
|||
|
||||
/**
|
||||
* 按照corpinfoId和incidentType统计个数
|
||||
* @param corpinfoIds 公司ID列表
|
||||
*
|
||||
* @param corpinfoIds 公司ID列表
|
||||
* @param eqAccidentType
|
||||
* @return 统计结果列表,包含corpinfoId、incidentType和count字段
|
||||
*/
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds);
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds,@Param("eqAccidentType") Integer eqAccidentType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ public interface AccidentRepository extends BaseRepository<AccidentDO> {
|
|||
|
||||
/**
|
||||
* 按照corpinfoId和incidentType统计个数
|
||||
* @param corpinfoIds 公司ID列表
|
||||
*
|
||||
* @param corpinfoIds 公司ID列表
|
||||
* @param eqAccidentType
|
||||
* @return 统计结果列表,包含corpinfoId、incidentType和count字段
|
||||
*/
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds);
|
||||
List<AccidentCountStat> countByCorpinfoIdAndIncidentType(@Param("corpinfoIds") List<String> corpinfoIds,@Param("eqAccidentType") Integer eqAccidentType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class AccidentRepositoryImpl extends BaseRepositoryImpl<AccidentMapper, A
|
|||
IPage<AccidentDO> result = accidentMapper.selectPage(iPage, queryWrapper);
|
||||
return PageHelper.pageToResponse(result, result.getRecords());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<AccidentDO> listAll(Map<String,Object> params) {
|
||||
QueryWrapper<AccidentDO> queryWrapper = new QueryWrapper<>();
|
||||
|
|
@ -43,10 +43,10 @@ public class AccidentRepositoryImpl extends BaseRepositoryImpl<AccidentMapper, A
|
|||
queryWrapper.orderByDesc("create_time");
|
||||
return accidentMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds) {
|
||||
return accidentMapper.countByCorpinfoIdAndIncidentType(corpinfoIds);
|
||||
public List<AccidentCountStat> countByCorpinfoIdAndIncidentType(List<String> corpinfoIds, Integer eqAccidentType) {
|
||||
return accidentMapper.countByCorpinfoIdAndIncidentType(corpinfoIds,eqAccidentType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
COUNT(*) as count
|
||||
from accident
|
||||
<where>
|
||||
<if test="eqAccidentType != null ">
|
||||
AND type = #{eqAccidentType}
|
||||
</if>
|
||||
<if test="corpinfoIds != null and !corpinfoIds.isEmpty() and corpinfoIds.size()>0">
|
||||
AND corpinfo_id IN
|
||||
<foreach collection="corpinfoIds" item="item" open="(" separator="," close=")">
|
||||
|
|
|
|||
Loading…
Reference in New Issue