package com.vci.frameworkcore.compatibility.impl; import com.vci.corba.common.PLException; import com.vci.corba.common.data.UserEntityInfo; import com.vci.corba.framework.data.PasswordStrategyInfo; import com.vci.corba.omd.data.BusinessObject; import com.vci.frameworkcore.compatibility.SmPwdStrategyQueryServiceI; import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; import com.vci.frameworkcore.constant.FrameWorkBtmTypeConstant; import com.vci.frameworkcore.enumpck.RoleClassifyEnum; import com.vci.frameworkcore.enumpck.RoleControlAreaEnum; import com.vci.frameworkcore.model.SmPasswordStrategyDO; import com.vci.frameworkcore.model.SmPasswordStrategyForPlatform1; import com.vci.frameworkcore.model.SmRoleForPlatform1; import com.vci.frameworkcore.pagemodel.SmPasswordStrategyVO; import com.vci.frameworkcore.pagemodel.SmRoleVO; import com.vci.omd.utils.ObjectTool; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.DataGrid; import com.vci.starter.web.pagemodel.PageHelper; import com.vci.starter.web.util.BeanUtil; import com.vci.starter.web.util.VciBaseUtil; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.service.WebBoServiceI; import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.Collectors; import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; /** * 密码策略查询服务 * @author ludc * @date 2024/6/24 16:33 */ @Service public class SmPwdStrategyQueryServiceImpl implements SmPwdStrategyQueryServiceI { /** * 业务数据服务 */ @Autowired private WebBoServiceI boService; /** * 用户查询服务 */ @Autowired private SmUserQueryServiceI smUserQueryService; /** * 平台调用客户端 */ @Autowired private PlatformClientUtil platformClientUtil; /** * 获取默认密码策略 * @return */ public SmPasswordStrategyVO getPasswordStrategyVOByDefault(){ //获取默认的 VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class); queryWrapperForDO.eq("plisdefault","1"); List cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() + (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null); if(!CollectionUtils.isEmpty(cboList)){ SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO(); WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO); return pwdStrategyDO2VO(passwordStrategyDO); } return null; } /** * 密码策略分页查询 * @param conditionMap * @param pageHelper * @return */ @Override public DataGrid refDataGrid(Map conditionMap, PageHelper pageHelper) throws PLException { if(pageHelper == null){ pageHelper = new PageHelper(-1); } pageHelper.addDefaultAsc("pname"); VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyDO.class,pageHelper); //queryWrapper.eq("pltype","2"); platformClientUtil.getFrameworkService().fetchAllPasswordStrategy(); //platformClientUtil.getFrameworkService().fetchpassword(); List smPasswordStrategyForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmPasswordStrategyForPlatform1.class); DataGrid dataGrid = new DataGrid<>(); if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){ dataGrid.setData(pltPwdStrategy2SmPwdStrategyVOs(smPasswordStrategyForPlatform1s)); dataGrid.setTotal(boService.countByQueryWrapper(queryWrapper,SmPasswordStrategyForPlatform1.class)); } return dataGrid; } /** * 查询密码安全策略,下拉使用的接口 * @param conditionMap * @return key为密码策略name,value为密码策略的oid * @throws VciBaseException */ @Override public List> selectPwdStrategyMap(Map conditionMap) throws PLException { PageHelper pageHelper = new PageHelper(-1); pageHelper.addDefaultAsc("plname"); PasswordStrategyInfo[] passwordStrategyInfos = platformClientUtil.getFrameworkService().fetchAllPasswordStrategy(); List> mapArrayList = new ArrayList<>(); if(Func.isEmpty(passwordStrategyInfos)){ return mapArrayList; } Arrays.stream(passwordStrategyInfos).forEach(item->{ Map map = new HashMap<>(); map.put("name",item.name); map.put("id",item.id); mapArrayList.add(map); }); return mapArrayList; } /** * 原平台密码策略转SmPasswordStrategyVOS对象 * @param smPasswordStrategyForPlatform1s 原平台的密码策略 * @return */ private List pltPwdStrategy2SmPwdStrategyVOs(List smPasswordStrategyForPlatform1s){ List smPasswordStrategyVOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){ smPasswordStrategyForPlatform1s.stream().forEach(s -> { smPasswordStrategyVOList.add(pltPwdStrategy2SmPwdStrategyVO(s)); }); } return smPasswordStrategyVOList; } /** * 原平台密码策略转SmPasswordStrategyVO对象 * @param strategyForPlatform1 原平台的密码策略 * @return 新的密码策略对象 */ private SmPasswordStrategyVO pltPwdStrategy2SmPwdStrategyVO(SmPasswordStrategyForPlatform1 strategyForPlatform1){ SmPasswordStrategyVO strategyVO = new SmPasswordStrategyVO(); strategyVO.setOid(strategyForPlatform1.getPluid()); strategyVO.setId(""); strategyVO.setName(strategyForPlatform1.getPname()); strategyVO.setMaxLength(strategyForPlatform1.getPlmaxlength()); strategyVO.setMinLength(strategyForPlatform1.getPlength()); strategyVO.setValidDay(strategyForPlatform1.getPremindday()); strategyVO.setRemindDay(strategyForPlatform1.getPremindday()); strategyVO.setRetryTime(strategyForPlatform1.getPretrytime()); strategyVO.setLockTime(strategyForPlatform1.getPlocktime()); strategyVO.setDefaultFlag(strategyForPlatform1.getPlisdefault() == 1); strategyVO.setDescription(strategyForPlatform1.getPldesc()); strategyVO.setCreateTime(strategyForPlatform1.getPlcreatetime()); strategyVO.setCreator(strategyForPlatform1.getPlcreateuser()); strategyVO.setLastModifyTime(strategyForPlatform1.getPlupdatetime()); strategyVO.setLastModifier(strategyForPlatform1.getPlupdateuser()); strategyVO.getRequireCharType(strategyForPlatform1.getPcharspecies()); strategyVO.setLicensors(strategyForPlatform1.getPllicensors()); strategyVO.setRequireCharCount(strategyForPlatform1.getPlrequiredtype()); return strategyVO; } /** * 保存用户关联密码策略 * @param userIds * @param passwordStrategId * @return */ @Override public boolean saveUserPasswordStrateg(String[] userIds, String passwordStrategId) throws PLException { VciBaseUtil.alertNotNull(userIds,"用户主键",passwordStrategId,"密码安全策略主键"); //TODO:这里没有做查重处理,明天记得验证一下这儿是不是会自动做saveOrUpdate的处理 return platformClientUtil.getFrameworkService().saveUserPasswordStrateg(userIds,passwordStrategId,new UserEntityInfo()); } /** * 根据主键查询密码策略map对象 * @param oidList * @return key为密码策略主键 value为密码策略 */ @Override public Map mapPasswordStrategyVOMapByOid(Collection oidList) { VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class); queryWrapperForDO.in("oid",oidList.stream().collect(Collectors.joining(","))); List cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() + (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null); Map smPasswordStrategyVOMap = new HashMap<>(); if(Func.isEmpty(cboList)){ return new HashMap<>(); } cboList.stream().forEach(item->{ SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO(); WebUtil.copyValueToObjectFromCbos(item,passwordStrategyDO); SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO(); BeanUtil.convert(passwordStrategyDO,passwordStrategyVO); smPasswordStrategyVOMap.put(passwordStrategyVO.getOid(),passwordStrategyVO); }); return smPasswordStrategyVOMap; } /** * 使用主键获取密码策略 * @param oid 主键 * @return 密码策略显示对象 */ public SmPasswordStrategyVO getPasswordStrategyVOByOid(String oid){ VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class); queryWrapperForDO.eq("oid",oid.trim()); List cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() + (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null); if(!CollectionUtils.isEmpty(cboList)){ SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO(); WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO); SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO(); BeanUtil.convert(passwordStrategyDO,passwordStrategyVO); return passwordStrategyVO; }else{ //获取默认的 queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class); queryWrapperForDO.eq("plisdefault","1"); cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() + (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null); if(!CollectionUtils.isEmpty(cboList)){ SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO(); WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO); return pwdStrategyDO2VO(passwordStrategyDO); } } return null; } /** * 多条密码策略do对象转vo对象 * @param smPasswordStrategyDOList * @return */ private List pwdStrategyDO2VOS(List smPasswordStrategyDOList){ List smPasswordStrategyVOList = new ArrayList<>(); if(Func.isEmpty(smPasswordStrategyDOList)) { return smPasswordStrategyVOList; } smPasswordStrategyDOList.stream().forEach(item->{ smPasswordStrategyVOList.add(pwdStrategyDO2VO(item)); }); return smPasswordStrategyVOList; } /** * 密码策略do对象转vo对象 * @param smPasswordStrategyDO * @return */ private SmPasswordStrategyVO pwdStrategyDO2VO(SmPasswordStrategyDO smPasswordStrategyDO){ SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO(); BeanUtil.convert(smPasswordStrategyDO,passwordStrategyVO); return passwordStrategyVO; } /** * 根据用户的主键,获取用户的密码安全策略 * @param userOid 用户的主键 * @return 密码安全策略的显示对象,如果不存在则会返回Null * @throws VciBaseException 参数为空或者数据库查询出错的时候会抛出异常 */ @Override public SmPasswordStrategyVO getPasswordStrategyVOByUserOid(String userOid) throws PLException { WebUtil.alertNotNull(userOid,"用户的主键"); if(!smUserQueryService.checkUserExist(null,userOid)){ throw new VciBaseException(DATA_OID_NOT_EXIST); } String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid = '"+ userOid +"'"; List cbos = boService.queryBySql(sql, null); if(Func.isNotEmpty(cbos)){ return getPasswordStrategyVOByOid(ObjectTool.getNewBOAttributeValue(cbos.get(0), "plpasswordstrategyuid")); } return null; } /** * 根据多条用户主键,获取用户的密码安全策略 * @param userOids * @return * @throws PLException */ @Override public List listSmPasswordStrategyVOByUserOids(Collection userOids) { WebUtil.alertNotNull(userOids,"用户的主键"); //先查关联表 List userPwdStrategyList = new ArrayList<>(); WebUtil.switchCollectionForOracleIn(userOids).stream().forEach(userOidSplit->{ //查关联表sql String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid in (" + WebUtil.toInSql(userOidSplit.toArray(new String[0])) + ")"; List cbos = boService.queryBySql(sql, null); cbos.stream().forEach(cbo->{ userPwdStrategyList.add(ObjectTool.getNewBOAttributeValue(cbo,"plpasswordstrategyuid")); }); }); return listSmPasswordStrategyVOByOids(userPwdStrategyList); } /** * 根据用户主键查询密码策略关联表中的密码策略主键 * @param userOids * @return key为用户oid:value为密码策略oid */ private Map mapUserPwdStrategy(Collection userOids){ Map userPwdStrategyMap = new HashMap<>(); WebUtil.switchCollectionForOracleIn(userOids).stream().forEach(userOidSplit->{ //查关联表sql String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid in (" + WebUtil.toInSql(userOidSplit.toArray(new String[0])) + ")"; List cbos = boService.queryBySql(sql, null); cbos.stream().forEach(cbo->{ String pluseruid = ObjectTool.getNewBOAttributeValue(cbo, "pluseruid"); String plpasswordstrategyuid = ObjectTool.getNewBOAttributeValue(cbo, "plpasswordstrategyuid"); userPwdStrategyMap.put(pluseruid,plpasswordstrategyuid); }); }); return userPwdStrategyMap; } /** * 根据主键,批量获取密码安全策略主键 * @param oids * @return * @throws PLException */ @Override public List listSmPasswordStrategyVOByOids(Collection oids) { VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class); queryWrapperForDO.in("oid",oids.stream().collect(Collectors.joining(","))); List cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " + queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() + (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null); List smPasswordStrategyVOList = new ArrayList<>(); if(Func.isEmpty(cboList)){ return smPasswordStrategyVOList; } cboList.stream().forEach(item->{ SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO(); WebUtil.copyValueToObjectFromCbos(item,passwordStrategyDO); SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO(); BeanUtil.convert(passwordStrategyDO,passwordStrategyVO); smPasswordStrategyVOList.add(passwordStrategyVO); }); return smPasswordStrategyVOList; } /** * 批量根据用户的主键来获取密码策略 * @param userOidCollection 用户主键集合 * @return 密码策略的显示对象,key是用户主键,value是这个用户关联的密码策略 */ @Override public Map batchSmPwdStrategyByUserOids(Collection userOidCollection) { if(CollectionUtils.isEmpty(userOidCollection)){ return new HashMap<>(); } Map smPasswordStrategyVOMap = new HashMap<>(); Map userPasswordStrategyVOMap = new HashMap<>(); Map returnMap = new HashMap<>(); WebUtil.switchCollectionForOracleIn(userOidCollection).stream().forEach(userOids->{ //查询密码策略关联信息,key为用户oid:value为密码策略oid Map userPwdStrategyMap = mapUserPwdStrategy(userOids); userPasswordStrategyVOMap.putAll(userPwdStrategyMap); //查询密码策略,key为密码策略主键:value为密码策略 smPasswordStrategyVOMap.putAll(mapPasswordStrategyVOMapByOid(userPwdStrategyMap.values())); }); //查询默认的密码策略 SmPasswordStrategyVO passwordStrategyVOByDefault = getPasswordStrategyVOByDefault(); //循环用户id,查询是否有符合条件的oid userOidCollection.stream().forEach(oid->{ SmPasswordStrategyVO smPasswordStrategyVO; //通过用户oid没获取到密码策略oid,说明没有给当前用户设置策略,直接返默认的密码策略 String pwdStrategyId = userPasswordStrategyVOMap.get(oid); if(Func.isNotBlank(pwdStrategyId)){ //通过密码策略oid去map中取密码策略 smPasswordStrategyVO = smPasswordStrategyVOMap.get(pwdStrategyId); }else { smPasswordStrategyVO = passwordStrategyVOByDefault; } returnMap.put(oid,smPasswordStrategyVO); }); return returnMap; } }