😎完成产品管理批量同步到SAP

This commit is contained in:
bairubing 2024-09-25 14:37:03 +08:00
parent 5b0d28bba5
commit 5d6156f20f
5 changed files with 178 additions and 27 deletions

View File

@ -38,7 +38,7 @@
"ExcludeOfMethods": [], // GlobalEnabled=true "ExcludeOfMethods": [], // GlobalEnabled=true
"BahLogLevel": "Information", // Oops.Oh Oops.Bah "BahLogLevel": "Information", // Oops.Oh Oops.Bah
"WithReturnValue": true, // true "WithReturnValue": true, // true
"ReturnValueThreshold": 500, // 0 "ReturnValueThreshold": 0, // 0500
"JsonBehavior": "None", // JsonNone(OnlyJsonAll) "JsonBehavior": "None", // JsonNone(OnlyJsonAll)
"JsonIndented": false, // Json "JsonIndented": false, // Json
"UseUtcTimestamp": false, // UTCLOCAL "UseUtcTimestamp": false, // UTCLOCAL

View File

@ -120,7 +120,6 @@ public class ProductManagementService : IDynamicApiController, ITransient
[DisplayName("产品管理-同步到 SAP")] [DisplayName("产品管理-同步到 SAP")]
public async Task<SapOutput> SyncToSAP(ProductManagementBaseInput input) public async Task<SapOutput> SyncToSAP(ProductManagementBaseInput input)
{ {
const string lengthError = "物料编码长度大于40请检查"; const string lengthError = "物料编码长度大于40请检查";
// 验证物料描述长度 // 验证物料描述长度
@ -213,8 +212,8 @@ public class ProductManagementService : IDynamicApiController, ITransient
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[ApiDescriptionSettings(Name = "GetBOM", Description = "分页查询", Order = 1000), HttpPost] [ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost]
[DisplayName("分页查询产品管理")] [DisplayName("获取BOM")]
public async Task<SqlSugarPagedList<ProductManagementBomOutput>> GetBOM(BomPageProductManagementInput input) public async Task<SqlSugarPagedList<ProductManagementBomOutput>> GetBOM(BomPageProductManagementInput input)
{ {
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").FirstAsync(); var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 110 && x.ConfigLabel == "mBOM").FirstAsync();
@ -227,10 +226,12 @@ public class ProductManagementService : IDynamicApiController, ITransient
return BomData; return BomData;
} }
/// <summary> /// <summary>
/// Bom同步到SAP /// 产品管理-Bom同步到SAP
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost]
[DisplayName("产品管理-Bom同步到SAP")]
public async Task<SapOutput> SyncToSAPBom(List<BomPageProductManagementInput> input) public async Task<SapOutput> SyncToSAPBom(List<BomPageProductManagementInput> input)
{ {
var ParentData = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync(); var ParentData = await _obj110Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync();
@ -310,5 +311,119 @@ public class ProductManagementService : IDynamicApiController, ITransient
}; };
return output; return output;
} }
/// <summary>
/// 产品管理-批量同步到SAP
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
[DisplayName("产品管理-批量同步到SAP")]
public async Task<List<SapOutput>> BatchSyncToSAP(List<ProductManagementBaseInput> input)
{
const string lengthError = "物料编码长度大于40请检查";
const string synchronized = "该物料编码已同步!";
var SapOutputList=new List<SapOutput>();
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
for (int i = 0; i < input.Count; i++)
{
// 验证物料描述长度
if (input[i].fld004484.Length > 40)
{
await _obj110Rep.AsUpdateable()
.SetColumns(it => new Obj110
{
fld004629 = DateTime.Now,
fld004312 = "N",
fld004313 = lengthError
})
.Where(it => it.idRecord == input[i].idRecord)
.ExecuteCommandAsync().ConfigureAwait(false);
SapOutputList.Add(new SapOutput()
{
materialCode = input[i]._System_objNBS,
code = "失败",
msg = lengthError,
result = lengthError
});
continue;
}
if (input[i].fld004312=="N")
{
SapOutputList.Add(new SapOutput()
{
materialCode = input[i]._System_objNBS,
code = "失败",
msg = synchronized,
result = synchronized
});
continue;
}
//获取时间戳精确到毫秒sap要求每次调用生成不重复guid
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
var sapMaterialInput = new SapMaterialInput()
{
Reqkeyid = "",
Businessid = "",
Messageid = "",
Sndprn = "PLM",
Rcvprn = "SAP",
Requser = Requser,
Note1 = "",
Note2 = "",
Note3 = "",
Zwbid = millisecondTimestamp,
Matnr = input[i]._System_objNBS,
Mbrsh = input[i].fld004323,
Mtart = input[i].fld004324,
Maktx = input[i].fld004484,
Meins = input[i].fld004861,
Matkl = input[i].fld004485,
Bismt = input[i].fld004880,
Groes = input[i].fld004879,
Normt = input[i].fld004887,
Ferth = input[i].fld004882,
Zeinr = input[i].fld004881,
Mstae = input[i].fld004699,
Raube = input[i].fld004877,
Mhdrz = input[i].fld004876,
Mhdhb = input[i].fld004895,
Werks = input[i].fld004325,
Beskz = input[i].fld004490,
Sobsl = input[i].fld004491,
Schgt = input[i].fld004873,
Rgekz = input[i].fld004872,
Zbom = input[i].fld004698
};
var sapOutput = await _sapBomService.SapMaterialApi(sapMaterialInput);
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
string msg = sapOutput.msg;
if (sapOutput.msg == "")
{
msg = "同步成功";
}
await _obj110Rep.AsUpdateable()
.SetColumns(it => new Obj110
{
fld004629 = DateTime.Now,
fld004311 = codeVal,
fld004312 = "N",
fld004313 = msg
})
.Where(it => it.idRecord == input[i].idRecord)
.ExecuteCommandAsync();
var output = new SapOutput()
{
materialCode = input[0]._System_objNBS,
code = codeVal,
msg = msg,
result = sapOutput.result
};
SapOutputList.Add(output);
}
return SapOutputList;
}
} }

