|
|
@@ -1,16 +1,28 @@
|
|
|
package com.goafanti.admin.controller;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.goafanti.admin.bo.InputAdmin;
|
|
|
+import com.goafanti.admin.service.AdminService;
|
|
|
import com.goafanti.common.bo.Result;
|
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
|
+import com.goafanti.common.constant.ErrorConstants;
|
|
|
import com.goafanti.common.controller.BaseApiController;
|
|
|
+import com.goafanti.common.enums.AdminFields;
|
|
|
+import com.goafanti.common.model.Admin;
|
|
|
+import com.goafanti.common.utils.PasswordUtil;
|
|
|
+import com.goafanti.common.utils.StringUtils;
|
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
|
import com.goafanti.easemob.EasemobUtils;
|
|
|
import com.goafanti.easemob.bo.EasemobInfo;
|
|
|
@@ -22,7 +34,10 @@ public class AdminSystemController extends BaseApiController {
|
|
|
|
|
|
@Autowired
|
|
|
EasemobUtils easemobUtils;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private AdminService adminService;
|
|
|
+ @Resource(name = "passwordUtil")
|
|
|
+ private PasswordUtil passwordUtil;
|
|
|
/**
|
|
|
* 初始化系统消息用户
|
|
|
*/
|
|
|
@@ -40,6 +55,63 @@ public class AdminSystemController extends BaseApiController {
|
|
|
}
|
|
|
return res().data(false);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理员修改本人信息
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/updateAdminInfo", method = RequestMethod.POST)
|
|
|
+ public Result updateAdminInfo(@Valid InputAdmin admin, String pwd, BindingResult bindingResult) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "超级管理员"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
|
|
|
+ AdminFields.getFieldDesc(bindingResult.getFieldError().getField())));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(admin.getId())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(admin.getMobile())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(admin.getName())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ Admin a = adminService.selectByMobile(admin.getMobile().trim());
|
|
|
+ if (!TokenManager.getAdminId().equals(a.getId())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ Admin ad = new Admin();
|
|
|
+ BeanUtils.copyProperties(admin, ad);
|
|
|
+ Admin aa = adminService.selectByPrimaryKey(TokenManager.getAdminId());
|
|
|
+ ad.setMobile(ad.getMobile().trim());
|
|
|
+ ad.setCreateTime(aa.getCreateTime());
|
|
|
+ if (StringUtils.isNotBlank(ad.getPassword())) {
|
|
|
+ if (StringUtils.isBlank(pwd)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "原密码"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (!aa.getPassword().equals(passwordUtil.getEncryptPwd(pwd, aa.getCreateTime()))) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR, "", "原密码"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ ad.setPassword(passwordUtil.getEncryptPwd(ad));
|
|
|
+ } else {
|
|
|
+ ad.setPassword(aa.getPassword());
|
|
|
+ }
|
|
|
+ res.setData(adminService.updateByPrimaryKey(ad));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 测试发送消息
|