yl
2023-05-30 925394b1b7f61a2c2a15fdaa0ecd0763214ccda1
VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -1,4 +1,5 @@
using Dapper;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
@@ -125,7 +126,8 @@
                    //获取最大单据号
                    if (i == 1)  //首单获取工单号
                    {
                        sql = @"select isnull(max(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code))),0)+1 as worknumb from TK_Wrk_Man where m_po=@erpordercode";
                        sql = @"select isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as worknumb
                                from TK_Wrk_Man where m_po=@erpordercode";
                        dynamicParams.Add("@erpordercode", erpordercode);
                        var data = DapperHelper.selectdata(sql, dynamicParams);
                        num = Convert.ToInt32(data.Rows[0]["WORKNUMB"].ToString());
@@ -385,6 +387,83 @@
        }
        #endregion
        #region[MES报废补单工单查询]
        public static ToMessage MesBadOrderSearch(string mesordercode, string sourceorder, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mesordercode != "" && mesordercode != null)
                {
                    search += "and A.wo_code like '%'+@mesordercode+'%' ";
                    dynamicParams.Add("@mesordercode", mesordercode);
                }
                if (sourceorder != "" && sourceorder != null)
                {
                    search += "and A.m_po like '%'+@sourceorder+'%' ";
                    dynamicParams.Add("@sourceorder", sourceorder);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and A.materiel_code like '%'+@partcode+'%' ";
                    dynamicParams.Add("@partcode", partcode);
                }
                if (partname != "" && partname != null)
                {
                    search += "and B.partname like '%'+@partname+'%' ";
                    dynamicParams.Add("@partname", partname);
                }
                if (partspec != "" && partspec != null)
                {
                    search += "and B.partspec like '%'+@partspec+'%' ";
                    dynamicParams.Add("@partspec", partspec);
                }
                if (createdate != "" && createdate != null)
                {
                    search += "and CONVERT(varchar(100),A.lm_date,23)=@createdate ";
                    dynamicParams.Add("@createdate", createdate);
                }
                if (creatuser != "" && creatuser != null)
                {
                    search += "and U.username like '%'+@creatuser+'%' ";
                    dynamicParams.Add("@creatuser", creatuser);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.id, A.status,A.wotype,A.wo_code,A.materiel_code as partcode,B.partname,B.partspec,A.plan_qty,A.wkshp_code,C.org_name as wkshp_name,
                            A.route_code,E.name as route_name,A.stck_code,F.name as stck_name,A.plan_startdate,A.plan_enddate,A.piroque,A.sourceid,A.m_po,U.username as lm_user,A.lm_date,S.bad_qty
                            from TK_Wrk_Man A
                            left join (select wo_code,sum(bad_qty) as bad_qty from  TK_Wrk_Step where bad_qty>0 group by wo_code) S on A.wo_code=S.wo_code
                            left join TMateriel_Info B on A.materiel_code=B.partcode
                            left join TOrganization C on A.wkshp_code=C.org_code
                            left join T_Sec_Stck D on A.stck_code=D.code
                            left join TFlw_Rout E on A.route_code=E.code
                            left join T_Sec_Stck F on A.stck_code=F.code
                            left join TUser U on A.lm_user=U.usercode
                            where A.is_delete<>'1'  and A.status='START' and A.wotype='PO' and S.bad_qty>0 " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = data.ToList();
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[产品编码查找工艺路线下拉接口]
        public static ToMessage PartSelectRoute(string partcode)
        {
@@ -505,10 +584,11 @@
                    }
                }
                //判断工艺路线对应工序关联的工作站是否有设置节拍工价
                sql = @"select AA.step_code,AA.eqp_code,S.unprice  from (
                        select A.code,B.step_code,C.eqp_code from TFlw_Rout A
                sql = @"select AA.step_code,AA.eqp_code,AA.flwtype,S.unprice  from (
                        select A.code,B.step_code,C.eqp_code,S.flwtype from TFlw_Rout A
                        inner join TFlw_Rtdt B on A.code=B.rout_code
                        left join TFlw_Rteqp C on B.step_code=C.step_code
                        left join TStep S on B.step_code=S.stepcode
                        where A.code=@route_code
                        ) as AA
                        left join (select * from TPrteEqp_Stad   where materiel_code=@partcode and route_code=@route_code) as S on
