144 lines
5.3 KiB
C#
144 lines
5.3 KiB
C#
using CRM.Core.DTO.Hg;
|
|
using Newtonsoft.Json;
|
|
using Quartz;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.Common.StockHelper;
|
|
using WX.CRM.Model.Enum;
|
|
|
|
namespace WX.CRM.CRMServices.CRMJobs
|
|
{
|
|
public class HgPunishNoticeJob : IJob
|
|
{
|
|
private static bool isRuning = false;
|
|
private readonly CACHE_BL cache_BL;
|
|
public HgPunishNoticeJob()
|
|
{
|
|
cache_BL = new CACHE_BL();
|
|
}
|
|
|
|
public void Execute(JobExecutionContext context)
|
|
{
|
|
if (isRuning)
|
|
return;
|
|
isRuning = true;
|
|
try
|
|
{
|
|
WX.CRM.Common.LogHelper.Info("start HgPunishNoticeJob!");
|
|
Start();
|
|
WX.CRM.Common.LogHelper.Info("end HgPunishNoticeJob!");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
WX.CRM.Common.LogHelper.Error(string.Concat("WX.CRM.CRMServices.CRMJobs.HgPunishNoticeJob.Execute ", e.Message, e.StackTrace));
|
|
}
|
|
finally
|
|
{
|
|
isRuning = false;
|
|
}
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi);
|
|
var url = $"{webapi}/order/GetCheckQualityNotice";
|
|
var punishNoticeDay = -7;
|
|
var punishNoticeDayCfg = Utility.GetSettingOrNullByKey("PunishNoticeDay");
|
|
if (!string.IsNullOrEmpty(punishNoticeDayCfg))
|
|
{
|
|
punishNoticeDay = Convert.ToInt32(punishNoticeDayCfg);
|
|
}
|
|
|
|
var dto = new HgCheckQualitySearchDto() { PageIndex = 1, PageSize = int.MaxValue, stime = DateTime.Now.AddDays(punishNoticeDay), etime = DateTime.Now };
|
|
|
|
var result = Utility.PostAjaxData(url, dto.ToJson(), Encoding.UTF8);
|
|
var rsp = JsonConvert.DeserializeObject<Common.StockHelper.ApiResult<PageResult<Hg_CheckQuality_Notice>>>(result);
|
|
var data = rsp.Data.Data;
|
|
foreach (var notice in data)
|
|
{
|
|
var noticeWeek = notice.NoticeCtime.DayOfWeek.ToString();
|
|
var diffDay = 3;
|
|
|
|
if (noticeWeek == "Thursday")
|
|
{
|
|
//星期四,星期二执行
|
|
diffDay = 5;
|
|
}
|
|
else if (noticeWeek == "Friday")
|
|
{
|
|
//星期五,星期三执行
|
|
diffDay = 5;
|
|
}
|
|
else if (noticeWeek == "Saturday")
|
|
{
|
|
//星期六,星期三执行
|
|
diffDay = 4;
|
|
}
|
|
|
|
var noticeDay = Convert.ToDateTime(notice.NoticeCtime.ToShortDateString()).AddDays(diffDay);
|
|
if (DateTime.Now > noticeDay)
|
|
{
|
|
//LogHelper.Info($"执行自动确认=>{notice.ToJson()}");
|
|
AutoSign(notice.Hg_CheckQuality_NoticeSigns);
|
|
}
|
|
//else
|
|
//{
|
|
// LogHelper.Info($"时间还没到=>{notice.ToJson()}");
|
|
//}
|
|
}
|
|
}
|
|
private void AutoSign(List<Hg_CheckQuality_NoticeSign_Dto> list)
|
|
{
|
|
var webapi = cache_BL.GetValue_Parameter(Parameter.Hg_Core_WebApi);
|
|
var url = $"{webapi}/Order/AddQualityNoticeOption";
|
|
|
|
var sale = list.Find(p => p.NoticeLevel == "sale");
|
|
var manage = list.Find(p => p.NoticeLevel == "manage");
|
|
LogHelper.Info($"执行自动确认=>{sale.ToJson()}");
|
|
LogHelper.Info($"执行自动确认=>{manage.ToJson()}");
|
|
if (sale.Sign == 0)
|
|
{
|
|
var dto2 = new QualityNoticeOption()
|
|
{
|
|
eid = Convert.ToInt32(sale.eid),
|
|
id = sale.NoticeId,
|
|
NoticeLevel = sale.NoticeLevel,
|
|
opinion = "系统自动确认"
|
|
};
|
|
var result = Utility.PostAjaxData(url, JsonConvert.SerializeObject(dto2), Encoding.UTF8);
|
|
var data = JsonConvert.DeserializeObject<HGApiResult<bool>>(result);
|
|
LogHelper.Info($"{sale.ToJson()}自动确认结果=>{data.ToJson()}");
|
|
if (data.code == 0)
|
|
{
|
|
LogHelper.Info($"自动确认成功=>{sale.ToJson()}");
|
|
}
|
|
}
|
|
if (manage.Sign == 0)
|
|
{
|
|
var dto2 = new QualityNoticeOption()
|
|
{
|
|
eid = Convert.ToInt32(manage.eid),
|
|
id = manage.NoticeId,
|
|
NoticeLevel = manage.NoticeLevel,
|
|
opinion = "系统自动确认"
|
|
};
|
|
var result = Utility.PostAjaxData(url, JsonConvert.SerializeObject(dto2), Encoding.UTF8);
|
|
var data = JsonConvert.DeserializeObject<HGApiResult<bool>>(result);
|
|
LogHelper.Info($"{manage.ToJson()}自动确认结果=>{data.ToJson()}");
|
|
if (data.code == 0)
|
|
{
|
|
LogHelper.Info($"自动确认成功=>{manage.ToJson()}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|