添加项目文件。
This commit is contained in:
539
SamplePre.ProcessBll/BLL/SampleSequenceBll.cs
Normal file
539
SamplePre.ProcessBll/BLL/SampleSequenceBll.cs
Normal file
@@ -0,0 +1,539 @@
|
||||
using DataDAL;
|
||||
using DataDAL.DBContext;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.DAL;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamplePre.ProcessBll.SampleSequence
|
||||
{
|
||||
/// <summary>
|
||||
/// 样本序列管理业务逻辑
|
||||
/// </summary>
|
||||
public class SampleSequenceBll
|
||||
{
|
||||
SampleSequenceDal sampleSequenceDal = new SampleSequenceDal();
|
||||
|
||||
|
||||
|
||||
SOPDal sopDal = new SOPDal();
|
||||
|
||||
|
||||
public List<sys_dict> GetSampleType()
|
||||
{
|
||||
|
||||
|
||||
List<sys_dict> data = DBFactory.Instance.Queryable<sys_dict>().Where(p => p.class_id == 3).ToList();
|
||||
|
||||
return data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取标准动作参数
|
||||
/// </summary>
|
||||
/// <param name="standId"></param>
|
||||
/// <returns></returns>
|
||||
public List<sys_standard_action_parm_ext> GetStrandActionParamByStrandId(string standId)
|
||||
{
|
||||
var result = DBFactory.Instance.Queryable<sys_standard_action_parm>()
|
||||
.LeftJoin<sys_action>((a, b) => a.action_id == b.id)
|
||||
.LeftJoin<sys_parm>((a, b, c) => a.parm_id == c.id)
|
||||
.LeftJoin<sys_standard>((a, b, c,d) => a.standard_id == d.id)
|
||||
.Where((a, b, c, d) => a.standard_id == standId)
|
||||
.OrderBy((a, b, c, d) => a.action_seqno)
|
||||
.Select((a, b, c, d) => new sys_standard_action_parm_ext
|
||||
{
|
||||
id = a.id,
|
||||
standard_id = a.standard_id,
|
||||
action_id = a.action_id,
|
||||
action_seqno = a.action_seqno,
|
||||
parm_id = a.parm_id,
|
||||
parm_seqno = a.parm_seqno,
|
||||
standard_process_id = a.standard_process_id,
|
||||
data_value = a.data_value,
|
||||
action_name = b.action_name,
|
||||
title = c.title,
|
||||
unit = c.unit,
|
||||
data_type = c.data_type,
|
||||
plc_type = c.plc_type,
|
||||
actionAndseqno = $"{d.standard_name}: {a.action_seqno}{b.action_name}"
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
//List<sys_standard_action_parm_ext> datas = sopDal.GetStrandActionParamByStrandId(standId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<sys_action_ext> QuerySysAction()
|
||||
{
|
||||
var result = DBFactory.Instance.Queryable<sys_action>()
|
||||
.LeftJoin<sys_dict>((a, s) => a.action_unit == s.id)
|
||||
.Where((a, s) => s.class_id == 2)
|
||||
.Select((a, s) => new sys_action_ext
|
||||
{
|
||||
id = a.id,
|
||||
action_name = a.action_name,
|
||||
action_unit = a.action_unit,
|
||||
action_adress = a.action_adress,
|
||||
plc_type = a.plc_type,
|
||||
remark = a.remark,
|
||||
action_unitname = s.data_value
|
||||
})
|
||||
.ToList();
|
||||
|
||||
//List<sys_action_ext> sysActions = standardDal.QuerySysAction();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int DelTubeInputByCode(string code)
|
||||
{
|
||||
|
||||
|
||||
int val = DBFactory.Instance.Deleteable<tube_input>().Where(p => p.qrcode == code).ExecuteCommand();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存下发命令记录
|
||||
/// </summary>
|
||||
/// <param name="cmdExec"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public int SaveCmdExec(sample_exec_ext cmdExec)
|
||||
{
|
||||
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
|
||||
//主记录
|
||||
int val = _db.Insertable<sample_exec>(cmdExec).ExecuteCommand();
|
||||
//明细
|
||||
int val2 = _db.Insertable<sample_exec_detail>(cmdExec.sampleExecDetails).ExecuteCommand();
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
public List<sys_standard> QuerySysStandards(string sampleId)
|
||||
{
|
||||
|
||||
List<sys_standard> data = DBFactory.Instance.Queryable<sys_standard>().Where(p => p.sample_id == sampleId).ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public string QueryQrcode()
|
||||
{
|
||||
string qrcode = "";
|
||||
|
||||
List<sys_dict> data = DBFactory.Instance.Queryable<sys_dict>().Where(p => p.class_id == 1).ToList();
|
||||
if (data.Count > 0)
|
||||
{
|
||||
qrcode = (int.Parse(data[0].data_value) + 1).ToString("0000");
|
||||
}
|
||||
return qrcode;
|
||||
|
||||
}
|
||||
|
||||
public int SaveDataAndQrcode(tube_input qRcode, sys_dict sys_Dict)
|
||||
{
|
||||
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
|
||||
//保存样品记录
|
||||
_db.Insertable<tube_input>(qRcode).ExecuteCommand();
|
||||
|
||||
//更新二维码
|
||||
int val = _db.Updateable<sys_dict>()
|
||||
.SetColumns(p => new sys_dict() { data_value = sys_Dict.data_value })
|
||||
.Where(p => p.class_id == 1)
|
||||
.ExecuteCommand();
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public List<tube_input> GetTubeData(DateTime dt1, DateTime dt2)
|
||||
{
|
||||
List<tube_input> data = DBFactory.Instance.Queryable<tube_input>().Where(p => p.input_date >= dt1 && p.input_date <= dt2).ToList();
|
||||
|
||||
|
||||
return data;;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成指令字节数组byte
|
||||
/// </summary>
|
||||
/// <param name="sysAction"></param>
|
||||
/// <param name="standardProcessParms"></param>
|
||||
/// <returns></returns>
|
||||
public List<byte> CreateCmdBytes(List<sys_action_ext> sysAction, List<string> sopIds, List<sys_standard_action_parm_ext> standardProcessParms)
|
||||
{
|
||||
string cmdReamrk = "";
|
||||
|
||||
List<byte> sop = new List<byte>();
|
||||
|
||||
try
|
||||
{
|
||||
//起始位
|
||||
sop.Insert(0, 0xCC);
|
||||
cmdReamrk += $"【0 开始:{sop[0]}】 ";
|
||||
|
||||
//插入总字节数-占位
|
||||
sop.Insert(1, 0);
|
||||
//cmdReamrk += $"【1 总字节数:{Convert.ToByte(seq + 1)}】 ";
|
||||
|
||||
//插入总动作数
|
||||
sop.Insert(2, 0);
|
||||
//cmdReamrk += $"【2 总动作数:0】 ";
|
||||
|
||||
int seq = 3;
|
||||
|
||||
//总动作数
|
||||
int actionCount = 0;
|
||||
//===============
|
||||
foreach (string standrad_id in sopIds)
|
||||
{
|
||||
//查询标准下的动作
|
||||
var standardActions = GetStrandActionByStrandId(standrad_id);
|
||||
//动作排序
|
||||
standardActions = standardActions.OrderBy(p => p.process_no).ToList();
|
||||
|
||||
actionCount += standardActions.Count();
|
||||
|
||||
foreach (var actionItem in standardActions)
|
||||
{
|
||||
//int start = seq; //记录起始位置
|
||||
|
||||
//转换PLC映射名称
|
||||
string action_plc = sysAction.FirstOrDefault(p => p.id == actionItem.process_id)?.plc_type;
|
||||
//动作类型(如:离心)
|
||||
byte action_byte = Convert.ToByte(action_plc);
|
||||
sop.Insert(seq, action_byte);
|
||||
cmdReamrk += $"【{seq} 动作:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
//查询动作下的参数
|
||||
var paramData = standardProcessParms.Where(p => p.action_id == actionItem.process_id && p.action_seqno == actionItem.process_no && p.standard_id == standrad_id).ToList();
|
||||
//插入动作字节长度
|
||||
int actionLenth = (int)(paramData.Count() * 5 + 2);
|
||||
sop.Insert(seq, (byte)actionLenth);
|
||||
cmdReamrk += $"【{seq} 动作字节长度:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
foreach (var item in paramData)
|
||||
{
|
||||
//转换plc参数类型
|
||||
string param_plc = item.plc_type;//parms.FirstOrDefault(p => p.title == item.title).plc_type;
|
||||
|
||||
//参数类型(如:时间)
|
||||
byte parm_byte = Convert.ToByte(param_plc);
|
||||
sop.Insert(seq, parm_byte);
|
||||
cmdReamrk += $"【{seq} 参数类型:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
|
||||
sys_standard_action_parm_ext actionParm = standardProcessParms.FirstOrDefault(p => p.title == item.title);
|
||||
string param_val = actionParm.data_value;
|
||||
if (actionParm.unit.ToUpper() == "ML") //都转换成最小单位ul
|
||||
{
|
||||
param_val = (float.Parse(param_val) * 1000).ToString();
|
||||
}
|
||||
|
||||
|
||||
//参数值
|
||||
float paramval = 0;
|
||||
paramval = float.Parse(param_val);
|
||||
|
||||
cmdReamrk += $"【{seq} 参数值float:{paramval}】 ";
|
||||
|
||||
|
||||
byte[] paramval_bytes = BitConverter.GetBytes(paramval);
|
||||
|
||||
sop.Insert(seq, paramval_bytes[0]);
|
||||
cmdReamrk += $"【{seq} 参数值byte:{sop[seq]}-";
|
||||
seq++;
|
||||
sop.Insert(seq, paramval_bytes[1]);
|
||||
cmdReamrk += $"{sop[seq]}-";
|
||||
seq++;
|
||||
sop.Insert(seq, paramval_bytes[2]);
|
||||
cmdReamrk += $"{sop[seq]}-";
|
||||
seq++;
|
||||
sop.Insert(seq, paramval_bytes[3]);
|
||||
cmdReamrk += $"{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//=================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//结束
|
||||
sop.Insert(seq, 0xEE);
|
||||
cmdReamrk += $"【{seq} 结束:{sop[seq]}-";
|
||||
seq++;
|
||||
sop.Insert(seq, 0xEE);
|
||||
cmdReamrk += $"{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
|
||||
//修改总字节数
|
||||
sop[1] = (byte)sop.Count;
|
||||
cmdReamrk += $"【1 总字节数:{sop[1]}】 ";
|
||||
|
||||
//修改总动作数据
|
||||
sop[2] = (byte)actionCount;
|
||||
cmdReamrk += $"【2 总动作数:{sop[2]}】 ";
|
||||
|
||||
LoggerHelper.Logger.Info($"{cmdReamrk}");
|
||||
|
||||
|
||||
return sop;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LoggerHelper.Logger.Error(ex.StackTrace);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成指令字节数组ushort
|
||||
/// </summary>
|
||||
/// <param name="sysAction"></param>
|
||||
/// <param name="standardProcessParms"></param>
|
||||
/// <returns></returns>
|
||||
public List<ushort> CreateCmdUshorts(List<sys_action_ext> sysAction, List<sys_standard_action_ext> standardActions, List<sys_standard_action_parm_ext> standardProcessParms)
|
||||
{
|
||||
string cmdReamrk = "";
|
||||
|
||||
List<ushort> sop = new List<ushort>();
|
||||
|
||||
try
|
||||
{
|
||||
//起始位
|
||||
sop.Insert(0, 0xCC);
|
||||
cmdReamrk += $"【0 开始:{sop[0]}】 ";
|
||||
|
||||
//插入总字节数
|
||||
sop.Insert(1, 0);
|
||||
//cmdReamrk += $"【1 总字节数:{0}】 ";
|
||||
|
||||
//插入总动作数
|
||||
sop.Insert(2, Convert.ToByte(standardActions.Count()));
|
||||
cmdReamrk += $"【2 总动作数:{Convert.ToByte(standardActions.Count())}】 ";
|
||||
|
||||
|
||||
|
||||
int seq = 3;
|
||||
foreach (var actionItem in standardActions)
|
||||
{
|
||||
int start = seq; //记录起始位置
|
||||
|
||||
//转换PLC映射名称
|
||||
string action_plc = sysAction.FirstOrDefault(p => p.id == actionItem.process_id)?.plc_type;
|
||||
//动作类型(如:离心)
|
||||
ushort action_byte = Convert.ToUInt16(action_plc);
|
||||
sop.Insert(seq, action_byte);
|
||||
cmdReamrk += $"【{seq} 动作:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
//查询动作下的参数
|
||||
var paramData = standardProcessParms.Where(p => p.action_id == actionItem.process_id && p.action_seqno == actionItem.process_no).ToList();
|
||||
//插入动作寄存器长度
|
||||
int actionLenth = (int)(paramData.Count() * 3 + 2);
|
||||
sop.Insert(seq, (byte)actionLenth);
|
||||
cmdReamrk += $"【{seq} 动作长度:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
foreach (var item in paramData)
|
||||
{
|
||||
//转换plc参数类型
|
||||
string param_plc = item.plc_type;//parms.FirstOrDefault(p => p.title == item.title).plc_type;
|
||||
|
||||
//参数类型(如:时间)
|
||||
ushort parm_byte = Convert.ToUInt16(param_plc);
|
||||
sop.Insert(seq, parm_byte);
|
||||
cmdReamrk += $"【{seq} 参数类型:{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
|
||||
sys_standard_action_parm_ext actionParm = standardProcessParms.FirstOrDefault(p => p.title == item.title);
|
||||
string param_val = actionParm.data_value;
|
||||
if (actionParm.unit.ToUpper() == "ML") //都转换成最小单位ul
|
||||
{
|
||||
param_val = (float.Parse(param_val) * 1000).ToString();
|
||||
}
|
||||
|
||||
|
||||
//参数值
|
||||
float paramval = 0;
|
||||
paramval = float.Parse(param_val);
|
||||
|
||||
cmdReamrk += $"【{seq} 参数值float:{paramval}】 ";
|
||||
|
||||
//===float转ushort数组
|
||||
byte[] bytes = BitConverter.GetBytes(paramval);
|
||||
var a = BitConverter.ToUInt16(new byte[] { bytes[0], bytes[1] }, 0);
|
||||
var b = BitConverter.ToUInt16(new byte[] { bytes[2], bytes[3] }, 0);
|
||||
|
||||
ushort[] ushorts = { b, a };
|
||||
|
||||
sop.Insert(seq, ushorts[0]);
|
||||
cmdReamrk += $"【{seq} 参数值ushort:{sop[seq]}-";
|
||||
seq++;
|
||||
|
||||
sop.Insert(seq, ushorts[1]);
|
||||
cmdReamrk += $"{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
//============
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//结束
|
||||
sop.Insert(seq, 0xEE);
|
||||
cmdReamrk += $"【{seq} 结束:{sop[seq]}-";
|
||||
seq++;
|
||||
sop.Insert(seq, 0xEE);
|
||||
cmdReamrk += $"{sop[seq]}】 ";
|
||||
seq++;
|
||||
|
||||
|
||||
//修改总寄存器数量
|
||||
sop[1] = (ushort)sop.Count;
|
||||
cmdReamrk += $"【1 总寄存器数:{sop[1]}】 ";
|
||||
|
||||
LoggerHelper.Logger.Info($"{cmdReamrk}");
|
||||
|
||||
|
||||
return sop;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LoggerHelper.Logger.Error(ex.StackTrace);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<sample_exec_detail_ext> GetSampleExecDetails()
|
||||
{
|
||||
var result = DBFactory.Instance.Queryable<sample_exec_detail>()
|
||||
.LeftJoin<sample_exec>((a, b) => a.master_id == b.id)
|
||||
.LeftJoin<tube_input>((a, b, c) => a.qrcode == c.qrcode)
|
||||
.Where((a, b, c) => b.exec_state == "执行中")
|
||||
.Select((a, b, c) => new sample_exec_detail_ext {
|
||||
id = a.id,
|
||||
master_id = a.master_id,
|
||||
qrcode = a.qrcode,
|
||||
exec_state = b.exec_state,
|
||||
item_name= c.item_name,
|
||||
standrad_id = c.standrad_id,
|
||||
standrad = c.standrad,
|
||||
input_date = c.input_date,
|
||||
input_user = c.input_user
|
||||
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
return result;// sampleSequenceDal.GetSampleExecDetails();
|
||||
}
|
||||
|
||||
public List<tube_input> QueryTubeInputByBachNo(string bachNo)
|
||||
{
|
||||
return DBFactory.Instance.Queryable<tube_input>().Where(p => p.bach_no == bachNo).ToList();
|
||||
}
|
||||
|
||||
public List<sys_standard_action_ext> GetStrandActionByStrandId(string standrad_id)
|
||||
{
|
||||
|
||||
|
||||
List<sys_standard_action_ext> data = DBFactory.Instance.Queryable<sys_standard_action>()
|
||||
.LeftJoin<sys_action>((a, b) => a.process_id == b.id)
|
||||
.Where((a, b) => a.standard_id == standrad_id)
|
||||
.Select((a, b) => new sys_standard_action_ext
|
||||
{
|
||||
id = a.id,
|
||||
standard_id = a.standard_id,
|
||||
process_id = a.process_id,
|
||||
process_no = a.process_no,
|
||||
action_name = b.action_name,
|
||||
remark = b.remark
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user