@@ -518,15 +598,45 @@
                var dtc = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dtc.Rows.Count; i++)
                {
                    if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0)
                    if (dtc.Rows[i]["flwtype"].ToString() == "Z") //判断工序是否为自制
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "节拍工价中:当前产品【" + partcode + "】,对应工艺路线【" + routecode + "】未设置(或未设置全)或工价小于等于0!";
                        mes.data = null;
                        return mes;
                        if (dtc.Rows[i].IsNull("unprice") || decimal.Parse(dtc.Rows[i]["unprice"].ToString()) == 0)
                        {
                            mes.code = "300";
                            mes.count = 0;
                            mes.Message = "节拍工价中:当前产品【" + partcode + "】,对应工艺路线【" + routecode + "】未设置(或未设置全)或工价小于等于0!";
                            mes.data = null;
                            return mes;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[MES工单新增、获取工单号]
        public static ToMessage AddMesOrderCodeSearch()
        {
            string sql = "";
            string wo_code = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取单据号
                sql = @"SELECT 'SGPO'+CONVERT(varchar(12) , getdate(), 112 )+'_'+cast(isnull(max(cast(substring(wo_code,charindex('_',wo_code)+1,len(wo_code)-charindex('_',wo_code)) as numeric)),0)+1 as varchar) as numct
                        FROM TK_Wrk_Man where wo_code like '%SGPO%'";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.data = data.Rows[0]["numct"].ToString();
            }
            catch (Exception e)
            {
@@ -597,6 +707,25 @@
                            CreateDate = DateTime.Now.ToString()
                        }
                    });
                    //写入工单工艺路线工序工价复制表
                    sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code)
                           select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice,
                           S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code
                           from TFlw_Rtdt A
                           inner join TFlw_Rteqp C on A.step_code=C.step_code
                           inner join (select *   from TPrteEqp_Stad  where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            mesordercode = mesordercode,
                            materiel_code = partcode,
                            routecode = routecode
                        }
                    });
                    //if (is_aps == "Y")  //是否排程
                    //{
                    //    string sql1 = "select id from TBom_Main  where materiel_code='" + PartNumber + "' and status='Y' and version='" + VsionId + "'";
