安全事故登记

master
wany 2024-08-22 10:44:12 +08:00
parent 338c704529
commit 25af0f1205
7 changed files with 354 additions and 3 deletions

View File

@ -0,0 +1,63 @@
package com.gunshi.project.xyt.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R;
import com.gunshi.project.xyt.entity.so.CommonDataPageSo;
import com.gunshi.project.xyt.model.SafetyAccidentReg;
import com.gunshi.project.xyt.service.SafetyAccidentRegService;
import com.gunshi.project.xyt.validate.markers.Insert;
import com.gunshi.project.xyt.validate.markers.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
/**
* :
* author: xusan
* date: 2024-08-21 14:45:44
*/
@Tag(name = "安全事故登记")
@RestController
@RequestMapping(value="/safety/accident/reg")
public class SafetyAccidentRegController extends AbstractCommonFileController {
@Autowired
private SafetyAccidentRegService service;
@Operation(summary = "新增")
@PostMapping("/insert")
public R<SafetyAccidentReg> insert(@Validated(Insert.class) @RequestBody SafetyAccidentReg dto) {
return R.ok(service.saveData(dto));
}
@Operation(summary = "修改")
@PostMapping("/update")
public R<SafetyAccidentReg> update(@Validated(Update.class) @RequestBody SafetyAccidentReg dto) {
return R.ok(service.updateData(dto));
}
@Operation(summary = "删除")
@GetMapping("/del/{id}")
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
return R.ok(service.delData(id));
}
@Operation(summary = "分页")
@PostMapping("/page")
public R<Page<SafetyAccidentReg>> page(@RequestBody CommonDataPageSo page) {
return R.ok(service.pageQuery(page));
}
@Override
public String getGroupId() {
return "safetyAccidentReg";
}
}

View File

@ -17,11 +17,11 @@ import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
/**
* :
* :
* author: wanyan
* date: 2024-08-20 17:40:37
*/
@Tag(name = "安隐患排查")
@Tag(name = "安隐患排查")
@RestController
@RequestMapping(value="/safety/hazard/invest")
public class SafetyHazardInvestController extends AbstractCommonFileController{

View File

@ -0,0 +1,15 @@
package com.gunshi.project.xyt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gunshi.project.xyt.model.SafetyAccidentReg;
import org.apache.ibatis.annotations.Mapper;
/**
* :
* author: xusan
* date: 2024-08-21 15:44:55
*/
@Mapper
public interface SafetyAccidentRegMapper extends BaseMapper<SafetyAccidentReg> {
}

View File

@ -0,0 +1,137 @@
package com.gunshi.project.xyt.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.gunshi.core.dateformat.DateFormatString;
import com.gunshi.project.xyt.validate.markers.Update;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* :
* author: xusan
* date: 2024-08-21 15:44:54
*/
@Schema(description="安全事故登记")
@Data
@TableName("public.safety_accident_reg")
public class SafetyAccidentReg implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(value="id", type= IdType.AUTO)
@Schema(description="主键")
@NotNull(message = "主键不能为空",groups = {Update.class})
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/**
*
*/
@TableField(value="name")
@Schema(description="事故名称")
@Size(max = 200,message = "事故名称最大长度要小于 200")
private String name;
/**
*
*/
@TableField(value="accident_date")
@Schema(description="事故发生时间")
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM, timezone = "GMT+8")
private Date accidentDate;
/**
* (1234)
*/
@TableField(value="accident_level")
@Schema(description="事故级别(1一般事故2较大事故3重大事故4特别重大事故)")
private Integer accidentLevel;
/**
*
*/
@TableField(value="accident_desc")
@Schema(description="事故情况描述")
@Size(max = 500,message = "事故情况描述最大长度要小于 500")
private String accidentDesc;
/**
* ()
*/
@TableField(value="economic_losses")
@Schema(description="直接经济损失(万元)")
private BigDecimal economicLosses;
/**
*
*/
@TableField(value="dead_number")
@Schema(description="死亡人数")
private Integer deadNumber;
/**
*
*/
@TableField(value="injure_number")
@Schema(description="受伤人数")
private Integer injureNumber;
/**
*
*/
@TableField(value="invest_org")
@Schema(description="事故调查单位")
@Size(max = 200,message = "事故调查单位最大长度要小于 200")
private String investOrg;
/**
*
*/
@TableField(value="close_case_date")
@Schema(description="事故结案日期")
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD, timezone = "GMT+8")
private Date closeCaseDate;
/**
*
*/
@TableField(value="invest_desc")
@Schema(description="事故调查情况")
@Size(max = 500,message = "事故调查情况最大长度要小于 500")
private String investDesc;
/**
*
*/
@TableField(value="handle_result")
@Schema(description="处理结果")
@Size(max = 500,message = "处理结果最大长度要小于 500")
private String handleResult;
@TableField(exist = false)
@Schema(description = "现场图片")
private List<FileAssociations> accidentPic;
@TableField(exist = false)
@Schema(description = "事故调查与处理资料")
private List<FileAssociations> accidentHandle;
}

