using BWP.B3ClientService.BO;
|
|
using Forks.EnterpriseServices.DataForm;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.JsonRpc;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Script.Serialization;
|
|
using Newtonsoft.Json;
|
|
using TSingSoft.WebPluginFramework;
|
|
|
|
namespace BWP.B3ClientService.Rpcs
|
|
{
|
|
[Rpc]
|
|
public static class BaseInfoRpc
|
|
{
|
|
static JavaScriptSerializer serializer = new JavaScriptSerializer();
|
|
|
|
|
|
[Rpc]
|
|
public static string GetWorkShopList()
|
|
{
|
|
var query = new DmoQuery(typeof(WorkShop));
|
|
var list = query.EExecuteList().Cast<WorkShop>().ToList();
|
|
return JsonConvert.SerializeObject(list);
|
|
}
|
|
|
|
[Rpc]
|
|
public static string GetWorkUnitList()
|
|
{
|
|
var query = new DmoQuery(typeof(WorkUnit));
|
|
var list = query.EExecuteList().Cast<WorkUnit>().ToList();
|
|
return JsonConvert.SerializeObject(list);
|
|
}
|
|
|
|
[Rpc]
|
|
public static string GetStoreList()
|
|
{
|
|
var query = new DmoQuery(typeof(Store));
|
|
var list = query.EExecuteList().Cast<Store>().ToList();
|
|
return JsonConvert.SerializeObject(list);
|
|
}
|
|
|
|
[Rpc]
|
|
public static string GetProductBatchList()
|
|
{
|
|
//只查询5天前的批次
|
|
var query = new DmoQuery(typeof(ProductBatch));
|
|
query.Range=SelectRange.Top(5);
|
|
var list = query.EExecuteList().Cast<ProductBatch>().ToList();
|
|
return JsonConvert.SerializeObject(list);
|
|
}
|
|
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetCarList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<Car>(input, args, top);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetSupplierList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<Supplier>(input, args, top);
|
|
}
|
|
|
|
static List<WordPair> GetBaseInfoList<T>(string input, string args, int top)
|
|
where T : BaseInfo
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(T)));
|
|
if (top > 50)
|
|
top = 50;
|
|
if (top >= 0)
|
|
query.Range = SelectRange.Top(top);
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("Name"));
|
|
if (!string.IsNullOrEmpty(input))
|
|
query.Where.Conditions.Add(DQCondition.Or(DQCondition.Like("Name", input), DQCondition.Like("Spell", input)));
|
|
var list = new List<WordPair>();
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
list.Add(new WordPair(reader[1].ToString(), reader[0].ToString()));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetPurchaseTypeList(string input, string args, int top)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(PurchaseType)));
|
|
if (top > 50)
|
|
top = 50;
|
|
query.Range = SelectRange.Top(top);
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("Name"));
|
|
var list = new List<WordPair>();
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
list.Add(new WordPair(reader[1].ToString(), reader[0].ToString()));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetEmployeeList(string input, string args, int top)
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(BWP.B3Frameworks.BO.Employee)));
|
|
if (top > 50)
|
|
top = 50;
|
|
query.Range = SelectRange.Top(top);
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("Name"));
|
|
query.Where.Conditions.Add(DQCondition.EQ("Stopped", false));
|
|
if (!string.IsNullOrEmpty(input))
|
|
query.Where.Conditions.Add(DQCondition.Or(DQCondition.Like("Name", input), DQCondition.Like("Spell", input)));
|
|
var list = new List<WordPair>();
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
using (var reader = session.ExecuteReader(query))
|
|
{
|
|
while (reader.Read())
|
|
list.Add(new WordPair(reader[1].ToString(), reader[0].ToString()));
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetZoneList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<Zone>(input, args, top);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetFarmerList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<Farmer>(input, args, top);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetHogGradeList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<HogGrade>(input, args, top);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetLiveColonyHouseList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<LiveColonyHouse>(input, args, top);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetWhiteBarList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<WhiteBar>(input, args, top);
|
|
}
|
|
|
|
|
|
|
|
[Rpc]
|
|
public static List<Sanction> GetSanctionList()
|
|
{
|
|
var dmo = new DmoQuery(typeof(Sanction));
|
|
return dmo.EExecuteList().Cast<Sanction>().ToList();
|
|
}
|
|
|
|
[Rpc]
|
|
public static string GetLivestock()
|
|
{
|
|
var query = new DQueryDom(new JoinAlias(typeof(Livestock)));
|
|
query.Columns.Add(DQSelectColumn.Field("ID"));
|
|
query.Columns.Add(DQSelectColumn.Field("Name"));
|
|
query.Columns.Add(DQSelectColumn.Field("Technics"));
|
|
query.Columns.Add(DQSelectColumn.Field("Shortcut"));
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("SortNum", false));
|
|
var list = query.EExecuteList<long, string, short,string>().Select(x => new CTuple<long, string, short,string>(x.Item1, x.Item2, x.Item3,x.Item4)).ToList();
|
|
return serializer.Serialize(list);
|
|
}
|
|
|
|
[Rpc]
|
|
public static List<WordPair> GetLiveVarietiesList(string input, string args, int top)
|
|
{
|
|
return GetBaseInfoList<LiveVarieties>(input, args, top);
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int UpdateOrInsertFarmer(Farmer farmer)
|
|
{
|
|
UpdateBaseInfo(farmer);
|
|
return 1;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int UpdateOrInsertCar(Car car)
|
|
{
|
|
UpdateBaseInfo(car);
|
|
return 1;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int UpdateOrInsertSupplier(Supplier supplier)
|
|
{
|
|
UpdateBaseInfo(supplier);
|
|
return 1;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int DeleteFarmer(long id)
|
|
{
|
|
DeleteBaseInfo<Farmer>(id);
|
|
return 1;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int DeleteCar(long id)
|
|
{
|
|
DeleteBaseInfo<Car>(id);
|
|
return 1;
|
|
}
|
|
|
|
[Rpc(RpcFlags.SkipAuth)]
|
|
public static int DeleteSupplier(long id)
|
|
{
|
|
DeleteBaseInfo<Supplier>(id);
|
|
return 1;
|
|
}
|
|
|
|
static void UpdateBaseInfo<T>(T entity)
|
|
where T : BWP.B3ClientService.BO.BaseInfo, new()
|
|
{
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
session.AddUpdateOrInsert(entity);
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
static void DeleteBaseInfo<T>(long id)
|
|
where T : BWP.B3ClientService.BO.BaseInfo, new()
|
|
{
|
|
using (var session = Dmo.NewSession())
|
|
{
|
|
var delete = new DQDeleteDom(typeof(T));
|
|
delete.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
session.ExecuteNonQuery(delete);
|
|
session.Commit();
|
|
}
|
|
}
|
|
}
|
|
}
|