C# 流程脚本业务信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.Flow;

namespace WCSPro.IServices.Develop.Script
{
    /// <summary>
    /// 流程脚本业信息务逻辑接口
    /// </summary>
    public interface IScriptService
    {
        /// <summary>
        /// 查询脚本
        /// </summary>
        /// <param name="code">脚本编号,模糊条件,可空。</param>
        /// <param name="name">脚本名称,模糊条件,可空。</param>
        /// <param name="type">脚本类型,模糊条件,可空。</param>
        /// <returns></returns>
        List<ScriptInfo> QueryScripts(string code, string name, string type);

        /// <summary>
        /// 检查脚本编号是否已存在
        /// </summary>
        /// <param name="code">脚本编号</param>
        /// <returns></returns>
        bool ExistsScriptCode(string code);

        /// <summary>
        /// 检查脚本是否已存在
        /// </summary>
        /// <param name="script">脚本信息对象</param>
        /// <returns></returns>
        bool ExistsScript(ScriptInfo script);

        /// <summary>
        /// 添加脚本
        /// </summary>
        /// <param name="script">脚本信息对象</param>
        /// <returns></returns>
        bool AddScript(ScriptInfo script);

        /// <summary>
        /// 修改改脚本
        /// </summary>
        /// <param name="script">脚本信息对象</param>
        /// <returns></returns>
        bool UpdateScript(ScriptInfo script);

        /// <summary>
        /// 删除脚本
        /// </summary>
        /// <param name="script">脚本信息对象</param>
        /// <returns></returns>
        bool DeleteScript(ScriptInfo script);

        /// <summary>
        /// 根据编号获取脚本
        /// </summary>
        /// <param name="code">脚本编号</param>
        /// <returns></returns>
        ScriptInfo GetScriptByCode(string code);



    }
}

using CommonLib.LogUtils.Log4net;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
using WCSPro.IDAL;
using WCSPro.IServices.Develop.Script;
using WCSPro.Model.Flow;

namespace WCSPro.Services.Develop.Script
{
    /// <summary>
    /// 流程脚本业信息务逻辑处理类
    /// </summary>
    public class ScriptService : IScriptService
    {
        public ScriptService(IContainerProvider container)
        {
            this.Container = container;
            this.ScriptInfoDAL = this.Container.Resolve<IScriptInfoDAL>();
        }

        private IContainerProvider Container { get; }
        private IScriptInfoDAL ScriptInfoDAL { get; }

        /// <summary>
        /// 日志操作对象
        /// </summary>
        private Log4 Logger { get; } = new Log4(typeof(ScriptService));



        public List<ScriptInfo> QueryScripts(string code, string name, string type)
        {
            try
            {
                return ScriptInfoDAL.QueryScripts(code, name, type);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return null;
            }
        }
        public bool ExistsScriptCode(string code)
        {
            try
            {
                return ScriptInfoDAL.ExistsCode(code);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return false;
            }
        }

        public bool ExistsScript(ScriptInfo script)
        {
            try
            {
                return ScriptInfoDAL.Exists(script);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return false;
            }
        }


        public bool AddScript(ScriptInfo script)
        {
            try
            {
                return this.ScriptInfoDAL.AddObj(script);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return false;
            }
        }

        public bool UpdateScript(ScriptInfo script)
        {
            try
            {
                return this.ScriptInfoDAL.UpdateObj(script);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return false;
            }
        }

        public bool DeleteScript(ScriptInfo script)
        {
            try
            {
                return this.ScriptInfoDAL.DeleteObjById(script.GID);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return false;
            }
        }

        public ScriptInfo GetScriptByCode(string code)
        {
            try
            {
                return this.ScriptInfoDAL.GetScriptByCode(code);
            }
            catch (Exception ex)
            {
                string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
                Logger.Error(err, ex);
                return null;
            }
        }

    }
}

