a
This commit is contained in:
37
EastChanger/STK_Inventory/ListEventPlugInEx.cs
Normal file
37
EastChanger/STK_Inventory/ListEventPlugInEx.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
||||
using Kingdee.BOS.Core.DynamicForm;
|
||||
using Kingdee.BOS.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Kingdee.BOS.Core.List.PlugIn;
|
||||
using Kingdee.BOS;
|
||||
|
||||
namespace EastChanger.STK_Inventory
|
||||
{
|
||||
[Description("【列表插件】【1.海关同步】"), HotUpdate]
|
||||
public class ListEventPlugInEx : AbstractListPlugIn
|
||||
{
|
||||
private IOperationResult opResult;
|
||||
public override void BarItemClick(BarItemClickEventArgs e)
|
||||
{
|
||||
base.BarItemClick(e);
|
||||
//同步海关信息
|
||||
if (e.BarItemKey.Equals("ImmediateInventory"))
|
||||
{
|
||||
opResult = new OperationResult();
|
||||
var list = this.ListView.SelectedRowsInfo;
|
||||
|
||||
var fidList = list.Select(x => x.PrimaryKeyValue).Distinct().ToList();
|
||||
STKInventoryService service = new STKInventoryService(this.Context);
|
||||
service.HandleSyncData(fidList, opResult);
|
||||
|
||||
if (opResult.OperateResult.Any())
|
||||
this.View.ShowOperateResult(opResult.OperateResult);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
209
EastChanger/STK_Inventory/STKInventoryService.cs
Normal file
209
EastChanger/STK_Inventory/STKInventoryService.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using ExtensionMethods;
|
||||
using Kingdee.BOS;
|
||||
using Kingdee.BOS.App.Data;
|
||||
using Kingdee.BOS.Core.DynamicForm;
|
||||
using Kingdee.BOS.Log;
|
||||
using Kingdee.BOS.Util;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace EastChanger.STK_Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// 即时库存明细
|
||||
/// </summary>
|
||||
public class STKInventoryService : BaseService
|
||||
{
|
||||
public STKInventoryService(Context context) : base(context, "supvWarehouse.save", "即时库存明细")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理请求数据
|
||||
/// </summary>
|
||||
/// <param name="idList"></param>
|
||||
/// <param name="opResult"></param>
|
||||
public void HandleSyncData(List<string> idList, IOperationResult opResult)
|
||||
{
|
||||
var declInfos = GetDeclInfos();
|
||||
var headSql = @"
|
||||
SELECT
|
||||
t0.ID
|
||||
,t0.declaCode
|
||||
,t0.status
|
||||
,t0.materialWarehouse
|
||||
,t0.LEDGERID
|
||||
,t0.FENTRYID
|
||||
,t0.FBOOKNUM
|
||||
,t0.FCUSTOMSCODE
|
||||
,t0.FLEDGERSTOCKID
|
||||
,t0.code
|
||||
,t0.name
|
||||
,t0.specificationsModels
|
||||
,t0.calcUnit
|
||||
,t0.cunit
|
||||
,t0.warehouseCd
|
||||
,t0.warehousePosiCd
|
||||
,t0.itemNo
|
||||
,t0.reduceable
|
||||
,t0.inputMan
|
||||
,t0.declaType
|
||||
FROM
|
||||
V_IMMEDIATE_INVENTORY t0
|
||||
WHERE 1 = 1
|
||||
{0}
|
||||
";
|
||||
|
||||
var whereSql = "";
|
||||
if (idList != null && idList.Any())
|
||||
whereSql = string.Format(" AND t0.ID IN ({0}) ", string.Join("','", idList));
|
||||
var toSql = string.Format(headSql, whereSql);
|
||||
|
||||
List<Dictionary<string, object>> itemList = new List<Dictionary<string, object>>();
|
||||
var dbList = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{toSql}");
|
||||
if (dbList != null && dbList.Any())
|
||||
{
|
||||
var groupList = dbList.GroupBy(x => x["FBOOKNUM"].ToString());
|
||||
int no = 0;
|
||||
foreach (var bookEntity in groupList)
|
||||
{
|
||||
no++;
|
||||
var bookNum = bookEntity.Key;
|
||||
foreach (var entity in bookEntity)
|
||||
{
|
||||
var item = new Dictionary<string, object>();
|
||||
item.Add("itemNo", entity["itemNo"].ToSafeTurnString());
|
||||
item.Add("code", entity["code"].ToSafeTurnString());
|
||||
item.Add("name", entity["name"].ToSafeTurnString());
|
||||
item.Add("specificationsModels", entity["specificationsModels"].ToSafeTurnString());
|
||||
item.Add("calcUnit", entity["calcUnit"].ToSafeTurnString());
|
||||
item.Add("cunit", entity["cunit"].ToSafeTurnString());
|
||||
item.Add("reduceable", entity["reduceable"].ToSafeTurnString());
|
||||
item.Add("materialWarehouse", entity["materialWarehouse"].ToSafeTurnString());
|
||||
item.Add("warehouseCd", entity["warehouseCd"].ToSafeTurnString());
|
||||
item.Add("warehousePosiCd", entity["warehousePosiCd"].ToSafeTurnString());
|
||||
itemList.Add(item);
|
||||
}
|
||||
var oIdList = bookEntity.ToDictionary(k => k["ID"].ToString(), v => v["itemNo"].Long2Int());
|
||||
|
||||
var main = declInfos[bookNum];
|
||||
|
||||
var newDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
//no 补位序号,防止一秒内多次执行,生成相同的itemNo
|
||||
string itemNo = $"CD{DateTime.Now:yyMMddHHmmss}{no:D2}";
|
||||
main.Add("compileDate", newDate);
|
||||
main.Add("inputMan", _context.UserName);
|
||||
main.Add("declaType", "00");
|
||||
main.Add("busiType", "03");
|
||||
main.Add("inputDate", newDate);
|
||||
main.Add("declaDate", newDate);
|
||||
main.Add("declaCode", itemNo);
|
||||
main.Add("itemList", itemList);
|
||||
|
||||
var dataJson = JsonUtil.Serialize(main);
|
||||
var result = this.Execute(dataJson);
|
||||
if (!result.IsNullOrEmpty())
|
||||
{
|
||||
JToken resData = JsonUtil.DeserializeObject<JToken>(result);
|
||||
var code = resData["code"].Long2Int();
|
||||
if (code == 0)
|
||||
{
|
||||
var data = resData["data"];
|
||||
var rtnFlag = data["rtnFlag"].Long2Int() == 0;
|
||||
var rtnMessage = data["rtnMessage"].ToString();
|
||||
|
||||
JArray rtnItemList = null;
|
||||
if (rtnFlag)
|
||||
rtnItemList = data["rtnObj"]["entity"]["itemList"] as JArray;
|
||||
|
||||
foreach (var kv in oIdList)
|
||||
{
|
||||
var id = kv.Key;
|
||||
var msg = $"明细ID:{id},{rtnMessage}。";
|
||||
if (rtnFlag)
|
||||
{
|
||||
var index = kv.Value - 1;
|
||||
var rtnItem = rtnItemList[index];
|
||||
var rItemNo = rtnItem["itemNo"].ToString();
|
||||
var declaId = rtnItemList["declaId"].ToString();
|
||||
var syncId = rtnItemList["id"].ToString();
|
||||
//UpdateStkInventoryInfo(id, 1, itemNo, declaId, syncId);
|
||||
InserSyncRecord(id, 1, itemNo, declaId, syncId);
|
||||
}
|
||||
ExecuteOperateResult(opResult, itemNo, msg, rtnFlag);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecuteOperateResult(opResult, itemNo, resData["msg"].ToString(), false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据账册分类后设置申报信息表头
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Dictionary<string, Dictionary<string, object>> GetDeclInfos()
|
||||
{
|
||||
var newDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
var ledgerSql = @"SELECT * FROM V_LEDGER_INFO";
|
||||
|
||||
var ledgerInfos = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{ledgerSql}");
|
||||
var groupList = ledgerInfos.GroupBy(x => x["FBOOKNUM"].ToString()).ToList();
|
||||
//var lInfo = ledgerInfos[0];
|
||||
var resultData = new Dictionary<string, Dictionary<string, object>>();
|
||||
foreach (var item in groupList)
|
||||
{
|
||||
var main = new Dictionary<string, object>();
|
||||
resultData.Add(item.Key, main);
|
||||
var lInfo = item.ToList()[0];
|
||||
main.Add("entCusCode", lInfo["FENTCUSCODE"]);
|
||||
main.Add("entCreditCode", lInfo["FENTCREDITCODE"]);
|
||||
main.Add("entName", lInfo["FENTNAME"]);
|
||||
main.Add("declaEntCusCode", lInfo["FDECLAENTCUSCODE"]);
|
||||
main.Add("declaEntCreditCode", lInfo["FDECLAENTCREDITCODE"]);
|
||||
main.Add("declaEntName", lInfo["FDECLAENTNAME"]);
|
||||
main.Add("customsCode", lInfo["FCUSTOMSCODE"]);
|
||||
main.Add("bookNum", lInfo["FBOOKNUM"]);
|
||||
}
|
||||
|
||||
return resultData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步完成后更新即时库存明细信息
|
||||
/// </summary>
|
||||
/// <param name="id">明细id</param>
|
||||
/// <param name="status">同步状态</param>
|
||||
/// <param name="itemNo">同步编号</param>
|
||||
/// <param name="declaId">申报id</param>
|
||||
/// <param name="syncId">同步id</param>
|
||||
private void UpdateStkInventoryInfo(string id, int status, string itemNo, string declaId, string syncId)
|
||||
{
|
||||
var headSql = $@"UPDATE T_STK_INVENTORY set FBILLNO = '{itemNo}' ,FSTATUS = {status},FDeclaId = '{declaId}',FSyncId ='{syncId}' WHERE FID = '{id}' ";
|
||||
DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{headSql}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步完成后记录当前即时库存明细信息
|
||||
/// </summary>
|
||||
/// <param name="OId"></param>
|
||||
/// <param name="itemNo"></param>
|
||||
private void InserSyncRecord(string oId, int status, string itemNo, string declaId, string syncId)
|
||||
{
|
||||
var newId = Guid.NewGuid();
|
||||
var headSql = $@"EXEC PROC_INSERT_STK_SYNC_RECORD '{newId}' ,'{oId}' ,'{itemNo}' ,'{declaId}' ,'{syncId}' ,{status}";
|
||||
DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{headSql}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user