67 lines
2.1 KiB
Java
67 lines
2.1 KiB
Java
package com.gunshi.project.hsz.service;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.gunshi.project.hsz.mapper.TermiteAdverPicMapper;
|
|
import com.gunshi.project.hsz.model.FileAssociations;
|
|
import com.gunshi.project.hsz.model.TermiteAdverPic;
|
|
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.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 描述: 白蚁防治宣传图片墙
|
|
* author: xusan
|
|
* date: 2024-08-29 17:33:09
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class TermiteAdverPicService extends ServiceImpl<TermiteAdverPicMapper, TermiteAdverPic>
|
|
{
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
public TermiteAdverPic saveData(TermiteAdverPic dto) {
|
|
dto.setId(IdWorker.getId());
|
|
dto.setCreateTime(new Date());
|
|
boolean result = this.save(dto);
|
|
if (result) {
|
|
fileService.saveFile(Arrays.asList(dto.getPic()), getGroupId(), String.valueOf(dto.getId()));
|
|
}
|
|
return dto;
|
|
}
|
|
|
|
public String getGroupId() {
|
|
return "termiteAdverPic";
|
|
}
|
|
|
|
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 List<TermiteAdverPic> queryList() {
|
|
List<TermiteAdverPic> list = this.list().stream().sorted(Comparator.comparing(TermiteAdverPic::getCreateTime).reversed()).collect(Collectors.toList());
|
|
for(TermiteAdverPic pic : list){
|
|
List<FileAssociations> files = fileService.getFiles(getGroupId(), pic.getId().toString());
|
|
pic.setPic(files.get(0));
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|