| | |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.starter.web.annotation.Column; |
| | | import com.vci.starter.web.annotation.VciFieldType; |
| | | import com.vci.starter.web.constant.QueryOptionConstant; |
| | | import com.vci.starter.web.enumpck.BooleanEnum; |
| | | import com.vci.starter.web.enumpck.VciFieldTypeEnum; |
| | | 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.BeanUtilForVCI; |
| | | import com.vci.starter.web.util.Lcm.Func; |
| | | 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.properties.WebProperties; |
| | | import com.vci.web.service.*; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.math3.distribution.TDistribution; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.DocumentHelper; |
| | | import org.slf4j.Logger; |
| | |
| | | // 一层参照 a.b |
| | | // 第二个参数给空,是此不处从属性中查其参数的业务类型,由下下专用掊中进行处理 |
| | | BtmRefQueryOption refOpt = new BtmRefQueryOption( |
| | | kvs[0], "", new String[]{kvs[1]} |
| | | kvs[0], "", new String[]{kvs[1]} |
| | | ); |
| | | refOpts.add(refOpt); |
| | | } else if(len == 3){ |
| | |
| | | // 三层以的参照 a.b.c.d a.b.c.d.e |
| | | // TODO 需要支持三层以及以上的参照 |
| | | } |
| | | }else if(attrName.indexOf("_")>-1 |
| | | }else if(attrName.indexOf("_")>-1 |
| | | && !"lcStatus_text".toLowerCase().equalsIgnoreCase(attrName.toLowerCase())){ |
| | | enumAttrName.add(attrName); |
| | | }else{ |
| | |
| | | ObjectQueryService.FindBTMObjectsV3Result bos = qtService.findBTMObjectsV3(qt.getId(), OQTool.qtTOXMl(qt).asXML(), refOpts.toArray(new BtmRefQueryOption[refOpts.size()])); |
| | | if (bos != null && bos.count > 0) { |
| | | for (BusinessObject bo : bos.returnValue) { |
| | | // BusinessObject cbo = new BusinessObject(); |
| | | // cbo = bo; |
| | | queryEnumText(bo,enumAttrName); |
| | | allCbos.add(bo); |
| | | } |
| | |
| | | Map<String, OsStatusVO> statusVOMap = statusService.selectAllStatusMap(); |
| | | cbos.stream().forEach(cbo->{ |
| | | try{ |
| | | ObjectTool.setBOAttributeValue(cbo,"lcStatus_text", statusVOMap.getOrDefault(cbo.lcStatus,new OsStatusVO()).getName()); |
| | | ObjectTool.setBOAttributeValue(cbo,"lcStatus_text".toLowerCase(), statusVOMap.getOrDefault(cbo.lcStatus,new OsStatusVO()).getName()); |
| | | }catch(Exception e){ |
| | | logger.error("获取生命周期中状态的显示文本出错",e); |
| | | } |
| | |
| | | @Override |
| | | public void queryEnumText(BusinessObject cbo, LinkObject clo, List<String> enumAttrName) throws VciBaseException{ |
| | | if(enumAttrName.size()>0){//查询枚举 |
| | | for(String enumAttr:enumAttrName){//格式为 code_field code是枚举的编码,field是当前业务类型存储枚举值的字段 |
| | | for(String enumAttr : enumAttrName){//格式为 code_field code是枚举的编码,field是当前业务类型存储枚举值的字段 |
| | | if(enumAttr.toLowerCase().equals("creator_name")){ |
| | | //创建人的名称 |
| | | String creator = ""; |
| | |
| | | String enumCode = tempArray[0];//枚举编码 |
| | | if (tempArray.length > 1) { |
| | | //从枚举中获取值 |
| | | String valueFieldName = tempArray[1]; |
| | | String valueFieldName = tempArray[1];//枚举在业务类型上存放的属性 |
| | | String comboxField = ""; |
| | | if(valueFieldName.contains("#")){ |
| | | valueFieldName = tempArray[1].split("#")[0]; |
| | | comboxField = tempArray[1].split("#")[1]; |
| | | } |
| | | //获取枚举项 |
| | | String enumKey = ""; |
| | | if (cbo != null) { |
| | | enumKey = ObjectTool.getBOAttributeValue(cbo,valueFieldName); |
| | | } else if (clo != null) { |
| | | enumKey = ObjectTool.getLOAttributeValue(clo,valueFieldName); |
| | | } |
| | | //获取枚举项的中文显示 |
| | | String enumText = ""; |
| | | if (WebUtil.isNotNull(enumKey)) { |
| | | enumText = enumService.getValue(enumCode, enumKey); |
| | |
| | | * @throws VciBaseException 查询出错会抛出异常 |
| | | */ |
| | | @Override |
| | | public List<BusinessObject> queryCBOByScheme(String queryScheme, |
| | | Map<String, String> conditionMap, Map<String, Object> replaceMap, |
| | | PageHelper ph, List<String> clauseList) throws VciBaseException { |
| | | public List<BusinessObject> queryCBOByScheme(String queryScheme, Map<String, String> conditionMap, Map<String, Object> replaceMap, |
| | | PageHelper ph, List<String> clauseList) throws VciBaseException { |
| | | QueryTemplate qt = getQtByName(queryScheme,replaceMap); |
| | | return baseQueryCBO(qt,conditionMap,ph,clauseList); |
| | | } |
| | |
| | | /** |
| | | * 只用sql语句查询,这个和queryBySqlForMap区别是,特殊的sql(如包含有函数的)可以用这个方法,但是有sql注入风险 |
| | | * @param sql sql语句,查询条件必须自行在其中处理完成 |
| | | * @return 数据映射 |
| | | * @return 数据映射。Map中,key值为大写。 |
| | | * @throws VciBaseException 查询出错活抛出异常 |
| | | */ |
| | | @Override |
| | |
| | | List<Map> allData = queryByOnlySqlForMap(sql); |
| | | //需要转换一下cbo的那个属性 |
| | | Map<String/**业务类型中的字段*/, String/**属性里的字段**/> fieldNameMap = WebUtil.getFieldNameMap(tClass); |
| | | Map<String, Field> fieldMap = WebUtil.getFieldMapForObject(tClass); |
| | | List<T> dataList = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(allData)){ |
| | | allData.stream().forEach(data->{ |
| | | Map thisData = new HashMap(); |
| | | if(!CollectionUtils.isEmpty(data)){ |
| | | data.forEach((key,value)->{ |
| | | thisData.put(fieldNameMap.getOrDefault(((String)key).toLowerCase(Locale.ROOT), (String) key),value); |
| | | String fieldName = fieldNameMap.getOrDefault(((String)key).toLowerCase(Locale.ROOT), (String) key); |
| | | String fieldValue = String.valueOf(value); |
| | | if(fieldMap.containsKey(fieldName)){ |
| | | Field field = fieldMap.get(fieldName); |
| | | if(field.isAnnotationPresent(VciFieldType.class)){ |
| | | VciFieldType vciFieldType = field.getAnnotation(VciFieldType.class); |
| | | VciFieldTypeEnum vciFieldTypeEnum = vciFieldType.value(); |
| | | if(VciFieldTypeEnum.VTDateTime.equals(vciFieldTypeEnum) && StringUtils.isNotBlank(fieldValue)){ |
| | | fieldValue = VciDateUtil.date2Str(VciDateUtil.long2Date(Long.parseLong(fieldValue)), VciDateUtil.DateTimeFormat); |
| | | } |
| | | if(VciFieldTypeEnum.VTDate.equals(vciFieldTypeEnum) && StringUtils.isNotBlank(fieldValue)){ |
| | | fieldValue = VciDateUtil.date2Str(VciDateUtil.long2Date(Long.parseLong(fieldValue)), VciDateUtil.DateFormat); |
| | | } |
| | | if(VciFieldTypeEnum.VTTime.equals(vciFieldTypeEnum) && StringUtils.isNotBlank(fieldValue)){ |
| | | fieldValue = VciDateUtil.date2Str(VciDateUtil.long2Date(Long.parseLong(fieldValue)), VciDateUtil.TimeFormat); |
| | | } |
| | | } |
| | | } |
| | | thisData.put(fieldName,fieldValue); |
| | | }); |
| | | } |
| | | try { |
| | |
| | | * 根据sql语句来查询内容,返回Map----sql不能是select * 或者 select t.* |
| | | * @param sql 为了防止SQL注入,值必须在sql语句里以:xxx格式,如 id =:idvalue,然后在conditionMap中添加建为idvalue的格式 |
| | | * @param conditionMap 查询条件,必须与sql里对应 |
| | | * @return 业务数据的映射 |
| | | * @return 业务数据的映射。 |
| | | * @throws VciBaseException 查询出错会抛出异常 |
| | | */ |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * 和上个方法一样,多传了查询字段 selectKeys |
| | | * 和上个方法一样,多传了查询字段 selectKeys。sql不能是select * 或者 select t.* |
| | | * @param sql sql语句 |
| | | * @param conditionMap 查询条件 |
| | | * @param selectKeys 查询的字段 |
| | |
| | | ava = new AttributeValue[0]; |
| | | } |
| | | try { |
| | | String[][] results =platformClientUtil.getSqlQueryService(sql, ava); |
| | | String[][] results = platformClientUtil.getSqlQueryService(sql, ava); |
| | | if(results.length>0){ |
| | | if(selectKeys==null) { |
| | | String selectSql = sql.substring(sql.toLowerCase(Locale.ROOT).indexOf("select") + 6, sql.toLowerCase(Locale.ROOT).indexOf(" from")).trim(); |
| | |
| | | swapConditionMap(c,conditionMap); |
| | | //获取要查询的所有的列 |
| | | Map<String,String> allFieldAttrMap = WebUtil.getFieldNameMap(c); |
| | | if(!allFieldAttrMap.containsKey("lctid")){ |
| | | allFieldAttrMap.put("lctid","lctid"); |
| | | //修改allFieldAttrMap集合中的key的大小写 |
| | | List<String> queryAttr = new ArrayList<String>(); |
| | | Iterator<String> it = allFieldAttrMap.keySet().iterator(); |
| | | while(it.hasNext()){ |
| | | queryAttr.add(it.next()); |
| | | } |
| | | List<String> queryAttr = new ArrayList<String>(); |
| | | Iterator<String> it = allFieldAttrMap.keySet().iterator(); |
| | | while(it.hasNext()){ |
| | | queryAttr.add(it.next()); |
| | | } |
| | | for(String columnName:queryAttr){ |
| | | String fieldName = allFieldAttrMap.get(columnName); |
| | | allFieldAttrMap.remove(columnName); |
| | | for(String columnName : queryAttr){ |
| | | String fieldName = allFieldAttrMap.get(columnName); |
| | | allFieldAttrMap.remove(columnName); |
| | | allFieldAttrMap.put(columnName.toLowerCase(),fieldName); |
| | | } |
| | | |
| | | List<T> allObject = new ArrayList<T>(); |
| | | List<BusinessObject> allCbos = queryCBO(WebUtil.getBtmTypeByObject(c), conditionMap, ph, allFieldAttrMap.keySet().stream().collect(Collectors.toList()));//执行查询 |
| | | List<String> oids = new ArrayList<String>(); |
| | | |
| | | if(allCbos!=null&&allCbos.size()>0){ |
| | | List<String> clauseList = new ArrayList<>(allFieldAttrMap.keySet()); |
| | | |
| | | List<BusinessObject> allCbos = queryCBO(WebUtil.getBtmTypeByObject(c).toLowerCase(), conditionMap, ph, clauseList); |
| | | if(!CollectionUtils.isEmpty(allCbos)){ |
| | | for(BusinessObject cbo : allCbos){ |
| | | T obj = null; |
| | | try { |
| | | obj = c.newInstance(); |
| | | WebUtil.copyValueToObjectFromCbos(cbo, obj,allFieldAttrMap);//为了少去查询一次字段 |
| | | } catch (InstantiationException e) { |
| | | WebUtil.copyValueToObjectFromCbos(cbo, obj, allFieldAttrMap);//为了少去查询一次字段 |
| | | } catch (Exception e) { |
| | | |
| | | } catch (IllegalAccessException e) { |
| | | } |
| | | if(obj !=null){ |
| | | oids.add(cbo.oid); |
| | | allObject.add(obj); |
| | | } |
| | | } |
| | |
| | | swapConditionMap(c,conditionMap); |
| | | //获取要查询的所有的列 |
| | | Map<String,String> allFieldAttrMap = WebUtil.getFieldNameMap(c); |
| | | //修改allFieldAttrMap集合中的key的大小写 |
| | | List<String> queryAttr = new ArrayList<String>(); |
| | | Iterator<String> it = allFieldAttrMap.keySet().iterator(); |
| | | while(it.hasNext()){ |
| | |
| | | allFieldAttrMap.remove(columnName); |
| | | allFieldAttrMap.put(columnName.toLowerCase(),fieldName); |
| | | } |
| | | List<String> clauseList = new ArrayList<>(allFieldAttrMap.keySet()); |
| | | List<T> allObject = new ArrayList<T>(); |
| | | List<BusinessObject> allCbos = queryCBOByScheme(queryScheme, conditionMap, replaceMap,ph, allFieldAttrMap.keySet().stream().collect(Collectors.toList())); |
| | | List<BusinessObject> allCbos = queryCBOByScheme(queryScheme, conditionMap, replaceMap,ph, clauseList); |
| | | List<String> oids = new ArrayList<String>(); |
| | | if(allCbos!=null&&allCbos.size()>0){ |
| | | if(allCbos != null && allCbos.size() > 0){ |
| | | for(BusinessObject cbo : allCbos){ |
| | | T obj = null; |
| | | try { |
| | | obj = c.newInstance(); |
| | | WebUtil.copyValueToObjectFromCbos(cbo, obj,allFieldAttrMap);//为了少去查询一次字段 |
| | | } catch (InstantiationException e) { |
| | | } catch (Exception e) { |
| | | |
| | | } catch (IllegalAccessException e) { |
| | | } |
| | | if(obj !=null){ |
| | | oids.add(cbo.oid); |
| | |
| | | //编辑的时候,TS和OID不能设置.因为平台那接口设置了就会报错 |
| | | }else { |
| | | //需要判断是否默认的属性,如果是默认属性,则使用对象的赋值的方式 |
| | | if (WebUtil.isDefaultField(fieldName) && WebUtil.inArray(new String[]{"id", "name", "description","lcstatus","revisionvalue","versionvalue"}, fieldName.toLowerCase())) { |
| | | WebUtil.setValueToField(fieldName, cbo, value); |
| | | ObjectTool.setBOAttributeValue(cbo, attrName.toLowerCase(), value); |
| | | } else { |
| | | ObjectTool.setBOAttributeValue(cbo, attrName.toLowerCase(), value); |
| | | if (WebUtil.isDefaultField(fieldName.toLowerCase()) && WebUtil.inArray(new String[]{"id", "name", "description","lcstatus","revisionvalue","versionvalue"}, fieldName.toLowerCase())) { |
| | | WebUtil.setValueToCboField(fieldName, cbo, value); |
| | | } |
| | | ObjectTool.setBOAttributeValue(cbo, attrName.toLowerCase(), value); |
| | | } |
| | | } |
| | | } |
| | |
| | | public <T> BatchCBO delete(T obj) throws VciBaseException { |
| | | return delete(obj,true); |
| | | } |
| | | |
| | | /** |
| | | * 删除数据,可以在request里设置不持久化 |
| | | * @param obj 删除数据对象 |
| | | * @param checkRefered 是否删除引用的数据 |
| | | * @return 需要创建的CBO,CLO;需要修改的CBO,CLO;需要删除的CBO,CLO |
| | | * @throws VciBaseException |
| | | */ |
| | | @Override |
| | | public <T> BatchCBO delete(T obj,boolean checkRefered) throws VciBaseException{ |
| | | List<T> list = new ArrayList<T>(); |
| | | list.add(obj); |
| | | return batchDelete(list,checkRefered); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量删除数据,可以在request里设置不持久化 |
| | |
| | | String btmType = WebUtil.getBtmTypeByObject(obj.getClass()); |
| | | String pkValue = WebUtil.getValueFromFieldForCbo(pkField, obj); |
| | | //所以这里也是直接查询的单个' |
| | | List<BusinessObject> deleteCbos = queryCBO(btmType, getOneQuery( |
| | | WebUtil.getCboAttrNameFromField(pkField, obj.getClass()), pkValue)); |
| | | if(deleteCbos!=null){ |
| | | List<BusinessObject> deleteCbos = queryCBO(btmType, getOneQuery(WebUtil.getCboAttrNameFromField(pkField, obj.getClass()), pkValue)); |
| | | if(!CollectionUtils.isEmpty(deleteCbos)){ |
| | | allDeleteCbos.addAll(deleteCbos); |
| | | if(!btmBos.containsKey(btmType)){ |
| | | btmBos.put(btmType, deleteCbos); |
| | |
| | | conditionMap.put(QUERY_FILTER_SECRET,BooleanEnum.FASLE.getValue());//查询的时候不能查询密级 |
| | | List<BusinessObject> allCbos = queryCBO(btmType, conditionMap); |
| | | BatchCBO batchCbo = new BatchCBO(); |
| | | if(allCbos.size()>0){ |
| | | if(!CollectionUtils.isEmpty(allCbos)){ |
| | | Map<String,List<BusinessObject>> btmBos = new HashMap<String, List<BusinessObject>>(); |
| | | btmBos.put(btmType, allCbos); |
| | | checkCanDelete(btmBos); |
| | | Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>(); |
| | | allDeleteCbos.addAll(allCbos); |
| | | Set<BusinessObject> allDeleteCbos = new HashSet<BusinessObject>(allCbos); |
| | | batchCbo.setDeleteCbos(allDeleteCbos); |
| | | } |
| | | if(allCbos.size()>0 && WebUtil.isPersistence()){ |
| | | if(!CollectionUtils.isEmpty(allCbos) && WebUtil.isPersistence()){ |
| | | persistenceBatch(batchCbo); |
| | | } |
| | | return batchCbo; |
| | |
| | | selectSql += ",btmname "; |
| | | } |
| | | sql = selectSql + fromSql; |
| | | List<BusinessObject> allDelete =queryBySql(sql, conditionMap); |
| | | List<BusinessObject> allDelete = queryBySql(sql, conditionMap); |
| | | if(allDelete.size() == 0){ |
| | | return batchCbo;//没有删除任何数据 |
| | | } |
| | |
| | | return queryGridByBo(btmType,conditionMap,new PageHelper(-1,true)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据业务类型来查询列表数据;可以在pageHelper中设置是否查询总数 |
| | | * @param btmType 业务类型名称 |
| | |
| | | public DataGrid queryGridByBo(String btmType, |
| | | Map<String, String> conditionMap, PageHelper ph) |
| | | throws VciBaseException { |
| | | return queryGridByBo(btmType,conditionMap,ph,null); |
| | | return queryGridByBo(btmType,conditionMap,ph,new ArrayList<String>()); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | List<BusinessObject> allCbos = queryCBO(btmType, conditionMap, ph, clauseList); |
| | | DataGrid dg = new DataGrid(); |
| | | if(allCbos.size()>0){ |
| | | if(!CollectionUtils.isEmpty(allCbos)){ |
| | | List<Map> mapList = cbos2Map(allCbos); |
| | | dg.setData(mapList); |
| | | //肯定是当前分页有值,才会有总数 |