|
|
@ -12,8 +12,12 @@ import com.iflytop.gd.app.model.vo.PhotoListVO; |
|
|
|
import com.iflytop.gd.app.model.vo.PhotoVO; |
|
|
|
import com.iflytop.gd.app.service.device.module.SolutionModuleService; |
|
|
|
import com.iflytop.gd.common.base.BasePageQuery; |
|
|
|
import com.iflytop.gd.common.enums.PhotoModeType; |
|
|
|
import com.iflytop.gd.common.exception.AppException; |
|
|
|
import com.iflytop.gd.common.result.ResultCode; |
|
|
|
import com.iflytop.gd.hardware.drivers.CameraBaslerDriver; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
@ -21,6 +25,8 @@ import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.StandardCopyOption; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
@ -29,6 +35,7 @@ import java.util.stream.Collectors; |
|
|
|
/** |
|
|
|
* 照片接口服务 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
@ -94,14 +101,31 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
} |
|
|
|
|
|
|
|
public void save(PhotoSaveDTO photoSaveDTO) { |
|
|
|
Path sourcePath = Paths.get(path + "/temp/" + photoSaveDTO.getFileName()); |
|
|
|
Path targetPath = Paths.get(path + "/data/" + photoSaveDTO.getFileName()); |
|
|
|
try { |
|
|
|
Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
System.out.println("文件已成功移动!"); |
|
|
|
} catch (Exception e) { |
|
|
|
System.err.println("文件移动失败: " + e.getMessage()); |
|
|
|
Photos photos = this.getById(photoSaveDTO.getId()); |
|
|
|
if (photos == null) {//新增 |
|
|
|
String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
String imagePath = "/data/" + todayDate + "/" + photoSaveDTO.getFileName(); |
|
|
|
try { |
|
|
|
Path sourcePath = Paths.get(path + "/temp/" + photoSaveDTO.getFileName()); |
|
|
|
Path targetPath = Paths.get(path + imagePath); |
|
|
|
Path targetDirectory = targetPath.getParent(); |
|
|
|
if (!Files.exists(targetDirectory)) { |
|
|
|
Files.createDirectories(targetDirectory); |
|
|
|
} |
|
|
|
Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
log.info("照片文件已成功移动!"); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("照片文件已成功移动失败 ", e); |
|
|
|
throw new AppException(ResultCode.SYSTEM_ERROR); |
|
|
|
} |
|
|
|
photos = new Photos(); |
|
|
|
photos.setImagePath(imagePath); |
|
|
|
photos.setMode(PhotoModeType.manual); |
|
|
|
} |
|
|
|
photos.setOreId(photoSaveDTO.getOreId()); |
|
|
|
photos.setProblem(photoSaveDTO.getProblem()); |
|
|
|
photos.setRemarks(photoSaveDTO.getRemarks()); |
|
|
|
this.saveOrUpdate(photos); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean deletePhoto(String idsStr) { |
|
|
|