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);*/
}
}
}
02-23
603
10-22
2085
07-09
1105