You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

93 lines
3.3 KiB

using System;
using System.Collections.Generic;
using System.Threading;
using BWP.B3Frameworks;
using BWP.B3Frameworks.BL;
using BWP.B3Frameworks.BO;
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:若当前日期-最晚【销售出库单】的日期=60 则停用客户
//E:查找客户档案上的销售人员,根据销售人员查找关联的用户
//F:将停用客户的名单推送给销售人员关联的用户
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("LastGoodsOutStoreDate"));
dom.Where.Conditions.Add(DQCondition.EQ("Stopped", false));
dom.Where.Conditions.Add(DQCondition.IsNotNull(DQExpression.Field("LastGoodsOutStoreDate")));
var list = dom.EExecuteList<long, DateTime>();
var userMesageBL = BIFactory.Create<IUserMessageBL>();
var cusBL = BIFactory.Create<ICustomerBL>();
foreach (var tuple in list) {
var span = DateTime.Today - tuple.Item2;
if (span.Days >= 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}因60天内未发货,被系统自动停用。", cus.Name, tuple.Item1);
userMesageBL.Insert(BLContext.User.ID, new long[] { userID.Value }, message);
}
}
}
}
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;
}
}
}