VueWebCoreApi/DLL/DAL/WorkOrderDAL.cs
@@ -808,17 +808,50 @@
                    }
                }
                //获取工序信息
                sql = @"select S.wo_code,S.seq,S.step_code,T.stepname,S.stepprice,(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice,(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                        S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty,(isnull(S.plan_qty,0)-(isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0))) as delive_qty,S.isbott,S.isend 
                        from TK_Wrk_Step S
                        left join TStep  T on S.step_code=T.stepcode
                        where S.wo_code=@wocode order by S.seq ";
                dynamicParams.Add("@wocode", wocode);
                var data1 = DapperHelper.selectdata(sql, dynamicParams);
                var parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams);
                //获取工序对应设备信息
                for (int i = 0; i < parents.Count; i++)
                {
                    if (parents[i].flwtype == "Z")
                    {
                        //通过工艺路线工序表ID查找对应设备信息
                        sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TEqpInfo E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                        dynamicParams.Add("@m_id", parents[i].id);
                        var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                        parents[i].children = children.ToList();
                    }
                    else
                    {
                        //通过工艺路线工序表ID查找对应外协供应商信息
                        sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TCustomer E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                        dynamicParams.Add("@m_id", parents[i].id);
                        var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                        parents[i].children = children.ToList();
                    }
                }
                dir.Add("canupdate_qty", canupdate_qty);
                dir.Add("stepdata", data1);
                dir.Add("stepdata", parents);
                mes.code = "200";
                mes.count = data1.Rows.Count;
                mes.count = parents.Count;
                mes.message = "查询成功";
                mes.data = dir;
            }
