|
|
using CommonFunc.Tools;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using XGL.Models.Model.FoamingMac;
|
|
|
|
|
|
namespace XGL.Data.DBService
|
|
|
{
|
|
|
public class FormingMachineService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取成型机在产物料信息
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataTable GetFormingMachineInfo(string devicecode,string workDate)
|
|
|
{
|
|
|
// string sql = $@"SELECT DISTINCT
|
|
|
// ord.workorder_id,
|
|
|
// ord.workorder_code,
|
|
|
// res.OrderCode,
|
|
|
// ord.product_name,
|
|
|
// product_code,
|
|
|
// isnull( car_num, 0 ) AS car_num,
|
|
|
// isnull( plan_time, '1900-01-01 08:00:00' ) AS plan_time,
|
|
|
// ord.status ,
|
|
|
// ord.route_code,
|
|
|
// ord.attr1,
|
|
|
// ord.shift_id
|
|
|
//FROM
|
|
|
// mes_material_transfer_result res
|
|
|
// LEFT JOIN pro_order_workorder ord ON res.OrderCode = ord.workorder_id
|
|
|
// LEFT JOIN pro_wet_material_plan_detail wet ON wet.workorder_id = res.OrderCode
|
|
|
// LEFT JOIN pro_rfid_process_detail rfid ON rfid.workorder_code = ord.workorder_code
|
|
|
// AND rfid.rfid = res.rfid
|
|
|
//WHERE
|
|
|
// equipmentCode = '{devicecode}'
|
|
|
// AND rfid.create_time >= (
|
|
|
// SELECT
|
|
|
// CONCAT ( CONVERT ( VARCHAR ( 10 ), GetDate( ), 120 ), ' ', Shift_Start_Time ) AS Shift_Start_Time
|
|
|
// FROM
|
|
|
// base_shifts_t
|
|
|
// WHERE
|
|
|
// Shift_Start_Time <= CONVERT ( TIME, GETDATE( ) )
|
|
|
// AND Shift_End_Time > CONVERT ( TIME, GETDATE( ) )
|
|
|
// )
|
|
|
// AND rfid.create_time<= (
|
|
|
// SELECT
|
|
|
// CONCAT ( CONVERT ( VARCHAR ( 10 ), GetDate( ), 120 ), ' ', Shift_End_Time ) AS Shift_End_Time
|
|
|
// FROM
|
|
|
// base_shifts_t
|
|
|
// WHERE
|
|
|
// Shift_Start_Time <= CONVERT ( TIME, GETDATE( ) )
|
|
|
// AND Shift_End_Time > CONVERT ( TIME, GETDATE( ) )
|
|
|
// ) And ord.prod_line_code like '%{devicecode}%'
|
|
|
//ORDER BY
|
|
|
// ( isnull( plan_time, '1900-01-01 08:00:00' ) ) DESC";
|
|
|
|
|
|
string sql = $@"SELECT DISTINCT
|
|
|
ord.workorder_id,
|
|
|
ord.workorder_code,
|
|
|
res.OrderCode,
|
|
|
ord.product_name,
|
|
|
product_code,
|
|
|
isnull( car_num, 0 ) AS car_num,
|
|
|
isnull( plan_time, '1900-01-01 08:00:00' ) AS plan_time,
|
|
|
ord.status ,
|
|
|
ord.route_code,
|
|
|
ord.attr1,
|
|
|
ord.shift_id ,totalCount,shift.Shift_Desc
|
|
|
FROM
|
|
|
pro_order_workorder ord
|
|
|
LEFT JOIN mes_material_transfer_result res ON res.OrderCode = ord.workorder_id
|
|
|
LEFT JOIN pro_wet_material_plan_detail wet ON wet.workorder_id = res.OrderCode
|
|
|
LEFT JOIN pro_rfid_process_detail rfid ON rfid.workorder_code = ord.workorder_code
|
|
|
left join (select count(*) as totalCount,ordercode from mes_material_transfer_result
|
|
|
where CONVERT(VARCHAR(10), update_time , 120) = CONVERT(VARCHAR(10),'{workDate}', 120) and equipmentCode = '{devicecode}' group by OrderCode) tt
|
|
|
on (tt.ordercode = wet.workorder_id )
|
|
|
AND rfid.rfid = res.rfid
|
|
|
LEFT JOIN base_shifts_t shift on ord.shift_id = shift.Shift_Id
|
|
|
WHERE
|
|
|
CONVERT(VARCHAR(10), wet.plan_time , 120) = CONVERT(VARCHAR(10), '{workDate}', 120 )
|
|
|
And ord.prod_line_code like '%{devicecode}%' and totalCount is not null
|
|
|
ORDER BY
|
|
|
( isnull( plan_time, '1900-01-01 08:00:00' ) ) DESC";
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
return dtset.Tables[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public DataTable GetShiftList()
|
|
|
{
|
|
|
string sql = $@"select shift_id,Shift_Code,Shift_Desc,Shift_Start_Time,Shift_End_Time from base_shifts_t where del_flag ='0' ";
|
|
|
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
|
|
|
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
return dtset.Tables[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取成型机状态
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public string getnumber(string order, string devicecode,string shetl)
|
|
|
{
|
|
|
string sql = $@"SELECT COUNT(*) FROM mes_material_transfer_result WHERE equipmentCode='{order}' and work_date='{devicecode}' and shift_id='{shetl}' and rfid_status='1'";
|
|
|
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
if (dtset != null && dtset.Tables.Count > 0)
|
|
|
{
|
|
|
// 获取查询结果中的计数值并转换为字符串
|
|
|
string countAsString = dtset.Tables[0].Rows[0][0].ToString();
|
|
|
return countAsString;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取成型机状态
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataTable GetFormingMachineState(string devicecode)
|
|
|
{
|
|
|
|
|
|
string sql = $@"select status from base_equipment where equipment_code = '{devicecode}'; ";
|
|
|
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
return dtset.Tables[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询出入记录
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataTable GetInOutHistoryList(string workOrderCode,string devicecode,string workDate)
|
|
|
{
|
|
|
string sql = $@"SELECT DISTINCT ord.workorder_id,ord.workorder_code,res.OrderCode,ord.product_name,product_code,isnull(car_num,0) as car_num,
|
|
|
isnull([begin],'1900-01-01 08:00:00') as [begin],ord.status,ord.route_code,ord.attr1,work_batch_code,res.taskcode,res.rfid,plan_time ,res.update_time
|
|
|
FROM [dbo].[mes_material_transfer_result] res
|
|
|
LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
|
|
|
left JOIN pro_wet_material_plan_detail wet on wet.workorder_id = ord.workorder_id
|
|
|
LEFT JOIN pro_rfid_process_detail rfid on rfid.workorder_code = ord.workorder_code and rfid.rfid = res.rfid
|
|
|
where equipmentCode = '{devicecode}' and work_date = '{workDate}' and ord.workorder_code = '{workOrderCode}' and res.OrderCode is not null ORDER BY update_time desc; ";
|
|
|
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
return dtset.Tables[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询完成记录
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataTable GetCompleteHistoryList(string devicecode)
|
|
|
{
|
|
|
//taskcode=1,当前机台完成,ord.status = 'w3'当前工单完成
|
|
|
// string sql = $@"SELECT workorder_code,product_name,product_code,isnull(car_num,0) as car_num,isnull([begin],'1900-00-00') as [begin],beout,ord.status,product_date,ord.create_time FROM [dbo].[mes_material_transfer_result] res
|
|
|
//LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
|
|
|
//where res.taskcode = '1' and equipmentCode = '{devicecode}'; ";
|
|
|
string sql = $@"SELECT ord.workorder_id,ord.workorder_code,res.OrderCode,ord.product_name,product_code,isnull(car_num,0) as car_num,
|
|
|
isnull([begin],'1900-01-01 08:00:00') as [begin],ord.status ,ord.route_code,ord.attr1,work_batch_code,res.taskcode,res.rfid,plan_time ,res.update_time
|
|
|
FROM [dbo].[mes_material_transfer_result] res
|
|
|
LEFT JOIN pro_order_workorder ord on res.OrderCode = ord.workorder_id
|
|
|
left JOIN pro_wet_material_plan_detail wet on wet.workorder_id = ord.workorder_id
|
|
|
LEFT JOIN pro_rfid_process_detail rfid on rfid.workorder_code = ord.workorder_code and rfid.rfid = res.rfid
|
|
|
where res.taskcode = '0' and equipmentCode = 'C6' and res.OrderCode is not null ORDER BY plan_time; ";
|
|
|
|
|
|
DataSet dtset = Utils.netClientDBHelper.getDataSet(sql);
|
|
|
if (dtset != null && dtset.Tables.Count > 0 && dtset.Tables[0].Rows.Count > 0)
|
|
|
{
|
|
|
return dtset.Tables[0];
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取工单当前状态,弃用
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public string GetWorkOrderStatus(string orderCode)
|
|
|
{
|
|
|
|
|
|
string sql = $@"select status from pro_order_workorder where workorder_code = '{orderCode}'";
|
|
|
var obj = Utils.netClientDBHelper.getScalar(sql, null);
|
|
|
string issucc = obj == null ? "" : obj.ToString();
|
|
|
|
|
|
return issucc;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新工单
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool UpdateWorkOrder(string orderCode,string status)
|
|
|
{
|
|
|
|
|
|
string sql = $@"update pro_order_workorder set status = '{status}' where workorder_code = '{orderCode}'";
|
|
|
|
|
|
int issucc = Utils.netClientDBHelper.executeUpdate(sql);
|
|
|
|
|
|
return issucc > 0 ? true : false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新工单
|
|
|
/// </summary>
|
|
|
/// <param name="bdt"></param>
|
|
|
/// <param name="edt"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool InsertData(FoamingMacModel formingModel)
|
|
|
{
|
|
|
|
|
|
string sql = $@"INSERT INTO [lanju_op_xiaolan_ds].[dbo].[mes_material_transfer_result] (
|
|
|
[id],
|
|
|
[begin],
|
|
|
[beout],
|
|
|
[equipmentCode],
|
|
|
[OrderCode],
|
|
|
[sku],
|
|
|
[planID],
|
|
|
[rfid],
|
|
|
[now_process_id],
|
|
|
[status],
|
|
|
[create_time],
|
|
|
[rfid_status],
|
|
|
[taskcode],
|
|
|
[state],
|
|
|
[update_time]
|
|
|
)
|
|
|
VALUES
|
|
|
(
|
|
|
'{CommonFunc.Common.GetUUID()}',
|
|
|
'GetDate()',
|
|
|
'GetDate()',
|
|
|
'{Utils.GetAppSetting("DeviceCode")}',
|
|
|
'{formingModel.workorder_id}',
|
|
|
'{formingModel.product_code}',
|
|
|
'',
|
|
|
'{formingModel.rfid}',
|
|
|
'',
|
|
|
'4',
|
|
|
'GetDate()',
|
|
|
'1',
|
|
|
'0',
|
|
|
'1',
|
|
|
'GetDate()'
|
|
|
);";
|
|
|
|
|
|
int issucc = Utils.netClientDBHelper.executeUpdate(sql);
|
|
|
|
|
|
return issucc > 0 ? true : false;
|
|
|
}
|
|
|
}
|
|
|
}
|