Bladeren bron

文件上传

lyhzzz 3 jaren geleden
bovenliggende
commit
21217feecf

+ 6 - 4
4dkankan-center-platform/src/main/java/com/fdkankan/agent/controller/AgentAuditController.java

@@ -20,7 +20,9 @@ import org.springframework.web.bind.annotation.*;
 import java.util.LinkedHashMap;
 import java.util.List;
 
-//经销商申请模块
+/**
+ * 经销商申请模块
+ */
 @RestController
 @RequestMapping("/api")
 public class AgentAuditController {
@@ -35,7 +37,7 @@ public class AgentAuditController {
      */
     @PostMapping("/agentAduit/save")
     public ResultData agentAuditSave(
-            @RequestBody RequestAgentAudit param) throws Exception {
+            @RequestBody RequestAgentAudit param) {
         if(param == null || StringUtils.isEmpty(param.getName()) || StringUtils.isEmpty(param.getAddress()) ||
                 StringUtils.isEmpty(param.getCountry()) || StringUtils.isEmpty(param.getRegion()) ||
                 StringUtils.isEmpty(param.getSurName()) || StringUtils.isEmpty(param.getUserName()) ||
@@ -60,7 +62,7 @@ public class AgentAuditController {
     @GetMapping("/manager/agentAduit/list")
     public ResultData list(
             @RequestParam(value="pageNum", defaultValue="1", required = false) Integer pageNum,
-            @RequestParam(value="pageSize", defaultValue="10", required = false) Integer pageSize) throws Exception{
+            @RequestParam(value="pageSize", defaultValue="10", required = false) Integer pageSize) {
 
         LinkedHashMap<String,String> condition = new LinkedHashMap<>();
         condition.put("rec_status = 'A'","and");
@@ -71,7 +73,7 @@ public class AgentAuditController {
 
     @PostMapping("/manager/agentAduit/update/active/{id}/{state}")
     private ResultData updateActive(
-            @PathVariable("id") Long id, @PathVariable("state") String state) throws Exception{
+            @PathVariable("id") Long id, @PathVariable("state") String state) {
         LinkedHashMap<String,String> condition = new LinkedHashMap<>();
         condition.put("id ="+id,"and");
         condition.put("rec_status = 'A'","and");

+ 2 - 2
4dkankan-center-platform/src/main/java/com/fdkankan/agent/controller/AgentController.java

@@ -34,7 +34,7 @@ public class AgentController {
      * @return
      */
     @PostMapping(value = "/detail")
-    public ResultData detail(HttpServletRequest request ) throws Exception {
+    public ResultData detail(HttpServletRequest request ) {
         String userName = JWT.decode( request.getHeader("token")).getClaim("userName").asString();
         String agentId = userName.split(":")[1];
         LinkedHashMap<String,String > queryMap = new LinkedHashMap<>();
@@ -50,7 +50,7 @@ public class AgentController {
      * @return
      */
     @PostMapping(value = "/notice")
-    public ResultData notice(HttpServletRequest request ) throws Exception {
+    public ResultData notice(HttpServletRequest request ) {
         AgentNoticeVo agentNoticeVo = new AgentNoticeVo();
         LinkedHashMap<String,String> queryMap = new LinkedHashMap<>();
         queryMap.put("rec_status = A" ,"and");

+ 3 - 2
4dkankan-center-platform/src/main/java/com/fdkankan/agent/service/impl/AgentAuditService.java

@@ -53,8 +53,9 @@ public class AgentAuditService extends AbstractService<AgentAudit> implements IA
 			condition.put("(address like '%"+itemName+"%' )","or");
 			condition.put("(note_content like '%"+itemName+"%' ))","or");
 		}
-		List<AgentAudit> list = this.getAllList(condition, "create_time desc");
-		return ResultData.ok(pageNum,pageSize,list.size(),list);
+		List<AgentAudit> list = this.getList(condition, pageNum,pageSize,"create_time desc");
+		Integer total = this.getCount(condition,null);
+		return ResultData.ok(pageNum,pageSize,total,list);
 	}
 }
 

+ 74 - 0
4dkankan-center-platform/src/main/java/com/fdkankan/goods/controller/CameraVersionController.java

@@ -0,0 +1,74 @@
+package com.fdkankan.goods.controller;
+
+import com.fdkankan.agent.controller.request.RequestSearch;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.goods.controller.request.RequestCameraVersion;
+import com.fdkankan.goods.entity.CameraVersion;
+import com.fdkankan.goods.service.ICameraVersionService;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ * 相机版本管理模块
+ */
+@RequestMapping("/api")
+public class CameraVersionController {
+
+    @Autowired
+    private ICameraVersionService cameraVersionService;
+
+
+    /**
+     * 获取相机版本列表
+     */
+    @GetMapping("/manager/goods/version/list")
+    private ResultData getList(@RequestParam(value="pageNum", defaultValue="1", required = false) Integer pageNum,
+                               @RequestParam(value="pageSize", defaultValue="10", required = false) Integer pageSize,
+                               String type) {
+
+        LinkedHashMap<String,String> condition = new LinkedHashMap<>();
+        if(StringUtils.isBlank(type)){
+            type = "1";
+        }
+        condition.put("res_status = 'A'","and");
+        condition.put("type = "+ type,"and");
+        List<CameraVersion> list = cameraVersionService.getList(condition,pageNum, pageSize, "create_time desc");
+        Integer total = cameraVersionService.getCount(condition,null);
+        return ResultData.ok(pageNum,pageSize,total,list);
+    }
+
+    /**
+     * 更新状态
+     * @param id
+     * @param status   状态
+     * @param type     相机类型,1八目,2双目,不传默认八目 3:转台相机 4:激光
+     * @return
+     */
+    @GetMapping("/manager/goods/version/update/{id}/{status}/{type}")
+    private ResultData updateStatus(@PathVariable("id") Long id, @PathVariable("status") String status, @PathVariable("type") String type) {
+        return cameraVersionService.updateStatus(id, StringUtils.upperCase(status), type);
+    }
+
+
+    @PostMapping("/manager/goods/version/search")
+    private ResultData search(@RequestBody RequestSearch param){
+        return cameraVersionService.searchLike(param);
+    }
+
+
+    @PostMapping(value = "/manager/goods/version/upload", consumes = { "multipart/form-data" })
+    private ResultData upload(@RequestParam("file") MultipartFile file,
+                          @RequestParam("version") String version,
+                          @RequestParam("description") String description,
+                          @RequestParam("minVersion") String minVersion,
+                          String type) {
+
+        return cameraVersionService.upload(file, version,description,minVersion,type);
+    }
+}

+ 18 - 0
4dkankan-center-platform/src/main/java/com/fdkankan/goods/controller/request/RequestCameraVersion.java

@@ -0,0 +1,18 @@
+package com.fdkankan.goods.controller.request;
+
+import lombok.Data;
+
+@Data
+public class RequestCameraVersion {
+
+    private static final long serialVersionUID = 2345798398902100085L;
+
+    private String description; // 描述
+
+    private String version; // 相机版本
+
+    private String minVersion; // 相机版本
+
+    private Integer type;
+
+}

+ 8 - 0
4dkankan-center-platform/src/main/java/com/fdkankan/goods/service/ICameraVersionService.java

@@ -1,10 +1,18 @@
 package com.fdkankan.goods.service;
 
 
+import com.fdkankan.agent.controller.request.RequestSearch;
 import com.fdkankan.common.base.IServiceOperations;
+import com.fdkankan.common.response.ResultData;
 import com.fdkankan.goods.entity.CameraVersion;
+import org.springframework.web.multipart.MultipartFile;
 
 public interface ICameraVersionService extends IServiceOperations<CameraVersion> {
 
+    ResultData updateStatus(Long id, String upperCase, String type);
+
+    ResultData searchLike(RequestSearch param);
+
+    ResultData upload(MultipartFile file, String version, String description, String minVersion, String type)throws Exception;
 }
 

+ 130 - 0
4dkankan-center-platform/src/main/java/com/fdkankan/goods/service/impl/CameraVersionService.java

@@ -1,17 +1,40 @@
 package com.fdkankan.goods.service.impl;
 
+import com.fdkankan.agent.controller.request.RequestSearch;
 import com.fdkankan.common.base.AbstractService;
 import com.fdkankan.common.base.IOperations;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.common.util.FileUtil;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.common.validation.ValidationUtils;
 import com.fdkankan.goods.entity.CameraVersion;
 import com.fdkankan.goods.mapper.ICameraVersionMapper;
 import com.fdkankan.goods.service.ICameraVersionService;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Base64;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
 
 @Service("CameraVersionService")
 public class CameraVersionService extends AbstractService<CameraVersion> implements ICameraVersionService {
 
+	private static Logger log = LoggerFactory.getLogger("programLog");
+
+	private static String ALIYUN_SSO_PATH = "camera_version/";
+
+	private static String YAMAXUN_S3_PATH = "https://eurs3.4dkankan.com/camera_version/";
+
+	private static String DIR_NAME = "camera_version/";
+
 	public CameraVersionService() {
 		this.setTableName("t_camera_version");
 	}
@@ -26,5 +49,112 @@ public class CameraVersionService extends AbstractService<CameraVersion> impleme
 	public void setTableName(String tableName){
 		this.tableName = tableName;
 	}
+
+	@Override
+	public ResultData updateStatus(Long id, String status, String type) {
+		LinkedHashMap<String,String> condition = new LinkedHashMap<>();
+		condition.put("id= "+id,"and");
+		CameraVersion cameraVersion = this.getOne(condition);
+		if(cameraVersion == null){
+			return ResultData.error(ErrorCode.FAILURE_CODE_3001);
+		}
+		if (!ValidationUtils.validateRecStatus(status)) {
+			return ResultData.error(ErrorCode.FAILURE_CODE_3001);
+		}
+
+		condition = new LinkedHashMap<>();
+		if(StringUtils.isBlank(type)){
+			type = "1";
+		}
+		condition.put("res_status = 'A'","and");
+		condition.put("type = "+ type,"and");
+		List<CameraVersion> list = this.getAllList(condition);
+		for (CameraVersion version : list) {
+			version.setAcStatus("I");
+		}
+		this.update(list);
+
+		cameraVersion.setAcStatus(status);
+		this.update(cameraVersion);
+		return ResultData.ok();
+	}
+
+	@Override
+	public ResultData searchLike(RequestSearch param) {
+		Integer pageNum = Integer.valueOf(param.getPageNum());
+		Integer pageSize = Integer.valueOf(param.getPageSize());
+		String startDate = param.getStartDate();
+		String endDate = param.getEndDate();
+		String itemName = param.getItemName();
+		Integer type = StringUtils.isNotBlank(param.getType()) ? Integer.valueOf(param.getType()) : 1;
+
+		LinkedHashMap<String,String> condition = new LinkedHashMap<>();
+		condition.put("rec_status ='A'","and");
+		condition.put("camera_type ="+type,"and");
+		if(StringUtils.isNotBlank(startDate)){
+			condition.put("create_time >= '"+startDate+"'","and");
+		}
+		if(StringUtils.isNotBlank(endDate)){
+			condition.put("create_time <= '"+endDate+"' ","and");
+		}
+		if(StringUtils.isNotBlank(itemName)){
+			condition.put("((file_name like '%"+itemName+"%' )","and");
+			condition.put("(version like '%"+itemName+"%' )","or");
+			condition.put("(note_content like '%"+itemName+"%' ))","or");
+		}
+		List<CameraVersion> list = this.getList(condition, pageNum,pageSize,"create_time desc");
+		Integer total = this.getCount(condition,null);
+		return ResultData.ok(pageNum,pageSize,total,list);
+	}
+
+
+	/**
+	 * 上传文件到阿里云
+	 */
+	@Override
+	public ResultData upload(MultipartFile file, String version, String description, String minVersion, String StringType) throws Exception{
+		Integer type = StringUtils.isNotBlank(StringType) ? Integer.valueOf(StringType) : 1;
+		log.info("run upload");
+		if (!file.isEmpty()&& file.getSize() <= 0) {
+			return ResultData.error(ErrorCode.FAILURE_CODE_3017);
+		}
+
+		// 文件名全名
+		String fullFileName = file.getOriginalFilename();
+
+		// 将文件转字节-> 字符串
+		String fileContent = Base64.getEncoder().encodeToString(file.getBytes());
+
+		// 获取类路径
+		String resourcePath = FileUtils.getResource();
+		log.info("resourcePath: {}", resourcePath);
+
+		// 创建目录
+		String dirPath = resourcePath + DIR_NAME  ;
+		FileUtils.createDir(dirPath);
+
+		// 拼接唯一文件名
+		String fileName = dateStr() + fullFileName;
+
+		// 文件保存路径
+		String filePath = dirPath + dateStr() + fullFileName;
+
+		// 写文件到本地
+		FileUtils.base64ToFileWriter(fileContent, filePath);
+		log.info("filePath: {}", filePath);
+
+		// 读取本地文件
+		byte[] content = FileUtil.getContent(filePath);
+
+		return null;
+	}
+
+	// 获取时间戳
+	private String dateStr() {
+		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
+		String format = df.format(new Date());
+		long timeMillis = System.currentTimeMillis();
+		return format + "_" + timeMillis + "_";
+	}
 }
 

+ 19 - 1
4dkankan-common/pom.xml

@@ -14,7 +14,6 @@
     <artifactId>4dkankan-common</artifactId>
 
     <dependencies>
-
         <dependency>
             <groupId>org.mybatis.spring.boot</groupId>
             <artifactId>mybatis-spring-boot-starter</artifactId>
@@ -46,6 +45,25 @@
             <artifactId>fastjson</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.ant</groupId>
+            <artifactId>ant</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>joinery</groupId>
+            <artifactId>jave</artifactId>
+            <version>1.0.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco</groupId>
+            <artifactId>javacpp</artifactId>
+            <version>1.4.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco</groupId>
+            <artifactId>javacv-platform</artifactId>
+            <version>1.4.3</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 240 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/FileUtil.java

@@ -0,0 +1,240 @@
+package com.fdkankan.common.util;
+
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+
+/**
+ * @author MeepoGuan
+ *
+ * <p>Description: file_util</p>
+ *
+ * 2017年4月30日
+ *
+ */
+public class FileUtil {
+
+/*	public static void main(String[] args) {
+		String dirName = "d:/FH/topic/";// 创建目录
+		FileUtil.createDir(dirName);
+	}*/
+
+	/**
+	 * 创建目录
+	 * 
+	 * @param destDirName
+	 *            目标目录名
+	 * @return 目录创建成功返回true,否则返回false
+	 */
+	public static boolean createDir(String destDirName) {
+		File dir = new File(destDirName);
+		if (dir.exists()) {
+			return false;
+		}
+		if (!destDirName.endsWith(File.separator)) {
+			destDirName = destDirName + File.separator;
+		}
+		// 创建单个目录
+		if (dir.mkdirs()) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	/**
+	 * 删除文件
+	 * 
+	 * @param filePathAndName
+	 *            String 文件路径及名称 如c:/fqf.txt
+	 * @return boolean
+	 */
+	public static void delFile(String filePathAndName) {
+		try {
+			String filePath = filePathAndName;
+			filePath = filePath.toString();
+			File myDelFile = new File(filePath);
+			myDelFile.delete();
+
+		} catch (Exception e) {
+			System.out.println("删除文件操作出错");
+			e.printStackTrace();
+
+		}
+
+	}
+
+	/**
+	 * 读取到字节数组0
+	 * 
+	 * @param filePath //路径
+	 * @throws IOException
+	 */
+	public static byte[] getContent(String filePath) throws IOException {
+		File file = new File(filePath);
+		long fileSize = file.length();
+		if (fileSize > Integer.MAX_VALUE) {
+			System.out.println("file too big...");
+			return null;
+		}
+		FileInputStream fi = new FileInputStream(file);
+		byte[] buffer = new byte[(int) fileSize];
+		int offset = 0;
+		int numRead = 0;
+		while (offset < buffer.length
+				&& (numRead = fi.read(buffer, offset, buffer.length - offset)) >= 0) {
+			offset += numRead;
+		}
+		// 确保所有数据均被读取
+		if (offset != buffer.length) {
+			throw new IOException("Could not completely read file "
+					+ file.getName());
+		}
+		fi.close();
+		return buffer;
+	}
+
+	/**
+	 * 读取到字节数组1
+	 * 
+	 * @param filePath
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] toByteArray(String filePath) throws IOException {
+
+		File f = new File(filePath);
+		if (!f.exists()) {
+			throw new FileNotFoundException(filePath);
+		}
+		ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
+		BufferedInputStream in = null;
+		try {
+			in = new BufferedInputStream(new FileInputStream(f));
+			int buf_size = 1024;
+			byte[] buffer = new byte[buf_size];
+			int len = 0;
+			while (-1 != (len = in.read(buffer, 0, buf_size))) {
+				bos.write(buffer, 0, len);
+			}
+			return bos.toByteArray();
+		} catch (IOException e) {
+			e.printStackTrace();
+			throw e;
+		} finally {
+			try {
+				in.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			bos.close();
+		}
+	}
+
+	/**
+	 * 读取到字节数组2
+	 * 
+	 * @param filePath
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] toByteArray2(String filePath) throws IOException {
+
+		File f = new File(filePath);
+		if (!f.exists()) {
+			throw new FileNotFoundException(filePath);
+		}
+
+		FileChannel channel = null;
+		FileInputStream fs = null;
+		try {
+			fs = new FileInputStream(f);
+			channel = fs.getChannel();
+			ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size());
+			while ((channel.read(byteBuffer)) > 0) {
+				// do nothing
+				// System.out.println("reading");
+			}
+			return byteBuffer.array();
+		} catch (IOException e) {
+			e.printStackTrace();
+			throw e;
+		} finally {
+			try {
+				channel.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			try {
+				fs.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	/**
+	 * Mapped File way MappedByteBuffer 可以在处理大文件时,提升性能
+	 * 
+	 * @param filePath
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] toByteArray3(String filePath) throws IOException {
+
+		FileChannel fc = null;
+		RandomAccessFile rf = null;
+		try {
+			rf = new RandomAccessFile(filePath, "r");
+			fc = rf.getChannel();
+			MappedByteBuffer byteBuffer = fc.map(MapMode.READ_ONLY, 0,
+					fc.size()).load();
+			//System.out.println(byteBuffer.isLoaded());
+			byte[] result = new byte[(int) fc.size()];
+			if (byteBuffer.remaining() > 0) {
+				// System.out.println("remain");
+				byteBuffer.get(result, 0, byteBuffer.remaining());
+			}
+			return result;
+		} catch (IOException e) {
+			e.printStackTrace();
+			throw e;
+		} finally {
+			try {
+				rf.close();
+				fc.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+    public static File[] sort(File[] s) {
+        //中间值
+        File temp = null;
+        //外循环:我认为最小的数,从0~长度-1
+        for (int j = 0; j < s.length - 1; j++) {
+            //最小值:假设第一个数就是最小的
+            String min = s[j].getName();
+            //记录最小数的下标的
+            int minIndex = j;
+            //内循环:拿我认为的最小的数和后面的数一个个进行比较
+            for (int k = j + 1; k < s.length; k++) {
+                //找到最小值
+                if (Integer.parseInt(min.substring(0, min.indexOf("."))) > Integer.parseInt(s[k].getName().substring(0, s[k].getName().indexOf(".")))) {
+                    //修改最小
+                    min = s[k].getName();
+                    minIndex = k;
+                }
+            }
+            //当退出内层循环就找到这次的最小值
+            //交换位置
+            temp = s[j];
+            s[j] = s[minIndex];
+            s[minIndex] = temp;
+        }
+        return s;
+    }
+}

File diff suppressed because it is too large
+ 1082 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/FileUtils.java


+ 7 - 0
pom.xml

@@ -34,6 +34,7 @@
         <druid-version>1.1.17</druid-version>
         <spring.plugin.metadata-version>1.2.0.RELEASE</spring.plugin.metadata-version>
         <jwt-version>3.10.3</jwt-version>
+        <ant-version>1.8.2</ant-version>
     </properties>
 
     <dependencyManagement>
@@ -104,6 +105,12 @@
                 <version>${jwt-version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.apache.ant</groupId>
+                <artifactId>ant</artifactId>
+                <version>${ant-version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>