@@ -1150,35 +1183,184 @@
                if (route) //工艺路线版
                {
                    //MES工单查找历史引用最新工序信息
                    sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend
                        from TK_Wrk_Step S
                        inner join (
                        select top 1 A.wo_code,A.route_code   from TK_Wrk_Man A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.route_code=S.route_code
                        where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode and A.route_code=@routecode
                        order by A.lm_date desc
                        ) as W on S.wo_code=W.wo_code and S.route_code=W.route_code
                        left join TStep  T on S.step_code=T.stepcode
                        order by S.seq";
                    sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice,'0' as produceq_qty,
                           '0' as good_qty,'0' as ng_qty,'0' as laborbad_qty,'0' as materielbad_qty,'0' as delive_qty,isbott,isend
                           from TK_Wrk_Step S
                           inner join (
                           select top 1 S.id,A.wo_code,A.route_code   from TK_Wrk_Man A
                           inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.route_code=S.route_code
                           where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode and A.route_code=@routecode
                           order by A.lm_date desc
                           ) as W on S.wo_code=W.wo_code and S.route_code=W.route_code
                           left join TStep  T on S.step_code=T.stepcode
                           order by S.seq";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    dynamicParams.Add("@partcode", partcode);
                    dynamicParams.Add("@routecode", routecode);
                    var parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams);
                    //获取工序对应设备信息
                    for (int i = 0; i < parents.Count; i++)
                    {
                        if (parents[i].flwtype == "Z")
                        {
                            //通过工艺路线工序表ID查找对应设备信息
                            sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TEqpInfo E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                            dynamicParams.Add("@m_id", parents[i].id);
                            var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                            parents[i].children = children.ToList();
                        }
                        else
                        {
                            //通过工艺路线工序表ID查找对应外协供应商信息
                            sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TCustomer E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                            dynamicParams.Add("@m_id", parents[i].id);
                            var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                            parents[i].children = children.ToList();
                        }
                    }
                }
                else
                {
                    //MES工单查找历史引用最新工序信息
                    sql = @"select S.wo_code,S.seq,S.step_code,S.stepprice,isbott,isend
                        from TK_Wrk_Step S
                        inner join (
                        select top 1 A.wo_code   from TK_Wrk_Man A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code
                        where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode
                        order by A.lm_date desc
                        ) as W on S.wo_code=W.wo_code
                        left join TStep  T on S.step_code=T.stepcode
                        order by S.seq";
                    sql = @"select S.id,S.wo_code,S.seq,S.step_code,T.stepname,T.flwtype,S.stepprice,'0' as produceq_qty,
                            '0' as good_qty,'0' as ng_qty,'0' as laborbad_qty,'0' as materielbad_qty,'0' as delive_qty,isbott,isend
                            from TK_Wrk_Step S
                            inner join (
                            select top 1 A.wo_code   from TK_Wrk_Man A
                            inner join TK_Wrk_Step S on A.wo_code=S.wo_code
                            where A.materiel_code=@partcode and A.wkshp_code=@wkshopcode
                            order by A.lm_date desc
                            ) as W on S.wo_code=W.wo_code
                            left join TStep  T on S.step_code=T.stepcode
                            order by S.seq";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    dynamicParams.Add("@partcode", partcode);
                    var parents = DapperHelper.select<WorkRouteStepEqp>(sql, dynamicParams);
                    //获取工序对应设备信息
                    for (int i = 0; i < parents.Count; i++)
                    {
                        if (parents[i].flwtype == "Z")
                        {
                            //通过工艺路线工序表ID查找对应设备信息
                            sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TEqpInfo E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                            dynamicParams.Add("@m_id", parents[i].id);
                            var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                            parents[i].children = children.ToList();
                        }
                        else
                        {
                            //通过工艺路线工序表ID查找对应外协供应商信息
                            sql = @"select S.eqp_code,E.name as eqp_name,S.eqpprice as eqp_price,
                                (isnull(S.good_qty,0)+isnull(S.ng_qty,0)+isnull(S.laborbad_qty,0)+isnull(S.materielbad_qty,0)) as produceq_qty,
                                S.good_qty,S.ng_qty,S.laborbad_qty,S.materielbad_qty
                                from TK_Wrk_StepEqp S
                                inner join TCustomer E on S.eqp_code=E.code
                                where S.m_id=@m_id";
                            dynamicParams.Add("@m_id", parents[i].id);
                            var children = DapperHelper.select<WorkRouteStepEqpSub>(sql, dynamicParams);
                            parents[i].children = children.ToList();
                        }
                    }
                }
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.count = data.Rows.Count;
                mes.data = data;
                mes.message = "查询成功!";
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[MES工单查看工单SOP]
        public static ToMessage MesOrderSopSearch(string wocode, string materielcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取SOP文件信息
                sql = @"select filename,filepath,version from TWrkOrderSop
                        where wo=@wocode and materielcode=@materielcode
                        order by version";
                dynamicParams.Add("@wocode", wocode);
                dynamicParams.Add("@materielcode", materielcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.message = "查询成功!";
                    mes.data = data;
                }
                else
                {
                    mes.code = "300";
                    mes.message = "当前工单产品暂无SOP文件!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[MES工单查看工艺SOP]
        public static ToMessage MesOrderProcessSopSearch(string materielcode, string routecode, string stepcode, User us)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                dynamic dynObj = JObject.Parse(us.mesSetting);
                bool route = dynObj.route;
                if (route) //工艺路线版
                {
                    //获取SOP文件信息
                    sql = @"select filename,filepath,version from TProcessSop
                        where  materielcode=@materielcode and routecode=@routecode and stepcode=@stepcode
                        order by version";
                    dynamicParams.Add("@materielcode", materielcode);
                    dynamicParams.Add("@routecode", routecode);
                    dynamicParams.Add("@stepcode", stepcode);
                }
                else
                {
                    //获取SOP文件信息
                    sql = @"select filename,filepath,version from TProcessSop
                        where  materielcode=@materielcode and stepcode=@stepcode
                        order by version";
                    dynamicParams.Add("@materielcode", materielcode);
                    dynamicParams.Add("@stepcode", stepcode);
                }
                var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -1838,7 +2020,7 @@
                        else //不按序收发料
                        {
                            mes = ScanStartReport.NoWXEncodingSeach(SelectType, wocode, stepcode);
                        }
                        }
                        break;
                    default:
                        break;
@@ -3297,7 +3479,7 @@
                                    }
                                }
                            }
                        }
                        }
                    }
                }
                else //不按序
@@ -3305,10 +3487,10 @@
                    //控制逻辑:当前工序报工调整-> (本道工序当前调整合格数+本道工序非当前报工合格总数)<下道工序报工总数(合格+不良+报废)   ==不能小于下道报工总数
                    list.Clear();
                    //判断当前工序是自制工序还是外协工序
                    if (json[0].flw_type.ToString() == "Z")
                    if (json[0].flw_type.ToString() == "Z")
                    {
                       //查询当前报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                        //查询当前报工工序非此次报工:总报工数量、总不良数量、总工废数量、总料废数量
                        sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(laborbad_qty),0) as laborbad_qty,isnull(sum(materielbad_qty),0) as materielbad_qty   
                                from TK_Wrk_Record where wo_code=@wo_code and style='B' and id<>@id and step_code=@step_code";
                        dynamicParams.Add("@wo_code", json[0].wo_code);
