using Dapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.SqlClient;
|
using System.Linq;
|
using System.Web;
|
using VueWebApi.DDKanBanModel;
|
using VueWebApi.Models;
|
using VueWebApi.Tools;
|
|
namespace VueWebApi.DLL.DAL
|
{
|
public class KanBanManagerentDAL
|
{
|
public static DataTable dt; //定义全局变量dt
|
public static bool res; //定义全局变量dt
|
public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
|
public static string strProcName = ""; //定义全局sql变量
|
public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合
|
public static SqlParameter[] parameters; //定义全局SqlParameter参数数组
|
|
#region[大岛车间综合看板,获取生产车间]
|
public static ToMessage ShopSearch()
|
{
|
string sql = "";
|
string search = "";
|
var dynamicParams = new DynamicParameters();
|
try
|
{
|
//获取车间信息
|
sql = @"select org_code ,org_name from TOrganization where is_delete='0' and description='W'";
|
var data = DapperHelper.selectdata(sql, dynamicParams);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛车间综合看板,左上产线加工任务接口]
|
public static ToMessage LineSearchTopLeftData(string shopcode)
|
{
|
string sql = "";
|
List<ShopTopLeft> list = new List<ShopTopLeft>();
|
var dynamicParams = new DynamicParameters();
|
try
|
{
|
if (shopcode != null || shopcode != "") //产线编码不为空
|
{
|
string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
|
//查询产线下已开工的加工单信息
|
sql = @"select * from (
|
select distinct E.saleOrderCode,A.wo_code,P.plan_qty,M.partcode,M.partname,M.partspec,T.name as uomname from TK_Wrk_Record A
|
inner join TK_Wrk_Man P on A.wo_code=P.wo_code
|
left join TMateriel_Info M on P.materiel_code=M.partcode
|
left join TUom T on M.uom_code=T.code
|
left join TKimp_Ewo E on P.m_po=E.wo and P.sourceid=E.id
|
left join (
|
select wo_code,sum(good_qty) as good_qty,sum(ng_qty) as ng_qty,sum(bad_qty) as bad_qty from TK_Wrk_Step where isend='Y' group by wo_code
|
) S on P.wo_code=S.wo_code
|
where P.status<>'CLOSED' and P.status<>'NEW' and P.wkshp_code in @shopcode and A.style='S' and A.step_seq='1'
|
) as AA where AA.plan_qty>(AA.good_qty+aa.bad_qty+AA.ng_qty)";
|
var data0 = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
|
|
if (data0.Rows.Count > 0)
|
{
|
for (int j = 0; j < data0.Rows.Count; j++)
|
{
|
string saleOrderCode = data0.Rows[j]["SALEORDERCODE"].ToString();//销售订单号
|
string wo_code = data0.Rows[j]["WO_CODE"].ToString();//工单号
|
string plan_qty = data0.Rows[j]["PLAN_QTY"].ToString();//任务数量
|
string partcode = data0.Rows[j]["PARTCODE"].ToString();//产品编码
|
string partname = data0.Rows[j]["PARTNAME"].ToString();//产品名称
|
string partspec = data0.Rows[j]["PARTSPEC"].ToString();//产品规格
|
string uomname = data0.Rows[j]["UOMNAME"].ToString();//单位名称
|
ShopTopLeft lineone = new ShopTopLeft();
|
lineone.saleordercode = saleOrderCode;
|
lineone.workcode = wo_code;
|
lineone.qty = plan_qty;
|
lineone.partnumber = partcode;
|
lineone.partname = partname;
|
lineone.partspec = partspec;
|
lineone.uom = uomname;
|
lineone.children = new List<TreeTwo>();
|
|
//查新工单下工序信息
|
sql = @"select A.seq,T.stepcode,T.stepname,A.plan_qty,A.good_qty,A.ng_qty,A.status
|
from TK_Wrk_Step A
|
left join TStep T on A.step_code=T.stepcode
|
where A.wo_code=@wo_code";
|
dynamicParams.Add("@wo_code", wo_code);
|
var data1 = DapperHelper.selectdata(sql, dynamicParams);
|
for (int k = 0; k < data1.Rows.Count; k++)
|
{
|
string stepseq = data1.Rows[k]["SEQ"].ToString();//工序序号
|
string stepcode = data1.Rows[k]["STEPCODE"].ToString();//工序编码
|
string stepname = data1.Rows[k]["STEPNAME"].ToString();//工序名称
|
string planqty = data1.Rows[k]["PLAN_QTY"].ToString();//任务数量
|
string good_qty = data1.Rows[k]["GOOD_QTY"].ToString();//报工数量
|
string ng_qty = data1.Rows[k]["NG_QTY"].ToString();//不良数量
|
string status = data1.Rows[k]["STATUS"].ToString();//状态
|
TreeTwo linetwo = new TreeTwo();
|
linetwo.stepseq = stepseq;
|
linetwo.stepcode = stepcode;
|
linetwo.stepname = stepname;
|
linetwo.planqty = planqty;
|
linetwo.goodqty = good_qty;
|
linetwo.ngqty = ng_qty;
|
linetwo.status = status;
|
lineone.children.Add(linetwo);
|
}
|
list.Add(lineone);
|
}
|
}
|
else
|
{
|
mes.code = "300";
|
mes.Message = "当前车间下无在生产任务!";
|
mes.data = null;
|
}
|
}
|
else
|
{
|
mes.code = "300";
|
mes.Message = "车间参数不能为空!";
|
mes.data = null;
|
}
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = list;
|
return mes;
|
}
|
#endregion\
|
|
#region[大岛车间综合看板,左下列表接口]
|
public static ToMessage LineSearchBottomLeftData(string shopcode)
|
{
|
string sql = "";
|
var dynamicParams = new DynamicParameters();
|
string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
|
try
|
{
|
//获取任务列表信息
|
sql = @"select A.*,ROW_NUMBER() OVER(ORDER BY (case when A.warning<=2 then A.planenddate end) asc ,A.planstartdate asc) AS RowNum from(
|
select A.status,A.lm_date,E.saleOrderCode,A.wo_code,M.partcode,M.partname,M.partspec,U.name,
|
A.plan_qty,B.good_qty,B.ng_qty,E.planstartdate,E.planenddate, datediff(day,getdate(),E.planenddate) warning
|
from TK_Wrk_Man A
|
inner join TK_Wrk_Step B on A.wo_code=B.wo_code
|
inner join TKimp_Ewo E on A.m_po=E.wo and A.sourceid=E.id
|
left join TMateriel_Info M on A.materiel_code=M.partcode
|
left join TUom U on M.uom_code=U.code
|
where A.status<>'CLOSED' and A.wkshp_code in @shopcode and A.is_delete<>'1' and B.isend='Y'
|
and A.plan_qty>(B.good_qty+B.ng_qty+B.bad_qty)
|
)as A ";
|
var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛车间综合看板,右上top排行接口,当日]
|
public static ToMessage LineSearchTopRightData(string shopcode)
|
{
|
string sql = "";
|
var dynamicParams = new DynamicParameters();
|
string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
|
try
|
{
|
//获取产品报工top5信息
|
sql = @"select top 5 A.org_name as wkshname,A.name as linename,A.partname,isnull(sum(A.good_qty),0) as good_qty from(
|
select W.org_name,E.name,M.partname,A.good_qty from TK_Wrk_Record A
|
inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
|
inner join TMateriel_Info M on A.materiel_code=M.partcode
|
inner join TEqpInfo E on A.eqp_code=E.code
|
inner join TOrganization W on E.wksp_code=W.org_code and W.description='W'
|
where A.style='B' and S.isend='Y' and W.org_code in @shopcode and datediff(day,GETDATE(),A.lm_date)=0
|
union all
|
select C.name as linename,'' as wkshname,M.partname,A.sqty as good_qty from TK_Wrk_OutRecord A
|
inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
|
inner join TMateriel_Info M on A.materiel_code=M.partcode
|
inner join TCustomer C on A.wx_code=C.code and C.btype='WX'
|
where A.style='S' and S.isend='Y' and datediff(day,GETDATE(),A.lm_date)=0
|
) as A group by A.org_name,A.name,A.partname order by good_qty desc";
|
var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛车间综合看板,右下top排行接口,当前时间往前一周]
|
public static ToMessage LineSearchBottomRightData(string shopcode)
|
{
|
string sql = "";
|
var dynamicParams = new DynamicParameters();
|
string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
|
try
|
{
|
//获取报工不良top5信息
|
sql = @"select isnull(COUNT(B.name),0) cont,B.name
|
from CSR_WorkRecord_Defect A
|
inner join TDefect B on A.defect_code=B.code
|
inner join TK_Wrk_Man M on A.wo_code=M.wo_code
|
where DateDiff(dd,A.lm_date,getdate())<=7 and M.wkshp_code in @shopcode
|
group by B.name order by cont desc";
|
var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
|
#region[采购订单跟踪管理看板,左上本月采购订单数、本月采购进货单数、本月采购入库单数]
|
public static ToMessage PurchaseLeftTop()
|
{
|
string sql = "";
|
try
|
{
|
//获取本月采购订单数、本月采购进货单数、本月采购入库单数
|
sql = @"select * from h_v_DDKanBan_PurchaseLeftTop ";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[采购订单跟踪管理看板,左下采购订单跟踪列表]
|
public static ToMessage PurchaseLeftBottom()
|
{
|
string sql = "";
|
try
|
{
|
//获取采购订单跟踪列表
|
sql = @"select * from h_v_DDKanBan_PurchaseLeftBottom ";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[采购订单跟踪管理看板,右侧Top]
|
public static ToMessage PurchaseRight()
|
{
|
string sql = "";
|
try
|
{
|
//获取采购订单跟踪列表
|
sql = @"select * from h_v_DDKanBan_PurchaseRight ";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
|
|
#region[大岛仓库看板,左上产品待入库列表]
|
public static ToMessage WareHouseTopLeftData()
|
{
|
string sql = "";
|
try
|
{
|
//获取仓库生产加工单待入库列表
|
sql = @"select * from h_v_DDKanBan_WareHouseTopLeft order by voucherdate";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛仓库看板,左下产品待发货列表]
|
public static ToMessage WareHouseTopBottomData()
|
{
|
string sql = "";
|
try
|
{
|
//获取仓库生产加工单待入库列表
|
sql = @"select * from h_v_DDKanBan_WareHouseTopBottom order by voucherdate";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛仓库看板,右上成品库、半成品库top5库存排行]
|
public static ToMessage WareHouseRightTopData()
|
{
|
string sql = "";
|
try
|
{
|
sql = @"select * from h_v_DDKanBan_WareHouseRightTop";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
#region[大岛仓库看板,右下原料库库top5库存排行]
|
public static ToMessage WareHouseRightBottomData()
|
{
|
string sql = "";
|
try
|
{
|
sql = @"select * from h_v_DDKanBan_WareHouseRightBottom";
|
var data = DapperHelper.selecttable(sql);
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
|
|
#region[车间看板公告]
|
public static ToMessage WkspReportNotice(string shopcode)
|
{
|
string sql = "";
|
var dynamicParams = new DynamicParameters();
|
try
|
{
|
string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[]
|
//获取车间公告信息
|
sql = @"select contents from TSystemAnnouncement
|
where wksp_code in @shopcode";
|
var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
|
mes.code = "200";
|
mes.Message = "查询成功!";
|
mes.data = data;
|
}
|
catch (Exception e)
|
{
|
mes.code = "300";
|
mes.count = 0;
|
mes.Message = e.Message;
|
mes.data = null;
|
}
|
return mes;
|
}
|
#endregion
|
}
|
}
|