Commit de39ea68 by Neo Turing

优化

parent 33bc7b8d
...@@ -57,7 +57,13 @@ namespace Kivii.Third.Scjgj ...@@ -57,7 +57,13 @@ namespace Kivii.Third.Scjgj
} }
return rtns; return rtns;
} }
internal static PlanDetail ConvertTo(this PlanDetail item, IDbConnection conn = null) /// <summary>
/// 此方法是将原始的PlanDetail数据从其他子表中将数据丰富完善
/// </summary>
/// <param name="item"></param>
/// <param name="conn"></param>
/// <returns></returns>
internal static PlanDetail DataFilling(this PlanDetail item, IDbConnection conn = null)
{ {
PlanDetail rtns = new PlanDetail(); PlanDetail rtns = new PlanDetail();
bool connDispose = false; bool connDispose = false;
...@@ -282,16 +288,16 @@ namespace Kivii.Third.Scjgj ...@@ -282,16 +288,16 @@ namespace Kivii.Third.Scjgj
switch (item.CHECK_TYPE) switch (item.CHECK_TYPE)
{ {
case "1": case "1":
rtns = item.ConvertToNormal(conn); rtns = item.DataFillingNormal(conn);
break; break;
case "2": case "2":
rtns = item.ConvertToMarket(conn); rtns = item.DataFillingMarket(conn);
break; break;
case "3": case "3":
rtns = item.ConvertToCommerce(conn); rtns = item.DataFillingCommerce(conn);
break; break;
case "4": case "4":
rtns = item.ConvertToOther(conn); rtns = item.DataFillingOther(conn);
break; break;
default: default:
break; break;
...@@ -306,8 +312,13 @@ namespace Kivii.Third.Scjgj ...@@ -306,8 +312,13 @@ namespace Kivii.Third.Scjgj
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <returns></returns> /// <returns></returns>
internal static PlanDetail ConvertToNormal(this PlanDetail item, IDbConnection conn) internal static PlanDetail DataFillingNormal(this PlanDetail item, IDbConnection conn)
{ {
var rtns = new PlanDetail();
item.Cary = new Cary();
item.ProduceUnit = new ProduceUnit();
item.ExecUint = new ExecUint();
item.Other= new Other();
if (item.CARY_ID != null) if (item.CARY_ID != null)
{ {
item.Cary = GetCaryById(conn, item.CARY_ID); item.Cary = GetCaryById(conn, item.CARY_ID);
...@@ -322,7 +333,8 @@ namespace Kivii.Third.Scjgj ...@@ -322,7 +333,8 @@ namespace Kivii.Third.Scjgj
{ {
item.ExecUint = GetExecUintById(conn, item.EXEC_ID); item.ExecUint = GetExecUintById(conn, item.EXEC_ID);
} }
return item; rtns.PopulateWith(item);
return rtns;
} }
/// <summary> /// <summary>
/// 市场买样 /// 市场买样
...@@ -330,8 +342,13 @@ namespace Kivii.Third.Scjgj ...@@ -330,8 +342,13 @@ namespace Kivii.Third.Scjgj
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <returns></returns> /// <returns></returns>
internal static PlanDetail ConvertToMarket(this PlanDetail item, IDbConnection conn) internal static PlanDetail DataFillingMarket(this PlanDetail item, IDbConnection conn)
{ {
var rtns = new PlanDetail();
item.Cary = new Cary();
item.ProduceUnit = new ProduceUnit();
item.ExecUint = new ExecUint();
item.Other= new Other();
if (item.CARY_ID != null) if (item.CARY_ID != null)
{ {
item.Cary = GetCaryById(conn, item.CARY_ID); item.Cary = GetCaryById(conn, item.CARY_ID);
...@@ -346,7 +363,8 @@ namespace Kivii.Third.Scjgj ...@@ -346,7 +363,8 @@ namespace Kivii.Third.Scjgj
{ {
item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID); item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID);
} }
return item; rtns.PopulateWith(item);
return rtns;
} }
/// <summary> /// <summary>
/// 电商买样 /// 电商买样
...@@ -354,8 +372,13 @@ namespace Kivii.Third.Scjgj ...@@ -354,8 +372,13 @@ namespace Kivii.Third.Scjgj
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <returns></returns> /// <returns></returns>
internal static PlanDetail ConvertToCommerce(this PlanDetail item, IDbConnection conn) internal static PlanDetail DataFillingCommerce(this PlanDetail item, IDbConnection conn)
{ {
var rtns = new PlanDetail();
item.Cary = new Cary();
item.ProduceUnit = new ProduceUnit();
item.ExecUint = new ExecUint();
item.Other= new Other();
if (item.CARY_ID != null) if (item.CARY_ID != null)
{ {
item.Cary = GetCaryById(conn, item.CARY_ID); item.Cary = GetCaryById(conn, item.CARY_ID);
...@@ -375,8 +398,8 @@ namespace Kivii.Third.Scjgj ...@@ -375,8 +398,8 @@ namespace Kivii.Third.Scjgj
{ {
item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID); item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID);
} }
rtns.PopulateWith(item);
return item; return rtns;
} }
/// <summary> /// <summary>
/// 其他抽样 /// 其他抽样
...@@ -384,8 +407,13 @@ namespace Kivii.Third.Scjgj ...@@ -384,8 +407,13 @@ namespace Kivii.Third.Scjgj
/// <param name="item"></param> /// <param name="item"></param>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <returns></returns> /// <returns></returns>
internal static PlanDetail ConvertToOther(this PlanDetail item, IDbConnection conn) internal static PlanDetail DataFillingOther(this PlanDetail item, IDbConnection conn)
{ {
var rtns = new PlanDetail();
item.Cary = new Cary();
item.ProduceUnit = new ProduceUnit();
item.ExecUint = new ExecUint();
item.Other= new Other();
if (item.CARY_ID != null) if (item.CARY_ID != null)
{ {
item.Cary = GetCaryById(conn, item.CARY_ID); item.Cary = GetCaryById(conn, item.CARY_ID);
...@@ -405,8 +433,8 @@ namespace Kivii.Third.Scjgj ...@@ -405,8 +433,8 @@ namespace Kivii.Third.Scjgj
{ {
item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID); item.ProduceUnit = GetProduceUnitById(conn, item.PRO_ID);
} }
rtns.PopulateWith(item);
return item; return rtns;
} }
/// <summary> /// <summary>
...@@ -417,9 +445,14 @@ namespace Kivii.Third.Scjgj ...@@ -417,9 +445,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static Plan GetPlan(IDbConnection conn, string plancode) internal static Plan GetPlan(IDbConnection conn, string plancode)
{ {
var rtns = new Plan();
if (plancode == null) return rtns;
var query = conn.From<Plan>(); var query = conn.From<Plan>();
query.Where(o => o.PLAN_CODE == plancode); query.Where(o => o.PLAN_CODE == plancode);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new Plan();
return rtns;
} }
/// <summary> /// <summary>
/// 受检单位信息 /// 受检单位信息
...@@ -429,11 +462,14 @@ namespace Kivii.Third.Scjgj ...@@ -429,11 +462,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static Cary GetCaryById(IDbConnection conn, int? caryId) internal static Cary GetCaryById(IDbConnection conn, int? caryId)
{ {
if (caryId == null) return null; var rtns = new Cary();
if (caryId == null) return rtns;
var query = conn.From<Cary>(); var query = conn.From<Cary>();
query.Where(o => o.ID == caryId); query.Where(o => o.ID == caryId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new Cary();
return rtns;
} }
/// <summary> /// <summary>
/// 生产单位信息 /// 生产单位信息
...@@ -443,11 +479,14 @@ namespace Kivii.Third.Scjgj ...@@ -443,11 +479,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static ProduceUnit GetProduceUnitById(IDbConnection conn, int? proId) internal static ProduceUnit GetProduceUnitById(IDbConnection conn, int? proId)
{ {
if (proId == null) return null; var rtns = new ProduceUnit();
if (proId == null) return rtns;
var query = conn.From<ProduceUnit>(); var query = conn.From<ProduceUnit>();
query.Where(o => o.ID == proId); query.Where(o => o.ID == proId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new ProduceUnit();
return rtns;
} }
/// <summary> /// <summary>
/// 抽样机构信息 /// 抽样机构信息
...@@ -457,11 +496,14 @@ namespace Kivii.Third.Scjgj ...@@ -457,11 +496,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static ExecUint GetExecUintById(IDbConnection conn, int? execId) internal static ExecUint GetExecUintById(IDbConnection conn, int? execId)
{ {
if (execId == null) return null; var rtns = new ExecUint();
if (execId == null) return rtns;
var query = conn.From<ExecUint>(); var query = conn.From<ExecUint>();
query.Where(o => o.ID == execId); query.Where(o => o.ID == execId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new ExecUint();
return rtns;
} }
/// <summary> /// <summary>
/// 电商单位信息 /// 电商单位信息
...@@ -471,11 +513,14 @@ namespace Kivii.Third.Scjgj ...@@ -471,11 +513,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static EcPlatform GetEcPlatformById(IDbConnection conn, int? ecId) internal static EcPlatform GetEcPlatformById(IDbConnection conn, int? ecId)
{ {
if (ecId == null) return null; var rtns = new EcPlatform();
if (ecId == null) return rtns;
var query = conn.From<EcPlatform>(); var query = conn.From<EcPlatform>();
query.Where(o => o.EC_ID == ecId); query.Where(o => o.EC_ID == ecId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new EcPlatform();
return rtns;
} }
/// <summary> /// <summary>
/// 其他来源单位信息 /// 其他来源单位信息
...@@ -485,11 +530,14 @@ namespace Kivii.Third.Scjgj ...@@ -485,11 +530,14 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static Other GetOtherById(IDbConnection conn, int? otherId) internal static Other GetOtherById(IDbConnection conn, int? otherId)
{ {
if (otherId == null) return null; var rtns = new Other();
if (otherId == null) return rtns;
var query = conn.From<Other>(); var query = conn.From<Other>();
query.Where(o => o.ID == otherId); query.Where(o => o.ID == otherId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new Other();
return rtns;
} }
/// <summary> /// <summary>
/// 直播平台信息 /// 直播平台信息
...@@ -499,23 +547,31 @@ namespace Kivii.Third.Scjgj ...@@ -499,23 +547,31 @@ namespace Kivii.Third.Scjgj
/// <returns></returns> /// <returns></returns>
internal static Live GetLiveById(IDbConnection conn, int? liveId) internal static Live GetLiveById(IDbConnection conn, int? liveId)
{ {
if (liveId == null) return null; var rtns = new Live();
if (liveId == null) return rtns;
var query = conn.From<Live>(); var query = conn.From<Live>();
query.Where(o => o.LIVE_ID == liveId); query.Where(o => o.LIVE_ID == liveId);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new Live();
return rtns;
} }
/// <summary> /// <summary>
/// 任务来源对照表 /// 任务来源对照表
/// </summary> /// </summary>
/// <param name="conn"></param> /// <param name="conn"></param>
/// <param name="TaskSource"></param> /// <param name="taskSource"></param>
/// <returns></returns> /// <returns></returns>
internal static TaskSource GetTaskSource(IDbConnection conn, string TaskSource) internal static TaskSource GetTaskSource(IDbConnection conn, string taskSource)
{ {
var rtns = new TaskSource();
if (taskSource == null) return rtns;
var query = conn.From<TaskSource>(); var query = conn.From<TaskSource>();
query.Where(o => o.TASK_SOURCE == TaskSource); query.Where(o => o.TASK_SOURCE == taskSource);
return conn.Single(query); rtns = conn.Single(query);
if (rtns == null) rtns = new TaskSource();
return rtns;
} }
/// <summary> /// <summary>
......
...@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; ...@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("5.4.2024.6270")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("5.4.2024.6270")]
...@@ -97,7 +97,9 @@ namespace Kivii.Third.Scjgj ...@@ -97,7 +97,9 @@ namespace Kivii.Third.Scjgj
if (Take.HasValue && Take.Value > 0) query.Take(Take.Value); if (Take.HasValue && Take.Value > 0) query.Take(Take.Value);
if (!OrderBy.IsNullOrEmpty()) query.OrderBy(OrderBy); if (!OrderBy.IsNullOrEmpty()) query.OrderBy(OrderBy);
var results = conn.Select(query); var results = conn.Select(query);
var total = conn.Scalar<PlanDetail, int>(o => Sql.Count(o.ID)); int total = 0;
if (!QueryValues.IsNullOrEmpty()) total = conn.Scalar<PlanDetail, int>(o => Sql.Count(o.ID), o => o.PLAN_CODE.Contains(QueryValues));
else total = conn.Scalar<PlanDetail, int>(o => Sql.Count(o.ID));
rtns.Results = results; rtns.Results = results;
rtns.Total = total; rtns.Total = total;
} }
...@@ -131,12 +133,12 @@ namespace Kivii.Third.Scjgj ...@@ -131,12 +133,12 @@ namespace Kivii.Third.Scjgj
public string PlanNumber { get; set; }//计划批次号LOT_NUM public string PlanNumber { get; set; }//计划批次号LOT_NUM
public bool ToReport { get; set; }
public override object OnExecution(IRequest req, IResponse res) public override object OnExecution(IRequest req, IResponse res)
{ {
BatchNumber.ThrowIfNullOrEmpty("请传入计划编号"); BatchNumber.ThrowIfNullOrEmpty("请传入计划编号");
PlanNumber.ThrowIfNullOrEmpty("请传入批次号"); PlanNumber.ThrowIfNullOrEmpty("请传入批次号");
var rtns = new RestfulQueryResponse<PlanDetail>(); var result = new PlanDetail();
rtns.Results = new List<PlanDetail>();
var factory = Kivii.Linq.LinqUtils.GetLinqConnectionFactory(Configs.ConnectionString, Configs.ConnectionProviderName); var factory = Kivii.Linq.LinqUtils.GetLinqConnectionFactory(Configs.ConnectionString, Configs.ConnectionProviderName);
using (var conn = factory.OpenDbConnection()) using (var conn = factory.OpenDbConnection())
{ {
...@@ -146,8 +148,8 @@ namespace Kivii.Third.Scjgj ...@@ -146,8 +148,8 @@ namespace Kivii.Third.Scjgj
query.Where(o => o.PLAN_CODE == BatchNumber && o.LOT_NUM == PlanNumber); query.Where(o => o.PLAN_CODE == BatchNumber && o.LOT_NUM == PlanNumber);
var planDetail = conn.Single(query); var planDetail = conn.Single(query);
if (planDetail == null) throw new Exception("未找到此任务单"); if (planDetail == null) throw new Exception("未找到此任务单");
var result = planDetail.ConvertTo(conn); result = planDetail.DataFilling(conn);
rtns.Results.Add(result);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -155,21 +157,18 @@ namespace Kivii.Third.Scjgj ...@@ -155,21 +157,18 @@ namespace Kivii.Third.Scjgj
} }
} }
if (!ToReport)
{
var rtns=new RestfulReadResponse<PlanDetail>();
rtns.Result = result;
return rtns; return rtns;
} }
} else
[RequiresAnyRole(MemberRoles.Everyone)]
public class PlanDetailConvertToReport : RestfulExecution<PlanDetail>
{
public PlanDetail Item { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{ {
var rtns = new RestfulReadResponse<Report>(); var rtns = new RestfulReadResponse<Report>();
rtns.Result = Item.ConvertTo(); rtns.Result = result.ConvertTo();
return rtns; return rtns;
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment