|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.iflytop.gd.app.mapper.PhotosMapper; |
|
|
|
import com.iflytop.gd.app.model.dto.PhotoSaveDTO; |
|
|
|
import com.iflytop.gd.app.model.dto.PhotoTakeDTO; |
|
|
|
import com.iflytop.gd.app.model.entity.Ores; |
|
|
|
import com.iflytop.gd.app.model.entity.Photos; |
|
|
|
import com.iflytop.gd.app.model.vo.PhotoListVO; |
|
|
|
import com.iflytop.gd.app.model.vo.PhotoVO; |
|
|
@ -21,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
@ -31,6 +33,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 照片接口服务 |
|
|
@ -41,6 +44,7 @@ import java.util.stream.Collectors; |
|
|
|
public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
private final CameraBaslerDriver driver; |
|
|
|
private final SolutionModuleService solutionModuleService; |
|
|
|
private final OresService oresService; |
|
|
|
|
|
|
|
@Value("${photo.url}") |
|
|
|
private String url; |
|
|
@ -84,14 +88,28 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
} |
|
|
|
|
|
|
|
public String take(PhotoTakeDTO photoTakeDTO) throws Exception { |
|
|
|
Path directoryPath = Paths.get(path + "/temp"); |
|
|
|
try (Stream<Path> paths = Files.list(directoryPath)) { |
|
|
|
paths.forEach(file -> { |
|
|
|
try { |
|
|
|
Files.delete(file); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("删除文件时发生错误", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("读取目录时发生错误", e); |
|
|
|
} |
|
|
|
|
|
|
|
if (photoTakeDTO.getLightIntensity() != null) { |
|
|
|
solutionModuleService.fillLightOpen(photoTakeDTO.getLightIntensity()); |
|
|
|
} |
|
|
|
try { |
|
|
|
String filePath = path + "/temp/" + System.currentTimeMillis() + ".png"; |
|
|
|
String tempFilePath = "/temp/" + System.currentTimeMillis() + ".png"; |
|
|
|
String filePath = path + tempFilePath; |
|
|
|
driver.enable(); |
|
|
|
driver.saveColorImg(filePath); |
|
|
|
return url + filePath; |
|
|
|
return url + tempFilePath; |
|
|
|
} finally { |
|
|
|
driver.disable(); |
|
|
|
if (photoTakeDTO.getLightIntensity() != null) { |
|
|
@ -104,9 +122,10 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
Photos photos = this.getById(photoSaveDTO.getId()); |
|
|
|
if (photos == null) {//新增 |
|
|
|
String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
String tempPath = "/temp/" + photoSaveDTO.getFileName(); |
|
|
|
String imagePath = "/data/" + todayDate + "/" + photoSaveDTO.getFileName(); |
|
|
|
try { |
|
|
|
Path sourcePath = Paths.get(path + "/temp/" + photoSaveDTO.getFileName()); |
|
|
|
Path sourcePath = Paths.get(path + tempPath); |
|
|
|
Path targetPath = Paths.get(path + imagePath); |
|
|
|
Path targetDirectory = targetPath.getParent(); |
|
|
|
if (!Files.exists(targetDirectory)) { |
|
|
@ -122,7 +141,12 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
photos.setImagePath(imagePath); |
|
|
|
photos.setMode(PhotoModeType.manual); |
|
|
|
} |
|
|
|
Ores ores = oresService.getById(photoSaveDTO.getOreId()); |
|
|
|
if (ores == null) { |
|
|
|
throw new AppException(ResultCode.DATA_ALREADY_NOT_EXISTS); |
|
|
|
} |
|
|
|
photos.setOreId(photoSaveDTO.getOreId()); |
|
|
|
photos.setOreName(ores.getName()); |
|
|
|
photos.setProblem(photoSaveDTO.getProblem()); |
|
|
|
photos.setRemarks(photoSaveDTO.getRemarks()); |
|
|
|
this.saveOrUpdate(photos); |
|
|
|