This commit is contained in:
PastSaid
2024-03-18 11:42:45 +08:00
parent 08d8878eef
commit c31957eb64
56 changed files with 1485 additions and 123 deletions

View File

@@ -0,0 +1,19 @@
using EastChanger.Entites;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EastChanger.STK_StockCountGain
{
public class CountGainRequest : BaseRequest<List<Dictionary<string, object>>>
{
/// <summary>
/// 盘点日期
/// </summary>
public string inventoryDt { get; set; }
}
}

View File

@@ -0,0 +1,40 @@
using ExtensionMethods;
using Kingdee.BOS;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Validation;
using Kingdee.BOS.TCP;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EastChanger.STK_StockCountGain
{
public class OperationEventPlugInEx : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("FSTATUS");
}
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
if (this.FormOperation.OperationId == 3)
{
var validator = new CustomsSyncVaildators(4);
//是否需要校验true是需要
validator.AlwaysValidate = true;
//校验单据头
validator.EntityKey = "FBillHead";
//加载校验器
e.Validators.Add(validator);
}
}
}
}

View File

@@ -2,6 +2,9 @@
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.Util;
using Newtonsoft.Json.Linq;
using System;
@@ -16,93 +19,110 @@ namespace EastChanger.STK_StockCountGain
/// </summary>
public class STKStockCountGainService : BaseService, ISynchonService
{
public STKStockCountGainService(Context context, string apiName = "supvInventoryProfitLoss.save", string moduleCnName = "盘盈单") : base(context, apiName, moduleCnName)
/// <summary>
/// 同步类型 0.手动同步 1.自动同步
/// </summary>
private readonly int _syncType;
public STKStockCountGainService(Context context, int syncType = 0) : base(context, 4)
{
_syncType = syncType;
}
public string ModuleCnName => this._moduleCnName;
public void HandleSyncData(List<string> idList, IOperationResult opResult)
/// <summary>
///
/// </summary>
/// <param name="idList"></param>
/// <param name="opResult"></param>
/// <param name="action">1.删除</param>
public void HandleSyncData(List<string> idList, IOperationResult opResult, int action)
{
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
var whereSql = " AND FDOCUMENTSTATUS = 'C' ";
if (action == 1)
whereSql = " AND (SyncStatus = '1' OR SyncStatus = '-2') ";
else
whereSql += " AND SyncStatus != '1' ";
if (idList != null && idList.Any())
whereSql += $" AND ID IN ({string.Join(",", idList)}) ";
var headSql = $@"
SELECT * FROM V_SYNC_STKCOUNTGAIN
WHERE 1 = 1
{0}
{whereSql}
";
var entrySql = $@"
SELECT * FROM V_SYNC_STKCOUNTGAINENTRY
WHERE 1 = 1
{whereSql}
";
var whereSql = "";
if (idList != null && idList.Any())
whereSql = string.Format(" AND t0.ID IN ({0}) ", string.Join("','", idList));
var toSql = string.Format(headSql, whereSql);
var headList = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{headSql}");
var entryList = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{entrySql}");
List<Dictionary<string, object>> itemList = new List<Dictionary<string, object>>();
var dbList = DBUtils.ExecuteDynamicObject(_context, $"/*dialect*/{toSql}");
if (dbList != null && dbList.Any())
if (headList != null && headList.Any())
{
var groupList = dbList.GroupBy(x => x["FBOOKNUM"].ToString());
int no = 0;
foreach (var bookEntity in groupList)
var groupList = entryList.GroupBy(x => x["ID"].ToString());
foreach (var head in headList)
{
no++;
var bookNum = bookEntity.Key;
foreach (var entity in bookEntity)
var itemList = new List<Dictionary<string, object>>();
var id = head["ID"].ToSafeTurnString();
var bookNum = head["FBOOKNUM"].ToSafeTurnString();
var syncStatus = head["SyncStatus"].Long2Int();
//申报类型
var declaType = "";
if (syncStatus == 1 || syncStatus == -2)
declaType = "01";
else
declaType = "00";
//申报通用表头信息
#region
var main = new Dictionary<string, object>(declInfos[bookNum]);
main.Add("declaCode", id);
main.Add("inventoryDt", head["inventoryDt"].ToSafeTurnString());
main.Add("inputMan", head["inputMan"].ToSafeTurnString());
main.Add("declaType", declaType);
main.Add("busiType", "03");
main.Add("inputDate", head["inputDate"].ToSafeTurnString());
main.Add("declaDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
main.Add("itemList", itemList);
#endregion
#region
var list = groupList.FirstOrDefault(w => w.Key == id);
foreach (var entity in list.ToList())
{
var item = new Dictionary<string, object>();
itemList.Add(item);
item.Add("itemNo", entity["itemNo"].ToSafeTurnString());
item.Add("code", entity["code"].ToSafeTurnString());
item.Add("name", entity["name"].ToSafeTurnString());
item.Add("materialCd", entity["materialCd"].ToSafeTurnString());
item.Add("materialDesc", entity["materialDesc"].ToSafeTurnString());
item.Add("materialType", entity["materialType"].ToSafeTurnString());
item.Add("specificationsModels", entity["specificationsModels"].ToSafeTurnString());
item.Add("adjmtrMarkcd", entity["adjmtrMarkcd"].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("erpWarehouse", entity["erpWarehouse"].ToSafeTurnString());
item.Add("warehouseNumberDifference", entity["warehouseNumberDifference"].ToSafeTurnString());
item.Add("erpWarehouseValue", entity["erpWarehouseValue"].ToSafeTurnString());
item.Add("warehouseValuDifference", entity["warehouseValuDifference"].ToSafeTurnString());
item.Add("currency", entity["currency"].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);
#endregion
var dataJson = JsonUtil.Serialize(main);
var result = this.DoSubmit(dataJson);
if (!result.IsNullOrEmpty())
{
JToken resData = JsonUtil.DeserializeObject<JToken>(result);
@@ -112,36 +132,29 @@ WHERE 1 = 1
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);
}
UpdateStatus(this._context, id, (rtnFlag ? "1" : "-1"));
ExecuteOperateResult(opResult, id, rtnMessage, rtnFlag);
}
else
{
ExecuteOperateResult(opResult, itemNo, resData["msg"].ToString(), false);
UpdateStatus(this._context, id, "-1");
ExecuteOperateResult(opResult, id, resData["msg"].ToString(), false);
}
}
}
}
}
/// <summary>
/// 同步完成后更新单据同步状态
/// </summary>
/// <param name="context"></param>
/// <param name="id"></param>
/// <param name="status"></param>
public void UpdateStatus(Context context, string id, string status)
{
var headSql = $@"UPDATE T_STK_STKCOUNTGAIN set FSTATUS='{status}' where FID = " + id;
DBUtils.ExecuteDynamicObject(context, $"/*dialect*/{headSql}");
}
}
}