|
|
|
@ -15,6 +15,7 @@ import com.shxy.xymanager_common.dto.*;
|
|
|
|
|
import com.shxy.xymanager_common.entity.*;
|
|
|
|
|
import com.shxy.xymanager_common.enums.CommonStatus;
|
|
|
|
|
import com.shxy.xymanager_common.enums.TakePicStatus;
|
|
|
|
|
import com.shxy.xymanager_common.exception.ApiException;
|
|
|
|
|
import com.shxy.xymanager_common.exception.Asserts;
|
|
|
|
|
import com.shxy.xymanager_common.model.*;
|
|
|
|
|
import com.shxy.xymanager_common.page.PageUtils;
|
|
|
|
@ -25,7 +26,6 @@ import com.shxy.xymanager_common.vo.*;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.*;
|
|
|
|
|
import com.shxy.xymanager_service.service.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -34,10 +34,13 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -423,6 +426,71 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
|
|
|
|
|
return Asserts.success("OK");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void upload(MultipartFile file, String cmdid) throws Exception {
|
|
|
|
|
Terminals term = terminalExtService.getByCmdid(cmdid);
|
|
|
|
|
if (term == null) {
|
|
|
|
|
throw new ApiException(cmdid + "该装置不存在");
|
|
|
|
|
}
|
|
|
|
|
String suffix;
|
|
|
|
|
String hexC = "";
|
|
|
|
|
Long time;
|
|
|
|
|
TerminalPhoto record = new TerminalPhoto();
|
|
|
|
|
try {
|
|
|
|
|
String fileName = org.springframework.util.StringUtils.cleanPath(file.getOriginalFilename());
|
|
|
|
|
suffix = org.springframework.util.StringUtils.getFilenameExtension(fileName);
|
|
|
|
|
String prefix = fileName.replace("." + suffix, "");
|
|
|
|
|
String[] str = prefix.split("_");
|
|
|
|
|
Long photoId = Long.parseLong(str[1], 16);
|
|
|
|
|
Integer channel = Integer.parseInt(str[2], 16);
|
|
|
|
|
hexC = str[3];
|
|
|
|
|
Integer preset = Integer.parseInt(hexC, 16);
|
|
|
|
|
time = Long.parseLong(str[6], 16);
|
|
|
|
|
record.setChannelId(channel);
|
|
|
|
|
record.setPresetId(preset);
|
|
|
|
|
record.setPhotoTime(BigInteger.valueOf(time));
|
|
|
|
|
record.setOrginalId(BigInteger.valueOf(photoId));
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
throw new ApiException("文件名不符合规范,解析失败");
|
|
|
|
|
}
|
|
|
|
|
int length = cmdid.length();
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
String folder = DateUtil.format(now, "yyyy/MM/dd") + "/" + cmdid.substring(length - 2);
|
|
|
|
|
File dir = new File(C_PATH + folder);
|
|
|
|
|
dir.mkdirs();
|
|
|
|
|
Date photoTime = new Date(time * 1000);
|
|
|
|
|
String strTime = DateUtil.format(photoTime, "yyyyMMddHHmmss");
|
|
|
|
|
String filename = cmdid + "_" + record.getChannelId() + "_" + hexC + "_" + strTime + "." + suffix;
|
|
|
|
|
String filePath = folder + "/" + filename;
|
|
|
|
|
|
|
|
|
|
File dest = new File(C_PATH + filePath);
|
|
|
|
|
file.transferTo(dest);
|
|
|
|
|
log.info("成功上传一张图片" + filePath);
|
|
|
|
|
|
|
|
|
|
record.setTermId(term.getId());
|
|
|
|
|
record.setMediaType(0);
|
|
|
|
|
record.setPath(filePath);
|
|
|
|
|
record.setRecvTime(BigInteger.valueOf(now.getTime() / 1000));
|
|
|
|
|
record.setRecvEndTime(BigInteger.valueOf(now.getTime() / 1000));
|
|
|
|
|
record.setCreateTime(now);
|
|
|
|
|
record.setFlags(0);
|
|
|
|
|
record.setIsMark(0);
|
|
|
|
|
try {
|
|
|
|
|
BufferedImage image = ImageIO.read(dest);
|
|
|
|
|
if (image != null) {
|
|
|
|
|
int width = image.getWidth();
|
|
|
|
|
int height = image.getHeight();
|
|
|
|
|
record.setWidth(width);
|
|
|
|
|
record.setHeight(height);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException ignore) {
|
|
|
|
|
}
|
|
|
|
|
long fileSize = Files.size(Paths.get(C_PATH + filePath));
|
|
|
|
|
record.setFileSize((int) fileSize);
|
|
|
|
|
|
|
|
|
|
terminalPhotoDao.insert(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图片查询
|
|
|
|
|
*/
|
|
|
|
|