@@ -664,6 +793,35 @@
                            CreateDate = DateTime.Now.ToString()
                        }
                    });
                    //删除工单工艺路线工序工价复制表
                    sql = @"delete TWoPrteEqp_Stad where wo=@mesordercode";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            mesordercode = mesordercode
                        }
                    });
                    //写入工单工艺路线工序工价复制表
                    sql = @"insert into TWoPrteEqp_Stad(wo,materiel_code,eqp_code,stand_value,opc_conver,route_code,unprice,eqp_value,cavity_qty,wkspcode,lm_user,lm_date,torg_code,is_delete,step_code)
                           select distinct @mesordercode as wo,S.materiel_code,S.eqp_code,S.stand_value,S.opc_conver,S.route_code,S.unprice,
                           S.eqp_value,S.cavity_qty,S.wkspcode,S.lm_user,S.lm_date,S.torg_code,S.is_delete,S.step_code
                           from TFlw_Rtdt A
                           inner join TFlw_Rteqp C on A.step_code=C.step_code
                           inner join (select *   from TPrteEqp_Stad  where materiel_code=@materiel_code and route_code=@routecode) as S on C.step_code=S.step_code and C.eqp_code=S.eqp_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            mesordercode = mesordercode,
                            materiel_code = partcode,
                            routecode = routecode
                        }
                    });
                    bool aa = DapperHelper.DoTransaction(list);
                    if (aa)
                    {
@@ -2216,13 +2374,15 @@
        }
        #endregion
        #region[生产开报工,工序检验扫码获取任务信息]
        public static ToMessage MesOrderStepCheckSearch(string orderstepqrcode)
        #region[工序检验扫码获取任务信息]
        public static ToMessage MesOrderStepCheckSearch(string orderstepqrcode, string checktype)
        {
            var sql = "";
            string ordercode = "";
            string stepcode = "";
            var dynamicParams = new DynamicParameters();
            Dictionary<string, object> list = new Dictionary<string, object>();
            try
            {
                if (orderstepqrcode != "" && orderstepqrcode != null)
@@ -2242,7 +2402,7 @@
                        stepcode = arra[1]; //获取指定字符串前面的字符
                    }
                    //通过扫描二维码信息查找任务信息
                    sql = @"select A.wo_code,M.partcode,M.partname,M.partspec,S.stepcode,S.stepname
                    sql = @"select A.wo_code,A.good_qty,M.partcode,M.partname,M.partspec,M.stocktype_code,S.stepcode,S.stepname
                            from TK_Wrk_Step 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
@@ -2253,11 +2413,44 @@
                    var data = DapperHelper.selectdata(sql, dynamicParams);
                    if (data.Rows.Count > 0)
                    {
                        mes.code = "200";
                        mes.count = 0;
                        mes.Message = "查询成功!";
                        mes.data = data;
                        return mes;
                        if (decimal.Parse(data.Rows[0]["good_qty"].ToString()) > 0)
                        {
                            //获取绑定的质检方案、抽样方式、样本数
                            sql = @"select code as checkstandcode,name as checkstandname,sampmethod,sampscare
                            from TStepCheckStandard
                            where (PATINDEX('%,' + RTRIM(@partcode) + ',%',',' + suitpart + ',')>0 or PATINDEX('%,' + RTRIM(@stocktype_code) + ',%',',' + suitpart + ',')>0)
                            and checktype=@checktype and stepcode=@stepcode ";
                            dynamicParams.Add("@partcode", data.Rows[0]["partcode"].ToString());//物料编码
                            dynamicParams.Add("@stepcode", stepcode);//工序编码
                            dynamicParams.Add("@stocktype_code", data.Rows[0]["stocktype_code"].ToString());//存货类型编码
                            dynamicParams.Add("@checktype", checktype);//检验类型
                            var data1 = DapperHelper.selectdata(sql, dynamicParams);
                            if (data1.Rows.Count > 0)
                            {
                                list.Add("labcont", data);
                                list.Add("chekstand", data1);
                                mes.code = "200";
                                mes.count = 0;
                                mes.Message = "查询成功!";
                                mes.data = list;
                            }
                            else
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.Message = "当前产品【" + data.Rows[0]["partname"].ToString() + "】,对应工序【" + data.Rows[0]["stepname"].ToString() + "】,未指定质检方案!";
                                mes.data = null;
                                return mes;
                            }
                        }
                        else
                        {
                            mes.code = "300";
                            mes.count = 0;
                            mes.Message = "当前工序任务无报工产出!";
                            mes.data = null;
                            return mes;
                        }
                    }
                    else
                    {
@@ -2288,47 +2481,36 @@
        }
        #endregion
        #region[生产开报工,工序检验获取检验标准下拉框数据]
        public static ToMessage MesOrderStepCheckSelect()
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取工序检验标准
                sql = @"select code,name  from TStepCheckStandard where is_delete<>'1'";
                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[生产开报工,工序检验根据检验标准获取检验项目列表]
        #region[工序检验根据选择的检验方案查找检验项目]
        public static ToMessage MesOrderStepCheckItemList(string checkstandcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //根据检验标准编码获取工序检验项目
                sql = @"select B.code,B.name,A.stepcheckitem_desc,A.stepcheckitem_seq   from TStepCheckStandardSub A
                //质检方案编码获取检验项
                sql = @"select A.stepcheckitem_seq, B.code,B.name,A.required,A.numberjudge,A.unit,A.decimalnum,
                        A.standvalue,A.uppervalue,A.lowervalue,A.stepcheckitem_desc
                        from TStepCheckStandardSub A
                        left join TStepCheckItem B on A.stepcheckitem_code=B.code
                        where B.is_delete<>'1' and A.stepstaned_code=@checkstandcode";
                dynamicParams.Add("@checkstandcode", checkstandcode);
                        where A.stepstaned_code=@checkstandcode
                        order by A.stepcheckitem_seq";
                dynamicParams.Add("@checkstandcode", checkstandcode);//质检方案编码
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.data = data;
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "查询成功!";
                    mes.data = data;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "当前质检方案无检验项!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
@@ -2341,21 +2523,24 @@
        }
        #endregion
        #region[生产开报工,工序检验提交保存]
        public static ToMessage SaveMesOrderStepCheckItem(string mesordercode, string partcode, string stepcode, string checkstanedcode, string checkusercode, string checktypecode, string checkresult, string checkdescr, string checkqty, string username, List<StepCheck> json)
        #region[工序检验,提交]
        public static ToMessage SaveMesOrderStepCheckItem(string wocode, string partcode, string stepcode, string checkstandcode, string check_type, string sampmethod, string qualitystatus, string labqty, string sampleqty, string goodqty, string ngqty, string checkitemcont, string username)
        {
            var sql = "";
            string[] arra = new string[] { };
            string[] arra1 = new string[] { };
            List<object> list = new List<object>();
            string checktypename = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                string date = DateTime.Now.ToString(); //获取系统时间
                string datetime = DateTime.Now.ToString(); //获取系统时间
                //获取检验项目信息
                JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(checkitemcont);
                list.Clear();
                switch (checktypecode)
                //写入检验记录主表
                sql = @"insert into  TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,sampmethod,check_result,check_qty,good_qty,ng_qty,lm_user,lm_date)
                                values(@wo_code,@partcode,@step_code,@checkstaned_code,@check_user,@check_type,@check_typename,@sampmethod,@check_result,@check_qty,@good_qty,@ng_qty,@lm_user,@lm_date)";
                switch (check_type)
                {
                    case "FirstCheck":
                        checktypename = "首检";
@@ -2369,20 +2554,48 @@
                    default:
                        break;
                }
                //写入工序检验记录主表
                sql = @"insert into  TStepCheckRecord(wo_code,partcode,step_code,checkstaned_code,check_user,check_type,check_typename,check_result,check_descr,check_qty,lm_user,lm_date)
                                values(@mesordercode,@partcode,@stepcode,@checkstanedcode,@checkusercode,@checktypecode,@checktypename,@checkresult,@checkdescr,@check_qty,@lm_user,@lm_date)";
                list.Add(new { str = sql, parm = new { mesordercode = mesordercode, partcode = partcode, stepcode = stepcode, checkstanedcode = checkstanedcode, checkusercode = checkusercode, checktypecode = checktypecode, checktypename = checktypename, checkresult = checkresult, checkdescr = checkdescr, check_qty = checkqty, lm_user = username, lm_date = date } });
                //写入工序检验记录子表
                //获取主表最大ID
                sql = @"select ISNULL(IDENT_CURRENT('TStepCheckRecord')+1,1) as id";
                var dt = DapperHelper.selecttable(sql);
                for (int i = 0; i < json.Count; i++)
                list.Add(new
                {
                    sql = @"insert into  TStepCheckRecordSub(m_id,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_result,lm_user,lm_date)
                                values(@m_id,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_result,@lm_user,@lm_date)";
                    list.Add(new { str = sql, parm = new { m_id = int.Parse(dt.Rows[0]["ID"].ToString()), checkiem_seq = int.Parse(json[i].seq), checkitem_code = json[i].code, checkitem_name = json[i].name, checkitem_descr = json[i].descr, check_result = json[i].checkresult, lm_user = username, lm_date = date } });
                    str = sql,
                    parm = new
                    {
                        wo_code = wocode,
                        partcode = partcode,
                        step_code = stepcode,
                        checkstaned_code = checkstandcode,
                        check_user = username,
                        check_type = check_type,
                        check_typename = checktypename,
                        sampmethod = sampmethod,
                        check_result = qualitystatus,
                        check_qty = decimal.Parse(sampleqty),
                        good_qty = decimal.Parse(goodqty),
                        ng_qty = decimal.Parse(ngqty),
                        lm_user = username,
                        lm_date = datetime
                    }
                });
                //写入检验记录子表
                for (int j = 0; j < arra.Count; j++)
                {
                    sql = @"insert into  TStepCheckRecordSub(m_id,checknum,checkitem_seq,checkitem_code,checkitem_name,checkitem_descr,check_value,check_result,lm_user,lm_date)
                                values(CONVERT(INT,IDENT_CURRENT('TStepCheckRecord')),@checknum,@checkiem_seq,@checkitem_code,@checkitem_name,@checkitem_descr,@check_value,@check_result,@lm_user,@lm_date)";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            checknum = arra[j]["checknum"].ToString(),
                            checkiem_seq = arra[j]["checkiem_seq"].ToString(),
                            checkitem_code = arra[j]["checkitem_code"].ToString(),
                            checkitem_name = arra[j]["checkitem_name"].ToString(),
                            checkitem_descr = arra[j]["checkitem_descr"].ToString(),
                            check_value = arra[j]["check_value"].ToString(),
                            check_result = arra[j]["check_result"].ToString(),
                            lm_user = username,
                            lm_date = datetime
                        }
                    });
                }
                bool aa = DapperHelper.DoTransaction(list);
@@ -2390,14 +2603,14 @@
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "检验成功!";
                    mes.Message = "操作成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "检验失败!";
                    mes.Message = "操作失败!";
                    mes.data = null;
                }
            }