<bean id="multipartResolver"
class="com.jssh.credit.infrastructure.multipart.resolver.CommonsMultipartResolverExt">
<property name="maxUploadSize">
<value>524288000</value>
</property>
<property name="defaultEncoding">
<value>UTF-8</value>
</property>
</bean>
@RequestMapping("/addBrokersByFile")
@ResponseBody
public ResponseMessage addBrokersByFile(HttpServletRequest request, MultipartHttpServletRequest multipartRequest){
UserRequestDTO user = WebHelper.getUser(request);
if (user==null)
return new ResponseMessage(ResponseConstants.登录失效,"登录已失效");
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(request.getSession()
.getServletContext());
if (commonsMultipartResolver.isMultipart(request)) {
MultipartFile multipartFile = multipartRequest.getFile("file");
String _fileName = multipartFile.getOriginalFilename();
String suffix = _fileName.substring(_fileName.lastIndexOf("."));
if (".xls".equals(suffix)){
String localPath = MyConfigProperty.getProperty("uploads_local_path");
if (StringUtils.isNotBlank(localPath)&&localPath.startsWith("file:"))
localPath = localPath.substring(5);
String fileName = localPath+"\\excel\\"+user.getUserAccount()+"\\"+ DateUtils.dfYMDHM.format(new Date())+"\\";
File excelFile = new File(fileName+_fileName);
if (!excelFile.exists()){
new File(fileName).mkdirs();
try {
excelFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
multipartFile.transferTo(excelFile);
} catch (IOException e) {
e.printStackTrace();
return new ResponseMessage(ResponseConstants.ERROR,"文件解析失败");
}
try{
return new ResponseMessage(ResponseConstants.OK,"Excel文件导入成功");
}catch(Exception e){
return new ResponseMessage(ResponseConstants.ERROR,e.getMessage());
}
}else{
return new ResponseMessage(ResponseConstants.ERROR,"文件格式不正确,请使用下载的模版填写");
}
}
return null;
}