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