using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using BWP.B3Frameworks;
|
|
using BWP.B3Frameworks.BL;
|
|
using BWP.B3Frameworks.BO;
|
|
using BWP.B3Frameworks.BO.NamedValueTemplate;
|
|
using BWP.B3Frameworks.Utils;
|
|
using BWP.B3Sale.BL;
|
|
using BWP.B3Sale.BO;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using TSingSoft.WebPluginFramework;
|
|
using TSingSoft.WebPluginFramework.TimerTasks;
|
|
|
|
namespace BWP.B3_YunKen.TimerTask {
|
|
|
|
public class StoppedCustomerTask : ITimerTask {
|
|
|
|
public string Name { get { return "耘垦停用客户定时任务"; } }
|
|
|
|
public int Days { get { return new B3YunKenOnlineConfiguration().AutoStoppedCustomerDays.Value; } }//天数
|
|
|
|
volatile static object _lockObj = new object();
|
|
|
|
public void Execute() {
|
|
if (!Monitor.TryEnter(_lockObj)) {
|
|
throw new SameTaskNotFinishException(this);
|
|
}
|
|
|
|
try {
|
|
DoExecute();
|
|
} finally {
|
|
Monitor.Exit(_lockObj);
|
|
}
|
|
|
|
}
|
|
|
|
// A:查找启用状态且是否经销商为是的客户
|
|
//B:根据客户查找该【经销商】的【客户验收单】
|
|
//C:确定客户最晚【客户验收】的日期
|
|
//D:若当前日期-最晚【客户验收单】的发货时间>=X且当前日期-【客户档案】的启用时间>=X 则停用客户
|
|
//E:查找客户档案上的销售人员,根据销售人员查找关联的用户
|
|
//F:将停用客户的名单推送给销售人员关联的用户
|
|
//说明:x为【在线设置】中设置自动停用未发货客户的天数
|
|
|
|
private void DoExecute() {
|
|
|
|
var mDmoTypeID = DmoTypeIDAttribute.GetID(typeof(Customer));
|
|
var dom = new DQueryDom(new JoinAlias(typeof(Customer)));
|
|
dom.Columns.Add(DQSelectColumn.Field("ID"));
|
|
dom.Columns.Add(DQSelectColumn.Field("StopedTime"));
|
|
dom.Where.Conditions.Add(DQCondition.EQ("Stopped", false));
|
|
dom.Where.Conditions.Add(DQCondition.EQ("IsDealers", true));
|
|
var list = dom.EExecuteList<long, DateTime?>();
|
|
var userMesageBL = BIFactory.Create<IUserMessageBL>();
|
|
var cusBL = BIFactory.Create<ICustomerBL>();
|
|
foreach (var tuple in list) {
|
|
var loadTime = GetMaxLoadTime(tuple.Item1);
|
|
if (loadTime != null) {
|
|
var diffDays = (DateTime.Now - loadTime.Value).Days;
|
|
int? diffDays2 = null;
|
|
if (tuple.Item2 != null) {
|
|
diffDays2 = (DateTime.Now - tuple.Item2.Value).Days;
|
|
}
|
|
if (diffDays >= Days && diffDays2 >= Days) {
|
|
var cus = cusBL.Load(tuple.Item1);
|
|
cus.StopedByCustomerTask = true;
|
|
cus.StopReason = Days + "天内未发货";
|
|
cusBL.Update(cus);
|
|
cusBL.Stop(cus);
|
|
if (cus.Employee_ID.HasValue) {
|
|
var userID = GetBindingEmployeeID(cus.Employee_ID.Value);
|
|
if (userID == null)
|
|
continue;
|
|
var message = new CommonUserMessage();
|
|
message.TargetDmoTypeID = mDmoTypeID;
|
|
message.TargetDmoID = tuple.Item1;
|
|
message.Text = string.Format("客户{0}NO.{1}因{2}天内未发货,被系统自动停用。", cus.Name, tuple.Item1, Days);
|
|
userMesageBL.Insert(BLContext.User.ID, new long[] { userID.Value }, message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private static DateTime? GetMaxLoadTime(long cusID)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(CustomerAccept)));
|
|
query.Columns.Add(DQSelectColumn.Max("LoadTime"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("CustomerDealer_ID", cusID));
|
|
query.Where.Conditions.Add(DQCondition.EQ("BillState", 单据状态.已审核));
|
|
return (DateTime?)query.EExecuteScalar();
|
|
}
|
|
|
|
private static long? GetBindingEmployeeID(long employeeID) {
|
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(User_Employee)));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Employee_ID", employeeID));
|
|
query.Columns.Add(DQSelectColumn.Field("User_ID"));
|
|
|
|
var result = (long?)query.EExecuteScalar();
|
|
return result;
|
|
}
|
|
}
|
|
}
|