|  | @ -3,12 +3,14 @@ package com.yihu.jw.base.service.doctor;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.contant.CommonContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.doctor.BaseDoctorRoleInfoDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.doctor.BaseModuleRoleDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.role.BaseRoleMenuDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.role.RoleDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.saas.SaasDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.dao.user.UserDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.module.SaasModuleService;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.org.BaseOrgSaasService;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.org.BaseOrgUserService;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.org.OrgTree;
 | 
	
	
		
			
				|  | @ -18,10 +20,14 @@ import com.yihu.jw.base.util.ConstantUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.util.JavaBeanUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorRoleInfoDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseModuleRoleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.module.ModuleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.module.SaasModuleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.org.BaseOrgUserDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.role.RoleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.saas.SaasDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.user.UserDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.base.module.ModuleVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.base.module.SaasModuleVO;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import com.yihu.utils.security.MD5;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
	
		
			
				|  | @ -35,7 +41,9 @@ import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.text.ParseException;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * 
 | 
	
	
		
			
				|  | @ -67,10 +75,67 @@ public class BaseDoctorRoleInfoService extends BaseJpaService<BaseDoctorRoleInfo
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseModuleRoleService baseModuleRoleService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SaasModuleService saasModuleService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${configDefault.saasId}")
 | 
	
		
			
				|  |  |     private String defaultSaasId;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取租户下的模块列表
 | 
	
		
			
				|  |  |      * @param saasId
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject getModuleTreeBySaas(String saasId,String roleId) throws ParseException {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(saasId) && StringUtils.isEmpty(roleId)){
 | 
	
		
			
				|  |  |             result.put("msg","parameter saasId and roleId are null ");
 | 
	
		
			
				|  |  |             result.put("response",ConstantUtils.FAIL);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String filters = "status="+ ModuleDO.Status.available.getValue()+";";
 | 
	
		
			
				|  |  |         List<SaasModuleDO> modules = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(!StringUtils.isEmpty(saasId) && StringUtils.isEmpty(roleId)){
 | 
	
		
			
				|  |  |             filters += "saasId="+saasId;
 | 
	
		
			
				|  |  |             modules = saasModuleService.search(null, filters, null);
 | 
	
		
			
				|  |  |         }else if(!StringUtils.isEmpty(saasId) && !StringUtils.isEmpty(roleId)){
 | 
	
		
			
				|  |  |             Set<Object> moduleIdSet = new HashSet<>();
 | 
	
		
			
				|  |  |             moduleIdSet = baseModuleRoleService.findModuleIdList(roleId);
 | 
	
		
			
				|  |  |             if(moduleIdSet.size() < 0){
 | 
	
		
			
				|  |  |                 result.put("msg","no modules under this role:" + roleId);
 | 
	
		
			
				|  |  |                 result.put("response",ConstantUtils.FAIL);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  |             moduleIdSet.forEach(one -> sb.append(one).append(","));
 | 
	
		
			
				|  |  |             filters += "id=" + sb.toString();
 | 
	
		
			
				|  |  |             modules = saasModuleService.search(null, filters, null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<SaasModuleVO> moduleVOs = convertToModels(modules,new ArrayList<>(modules.size()),SaasModuleVO.class);
 | 
	
		
			
				|  |  |         List<ModuleVO> moduleVOList = new ArrayList<>(moduleVOs.size());
 | 
	
		
			
				|  |  |         //转化为module
 | 
	
		
			
				|  |  |         moduleVOs.forEach(one->{
 | 
	
		
			
				|  |  |             ModuleVO vo = new ModuleVO();
 | 
	
		
			
				|  |  |             vo.setId(one.getModuleId());
 | 
	
		
			
				|  |  |             vo.setParentId(one.getParentModuleId());
 | 
	
		
			
				|  |  |             vo.setIsMust(one.getIsMust());
 | 
	
		
			
				|  |  |             vo.setName(one.getName());
 | 
	
		
			
				|  |  |             moduleVOList.add(vo);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         List<ModuleVO> moduleVOList2 = moduleVOList;
 | 
	
		
			
				|  |  |         Map<String,List<ModuleVO>> map = moduleVOList2.stream().collect(Collectors.groupingBy(ModuleVO::getParentId));
 | 
	
		
			
				|  |  |         moduleVOList2.forEach(module->{
 | 
	
		
			
				|  |  |             List<ModuleVO> tmp = map.get(module.getId());
 | 
	
		
			
				|  |  |             module.setChildren(tmp);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         moduleVOList2 = moduleVOList2.stream()
 | 
	
		
			
				|  |  |                 .filter(module -> CommonContant.DEFAULT_PARENTID.equals(module.getParentId()))
 | 
	
		
			
				|  |  |                 .collect(Collectors.toList());
 | 
	
		
			
				|  |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
	
		
			
				|  |  |         result.put("msg",moduleVOList2);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 创建角色信息
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -172,7 +237,7 @@ public class BaseDoctorRoleInfoService extends BaseJpaService<BaseDoctorRoleInfo
 | 
	
		
			
				|  |  |         this.save(roleInfoDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //修改角色与模块关联关系
 | 
	
		
			
				|  |  |         Set<Object> roleIdList = baseModuleRoleService.findModuleIdList(roleInfoDO.getId());
 | 
	
		
			
				|  |  |         Set<Object> roleIdList = baseModuleRoleService.findModuleIdList(roleInfoDO.getCode());
 | 
	
		
			
				|  |  |         BaseModuleRoleDO moduleRoleDO = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             for (Object obj : module) {
 | 
	
	
		
			
				|  | @ -218,9 +283,12 @@ public class BaseDoctorRoleInfoService extends BaseJpaService<BaseDoctorRoleInfo
 | 
	
		
			
				|  |  |             result.put("response",ConstantUtils.FAIL);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<BaseModuleRoleDO> moduleRoleDOList =  baseModuleRoleService.findModuleListByRoleCode(roleInfoDO.getCode());
 | 
	
		
			
				|  |  |         JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |         jsonObject.put("role",roleInfoDO);
 | 
	
		
			
				|  |  |         jsonObject.put("module",moduleRoleDOList);
 | 
	
		
			
				|  |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
	
		
			
				|  |  |         result.put("msg",roleInfoDO);
 | 
	
		
			
				|  |  |         result.put("msg",jsonObject);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -251,6 +319,25 @@ public class BaseDoctorRoleInfoService extends BaseJpaService<BaseDoctorRoleInfo
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 判断某一租户下角色名称是否存在
 | 
	
		
			
				|  |  |      * @param saasId
 | 
	
		
			
				|  |  |      * @param name
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject existNameOfSaas(String saasId,String name){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(saasId) || StringUtils.isEmpty(name)){
 | 
	
		
			
				|  |  |             result.put("msg","parameter saasId or name is null");
 | 
	
		
			
				|  |  |             result.put("response",ConstantUtils.FAIL);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BaseDoctorRoleInfoDO roleInfoDO = baseDoctorRoleInfoDao.findBySaasidAndName(saasId,name);
 | 
	
		
			
				|  |  |         result.put("response",ConstantUtils.SUCCESS);
 | 
	
		
			
				|  |  |         result.put("msg",null == roleInfoDO);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 | 
	
		
			
				|  |  | 
 |