101 lines
2.9 KiB
Plaintext
101 lines
2.9 KiB
Plaintext
|
|
package com.nationalelectric.greenH5;
|
|||
|
|
|
|||
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|||
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|||
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|||
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
|
|
|||
|
|
import com.nationalelectirc.Constant.Constant;
|
|||
|
|
import com.nationalelectirc.utils.RestResult;
|
|||
|
|
import com.nationalelectirc.utils.Utils;
|
|||
|
|
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenPersonElecAcc;
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenUserRoleRel;
|
|||
|
|
import com.nationalelectric.greenH5.po.UploadFile;
|
|||
|
|
import com.nationalelectric.greenH5.utils.GetTokenUtil;
|
|||
|
|
import com.sgcc.uap.mdd.model.utils.StringUtil;
|
|||
|
|
import com.sgcc.uap.persistence.IHibernateDao;
|
|||
|
|
|
|||
|
|
import com.alibaba.fastjson.JSONObject;
|
|||
|
|
import com.jysoft.unipush.AliasManage;
|
|||
|
|
|
|||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
|
|
|||
|
|
import java.io.File;
|
|||
|
|
import java.io.IOException;
|
|||
|
|
import java.net.URLDecoder;
|
|||
|
|
import java.util.*;
|
|||
|
|
|
|||
|
|
import javax.servlet.http.HttpServletRequest;
|
|||
|
|
import javax.servlet.http.HttpServletResponse;
|
|||
|
|
|
|||
|
|
import org.springframework.stereotype.Controller;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* <b>概述</b>:<br>
|
|||
|
|
* TODO
|
|||
|
|
* <p>
|
|||
|
|
* <b>功能</b>:<br>
|
|||
|
|
* TODO
|
|||
|
|
*
|
|||
|
|
* @author niguang
|
|||
|
|
*/
|
|||
|
|
@Controller
|
|||
|
|
@RequestMapping("/uploadFile")
|
|||
|
|
public class UploadFileController {
|
|||
|
|
|
|||
|
|
|
|||
|
|
@Autowired
|
|||
|
|
IHibernateDao hibernateDao;
|
|||
|
|
@Autowired
|
|||
|
|
private BaseServiceImpl baseService;
|
|||
|
|
|
|||
|
|
@Autowired
|
|||
|
|
private GreenDictionaryInfoController greenDictionaryInfoController;
|
|||
|
|
|
|||
|
|
|
|||
|
|
@RequestMapping("/upload")
|
|||
|
|
@ResponseBody
|
|||
|
|
public Map<String, Object> uploadApk(@RequestParam("myFile") CommonsMultipartFile file,@RequestParam("userId") String userId){
|
|||
|
|
|
|||
|
|
Map<String, Object> resultMap = new HashMap<String, Object>();
|
|||
|
|
try {
|
|||
|
|
|
|||
|
|
String strArr[] = file.getOriginalFilename().split("\\.");
|
|||
|
|
String name = strArr[strArr.length-2];
|
|||
|
|
String type = strArr[strArr.length-1];
|
|||
|
|
if("doc".equals(type)||"docx".equals(type)||"xls".equals(type)||"xlsx".equals(type)||"pdf".equals(type)){
|
|||
|
|
String id = UUID.randomUUID().toString().replace("-", "");
|
|||
|
|
String path=baseService.getAppImgDir()+id+"."+type;//"D:/ystp/"+
|
|||
|
|
File newFile=new File(path);
|
|||
|
|
file.transferTo(newFile);
|
|||
|
|
UploadFile uf = new UploadFile();
|
|||
|
|
uf.setId(id);
|
|||
|
|
uf.setCreateTime(new Date());
|
|||
|
|
uf.setFileName(name);
|
|||
|
|
uf.setFileType(type);
|
|||
|
|
uf.setCreateBy(userId);
|
|||
|
|
uf.setFilePath(path);
|
|||
|
|
hibernateDao.saveObject(uf);
|
|||
|
|
resultMap.put("returnCode", "1");
|
|||
|
|
resultMap.put("id", id);
|
|||
|
|
}else{
|
|||
|
|
resultMap.put("returnCode", "0");
|
|||
|
|
resultMap.put("returnMsg", "请确认上传文件格式!");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
} catch (IOException e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
resultMap.put("msg", "上传失败");
|
|||
|
|
}
|
|||
|
|
return resultMap;
|
|||
|
|
}
|
|||
|
|
}
|