|
|
@@ -1,23 +1,39 @@
|
|
|
package com.goafanti.admin.controller;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.goafanti.admin.bo.AdminListBo;
|
|
|
+import com.goafanti.admin.bo.AdminLocationBo;
|
|
|
import com.goafanti.admin.service.AdminLocationService;
|
|
|
-import com.goafanti.admin.service.AdminService;
|
|
|
import com.goafanti.admin.service.NewAdminService;
|
|
|
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.model.Admin;
|
|
|
+import com.goafanti.common.model.AdminLocation;
|
|
|
import com.goafanti.common.utils.PasswordUtil;
|
|
|
import com.goafanti.common.utils.StringUtils;
|
|
|
+import com.goafanti.core.shiro.token.TokenManager;
|
|
|
import com.goafanti.user.service.UserService;
|
|
|
|
|
|
@Controller
|
|
|
-@RequestMapping(value = "open/api/admin/superviser")
|
|
|
+@RequestMapping(value = "api/admin/superviser")
|
|
|
public class AdminSuperviserApiController extends CertifyApiController {
|
|
|
@Resource
|
|
|
private NewAdminService newAdminService;
|
|
|
@@ -44,4 +60,246 @@ public class AdminSuperviserApiController extends CertifyApiController {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增管理员
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/insertAdmin", method = RequestMethod.POST)
|
|
|
+ public Result insertAdmin(@RequestParam(value = "roles[]", required = false) String[] roleIds, String data) {
|
|
|
+ Result res = new Result();
|
|
|
+ JSONObject jo = (JSONObject) JSON.parse(data);
|
|
|
+ if (null != jo) {
|
|
|
+ Admin admin = jo.toJavaObject(Admin.class);
|
|
|
+
|
|
|
+ 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 = newAdminService.selectByMobile(admin.getMobile().trim());
|
|
|
+ if (null != a) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin ad = new Admin();
|
|
|
+ BeanUtils.copyProperties(admin, ad);
|
|
|
+ /*ad.setId(UUID.randomUUID().toString());*/
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ now.set(Calendar.MILLISECOND, 0);
|
|
|
+
|
|
|
+ ad.setCreateTime(now.getTime());
|
|
|
+ if (StringUtils.isBlank(ad.getPassword())) {
|
|
|
+ ad.setPassword(AFTConstants.INITIALPASSWORD);
|
|
|
+ }
|
|
|
+ ad.setPassword(passwordUtil.getEncryptPwd(ad));
|
|
|
+ List<String> roles = new ArrayList<String>();
|
|
|
+ if (roleIds != null && roleIds.length > 0) {
|
|
|
+ for (String role : roleIds) {
|
|
|
+ roles.add(role);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setData(newAdminService.insertNewAdmin(ad,roles));
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改管理员信息
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/updateAdmin", method = RequestMethod.POST)
|
|
|
+ public Result updateAdmin(@RequestParam(value = "roles[]", required = false) String[] roleIds, String data) {
|
|
|
+ Result res = new Result();
|
|
|
+ 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.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;
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin aa = newAdminService.selectByMobile(admin.getMobile().trim());
|
|
|
+ if (null != aa && !admin.getId().equals(aa.getId())) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin a = newAdminService.selectByPrimaryKey(admin.getId());
|
|
|
+ if (null == a) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
+
|
|
|
+ }
|
|
|
+ Admin ad = new Admin();
|
|
|
+ BeanUtils.copyProperties(admin, ad);
|
|
|
+ res = disposeAdminLocationList(res, jo, ad);
|
|
|
+ if (!res.getError().isEmpty()) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> roles = new ArrayList<String>();
|
|
|
+ if (roleIds != null && roleIds.length > 0) {
|
|
|
+ for (String role : roleIds) {
|
|
|
+ roles.add(role);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.setData(newAdminService.updateByPrimaryKeySelective(ad, roles));
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置管理员密码
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
|
|
|
+ public Result resetPwd(String id) {
|
|
|
+ Result res = new Result();
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = newAdminService.selectByPrimaryKey(id);
|
|
|
+ if (null == admin) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ Admin a = new Admin();
|
|
|
+ a.setId(admin.getId());
|
|
|
+ a.setCreateTime(admin.getCreateTime());
|
|
|
+ a.setPassword(AFTConstants.INITIALPASSWORD);
|
|
|
+ a.setPassword(passwordUtil.getEncryptPwd(a));
|
|
|
+ res.setData(newAdminService.updateByPrimaryKey(a));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result disposeAdminLocationList(Result res, JSONObject jo, Admin ad) {
|
|
|
+ JSONArray locations = jo.getJSONArray("locations");
|
|
|
+ if (null == locations || locations.size()<1){
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ List<AdminLocation> adminLocationList = new ArrayList<>();
|
|
|
+ AdminLocation al = null;
|
|
|
+ Boolean areaAdminFlag = false;
|
|
|
+ List<Integer> locationList = null;
|
|
|
+ if (TokenManager.hasRole(AFTConstants.AREAADMIN)) {
|
|
|
+ locationList = new ArrayList<>();
|
|
|
+ areaAdminFlag = true;
|
|
|
+ }
|
|
|
+ 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 (areaAdminFlag) {
|
|
|
+ locationList.add(province);
|
|
|
+ }
|
|
|
+ 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));
|
|
|
+ if (areaAdminFlag) {
|
|
|
+ locationList.add(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ adminLocationList.add(disposeAdminLocation(al, ad, province, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (areaAdminFlag) {
|
|
|
+ List<Integer> albList = disposeAdminLocationBo();
|
|
|
+ if (!albList.containsAll(locationList)) {
|
|
|
+ res.getError().add(buildError("", "所选所在地区域不在负责区域,无法添加或修改"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> disposeAdminLocationBo() {
|
|
|
+ List<AdminLocationBo> alb = adminLocationService.findLocation(TokenManager.getAdminId());
|
|
|
+ List<Integer> albList = null;
|
|
|
+ if (!alb.isEmpty()) {
|
|
|
+ Integer albProvince = null;
|
|
|
+ albList = new ArrayList<>();
|
|
|
+ for (AdminLocationBo bo : alb) {
|
|
|
+ albProvince = bo.getProvince();
|
|
|
+ albList.add(albProvince);
|
|
|
+ if (!StringUtils.isBlank(bo.getCity())) {
|
|
|
+ String[] albArr = bo.getCity().trim().split(",|,");
|
|
|
+ if (null != albArr && albArr.length > 0) {
|
|
|
+ for (String ss : albArr) {
|
|
|
+ albList.add(Integer.valueOf(ss));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return albList;
|
|
|
+ }
|
|
|
+ /** 图片上传 **/
|
|
|
+ @RequestMapping(value = "/uploadAdminImg", method = RequestMethod.POST)
|
|
|
+ public Result uploadCustomerImg(HttpServletRequest req,String sign){
|
|
|
+ Result res = new Result();
|
|
|
+ res.setData(handleFile(res, "/customer_sys_file/", false, req, sign));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**新增获取ID**/
|
|
|
+ @RequestMapping(value = "/newId", method = RequestMethod.POST)
|
|
|
+ public Result newId(){
|
|
|
+ Result res = new Result();
|
|
|
+ res.setData(UUID.randomUUID().toString());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**编辑页面信息获取**/
|
|
|
+ @RequestMapping(value = "/selectAllByid", method = RequestMethod.POST)
|
|
|
+ public Result selectAllByid(String id){
|
|
|
+ Result res = new Result();
|
|
|
+ res.setData(newAdminService.selectAllByid(id));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|