Commit bc75b5e0 by songyinghui

feat: 好办权限初始化

parent b91368ea
......@@ -510,55 +510,60 @@ public class HaobanRoleApiServiceImpl implements HaobanRoleApiService {
for (TabHaobanWxEnterprise wxEnterpris : tabHaobanWxEnterprises) {
// 查询企微下 导购、店长、区经 的role_id
String wxEnterpriseId = wxEnterpris.getWxEnterpriseId();
// 只取好办后台
List<HaobanRoleBO> haobanRoleBOS = haobanRoleService.getListByWxEnterpriseId(wxEnterpriseId, 1);
if (CollectionUtils.isEmpty(haobanRoleBOS)) {
logger.info("企业{} 企微 {} 下没有角色 ", contentMaterialROleInitQDTO.getEnterpriseId(), wxEnterpriseId);
// 处理商户权限
handlerMaterchant(contentMaterialROleInitQDTO, wxEnterpriseId);
}
return ServiceResponse.success();
}
private void handlerMaterchant(ContentMaterialROleInitQDTO contentMaterialROleInitQDTO, String wxEnterpriseId) {
// 运维 + 好办后台
List<HaobanRoleBO> haobanRoleBOS = haobanRoleService.getListByWxEnterpriseId(wxEnterpriseId, null);
if (CollectionUtils.isEmpty(haobanRoleBOS)) {
logger.info("企业{} 企微 {} 下没有角色 ", contentMaterialROleInitQDTO.getEnterpriseId(), wxEnterpriseId);
return;
}
// 为role 添加菜单
List<TabHaobanRoleMenu> haobanRoleMenus = new ArrayList<>();
for (HaobanRoleBO haobanRoleBO : haobanRoleBOS) {
List<String> menuCodes = menuCodeMap.get(haobanRoleBO.getClerkType() + "" + contentMaterialROleInitQDTO.getVersion());
if (CollectionUtils.isEmpty(menuCodes)) {
continue;
}
// 为role 添加菜单
List<TabHaobanRoleMenu> haobanRoleMenus = new ArrayList<>();
for (HaobanRoleBO haobanRoleBO : haobanRoleBOS) {
List<String> menuCodes = menuCodeMap.get(haobanRoleBO.getClerkType() + "" + contentMaterialROleInitQDTO.getVersion());
if (CollectionUtils.isEmpty(menuCodes)) {
continue;
}
logger.info("本次对应的menuCode:{}", JSON.toJSONString(menuCodes));
List<String> hasExistMenuCodes = haobanRoleMenuService.getByWxEnterpriseIdAndRoleId(wxEnterpriseId, haobanRoleBO.getRoleId());
if (CollectionUtils.isEmpty(hasExistMenuCodes)) {
hasExistMenuCodes = new ArrayList<>();
}
List<String> excludeMenuCodes = hasExistMenuCodes;
if (!hasExistMenuCodes.contains("commodityCenter")) {
// 如果该角色原来没有【商品中心权限】 不勾选发圈素材和素材数量
logger.info("roleId:{} 原本没有商品中心权限 ", haobanRoleBO.getRoleId());
excludeMenuCodes.add("goodsDetail_material");
excludeMenuCodes.add("goodsCenter_Count");
}
List<TabHaobanRoleMenu> tabHaobanRoleMenus = menuCodes.stream()
.filter(item -> !excludeMenuCodes.contains(item))
.map(item -> {
TabHaobanRoleMenu temp = new TabHaobanRoleMenu();
temp.setRoleMenuId(UniqueIdUtils.uniqueLong());
temp.setRoleId(haobanRoleBO.getRoleId());
temp.setWxEnterpriseId(wxEnterpriseId);
temp.setStatusFlag(1);
temp.setMenuCode(item);
temp.setCreateTime(new Date());
temp.setUpdateTime(new Date());
return temp;
})
.collect(Collectors.toList());
logger.info("企微:{} roleId:{} 新增权限code: {}", wxEnterpriseId, haobanRoleBO.getRoleId(), JSON.toJSONString(tabHaobanRoleMenus));
haobanRoleMenus.addAll(tabHaobanRoleMenus);
logger.info("本次对应的menuCode:{}", JSON.toJSONString(menuCodes));
List<String> hasExistMenuCodes = haobanRoleMenuService.getByWxEnterpriseIdAndRoleId(wxEnterpriseId, haobanRoleBO.getRoleId());
if (CollectionUtils.isEmpty(hasExistMenuCodes)) {
hasExistMenuCodes = new ArrayList<>();
}
logger.info("企微:{} 新增权限code: {}", wxEnterpriseId, JSON.toJSONString(haobanRoleMenus));
if (CollectionUtils.isNotEmpty(haobanRoleMenus)) {
haobanRoleMenuService.insertBatch(haobanRoleMenus);
List<String> excludeMenuCodes = hasExistMenuCodes;
if (!hasExistMenuCodes.contains("commodityCenter")) {
// 如果该角色原来没有【商品中心权限】 不勾选发圈素材和素材数量
logger.info("roleId:{} 原本没有商品中心权限 ", haobanRoleBO.getRoleId());
excludeMenuCodes.add("goodsDetail_material");
excludeMenuCodes.add("goodsCenter_Count");
}
List<TabHaobanRoleMenu> tabHaobanRoleMenus = menuCodes.stream()
.filter(item -> !excludeMenuCodes.contains(item))
.map(item -> {
TabHaobanRoleMenu temp = new TabHaobanRoleMenu();
temp.setRoleMenuId(UniqueIdUtils.uniqueLong());
temp.setRoleId(haobanRoleBO.getRoleId());
temp.setWxEnterpriseId(wxEnterpriseId);
temp.setStatusFlag(1);
temp.setMenuCode(item);
temp.setCreateTime(new Date());
temp.setUpdateTime(new Date());
return temp;
})
.collect(Collectors.toList());
logger.info("企微:{} roleId:{} 新增权限code: {}", wxEnterpriseId, haobanRoleBO.getRoleId(), JSON.toJSONString(tabHaobanRoleMenus));
haobanRoleMenus.addAll(tabHaobanRoleMenus);
}
logger.info("企微:{} 新增权限code: {}", wxEnterpriseId, JSON.toJSONString(haobanRoleMenus));
if (CollectionUtils.isNotEmpty(haobanRoleMenus)) {
haobanRoleMenuService.insertBatch(haobanRoleMenus);
}
return ServiceResponse.success();
}
private static final Map<String, List<String> > menuCodeMap = new HashMap<>();
......
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