View File

@ -16,6 +16,7 @@ namespace Vistar.Application.Util;
/// </summary> /// </summary>
public class SapOutput public class SapOutput
{ {
public string? materialCode { get; set; }
public string code { get; set; } public string code { get; set; }
public string msg { get; set; } public string msg { get; set; }
public string result { get; set; } public string result { get; set; }

View File

@ -5,6 +5,7 @@ enum Api {
SyncToSAPProductManagement = '/api/productManagement/SyncToSAP', SyncToSAPProductManagement = '/api/productManagement/SyncToSAP',
GetetBOMProductManagement = '/api/productManagement/getBOM', GetetBOMProductManagement = '/api/productManagement/getBOM',
SyncToSAPBomProductManagement = '/api/productManagement/syncToSAPBom', SyncToSAPBomProductManagement = '/api/productManagement/syncToSAPBom',
BatchSyncToSAPProductManagement = '/api/productManagement/batchSyncToSAP'
} }
// 分页查询产品管理 // 分页查询产品管理
@ -44,4 +45,10 @@ export const SyncToSAPBomProductManagement = (params?: any) =>
method: 'post', method: 'post',
data: params, data: params,
}); });
// 批量同步到SAP
export const BatchSyncToSAPProductManagement = (params?: any) =>
request({
url: Api.BatchSyncToSAPProductManagement,
method: 'post',
data: params,
});

View File

