提交代码

master
胡锐 1 month ago
parent 024b3c5e0f
commit e26f98089e
  1. 9
      cweb/src/main/java/com/hfkj/controller/UserController.java

@ -1,6 +1,7 @@
package com.hfkj.controller; package com.hfkj.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode; import com.hfkj.common.exception.SysCode;
@ -99,6 +100,9 @@ public class UserController {
FileOutputStream out = null; FileOutputStream out = null;
try { try {
String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
if (!fileType.endsWith("jpg") && !fileType.endsWith("png")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "只能上传jpg或png格式文件");
}
String fileName = System.currentTimeMillis() + "." + fileType; String fileName = System.currentTimeMillis() + "." + fileType;
String childPath = "user-head"; String childPath = "user-head";
String destDirName = sysConfig.getFileUrl() + File.separator + childPath; String destDirName = sysConfig.getFileUrl() + File.separator + childPath;
@ -114,7 +118,10 @@ public class UserController {
// 修改用户头像 // 修改用户头像
user.setHeadImg(CommonSysConst.getSysConfig().getDomain()+"/filesystem/"+fileNames.get(0)); user.setHeadImg(CommonSysConst.getSysConfig().getDomain()+"/filesystem/"+fileNames.get(0));
userService.updateInfo(user); userService.updateInfo(user);
return ResponseMsgUtil.success(user.getHeadImg());
} catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "上传失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "上传失败");
@ -126,7 +133,7 @@ public class UserController {
} }
} }
} }
return ResponseMsgUtil.success(user.getHeadImg()); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "上传失败");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);

Loading…
Cancel
Save