Browse Source

修改。

master
yibo 8 years ago
parent
commit
2d8025e2f2
6 changed files with 154 additions and 20 deletions
  1. +1
    -0
      B3ClientService/B3ClientService.csproj
  2. +4
    -1
      B3ClientService/BO/Bill/WeightBill/WeightBill.cs
  3. +41
    -0
      B3ClientService/ClientServiceUtils.cs
  4. +59
    -8
      B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs
  5. +44
    -10
      B3ClientService/Rpcs/BillRpc/OrderDetailRpc.cs
  6. +5
    -1
      B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs

+ 1
- 0
B3ClientService/B3ClientService.csproj View File

@ -122,6 +122,7 @@
<Compile Include="Tasks\UpdateLoad\UploadSecondOrder.cs" />
<Compile Include="Tasks\UpdateLoad\UploadTest.cs" />
<Compile Include="Tasks\UpdateLoad\UpLoadWeightBill.cs" />
<Compile Include="ClientServiceUtils.cs" />
<Compile Include="WordPair.cs" />
</ItemGroup>
<ItemGroup>


+ 4
- 1
B3ClientService/BO/Bill/WeightBill/WeightBill.cs View File

@ -9,8 +9,11 @@ using TSingSoft.WebPluginFramework;
namespace BWP.B3ClientService.BO
{
[Serializable]
public class WeightBill : SyncBill
public class WeightBill : SyncBill, IWithRowVersion
{
[DbColumn(DefaultValue = 0)]
public int RowVersion { get; set; }
#region BasicFile
public long? AccountingUnit_ID { get; set; }


+ 41
- 0
B3ClientService/ClientServiceUtils.cs View File

@ -0,0 +1,41 @@
using BWP.B3ClientService.BO;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebPluginFramework;
namespace BWP.B3ClientService
{
public interface IWithRowVersion
{
long ID { get; set; }
int RowVersion { get; set; }
}
public static class ClientServiceUtils
{
public static bool RowVersionSame<T>(int rowVersion, long id)
where T : IWithRowVersion
{
var query = new DQueryDom(new JoinAlias(typeof(T)));
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", id), DQCondition.EQ("RowVersion", rowVersion)));
return query.EExists();
}
public static bool Exist<T>(long id)
where T : SyncBase
{
return Exist<T>("ID", id);
}
public static bool Exist<T>(string field, object value)
{
var query = new DQueryDom(new JoinAlias(typeof(T)));
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ(field, value), DQCondition.EQ("DeleteState", false)));
return query.EExists();
}
}
}

+ 59
- 8
B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs View File