@ -48,20 +48,20 @@
</template> --> </template> -->
<template #row_buttons="{ row }"> <template #row_buttons="{ row }">
<el-tooltip content="查看BOM" placement="top"> <el-tooltip content="查看BOM" placement="top">
<el-button icon="ele-MessageBox" size="small" text="" type="primary" @click="showBomDrawer(row)" > <el-button icon="ele-MessageBox" size="small" text="" type="primary"
@click="showBomDrawer(row)" v-if="row.fld004316!='N'">
查看BOM </el-button> 查看BOM </el-button>
</el-tooltip> </el-tooltip>
<!-- v-if="row.fld004316!='N'" -->
<el-tooltip content="工艺路线" placement="top"> <el-tooltip content="工艺路线" placement="top">
<el-button icon="ele-MessageBox" size="small" text="" type="primary" @click="showBomDrawer" v-if="row.fld004320!='N'"> <el-button icon="ele-MessageBox" size="small" text="" type="primary" @click="showBomDrawer"
v-if="row.fld004320 != 'N'">
工艺路线 </el-button> 工艺路线 </el-button>
</el-tooltip> </el-tooltip>
<el-tooltip content="同步到ERP" placement="top"> <el-tooltip content="同步到ERP" placement="top">
<el-button icon="ele-Promotion" size="small" text="" type="success" @click="syncToSAP(row)" <el-button icon="ele-Promotion" size="small" text="" type="success" @click="syncToSAP(row)"
v-auth="'productManagement/syncToSAP'" > 同步到SAP </el-button> v-auth="'productManagement/syncToSAP'" v-if="row.fld004312!='N'"> 同步到SAP </el-button>
</el-tooltip> </el-tooltip>
<!-- v-if="row.fld004312!='N'" -->
</template> </template>
</vxe-grid> </vxe-grid>
</el-card> </el-card>
@ -72,16 +72,16 @@
<!-- 这里可以放置 BOM 的具体内容 --> <!-- 这里可以放置 BOM 的具体内容 -->
<el-card class="full-table" shadow="hover" style="margin-top: 5px;height: 100%;"> <el-card class="full-table" shadow="hover" style="margin-top: 5px;height: 100%;">
<el-form :model="stateBom.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" <el-form :model="stateBom.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true"
label-width="auto" style="flex: 1 1 0%" @submit.prevent="handleQueryBom"> label-width="auto" style="flex: 1 1 0%" @submit.prevent="handleQueryBom">
<el-input v-model="stateBom.queryParams.ParentGuid" placeholder="父GUID" @click="handleQueryBom" /> <el-input v-model="stateBom.queryParams.ParentGuid" placeholder="父GUID" @click="handleQueryBom" />
</el-form> </el-form>
<vxe-grid ref="bomxGrid" v-bind="bomOptions" v-on="gridEvents"> <vxe-grid ref="bomxGrid" v-bind="bomOptions" v-on="gridEvents">
<template #toolbar_tools> <template #toolbar_tools>
<el-button style="position: absolute; left: 0" icon="ele-Promotion" size="small" text="" <el-button style="position: absolute; left: 0" icon="ele-Promotion" size="small" text=""
type="success" @click="syncToSAPBom" v-auth="'productManagement/syncToSAPBom'"> BOM同步到SAP type="success" @click="syncToSAPBom" v-auth="'productManagement/syncToSAPBom'"> BOM同步到SAP
</el-button> </el-button>
</template> </template>
</vxe-grid> </vxe-grid>
</el-card> </el-card>
</el-drawer> </el-drawer>
@ -100,7 +100,8 @@ import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage'; import { Local } from '/@/utils/storage';
import { formatDate } from '/@/utils/formatTime'; import { formatDate } from '/@/utils/formatTime';
import { PageProductManagement, BomTypeProductManagement, SyncToSAPProductManagement, GetetBOMProductManagement,SyncToSAPBomProductManagement } from '/@/api/materialManagement/productManagement'; import { PageProductManagement, BomTypeProductManagement, SyncToSAPProductManagement, GetetBOMProductManagement, SyncToSAPBomProductManagement, BatchSyncToSAPProductManagement } from '/@/api/materialManagement/productManagement';
import { disable } from 'ol/rotationconstraint';
// //
const xGrid = ref<VxeGridInstance>(); const xGrid = ref<VxeGridInstance>();
@ -141,7 +142,7 @@ const options = useVxeTable(
id: 'productManagement', id: 'productManagement',
name: '产品管理', name: '产品管理',
columns: [ columns: [
{ type: 'checkbox', title: '', width: 60 }, { type: 'checkbox', title: '', width: 60},
{ type: 'seq', title: '序号', width: 60 }, { type: 'seq', title: '序号', width: 60 },
{ field: '_System_objNBS', title: '物料编码', minWidth: 100, showOverflow: 'tooltip', sortable: false }, { field: '_System_objNBS', title: '物料编码', minWidth: 100, showOverflow: 'tooltip', sortable: false },
{ field: '_System_ObjDescription', title: '名称', minWidth: 100, showOverflow: 'tooltip', sortable: false }, { field: '_System_ObjDescription', title: '名称', minWidth: 100, showOverflow: 'tooltip', sortable: false },
@ -258,7 +259,7 @@ const syncToSAP = async (row: any) => {
const bomxGrid = ref<VxeGridInstance>(); const bomxGrid = ref<VxeGridInstance>();
// BOM // BOM
const showBomDrawer = async (row: any) => { const showBomDrawer = async (row: any) => {
stateBom.queryParams.ParentGuid=row.recordGuid; stateBom.queryParams.ParentGuid = row.recordGuid;
showBom.value = true; showBom.value = true;
await handleQueryBom(); await handleQueryBom();
}; };
@ -326,9 +327,8 @@ const handleQueryBom = async (reset = false) => {
//Bomsap //Bomsap
const syncToSAPBom = async () => { const syncToSAPBom = async () => {
//var data=bomxGrid.value?.getCheckboxRecords();
options.loading = true; options.loading = true;
var data=bomxGrid.value?.getTableData().fullData; var data = bomxGrid.value?.getTableData().fullData;
ElMessageBox.confirm(`确定要同步BOM吗`, '提示', { ElMessageBox.confirm(`确定要同步BOM吗`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
@ -347,9 +347,37 @@ const syncToSAPBom = async () => {
options.loading = false; options.loading = false;
} }
//SAP //SAP
const batchSyncToSAP = async () =>{ const batchSyncToSAP = async () => {
var data=xGrid.value?.getCheckboxRecords(); options.loading = true;
console.log("datadatadata",data) var data = xGrid.value?.getCheckboxRecords();
ElMessageBox.confirm(`确定要批量同步物料吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
var output = await BatchSyncToSAPProductManagement(data);
console.log("ssssssssssssssssssssss", output)
await handleQuery();
var succeed = 0;
var error = 0;
for (let i = 0; i < output.data.result.length; i++) {
var code = output.data.result[i].code
if (code == "成功") {
succeed++
} else {
error++
}
}
ElMessageBox.alert("同步成功:" + succeed + "" + "同步失败:" + error, '批量同步结果', {
//
// autofocus: false,
confirmButtonText: 'OK'
})
})
.catch(() => { });
options.loading = false;
} }
</script> </script>