Kingdee 批量执行计划定时删除计划订单

using Kingdee.BOS.Contracts;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Kingdee.BOS;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Core;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Log;
using Newtonsoft.Json;
using Kingdee.BOS.Core.Log;
using Kingdee.BOS.ServiceHelper;
using System.ComponentModel;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.DynamicForm;

namespace K3.App.Service.PlugIn.ExecutionPlanServicePlugIn
{
    [Description("批量执行计划定时删除计划订单")]
   // [Kingdee.BOS.Util.HotUpdate]
    //GSB.K3.App.Service.PlugIn.ExecutionPlanServicePlugIn.BatchDeletePlanOrderServicePlugIn, GSB.K3.App.Service.PlugIn
    public class BatchDeletePlanOrderServicePlugIn : IScheduleService
    {
        //BusinessDataServiceHelper.Delete
        public void Run(Context ctx, Schedule schedule)
        {
            try {
                Logger.Info("GSB_BatchDeleteBill", JsonConvert.SerializeObject(schedule.Parameters));
                var sql = string.Format(GetConfigEntity.GetConfig("DeletePLN_PLANORDER"));
                var objs = DBUtils.ExecuteDynamicObject(ctx, sql);
                if (objs == null || objs.Count == 0)
                {
                    Logger.Info("GSB_BatchDeleteBill", "批量删除计划订单数量为0,任务终止。");
                    return;
                }
                var businessInfo = ((FormMetadata)new MetaDataService().Load(ctx, "PLN_PLANORDER")).BusinessInfo;
                var pkids = objs.Select(o => o[0]).ToArray();
                //IOperationResult result
                var result = new DeleteService().Delete(ctx, businessInfo, pkids, OperateOption.Create());
                
                if (result.IsSuccess)
                {
                    var log = "执行成功的单据:" + string.Join(",",
                        result.SuccessDataEnity.Select(o => string.Format("{0}({1})", o["BillNo"], o[0])));
                    if (result.OperateResult != null && result.OperateResult.Count > 0)
                    {
                        log += "\r\n操作结果:" + string.Join(",", result.OperateResult.Select(o => o.Message));
                    }
                    Logger.Info("GSB_BatchDeleteBill", "批量删除计划订单成功:\r\n" + log);
                }
                else
                {
                    var successPkIds = result.SuccessDataEnity == null ? new long[] { } : result.SuccessDataEnity.Select(o => Convert.ToInt64(o[0])).ToArray();
                    var successBills = result.SuccessDataEnity == null ? new string[] { } : result.SuccessDataEnity.Select(o => string.Format("{0}({1})", o["BillNo"], o[0])).ToArray();
                    var failureBills = objs.Where(o => !successPkIds.Contains(Convert.ToInt64(o[0]))).Select(o => string.Format("{0}({1})", o[1], o[0])).ToArray();
                    var log = "执行成功的单据:" + string.Join(",", successBills);
                    log += "\r\n执行失败的单据:" + string.Join(",", failureBills);
                    log += "\r\n失败原因:" + JsonConvert.SerializeObject(result.OperateResult.GetFailResult())
                        + "\r\n" + JsonConvert.SerializeObject(result.ValidationErrors);
                    if (result.OperateResult != null && result.OperateResult.Count > 0)
                    {
                        log += "\r\n操作结果:" + string.Join(",", result.OperateResult.Select(o => o.Message));
                    }
                    Logger.Info("GSB-BatchDeleteBill", "批量删除计划订单失败:\r\n" + log);
                }

            }
            catch (Exception ex)
            {
                Logger.Error("GSB_BatchDeleteBill", "批量删除计划订单失败。", ex);
            }
            finally
            {
                Logger.Info("GSB_BatchDeleteBill", "批量删除计划订单结束。");
            }
            /*
            var logs = new List<LogObject>();
            var Logobj = new LogObject
            {
                pkValue = "0",
                Description = JsonConvert.SerializeObject(result),
                OperateName = "保存上机日志",
                ObjectTypeId = "GSB-BatchDeleteBill",
                SubSystemId = "BOS",
                Environment = OperatingEnvironment.BizOperate
            };
            logs.Add(Logobj);
            LogServiceHelper.BatchWriteLog(ctx, logs);*/
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值