Commit 3660055b by liulei

APP文件上传

parent 3236342b
...@@ -8,7 +8,9 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -8,7 +8,9 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
@SpringBootApplication(scanBasePackages = "com.baosight") @SpringBootApplication(scanBasePackages = "com.baosight")
@ServletComponentScan("com.baosight.iplat4j.core.web.servlet") @ServletComponentScan("com.baosight.iplat4j.core.web.servlet")
...@@ -26,4 +28,12 @@ public class HpjxApplication extends SpringBootServletInitializer { ...@@ -26,4 +28,12 @@ public class HpjxApplication extends SpringBootServletInitializer {
return application.sources(HpjxApplication.class); return application.sources(HpjxApplication.class);
} }
@Bean("multipartResolver")
public CommonsMultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setMaxInMemorySize(10000);
return resolver;
}
} }
package com.baosight.hpjx.controller;
import com.baosight.hpjx.hp.mt.untils.Base64ToMultipartFile;
import com.baosight.hpjx.hp.mt.untils.UploadUtils2;
import com.baosight.hpjx.util.FileUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.hpjx.util.StringUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import com.baosight.iplat4j.eu.dm.document.bos.s3.api.signed.SignedBosHelp;
import com.baosight.iplat4j.eu.dm.document.bos.s3.param.BosParamHelp;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* @author:songx
* @date:2024/3/14,14:26
*/
@CrossOrigin
@RestController
@RequestMapping({"/upload/file"})
public class FileUploadController {
/**
* 更具docId上传文件
*
* @param file
* @throws IOException
*/
@RequestMapping(value = "/app", method = RequestMethod.POST)
public Map upload(MultipartFile file) throws IOException {
Map resultMap = new HashMap();
try {
JSONObject upload = UploadUtils2.upload((CommonsMultipartFile)file);
resultMap.put("id",upload.getString("docId"));
resultMap.put("status", EiConstant.STATUS_SUCCESS);
resultMap.put("message", "SUCCESS");
return resultMap;
} catch (Exception e) {
resultMap.put("status", 500);
resultMap.put("message", LogUtils.getMsg(e));
return resultMap;
}
}
}
...@@ -211,10 +211,7 @@ public class ServiceHPMT002 extends ServiceBase { ...@@ -211,10 +211,7 @@ public class ServiceHPMT002 extends ServiceBase {
String docId = hpzl001A.getDocId(); String docId = hpzl001A.getDocId();
dirId.put("docId", docId); dirId.put("docId", docId);
List<Map> query = this.dao.query("HPMT002.queryFile", dirId); List<Map> query = this.dao.query("HPMT002.queryFile", dirId);
File file = new File(ROOT_PATH + "/A/" + query.get(0).get("CHG_NAME")); imgList.add((String) query.get(0).get("URL"));
BufferedImage bf = ImageIO.read(file);
String imgBase64 = UploadUtils.imageToBase64(bf);
imgList.add(imgBase64);
} }
//处理的文件 //处理的文件
Map Map2 = new HashMap(); Map Map2 = new HashMap();
...@@ -228,17 +225,12 @@ public class ServiceHPMT002 extends ServiceBase { ...@@ -228,17 +225,12 @@ public class ServiceHPMT002 extends ServiceBase {
String docId = hpzl001A.getDocId(); String docId = hpzl001A.getDocId();
dirId.put("docId", docId); dirId.put("docId", docId);
List<Map> query = this.dao.query("HPMT002.queryFile", dirId); List<Map> query = this.dao.query("HPMT002.queryFile", dirId);
File file = new File(ROOT_PATH+ "/A/" + query.get(0).get("CHG_NAME")); imgList2.add((String) query.get(0).get("URL"));
BufferedImage bf = ImageIO.read(file);
String imgBase64 = UploadUtils.imageToBase64(bf);
imgList2.add(imgBase64);
} }
Map sqlMap = new HashMap(); Map sqlMap = new HashMap();
sqlMap.put("companyCode", companyCode); sqlMap.put("companyCode", companyCode);
sqlMap.put("id", id); sqlMap.put("id", id);
List<Map> rows = this.dao.query("HPMT002.pmQualityDetail", sqlMap); List<Map> rows = this.dao.query("HPMT002.pmQualityDetail", sqlMap);
EiBlock eiBlock = new EiBlock(EiConstant.resultBlock);
eiBlock.setRows(rows);
resultMap.put("result",rows); resultMap.put("result",rows);
resultMap.put("img",imgList); resultMap.put("img",imgList);
resultMap.put("img2",imgList2); resultMap.put("img2",imgList2);
......
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
<select id="queryFile" resultClass="java.util.HashMap"> <select id="queryFile" resultClass="java.util.HashMap">
SELECT CHG_NAME FROM iplat.TEUDM02 where DOC_ID=#docId# SELECT URL FROM iplat.TEUDM05 where RES_ID=#docId#
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment