519 lines
18 KiB
C#
519 lines
18 KiB
C#
using DataDAL;
|
|
using Models.Const;
|
|
using Models.Ext;
|
|
using Models.Models;
|
|
using Newtonsoft.Json;
|
|
using SamplePre.Common;
|
|
using SamplePre.DAL;
|
|
using SamplePre.DAL.DBContext;
|
|
using SamplePre.Models;
|
|
using SamplePre.Models.Ext;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
using static System.Collections.Specialized.BitVector32;
|
|
|
|
namespace SamplePre.ProcessBll.BLL
|
|
{
|
|
public class SOPManagerBll
|
|
{
|
|
|
|
SOPDal sopDal = new SOPDal();
|
|
|
|
public List<sys_action_parm_map_ext> GetActionParmById(string actionID)
|
|
{
|
|
|
|
var result = DBFactory.Instance.Queryable<sys_action_parm_map>()
|
|
.LeftJoin<sys_parm>((a, b) => a.parm_id == b.id)
|
|
.Where((a, b) => a.process_id == actionID && b.title != null)
|
|
.Select((a, b) => new sys_action_parm_map_ext
|
|
{
|
|
id = a.id,
|
|
process_id = a.process_id,
|
|
parm_id = a.parm_id,
|
|
title = b.title,
|
|
unit = b.unit,
|
|
data_type = b.data_type,
|
|
data_value = b.data_value,
|
|
plc_type = b.plc_type
|
|
|
|
|
|
})
|
|
.ToList();
|
|
|
|
|
|
//List<sys_action_parm_map_ext> paramsList = standardDal.GetProcess_parm_mapByProcessId(actionID);
|
|
return result;//paramsList;
|
|
}
|
|
|
|
|
|
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)
|
|
.Where((a,b,c)=>a.standard_id == standId)
|
|
.OrderBy((a,b,c)=>a.action_seqno)
|
|
.Select((a,b,c)=> 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
|
|
})
|
|
.ToList();
|
|
|
|
|
|
//List<sys_standard_action_parm_ext> paramsList = sopDal.GetStrandActionParamByStrandId(standId);
|
|
return result; //paramsList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除动作下的参数配置
|
|
/// </summary>
|
|
/// <param name="standId"></param>
|
|
/// <param name="actionId"></param>
|
|
/// <param name="seqno"></param>
|
|
public int removeActionParmByActionId(string standId, string actionId, int seqno)
|
|
{
|
|
|
|
var val = DBFactory.Instance.Deleteable<sys_standard_action_parm>(p => p.standard_id == standId && p.action_id == actionId && p.action_seqno == seqno)
|
|
.ExecuteCommand();
|
|
return val;
|
|
//sopDal.removeActionParmByActionId(standId, actionId, seqno);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除动作下的参数配置byid
|
|
/// </summary>
|
|
/// <param name="standId"></param>
|
|
/// <param name="actionId"></param>
|
|
/// <param name="seqno"></param>
|
|
public int removeActionParmByParamId(string standId, string actionId, int seqno,string paramId)
|
|
{
|
|
|
|
var val = DBFactory.Instance.Deleteable<sys_standard_action_parm>(p => p.standard_id == standId && p.action_id == actionId && p.action_seqno == seqno && p.parm_id == paramId)
|
|
.ExecuteCommand();
|
|
return val;
|
|
//sopDal.removeActionParmByActionId(standId, actionId, seqno);
|
|
}
|
|
|
|
|
|
|
|
public int updateStandardActionParm(sys_standard_action_parm item)
|
|
{
|
|
//sopDal.updateStandardActionParm(item);
|
|
|
|
int val = DBFactory.Instance.Updateable<sys_standard_action_parm>()
|
|
.SetColumns(p=> new sys_standard_action_parm() { data_value = item.data_value })
|
|
.Where(p=>p.id == item.id)
|
|
.ExecuteCommand();
|
|
|
|
return val;
|
|
}
|
|
|
|
public bool IsExisAction(string actionId)
|
|
{
|
|
|
|
List<sys_standard_action_parm> data = DBFactory.Instance.Queryable<sys_standard_action_parm>().Where(p => p.action_id == actionId).ToList();
|
|
|
|
return data.Count() > 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<sys_standard_action_ext> QueryStandardActionByStandardId(string standId)
|
|
{
|
|
|
|
var result = DBFactory.Instance.Queryable<sys_standard_action>().
|
|
LeftJoin<sys_action>((a, b) => a.process_id == b.id).
|
|
Where((a, b) => a.standard_id == standId).
|
|
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 result;//standardDal.QueryStandardActionByStandardId(standId);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 更新动作序号
|
|
/// </summary>
|
|
/// <param name="action"></param>
|
|
/// <returns></returns>
|
|
public int UpdateActionSeqno(sys_standard_action_ext action)
|
|
{
|
|
// return sopDal.UpdateActionSeqno(action);
|
|
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
_db.BeginTran();
|
|
var val = _db.Updateable<sys_standard_action>()
|
|
.SetColumns(it => new sys_standard_action() { process_no = action.new_action_seqno })
|
|
.Where(p => p.standard_id == action.standard_id && p.process_id == action.process_id && p.process_no == action.process_no)
|
|
.ExecuteCommand();
|
|
|
|
|
|
////参数里的动作顺序
|
|
var val2 = _db.Updateable<sys_standard_action_parm>()
|
|
.SetColumns(it => new sys_standard_action_parm() { action_seqno = action.new_action_seqno })
|
|
.Where(p => p.standard_id == action.standard_id && p.action_id == action.process_id && p.action_seqno == action.process_no)
|
|
.ExecuteCommand();
|
|
|
|
_db.CommitTran();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
return -1;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除标准,及标准下的所有配置
|
|
/// </summary>
|
|
/// <param name="iD"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public int DelStandardActionParamByStandId(string standardId)
|
|
{
|
|
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
_db.BeginTran();
|
|
|
|
_db.Deleteable<sys_standard>().Where(p => p.id == standardId).ExecuteCommand();
|
|
_db.Deleteable<sys_standard_action>().Where(p => p.standard_id == standardId).ExecuteCommand();
|
|
_db.Deleteable<sys_standard_action_parm>().Where(p => p.standard_id == standardId).ExecuteCommand();
|
|
|
|
_db.CommitTran();
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
return -1;
|
|
}
|
|
|
|
return 1;
|
|
//return sopDal.DelStandardActionParamByStandId(iD);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取标准下的动作,动作中包含参数的预览
|
|
/// </summary>
|
|
/// <param name="standID"></param>
|
|
/// <returns></returns>
|
|
public List<sys_standard_action_ext> QueryStandardProcessByStandardId(string standID)
|
|
{
|
|
return sopDal.QueryStandardProcessByStandardId(standID);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 保存标准动作表、动作参数表
|
|
/// </summary>
|
|
/// <param name="action"></param>
|
|
/// <returns></returns>
|
|
public int SaveStandardAction_param(sys_standard_action action)
|
|
{
|
|
//return standardDal.Save_standard_process_map(procemodel);
|
|
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
_db.BeginTran();
|
|
//保存标准动作
|
|
_db.Insertable<sys_standard_action>(action).ExecuteCommand();
|
|
|
|
|
|
//保存标准动作参数表
|
|
//获取动作下的参数
|
|
List<sys_action_parm_map_ext> paramList = GetActionParmById(action.process_id);
|
|
List<sys_standard_action_parm> new_parms = new List<sys_standard_action_parm>();
|
|
foreach (var item in paramList)
|
|
{
|
|
//保存标准动作参数表
|
|
sys_standard_action_parm parmmodel = new sys_standard_action_parm()
|
|
{
|
|
id = Guid.NewGuid().ToString(),
|
|
standard_id = action.standard_id,
|
|
action_id = action.process_id,
|
|
action_seqno = action.process_no,
|
|
parm_id = item.parm_id,
|
|
data_value = item.data_value,
|
|
parm_seqno = item.id
|
|
};
|
|
new_parms.Add(parmmodel);
|
|
}
|
|
_db.Insertable<sys_standard_action_parm>(new_parms).ExecuteCommand();
|
|
|
|
_db.CommitTran();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
return -1;
|
|
}
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// sop导出
|
|
/// </summary>
|
|
/// <param name="sysStandardId"></param>
|
|
public void ExprotSop(string sysStandardId ,string filePath)
|
|
{
|
|
//标准信息
|
|
sys_standard sysStandard = DBFactory.Instance.Queryable<sys_standard>().Where(p=>p.id == sysStandardId).Single();
|
|
|
|
//标准动作信息
|
|
List<sys_standard_action> standardActions = DBFactory.Instance.Queryable<sys_standard_action>().Where(p => p.standard_id == sysStandardId).ToList();
|
|
|
|
//标准动作信息
|
|
List<sys_standard_action_parm> standardActionsParams = DBFactory.Instance.Queryable<sys_standard_action_parm>().Where(p => p.standard_id == sysStandardId).ToList();
|
|
|
|
|
|
SopDataInfo sopDataInfo = new SopDataInfo();
|
|
sopDataInfo.sysStandard = sysStandard;
|
|
sopDataInfo.sysStandActions = standardActions;
|
|
sopDataInfo.sysStandardActionParms = standardActionsParams;
|
|
|
|
|
|
// 2. 序列化:格式化易读、保留中文
|
|
string jsonStr = JsonConvert.SerializeObject(sopDataInfo);
|
|
|
|
// 3. 写入TXT文件
|
|
File.WriteAllText(filePath, jsonStr);
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入SOP
|
|
/// </summary>
|
|
/// <param name="selectFilePath"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public bool ImportSop(string selectFilePath)
|
|
{
|
|
|
|
string fileContent = File.ReadAllText(selectFilePath, System.Text.Encoding.UTF8);
|
|
|
|
SopDataInfo sopDataInfo = JsonConvert.DeserializeObject<SopDataInfo>(fileContent);
|
|
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
//开始事务
|
|
_db.BeginTran();
|
|
|
|
//标准
|
|
sopDataInfo.sysStandard.id = Guid.NewGuid().ToString();
|
|
sopDataInfo.sysStandard.standard_name = sopDataInfo.sysStandard.standard_name + "_imp";
|
|
DBFactory.Instance.Insertable<sys_standard>(sopDataInfo.sysStandard).ExecuteCommand();
|
|
|
|
|
|
//标准动作
|
|
foreach (var item in sopDataInfo.sysStandActions)
|
|
{
|
|
item.id = Guid.NewGuid().ToString();
|
|
item.standard_id = sopDataInfo.sysStandard.id;
|
|
}
|
|
DBFactory.Instance.Insertable<sys_standard_action>(sopDataInfo.sysStandActions).ExecuteCommand();
|
|
//标准动作参数
|
|
foreach (var item in sopDataInfo.sysStandardActionParms)
|
|
{
|
|
item.id = Guid.NewGuid().ToString();
|
|
item.standard_id = sopDataInfo.sysStandard.id;
|
|
}
|
|
DBFactory.Instance.Insertable<sys_standard_action_parm>(sopDataInfo.sysStandardActionParms).ExecuteCommand();
|
|
|
|
//提交事务
|
|
_db.CommitTran();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取左侧标准树
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public List<TreeListItem> GetStandardData()
|
|
{
|
|
List<TreeListItem> treeListItems = new List<TreeListItem>();
|
|
|
|
//获取样本
|
|
List<sys_dict> yangbens = SystemConst.dictDatas.Where(p => p.class_id == 3).ToList(); //sopBll.QueryGyData(); //standardDal.QueryGyData();
|
|
|
|
foreach (var item in yangbens)
|
|
{
|
|
treeListItems.Add(new TreeListItem() { ID = item.id, DisplayText = item.data_value, ParentID = "0" });
|
|
}
|
|
|
|
//获取标准
|
|
List<sys_standard> SopList = QueryAllGyStandards(); //standardDal.QueryAllGyStandards();
|
|
foreach (var item in SopList)
|
|
{
|
|
treeListItems.Add(new TreeListItem() { ID = item.id, DisplayText = item.standard_name, ParentID = item.sample_id });
|
|
}
|
|
|
|
return treeListItems;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有标准
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<sys_standard> QueryAllGyStandards()
|
|
{
|
|
List<sys_standard> data = DBFactory.Instance.Queryable<sys_standard>().ToList();
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取动作字典
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
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();
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除标准的动作
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
public void removeStandAction(sys_standard_action_ext sysStandardAction)
|
|
{
|
|
//移除动作
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
_db.BeginTran();
|
|
|
|
var va11 = _db.Deleteable<sys_standard_action>(p => p.id == sysStandardAction.id).ExecuteCommand();
|
|
|
|
//移除动作下的参数配置
|
|
var val2 = _db.Deleteable<sys_standard_action_parm>(p => p.standard_id == sysStandardAction.standard_id
|
|
&& p.action_id == sysStandardAction.process_id
|
|
&& p.action_seqno == sysStandardAction.process_no).ExecuteCommand();
|
|
_db.CommitTran();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存动作参数配置
|
|
/// </summary>
|
|
/// <param name="actionParms"></param>
|
|
/// <returns></returns>
|
|
public int SaveStandardActionParam(List<sys_standard_action_parm> actionParms)
|
|
{
|
|
int val = DBFactory.Instance.Insertable<sys_standard_action_parm>(actionParms).ExecuteCommand();
|
|
|
|
return val;
|
|
}
|
|
|
|
public int SaveStandardCopy(sys_standard new_sysStandard, List<sys_standard_action> newStandActions, List<sys_standard_action_parm> sysStandardActionParms)
|
|
{
|
|
var _db = DBFactory.Instance;
|
|
|
|
try
|
|
{
|
|
_db.BeginTran();
|
|
|
|
_db.Insertable<sys_standard>(new_sysStandard).ExecuteCommand();
|
|
|
|
_db.Insertable<sys_standard_action>(newStandActions).ExecuteCommand();
|
|
|
|
_db.Insertable<sys_standard_action_parm>(sysStandardActionParms).ExecuteCommand();
|
|
|
|
_db.CommitTran();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_db.RollbackTran();
|
|
|
|
LoggerHelper.Logger.Error(ex.Message);
|
|
return -1;
|
|
}
|
|
|
|
|
|
return 1;
|
|
}
|
|
}
|
|
}
|