@RequestMapping("/upload")
public String upload(
@RequestParam(value = "fileUpload1",required = false) MultipartFile fileUpload1,
@RequestParam(value = "installNo",required = false)String installNo,
@RequestParam(value = "type",required = false)String type){
Operator principal = (Operator) SecurityUtils.getSubject().getPrincipal();
InstallPath installPath = new InstallPath();
installPath.setInstallPathOperason(principal.getOperatorId());
installPath.setCompanyId(principal.getCompanyId());
installPath.setInstallPathType(type);
installPath.setInstallNo(installNo);
installPath.setInstallPathStatus("1");
if (type.equals("1")){
installPath.setInstallPathOtherName("书面申请");
}
if (type.equals("2")){
installPath.setInstallPathOtherName("身份证明");
}
if (type.equals("3")){
installPath.setInstallPathOtherName("建筑许可");
}
if (type.equals("4")){
installPath.setInstallPathOtherName("建筑平面");
}
if (type.equals("5")){
installPath.setInstallPathOtherName("勘察报告");
}
if (type.equals("6")){
installPath.setInstallPathOtherName("预算报告");
}
if (type.equals("7")){
installPath.setInstallPathOtherName("审核报告");
}
if (type.equals("8")){
installPath.setInstallPathOtherName("实施报告");
}
if (type.equals("9")){
installPath.setInstallPathOtherName("现场施工");
}
if (type.equals("10")){
installPath.setInstallPathOtherName("验收报告");
}
if(fileUpload1.isEmpty()){
return "文件为空";
}
String fileName = fileUpload1.getOriginalFilename();
fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "_" + fileName;
installPath.setInstallPathName(fileName);
String path = "/home/attach/pic/" + fileName;
File dest = new File(path);
boolean b = installService.findOldUrl(installNo, type, principal.getCompanyId());
if (b == false) {
return "已存在附件但覆盖失败,请稍后再尝试上传!";
}
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
try {
fileUpload1.transferTo(dest);
String url = request.getServerName()
+ ":"
+ request.getServerPort()
+path;
installPath.setInstallPathUrl(path);
installService.saveUrl(installPath);
} catch (IOException e) {
return "上传失败";
}
return "上传成功";
}
@GetMapping("/uploadPic")
public void uploadPic(HttpServletResponse response,
@RequestParam(value = "path",required = false)String path) {
File file = new File(path);
try {
if (file.exists()) {
InputStream in = new FileInputStream(path);
OutputStream os = response.getOutputStream();
byte[] b = new byte[1024];
while (in.read(b) != -1) {
os.write(b);
}
in.close();
os.flush();
os.close();
}
} catch (IOException e) {
}
}
function onUploadSuccess(e) {
alert(e.serverData);
this.setText("");
}
function onUploadError(e) {
alert(e.serverData)
}
$('#importBtn').click(function() {
mini.get("fileUpload1").setPostParam({installNo:GLOBAL.apply.installNo,type:7});
mini.get("fileUpload1").startUpload();
});
function setPicture(data) {
var identityCardImg = document.getElementById("identityCardImg");
var planAllowImg = document.getElementById("planAllowImg");
var buildingPictureImg = document.getElementById("buildingPictureImg");
var url = "/install/installation/uploadPic";
$.post("/install/installation/findAttach", {installNo:data.installNo},function (text,status) {
var o = mini.decode(text);
identityCardImg.src = url+"?path="+o[0].applyUrl;
planAllowImg.src = url+"?path="+o[0].permitUrl;
buildingPictureImg.src = url+"?path="+o[0].buildingPlaneUrl;
});
}