VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -475,6 +475,73 @@
        }
        #endregion
        #region[工单派发选择工艺路线或选择生产车间时判断绑定条件]
        public static ToMessage SelectRouteOrWkshop(string partcode, string routecode, string wkshopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                mes.code = "200";
                mes.Message = "";
                mes.data = null;
                //判断工艺路线对应工序是否都有关联工作站
                sql = @"select B.step_code,C.eqp_code 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
                        where A.code=@routecode";
                dynamicParams.Add("@routecode", routecode);
                var dtck = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dtck.Rows.Count; i++)
                {
                    if (dtck.Rows[i].IsNull("eqp_code"))
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "当前工艺路线对应工序【" + dtck.Rows[i]["step_code"].ToString() + "】,未关联设备,请关联所有工序对应设备!";
                        mes.data = null;
                        return mes;
                    }
                }
                //判断工艺路线对应工序关联的工作站是否有设置节拍工价
                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
                        AA.code=S.route_code and AA.step_code=S.step_code and AA.eqp_code=S.eqp_code";
                dynamicParams.Add("@partcode", partcode);
                dynamicParams.Add("@route_code", routecode);
                var dtc = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dtc.Rows.Count; i++)
                {
                    if (dtc.Rows[i]["flwtype"].ToString() == "Z") //判断工序是否为自制
                    {
                        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 AddUpdateMesOrder(string mesorderstus, string sourceorder, string ordertype, string mesordercode, string partcode, string mesqty, string routecode, string wkshopcode, string planstartdate, string planenddate, string orderlev, string username, string opertype)
        {
@@ -533,6 +600,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 + "'";
@@ -600,6 +686,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)
                    {
@@ -760,6 +875,40 @@
                         left join TMateriel_Info P on M.materiel_code=P.partcode
                        where A.wo_code=@wo_code order by A.seq";
                dynamicParams.Add("@wo_code", wo_code);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                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[MES工单工序任务查看SOP,获取SOP文件下拉列表]
        public static ToMessage SearchWorkStepSopList(string partcode, string routecode,string stepcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取SOP文件信息
                sql = @"select id,define_name,file_path   from TK_Sop_Matfile where materiel_code=@partcode and eqptype_code in(
                        select distinct T.code  from TMateriel_Route A
                        inner join TFlw_Rtdt B on A.route_code=B.rout_code
                        inner join TFlw_Rteqp E on B.step_code=E.step_code
                        inner join TEqpInfo  Q on E.eqp_code=Q.code
                        inner join TEqpType T on Q.eqptype_code=T.code
                        where A.materiel_code=@partcode and A.route_code=@routecode and B.step_code=@stepcode) order by file_version desc";
                dynamicParams.Add("@partcode", partcode);
                dynamicParams.Add("@routecode", routecode);
                dynamicParams.Add("@stepcode", stepcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.Message = "查询成功!";
@@ -2351,22 +2500,16 @@
        #region[生产管理,修改报工数据查询接口]
        public static ToMessage MesOrderStepVerifySearch(string reporttype, string wo_code, string partnumber, string partname, string partspec, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        public static ToMessage MesOrderStepVerifySearch(string verify, string wo_code, string partnumber, string partname, string partspec, string reportuser, string reportdateopendate, string reportdateclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (reporttype != "" && reporttype != null)
                if (verify != "" && verify != null)
                {
                    if (reporttype == "BZ")
                    {
                        search += "and AA.usergroup_code<>''";
                    }
                    else
                    {
                        search += "and AA.usergroup_code='' ";
                    }
                    search += "and AA.verify=@verify ";
                    dynamicParams.Add("@verify", verify);
                }
                if (wo_code != "" && wo_code != null)
                {
@@ -2410,20 +2553,19 @@
                var total = 0; //总条数
                var sql = @"select *  from(
                            select A.id,B.id as sbid,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,A.task_qty,M.wkshp_code,G.org_name as wkshp_name,A.eqp_code,E.name as eqp_name,
                            M.route_code,R.name as route_name,A.step_code,S.stepname,S.flwtype,D.first_choke,D.last_choke,T.unprice,B.usergroup_code,O.group_name as usergroup_name,B.report_person as usercode,U.username,
                            B.report_date,B.report_qty,B.ng_qty,B.bad_qty
                            M.route_code,R.name as route_name,A.step_seq,A.step_code,S.stepname,S.flwtype,D.first_choke,D.last_choke,T.unprice,B.report_person as usercode,U.username,
                            B.report_date,B.report_qty,B.ng_qty,B.bad_qty,B.verify,B.bad_money
                            from TK_Wrk_Record A
                            inner join TK_Wrk_RecordSub B on A.id=B.m_id
                            left join TK_Wrk_Man M on A.wo_code=M.wo_code
                            left join TStep S on A.step_code=S.stepcode
                            left join TPrteEqp_Stad T on A.materiel_code=T.materiel_code and M.route_code=T.route_code and A.step_code=T.step_code and A.eqp_code=T.eqp_code
                            left  join TWoPrteEqp_Stad T on A.wo_code=T.wo and A.materiel_code=T.materiel_code and A.eqp_code=T.eqp_code and A.step_code=T.step_code and M.route_code=T.route_code
                            left join TMateriel_Info P on A.materiel_code=P.partcode
                            left join TOrganization G on M.wkshp_code=G.org_code
                            left join TEqpInfo E on A.eqp_code=E.code
                            left join TFlw_Rout R on M.route_code=R.code
                            left join TFlw_Rtdt D on M.route_code=D.rout_code and A.step_code=D.step_code
                            left join TUser U on B.report_person=U.usercode
                            left join TGroup O on U.usergroup_code=O.group_code
                            where A.style='B' and B.style='B' and M.status<>'CLOSED'
                            ) as AA where" + search;
                //union all
@@ -2528,7 +2670,7 @@
                        }
                        //是否末道
                        if (json[i].last_choke == "Y")
                       else if (json[i].last_choke == "Y")
                        {
                            decimal this_reportqty = decimal.Parse(json[i].report_qty.ToString()); //报工数量(合格)
                            decimal this_ngqty = decimal.Parse(json[i].ng_qty.ToString()); //不良数量
@@ -2635,7 +2777,7 @@
                        ///////////////////////////////修改报工//////////////////////////////
                        //回写对应的报工记录子表合格数量、不良数量、报废数量
                        sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty+@ng_qty,bad_qty=bad_qty+@bad_qty,
                        sql = @"update TK_Wrk_RecordSub set report_qty=report_qty+@repair_qty,ng_qty=ng_qty+@ng_qty,bad_qty=bad_qty+@bad_qty,bad_money=bad_money+@bad_money,
                                updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                where  m_id=@m_id and id=@id and style='B'";
                        list.Add(new
@@ -2645,9 +2787,10 @@
                            {
                                m_id = int.Parse(json[i].id),
                                id = int.Parse(json[i].sbid),
                                repair_qty = decimal.Parse(json[i].report_qty),
                                ng_qty = decimal.Parse(json[i].ng_qty),
                                bad_qty = decimal.Parse(json[i].bad_qty),
                                repair_qty = decimal.Parse(json[i].report_dvalue),
                                ng_qty = decimal.Parse(json[i].ng_dvalue),
                                bad_qty = decimal.Parse(json[i].bad_dvalue),
                                bad_money = decimal.Parse(json[i].badmoney_dvalue),
                                updatereportuser = username,
                                updatereportdate = date
                            }
@@ -2660,9 +2803,9 @@
                            str = sql,
                            parm = new
                            {
                                good_qty = decimal.Parse(json[i].report_qty),
                                ng_qty = decimal.Parse(json[i].ng_qty),
                                bad_qty = decimal.Parse(json[i].bad_qty),
                                good_qty = decimal.Parse(json[i].report_dvalue),
                                ng_qty = decimal.Parse(json[i].ng_dvalue),
                                bad_qty = decimal.Parse(json[i].bad_dvalue),
                                wo_code = json[i].wo_code,
                                step_code = json[i].step_code,
                                id = int.Parse(json[i].id)
@@ -2676,7 +2819,7 @@
                            str = sql,
                            parm = new
                            {
                                ng_qty = decimal.Parse(json[i].ng_qty),
                                ng_qty = decimal.Parse(json[i].ng_dvalue),
                                wo_code = json[i].wo_code,
                                step_code = json[i].step_code,
                                id = int.Parse(json[i].id),
@@ -2768,9 +2911,9 @@
                    });
                    //写入报工记录审核表
                    sql = @"insert into  TK_WorkRecord_Verify(report_id,report_sbid,wo_code,partnumber,task_qty,wkshp_code,eqp_code,route_code,
                            step_seq,step_code,flw_type,first_choke,last_choke,unprice,usergroup_code,usercode,report_date,report_qty,report_dvalue,ng_qty,ng_dvalue,bad_qty,bad_dvalue,bad_money)
                            step_seq,step_code,flw_type,first_choke,last_choke,unprice,usergroup_code,usercode,report_date,report_qty,report_dvalue,ng_qty,ng_dvalue,bad_qty,bad_dvalue,bad_money,badmoney_dvalue)
                            values(@report_id,@report_sbid,@wo_code,@partnumber,@task_qty,@wkshp_code,@eqp_code,@route_code,
                            @step_seq,@step_code,@flw_type,@first_choke,@last_choke,@unprice,@usergroup_code,@usercode,@report_date,@report_qty,@report_dvalue,@ng_qty,@ng_dvalue,@bad_qty,@bad_dvalue,@bad_money)";
                            @step_seq,@step_code,@flw_type,@first_choke,@last_choke,@unprice,@usergroup_code,@usercode,@report_date,@report_qty,@report_dvalue,@ng_qty,@ng_dvalue,@bad_qty,@bad_dvalue,@bad_money,@badmoney_dvalue)";
                    list.Add(new
                    {
                        str = sql,
@@ -2790,7 +2933,7 @@
                            first_choke=json[i].first_choke.ToString(),
                            last_choke=json[i].last_choke.ToString(),
                            unprice=json[i].unprice.ToString(),
                            usergroup_code=json[i].usergroup_code.ToString(),
                            usergroup_code="",
                            usercode=json[i].usercode.ToString(),
                            report_date=json[i].report_date.ToString(),
                            report_qty=json[i].report_qty.ToString(),
@@ -2799,7 +2942,8 @@
                            ng_dvalue=json[i].ng_dvalue.ToString(),
                            bad_qty=json[i].bad_qty.ToString(),
                            bad_dvalue=json[i].bad_dvalue.ToString(),
                            bad_money=json[i].bad_money.ToString()
                            bad_money=json[i].bad_money.ToString(),
                            badmoney_dvalue= json[i].badmoney_dvalue.ToString()
                        }
                    });
                }
@@ -3038,7 +3182,7 @@
                                wo_code=json[i].wo_code.ToString(),
                                step_seq=json[i].step_seq.ToString(),
                                step_code=json[i].step_code.ToString(),
                                repair_qty = decimal.Parse(json[i].report_qty),
                                report_qty = decimal.Parse(json[i].report_qty),
                                ng_qty = decimal.Parse(json[i].ng_qty),
                                bad_qty = decimal.Parse(json[i].bad_qty),
                            }