@@ -3330,7 +3512,7 @@
                            return mes;
                        }
                    }
                    if (json[0].flw_type.ToString() == "W")
                    if (json[0].flw_type.ToString() == "W")
                    {
                        //获取当前工序、供应商对应的总发料数量
                        sql = @"select isnull(sum(fqty),0) as fqty
@@ -3352,7 +3534,7 @@
                        decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                        decimal notthis_laborbad_qty = decimal.Parse(dt.Rows[0]["laborbad_qty"].ToString());  //当前末道工序非本次报工工废总数
                        decimal notthis_materielbad_qty = decimal.Parse(dt.Rows[0]["materielbad_qty"].ToString());  //当前末道工序非本次报工料废总数
                       //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数
                                                                                                                    //获取当前末道工序收料总数量:本次修改收料数量+本次修改不良数量+本次修改工废数量+本次修改报工料废数量+当前工序非本次收料总数+当前工序非本次不良总数+当前工序非本次工废总数+当前工序非本次料废总数
                        decimal updatereportsumqty = this_reportqty + this_ngqty + this_laborbadqty + this_materielbadqty + notthis_reportqty + notthis_ngqty + notthis_laborbad_qty + notthis_materielbad_qty;
                        //判断当前工序供应商收料总数>当前工序供应商对应发料数量
                        if (updatereportsumqty > decimal.Parse(dt_0.Rows[0]["fqty"].ToString()))
@@ -3392,7 +3574,7 @@
                            }
                        });
                        //回写对应的报工记录主表合格数量、不良数量、报废数量
                        sql = @"update TK_Wrk_Record set start_qty=start_qty+@good_qty, good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                        sql = @"update TK_Wrk_Record set step_price=@step_price,start_qty=start_qty+@good_qty, good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'";
                        list.Add(new
@@ -3400,6 +3582,7 @@
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].unprice),
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
@@ -3494,7 +3677,7 @@
                            }
                        });
                        //回写对应的收料记录主表收料数量、不良数量、报废数量
                        sql = @"update TK_Wrk_OutRecord set sqty=sqty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                        sql = @"update TK_Wrk_OutRecord set step_price=@step_price,sqty=sqty+@good_qty,ng_qty=ng_qty+@ng_qty,laborbad_qty=laborbad_qty+@laborbad_qty,materielbad_qty=materielbad_qty+@materielbad_qty,
                            updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                            where wo_code=@wo_code and step_code=@step_code and id=@id and style='S' and wx_code=@wx_code";
                        list.Add(new
@@ -3502,6 +3685,7 @@
                            str = sql,
                            parm = new
                            {
                                step_price = decimal.Parse(json[0].unprice),
                                good_qty = decimal.Parse(json[0].report_dvalue),
                                ng_qty = this_ng_dvalue,
                                laborbad_qty = this_laborbad_dvalue,
@@ -3779,5 +3963,67 @@
            return mes;
        }
        #endregion
        #region[生产执行,报工弃审数据提交]
        public static ToMessage MesOrderStepReportNotVerifySeave(User us, string id, string steptype)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                if (steptype == "Z")//自制工序
                {
                    //回写报工记录主表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_Record set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                    //回写报工记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_RecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where m_id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                }
                if (steptype == "W")//外协工序
                {
                    //回写外协记录主表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_OutRecord set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                    //回写外协记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_OutRecordSub set verify='N',verifyuser=@verifyuser,verifydate=@verifydate  where m_id=@id";
                    list.Add(new { str = sql, parm = new { verifyuser = "", verifydate = "", id = id } });
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    if (steptype == "Z")
                    {
                        //写入操作记录表
                        LogHelper.DbOperateLog(us.usercode, "报工弃审", "自制报工记录id:" + string.Join(",", id), us.usertype);
                    }
                    if (steptype == "W")
                    {
                        LogHelper.DbOperateLog(us.usercode, "报工弃审", "外协收料记录id:" + string.Join(",", id), us.usertype);
                    }
                    mes.code = "200";
                    mes.count = 0;
                    mes.message = "审核成功!";
                    mes.data = null;
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.message = "审核失败!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
    }
}