using PropertyChanged;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WCSPro.Model.Flow
{
    /// <summary>
    /// 流程功能脚本(流程实体类)
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    [SugarIndex("Index_FlowScript_Code", nameof(Code), OrderByType.Desc, true)]
    public class ScriptInfo
    {
        /// <summary>
        /// 主键
        /// </summary>
        [Display(Name = "GID", AutoGenerateField = false)]
        [SugarColumn(IsPrimaryKey = true, ColumnDataType = "varchar(36)")]
        public string GID { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(100)")]
        public string Code { get; set; } = string.Empty;

        /// <summary>
        /// 流程名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(100)")]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 流程说明
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(500)")]
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 流程类型("配标脚本"、"清洗脚本"、"系统脚本"、"其它" 等等根据业务扩展)
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(32)")]
        public string ScriptType { get; set; } = string.Empty;

        /// <summary>
        /// 流程指令集
        /// </summary>
        [SugarColumn(IsJson = true, IsNullable = true)]
        public List<ScriptActCmd> Commands { get; set; }
    }
}

using PropertyChanged;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.ParametersModel;

namespace WCSPro.Model.Flow
{
    /// <summary>
    /// 流程动作命令实体类
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public class ScriptActCmd
    {
        /// <summary>
        /// 主键
        /// </summary>
        [Display(Name = "GID", AutoGenerateField = false)]
        [SugarColumn(IsPrimaryKey = true, ColumnDataType = "varchar(36)")]
        public string GID { get; set; } = Guid.NewGuid().ToString();

        /// <summary>
        /// 命令名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(100)")]
        public string CmdName { get; set; } = string.Empty;

        /// <summary>
        /// 命令说明
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(500)")]
        public string CmdDiscription { get; set; } = string.Empty;

        /// <summary>
        /// 命令参数
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string Parameters { get; set; } = string.Empty;

        /// <summary>
        /// 参数说明
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar(500)")]
        public string ParsDiscription { get; set; } = string.Empty;

        /// <summary>
        /// 指令方法名
        /// </summary>
        [SugarColumn(ColumnDataType = "varchar(100)")]
        public string CmdMethodName { get; set; } = string.Empty;

        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string Note { get; set; } = string.Empty;

        /// <summary>
        /// 指令返回
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string CmdResult { get; set; } = string.Empty;
    }
}

using CommonLib.DBUtils.SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.Flow;

namespace WCSPro.IDAL
{
    public interface IScriptInfoDAL : IBaseDAL<ScriptInfo>
    {
        /// <summary>
        /// 查询脚本
        /// </summary>
        /// <param name="code">脚本编号,模糊条件,可空。</param>
        /// <param name="name">脚本名称,模糊条件,可空。</param>
        /// <param name="type">脚本类型,模糊条件,可空。</param>
        /// <returns></returns>
        List<ScriptInfo> QueryScripts(string code, string name, string type);

        /// <summary>
        /// 检查脚本编号是否存在
        /// </summary>
        /// <param name="code">脚本编号</param>
        /// <returns></returns>
        bool ExistsCode(string code);

        /// <summary>
        /// 检查脚本是否已存在
        /// </summary>
        /// <param name="script">脚本信息对象</param>
        /// <returns></returns>
        bool Exists(ScriptInfo script);

        /// <summary>
        /// 根据编号获取脚本
        /// </summary>
        /// <param name="code">脚本编号</param>
        /// <returns></returns>
        ScriptInfo GetScriptByCode(string code);
    }
}

using CommonLib.DBUtils.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.IDAL;
using WCSPro.Model.Flow;

namespace WCSPro.DAL
{
    public class ScriptInfoDAL : BaseDAL<ScriptInfo>, IScriptInfoDAL
    {
        public ScriptInfoDAL(ISqlSugarClient db) : base(db)
        {
            Context.DbMaintenance.CreateDatabase();
            Context.CodeFirst.SetStringDefaultLength(200).InitTables<ScriptInfo>();
        }

        public bool Exists(ScriptInfo script)
        {
            return Context.Queryable<ScriptInfo>().Any(t => t.GID == script.GID);
        }

        public bool ExistsCode(string code)
        {
            return Context.Queryable<ScriptInfo>().Any(t => t.Code == code);
        }

        public ScriptInfo GetScriptByCode(string code)
        {
            return Context.Queryable<ScriptInfo>().Single(t => t.Code == code);
        }

        public List<ScriptInfo> QueryScripts(string code, string name, string type)
        {
            return Context.Queryable<ScriptInfo>()
                .WhereIF(!string.IsNullOrWhiteSpace(code), t => t.Code.Contains(code))
                .WhereIF(!string.IsNullOrWhiteSpace(name), t => t.Name.Contains(name))
                .WhereIF(!string.IsNullOrWhiteSpace(type), t => t.ScriptType.Contains(type))
                .ToList();
        }
    }
}

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值