|
@@ -4,11 +4,29 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huimv.manager.dao.entity.ImagePathEntity;
|
|
|
import com.huimv.manager.service.IImageService;
|
|
|
+import com.huimv.manager.utils.DateUtil;
|
|
|
+import com.huimv.manager.utils.ImageByteUtil;
|
|
|
+//import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
|
|
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
|
|
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
|
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
|
|
+//import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
+//import java.sql.Timestamp;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @Project : huimv.shiwan
|
|
@@ -18,12 +36,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @Author : ZhuoNing
|
|
|
* @Create : 2020-12-25
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
@CrossOrigin
|
|
|
@RestController
|
|
|
@RequestMapping("/imageManager")
|
|
|
public class ImageManagerController {
|
|
|
@Autowired
|
|
|
private IImageService imageService;
|
|
|
+ @Autowired
|
|
|
+ private DateUtil dateUtil;
|
|
|
|
|
|
/**
|
|
|
* @Method : getLastImageAiResult
|
|
@@ -37,9 +58,7 @@ public class ImageManagerController {
|
|
|
*/
|
|
|
@RequestMapping(value="/getLastImageAiResult",method = RequestMethod.GET)
|
|
|
public String getLastImageAiResult(){
|
|
|
- //
|
|
|
- ImagePathEntity imagePathEntity = imageService.getLastImage();
|
|
|
- return JSONObject.toJSON(imagePathEntity).toString();
|
|
|
+ return JSONObject.toJSON(imageService.getLastImage()).toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -55,11 +74,304 @@ public class ImageManagerController {
|
|
|
@RequestMapping(value="/getNextImageAiResult",method = RequestMethod.GET)
|
|
|
public String getNextImageAiResult(){
|
|
|
//
|
|
|
- return imageService.getNextImage();
|
|
|
+ return JSONObject.toJSON(imageService.getNextImage()).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : listImage
|
|
|
+ * @Description :
|
|
|
+ * @Params : [startDate, endDate, pageNo, pageSize]
|
|
|
+ * @Return : com.alibaba.fastjson.JSONArray
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/1/22
|
|
|
+ * @Time : 16:28
|
|
|
+ */
|
|
|
+ @Deprecated
|
|
|
+ @RequestMapping(value="/listImage",method = RequestMethod.GET)
|
|
|
+ public JSONObject listImage(@RequestParam(value = "startDate",required = true) String startDate,@RequestParam(value = "endDate",required = true) String endDate,@RequestParam(value = "pageNo",required = true) int pageNo,@RequestParam(value = "pageSize",required = true) int pageSize){
|
|
|
+ log.info("startDate>>"+startDate);
|
|
|
+ log.info("endDate>>"+endDate);
|
|
|
+ log.info("pageNo>>"+pageNo);
|
|
|
+ log.info("pageSize>>"+pageSize);
|
|
|
+ //
|
|
|
+ List<ImagePathEntity> imageList = imageService.getImageList(startDate,endDate,pageNo,pageSize);
|
|
|
+ JSONArray imageJa = new JSONArray();
|
|
|
+ for(ImagePathEntity imageEntity:imageList){
|
|
|
+// JSONObject dataJo = (JSONObject) JSONObject.toJSON(imageEntity);
|
|
|
+ JSONObject imageJo = new JSONObject();
|
|
|
+ imageJo.put("aiData",imageEntity.getAiData());
|
|
|
+ imageJo.put("aiResult",imageEntity.getAiResult());
|
|
|
+ imageJo.put("aiTimeUsed",imageEntity.getAiTimeUsed());
|
|
|
+ imageJo.put("createDate",dateUtil.formatTimestamp(imageEntity.getCreateDate()));
|
|
|
+ imageJo.put("effective",imageEntity.getEffective());
|
|
|
+ imageJo.put("fileName",imageEntity.getFileName());
|
|
|
+ imageJo.put("id",imageEntity.getId());
|
|
|
+ imageJo.put("imgPath",imageEntity.getImgPath());
|
|
|
+ imageJo.put("name",imageEntity.getName());
|
|
|
+ imageJo.put("relativePath",imageEntity.getRelativePath());
|
|
|
+ imageJa.add(imageJo);
|
|
|
+ }
|
|
|
+ // 读取记录数
|
|
|
+ int total = imageService.getTotal(startDate,endDate);
|
|
|
+ JSONObject outJo = new JSONObject();
|
|
|
+ outJo.put("data",imageJa);
|
|
|
+ outJo.put("total",total);
|
|
|
+ return outJo;
|
|
|
}
|
|
|
|
|
|
-// public JSONArray listImage(String startDate, String endDate){
|
|
|
-// imageService
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * @Method : previousImage
|
|
|
+ * @Description : 读取前一张
|
|
|
+ * @Params : [id]
|
|
|
+ * @Return : com.alibaba.fastjson.JSONObject
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/1/23
|
|
|
+ * @Time : 19:09
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getPreviousImage",method = RequestMethod.GET)
|
|
|
+ public JSONObject getPreviousImage(@RequestParam(value = "imageId",required = true) int imageId){
|
|
|
+ return imageService.getOneImage("previous",imageId);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * @Method : nextImage
|
|
|
+ * @Description : 读取下一张图片
|
|
|
+ * @Params : [id]
|
|
|
+ * @Return : com.alibaba.fastjson.JSONObject
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/1/23
|
|
|
+ * @Time : 19:09
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getNextImage",method = RequestMethod.GET)
|
|
|
+ public JSONObject getNextImage(@RequestParam(value = "imageId",required = true) int imageId){
|
|
|
+ //
|
|
|
+ return imageService.getOneImage("next",imageId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
+ @RequestMapping("/exportPicture")
|
|
|
+ public void exportPicture(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
+ //定义根路径
|
|
|
+ String rootPath = request.getRealPath("/");
|
|
|
+ //创建文件
|
|
|
+ File file = new File(rootPath+"temp_download");
|
|
|
+ //判断文件是否存在,如果不存在,则创建此文件夹
|
|
|
+ if(!file.exists()){
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ String name = "图片压缩包下载";
|
|
|
+ String fileName = name+new Date().getTime();
|
|
|
+ String zipFileName = fileName + ".zip";
|
|
|
+ File zipFile = null;
|
|
|
+ String path = rootPath + "temp_download";
|
|
|
+
|
|
|
+ //调用工具类获取图片
|
|
|
+ byte[] data = ImageByteUtil.image2byte("F:\\blank.jpg");
|
|
|
+ //new一个文件对象用来保存图片,默认保存当前工程根目录
|
|
|
+ if(data != null){
|
|
|
+ File imageFile = new File(path+File.separator+fileName+".jpg");
|
|
|
+ //创建输出流
|
|
|
+ FileOutputStream outStream = new FileOutputStream(imageFile);
|
|
|
+ //写入数据
|
|
|
+ outStream.write(data);
|
|
|
+ //关闭输出流
|
|
|
+ outStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ /*
|
|
|
+ * 用JDK自带的zipentry压缩后,压缩包中的文件名中文乱码,故放弃此种方法,使用commons-compress-1.6.jar包
|
|
|
+ * ZipEntry zipEntry = new ZipEntry(new
|
|
|
+ * String(txtFile.getName().getBytes("GB2312"),"ISO-8859-1"));
|
|
|
+ * zos.putNextEntry(zipEntry); ZipOutputStream zos = new
|
|
|
+ * ZipOutputStream(zipFos); ZipEntry zipEntry = new ZipEntry(new
|
|
|
+ * String(txtFile.getName().getBytes("GB2312"),"ISO-8859-1")); zos.
|
|
|
+ * putNextEntry(zipEntry);
|
|
|
+ * zos.write(FileUtils.readFileToByteArray(txtFile)); zos.flush();
|
|
|
+ * zos.close();
|
|
|
+ */
|
|
|
+ //获取创建好的图片文件
|
|
|
+ File imageFile = new File(path+"/"+fileName+".jpg");
|
|
|
+ // 打成压缩包
|
|
|
+ zipFile = new File(path + "/" + zipFileName);
|
|
|
+ FileOutputStream zipFos = new FileOutputStream(zipFile);
|
|
|
+ ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
|
|
|
+ if (archOut instanceof ZipArchiveOutputStream) {
|
|
|
+ ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
|
|
|
+ ZipArchiveEntry zipEntry = new ZipArchiveEntry(imageFile, imageFile.getName());
|
|
|
+ zos.putArchiveEntry(zipEntry);
|
|
|
+ zos.write(FileUtils.readFileToByteArray(imageFile));
|
|
|
+ zos.closeArchiveEntry();
|
|
|
+ zos.flush();
|
|
|
+ zos.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 压缩完删除txt文件
|
|
|
+ if (imageFile.exists()) {
|
|
|
+ imageFile.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 输出到客户端
|
|
|
+ OutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes("GB2312"), "ISO-8859-1"));
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ out.write(FileUtils.readFileToByteArray(zipFile));
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ // 输出客户端结束后,删除压缩包
|
|
|
+ if (zipFile.exists()) {
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (ArchiveException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 压缩多个文件到一个zip压缩包中
|
|
|
+ * @description :
|
|
|
+ * @date 2016-11-4
|
|
|
+ * @author liucong
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @throws Exception
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @RequestMapping("/zipMoreFiles")
|
|
|
+ public void zipMoreFiles(HttpServletRequest request,HttpServletResponse response) throws Exception{
|
|
|
+ //定义根路径
|
|
|
+ String rootPath = request.getRealPath("/");
|
|
|
+ //创建文件
|
|
|
+ File file = new File(rootPath+"temp_download");
|
|
|
+ //判断文件是否存在,如果不存在,则创建此文件夹
|
|
|
+ if(!file.exists()){
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ String name = "图片压缩包下载";
|
|
|
+ String fileName = name+new Date().getTime();
|
|
|
+ String zipFileName = fileName + ".zip";
|
|
|
+ File zipFile = null;
|
|
|
+ String path = rootPath + "temp_download";
|
|
|
+ //获取本地文件夹中图片集合,事先准备好图片
|
|
|
+ File files = new File("F:\\images\\");
|
|
|
+ //获取该文件夹中的图片文件数组
|
|
|
+ File[] filelist = files.listFiles();
|
|
|
+ // 打成压缩包
|
|
|
+ zipFile = new File(path + "/" + zipFileName);
|
|
|
+ FileOutputStream zipFos = new FileOutputStream(zipFile);
|
|
|
+ ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
|
|
|
+ if (archOut instanceof ZipArchiveOutputStream) {
|
|
|
+ ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
|
|
|
+ for(File imageFile : filelist){
|
|
|
+ ZipArchiveEntry zipEntry = new ZipArchiveEntry(imageFile, imageFile.getName());
|
|
|
+ zos.putArchiveEntry(zipEntry);
|
|
|
+ zos.write(FileUtils.readFileToByteArray(imageFile));
|
|
|
+ zos.closeArchiveEntry();
|
|
|
+ zos.flush();
|
|
|
+ }
|
|
|
+ zos.close();
|
|
|
+ }
|
|
|
+ // 输出到客户端
|
|
|
+ OutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes("GB2312"), "ISO-8859-1"));
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ out.write(FileUtils.readFileToByteArray(zipFile));
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ // 输出客户端结束后,删除压缩包
|
|
|
+ if (zipFile.exists()) {
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @RequestMapping("/exportImage")
|
|
|
+ public void exportImage(HttpServletRequest request,HttpServletResponse response,@RequestParam(value="startDate",required = false) String startDate,@RequestParam(value="endDate",required = false) String endDate,@RequestParam(value="imageIds",required = false) String imageIds) throws Exception{
|
|
|
+// if(imageIds == null || imageIds.trim().isEmpty()){
|
|
|
+// log.error("输入参数[imageIds]不能为空.");
|
|
|
+// return ;
|
|
|
+// }
|
|
|
+ log.info("输入参数[startDate]>>"+startDate);
|
|
|
+ log.info("输入参数[endDate]>>"+endDate);
|
|
|
+ log.info("输入参数[imageIds]>>"+imageIds);
|
|
|
+ if(startDate == null && endDate == null && imageIds ==null ){
|
|
|
+ log.error("日期区间或指定图片导出二选一");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ // 读取图片文件
|
|
|
+ List<ImagePathEntity> imageList = imageService.getExportImageList(startDate,endDate,imageIds);
|
|
|
+ if(imageList.size()==0){
|
|
|
+ log.error("未读取到任何需要导出的图片.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+// System.out.println("imageList.size>>"+imageList.size());
|
|
|
+ int i = 0;
|
|
|
+ File[] fileList = new File[imageList.size()];
|
|
|
+ for(ImagePathEntity imagePathEntity:imageList){
|
|
|
+ File imageFile = new File(imagePathEntity.getImgPath());
|
|
|
+ fileList[i++]=imageFile;
|
|
|
+ }
|
|
|
+ //定义根路径
|
|
|
+ String rootPath = request.getRealPath("/");
|
|
|
+ //创建文件
|
|
|
+ File file = new File(rootPath+"temp_download");
|
|
|
+ //判断文件是否存在,如果不存在,则创建此文件夹
|
|
|
+ if(!file.exists()){
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ String name = "图片压缩包下载";
|
|
|
+ String fileName = name+new Date().getTime();
|
|
|
+ String zipFileName = fileName + ".zip";
|
|
|
+ File zipFile = null;
|
|
|
+ String path = rootPath + "temp_download";
|
|
|
+// 打成压缩包
|
|
|
+ zipFile = new File(path + "/" + zipFileName);
|
|
|
+ FileOutputStream zipFos = new FileOutputStream(zipFile);
|
|
|
+ ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
|
|
|
+ if (archOut instanceof ZipArchiveOutputStream) {
|
|
|
+ ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
|
|
|
+ for(File imageFile : fileList){
|
|
|
+ ZipArchiveEntry zipEntry = new ZipArchiveEntry(imageFile, imageFile.getName());
|
|
|
+ zos.putArchiveEntry(zipEntry);
|
|
|
+ zos.write(FileUtils.readFileToByteArray(imageFile));
|
|
|
+ zos.closeArchiveEntry();
|
|
|
+ zos.flush();
|
|
|
+ }
|
|
|
+ zos.close();
|
|
|
+ }
|
|
|
+ // 输出到客户端
|
|
|
+ OutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes("GB2312"), "ISO-8859-1"));
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ out.write(FileUtils.readFileToByteArray(zipFile));
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ // 输出客户端结束后,删除压缩包
|
|
|
+ if (zipFile.exists()) {
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/exportOneImage",method = RequestMethod.GET)
|
|
|
+ public void exportOneImage(@RequestParam(value = "type",required = true) String type){
|
|
|
+
|
|
|
+ }
|
|
|
}
|