| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package com.zksy.park.service.imp;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.zksy.common.core.domain.Result;
- import com.zksy.park.domain.FileGeneral;
- import com.zksy.park.domain.ParkStemScreen;
- import com.zksy.park.domain.dto.ParkStemScreenDto;
- import com.zksy.park.mapper.ParkStemScreenMapper;
- import com.zksy.park.service.FileGeneralService;
- import com.zksy.park.service.ParkStemScreenService;
- import com.zksy.service.MinioFileStorageService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.time.LocalDateTime;
- import java.util.List;
- /**
- * 园区灯杆大屏Service业务层处理
- *
- * @author sy
- * @date 2024-05-08
- */
- @Service
- public class ParkStemScreenServiceImpl extends ServiceImpl<ParkStemScreenMapper, ParkStemScreen> implements ParkStemScreenService {
- @Autowired
- private FileGeneralService fileGeneralService;
- @Autowired
- private MinioFileStorageService minioFileStorageService;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Result<Object> saveParkStemScreen(ParkStemScreenDto dto) {
- try {
- if (dto.getFiles() != null) {
- List<String> filePath = minioFileStorageService.uploadFileBatch(dto.getFiles(), "yqdgdp");
- dto.setFilePath(filePath);
- }
- ParkStemScreen entity = BeanUtil.copyProperties(dto, ParkStemScreen.class);
- entity.setCreateTime(LocalDateTime.now());
- entity.setUpdateTime(LocalDateTime.now());
- baseMapper.insert(entity);
- if (dto.getFilePath() != null) {
- dto.getFilePath().forEach(q ->{
- FileGeneral fileGeneral = new FileGeneral();
- fileGeneral.setFormId(entity.getId());
- fileGeneral.setFilePath(q);
- fileGeneralService.save(fileGeneral);
- });
- }
- return Result.ok("新增成功");
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Result<String> updateByParkStemScreenId(ParkStemScreenDto dto) {
- try {
- if (dto.getFiles() != null) {
- LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(FileGeneral::getFormId, dto.getId());
- fileGeneralService.remove(wrapper);
- List<String> filePath = minioFileStorageService.uploadFileBatch(dto.getFiles(), "yqdgdp");
- dto.setFilePath(filePath);
- if (filePath != null){
- filePath.forEach(q ->{
- FileGeneral fileGeneral = new FileGeneral();
- fileGeneral.setFormId(dto.getId());
- fileGeneral.setFilePath(q);
- fileGeneralService.save(fileGeneral);
- });
- }
- }
- ParkStemScreen entity = BeanUtil.copyProperties(dto, ParkStemScreen.class);
- entity.setUpdateTime(LocalDateTime.now());
- this.updateById(entity);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return Result.ok("更新成功");
- }
- @Override
- @Transactional
- public Result<String> deleteById(String id) {
- if (StrUtil.isNotBlank(id)) {
- LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(FileGeneral::getFormId, id);
- FileGeneral one = fileGeneralService.getOne(wrapper);
- if(one!=null){
- minioFileStorageService.deleteFile(one.getFilePath());
- fileGeneralService.remove(wrapper);
- }
- this.removeById(id);
- return Result.ok("删除成功");
- }
- return Result.error("删除失败");
- }
- @Override
- public Result<ParkStemScreen> getByIdWithFile(String id) {
- if (StrUtil.isNotBlank(id)) {
- ParkStemScreen parkStemScreen = this.getById(id);
- LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(FileGeneral::getFormId, id);
- List<FileGeneral> fileGeneralList = fileGeneralService.list(wrapper);
- if(fileGeneralList != null){
- List<String> stringList = null;
- fileGeneralList.forEach(q ->{
- stringList.add(q.getFilePath());
- });
- parkStemScreen.setFilePath(stringList);
- }
- return Result.ok(parkStemScreen);
- }
- return Result.error("获取失败");
- }
- }
|