gunshi-project-ss/src/main/java/com/gunshi/project/hsz/service/SafetyAccidentRegService.java

110 lines
4.1 KiB
Java
Raw Normal View History

2025-07-17 15:26:39 +08:00
package com.gunshi.project.hsz.service;
2024-08-22 10:44:12 +08:00
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;
2025-07-17 15:26:39 +08:00
import com.gunshi.project.hsz.entity.so.CommonDataPageSo2;
import com.gunshi.project.hsz.mapper.SafetyAccidentRegMapper;
import com.gunshi.project.hsz.model.SafetyAccidentReg;
2024-08-22 10:44:12 +08:00
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;
2025-04-10 10:13:55 +08:00
public Page<SafetyAccidentReg> pageQuery(CommonDataPageSo2 page) {
2024-08-22 10:44:12 +08:00
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;
}
}