TG.WXCRM.V4/CRMServices/AutoRpt/SchedulingTasks.cs

84 lines
3.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WX.CRM.BLL.Autorpt;
using WX.CRM.BLL.Base;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.Model.Entity;
namespace WX.CRM.CRMServices.AutoRpt
{
public class SchedulingTasks
{
public void CreateSchedulingTasks()
{
Autorpt_basparameter_BL paraBl = new Autorpt_basparameter_BL();
Autorpt_executelog_BL logBl = new Autorpt_executelog_BL();
AUTORPT_SCHEDULINGTASKS_BL taskBl = new AUTORPT_SCHEDULINGTASKS_BL();
SEQUENCES_BL sequencesBl = new SEQUENCES_BL();
List<AUTORPT_SCHEDULINGTASKS> schedulingList = new List<AUTORPT_SCHEDULINGTASKS>();
var paraList = paraBl.GetAutoRpt_Para();
int timenum = 0;
string nowDate = DateTime.Now.ToShortDateString();
foreach (var m in paraList)
{
List<string> enableTimes = m.ENABLETIME.Split('#').ToList();
foreach (var time in enableTimes)
{
if (time.Length != 4 || !int.TryParse(time, out timenum))
{
AUTORPT_EXECUTELOG log = new AUTORPT_EXECUTELOG
{
DEPTCODE = m.DEPTCODE,
DIRECTORY = m.DIRECTORY,
PROCEDURENAME = m.PROCEDURENAME,
REPORTNAME = m.REPORTNAME,
RECORDCOUNT = 0,
STATUS = 100,
ERRORMSG = "启用时间格式错误,无法生成任务时间",
MEMO = m.REPORTMEMO
};
logBl.Create(log);
continue;
}
DateTime enableTime =
Convert.ToDateTime((nowDate + " " + time.Substring(0, 2) + ":" + time.Substring(2) + ":00"));
AUTORPT_SCHEDULINGTASKS schedulingtask = new AUTORPT_SCHEDULINGTASKS();
schedulingtask.PKID = sequencesBl.Seq_base_get();
schedulingtask.CTIME = DateTime.Now;
schedulingtask.PROCEDURENAME = m.PROCEDURENAME;
schedulingtask.ENABLENUM = m.ENABLENUM;
schedulingtask.ENABLETIME = enableTime;
schedulingtask.ERRORNUM = 0;
schedulingtask.SUCCESS = 0;
schedulingtask.SORTID = m.SORTID;
schedulingtask.DEPTCODE = m.DEPTCODE;
schedulingtask.REPORTNAME = m.REPORTNAME;
schedulingtask.DIRECTORY = m.DIRECTORY;
schedulingList.Add(schedulingtask);
}
}
if (schedulingList.Count > 0)
{
DataTable tab = Utility.ToOracleDataTable<AUTORPT_SCHEDULINGTASKS>(schedulingList);
OracleBulk_BL bl = new OracleBulk_BL();
ValidationErrors erros = new ValidationErrors();
bl.OracleBulkInsert(ref erros, "AUTORPT_SCHEDULINGTASKS", tab);
if (erros.Count > 0)
{
LogHelper.Error("自动报表AUTORPT_SCHEDULINGTASKS导入出错" + erros.Error);
}
else
{
taskBl.Delete(Convert.ToDateTime(nowDate));
}
}
}
}
}