|
|
@@ -6,11 +6,9 @@ import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.validation.Valid;
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
@@ -19,14 +17,12 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.goafanti.admin.bo.AdminLocationBo;
|
|
|
-import com.goafanti.admin.bo.InputAdmin;
|
|
|
import com.goafanti.admin.service.AdminLocationService;
|
|
|
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.CertifyApiController;
|
|
|
-import com.goafanti.common.enums.AdminFields;
|
|
|
import com.goafanti.common.model.Admin;
|
|
|
import com.goafanti.common.model.AdminLocation;
|
|
|
import com.goafanti.common.utils.PasswordUtil;
|
|
|
@@ -36,19 +32,19 @@ import com.goafanti.common.utils.StringUtils;
|
|
|
@RequestMapping(value = "/api/admin/supervise")
|
|
|
public class AdminSuperviseApiController extends CertifyApiController {
|
|
|
@Resource
|
|
|
- private AdminService adminService;
|
|
|
+ private AdminService adminService;
|
|
|
@Resource(name = "passwordUtil")
|
|
|
- private PasswordUtil passwordUtil;
|
|
|
+ private PasswordUtil passwordUtil;
|
|
|
@Resource
|
|
|
- private AdminLocationService adminLocationService;
|
|
|
-
|
|
|
+ private AdminLocationService adminLocationService;
|
|
|
+
|
|
|
/**
|
|
|
* 管理员详情获取地区
|
|
|
*/
|
|
|
@RequestMapping(value = "/adminDetailLocation", method = RequestMethod.GET)
|
|
|
- public Result adminDetailLocation(String id){
|
|
|
+ public Result adminDetailLocation(String id) {
|
|
|
Result res = new Result();
|
|
|
- if (StringUtils.isBlank(id)){
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户ID", "用户ID"));
|
|
|
return res;
|
|
|
}
|
|
|
@@ -88,6 +84,7 @@ public class AdminSuperviseApiController extends CertifyApiController {
|
|
|
/**
|
|
|
* 新增管理员
|
|
|
*/
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
@RequestMapping(value = "/insertAdmin", method = RequestMethod.POST)
|
|
|
public Result insertAdmin(String data) {
|
|
|
Result res = new Result();
|
|
|
@@ -114,50 +111,13 @@ public class AdminSuperviseApiController extends CertifyApiController {
|
|
|
Admin ad = new Admin();
|
|
|
BeanUtils.copyProperties(admin, ad);
|
|
|
ad.setId(UUID.randomUUID().toString());
|
|
|
- JSONArray locations = jo.getJSONArray("locations");
|
|
|
- List<AdminLocation> adminLocationList = new ArrayList<>();
|
|
|
- AdminLocation al = null;
|
|
|
- for (int i = 0; i < locations.size(); i++) {
|
|
|
- AdminLocationBo alb = locations.getJSONObject(i).toJavaObject(AdminLocationBo.class);
|
|
|
- Integer province = alb.getProvince();
|
|
|
- String city = alb.getCity();
|
|
|
- if (null == province) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "省份为空", "所在省份"));
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- if (province.intValue() > AFTConstants.PROVINCEMAXNUM) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在省份"));
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- if (!StringUtils.isBlank(city)) {
|
|
|
- String[] arr = city.trim().split(",|,");
|
|
|
- if (null != arr && arr.length > 0) {
|
|
|
- for (String s : arr) {
|
|
|
- Integer c = Integer.valueOf(s);
|
|
|
- if (c.intValue() > AFTConstants.CITYMAXNUM) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在市"));
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
- al = new AdminLocation();
|
|
|
- al.setId(UUID.randomUUID().toString());
|
|
|
- al.setAdminId(ad.getId());
|
|
|
- al.setProvince(province);
|
|
|
- al.setCity(c);
|
|
|
- adminLocationList.add(al);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- al = new AdminLocation();
|
|
|
- al.setId(UUID.randomUUID().toString());
|
|
|
- al.setAdminId(ad.getId());
|
|
|
- al.setProvince(province);
|
|
|
- adminLocationList.add(al);
|
|
|
- }
|
|
|
+ res = disposeAdminLocationList(res, jo, ad);
|
|
|
+ if (!res.getError().isEmpty()) {
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
+ List<AdminLocation> adminLocationList = (List<AdminLocation>) res.getData();
|
|
|
+
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
now.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
|
@@ -176,51 +136,49 @@ public class AdminSuperviseApiController extends CertifyApiController {
|
|
|
* 修改管理员信息
|
|
|
*/
|
|
|
@RequestMapping(value = "/updateAdmin", method = RequestMethod.POST)
|
|
|
- public Result updateAdmin(@RequestParam(value = "roles[]", required = false) String[] roleIds,
|
|
|
- @Valid InputAdmin admin, BindingResult bindingResult) {
|
|
|
+ public Result updateAdmin(@RequestParam(value = "roles[]", required = false) String[] roleIds, String data) {
|
|
|
Result res = new Result();
|
|
|
- if (bindingResult.hasErrors()) {
|
|
|
- res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
|
|
|
- AdminFields.getFieldDesc(bindingResult.getFieldError().getField())));
|
|
|
- return res;
|
|
|
- }
|
|
|
+ JSONObject jo = (JSONObject) JSON.parse(data);
|
|
|
+ if (null != jo) {
|
|
|
+ Admin admin = jo.toJavaObject(Admin.class);
|
|
|
|
|
|
- if (null == admin.getId()) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
- return res;
|
|
|
- }
|
|
|
+ if (null == admin.getId()) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
- if (null == admin.getMobile()) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
|
|
|
- return res;
|
|
|
- }
|
|
|
+ if (null == admin.getMobile()) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
- if (null == admin.getName()) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
|
|
|
- return res;
|
|
|
- }
|
|
|
+ if (null == admin.getName()) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
- Admin aa = adminService.selectByMobile(admin.getMobile().trim());
|
|
|
- if (null != aa && !admin.getId().equals(aa.getId())) {
|
|
|
- res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
|
|
|
- return res;
|
|
|
- }
|
|
|
+ Admin aa = adminService.selectByMobile(admin.getMobile().trim());
|
|
|
+ if (null != aa && !admin.getId().equals(aa.getId())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
|
|
|
- Admin a = adminService.selectByPrimaryKey(admin.getId());
|
|
|
+ Admin a = adminService.selectByPrimaryKey(admin.getId());
|
|
|
|
|
|
- if (null == a) {
|
|
|
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
- return res;
|
|
|
- }
|
|
|
- Admin ad = new Admin();
|
|
|
- BeanUtils.copyProperties(admin, ad);
|
|
|
- List<String> roles = new ArrayList<String>();
|
|
|
- if (roleIds != null && roleIds.length > 0) {
|
|
|
- for (String role : roleIds) {
|
|
|
- roles.add(role);
|
|
|
+ if (null == a) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
}
|
|
|
+ Admin ad = new Admin();
|
|
|
+ BeanUtils.copyProperties(admin, ad);
|
|
|
+ List<String> roles = new ArrayList<String>();
|
|
|
+ if (roleIds != null && roleIds.length > 0) {
|
|
|
+ for (String role : roleIds) {
|
|
|
+ roles.add(role);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setData(adminService.updateByPrimaryKeySelective(ad, roles));
|
|
|
}
|
|
|
- res.setData(adminService.updateByPrimaryKeySelective(ad, roles));
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
@@ -243,9 +201,58 @@ public class AdminSuperviseApiController extends CertifyApiController {
|
|
|
Admin a = new Admin();
|
|
|
a.setId(admin.getId());
|
|
|
a.setCreateTime(admin.getCreateTime());
|
|
|
- a.setPassword("123456");
|
|
|
+ a.setPassword(AFTConstants.INITIALPASSWORD);
|
|
|
a.setPassword(passwordUtil.getEncryptPwd(a));
|
|
|
res.setData(adminService.updateByPrimaryKey(a));
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ private Result disposeAdminLocationList(Result res, JSONObject jo, Admin ad) {
|
|
|
+ JSONArray locations = jo.getJSONArray("locations");
|
|
|
+ List<AdminLocation> adminLocationList = new ArrayList<>();
|
|
|
+ AdminLocation al = null;
|
|
|
+ for (int i = 0; i < locations.size(); i++) {
|
|
|
+ AdminLocationBo alb = locations.getJSONObject(i).toJavaObject(AdminLocationBo.class);
|
|
|
+ Integer province = alb.getProvince();
|
|
|
+ String city = alb.getCity();
|
|
|
+ if (null == province) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "省份为空", "所在省份"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (province.intValue() > AFTConstants.PROVINCEMAXNUM) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在省份"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isBlank(city)) {
|
|
|
+ String[] arr = city.trim().split(",|,");
|
|
|
+ if (null != arr && arr.length > 0) {
|
|
|
+ for (String s : arr) {
|
|
|
+ Integer c = Integer.valueOf(s);
|
|
|
+ if (c.intValue() > AFTConstants.CITYMAXNUM) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在市"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ adminLocationList.add(disposeAdminLocation(al, ad, province, c));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ adminLocationList.add(disposeAdminLocation(al, ad, province, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setData(adminLocationList);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AdminLocation disposeAdminLocation(AdminLocation al, Admin ad, Integer province, Integer c) {
|
|
|
+ al = new AdminLocation();
|
|
|
+ al.setId(UUID.randomUUID().toString());
|
|
|
+ al.setAdminId(ad.getId());
|
|
|
+ al.setProvince(province);
|
|
|
+ if (null != c) {
|
|
|
+ al.setCity(c);
|
|
|
+ }
|
|
|
+ return al;
|
|
|
+ }
|
|
|
}
|