ParkStemScreenServiceImpl.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.zksy.park.service.imp;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.zksy.common.core.domain.Result;
  7. import com.zksy.park.domain.FileGeneral;
  8. import com.zksy.park.domain.ParkStemScreen;
  9. import com.zksy.park.domain.dto.ParkStemScreenDto;
  10. import com.zksy.park.mapper.ParkStemScreenMapper;
  11. import com.zksy.park.service.FileGeneralService;
  12. import com.zksy.park.service.ParkStemScreenService;
  13. import com.zksy.service.MinioFileStorageService;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import java.time.LocalDateTime;
  18. import java.util.List;
  19. /**
  20. * 园区灯杆大屏Service业务层处理
  21. *
  22. * @author sy
  23. * @date 2024-05-08
  24. */
  25. @Service
  26. public class ParkStemScreenServiceImpl extends ServiceImpl<ParkStemScreenMapper, ParkStemScreen> implements ParkStemScreenService {
  27. @Autowired
  28. private FileGeneralService fileGeneralService;
  29. @Autowired
  30. private MinioFileStorageService minioFileStorageService;
  31. @Override
  32. @Transactional(rollbackFor = Exception.class)
  33. public Result<Object> saveParkStemScreen(ParkStemScreenDto dto) {
  34. try {
  35. if (dto.getFiles() != null) {
  36. List<String> filePath = minioFileStorageService.uploadFileBatch(dto.getFiles(), "yqdgdp");
  37. dto.setFilePath(filePath);
  38. }
  39. ParkStemScreen entity = BeanUtil.copyProperties(dto, ParkStemScreen.class);
  40. entity.setCreateTime(LocalDateTime.now());
  41. entity.setUpdateTime(LocalDateTime.now());
  42. baseMapper.insert(entity);
  43. if (dto.getFilePath() != null) {
  44. dto.getFilePath().forEach(q ->{
  45. FileGeneral fileGeneral = new FileGeneral();
  46. fileGeneral.setFormId(entity.getId());
  47. fileGeneral.setFilePath(q);
  48. fileGeneralService.save(fileGeneral);
  49. });
  50. }
  51. return Result.ok("新增成功");
  52. } catch (Exception e) {
  53. throw new RuntimeException(e);
  54. }
  55. }
  56. @Override
  57. @Transactional(rollbackFor = Exception.class)
  58. public Result<String> updateByParkStemScreenId(ParkStemScreenDto dto) {
  59. try {
  60. if (dto.getFiles() != null) {
  61. LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
  62. wrapper.eq(FileGeneral::getFormId, dto.getId());
  63. fileGeneralService.remove(wrapper);
  64. List<String> filePath = minioFileStorageService.uploadFileBatch(dto.getFiles(), "yqdgdp");
  65. dto.setFilePath(filePath);
  66. if (filePath != null){
  67. filePath.forEach(q ->{
  68. FileGeneral fileGeneral = new FileGeneral();
  69. fileGeneral.setFormId(dto.getId());
  70. fileGeneral.setFilePath(q);
  71. fileGeneralService.save(fileGeneral);
  72. });
  73. }
  74. }
  75. ParkStemScreen entity = BeanUtil.copyProperties(dto, ParkStemScreen.class);
  76. entity.setUpdateTime(LocalDateTime.now());
  77. this.updateById(entity);
  78. } catch (Exception e) {
  79. throw new RuntimeException(e);
  80. }
  81. return Result.ok("更新成功");
  82. }
  83. @Override
  84. @Transactional
  85. public Result<String> deleteById(String id) {
  86. if (StrUtil.isNotBlank(id)) {
  87. LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
  88. wrapper.eq(FileGeneral::getFormId, id);
  89. FileGeneral one = fileGeneralService.getOne(wrapper);
  90. if(one!=null){
  91. minioFileStorageService.deleteFile(one.getFilePath());
  92. fileGeneralService.remove(wrapper);
  93. }
  94. this.removeById(id);
  95. return Result.ok("删除成功");
  96. }
  97. return Result.error("删除失败");
  98. }
  99. @Override
  100. public Result<ParkStemScreen> getByIdWithFile(String id) {
  101. if (StrUtil.isNotBlank(id)) {
  102. ParkStemScreen parkStemScreen = this.getById(id);
  103. LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
  104. wrapper.eq(FileGeneral::getFormId, id);
  105. List<FileGeneral> fileGeneralList = fileGeneralService.list(wrapper);
  106. if(fileGeneralList != null){
  107. List<String> stringList = null;
  108. fileGeneralList.forEach(q ->{
  109. stringList.add(q.getFilePath());
  110. });
  111. parkStemScreen.setFilePath(stringList);
  112. }
  113. return Result.ok(parkStemScreen);
  114. }
  115. return Result.error("获取失败");
  116. }
  117. }