Commit 200f3b84 authored by 廖旭伟's avatar 廖旭伟

用户登录时根据授权区域查询站点列表;用户授权区域站点同步

parent 5e25a4c8
...@@ -17,6 +17,7 @@ import com.mortals.xhx.module.site.model.SiteQuery; ...@@ -17,6 +17,7 @@ import com.mortals.xhx.module.site.model.SiteQuery;
import com.mortals.xhx.module.site.model.SiteTreeSelect; import com.mortals.xhx.module.site.model.SiteTreeSelect;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -187,8 +188,15 @@ public class SiteController extends BaseCRUDJsonBodyMappingController<SiteServic ...@@ -187,8 +188,15 @@ public class SiteController extends BaseCRUDJsonBodyMappingController<SiteServic
String busiDesc = "查询" + this.getModuleDesc(); String busiDesc = "查询" + this.getModuleDesc();
int code=1; int code=1;
try { try {
List<SiteEntity> result = this.getService().find(query, context); if(CollectionUtils.isNotEmpty(query.getAreaCodeList())){
model.put("data", result); List<SiteEntity> siteEntityList= query.getAreaCodeList().stream().flatMap(areaId ->
this.service.getFlatSitesByAreaCode(areaId, getContext()).stream()
).distinct().collect(Collectors.toList());
model.put("data", siteEntityList);
}else {
List<SiteEntity> result = this.getService().find(query, context);
model.put("data", result);
}
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception var9) { } catch (Exception var9) {
......
...@@ -25,10 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -25,10 +25,7 @@ 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;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController @RestController
@Slf4j @Slf4j
...@@ -71,14 +68,10 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -71,14 +68,10 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
String token = authTokenService.createToken(userEntity); String token = authTokenService.createToken(userEntity);
data.put("token", token); data.put("token", token);
data.put("user", userEntity); data.put("user", userEntity);
if(StringUtils.isNotEmpty(userEntity.getSiteIds())){ if(StringUtils.isNotEmpty(userEntity.getAreaCodes())){
SitePdu sitePdu = new SitePdu(); SitePdu sitePdu = new SitePdu();
List<Long> siteIdList = new ArrayList<>(); List<String> areaCodeList = Arrays.asList(userEntity.getAreaCodes().split(","));
for(String idStr:userEntity.getSiteIds().split(",")){ sitePdu.setAreaCodeList(areaCodeList);
siteIdList.add(DataUtil.converStr2Long(idStr,0));
}
sitePdu.setIdList(siteIdList);
sitePdu.setSize(-1);
String resp = apiModelFeign.getSitesByQuery(sitePdu); String resp = apiModelFeign.getSitesByQuery(sitePdu);
ApiResp<JSONObject> apiResp = JSON.parseObject(resp, ApiResp.class); ApiResp<JSONObject> apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) { if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
......
...@@ -58,7 +58,6 @@ public class UserEntity extends UserVo implements IUser { ...@@ -58,7 +58,6 @@ public class UserEntity extends UserVo implements IUser {
/** /**
* 用户类型(0.系统用户,1.普通用户,2.工作人员) * 用户类型(0.系统用户,1.普通用户,2.工作人员)
*/ */
@JSONField(serialize = false)
private Integer userType; private Integer userType;
/** /**
* 所属站点id,多个逗号分隔 * 所属站点id,多个逗号分隔
...@@ -224,6 +223,7 @@ public class UserEntity extends UserVo implements IUser { ...@@ -224,6 +223,7 @@ public class UserEntity extends UserVo implements IUser {
* 获取 用户类型(0.系统用户,1.普通用户,2.工作人员) * 获取 用户类型(0.系统用户,1.普通用户,2.工作人员)
* @return Integer * @return Integer
*/ */
@Override
public Integer getUserType(){ public Integer getUserType(){
return userType; return userType;
} }
......
...@@ -68,4 +68,10 @@ public interface UserService extends ICRUDService<UserEntity,Long>{ ...@@ -68,4 +68,10 @@ public interface UserService extends ICRUDService<UserEntity,Long>{
void siteAuth(UserEntityExt entityExt,Context context); void siteAuth(UserEntityExt entityExt,Context context);
/**
* 同步用户站点授权
* @throws AppException
*/
void synchSitesAuth() throws AppException;
} }
\ No newline at end of file
...@@ -250,4 +250,25 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity ...@@ -250,4 +250,25 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
protected void updateAfter(UserEntity entity, Context context) throws AppException { protected void updateAfter(UserEntity entity, Context context) throws AppException {
super.updateAfter(entity, context); super.updateAfter(entity, context);
} }
@Override
public void synchSitesAuth() throws AppException {
UserEntity query = new UserEntity();
List<UserEntity> all = this.find(query);
all.forEach(item->{
if(StringUtils.isNotEmpty(item.getAreaCodes())){
List<String> areaCodeList = Arrays.asList(item.getAreaCodes().split(","));
String resp = areaService.getFlatSitesByAreaCodes(new AreaQuery().areaCodeList(areaCodeList), null);
JSONObject apiResp = JSON.parseObject(resp);
if (apiResp.getInteger("code") != YesNoEnum.YES.getValue()) {
throw new AppException("获取用户站点列表树数据失败:" + apiResp.getString("msg"));
}
String siteIds = apiResp.getString("data");
UserEntity userEntity = new UserEntity();
userEntity.setId(item.getId());
userEntity.setSiteIds(siteIds);
this.dao.update(userEntity);
}
});
}
} }
\ No newline at end of file
...@@ -218,4 +218,22 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic ...@@ -218,4 +218,22 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
return Rest.fail("获取token异常!"); return Rest.fail("获取token异常!");
} }
} }
/**
* 同步用户授权站点信息
*
* @return
*/
@PostMapping(value = "synchSiteAuth")
@UnAuth
public Rest<String> synchSitesAuth() {
try {
this.service.synchSitesAuth();
return Rest.ok("同步用户站点授权成功!");
} catch (Exception e) {
log.error("同步用户站点授权错误", e);
return Rest.fail("同步用户站点授权异常!");
}
}
} }
\ No newline at end of file
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