Files
GateDge2023_ljy/08.昶东/EastChanger/STK_StockCountGain/STKStockCountGainService.cs
PastSaid 08d8878eef a
2024-03-11 14:47:23 +08:00

148 lines
5.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ExtensionMethods;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Util;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EastChanger.STK_StockCountGain
{
/// <summary>
/// 盘盈单
/// </summary>
public class STKStockCountGainService : BaseService, ISynchonService
{
public STKStockCountGainService(Context context, string apiName = "supvInventoryProfitLoss.save", string moduleCnName = "盘盈单") : base(context, apiName, moduleCnName)
{
}
public string ModuleCnName => this._moduleCnName;
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.DoSubmit(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);
}
}
}
}
}
}
}