AWC 批量查询使用关系的最新版本并导出Excel
1.查询使用关系的方法:
* 调用查询返回数据
* @param {Object} data
* @returns {Promise}
* */
export let queryItemRevisionById = function (data) {
if (!data.item_id) {
messagingService.showInfo("请输入查询条件");
return;
}
var item_id=data.item_id.dbValue.replace(' ',';');
//根据id查询对ITEMS
let itemQuery = {
inputCriteria: [{
queryNames: ['__QueryLastedItemRevision'],
queryType: 1
}]
}
soaSvc.post("Query-2010-04-SavedQuery", "findSavedQueries", itemQuery).then(async (findQuery) => {
var savedQuery = findQuery.savedQueries[0];
let queryItemsCondition = {
query: savedQuery,
entries: ["ID"],
values: [data.item_id.dbValue],
}
//查询ITem对象
return await soaSvc.post("Query-2006-03-SavedQuery", "executeSavedQuery", queryItemsCondition, policyIOverride).then(async (queryUserResponse1) => {
let queryParentCondition = {
objects: queryUserResponse1.objects,
numLevels: 1,
whereUsedPrecise: false,
rule: "最新版本",
}
//查询引用的对象
var queryUserResponse2 = await soaSvc.post("Core-2007-01-DataManagement", "whereUsed", queryParentCondition, policyIOverride).then(async (queryUserResponse2) => {
console.log(queryUserResponse2);
return queryUserResponse2;
}).catch(
function (error) {
console.log(error);
}
);
createDataTable(queryUserResponse1, queryUserResponse2);
}).catch(
function (error) {
console.log(error);
}
);;
});
}
2.创建表格:
let createDataTable = function (queryUserResponse1, queryUserResponse2) {
columns = [{
title: '子项',
columns: [{
title: '子项ID',
field: 'child_item_id',
width: 'auto'
},
{
title: '子项版本',
field: 'child_item_revision_id',
width: 'auto'
},
{
title: '子项名称',
field: 'child_object_name',
width: 'auto'
},
{
title: '子项描述',
field: 'child_object_desc',
width: 'auto'
},
{
title: '子项状态',
field: 'child_release_status_list',
width: 'auto'
},
{
title: '子项发布日期',
field: 'child_date_released',
width: 'auto'
},
{
title: '子项类型',
field: 'child_object_type',
width: 'auto'
},
{
title: '子项所有者',
field: 'child_owning_user',
width: 'auto'
}
]
},
{
title: '父项',
columns: [{
title: '父项ID',
field: 'parent_item_id',
width: 'auto'
},
{
title: '父项版本',
field: 'parent_item_revision_id',
width: 'auto'
},
{
title: '父项名称',
field: 'parent_object_name',
width: 'auto'
},
{
title: '父项描述',
field: 'parent_object_desc',
width: 'auto'
},
{
title: '父项状态',
field: 'parent_release_status_list',
width: 'auto'
},
{
title: '父项发布日期',
field: 'parent_date_released',
width: 'auto'
},
{
title: '父项类型',
field: 'parent_object_type',
width: 'auto'
},
{
title: '父项所有者',
field: 'parent_owning_user',
width: 'auto'
}
]
}
];
records = [];
var map= new Map();
//获取其中的不重复的父项最大版本
_.forEach(queryUserResponse2.output, (output1 => {
_.forEach(output1.info, (info => {
var parent_item_id=info.parentItemRev.props.item_id.uiValues[0];
var parent_item_revision_id= info.parentItemRev.props.item_revision_id.uiValues[0];
if(!map.has(parent_item_id))
map.set(parent_item_id,parent_item_revision_id);
else{
var temp=map.get(parent_item_id);
if(temp<parent_item_revision_id)
map.set(parent_item_id,parent_item_revision_id);
}
}));
}));
_.forEach(queryUserResponse1.objects, (inputObject) => {
_.forEach(queryUserResponse2.output, (output1 => {
if (output1.inputObject === inputObject) {
_.forEach(output1.info, (info => {
var parent_item_id=info.parentItemRev.props.item_id.uiValues[0];
var parent_item_revision_id=info.parentItemRev.props.item_revision_id.uiValues[0]
if(map.get(parent_item_id)==parent_item_revision_id){
var record = {
child_item_id: inputObject.props.item_id.uiValues[0],
child_item_revision_id: inputObject.props.item_revision_id.uiValues[0],
child_object_name: inputObject.props.object_name.uiValues[0],
child_object_desc: inputObject.props.object_desc.uiValues[0],
child_release_status_list: inputObject.props.release_status_list.uiValues[0],
child_date_released: inputObject.props.date_released.uiValues[0],
child_object_type: inputObject.props.object_type.uiValues[0],
child_owning_user: inputObject.props.owning_user.uiValues[0],
parent_item_id: info.parentItemRev.props.item_id.uiValues[0],
parent_item_revision_id: info.parentItemRev.props.item_revision_id.uiValues[0],
parent_object_name: info.parentItemRev.props.object_name.uiValues[0],
parent_object_desc: info.parentItemRev.props.object_desc.uiValues[0],
parent_release_status_list: info.parentItemRev.props.release_status_list.uiValues[0],
parent_date_released: info.parentItemRev.props.date_released.uiValues[0],
parent_object_type: info.parentItemRev.props.object_type.uiValues[0],
parent_owning_user: info.parentItemRev.props.owning_user.uiValues[0]
};
records.push(record);
}
}));
}
}));
});
//构建表格
const option = {
records: records,
columns: columns,
autoWrapText: true,
heightMode: 'autoHeight',
editCellTrigger: 'click',
keyboardOptions: {
copySelected: true,
pasteValueToCell: true,
selectAllOnCtrlA: true
},
theme: vt.themes.ARCO.extends({
scrollStyle: {
visible: 'always',
scrollSliderColor: 'purple',
scrollRailColor: '#bac3cc',
hoverOn: false,
barToSide: true
}
}),
rowSeriesNumber: {
title: '序号',
width: 'auto',
headerStyle: {
color: 'black',
bgColor: 'pink'
},
style: {
color: 'red'
}
},
emptyTip: {
text: '未查询到数据!'
}
};
let dom = document.getElementById("QueryWhereUserdView");
queryWhereUserdDataTable = new vt.ListTable(dom, option);
window['queryWhereUserdDataTable'] = queryWhereUserdDataTable
}
3.最终效果,可以批量查询多个数据的使用关系: