|
|
@ -5,15 +5,22 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
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.Photos; |
|
|
|
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.hardware.drivers.CameraBaslerDriver; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.StandardCopyOption; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
@ -26,6 +33,7 @@ import java.util.stream.Collectors; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
private final CameraBaslerDriver driver; |
|
|
|
private final SolutionModuleService solutionModuleService; |
|
|
|
|
|
|
|
@Value("${photo.url}") |
|
|
|
private String url; |
|
|
@ -50,9 +58,9 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
return dataList; |
|
|
|
} |
|
|
|
|
|
|
|
public PhotoVO get(Long id){ |
|
|
|
public PhotoVO get(Long id) { |
|
|
|
Photos photos = this.getById(id); |
|
|
|
if(photos != null){ |
|
|
|
if (photos != null) { |
|
|
|
PhotoVO photoVO = new PhotoVO(); |
|
|
|
photoVO.setId(photos.getId()); |
|
|
|
photoVO.setMode(photos.getMode()); |
|
|
@ -68,7 +76,10 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public String take() { |
|
|
|
public String take(PhotoTakeDTO photoTakeDTO) throws Exception { |
|
|
|
if (photoTakeDTO.getLightIntensity() != null) { |
|
|
|
solutionModuleService.fillLightOpen(photoTakeDTO.getLightIntensity()); |
|
|
|
} |
|
|
|
try { |
|
|
|
String filePath = path + "/temp/" + System.currentTimeMillis() + ".png"; |
|
|
|
driver.enable(); |
|
|
@ -76,6 +87,20 @@ public class PhotosService extends ServiceImpl<PhotosMapper, Photos> { |
|
|
|
return url + filePath; |
|
|
|
} finally { |
|
|
|
driver.disable(); |
|
|
|
if (photoTakeDTO.getLightIntensity() != null) { |
|
|
|
solutionModuleService.fillLightClose(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|