|
@@ -1,18 +1,26 @@
|
|
|
package com.zksy.park.service.imp;
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.zksy.common.core.domain.Result;
|
|
|
import com.zksy.park.domain.FileGeneral;
|
|
import com.zksy.park.domain.FileGeneral;
|
|
|
import com.zksy.park.domain.ParkInfo;
|
|
import com.zksy.park.domain.ParkInfo;
|
|
|
|
|
+import com.zksy.park.domain.dto.PackInfoDto;
|
|
|
import com.zksy.park.mapper.ParkInfoMapper;
|
|
import com.zksy.park.mapper.ParkInfoMapper;
|
|
|
import com.zksy.park.service.FileGeneralService;
|
|
import com.zksy.park.service.FileGeneralService;
|
|
|
import com.zksy.park.service.ParkInfoService;
|
|
import com.zksy.park.service.ParkInfoService;
|
|
|
import com.zksy.service.MinioFileStorageService;
|
|
import com.zksy.service.MinioFileStorageService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 经营异常名录Service业务层处理
|
|
* 经营异常名录Service业务层处理
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @author sy
|
|
* @author sy
|
|
|
* @date 2024-05-08
|
|
* @date 2024-05-08
|
|
|
*/
|
|
*/
|
|
@@ -20,25 +28,86 @@ import org.springframework.stereotype.Service;
|
|
|
public class ParkInfoServiceImpl extends ServiceImpl<ParkInfoMapper, ParkInfo> implements ParkInfoService {
|
|
public class ParkInfoServiceImpl extends ServiceImpl<ParkInfoMapper, ParkInfo> implements ParkInfoService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FileGeneralService fileGeneralService;
|
|
private FileGeneralService fileGeneralService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MinioFileStorageService minioFileStorageService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public boolean saveParkInfo(ParkInfo entity) {
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Result<Object> saveParkInfo(PackInfoDto dto) {
|
|
|
try {
|
|
try {
|
|
|
- int entityResult = baseMapper.insert(entity);
|
|
|
|
|
- boolean fileGeneralResult = false;
|
|
|
|
|
- if(!"".equals(entity.getFilePath())){
|
|
|
|
|
|
|
+ if (dto.getFile() != null) {
|
|
|
|
|
+ String filePath = minioFileStorageService.uploadFile(dto.getFile(), dto.getBusinessType());
|
|
|
|
|
+ dto.setFilePath(filePath);
|
|
|
|
|
+ }
|
|
|
|
|
+ ParkInfo entity = BeanUtil.copyProperties(dto, ParkInfo.class);
|
|
|
|
|
+ entity.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ entity.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ baseMapper.insert(entity);
|
|
|
|
|
+ if (StrUtil.isNotBlank(dto.getFilePath())) {
|
|
|
FileGeneral fileGeneral = new FileGeneral();
|
|
FileGeneral fileGeneral = new FileGeneral();
|
|
|
fileGeneral.setFormId(entity.getId());
|
|
fileGeneral.setFormId(entity.getId());
|
|
|
- fileGeneral.setBusinessType(entity.getBusinessType());
|
|
|
|
|
- fileGeneral.setFilePath(entity.getFilePath());
|
|
|
|
|
- fileGeneralResult = fileGeneralService.save(fileGeneral);
|
|
|
|
|
|
|
+ fileGeneral.setFilePath(dto.getFilePath());
|
|
|
|
|
+ fileGeneralService.save(fileGeneral);
|
|
|
}
|
|
}
|
|
|
- if (entityResult >= 1 && fileGeneralResult == true){
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ return Result.ok("新增成功");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Result<String> updateByParkInfoId(PackInfoDto dto) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (dto.getFile() != null) {
|
|
|
|
|
+ LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(FileGeneral::getFormId, dto.getId());
|
|
|
|
|
+ fileGeneralService.remove(wrapper);
|
|
|
|
|
+ String filePath = minioFileStorageService.uploadFile(dto.getFile(), dto.getBusinessType());
|
|
|
|
|
+ dto.setFilePath(filePath);
|
|
|
|
|
+ FileGeneral fileGeneral = new FileGeneral();
|
|
|
|
|
+ fileGeneral.setFormId(dto.getId());
|
|
|
|
|
+ fileGeneral.setFilePath(dto.getFilePath());
|
|
|
|
|
+ fileGeneralService.save(fileGeneral);
|
|
|
}
|
|
}
|
|
|
|
|
+ ParkInfo entity = BeanUtil.copyProperties(dto, ParkInfo.class);
|
|
|
|
|
+ entity.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ this.updateById(entity);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
|
- return false;
|
|
|
|
|
|
|
+ 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<ParkInfo> getByIdWithFile(String id) {
|
|
|
|
|
+ if (StrUtil.isNotBlank(id)) {
|
|
|
|
|
+ ParkInfo parkInfo = this.getById(id);
|
|
|
|
|
+ LambdaQueryWrapper<FileGeneral> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(FileGeneral::getFormId, id);
|
|
|
|
|
+ FileGeneral one = fileGeneralService.getOne(wrapper);
|
|
|
|
|
+ if(one!=null){
|
|
|
|
|
+ parkInfo.setFilePath(one.getFilePath());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok(parkInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.error("获取失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|