110 lines
4.1 KiB
Java
110 lines
4.1 KiB
Java
package com.gunshi.project.hsz.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.hsz.entity.so.CommonDataPageSo2;
|
|
import com.gunshi.project.hsz.mapper.SafetyAccidentRegMapper;
|
|
import com.gunshi.project.hsz.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(CommonDataPageSo2 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;
|
|
}
|
|
|
|
}
|
|
|
|
|