屠宰场客户端
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.

134 lines
4.9 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BO;
using BO.BO.Bill;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.JsonRpc.Client;
using Newtonsoft.Json;
using SegmentationWeight.Rpc.Dto;
namespace SegmentationWeight.Rpc
{
public class SegmentationWeightRecordRpc : SyncToServerBase<SegmentationWeightRecord>
{
// 定义一个静态变量来保存类的实例
private static SegmentationWeightRecordRpc uniqueInstance;
// 定义一个标识确保线程同步
private static readonly object locker = new object();
// 定义私有构造函数,使外界不能创建该类实例
private SegmentationWeightRecordRpc()
{
}
/// <summary>
/// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点
/// </summary>
/// <returns></returns>
public static SegmentationWeightRecordRpc GetInstance()
{
// 当第一个线程运行到这里时,此时会对locker对象 "加锁",
// 当第二个线程运行该方法时,首先检测到locker对象为"加锁"状态,该线程就会挂起等待第一个线程解锁
// lock语句运行完之后(即线程运行完之后)会对该对象"解锁"
// 双重锁定只需要一句判断就可以了
if (uniqueInstance == null)
{
lock (locker)
{
// 如果类的实例不存在则创建,否则直接返回
if (uniqueInstance == null)
{
uniqueInstance = new SegmentationWeightRecordRpc();
}
}
}
return uniqueInstance;
}
protected override string InsertRpcUrl
{
get { return "/MainSystem/B3ClientService/Rpcs/BillRpc/SegmentationWeightRecordRpc/Insert"; }
}
protected override string UpdateRpcUrl
{
get { return "/MainSystem/B3ClientService/Rpcs/BillRpc/SegmentationWeightRecordRpc/Update"; }
}
protected override string DeleteRpcUrl
{
get { return "/MainSystem/B3ClientService/Rpcs/BillRpc/SegmentationWeightRecordRpc/Delete"; }
}
public BindingList<SegmentationWeightRecord> GetTodayList(string flag)
{
return GetListByDate(DateTime.Today, flag);
}
public BindingList<SegmentationWeightRecord> GetListByDate(DateTime date, string flag)
{
var bindList = new BindingList<SegmentationWeightRecord>();
var list = new List<SegmentationWeightRecord>();
var query = new DmoQuery(typeof(SegmentationWeightRecord));
query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", date.Date));
query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", date.Date.AddDays(1)));
query.Where.Conditions.Add(DQCondition.EQ("IsDeleted", false));
if (!string.IsNullOrEmpty(flag))
query.Where.Conditions.Add(DQCondition.EQ("GroupFlag", flag));
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", false));
using (var session = LocalDmoSession.New())
{
list = session.ExecuteList(query).Cast<SegmentationWeightRecord>().ToList();
}
foreach (SegmentationWeightRecord record in list)
{
bindList.Add(record);
}
return bindList;
}
public static int GetTodayTotalCount(DateTime date)
{
var query = new DQueryDom(new JoinAlias(typeof(SegmentationWeightRecord)));
query.Columns.Add(DQSelectColumn.Count());
query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("CreateTime", date.Date));
query.Where.Conditions.Add(DQCondition.LessThan("CreateTime", date.Date.AddDays(1))); ;
using (var session = LocalDmoSession.New())
{
return Convert.ToInt32(session.ExecuteScalar(query));
}
}
public BindingList<SegmentationWeightRecord> GetTodayGroupFlagList()
{
var bindList = new BindingList<SegmentationWeightRecord>();
var query = new DQueryDom(new JoinAlias(typeof(SegmentationWeightRecord)));
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("CreateTime", DateTime.Today, DateTime.Today + new TimeSpan(23, 59, 29)), DQCondition.EQ("IsDeleted", false), DQCondition.IsNotNull(DQExpression.Field("GroupFlag"))));
query.Columns.Add(DQSelectColumn.Field("Goods_Name"));
query.Columns.Add(DQSelectColumn.Field("GroupFlag"));
query.GroupBy.Expressions.Add(DQExpression.Field("Goods_Name"));
query.GroupBy.Expressions.Add(DQExpression.Field("GroupFlag"));
using (var session = LocalDmoSession.New())
{
using (var reader = session.ExecuteReader(query))
{
while (reader.Read())
bindList.Add(new SegmentationWeightRecord { Goods_Name = (string)reader[0], GroupFlag = (string)reader[1] });
}
}
return bindList;
}
}
}