@ -20,20 +20,31 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
{
static JavaScriptSerializer serializer = new JavaScriptSerializer();
/*
* //原型
SELECT w2.id, w1.* FROM B3ClientService_WeightBill w1, (  
SELECT TOP 100 row_number() OVER (order by (case when Remark is null or Remark='' then 0 else 1 end),ID) n, ID FROM B3ClientService_WeightBill ) w2 WHERE w1.ID = w2.ID AND w2.n > 90 ORDER BY w2.n ASC
*/
[Rpc]
public static string GetHouseAndSanctionList(DateTime date)
public static string GetHouseAndSanctionList(DateTime date, int pageSize, int pageNumber)
{
var temp = new JoinAlias(typeof(OrderTemp));
var query = new DQueryDom(temp);
OrderTemp.Register(query, date, pageSize * pageNumber);
var main = new JoinAlias(typeof(WeightBill));
var detail = new JoinAlias(typeof(WeightBill_Detail));
var query = new DQueryDom(main);
query.From.AddJoin(JoinType.Left, new DQDmoSource(main), DQCondition.EQ(temp, "ID", main, "ID"));
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.And(DQCondition.EQ(detail, "DeleteState", false), DQCondition.EQ(main, "ID", detail, "WeightBill_ID")));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("B3ID"));
query.Columns.Add(DQSelectColumn.Field("Employee_Name"));
query.Columns.Add(DQSelectColumn.Field("Supplier_Name"));
query.Columns.Add(DQSelectColumn.Field("HouseNames"));
query.Columns.Add(DQSelectColumn.Field("ID", main));
query.Columns.Add(DQSelectColumn.Field("B3ID", main));
query.Columns.Add(DQSelectColumn.Field("Employee_Name", main));
query.Columns.Add(DQSelectColumn.Field("Supplier_Name", main));
query.Columns.Add(DQSelectColumn.Field("HouseNames", main));
query.Columns.Add(DQSelectColumn.Field("Number", detail));
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("WeighTime", date, date + new TimeSpan(23, 59, 29)), DQCondition.EQ("DeleteState", false)));
query.Where.Conditions.Add(DQCondition.GreaterThan(temp, "RowNumber", pageSize * (pageNumber - 1)));
var list = new List<HouseAndSanctionList>();
using (var session = Dmo.NewSession())
{
@ -55,6 +66,36 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
return serializer.Serialize(list);
}
class OrderTemp
{
public int RowNumber { get; set; }
public long ID { get; set; }
public static void Register(DQueryDom root, DateTime date, int total)
{
var query = new DQueryDom(new JoinAlias("_pageTemp", typeof(WeightBill)));
query.Range = SelectRange.Top(total);
query.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet("row_number() OVER (order by (case when [_pageTemp].[HouseNames] is null or [_pageTemp].[HouseNames]='' then 0 else 1 end),[_pageTemp].[ID])"), "RowNumber"));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("WeighTime", date, date + new TimeSpan(23, 59, 29)), DQCondition.EQ("DeleteState", false)));
root.RegisterQueryTable(typeof(OrderTemp), new string[] { "RowNumber", "ID" }, query);
}
}
[Rpc]
public static int GetMaxPageNumber(DateTime date, int pageSize)
{
var query = new DQueryDom(new JoinAlias(typeof(WeightBill)));
query.Where.Conditions.Add(DQCondition.And(DQCondition.Between("WeighTime", date, date + new TimeSpan(23, 59, 29)), DQCondition.EQ("DeleteState", false)));
query.Columns.Add(DQSelectColumn.Count());
var total = Convert.ToInt32(query.EExecuteScalar());
var maxPageSize = total / pageSize;
if (total % pageSize != 0)
maxPageSize += 1;
return maxPageSize;
}
[Rpc]
public static int GetDetailTotalNumber(DateTime date)
{
@ -77,6 +118,9 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
var result = new HouseAndSanctionEdit();
using (var session = Dmo.NewSession())
{
var exist = ClientServiceUtils.Exist<WeightBill>(id);
if (!exist)
throw new Exception("过磅单已被删除");
result.ID = id;
result.HogGrade_ID = InnerBLUtil.GetDmoPropertyByID<long?>(session, typeof(WeightBill), "HogGrade_ID", id);
result.Number = InnerBLUtil.GetDmoProperty<int?>(session, typeof(WeightBill_Detail), "Number", new Tuple<string, object>("WeightBill_ID", id), new Tuple<string, object>("DeleteState", false));
@ -97,6 +141,12 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
public static int UpdateInsertHouseAndSanction(string json)
{
var entity = serializer.Deserialize<HouseAndSanctionEdit>(json);
var exist = ClientServiceUtils.Exist<WeightBill>(entity.ID);
if (!exist)
throw new Exception("过磅单已被删除,提交失败!");
var detailExist = ClientServiceUtils.Exist<WeightBill_Detail>("WeightBill_ID", entity.ID);
if (!detailExist)
throw new Exception("过磅记录已被删除,提交失败!");
using (var session = Dmo.NewSession())
{
//为了节省ID,把传过来的通过栋舍匹配,并到原有明细里。然后从新的集合里把上传的集合里不存在的剔除掉
@ -172,6 +222,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
update.Columns.Add(new DQUpdateColumn("HouseNames", string.Join(",", houseNames)));
update.Columns.Add(new DQUpdateColumn("SanctionNumber", entity.SanctionDetails.Sum(x => x.Number ?? 0)));
update.Columns.Add(new DQUpdateColumn("Sync", false));
update.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1))));
update.Columns.Add(new DQUpdateColumn("ModifyTime", DateTime.Now));
update.Where.Conditions.Add(DQCondition.EQ("ID", entity.ID));
session.ExecuteNonQuery(update);


