Commit 3c413d6a authored by “yiyousong”'s avatar “yiyousong”
parents bfc87ebc fac44ef5
...@@ -411,6 +411,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -411,6 +411,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
item.setCreateUserId(1L); item.setCreateUserId(1L);
item.setCreateUserName("系统管理员"); item.setCreateUserName("系统管理员");
item.setCreateTime(new Date()); item.setCreateTime(new Date());
item.setId(item.getId());
return item; return item;
} else { } else {
//更新用户列表 //更新用户列表
...@@ -421,7 +422,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -421,7 +422,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
return item; return item;
} }
}).collect(Collectors.toList()); }).collect(Collectors.toList());
Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null)); Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getUpdateUserId() == null));
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) { if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
//需要新增的用户 //需要新增的用户
log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size()); log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
......
...@@ -6,14 +6,18 @@ import com.alibaba.fastjson.JSONArray; ...@@ -6,14 +6,18 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.IAuthTokenService; import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.valid.service.ValidCodeService; import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.SitePdu; import com.mortals.xhx.common.pdu.SitePdu;
import com.mortals.xhx.common.utils.LoginAESUtil; import com.mortals.xhx.common.utils.LoginAESUtil;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import com.mortals.xhx.feign.model.IApiModelFeign; import com.mortals.xhx.feign.model.IApiModelFeign;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.menu.model.MenuEntity; import com.mortals.xhx.module.menu.model.MenuEntity;
...@@ -22,6 +26,7 @@ import com.mortals.xhx.module.user.model.UserEntity; ...@@ -22,6 +26,7 @@ import com.mortals.xhx.module.user.model.UserEntity;
import com.mortals.xhx.module.user.service.UserService; import com.mortals.xhx.module.user.service.UserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -43,6 +48,10 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -43,6 +48,10 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
private IApiModelFeign apiModelFeign; private IApiModelFeign apiModelFeign;
@Autowired @Autowired
private ValidCodeService validCodeService; private ValidCodeService validCodeService;
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
private static final String AES_KEY = "0000000671595991"; private static final String AES_KEY = "0000000671595991";
private static final String AES_IV = "tdrdadq59tbss5n7"; private static final String AES_IV = "tdrdadq59tbss5n7";
...@@ -59,15 +68,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -59,15 +68,15 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
ret.put(KEY_RESULT_MSG, "未获取到用户信息,请重新登录"); ret.put(KEY_RESULT_MSG, "未获取到用户信息,请重新登录");
return ret.toJSONString(); return ret.toJSONString();
} }
if(loginForm.getType()!=null&&loginForm.getType()==2){ if (loginForm.getType() != null && loginForm.getType() == 2) {
loginName = LoginAESUtil.decrypt(loginName,AES_KEY,AES_IV,LoginAESUtil.AES_CBC); loginName = LoginAESUtil.decrypt(loginName, AES_KEY, AES_IV, LoginAESUtil.AES_CBC);
password = LoginAESUtil.decrypt(password,AES_KEY,AES_IV,LoginAESUtil.AES_CBC); password = LoginAESUtil.decrypt(password, AES_KEY, AES_IV, LoginAESUtil.AES_CBC);
} }
UserEntity userEntity = null; UserEntity userEntity = null;
try { try {
loginForm.validate(); loginForm.validate();
boolean validCode = validCodeService.doCheckImageValidCode(loginForm.getMark(),super.getRequestIP(request),loginForm.getSecurityCode()); boolean validCode = validCodeService.doCheckImageValidCode(loginForm.getMark(), super.getRequestIP(request), loginForm.getSecurityCode());
if(!validCode){ if (!validCode) {
throw new AppException("验证码错误"); throw new AppException("验证码错误");
} }
userEntity = userService.userdoLogin(loginName, password, ip); userEntity = userService.userdoLogin(loginName, password, ip);
...@@ -82,15 +91,23 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -82,15 +91,23 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity); List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity);
userEntity.setMenuList(menuList); userEntity.setMenuList(menuList);
data.put("user", userEntity); data.put("user", userEntity);
if(userEntity.getId()==1 && StringUtils.isEmpty(userEntity.getAreaCodes())){ Set<String> urls = new HashSet<>();
String menuUrl = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrl)) {
urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrl = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrl);
}
data.put("urls", urls);
if (userEntity.getId() == 1 && StringUtils.isEmpty(userEntity.getAreaCodes())) {
JSONArray siteList = new JSONArray(); JSONArray siteList = new JSONArray();
JSONObject siteObject = new JSONObject(); JSONObject siteObject = new JSONObject();
siteObject.put("id",0); siteObject.put("id", 0);
siteObject.put("siteName","无站点"); siteObject.put("siteName", "无站点");
siteList.add(siteObject); siteList.add(siteObject);
data.put("siteList", siteList); data.put("siteList", siteList);
}else { } else {
if(StringUtils.isNotEmpty(userEntity.getAreaCodes())){ if (StringUtils.isNotEmpty(userEntity.getAreaCodes())) {
SitePdu sitePdu = new SitePdu(); SitePdu sitePdu = new SitePdu();
List<String> areaCodeList = Arrays.asList(userEntity.getAreaCodes().split(",")); List<String> areaCodeList = Arrays.asList(userEntity.getAreaCodes().split(","));
sitePdu.setAreaCodeList(areaCodeList); sitePdu.setAreaCodeList(areaCodeList);
...@@ -99,12 +116,12 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -99,12 +116,12 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
if (apiResp.getCode() != YesNoEnum.YES.getValue()) { if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取用户站点列表树数据失败:" + apiResp.getMsg()); throw new AppException("获取用户站点列表树数据失败:" + apiResp.getMsg());
} }
if(apiResp.getData().get("data")!=null) { if (apiResp.getData().get("data") != null) {
data.put("siteList", apiResp.getData().get("data")); data.put("siteList", apiResp.getData().get("data"));
}else { } else {
data.put("siteList", Collections.emptyList()); data.put("siteList", Collections.emptyList());
} }
}else { } else {
data.put("siteList", Collections.emptyList()); data.put("siteList", Collections.emptyList());
} }
} }
...@@ -120,9 +137,9 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -120,9 +137,9 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
return ret.toJSONString(); return ret.toJSONString();
} catch (Exception e) { } catch (Exception e) {
log.error("login error ", e); log.error("login error ", e);
if(e instanceof AppException){ if (e instanceof AppException) {
ret.put(KEY_RESULT_CODE, ((AppException) e).getCode()); ret.put(KEY_RESULT_CODE, ((AppException) e).getCode());
}else { } else {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE); ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
} }
ret.put(KEY_RESULT_MSG, super.convertException(e)); ret.put(KEY_RESULT_MSG, super.convertException(e));
...@@ -143,6 +160,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -143,6 +160,7 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
@RequestMapping("index") @RequestMapping("index")
public String index() throws Exception { public String index() throws Exception {
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
JSONObject data = new JSONObject();
IUser user = this.getCurUser(); IUser user = this.getCurUser();
if (user == null) { if (user == null) {
return ""; return "";
...@@ -150,7 +168,14 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -150,7 +168,14 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
UserEntity userEntity = userService.get(user.getId()); UserEntity userEntity = userService.get(user.getId());
List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity); List<MenuEntity> menuList = menuService.findTreeMenuByUser(userEntity);
userEntity.setMenuList(menuList); userEntity.setMenuList(menuList);
JSONObject data = new JSONObject(); Set<String> urls = new HashSet<>();
String menuUrl = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrl)) {
urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrl = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrl);
}
data.put("urls", urls);
data.put("user", userEntity); data.put("user", userEntity);
ret.put(KEY_RESULT_DATA, data); ret.put(KEY_RESULT_DATA, data);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS); ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
......
...@@ -71,7 +71,14 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re ...@@ -71,7 +71,14 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
@Override @Override
public Set<String> findUrlSetByUserId(Long userId) throws AppException { public Set<String> findUrlSetByUserId(Long userId) throws AppException {
Set<String> urls = new HashSet<>(); Set<String> urls = new HashSet<>();
List<ResourceEntity> resList = this.findListByUserId(userId); List<ResourceEntity> resList = new ArrayList<>();
if (1L == userId) {
//管理员
resList = this.find(new ResourceQuery());
} else {
resList = this.findListByUserId(userId);
}
for (ResourceEntity res : resList) { for (ResourceEntity res : resList) {
String url = res.getUrl(); String url = res.getUrl();
if (StringUtils.isEmpty(url)) { if (StringUtils.isEmpty(url)) {
...@@ -92,7 +99,7 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re ...@@ -92,7 +99,7 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
public Rest<String> refreshResourceUrl(String packageName, Context context) { public Rest<String> refreshResourceUrl(String packageName, Context context) {
List<Class<?>> classList = ControllerScanUtil.getAllClassByPackageName(packageName); List<Class<?>> classList = ControllerScanUtil.getAllClassByPackageName(packageName);
//System.out.println(classList); //获取到了所有的类 //System.out.println(classList); //获取到了所有的类
List<ResourceEntity> newResourcelist = ControllerScanUtil.getAnnotationInfo(classList).stream().filter(f->!ObjectUtils.isEmpty(f.getUrl())).collect(Collectors.toList()); List<ResourceEntity> newResourcelist = ControllerScanUtil.getAnnotationInfo(classList).stream().filter(f -> !ObjectUtils.isEmpty(f.getUrl())).collect(Collectors.toList());
Map<String, List<ResourceEntity>> localResourceMap = this.find(new ResourceQuery()).stream().collect(Collectors.groupingBy(x -> x.getName())); Map<String, List<ResourceEntity>> localResourceMap = this.find(new ResourceQuery()).stream().collect(Collectors.groupingBy(x -> x.getName()));
Map<String, List<ResourceEntity>> newResourceMap = newResourcelist.stream().collect(Collectors.groupingBy(x -> x.getName())); Map<String, List<ResourceEntity>> newResourceMap = newResourcelist.stream().collect(Collectors.groupingBy(x -> x.getName()));
......
...@@ -105,11 +105,10 @@ public class ControllerScanUtil { ...@@ -105,11 +105,10 @@ public class ControllerScanUtil {
Method[] methods = cls.getDeclaredMethods(); Method[] methods = cls.getDeclaredMethods();
if (methods != null && methods.length > 0) { if (methods != null && methods.length > 0) {
for (Method method : methods) { for (Method method : methods) {
boolean unAuth = method.isAnnotationPresent(UnAuth.class); // boolean unAuth = method.isAnnotationPresent(UnAuth.class);
if (unAuth) { // if (unAuth) {
continue; // continue;
} // }
boolean mExits = method.isAnnotationPresent(RequestMapping.class); boolean mExits = method.isAnnotationPresent(RequestMapping.class);
if (mExits) { if (mExits) {
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class); RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
...@@ -140,10 +139,10 @@ public class ControllerScanUtil { ...@@ -140,10 +139,10 @@ public class ControllerScanUtil {
Method[] superMethods = cls.getSuperclass().getDeclaredMethods(); Method[] superMethods = cls.getSuperclass().getDeclaredMethods();
if (superMethods != null && superMethods.length > 0) { if (superMethods != null && superMethods.length > 0) {
for (Method method : superMethods) { for (Method method : superMethods) {
boolean unAuth = method.isAnnotationPresent(UnAuth.class); /* boolean unAuth = method.isAnnotationPresent(UnAuth.class);
if (unAuth) { if (unAuth) {
continue; continue;
} }*/
boolean mExits = method.isAnnotationPresent(RequestMapping.class); boolean mExits = method.isAnnotationPresent(RequestMapping.class);
if (mExits) { if (mExits) {
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class); RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment