109 lines
4.0 KiB
Java
109 lines
4.0 KiB
Java
|
|
package com.gunshi.project.ss.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.ss.entity.so.MaintainPageSo;
|
||
|
|
import com.gunshi.project.ss.mapper.MaintainServiceMapper;
|
||
|
|
import com.gunshi.project.ss.model.MaintainService;
|
||
|
|
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-27 15:15:14
|
||
|
|
*/
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class MaintainServiceService extends ServiceImpl<MaintainServiceMapper, MaintainService>
|
||
|
|
{
|
||
|
|
@Autowired
|
||
|
|
private FileAssociationsService fileService;
|
||
|
|
|
||
|
|
public MaintainService saveData(MaintainService dto) {
|
||
|
|
dto.setId(IdWorker.getId());
|
||
|
|
boolean result = this.save(dto);
|
||
|
|
if (result) {
|
||
|
|
fileService.save(dto.getPics(), dto.getId().toString(), getGroupId(),getPicType());
|
||
|
|
fileService.save(dto.getVideos(), dto.getId().toString(), getGroupId(),getVideoType());
|
||
|
|
}
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getVideoType() {
|
||
|
|
return "mainVideo";
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getPicType() {
|
||
|
|
return "mainPic";
|
||
|
|
}
|
||
|
|
|
||
|
|
public MaintainService updateData(MaintainService 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.getPics(), dto.getId().toString(), getGroupId(),getPicType());
|
||
|
|
fileService.removeByBzIdAndType(dto.getId().toString(),getGroupId(),getVideoType());
|
||
|
|
fileService.save(dto.getVideos(), dto.getId().toString(), getGroupId(),getVideoType());
|
||
|
|
}
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getGroupId() {
|
||
|
|
return "maintainService";
|
||
|
|
}
|
||
|
|
|
||
|
|
public Page<MaintainService> pageQuery(MaintainPageSo page) {
|
||
|
|
LambdaQueryWrapper<MaintainService> query = Wrappers.lambdaQuery();
|
||
|
|
if (ObjectUtils.isNotNull(page.getMaintainType())) {
|
||
|
|
query.eq(MaintainService::getMaintainType, page.getMaintainType());
|
||
|
|
}
|
||
|
|
if (page.getDateTimeSo() != null && page.getDateTimeSo().getStart() != null) {
|
||
|
|
query.ge(MaintainService::getReportTime, page.getDateTimeSo().getStart());
|
||
|
|
}
|
||
|
|
if (page.getDateTimeSo() != null && page.getDateTimeSo().getEnd() != null) {
|
||
|
|
query.le(MaintainService::getReportTime, page.getDateTimeSo().getEnd());
|
||
|
|
}
|
||
|
|
query.orderByDesc(MaintainService::getReportTime);
|
||
|
|
Page<MaintainService> res = this.page(page.getPageSo().toPage(), query);
|
||
|
|
if (res.getRecords() != null) {
|
||
|
|
fillAttach(res.getRecords());
|
||
|
|
}
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void fillAttach(List<MaintainService> ret) {
|
||
|
|
for (MaintainService record : ret) {
|
||
|
|
record.setPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType()));
|
||
|
|
record.setVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType()));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|