Commit 40a774c2 by 徐高华

好办小程序权限

parent 2c052dd4
...@@ -34,5 +34,7 @@ public interface HaobanCommonMQApiService { ...@@ -34,5 +34,7 @@ public interface HaobanCommonMQApiService {
public void memberEventDel(String params) ; public void memberEventDel(String params) ;
// 会员扫码关注 // 会员扫码关注
public void memberEventWechat(String params) ; public void memberEventWechat(String params) ;
// 服务开通事件
public void serviceOpenOffEvent(String params) ;
} }
...@@ -8,6 +8,7 @@ import com.gic.haoban.manage.service.service.StaffClerkRelationService; ...@@ -8,6 +8,7 @@ import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.commons.util.StringUtil; import com.gic.commons.util.StringUtil;
import com.gic.haoban.manage.api.dto.MemberUnionidWechatAccountQDTO; import com.gic.haoban.manage.api.dto.MemberUnionidWechatAccountQDTO;
import com.gic.haoban.manage.api.service.ExternalClerkRelatedApiService; import com.gic.haoban.manage.api.service.ExternalClerkRelatedApiService;
import com.gic.haoban.manage.service.service.role.HaobanMenuService;
import com.gic.haoban.manage.service.util.EventUtils; import com.gic.haoban.manage.service.util.EventUtils;
import com.gic.member.api.dto.MemberInfoChangeNotifyDTO; import com.gic.member.api.dto.MemberInfoChangeNotifyDTO;
import com.gic.member.api.dto.event.wechat.WeChatOfficialAccountEventParam; import com.gic.member.api.dto.event.wechat.WeChatOfficialAccountEventParam;
...@@ -48,6 +49,8 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService { ...@@ -48,6 +49,8 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService {
private ExternalClerkRelatedApiService externalClerkRelatedApiService ; private ExternalClerkRelatedApiService externalClerkRelatedApiService ;
@Autowired @Autowired
private StaffClerkRelationService staffClerkRelationService ; private StaffClerkRelationService staffClerkRelationService ;
@Autowired
private HaobanMenuService haobanMenuService ;
@Override @Override
public void putCommonMessage(CommonMQDTO dto) { public void putCommonMessage(CommonMQDTO dto) {
...@@ -235,4 +238,9 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService { ...@@ -235,4 +238,9 @@ public class HaobanCommonMQApiServiceImpl implements HaobanCommonMQApiService {
log.error("通知好办失败", e); log.error("通知好办失败", e);
} }
} }
@Override
public void serviceOpenOffEvent(String params) {
this.haobanMenuService.saveMenuFromGicEvent(params);
}
} }
...@@ -243,42 +243,80 @@ public class HaobanRoleApiServiceImpl implements HaobanRoleApiService { ...@@ -243,42 +243,80 @@ public class HaobanRoleApiServiceImpl implements HaobanRoleApiService {
@Override @Override
public ServiceResponse<HaobanRoleDTO> getMenuByWxEnterpriseIdAndClerkType(String wxEnterpriseId, Integer clerkType, Integer systemFlag, String enterpriseId) { public ServiceResponse<HaobanRoleDTO> getMenuByWxEnterpriseIdAndClerkType(String wxEnterpriseId, Integer clerkType, Integer systemFlag, String enterpriseId) {
HaobanRoleBO haobanRoleBO = haobanRoleService.getByWxEnterpriseIdAndClerkType(wxEnterpriseId, clerkType, systemFlag); logger.info("查询好办小程序权限={},{},{},{}",systemFlag,wxEnterpriseId,clerkType,enterpriseId);
if (haobanRoleBO != null) { // 查询商户普通权限是,需要过滤超管没有的
List<String> menuCodes = haobanRoleMenuService.getByWxEnterpriseIdAndRoleId(wxEnterpriseId, haobanRoleBO.getRoleId()); HaobanRoleBO superRoleBO = haobanRoleService.getByWxEnterpriseIdAndClerkType(wxEnterpriseId, clerkType, 0);
List<HaobanMenuBO> allMenuList = haobanMenuService.getAllMenuList(); if(null == superRoleBO) {
// 添加关联的权限 return ServiceResponse.failure("9999","未配置运维权限") ;
List<HaobanMenuBO> haobanMenuList = new ArrayList<>() ; }
for(HaobanMenuBO item : allMenuList) { List<HaobanMenuBO> allMenuList = haobanMenuService.getAllMenuList();
String code = item.getMenuCode() ; Long superRoleId = superRoleBO.getRoleId() ;
// 开启的权限 List<String> superMenuCodeList = this.listRoleMenuCode(allMenuList,wxEnterpriseId, superRoleId);
if(menuCodes.contains(code)) { // 查询gic配置的权限
haobanMenuList.add(item) ; if(StringUtils.isNotBlank(enterpriseId) && !"-1".equals(enterpriseId)) {
continue ;
} }
// 无需授权的权限 logger.info("超管的权限={}",superMenuCodeList);
if(0==item.getAuthControl() && StringUtils.isEmpty(item.getBtnCodeRel())) { // 如果查询的后台的子管理员权限
haobanMenuList.add(item) ; HaobanRoleBO subRoleBO = null ;
menuCodes.add(code) ; List<String> subMenuCodes = null ;
continue ; if(systemFlag==1) {
} subRoleBO = haobanRoleService.getByWxEnterpriseIdAndClerkType(wxEnterpriseId, clerkType, 1);
if(null == subRoleBO) {
return ServiceResponse.failure("9999","未配置子管理员权限") ;
} }
for(HaobanMenuBO item : allMenuList) { Long subRoleId = subRoleBO.getRoleId() ;
String code = item.getBtnCodeRel() ; subMenuCodes = this.listRoleMenuCode(allMenuList,wxEnterpriseId,subRoleId) ;
if(0==item.getAuthControl() && StringUtils.isNotEmpty(item.getBtnCodeRel()) && menuCodes.contains(code)) { }
haobanMenuList.add(item) ; HaobanRoleBO retBO = new HaobanRoleBO();
menuCodes.add(code) ; if(systemFlag==0) {
continue ; retBO = superRoleBO ;
retBO.setMenuCodes(superMenuCodeList);
}else {
retBO = subRoleBO ;
List<String> subCodeList = new ArrayList<>() ;
for(String subCode : subMenuCodes) {
if(superMenuCodeList.contains(subCode)) {
subCodeList.add(subCode) ;
} }
} }
// 查询gic配置的权限 retBO.setMenuCodes(subCodeList);
if(StringUtils.isNotBlank(enterpriseId) && !"-1".equals(enterpriseId)) { }
List<HaobanMenuBO> haobanMenuList = new ArrayList<>() ;
Map<String,HaobanMenuBO> map = allMenuList.stream().collect(Collectors.toMap(HaobanMenuBO::getMenuCode,o->o,(k1,k2)->k1)) ;
for(String code : retBO.getMenuCodes()) {
HaobanMenuBO bo = map.get(code) ;
if(null != bo) {
haobanMenuList.add(bo) ;
}
}
retBO.setMenuList(EntityUtil.changeEntityListNew(HaobanMenuDTO.class, haobanMenuList));
return ServiceResponse.success(EntityUtil.changeEntityNew(HaobanRoleDTO.class, retBO));
}
private List<String> listRoleMenuCode(List<HaobanMenuBO> allMenuList , String wxEnterpriseId , Long roleId) {
List<String> menuCodes = haobanRoleMenuService.getByWxEnterpriseIdAndRoleId(wxEnterpriseId, roleId);
// 添加关联的权限
for(HaobanMenuBO item : allMenuList) {
String code = item.getMenuCode() ;
// 开启的权限
if(menuCodes.contains(code)) {
continue ;
}
// 无需授权的权限
if(0==item.getAuthControl() && StringUtils.isEmpty(item.getBtnCodeRel())) {
menuCodes.add(code) ;
continue ;
}
}
for(HaobanMenuBO item : allMenuList) {
String code = item.getBtnCodeRel() ;
if(0==item.getAuthControl() && StringUtils.isNotEmpty(item.getBtnCodeRel()) && menuCodes.contains(code)) {
menuCodes.add(code) ;
continue ;
} }
haobanRoleBO.setMenuCodes(menuCodes);
haobanRoleBO.setMenuList(EntityUtil.changeEntityListNew(HaobanMenuDTO.class, haobanMenuList));
} }
return ServiceResponse.success(EntityUtil.changeEntityNew(HaobanRoleDTO.class, haobanRoleBO)); return menuCodes ;
} }
@Override @Override
......
...@@ -96,5 +96,5 @@ public interface HaobanMenuService { ...@@ -96,5 +96,5 @@ public interface HaobanMenuService {
void deleteByMenuCode(String menuCode) ; void deleteByMenuCode(String menuCode) ;
void saveMenuFromGicNoitic(String enterpriseId) ; void saveMenuFromGicEvent(String params) ;
} }
package com.gic.haoban.manage.service.service.role.impl; package com.gic.haoban.manage.service.service.role.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.clerk.api.dto.right.MenuDTO;
import com.gic.clerk.api.dto.right.MenuListQDTO;
import com.gic.clerk.api.service.MenuApiService;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.UniqueIdUtils; import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper; import com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper;
...@@ -39,6 +43,8 @@ public class HaobanMenuServiceImpl implements HaobanMenuService { ...@@ -39,6 +43,8 @@ public class HaobanMenuServiceImpl implements HaobanMenuService {
private TabHaobanRoleMapper roleMapper ; private TabHaobanRoleMapper roleMapper ;
@Autowired @Autowired
private TabHaobanRoleMenuMapper roleMenuMapper ; private TabHaobanRoleMenuMapper roleMenuMapper ;
@Autowired
private MenuApiService menuApiService ;
@Override @Override
public TabHaobanMenu queryById(String menuCode) { public TabHaobanMenu queryById(String menuCode) {
...@@ -180,14 +186,41 @@ public class HaobanMenuServiceImpl implements HaobanMenuService { ...@@ -180,14 +186,41 @@ public class HaobanMenuServiceImpl implements HaobanMenuService {
} }
@Override @Override
public void saveMenuFromGicNoitic(String enterpriseId) { public void saveMenuFromGicEvent(String params) {
List<String> menuCodeList = Arrays.asList("1123") ; logger.info("服务开通-好办小程序={}",params);
List<Integer> addRoleTypeList = Arrays.asList(0,1,2); JSONObject json = JSONObject.parseObject(params) ;
logger.info("保存菜单={}",enterpriseId); String serviceCode = json.getString("serviceCode") ;
String enterpriseId = json.getString("enterpriseId") ;
String operationType = json.getString("operationType") ;
Boolean addOrDel = null ;
// 进行授权 auth 取消授权 cancel
if("auth".equals(operationType)) {
addOrDel = true;
}
if("cancel".equals(operationType)) {
addOrDel = false ;
}
MenuListQDTO qdto = new MenuListQDTO() ;
ServiceResponse<List<MenuDTO>> resp = this.menuApiService.listMenu(qdto) ;
if(!resp.isSuccess()) {
logger.info("失败={}",JSONObject.toJSONString(resp));
return;
}
List<TabHaobanWxEnterpriseRelated> wxEnterpriseList = this.wxEnterpriseRelatedMapper.listByEnterpriseId(enterpriseId) ; List<TabHaobanWxEnterpriseRelated> wxEnterpriseList = this.wxEnterpriseRelatedMapper.listByEnterpriseId(enterpriseId) ;
if(CollectionUtils.isEmpty(wxEnterpriseList)) {
logger.info("未关联企微={}",enterpriseId);
return ;
}
logger.info("gic关联的企微={}", JSONObject.toJSONString(wxEnterpriseList)); logger.info("gic关联的企微={}", JSONObject.toJSONString(wxEnterpriseList));
Date now = new Date() ; List<MenuDTO> menuDTOList = resp.getResult() ;
if(CollectionUtils.isNotEmpty(wxEnterpriseList)) { if(CollectionUtils.isEmpty(menuDTOList)) {
logger.info("无相关菜单");
return ;
}
for(MenuDTO gicMenu : menuDTOList) {
List<String> menuCodeList = Arrays.asList(gicMenu.getMenuCode()) ;
List<Integer> addRoleTypeList = Arrays.asList(0,1,2);
Date now = new Date() ;
for(int i=0;i<wxEnterpriseList.size();i++) { for(int i=0;i<wxEnterpriseList.size();i++) {
TabHaobanWxEnterpriseRelated item = wxEnterpriseList.get(i) ; TabHaobanWxEnterpriseRelated item = wxEnterpriseList.get(i) ;
String wxEnterpriseId = item.getWxEnterpriseId() ; String wxEnterpriseId = item.getWxEnterpriseId() ;
...@@ -195,12 +228,17 @@ public class HaobanMenuServiceImpl implements HaobanMenuService { ...@@ -195,12 +228,17 @@ public class HaobanMenuServiceImpl implements HaobanMenuService {
List<TabHaobanRole> list = this.roleMapper.getListByWxEnterpriseId(wxEnterpriseId,null) ; List<TabHaobanRole> list = this.roleMapper.getListByWxEnterpriseId(wxEnterpriseId,null) ;
TabHaobanRoleMenu menu = null ; TabHaobanRoleMenu menu = null ;
for(TabHaobanRole role : list) { for(TabHaobanRole role : list) {
Long roleId = role.getRoleId() ;
int roleType = role.getClerkType() ; int roleType = role.getClerkType() ;
if(!addRoleTypeList.contains(roleType)) { if(!addRoleTypeList.contains(roleType)) {
continue; continue;
} }
Long roleId = role.getRoleId() ;
for(String menuCode : menuCodeList) { for(String menuCode : menuCodeList) {
// 判断是否已存在
List<String> oldList = this.roleMenuMapper.getMenuInMenuCodes(wxEnterpriseId,roleId,Arrays.asList(menuCode)) ;
if(CollectionUtils.isNotEmpty(oldList)) {
continue;
}
menu = new TabHaobanRoleMenu() ; menu = new TabHaobanRoleMenu() ;
menu.setRoleMenuId(UniqueIdUtils.uniqueLong()); menu.setRoleMenuId(UniqueIdUtils.uniqueLong());
menu.setRoleId(roleId); menu.setRoleId(roleId);
...@@ -212,7 +250,6 @@ public class HaobanMenuServiceImpl implements HaobanMenuService { ...@@ -212,7 +250,6 @@ public class HaobanMenuServiceImpl implements HaobanMenuService {
insertMenuList.add(menu) ; insertMenuList.add(menu) ;
} }
} }
if(CollectionUtils.isNotEmpty(insertMenuList)) { if(CollectionUtils.isNotEmpty(insertMenuList)) {
this.roleMenuMapper.insertBatch(insertMenuList); this.roleMenuMapper.insertBatch(insertMenuList);
} }
......
...@@ -235,5 +235,6 @@ ...@@ -235,5 +235,6 @@
<dubbo:reference id="contentProducerApiService" interface="com.gic.content.api.service.ContentProducerApiService" timeout="10000" retries="0" check="false" /> <dubbo:reference id="contentProducerApiService" interface="com.gic.content.api.service.ContentProducerApiService" timeout="10000" retries="0" check="false" />
<dubbo:reference interface="com.gic.content.api.service.ContentMaterialApiService" id="contentMaterialApiService" timeout="10000" retries="0" check="false" /> <dubbo:reference interface="com.gic.content.api.service.ContentMaterialApiService" id="contentMaterialApiService" timeout="10000" retries="0" check="false" />
<dubbo:reference interface="com.gic.content.api.service.ContentSettingApiService" id="contentSettingApiService" timeout="10000" retries="0" check="false" /> <dubbo:reference interface="com.gic.content.api.service.ContentSettingApiService" id="contentSettingApiService" timeout="10000" retries="0" check="false" />
<dubbo:reference interface="com.gic.clerk.api.service.MenuApiService" id="menuApiService" timeout="10000" retries="0" check="false" />
</beans> </beans>
\ 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