获取当前用户信息
file:///C:\Users\baorui\AppData\Roaming\Tencent\Users\544328206\QQ\WinTemp\RichOle\$7BO27]W%D7DOV)KE}11}1X.jpg这里user为空。不知道为什么。
/**
* 导入库存Excel
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(params = "importRepertoryExcel", method = RequestMethod.POST)
@ResponseBody
public AjaxJson importRepertoryExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
AjaxJson j = new AjaxJson();
//, @RequestParam("clientId") String clientId
// String clientid = request.getParameter("clientId");
// System.out.println("****************"+clientId+"**************");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得文件:
MultipartFile multipartFile = multipartRequest.getFile("Filedata");
String clientid= multipartRequest.getParameter("clientId");
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd/HH");
/** 构建文件保存的目录* */
String logoPathDir = "/upload/"+ dateformat.format(new Date());
/** 得到文件保存目录的真实路径* */
String logoRealPathDir = request.getSession().getServletContext().getRealPath(logoPathDir);
/** 根据真实路径创建目录* */
File logoSaveFile = new File(logoRealPathDir);
if (!logoSaveFile.exists())
logoSaveFile.mkdirs();
/** 获取文件的后缀* */
String suffix = multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf("."));
/** 使用UUID生成文件名称* */
String logImageName = UUID.randomUUID().toString() + suffix;// 构建文件名称
/** 拼成完整的文件保存路径加文件* */
String fileName = logoRealPathDir + File.separator + logImageName;
File file = new File(fileName);
try {
multipartFile.transferTo(file);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/** 打印出上传到服务器的文件的绝对路径* */
System.out.println("****************"+fileName+"**************");
// 获得文件名:
String filename = multipartFile.getOriginalFilename();
System.out.println("文件名:"+filename);
//操作Excel
// String excelUrl = logoPathDir+logImageName;
SimpleDateFormat tjsjformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String excelUrl=fileName;
List<String[]> list = ExcelUtil.readExcel(excelUrl);
int index=0;
TSUser user = ResourceUtil.getSessionUserName();
for (String[] str : list) {
TbSellRepertoryEntity tbSellRepertory=new TbSellRepertoryEntity();
if(index!=0){
// tbSellRepertory.setId(UUID.randomUUID().toString());
tbSellRepertory.setDropName(str);
tbSellRepertory.setNumbers(Integer.parseInt(str));
tbSellRepertory.setTjsj(tjsjformat.parse(str));
tbSellRepertory.setCreateUser("销售");
/* tbSellRepertory.setCreateUser(user.getRealName());
tbSellRepertory.setCreateUserid(user.getId());
tbSellRepertory.setCreateDep(user.getTSDepart().getId());
tbSellRepertory.setCreateDep(user.getTSDepart().getDepartname());*/
tbSellRepertory.setCreateDate(new Date());
tbSellRepertory.setClientId(clientid);
tbSellRepertoryService.save(tbSellRepertory);
}
index++;
for (String s : str) {
System.out.print(s + " | ");
}
//org.jeecgframework.core.util.LogUtil.info("");
}
return j;
}
页:
[1]