+ 44
- 10
B3ClientService/Rpcs/BillRpc/OrderDetailRpc.cs View File

@ -153,17 +153,21 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
}
[Rpc]
public static string GetOrderDetail()
public static string GetOrderDetail(DateTime date, int pageSize, int pageNumber)
{
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail)));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID"));
query.Columns.Add(DQSelectColumn.Field("Order"));
query.Columns.Add(DQSelectColumn.Field("PlanNumber"));
query.Columns.Add(DQSelectColumn.Field("LiveColonyHouse_Name"));
query.Columns.Add(DQSelectColumn.Field("IsHurryButcher"));
query.Columns.Add(DQSelectColumn.Field("B3WeighBill_ID"));
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", DateTime.Today), DQCondition.EQ("DeleteState", false), DQCondition.EQ("SecondarySplit", false)));
var temp = new JoinAlias(typeof(OrderTemp));
var query = new DQueryDom(temp);
OrderTemp.Register(query, date, pageSize * pageNumber);
var alias = new JoinAlias(typeof(OrderDetail));
query.From.AddJoin(JoinType.Left, new DQDmoSource(alias), DQCondition.EQ(temp, "ID", alias, "ID"));
query.Columns.Add(DQSelectColumn.Field("ID", alias));
query.Columns.Add(DQSelectColumn.Field("WeightBill_ID", alias));
query.Columns.Add(DQSelectColumn.Field("Order", alias));
query.Columns.Add(DQSelectColumn.Field("PlanNumber", alias));
query.Columns.Add(DQSelectColumn.Field("LiveColonyHouse_Name", alias));
query.Columns.Add(DQSelectColumn.Field("IsHurryButcher", alias));
query.Columns.Add(DQSelectColumn.Field("B3WeighBill_ID", alias));
query.Where.Conditions.Add(DQCondition.GreaterThan(temp, "RowNumber", pageSize * (pageNumber - 1)));
var list = new List<OrderDetail>();
using (var session = Dmo.NewSession())
{
@ -186,6 +190,36 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
return serializer.Serialize(list);
}
class OrderTemp
{
public int RowNumber { get; set; }
public long ID { get; set; }
public static void Register(DQueryDom root, DateTime date, int total)
{
var query = new DQueryDom(new JoinAlias("_pageTemp", typeof(OrderDetail)));
query.Range = SelectRange.Top(total);
query.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet("row_number() OVER (order by [_pageTemp].[Order] desc)"), "RowNumber"));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false), DQCondition.EQ("SecondarySplit", false)));
root.RegisterQueryTable(typeof(OrderTemp), new string[] { "RowNumber", "ID" }, query);
}
}
[Rpc]
public static int GetMaxPageNumber(DateTime date, int pageSize)
{
var query = new DQueryDom(new JoinAlias(typeof(OrderDetail)));
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("Date", date), DQCondition.EQ("DeleteState", false), DQCondition.EQ("SecondarySplit", false)));
query.Columns.Add(DQSelectColumn.Count());
var total = Convert.ToInt32(query.EExecuteScalar());
var maxPageSize = total / pageSize;
if (total % pageSize != 0)
maxPageSize += 1;
return maxPageSize;
}
[Rpc]
public static int GetMaxOrder(DateTime date)
{


+ 5
- 1
B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs View File

@ -101,12 +101,17 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
{
if (dmo.ID != 0)
{
bool same = ClientServiceUtils.RowVersionSame<WeightBill>(dmo.RowVersion, dmo.ID);
if (!same)
throw new Exception("数据已被更改,请重新打开");
FillServerUpdateFields(session, dmo);
dmo.RowVersion += 1;
session.Update(dmo);
}
else
{
dmo.ModifyTime = DateTime.Now;
dmo.RowVersion += 1;
session.Insert(dmo);
}
@ -227,7 +232,6 @@ namespace BWP.B3ClientService.Rpcs.BillRpc
return true;
}
[Rpc]
public static string SyncBillB3Ids(List<long> ids)
{


Loading…
Cancel
Save