12
王 垚
2024-10-10 8d86234aea5856abd59226cec7c833fcc81e38d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Core;
using Kingdee.BOS.ServiceHelper;
using System.Data;
 
using Newtonsoft.Json.Linq;
using System;
using Kingdee.BOS.Util;
using System.Linq;
using ZD.Cloud.WebApi;
using Demo.BillView.PRD;
using Demo.Model.Model;
using System.Collections.Generic;
using ZD.Share.Common;
 
namespace Demo.TimedTaskPlugIn.PRD
{
    [Description("日计划工单 每日新增明细执行计划")]
    [HotUpdate]
    public class DayPlanAddTask : Kingdee.BOS.Contracts.IScheduleService
    {
        public void Run(Context ctx, Schedule schedule)
        {
            try
            {
                //LogService.Write("执行计划开始");
                string sql = string.Format(@"/*dialect*/
select FID,FDayPlanQuantity,FOrderQuantity,FOrderQuantity-FDayPlanQuantity as FKPQTY,CONVERT(NVARCHAR(20),GETDATE(),23) as FDATE from Sc_WorkBillSortBillMain 
where FOrderQuantity-FDayPlanQuantity >0 
"
);
                DataSet ds = DBServiceHelper.ExecuteDataSet(ctx, sql);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string _sql = $" /*dialect*/ select FEntryID, FHMASTERDATE from SC_WORKBILLSORTBILLSub  where FID={dr["FID"]} ";
                        List<DayPlanModel> dayPlanModel = new List<DayPlanModel>();
                        dayPlanModel = DBServiceHelper.ExecuteDataSet(ctx, sql).ToModelList<DayPlanModel>();
                        var fSpreadBillNo = dayPlanModel.LastOrDefault().FSpreadBillNo.Split('-');
                        JObject jsonRoot = new JObject();
                        jsonRoot.Add("Creator", "");
                        jsonRoot.Add("NeedUpDateFields", new JArray());
                        jsonRoot.Add("NeedReturnFields", new JArray());
                        jsonRoot.Add("IsDeleteEntry", "false");
                        jsonRoot.Add("SubSystemId", "");
                        jsonRoot.Add("IsVerifyBaseDataField", "");
                        JObject jsonModel = new JObject();
                        jsonModel.Add("FID", Convert.ToString(dr["FID"].ToString()));
                        JArray Entry = new JArray();
                        JObject jsonFPOOrderEntry = new JObject();
                        jsonFPOOrderEntry.Add("FHMasterDate", dr["FDATE"].ToString()); ;//主日期
                        jsonFPOOrderEntry.Add("FHQty ", dr["FKPQTY"].ToString()); ;//日计划数量
                        jsonFPOOrderEntry.Add("FSpreadBillNo", $"{fSpreadBillNo[0]}-{fSpreadBillNo[1]}-{Convert.ToInt32(fSpreadBillNo[2]) + 1}"); //流传单号 生产订单号+生产订单明细行号+序号mo0001-1-1+
                        Entry.Add(jsonFPOOrderEntry);
 
                        jsonModel.Add("FEntity", Entry);
                        jsonRoot.Add("Model", jsonModel);
                        CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
                        var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString());
                        //LogService.Write(jsonRoot.ToString());
                        JObject saveObj = JObject.Parse(result);
                        string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
                        if (saveIsSuc != "TRUE")
                        {
                            LogService.Write(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString());
                            return;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogService.Write(ex.Message.ToString());
            }
 
        }
 
    }
}