using System;
|
using System.Collections.Generic;
|
using Kingdee.BOS.Util;
|
using Kingdee.BOS.Core.Metadata.EntityElement;
|
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
using Kingdee.BOS.Orm.DataEntity;
|
using System.ComponentModel;
|
using Kingdee.BOS.ServiceHelper;
|
using System.Data;
|
using Newtonsoft.Json.Linq;
|
using ZD.Cloud.WebApi;
|
using Newtonsoft.Json;
|
using Kingdee.BOS.Core.DynamicForm;
|
using System.Linq;
|
using RestSharp;
|
using zymes_Project.Utility;
|
|
namespace zymes_Project.OperationService
|
{
|
[Description("[生产汇报单-审核]服务插件]")]
|
[HotUpdate]
|
public class zymes_RealessPrdMoReport : AbstractOperationServicePlugIn
|
{
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e)
|
{
|
base.OnPrepareOperationServiceOption(e);
|
|
//为了在BeginOperationTransaction里检查数据抛出异常时
|
//只回滚当前单据的事务,这里设置为不支持批量事务,这样BOS会
|
//循环为每一张单据创建事务调用操作
|
e.SupportTransaction = true;
|
e.SurportBatchTransaction = false;
|
}
|
public override void OnPreparePropertys(PreparePropertysEventArgs e)
|
{
|
base.OnPreparePropertys(e);
|
e.FieldKeys.Add("FEntity");
|
e.FieldKeys.Add("FEntity_FEntryID");
|
}
|
//public override void BeginOperationTransaction(BeginOperationTransactionArgs e)
|
//{
|
// base.BeginOperationTransaction(e);
|
// //foreach (var item in e.DataEntitys)
|
// //{
|
// // DynamicObjectCollection entryRows = item["FEntity"] as DynamicObjectCollection;
|
// //}
|
// Entity entity = this.BusinessInfo.GetEntity("FEntity");//获取明细信息
|
// foreach (var billObj in e.DataEntitys)
|
// {
|
// //DynamicObjectCollection entryRows = entity.DynamicProperty.GetValue(billObj.DataEntity)
|
// // as DynamicObjectCollection;
|
// DynamicObjectCollection entryRows = billObj["FEntity"] as DynamicObjectCollection;
|
// foreach (var entryRow in entryRows)
|
// {
|
// var fentryId = entryRow["Id"].ToString();
|
// //生成生产汇报单
|
// string sql = $"/*dialect*/ exec proc_jit_DayPlanAduitAddNemMoOrder {fentryId}";
|
// DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
|
// if (dt.Rows[0][0].ToString().Contains("成功"))
|
// continue;
|
// foreach (DataRow dr in dt.Rows)
|
// {
|
// JObject model = new JObject();
|
// model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = dr["FBillTypeNumber"].ToString() }); //单据类型
|
// model.Add("FCreatorId", new JObject() { ["FUserID"] = Context.UserId }); //创建人
|
// model.Add("FModifierId", new JObject() { ["FUserID"] = Context.UserId }); //修改人
|
// model.Add("FDate", dr["FDate"].ToString());
|
// model.Add("FBILLNO", dr["FSpreadBillNo"].ToString());
|
// model.Add("FPrdOrgId", new JObject() { ["Fnumber"] = dr["FPrdOrgNumber"].ToString() });
|
// model.Add("FWorkShopID0", new JObject() { ["Fnumber"] = dr["FWorkShopNumber"].ToString() });
|
// model.Add("FOwnerTypeId", dr["FOwnerTypeId"].ToString());
|
// model.Add("FIsRework", dr["FIsRework"].ToString());
|
// model.Add("FBusinessType", dr["FBusinessType"].ToString());
|
// model.Add("FTrustteed", dr["FTrustteed"].ToString());
|
// model.Add("FIsEntrust", dr["FIsEntrust"].ToString());
|
// model.Add("FPPBOMType", dr["FPPBOMType"].ToString());
|
// model.Add("FIssueMtrl", dr["FIssueMtrl"].ToString());
|
// JArray Fentity = new JArray();
|
// JObject FentityModel = new JObject();
|
// FentityModel.Add("FProductType", dr["FProductType"].ToString());
|
// FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = dr["FMATERIALNUMBER"].ToString() });
|
// FentityModel.Add("FWorkShopID", new JObject() { ["Fnumber"] = dr["FWorkShopNumber"].ToString() });
|
// FentityModel.Add("FUnitId", new JObject() { ["Fnumber"] = dr["FUnitNumber"].ToString() });
|
// FentityModel.Add("FQty", dr["FQty"].ToString());
|
// FentityModel.Add("FYieldQty", dr["FYieldQty"].ToString());
|
// FentityModel.Add("FPlanStartDate", dr["FPlanStartDate"].ToString());
|
// FentityModel.Add("FPlanFinishDate", dr["FPlanFinishDate"].ToString());
|
// FentityModel.Add("FRequestOrgId", new JObject() { ["Fnumber"] = dr["FRequestOrgNumber"].ToString() });
|
// FentityModel.Add("FBomId", new JObject() { ["Fnumber"] = dr["FBomNumber"].ToString() });
|
// FentityModel.Add("FISBACKFLUSH", dr["FISBACKFLUSH"].ToString());
|
// FentityModel.Add("FStockInOrgId", new JObject() { ["Fnumber"] = dr["FPrdOrgNumber"].ToString() });
|
// FentityModel.Add("FBaseYieldQty", dr["FBaseYieldQty"].ToString());
|
// FentityModel.Add("FReqType", dr["FReqType"].ToString());
|
// FentityModel.Add("FInStockOwnerTypeId", dr["FInStockOwnerTypeId"].ToString());
|
// FentityModel.Add("FBaseStockInLimitH", dr["FBaseStockInLimitH"].ToString());
|
// FentityModel.Add("FInStockOwnerId", new JObject() { ["Fnumber"] = dr["FPrdOrgNumber"].ToString() });
|
// FentityModel.Add("FCheckProduct", dr["FCheckProduct"].ToString());
|
// FentityModel.Add("FBaseStockInLimitL", dr["FBaseStockInLimitL"].ToString());
|
// FentityModel.Add("FBaseUnitQty", dr["FBaseUnitQty"].ToString());
|
// FentityModel.Add("FRoutingId", new JObject() { ["Fnumber"] = dr["FRoutingNumber"].ToString() });
|
// FentityModel.Add("FBaseUnitId", new JObject() { ["Fnumber"] = dr["FUnitNumber"].ToString() });
|
// FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = dr["FStockNumber"].ToString() });
|
// FentityModel.Add("FStockInLimitH", dr["FStockInLimitH"].ToString());
|
// FentityModel.Add("FStockInLimitL", dr["FStockInLimitL"].ToString());
|
// FentityModel.Add("FCostRate", dr["FCostRate"].ToString());
|
// FentityModel.Add("FCreateType", dr["FCreateType"].ToString());
|
// FentityModel.Add("FYieldRate", dr["FYieldRate"].ToString());
|
// FentityModel.Add("FGroup", dr["FGroup"].ToString());
|
// FentityModel.Add("FNoStockInQty", dr["FNoStockInQty"].ToString());
|
// FentityModel.Add("FBaseNoStockInQty", dr["FBaseNoStockInQty"].ToString());
|
// FentityModel.Add("FRowId", dr["FRowId"].ToString());
|
// FentityModel.Add("FPickMtrlStatus", dr["FPickMtrlStatus"].ToString());
|
// FentityModel.Add("FMOChangeFlag", dr["FMOChangeFlag"].ToString());
|
// FentityModel.Add("FDAYPLANBILLNO", dr["FDAYPLANBILLNO"].ToString());
|
// FentityModel.Add("FDayPlanFseq", dr["FDayPlanFseq"].ToString());
|
// FentityModel.Add("FDayPlanFentryId", dr["FDayPlanFentryId"].ToString());
|
// FentityModel.Add("FDayPlanFid", dr["FDayPlanFid"].ToString());
|
// FentityModel.Add("FDayPlanRemainQty", 0);
|
// FentityModel.Add("FDayPlanQty", dr["FQty"].ToString());
|
// FentityModel.Add("F_TEZV_Base", new JObject() { ["Fnumber"] = dr["FPREBDONENUMBER"].ToString() });//包装标识
|
// FentityModel.Add("F_bsv_Text1", dr["F_bsv_Text1"].ToString());//源单客户代码
|
// FentityModel.Add("F_bsv_Date", dr["F_bsv_Date"].ToString());//要求交期
|
// FentityModel.Add("F_bsv_KH", new JObject() { ["Fnumber"] = dr["FCUSTOMERNUMBER"].ToString() });//客户
|
// //////////////生产汇报单源单信息////////////////////
|
// //FSRCBILLTYPE,FSRCBILLID,FSRCBILLNO,FSRCBILLENTRYID,FSRCBILLENTRYSEQ,FSALEORDERID,FSALEORDERNO,FSALEORDERENTRYID,FSALEORDERENTRYSEQ
|
// FentityModel.Add("FSRCBILLTYPE", dr["FSRCBILLTYPE"].ToString());
|
// FentityModel.Add("FSRCBILLID", dr["FSRCBILLID"].ToString());
|
// FentityModel.Add("FSRCBILLNO", dr["FSRCBILLNO"].ToString());
|
// FentityModel.Add("FSRCBILLENTRYID", dr["FSRCBILLENTRYID"].ToString());
|
// FentityModel.Add("FSRCBILLENTRYSEQ", dr["FSRCBILLENTRYSEQ"].ToString());
|
// FentityModel.Add("FSALEORDERID", dr["FSALEORDERID"].ToString());
|
// FentityModel.Add("FSALEORDERNO", dr["FSALEORDERNO"].ToString());
|
// FentityModel.Add("FSALEORDERENTRYID", dr["FSALEORDERENTRYID"].ToString());
|
// FentityModel.Add("FSALEORDERENTRYSEQ", dr["FSALEORDERENTRYSEQ"].ToString());
|
// FentityModel.Add("FReqSrc", dr["FReqSrc"].ToString());//需求来源 1销售订单
|
// if (dr["FSRCBILLTYPE"].ToString() == "PLN_PLANORDER")
|
// {
|
// JArray _Fentity2 = new JArray();
|
// JObject _FentityModel2 = new JObject();
|
// _FentityModel2.Add("FTREEENTITY_Link_FFlowId", "");//业务流程图:FTREEENTITY_Link_FFlowId
|
// _FentityModel2.Add("FTREEENTITY_Link_FFlowLineId", "0");//推进路线:FTREEENTITY_Link_FFlowLineId
|
// _FentityModel2.Add("FTREEENTITY_Link_FRuleId", "PlanOrder_MO");//转换规则:FTREEENTITY_Link_FRuleId
|
// _FentityModel2.Add("FTREEENTITY_Link_FSTableId", "0");//源单表内码:FTREEENTITY_Link_FSTableId
|
// _FentityModel2.Add("FTREEENTITY_Link_FSTableName", "T_PLN_PLANORDER");//源单表:FTREEENTITY_Link_FSTableName
|
// _FentityModel2.Add("FTREEENTITY_Link_FSBillId", dr["FSBILLID"].ToString());//源单内码:FTREEENTITY_Link_FSBillId
|
// _FentityModel2.Add("FTREEENTITY_Link_FSId", dr["FSID"].ToString()); //源单分录内码:FTREEENTITY_Link_FSId
|
// _FentityModel2.Add("FTREEENTITY_Link_FBaseUnitQtyOld", dr["FQty"].ToString());//原始携带量:FTREEENTITY_Link_FBaseUnitQtyOld
|
// _FentityModel2.Add("FTREEENTITY_Link_FBaseUnitQty", dr["FQty"].ToString());//修改携带量:FTREEENTITY_Link_FBaseUnitQty
|
// _Fentity2.Add(_FentityModel2);
|
// FentityModel.Add("FTREEENTITY_Link", _Fentity2);
|
// }
|
// //////////////////////////////////////////////////
|
// Fentity.Add(FentityModel);
|
// model.Add("FTreeEntity", Fentity);
|
// JObject jsonRoot = new JObject()
|
// {
|
// ["Creator"] = "",
|
// ["NeedUpDateFields"] = new JArray(),
|
// ["NeedReturnFields"] = new JArray(),
|
// ["IsDeleteEntry"] = "false",
|
// ["SubSystemId"] = "",
|
// ["IsVerifyBaseDataField"] = "false",
|
// ["Model"] = model
|
// };
|
// var _result = InvokeHelper.Save("PRD_MO", jsonRoot.ToString());
|
// var _saveObj = JObject.Parse(_result);
|
// var saveIsSuc = _saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
|
// if (saveIsSuc != "TRUE")
|
// {
|
// e.CancelOperation = true;
|
// dictionary.Add(dr["FDAYPLANBILLNO"].ToString(), "生产汇报单生成失败," + _saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString());
|
// LogService.Write("生产汇报单生成失败json" + jsonRoot.ToString());
|
// //this.View.ShowErrMessage("生产汇报单生成失败," + _saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString());
|
// continue;
|
// }
|
// }
|
// }
|
// }
|
//}
|
public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
|
{
|
base.AfterExecuteOperationTransaction(e);
|
Entity entity = this.BusinessInfo.GetEntity("FEntity");//获取明细信息
|
foreach (var billObj in e.DataEntitys)
|
{
|
var sql = $"exec zymes_RealessPrdMoReport {billObj["Id"]} ";
|
DataSet ds = DBServiceHelper.ExecuteDataSet(Context, sql);
|
DataTable maindt = ds.Tables[1];
|
DataTable subdt = ds.Tables[0];
|
if (maindt.Rows.Count == 0 || subdt.Rows.Count == 0)
|
{
|
LogService.Write("生产汇报单同步异常:" + sql);
|
continue;
|
}
|
JArray array = new JArray();//明细表
|
foreach (DataRow dr in subdt.Rows)
|
{
|
JObject fentrymodel = new JObject();
|
foreach (DataColumn column in subdt.Columns)
|
{
|
fentrymodel.Add(column.ColumnName, dr[column.ColumnName].ToString());
|
}
|
array.Add(fentrymodel);
|
}
|
JObject model = new JObject();//主表
|
DataRow maindr = maindt.Rows[0];
|
foreach (DataColumn column in maindt.Columns)
|
{
|
model.Add(column.ColumnName, maindr[column.ColumnName].ToString());
|
}
|
model.Add("HENTRY", array);
|
JObject jsonRoot = new JObject()
|
{
|
["model"] = model
|
};
|
//LogService.Write("生产汇报单同步示例" + JsonConvert.SerializeObject(jsonRoot));
|
//string clientUrl = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "ClientUrl");//K/3 Cloud 业务站点地址
|
var client = new RestSharp.RestClient("http://61.130.182.102:18181/simoerAPI/");
|
//新增
|
var requestPost = new RestRequest("Sc_ICMOReportBill/Sc_ICMOReportBillSaveApi", Method.POST);
|
requestPost.AddParameter("application/json", JsonConvert.SerializeObject(jsonRoot), ParameterType.RequestBody);
|
IRestResponse responsePost = client.Execute(requestPost);
|
var contentPost = responsePost.Content;
|
if (!contentPost.Contains("成功"))
|
{
|
LogService.Write("生产汇报单同步异常,POST方式获取结果," + billObj["Id"] + "," + contentPost);
|
LogService.Write("生产汇报单同步异常,POST," + "Sc_ICMOReportBill/Sc_ICMOReportBillSaveApi");
|
LogService.Write("生产汇报单同步异常,JsonConvert.SerializeObject(jsonRoot)," + JsonConvert.SerializeObject(jsonRoot));
|
}
|
};
|
foreach (var item in dictionary)
|
{
|
ResultMessage.dataError(this.OperationResult.OperateResult, item.Key, item.Value);
|
}
|
}
|
public static class ResultMessage
|
{/// <summary>
|
/// 修改提示信息
|
/// </summary>
|
/// <param name="operateResult"></param>
|
/// <param name="billno"></param>
|
public static void dataError(OperateResultCollection operateResult, string billno, string message)
|
{
|
OperateResult operate = operateResult.Where(n => n.Number == billno).First();
|
operate.Message = message;
|
operate.SuccessStatus = false;
|
operate.MessageType = MessageType.FatalError;
|
}
|
}
|
}
|
}
|