level 11
这个聪明的家伙🔥
楼主
/**
* 转扣结果导入 上传解析
*
* @return
*/
@RequestMapping("resultPost")
@ResponseBody
public String resultPost(HttpServletRequest request, @RequestParam("file") CommonsMultipartFile[] files) {
String error = "调用了PaymentFileController.resultPost【转扣结果导入】方法";
UUserMas uUserMas = (UUserMas) request.getSession().getAttribute(UserConstant.SESSION_LOGIN_UUSERMAS);
logger.info(error+"操作人:"+uUserMas.getWorkCode());
String result = "";
List<Map<String, Object>> list = null;
FileOutputStream os = null;
InputStream in = null;
InputStream ins = null;
for (int i = 0; i < files.length; i++) {
if (!files[i].isEmpty()) {
try {
String fileName = files[i].getOriginalFilename();
String type = fileName.substring(fileName.lastIndexOf("."));
String docPath = FilePathConstant.getFilePathGroupByMonth(FilePathConstant.PAY_FILE_UP_DOC_PATH);
// 拿到输出流,同时重命名上传的文件
os = new FileOutputStream(docPath + System.currentTimeMillis() + type);
// 拿到上传文件的输入流
in = files[i].getInputStream();
// 拿到上传文件的输入流
ins = files[i].getInputStream();
// 以写字节的方式写文件
int b = 0;
while ((b = in.read()) != -1) {
os.write(b);
}
os.flush();
//从inputstream中获取上传内容信息
StringWriter writer = new StringWriter();
IOUtils.copy(ins, writer, "UTF-8");
String uploadContent = writer.toString();
if(StringUtils.isEmpty(uploadContent)){
throw new Exception("上传文件为空!");
}
//替换全部的换行为逗号
uploadContent = uploadContent.replaceAll("\r\n", ",");
//将字符串变成json格式
uploadContent = "[" + uploadContent + "]";
list = JsonUtil.toObject(uploadContent, new ObjectTypeToken<List<Map<String, Object>>>(){});
if(list != null && !list.isEmpty()){
result = iPayService.upOLPayFileResultPost(list,uUserMas.getWorkCode());
}
} catch (Exception e) {
logger.error(error + "异常!参数{}", e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error("error",e);
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.error("error",e);
}
}
if (ins != null) {
try {
ins.close();
} catch (IOException e) {
logger.error("error",e);
}
}
}
}
}
return result;
}
2018年03月21日 07点03分
1
* 转扣结果导入 上传解析
*
* @return
*/
@RequestMapping("resultPost")
@ResponseBody
public String resultPost(HttpServletRequest request, @RequestParam("file") CommonsMultipartFile[] files) {
String error = "调用了PaymentFileController.resultPost【转扣结果导入】方法";
UUserMas uUserMas = (UUserMas) request.getSession().getAttribute(UserConstant.SESSION_LOGIN_UUSERMAS);
logger.info(error+"操作人:"+uUserMas.getWorkCode());
String result = "";
List<Map<String, Object>> list = null;
FileOutputStream os = null;
InputStream in = null;
InputStream ins = null;
for (int i = 0; i < files.length; i++) {
if (!files[i].isEmpty()) {
try {
String fileName = files[i].getOriginalFilename();
String type = fileName.substring(fileName.lastIndexOf("."));
String docPath = FilePathConstant.getFilePathGroupByMonth(FilePathConstant.PAY_FILE_UP_DOC_PATH);
// 拿到输出流,同时重命名上传的文件
os = new FileOutputStream(docPath + System.currentTimeMillis() + type);
// 拿到上传文件的输入流
in = files[i].getInputStream();
// 拿到上传文件的输入流
ins = files[i].getInputStream();
// 以写字节的方式写文件
int b = 0;
while ((b = in.read()) != -1) {
os.write(b);
}
os.flush();
//从inputstream中获取上传内容信息
StringWriter writer = new StringWriter();
IOUtils.copy(ins, writer, "UTF-8");
String uploadContent = writer.toString();
if(StringUtils.isEmpty(uploadContent)){
throw new Exception("上传文件为空!");
}
//替换全部的换行为逗号
uploadContent = uploadContent.replaceAll("\r\n", ",");
//将字符串变成json格式
uploadContent = "[" + uploadContent + "]";
list = JsonUtil.toObject(uploadContent, new ObjectTypeToken<List<Map<String, Object>>>(){});
if(list != null && !list.isEmpty()){
result = iPayService.upOLPayFileResultPost(list,uUserMas.getWorkCode());
}
} catch (Exception e) {
logger.error(error + "异常!参数{}", e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
logger.error("error",e);
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.error("error",e);
}
}
if (ins != null) {
try {
ins.close();
} catch (IOException e) {
logger.error("error",e);
}
}
}
}
}
return result;
}