package com.vci.ubcs.code.service.impl; import com.alibaba.fastjson.JSONObject; import com.vci.ubcs.code.constant.MdmBtmTypeConstant; import com.vci.ubcs.code.dao.CodeClassifyTemplateAttrDaoI; import com.vci.ubcs.code.dao.CodeClassifyTemplateDaoI; import com.vci.ubcs.code.enumpack.CodeLevelTypeEnum; import com.vci.ubcs.code.model.CodeClassifyTemplateAttrDO; import com.vci.ubcs.code.model.CodeClassifyTemplateDO; import com.vci.ubcs.code.service.CodeClassifyTemplateAttrServiceI; import com.vci.ubcs.code.service.CodeTemplatePhaseServiceI; import com.vci.ubcs.code.utils.PatternUtil; import com.vci.starter.revision.service.RevisionModelUtil; import com.vci.starter.web.constant.QueryOptionConstant; import com.vci.starter.web.enumpck.VciFieldTypeEnum; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.*; import com.vci.starter.web.util.BeanUtil; import com.vci.starter.web.util.BeanUtilForVCI; import com.vci.starter.web.util.VciBaseUtil; import com.vci.starter.web.util.VciDateUtil; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.pageModel.BatchCBO; import com.vci.web.pageModel.OsBtmTypeAttributeVO; import com.vci.web.pageModel.UIFormReferVO; import com.vci.web.service.BdSelectInputCharServiceI; import com.vci.web.service.OsAttributeServiceI; import com.vci.web.service.OsBtmServiceI; import com.vci.web.service.WebBoServiceI; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.vci.ubcs.code.dto.CodeClassifyTemplateAttrDTO; import com.vci.ubcs.code.vo.pagemodel.CodeClassifyTemplateAttrVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; import static com.vci.frameworkcore.constant.FrameWorkLangCodeConstant.*; /** * 主题库分类的模板属性服务 * @author weidy * @date 2022-01-24 */ @Service public class CodeClassifyTemplateAttrServiceImpl implements CodeClassifyTemplateAttrServiceI { /** * 日志 */ private Logger logger = LoggerFactory.getLogger(getClass()); /** * 数据操作层 */ @Resource private CodeClassifyTemplateAttrDaoI codeClassifyTemplateAttrMapper; /** * 模板数据操作层 */ @Resource private CodeClassifyTemplateDaoI codeClassifyTemplateMapper; /** * 模板数据操作层 */ @Resource private CodeTemplatePhaseServiceI codeTemplatePhaseServiceI; /** * 业务类型操作的服务 */ @Autowired @Lazy private WebBoServiceI boService; /** * 对象的操作 */ @Autowired private RevisionModelUtil revisionModelUtil; /** * 查询这个业务类型的所有属性 */ @Autowired private OsBtmServiceI btmService; /** * 可选可输服务 */ @Autowired private BdSelectInputCharServiceI charService; /** * 属性的服务 */ @Autowired private OsAttributeServiceI attributeService; /** * 查询所有的主题库分类的模板属性 * @param conditionMap 查询条件 * @param pageHelper 分页和排序 * @return 执行结果 * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 */ @Override public DataGrid gridCodeClassifyTemplateAttr(Map conditionMap, PageHelper pageHelper) throws VciBaseException{ DataGrid dataGrid=new DataGrid(); //没有传递参数,就不执行查询逻辑 if(conditionMap.size()==0){ dataGrid.setData(new ArrayList<>()); dataGrid.setTotal(0); return dataGrid; } if (pageHelper == null) { pageHelper = new PageHelper(-1); } pageHelper.addDefaultAsc("ordernum"); List doList = codeClassifyTemplateAttrMapper.selectByCondition(conditionMap,pageHelper); if (!CollectionUtils.isEmpty(doList)) { dataGrid.setData(codeClassifyTemplateAttrDO2VOs(doList)); dataGrid.setTotal(VciBaseUtil.getInt(String.valueOf(codeClassifyTemplateAttrMapper.countByCondition(conditionMap)))); } return dataGrid; } /** * 批量数据对象转换为显示对象 * @param codeClassifyTemplateAttrDOs 数据对象列表 * @return 显示对象 * @throws VciBaseException 参数为空或者不存在的时候会抛出异常 */ @Override public List codeClassifyTemplateAttrDO2VOs(Collection codeClassifyTemplateAttrDOs) throws VciBaseException{ List voList = new ArrayList(); if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOs)){ for(CodeClassifyTemplateAttrDO s: codeClassifyTemplateAttrDOs){ CodeClassifyTemplateAttrVO vo = codeClassifyTemplateAttrDO2VO(s); if(vo != null){ voList.add(vo); } } } return voList; } /** * 数据对象转换为显示对象 * @param codeClassifyTemplateAttrDO 数据对象 * @return 显示对象 * @throws VciBaseException 拷贝属性出错的时候会抛出异常 */ @Override public CodeClassifyTemplateAttrVO codeClassifyTemplateAttrDO2VO(CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO) throws VciBaseException{ CodeClassifyTemplateAttrVO vo = new CodeClassifyTemplateAttrVO(); if(codeClassifyTemplateAttrDO != null){ BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDO,vo); //如果有lcstatus的类的话 vo.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(vo.getAttributedatatype())); } return vo; } /** * 增加主题库分类的模板属性 * @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象 * @return 执行结果 * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 */ @Override public CodeClassifyTemplateAttrVO addSave(CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{ VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"需要添加的数据对象"); //将DTO转换为DO CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = new CodeClassifyTemplateAttrDO(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO); codeClassifyTemplateAttrMapper.insert(codeClassifyTemplateAttrDO); return codeClassifyTemplateAttrDO2VO(codeClassifyTemplateAttrDO); } /** * 批量添加 * @param codeClassifyTemplateAttrDTOs 数据传输对象 * @return 保存后的显示对象 * @throws VciBaseException 执行出错的时候会抛出异常 */ @Override public List batchAddSave(List codeClassifyTemplateAttrDTOs) throws VciBaseException{ if(CollectionUtils.isEmpty(codeClassifyTemplateAttrDTOs)){ return new ArrayList<>(); } //取所有属性的英文名称,第三个验证需要用到 Map attrDTOMap =codeClassifyTemplateAttrDTOs.stream().collect(Collectors.toMap(s->s.getId().toLowerCase(Locale.ROOT), t->t)); //找属性中文名字重复 Map nameCountMap = codeClassifyTemplateAttrDTOs.stream().collect(Collectors.groupingBy(s -> s.getName(), Collectors.counting())); List repeatNameList = nameCountMap.keySet().stream().filter(s -> nameCountMap.get(s) > 1).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(repeatNameList)){ throw new VciBaseException("模板属性中文名称【{0}】重复",new String[]{ repeatNameList.stream().collect(Collectors.joining(","))}); } //找属性英文名字重复 Map idCountMap = codeClassifyTemplateAttrDTOs.stream().collect(Collectors.groupingBy(s -> s.getId().toLowerCase(Locale.ROOT), Collectors.counting())); List repeatIdList = idCountMap.keySet().stream().filter(s -> idCountMap.get(s) > 1).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(repeatIdList)){ throw new VciBaseException("模板属性英文名称【{0}】重复",new String[]{ repeatIdList.stream().collect(Collectors.joining(","))}); } //模板oid String CLASSIFYTEMPLATEOID = null; //转换 List codeClassifyTemplateAttrDOInsert = new ArrayList(); List prefix = new ArrayList<>(); List suffix = new ArrayList<>(); List dateFormates = new ArrayList<>(); for (CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO:codeClassifyTemplateAttrDTOs){ VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"需要添加的数据对象"); //将DTO转换为DO CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = new CodeClassifyTemplateAttrDO(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO); codeClassifyTemplateAttrDOInsert.add(codeClassifyTemplateAttrDO); if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getPrefixValue())){ prefix.add(codeClassifyTemplateAttrDO.getPrefixValue()); } if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getSuffixValue())){ suffix.add(codeClassifyTemplateAttrDO.getSuffixValue()); } if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getCodeDateFormat())){ dateFormates.add(codeClassifyTemplateAttrDO.getCodeDateFormat()); } //判断传过来的枚举注入是否是jsonArr格式 if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getEnumString())&&!checkKVArr(codeClassifyTemplateAttrDO.getEnumString())){ throw new VciBaseException("{0}{1}属性的枚举注入数据格式错误!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()}); } //分类注入 if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getClassifyInvokeAttr()) && !CodeLevelTypeEnum.MIN.getValue().equalsIgnoreCase(codeClassifyTemplateAttrDO.getClassifyInvokeLevel()) && VciBaseUtil.getInt(codeClassifyTemplateAttrDO.getClassifyInvokeLevel()) < 0){ throw new VciBaseException("{0}{1}属性的是分类注入,但是注入层级不能小于0!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()}); } //判断传过来的参照配置是否是json格式 if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getReferConfig())&&!checkKVObj(codeClassifyTemplateAttrDO.getReferConfig())){ throw new VciBaseException("{0}{1}属性的参照配置数据格式错误!",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()}); } if(StringUtils.isNotBlank(codeClassifyTemplateAttrDO.getCodeDateFormat()) && !checkDateFormat(codeClassifyTemplateAttrDO.getCodeDateFormat())){ throw new VciBaseException("{0}{1}属性的时间格式不符合要求",new String[]{codeClassifyTemplateAttrDO.getId(),codeClassifyTemplateAttrDO.getName()}); } //如果是组合规则,里面使用的属性不能缺失,也都得显示 String componentrule = codeClassifyTemplateAttrDTO.getComponentrule(); boolean isContainsDynamicParameter = PatternUtil.isContainsDynamicParameter(componentrule); if(isContainsDynamicParameter){ List userdAttrList = PatternUtil.getKeyListByContent(componentrule);//包含的所有${xxx}中的xxx if(!CollectionUtils.isEmpty(userdAttrList)){ String unExistAttr = userdAttrList.stream().filter(s -> !attrDTOMap.containsKey(s.toLowerCase(Locale.ROOT))).collect(Collectors.joining(",")); if(StringUtils.isNotBlank(unExistAttr)){ throw new VciBaseException("{0}属性是组合规则,但是规则里包含的属性[{1}]在当前模板中不存在!",new String[]{codeClassifyTemplateAttrDO.getName(), unExistAttr}); } //要看看表单是否显示 String unFormDisplayAttr = userdAttrList.stream().filter(s -> !VciBaseUtil.getBoolean(attrDTOMap.getOrDefault(s.toLowerCase(Locale.ROOT), new CodeClassifyTemplateAttrDTO()).getFormdisplayflag())).collect(Collectors.joining(",")); if(StringUtils.isNotBlank(unFormDisplayAttr)){ throw new VciBaseException("{0}属性是组合规则,但是规则里包含的属性[{1}]在当前模板中没有设置 表单显示 ",new String[]{codeClassifyTemplateAttrDO.getName(),unFormDisplayAttr}); } } } if(CLASSIFYTEMPLATEOID==null){ CLASSIFYTEMPLATEOID = codeClassifyTemplateAttrDTO.getClassifytemplateoid(); } } //执行数据保存操作 WebUtil.setPersistence(false);//不执行保存 //先都删了 VciQueryWrapperForDO deleteAttrWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class); deleteAttrWrapper.addQueryMap("CLASSIFYTEMPLATEOID",CLASSIFYTEMPLATEOID); List codeClassifyTemplateAttrDODelete = codeClassifyTemplateAttrMapper.selectByWrapper(deleteAttrWrapper); //oids List oids = new ArrayList(); for (CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDODelete){ oids.add(codeClassifyTemplateAttrDO.getOid()); } BatchCBO batchCBOTemplateDelete = new BatchCBO(); if(!CollectionUtils.isEmpty(oids)){ batchCBOTemplateDelete = codeClassifyTemplateAttrMapper.batchDeleteByOids(oids); } //再新增 if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOInsert)){ BatchCBO batchCBOTemplateAdd = codeClassifyTemplateAttrMapper.batchInsert(codeClassifyTemplateAttrDOInsert); batchCBOTemplateDelete.copyFromOther(batchCBOTemplateAdd); } //调用阶段 if(!CollectionUtils.isEmpty(codeClassifyTemplateAttrDOInsert)){ BatchCBO batchCBO0 = codeTemplatePhaseServiceI.codeTemplateAttrModifyTrigger(codeClassifyTemplateAttrDOInsert); batchCBOTemplateDelete.copyFromOther(batchCBO0); } SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo(); //处理可输可选的字符 if(!CollectionUtils.isEmpty(prefix)){ charService.saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"prefix",prefix,sessionInfo); } if(!CollectionUtils.isEmpty(suffix)){ charService.saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"suffix",suffix,sessionInfo); } if(!CollectionUtils.isEmpty(dateFormates)){ charService.saveBySameNamespaceAndFlag(MdmBtmTypeConstant.CODE_CLASSIFY_TEMPLATE_ATTR,"dateFormates",dateFormates,sessionInfo); } WebUtil.setPersistence(true);//执行保存 boService.persistenceBatch(batchCBOTemplateDelete);//一起执行保存 return codeClassifyTemplateAttrDO2VOs(codeClassifyTemplateAttrDOInsert); } /** * 修改主题库分类的模板属性 * @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象 * @return 执行结果 * @throws VciBaseException 参数为空,唯一项,必输项不通过时会抛出异常 */ @Override public BaseResult editSave(CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{ VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"数据对象",codeClassifyTemplateAttrDTO.getOid(),"主题库分类的模板属性主键"); //判断传过来的枚举注入是否是jsonArr格式 if(StringUtils.isNotBlank(codeClassifyTemplateAttrDTO.getEnumString())&&!checkKVArr(codeClassifyTemplateAttrDTO.getEnumString())){ throw new VciBaseException("枚举注入数据格式错误!"); } //判断传过来的参照配置是否是json格式 if(StringUtils.isNotBlank(codeClassifyTemplateAttrDTO.getReferbtmid())&&!checkKVObj(codeClassifyTemplateAttrDTO.getReferbtmid())){ throw new VciBaseException("枚举注入数据格式错误!"); } //检查ts CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDOCopyFromDTO = new CodeClassifyTemplateAttrDO(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDOCopyFromDTO); boolean tsBoolean = boService.checkTs(codeClassifyTemplateAttrDOCopyFromDTO); if(!tsBoolean){//不是最新的不让改 return BaseResult.fail("当前数据不是最新,请刷新后再修改!"); } //将DTO转换为DO CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = selectByOid(codeClassifyTemplateAttrDTO.getOid()); revisionModelUtil.copyFromDTOIgnore(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO); codeClassifyTemplateAttrMapper.updateByPrimaryKey(codeClassifyTemplateAttrDO); return BaseResult.success(codeClassifyTemplateAttrDO2VO(codeClassifyTemplateAttrDO)); } /** * 校验是否可以删除,如果存在下级,并且下级有数据引用则不能删除 * @param codeClassifyTemplateAttrDTO 数据传输对象 * @param codeClassifyTemplateAttrDO 数据库中的数据对象 * @return success为true为可以删除,false表示有数据引用,obj为true表示有下级 */ private BaseResult checkIsCanDeleteForDO(CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO, CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO) { boService.checkTs(codeClassifyTemplateAttrDO); if(!checkIsLinked(codeClassifyTemplateAttrDO.getOid())) { return BaseResult.success(); }else{ return BaseResult.fail(DATA_LINKED_NOT_DELETE,new String[]{""}); } } /** * 校验是否被引用 * @param oid 主键 * @throws VciBaseException 被引用的时候会抛出异常 */ private boolean checkIsLinked(String oid) throws VciBaseException{ //TODO 添加需要校验引用的地方 return false; } /** * 删除主题库分类的模板属性 * @param codeClassifyTemplateAttrDTO 主题库分类的模板属性数据传输对象,oid和ts需要传输 * @return 删除结果反馈::success:成功,fail:失败 * @throws VciBaseException 参数为空,被引用时抛出异常 */ @Override public BaseResult deleteCodeClassifyTemplateAttr(CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{ VciBaseUtil.alertNotNull(codeClassifyTemplateAttrDTO,"主题库分类的模板属性数据对象",codeClassifyTemplateAttrDTO.getOid(),"主题库分类的模板属性的主键"); CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = selectByOid(codeClassifyTemplateAttrDTO.getOid()); BaseResult baseResult = checkIsCanDeleteForDO(codeClassifyTemplateAttrDTO,codeClassifyTemplateAttrDO); if(baseResult.isSuccess()) { }else{ return baseResult; } //执行删除操作 BatchCBO batchCBO = codeClassifyTemplateAttrMapper.deleteByPrimaryKey(codeClassifyTemplateAttrDO.getOid()); return (batchCBO!=null && batchCBO.getDeleteCbos() !=null &&batchCBO.getDeleteCbos().size() > 0)?BaseResult.successMsg(DELETE_SUCCESS):BaseResult.fail(DELETE_FAIL); } /** * 主键获取主题库分类的模板属性 * @param oid 主键 * @return 主题库分类的模板属性显示对象 * @throws VciBaseException 参数为空,数据不存在时会抛出异常 */ @Override public CodeClassifyTemplateAttrVO getObjectByOid(String oid) throws VciBaseException{ return codeClassifyTemplateAttrDO2VO(selectByOid(oid)); } /** * 主键查询数据对象 * @param oid 主键 * @return 数据对象 * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 */ private CodeClassifyTemplateAttrDO selectByOid(String oid) throws VciBaseException{ VciBaseUtil.alertNotNull(oid,"主键"); CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = codeClassifyTemplateAttrMapper.selectByPrimaryKey(oid.trim()); if(codeClassifyTemplateAttrDO == null || StringUtils.isBlank(codeClassifyTemplateAttrDO.getOid())){ throw new VciBaseException(DATA_OID_NOT_EXIST); } return codeClassifyTemplateAttrDO; } /** * 主键批量获取主题库分类的模板属性 * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 * @return 主题库分类的模板属性显示对象 * @throws VciBaseException 查询出现异常时会抛出 */ @Override public Collection listCodeClassifyTemplateAttrByOids(Collection oidCollections) throws VciBaseException{ VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); List codeClassifyTemplateAttrDOList = listCodeClassifyTemplateAttrDOByOidCollections(oidCollections); return codeClassifyTemplateAttrDO2VOs(codeClassifyTemplateAttrDOList); } /** * 使用主键集合查询数据对象 * @param oidCollections 主键的集合 * @return 数据对象列表 */ private List listCodeClassifyTemplateAttrDOByOidCollections(Collection oidCollections){ List codeClassifyTemplateAttrDOList = new ArrayList(); if(!CollectionUtils.isEmpty(oidCollections)){ Collection> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); for(Collection oids: oidCollectionsList){ List tempDOList = codeClassifyTemplateAttrMapper.selectByPrimaryKeyCollection(oids); if(!CollectionUtils.isEmpty(tempDOList)){ codeClassifyTemplateAttrDOList.addAll(tempDOList); } } } return codeClassifyTemplateAttrDOList; } /** * 参照主题库分类的模板属性列表 * @param conditionMap 查询条件 * @param pageHelper 分页和排序 * @return 主题库分类的模板属性显示对象列表,生效的内容 * @throws VciBaseException 查询条件和分页出错的时候会抛出异常 */ @Override public DataGrid refDataGridCodeClassifyTemplateAttr(Map conditionMap, PageHelper pageHelper) throws VciBaseException{ if(conditionMap == null){ conditionMap = new HashMap(); } return gridCodeClassifyTemplateAttr(conditionMap,pageHelper); } /** * 查询这个模板,业务类型下的所有未选择的属性 * @param baseQueryObject * @return */ @Override public DataGrid codeClassifyTemplateAttrByBtm(BaseQueryObject baseQueryObject){ if(baseQueryObject.getConditionMap() == null){ baseQueryObject.setConditionMap(new HashMap<>()); } DataGrid dataGrid=new DataGrid(); //模板oid String templateAttrOid = baseQueryObject.getConditionMap().get("oid"); String name = baseQueryObject.getConditionMap().getOrDefault("name",""); String id = baseQueryObject.getConditionMap().getOrDefault("id",""); //没有oid不执行逻辑 if(StringUtils.isBlank(templateAttrOid)){ dataGrid.setData(new ArrayList<>()); dataGrid.setTotal(0); return dataGrid; } //查询模板对象 CodeClassifyTemplateDO codeClassifyTemplateDO = codeClassifyTemplateMapper.selectByPrimaryKey(templateAttrOid); //这个业务类型下的所有属性 List boAttrs = this.btmService.listAttributeByBtmId(codeClassifyTemplateDO.getBtmTypeId()); //把默认的属性也添加到boAttrs if(boAttrs == null){ boAttrs = new ArrayList<>(); } if(!CollectionUtils.isEmpty(attributeService.getDefaultAttributeVOs())){ List finalBoAttrs = boAttrs; attributeService.getDefaultAttributeVOs().stream().forEach(attr-> { OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO(); BeanUtil.convert(attr, attributeVO); if (VciQueryWrapperForDO.ID_FIELD.equalsIgnoreCase(attributeVO.getId())) { attributeVO.setName("企业编码"); } if ("name".equalsIgnoreCase(attributeVO.getId())) { attributeVO.setName("集团码"); } attributeVO.setAttrDataType(attr.getAttributeDataType()); attributeVO.setAttributeLength(attr.getAttrLength()); attributeVO.setReferBtmTypeId(attr.getBtmTypeId()); attributeVO.setReferBtmTypeName(attr.getBtmTypeName()); finalBoAttrs.add(attributeVO); }); boAttrs = finalBoAttrs; } //这个模板下已经有的属性 VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class); queryWrapper.addQueryMap("CLASSIFYTEMPLATEOID",templateAttrOid); List codeClassifyTemplateAttrDOList = codeClassifyTemplateAttrMapper.selectByWrapper(queryWrapper); List btmOids = new ArrayList(); for (CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDOList){ btmOids.add(codeClassifyTemplateAttrDO.getId()); } //过滤掉已经存在的属性 List boAttrss = new ArrayList(); for (OsBtmTypeAttributeVO osBtmTypeAttributeVO:boAttrs){ if(!btmOids.contains(osBtmTypeAttributeVO.getId())){ //看看是不是有模糊查询 boolean inSearch = true; if(StringUtils.isNotBlank(name) && !osBtmTypeAttributeVO.getName().contains(name.replace("*",""))){ inSearch = false; } if(StringUtils.isNotBlank(id) && !osBtmTypeAttributeVO.getId().contains(id.replace("*",""))){ inSearch = false; } if(inSearch) { boAttrss.add(osBtmTypeAttributeVO); } } } dataGrid.setData(boAttrss); dataGrid.setTotal(boAttrss.size()); return dataGrid; } /** * 查询这个模板,业务类型下已选择的属性 * @param baseQueryObject * @return */ @Override public DataGrid codeClassifyTemplateAttrByBtmHave(BaseQueryObject baseQueryObject){ DataGrid dataGrid=new DataGrid(); //模板oid String templateAttrOid = baseQueryObject.getConditionMap().get("oid"); //没有oid不执行逻辑 if(StringUtils.isBlank(templateAttrOid)){ dataGrid.setData(new ArrayList<>()); dataGrid.setTotal(0); return dataGrid; } //查询模板对象 CodeClassifyTemplateDO codeClassifyTemplateDO = codeClassifyTemplateMapper.selectByPrimaryKey(templateAttrOid); //这个业务类型下的所有属性 List boAttrs = this.btmService.listAttributeByBtmIdHasDefault(codeClassifyTemplateDO.getBtmTypeId()); //这个模板下已经有的属性 VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class); queryWrapper.addQueryMap("CLASSIFYTEMPLATEOID",templateAttrOid); List codeClassifyTemplateAttrDOList = codeClassifyTemplateAttrMapper.selectByWrapper(queryWrapper); List btmOids = new ArrayList(); for (CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO:codeClassifyTemplateAttrDOList){ btmOids.add(codeClassifyTemplateAttrDO.getId()); } //过滤掉除了自身的别的属性 List boAttrss = new ArrayList(); for (OsBtmTypeAttributeVO osBtmTypeAttributeVO:boAttrs){ if(btmOids.contains(osBtmTypeAttributeVO.getId())){ boAttrss.add(osBtmTypeAttributeVO); } } dataGrid.setData(boAttrss); dataGrid.setTotal(boAttrss.size()); return dataGrid; } /** * 同步到其他模板 * @param codeClassifyTemplateAttrDTO oid * @return */ @Override public BaseResult copyto(CodeClassifyTemplateAttrDTO codeClassifyTemplateAttrDTO) throws VciBaseException{ String templateAttrOid = codeClassifyTemplateAttrDTO.getOid(); //查询出来要复制的对象 CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDO = selectByOid(templateAttrOid); String id = codeClassifyTemplateAttrDO.getId();//英文名称 String classfyTemplateOid = codeClassifyTemplateAttrDO.getClassifyTemplateOid(); //查询其他id=id的模板属性 VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(CodeClassifyTemplateAttrDO.class); queryWrapper.addQueryMap("id",id); //所有id=id的模板属性 List codeClassifyTemplateAttrDOList = codeClassifyTemplateAttrMapper.selectByWrapper(queryWrapper); //要删除的模板属性的oids List deleteOids = new ArrayList(); //要修改的模板属性对象 List codeClassifyTemplateAttrDOListInsert = new ArrayList(); for (CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDOi:codeClassifyTemplateAttrDOList){ String oid = codeClassifyTemplateAttrDOi.getOid(); String templateOldOid = codeClassifyTemplateAttrDOi.getClassifyTemplateOid(); CodeClassifyTemplateAttrDO codeClassifyTemplateAttrDOInsert = new CodeClassifyTemplateAttrDO(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeClassifyTemplateAttrDO,codeClassifyTemplateAttrDOInsert); codeClassifyTemplateAttrDOInsert.setOid(oid); codeClassifyTemplateAttrDOInsert.setClassifyTemplateOid(templateOldOid); codeClassifyTemplateAttrDOListInsert.add(codeClassifyTemplateAttrDOInsert); deleteOids.add(codeClassifyTemplateAttrDOi.getOid()); } WebUtil.setPersistence(false);//不执行保存 //删除 BatchCBO batchCBOTemplateAttrDelete = codeClassifyTemplateAttrMapper.batchDeleteByOids(deleteOids); //再新增 BatchCBO batchCBOTemplateAttrInsert = codeClassifyTemplateAttrMapper.batchInsert(codeClassifyTemplateAttrDOListInsert); batchCBOTemplateAttrDelete.copyFromOther(batchCBOTemplateAttrInsert); WebUtil.setPersistence(true);//执行保存 boService.persistenceBatch(batchCBOTemplateAttrDelete);//一起执行保存 return BaseResult.success(); } /** * 使用模板的主键获取模板的属性--批量 * * @param templateOidCollection 模板的主键 * @return 属性的信息 */ @Override public List listCodeClassifyTemplateAttrByTemplateOids(Collection templateOidCollection) { if(CollectionUtils.isEmpty(templateOidCollection)){ return new ArrayList<>(); } List attrDOList = new ArrayList<>(); VciBaseUtil.switchCollectionForOracleIn(templateOidCollection).stream().forEach(templateOids->{ Map conditionMap = new HashMap<>(); conditionMap.put("classifytemplateoid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(templateOids.toArray(new String[0])) + ")"); PageHelper pageHelper = new PageHelper(-1); pageHelper.addDefaultAsc("orderNum"); List attrDOS = codeClassifyTemplateAttrMapper.selectByCondition(conditionMap, pageHelper); if(!CollectionUtils.isEmpty(attrDOS)){ attrDOList.addAll(attrDOS); } }); return codeClassifyTemplateAttrDO2VOs(attrDOList); } public boolean checkKVArr(String kvString){ boolean isKV = true; try { JSONObject.parseArray(kvString, KeyValue.class); }catch (Exception e){ isKV=false; } return isKV; } public boolean checkKVObj(String kvString){ boolean isKV = true; try { JSONObject.parseObject(kvString, UIFormReferVO.class); }catch (Exception e){ isKV=false; } return isKV; } /** * 校验时间格式 * @param dateFormat 时间格式 * @return true表示校验通过 */ public boolean checkDateFormat(String dateFormat){ try{ VciDateUtil.date2Str(new Date(),dateFormat); return true; }catch (Throwable e){ return false; } } }