View File

@ -1,6 +1,9 @@
package com.gunshi.project.xyt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.mapper.FileAssociationsMapper;
import com.gunshi.project.xyt.model.FileAssociations;
@ -147,4 +150,28 @@ public class FileAssociationsService extends ServiceImpl<FileAssociationsMapper,
return this.baseMapper.getFiles(tName,bId);
}
public void save(List<FileAssociations> attachList,String businessId, String tableName,String type) {
if (attachList != null && !attachList.isEmpty()) {
for (FileAssociations attach : attachList) {
attach.setId(IdWorker.getId());
attach.setBusinessId(businessId);
attach.setTableName(tableName);
attach.setType(type);
}
this.saveBatch(attachList);
}
}
public boolean removeByBzIdAndType(String businessId, String tableName,String type) {
return this.remove(new QueryWrapper<FileAssociations>().eq("business_id", businessId).eq("table_name", tableName).eq("type",type));
}
public List<FileAssociations> queryFileList(String businessId, String tableName,String type) {
LambdaQueryWrapper<FileAssociations> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(FileAssociations::getBusinessId,businessId)
.eq(FileAssociations::getTableName,tableName)
.eq(FileAssociations::getType,type);
return this.list(queryWrapper);
}
}

View File

@ -0,0 +1,109 @@
package com.gunshi.project.xyt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.xyt.entity.so.CommonDataPageSo;
import com.gunshi.project.xyt.mapper.SafetyAccidentRegMapper;
import com.gunshi.project.xyt.model.SafetyAccidentReg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
/**
* :
* author: xusan
* date: 2024-08-21 15:44:55
*/
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class SafetyAccidentRegService extends ServiceImpl<SafetyAccidentRegMapper, SafetyAccidentReg>
{
@Autowired
private FileAssociationsService fileService;
public Page<SafetyAccidentReg> pageQuery(CommonDataPageSo page) {
LambdaQueryWrapper<SafetyAccidentReg> query = Wrappers.lambdaQuery();
if (ObjectUtils.isNotNull(page.getName())) {
query.like(SafetyAccidentReg::getName, page.getName());
}
if (page.getDateSo() != null && page.getDateSo().getStart() != null) {
query.ge(SafetyAccidentReg::getAccidentDate, page.getDateSo().getStart());
}
if (page.getDateSo() != null && page.getDateSo().getEnd() != null) {
query.le(SafetyAccidentReg::getAccidentDate, page.getDateSo().getEnd());
}
query.orderByDesc(SafetyAccidentReg::getAccidentDate);
Page<SafetyAccidentReg> res = this.page(page.getPageSo().toPage(), query);
if (res.getRecords() != null) {
fillAttach(res.getRecords());
}
return res;
}
private void fillAttach(List<SafetyAccidentReg> ret) {
for (SafetyAccidentReg record : ret) {
record.setAccidentPic(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType()));
record.setAccidentHandle(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleType()));
}
}
public String getGroupId() {
return "safetyAccidentReg";
}
public SafetyAccidentReg saveData(SafetyAccidentReg dto) {
dto.setId(IdWorker.getId());
boolean result = this.save(dto);
if (result) {
fileService.save(dto.getAccidentPic(), dto.getId().toString(), getGroupId(),getPicType());
fileService.save(dto.getAccidentHandle(), dto.getId().toString(), getGroupId(),getHandleType());
}
return dto;
}
private String getHandleType() {
return "accidentHandle";
}
private String getPicType() {
return "accidentPic";
}
public SafetyAccidentReg updateData(SafetyAccidentReg dto) {
if (Objects.isNull(this.getById(dto.getId()))) {
throw new IllegalArgumentException("当前数据不存在");
}
boolean result = this.updateById(dto);
if (result) {
fileService.removeByBzIdAndType(dto.getId().toString(),getGroupId(),getPicType());
fileService.save(dto.getAccidentPic(), dto.getId().toString(), getGroupId(),getPicType());
fileService.removeByBzIdAndType(dto.getId().toString(),getGroupId(),getHandleType());
fileService.save(dto.getAccidentHandle(), dto.getId().toString(), getGroupId(),getHandleType());
}
return dto;
}
public Boolean delData(Serializable id) {
if (Objects.isNull(this.getById(id))) {
throw new IllegalArgumentException("当前数据不存在");
}
boolean data = this.removeById(id);
if (data) {
fileService.deleteFile(getGroupId(), id.toString());
}
return data;
}
}

View File

@ -19,7 +19,7 @@ import java.util.List;
import java.util.Objects;
/**
* :
* :
* author: wanyan
* date: 2024-08-21 10:40:37
*/