| | |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.corba.omd.etm.EnumItem; |
| | | import com.vci.corba.omd.etm.EnumType; |
| | | import com.vci.dto.OsEnumDTO; |
| | | import com.vci.dto.OsEnumItemDTO; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.starter.web.annotation.log.VciUnLog; |
| | | import com.vci.starter.web.enumpck.UserSecretEnum; |
| | |
| | | import com.vci.pagemodel.OsEnumItemVO; |
| | | import com.vci.pagemodel.OsEnumVO; |
| | | import com.vci.pagemodel.OsStatusVO; |
| | | import com.vci.starter.web.util.WebThreadLocalUtil; |
| | | import com.vci.web.service.OsEnumServiceI; |
| | | import com.vci.web.service.OsLifeCycleServiceI; |
| | | 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; |
| | |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | |
| | | /** |
| | | * 加载自身 |
| | | */ |
| | | @Autowired(required = false) |
| | | @Lazy |
| | | private OsEnumServiceI self; |
| | | |
| | | |
| | | /** |
| | | * 使用编号获取枚举明细 |
| | |
| | | int userSecret = WebUtil.getInt(WebUtil.getCurrentUserSessionInfoNotException().getUserSecret()); |
| | | List<OsEnumItemVO> itemVOS = new ArrayList<>(); |
| | | if(enumVO!=null && !CollectionUtils.isEmpty(enumVO.getItems())){ |
| | | itemVOS = enumVO.getItems().stream().filter(item->WebUtil.getInt(item.getId()) <= userSecret).collect(Collectors.toList()); |
| | | itemVOS = enumVO.getItems().stream().filter(item->WebUtil.getInt(item.getValue()) <= userSecret).collect(Collectors.toList()); |
| | | } |
| | | return itemVOS; |
| | | }else{ |
| | | return enumVOMap.getOrDefault(enumCode.toLowerCase(),new OsEnumVO()).getItems(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取枚举的内容 |
| | | * @param enumCode 枚举的编号(英文名称) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 枚举定义列表查询(缓存里面找且带name查询条件) |
| | | * @param enumName |
| | | * @return 枚举的显示对象 |
| | | */ |
| | | @Override |
| | | public List<OsEnumVO> getEnumTypeList(String enumName) throws PLException { |
| | | return enumDO2VOs(Arrays.stream(platformClientUtil.getEnumService().getEnumTypes(enumName,1,1)).collect(Collectors.toList())); |
| | | } |
| | | |
| | | /** |
| | | * 查看枚举的使用范围 |
| | | * @param enumName |
| | | * @return |
| | | * @throws PLException |
| | | */ |
| | | @Override |
| | | public List<OsEnumVO> getUsedEnumList(String enumName) throws PLException { |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据枚举英文名称获取枚举类型 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public OsEnumVO getEnumTypeById(String id) throws PLException { |
| | | if (Func.isBlank(id)) { |
| | | return null; |
| | | } |
| | | EnumType enumType = platformClientUtil.getEnumService().getEnumTypeByName(id); |
| | | return enumDO2VO(enumType); |
| | | } |
| | | |
| | | /** |
| | | * 新增枚举类型 |
| | | * @param osEnumDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addEnumType(OsEnumDTO osEnumDTO) throws PLException { |
| | | //1、枚举值判空 |
| | | VciBaseUtil.alertNotNull( |
| | | osEnumDTO,"枚举类型对象", |
| | | osEnumDTO.getId(),"枚举名称", |
| | | osEnumDTO.getEnumValueDataType(),"枚举的类型", |
| | | osEnumDTO.getLength(),"枚举长度" |
| | | ); |
| | | //2、枚举类型名称正则校验和查重 |
| | | if(!osEnumDTO.getId().matches("^[A-Za-z]+$")){ |
| | | throw new PLException("500", new String[] { "枚举名称只能为英文字母!"}); |
| | | } |
| | | OsEnumVO osEnumVO = this.getEnumTypeById(osEnumDTO.getId()); |
| | | if(Func.isNotEmpty(osEnumVO) && Func.isNotBlank(osEnumVO.getOid())){ |
| | | throw new PLException("500", new String[] { "枚举名称已存在,请修改枚举名称!"}); |
| | | } |
| | | //枚举项名称判重等操作 |
| | | checkOsEnumItem(osEnumDTO); |
| | | //默认值处理 |
| | | String userId = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | osEnumDTO.setCreator(userId); |
| | | osEnumDTO.setLastModifier(userId); |
| | | return platformClientUtil.getEnumService().addEnumType(this.osEnumDTO2EnumType(osEnumDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 修改枚举类型 |
| | | * @param osEnumDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updateEnumType(OsEnumDTO osEnumDTO) throws PLException { |
| | | //1、枚举值判空 |
| | | VciBaseUtil.alertNotNull( |
| | | osEnumDTO,"枚举类型对象", |
| | | osEnumDTO.getOid(),"枚举的主键", |
| | | osEnumDTO.getId(),"枚举名称", |
| | | osEnumDTO.getEnumValueDataType(),"枚举的类型", |
| | | osEnumDTO.getLength(),"枚举长度" |
| | | ); |
| | | //2、枚举类型名称(名称不允许修改)所以可以用名称查询是否存在 |
| | | OsEnumVO osEnumVO = this.getEnumTypeById(osEnumDTO.getId()); |
| | | if(Func.isEmpty(osEnumVO) || Func.isBlank(osEnumVO.getOid())){ |
| | | throw new PLException("500", new String[] { "当前修改枚举对象不存在,请刷新后重试!"}); |
| | | } |
| | | //3、枚举项判重,和长度等校验 |
| | | checkOsEnumItem(osEnumDTO); |
| | | //将osEnumVO中的默认值赋值给osEnumDTO对象 |
| | | String userId = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | osEnumDTO.setLastModifier(userId); |
| | | osEnumDTO.setCreator(osEnumVO.getCreator()); |
| | | osEnumDTO.setCreateTime(osEnumVO.getCreateTime()); |
| | | //修改和删除时ts参数为前端必传参数 |
| | | return platformClientUtil.getEnumService().modifyEnumType(osEnumDTO2EnumType(osEnumDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 删除枚举类型(包含删除枚举项功能) |
| | | * @param osEnumDTOS |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deleteEnumTypes(List<OsEnumDTO> osEnumDTOS) throws PLException { |
| | | VciBaseUtil.alertNotNull(osEnumDTOS,"待删除的枚举列表"); |
| | | //平台的deleteEnumTypes方法必传三个参数,oid、name和ts |
| | | List<EnumType> enumTypes = new ArrayList<>(); |
| | | for(OsEnumDTO osEnumDTO : osEnumDTOS){ |
| | | //oid和ts判空 |
| | | String oid = osEnumDTO.getOid(); |
| | | //name主要用来对缓存数据删除 |
| | | String name = osEnumDTO.getName(); |
| | | Date ts = osEnumDTO.getTs(); |
| | | if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){ |
| | | throw new PLException("500",new String[]{"待删除的枚举列表中主键【oid】和调整时间【ts】不能为空!"}); |
| | | } |
| | | EnumType enumType = new EnumType(); |
| | | enumType.oid = oid; |
| | | enumType.name = name; |
| | | enumType.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat); |
| | | enumTypes.add(enumType); |
| | | } |
| | | if(Func.isEmpty(enumTypes)){ |
| | | return false; |
| | | } |
| | | return platformClientUtil.getEnumService().deleteEnumTypes(enumTypes.toArray(new EnumType[enumTypes.size()])); |
| | | } |
| | | |
| | | /** |
| | | * 枚举项校验 |
| | | * @param osEnumDTO |
| | | * @return 校验失败直接抛出异常,否则不会做任何返回 |
| | | */ |
| | | private void checkOsEnumItem(OsEnumDTO osEnumDTO) throws PLException { |
| | | List<OsEnumItemDTO> items = osEnumDTO.getItems(); |
| | | if (Func.isNotEmpty(items)) { |
| | | //获取正则,主要是针对Integer类型的时候 |
| | | String regular = "Integer".equals(osEnumDTO.getEnumValueDataType()) ? "^[0-9]+$" : ""; |
| | | //利用set的add返回值进行name判重 |
| | | Set<String> uniqueNames = new HashSet<>(); |
| | | for (OsEnumItemDTO item : items) { |
| | | // 判断name属性是否有重复的值 |
| | | if (!uniqueNames.add(item.getName())) { |
| | | throw new PLException("500", new String[] {"以下枚举项名称: 【" + item.getName()+ "】重复,请修改枚举项名后重试!"}); |
| | | } |
| | | //判断枚举值是否超过设定长度 |
| | | if (item.getValue().length() > osEnumDTO.getLength()) { |
| | | throw new PLException("500", new String[] {"枚举项名称为:【" + item.getName() + "】的枚举值长度,超过限定长度【" + osEnumDTO.getLength() + "】"}); |
| | | } |
| | | //枚举类型正则校验 |
| | | if(Func.isNotBlank(regular) && !item.getValue().matches(regular)){ |
| | | throw new PLException("500", new String[] { "枚举值只能为【" + |
| | | ("String".equals(osEnumDTO.getEnumValueDataType()) ? "字符串":"整型") + "】类型!"}); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新平台枚举DTO对象转平台EnumType对象 |
| | | * @param osEnumDTO |
| | | * @return |
| | | */ |
| | | private EnumType osEnumDTO2EnumType(OsEnumDTO osEnumDTO){ |
| | | EnumType enumType = new EnumType(); |
| | | enumType.oid = osEnumDTO.getOid(); |
| | | enumType.name = osEnumDTO.getId(); |
| | | enumType.label = osEnumDTO.getName(); |
| | | enumType.length = osEnumDTO.getLength(); |
| | | enumType.creator = osEnumDTO.getCreator(); |
| | | enumType.ts = Func.format((Func.isNotEmpty(osEnumDTO.getTs()) ? osEnumDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat); |
| | | enumType.createTime = Func.isNotEmpty(osEnumDTO.getCreateTime()) ? osEnumDTO.getCreateTime().getTime():System.currentTimeMillis(); |
| | | enumType.modifier = osEnumDTO.getLastModifier(); |
| | | enumType.modifyTime = System.currentTimeMillis(); |
| | | enumType.type = osEnumDTO.getEnumValueDataType(); |
| | | //处理枚举项 |
| | | List<EnumItem> enumItems = new ArrayList<>(); |
| | | List<OsEnumItemDTO> items = osEnumDTO.getItems(); |
| | | if(Func.isNotEmpty(items)){ |
| | | items.stream().forEach(item->{ |
| | | EnumItem enumItem = new EnumItem(); |
| | | enumItem.name = item.getName(); |
| | | enumItem.value = item.getValue(); |
| | | enumItem.description = item.getDescription(); |
| | | enumItems.add(enumItem); |
| | | }); |
| | | } |
| | | enumType.items = enumItems.toArray(new EnumItem[enumItems.size()]); |
| | | return enumType; |
| | | } |
| | | |
| | | /** |
| | | * 查询所有的枚举映射 |
| | | * |
| | | * @return key是枚举的英文名称 |
| | |
| | | /** |
| | | * 枚举的数据对象转换为显示对象 |
| | | * |
| | | * @param enumItem 数据对象 |
| | | * @param enumType 数据对象 |
| | | * @return 显示对象 |
| | | */ |
| | | @Override |
| | | public OsEnumVO enumDO2VO(EnumType enumItem) { |
| | | public OsEnumVO enumDO2VO(EnumType enumType) { |
| | | OsEnumVO enumVO = new OsEnumVO(); |
| | | if(enumItem!=null){ |
| | | enumVO.setOid(enumItem.oid); |
| | | enumVO.setCreator(enumItem.creator); |
| | | enumVO.setLastModifier(enumItem.modifier); |
| | | enumVO.setId(enumItem.name); |
| | | enumVO.setName(enumItem.label); |
| | | enumVO.setEnumValueDataType(enumItem.type); |
| | | enumVO.setLength((int) enumItem.length); |
| | | if(enumType!=null){ |
| | | enumVO.setOid(enumType.oid); |
| | | enumVO.setCreator(enumType.creator); |
| | | enumVO.setLastModifier(enumType.modifier); |
| | | enumVO.setId(enumType.name); |
| | | enumVO.setName(enumType.label); |
| | | enumVO.setEnumValueDataType(enumType.type); |
| | | enumVO.setEnumValueDataTypeText("String".equalsIgnoreCase(enumType.type) ? "字符串":"整型"); |
| | | enumVO.setLength((int) enumType.length); |
| | | |
| | | try { |
| | | enumVO.setLastModifyTime(new Date(enumItem.createTime)); |
| | | enumVO.setLastModifyTime(new Date(enumType.createTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | enumVO.setCreateTime(new Date(enumItem.createTime)); |
| | | enumVO.setCreateTime(new Date(enumType.createTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | enumVO.setTs(VciDateUtil.str2Date(enumItem.ts,VciDateUtil.DateTimeMillFormat)); |
| | | enumVO.setTs(VciDateUtil.str2Date(enumType.ts,VciDateUtil.DateTimeMillFormat)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //枚举项处理 |
| | | List<OsEnumItemVO> itemVOS = new ArrayList<>(); |
| | | Map<String,String> itemVOMap = new HashMap<>(); |
| | | if(enumItem.items!=null && enumItem.items.length > 0){ |
| | | for(int i = 0 ; i < enumItem.items.length ; i ++){ |
| | | if(enumType.items!=null && enumType.items.length > 0){ |
| | | for(int i = 0 ; i < enumType.items.length ; i ++){ |
| | | OsEnumItemVO enumItemVO = new OsEnumItemVO(); |
| | | EnumItem enumChild = enumItem.items[i]; |
| | | enumItemVO.setId(enumChild.value); |
| | | EnumItem enumChild = enumType.items[i]; |
| | | enumItemVO.setValue(enumChild.value); |
| | | enumItemVO.setName(enumChild.name); |
| | | enumItemVO.setDescription(enumChild.description); |
| | | itemVOS.add(enumItemVO); |
| | |
| | | if(!CollectionUtils.isEmpty(enumItemVO)){ |
| | | enumItemVO.forEach(itemVO->{ |
| | | KeyValue keyValue = new KeyValue(); |
| | | keyValue.setKey(itemVO.getId()); |
| | | keyValue.setKey(itemVO.getValue()); |
| | | keyValue.setValue(itemVO.getName()); |
| | | keyValueList.add(keyValue); |
| | | }); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 参照枚举的信息 |
| | | * 参照枚举的信息 不建议使用这个方法,因为是sql拼接做的查询 |
| | | * |
| | | * @param conditionMap 查询条件 |
| | | * @param pageHelper 分页 |
| | |
| | | */ |
| | | @Override |
| | | public DataGrid<OsEnumVO> referDataGrid(Map<String, String> conditionMap, PageHelper pageHelper) { |
| | | DataGrid<OsEnumVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plenum",OsEnumVO.class,null); |
| | | DataGrid<OsEnumVO> dataGrid = queryObjectServiceInfoBySql(conditionMap, pageHelper, "plenumtype",OsEnumVO.class,null); |
| | | return dataGrid; |
| | | } |
| | | |
| | |
| | | return dataGrid; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除缓存 |
| | | */ |
| | |
| | | public void clearCache() { |
| | | |
| | | } |
| | | |
| | | } |