yl
2023-03-07 301936d643fe804b52b397dc594877d8d3cbe202
VueWebApi/DLL/DAL/ProductionManagementDAL.cs
@@ -66,7 +66,7 @@
                }
                if (creatuser != "" && creatuser != null)
                {
                    search += "and U.username like '%'+@creatuser+'%' ";
                    search += "and A.createuser like '%'+@creatuser+'%' ";
                    dynamicParams.Add("@creatuser", creatuser);
                }
@@ -77,12 +77,11 @@
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.id, A.status,A.wo,A.materiel_code as partcode,B.partname,B.partspec,A.qty,A.relse_qty,A.wkshp_code,C.org_name as wkshp_name,
                            A.stck_code,D.name as stck_name,A.planstartdate,A.planenddate,U.username as createuser,A.createdate
                            A.stck_code,D.name as stck_name,A.planstartdate,A.planenddate,A.createuser as createuser,A.createdate
                            from TKimp_Ewo A
                            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 TUser U on A.createuser=U.usercode
                            left join T_Sec_Stck D on A.stck_code=D.code
                            where A.is_delete<>'1' " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
@@ -385,6 +384,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)
        {
@@ -476,6 +552,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)
        {
@@ -534,6 +677,32 @@
                            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 + "'";
                    //    DataTable dt1 = DBHelper.GetTable(sql1);
                    //}
                    //增加工单用料表(子件)
                    bool aa = DapperHelper.DoTransaction(list);
                    if (aa)
@@ -594,6 +763,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)
                    {
@@ -631,7 +829,7 @@
            try
            {
                //判断工单是否为未开始状态或者已派发状态(满足其中一种都可删除,否则不允许删除)
                sql = @"select *  from TK_Wrk_Man where wo_code=@wocode and status='NEW' or status='ALLO'";
                sql = @"select *  from TK_Wrk_Man where wo_code=@wocode and status in('NEW','ALLO')";
                dynamicParams.Add("@wocode", wocode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
@@ -752,8 +950,42 @@
                         left join TStep B on A.step_code=B.stepcode
                         left join TK_Wrk_Man M on A.wo_code=M.wo_code
                         left join TMateriel_Info P on M.materiel_code=P.partcode
                        where A.wo_code=@wo_code";
                        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 = "查询成功!";
@@ -2343,6 +2575,732 @@
        #endregion
        #region[生产管理,修改报工数据查询接口]
        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 (verify != "" && verify != null)
                {
                    search += "and AA.verify=@verify ";
                    dynamicParams.Add("@verify", verify);
                }
                if (wo_code != "" && wo_code != null)
                {
                    search += "and AA.wo_code like '%'+@wo_code+'%' ";
                    dynamicParams.Add("@wo_code", wo_code);
                }
                if (partnumber != "" && partnumber != null)
                {
                    search += "and AA.partnumber like '%'+@partnumber+'%' ";
                    dynamicParams.Add("@partnumber", partnumber);
                }
                if (partname != "" && partname != null)
                {
                    search += "and AA.partname like '%'+@partname+'%' ";
                    dynamicParams.Add("@partname", partname);
                }
                if (partspec != "" && partspec != null)
                {
                    search += "and AA.partspec like '%'+@partspec+'%' ";
                    dynamicParams.Add("@partspec", partspec);
                }
                if (reportuser != "" && reportuser != null)
                {
                    search += "and AA.usercode like '%'+@reportuser+'%' ";
                    dynamicParams.Add("@reportuser", reportuser);
                }
                if (reportdateopendate != "" && reportdateopendate != null)
                {
                    search += "and AA.report_date between @reportdateopendate and @reportdateclosedate ";
                    dynamicParams.Add("@reportdateopendate", reportdateopendate + " 00:00:00");
                    dynamicParams.Add("@reportdateclosedate", reportdateclosedate + " 23:59:59");
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定自制报工外协收料数据--------------
                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_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 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
                            where A.style='B' and B.style='B' and M.status<>'CLOSED'
                            ) as AA where" + search;
                //union all
                //select A.id,A.wo_code,A.materiel_code as partnumber,P.partname,P.partspec,M.plan_qty as task_qty,M.wkshp_code,G.org_name as wkshp_name,A.wx_code as 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,'' as usergroup_code,'' as usergroup_name,B.in_person as usercode,U.username,
                //B.in_time as report_date,B.sqty as report_qty,B.ng_qty,B.bad_qty
                //from TK_Wrk_OutRecord A
                //inner join TK_Wrk_OutRecordSub 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.wx_code = T.eqp_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 TCustomer E on A.wx_code = E.code and E.btype = 'WX'
                //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.in_person = U.usercode
                //where A.style = 'S' and B.style = 'S' and M.status<>'CLOSED'
                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 MesOrderStepUpdateSeave(string username, List<UpdateProductReport> json)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                string date = DateTime.Now.ToString(); //获取系统时间
                list.Clear();
                //循环json数据
                for (int i = 0; i < json.Count; i++)
                {
                    //自制工序
                    if (json[i].flw_type.ToString() == "Z")
                    {
                        //是否首道
                        if (json[i].first_choke == "Y")
                        {
                            decimal this_reportqty = decimal.Parse(json[i].report_qty.ToString()); //报工数量(合格)
                            decimal this_ngqty = decimal.Parse(json[i].ng_qty.ToString()); //不良数量
                            decimal this_badqty = decimal.Parse(json[i].bad_qty.ToString()); //报废数量
                            //查询当前工序非此次报工:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_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[i].wo_code);
                            dynamicParams.Add("@id", json[i].id);
                            dynamicParams.Add("@step_code", json[i].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_badqty = decimal.Parse(dt.Rows[0]["bad_qty"].ToString());  //当前工序非本次报工总数
                            //判断:当前工序报工记录:本次报工数量+本次不良数量+本次报废数量+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次报废总数>工单任务数量
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_badqty + notthis_reportqty + notthis_ngqty + notthis_badqty;
                            if (updatereportsumqty > decimal.Parse(json[i].task_qty.ToString()))
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.Message = "自制首道工序修改报工总数量:【" + updatereportsumqty + "】不能大于工单任务数量:【" + json[i].task_qty.ToString() + "】!";
                                mes.data = null;
                                return mes;
                            }
                            //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                            dynamicParams.Add("@wo_code", json[i].wo_code);
                            dynamicParams.Add("@step_seq", json[i].step_seq);
                            var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                            if (dt0.Rows.Count > 0)
                            {
                                //判断当前工序:报工总数数量+不良总数数量+报废总数数量<下道工序报工总数量+下道工序不良总数量+下道工序报废总数量
                                decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                decimal last_badqty = decimal.Parse(dt0.Rows[0]["bad_qty"].ToString());  //下道工序报废总数量
                                decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_badqty;
                                if (updatereportsumqty < last_updatereportsumqty)
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "自制首道工序修改报工总数量:【" + updatereportsumqty + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改下道工序报工数量!";
                                    mes.data = null;
                                    return mes;
                                }
                            }
                        }
                        //是否末道
                       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()); //不良数量
                            decimal this_badqty = decimal.Parse(json[i].bad_qty.ToString()); //报废数量
                            //查询当前末道工序非此次报工:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_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[i].wo_code);
                            dynamicParams.Add("@id", json[i].id);
                            dynamicParams.Add("@step_code", json[i].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前末道工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前末道工序非本次报工总数
                            decimal notthis_badqty = decimal.Parse(dt.Rows[0]["bad_qty"].ToString());  //当前末道工序非本次报工总数
                            //获取当前末道工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改报废数量+当前末道工序非本次报工总数+当前末道工序非本次不良总数+当前末道工序非本次报废总数
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_badqty + notthis_reportqty + notthis_ngqty + notthis_badqty;
                            //查询当前末道工序上道工序:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                            dynamicParams.Add("@wo_code", json[i].wo_code);
                            dynamicParams.Add("@step_seq", json[i].step_seq);
                            var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                            if (dt0.Rows.Count > 0)
                            {
                                //判断:当前末道工序报工记录:当前末道工序报工总数(合格+不良+报废)>上道工序报工总数(合格+不良+报废)
                                decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                decimal last_badqty = decimal.Parse(dt0.Rows[0]["bad_qty"].ToString());  //下道工序报废总数量
                                decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_badqty;
                                if (updatereportsumqty > last_updatereportsumqty)
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "自制末道工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改上道工序报工数量!";
                                    mes.data = null;
                                    return mes;
                                }
                            }
                        }
                        else  //非首道非末道
                        {
                            decimal this_reportqty = decimal.Parse(json[i].report_qty.ToString()); //报工数量(合格)
                            decimal this_ngqty = decimal.Parse(json[i].ng_qty.ToString()); //不良数量
                            decimal this_badqty = decimal.Parse(json[i].bad_qty.ToString()); //报废数量
                            //查询当前工序非此次报工:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_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[i].wo_code);
                            dynamicParams.Add("@id", json[i].id);
                            dynamicParams.Add("@step_code", json[i].step_code);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            decimal notthis_reportqty = decimal.Parse(dt.Rows[0]["good_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_ngqty = decimal.Parse(dt.Rows[0]["ng_qty"].ToString());  //当前工序非本次报工总数
                            decimal notthis_badqty = decimal.Parse(dt.Rows[0]["bad_qty"].ToString());  //当前工序非本次报工总数
                            //获取当前末道工序报工总数量:本次修改报工数量+本次修改不良数量+本次修改报废数量+当前工序非本次报工总数+当前工序非本次不良总数+当前工序非本次报废总数
                            decimal updatereportsumqty = this_reportqty + this_ngqty + this_badqty + notthis_reportqty + notthis_ngqty + notthis_badqty;
                            //查询当前工序上道工序:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq-1";
                            dynamicParams.Add("@wo_code", json[i].wo_code);
                            dynamicParams.Add("@step_seq", json[i].step_seq);
                            var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                            if (dt0.Rows.Count > 0)
                            {
                                //判断:当前工序报工记录:当前工序报工总数(合格+不良+报废)>上道工序报工总数(合格+不良+报废)
                                decimal last_reportqty = decimal.Parse(dt0.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                decimal last_ngqty = decimal.Parse(dt0.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                decimal last_badqty = decimal.Parse(dt0.Rows[0]["bad_qty"].ToString());  //下道工序报废总数量
                                decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_badqty;
                                if (updatereportsumqty > last_updatereportsumqty)
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "自制工序修改报工总数量:【" + updatereportsumqty + "】不能大于上道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改上道工序报工数量!";
                                    mes.data = null;
                                    return mes;
                                }
                            }
                            //查询当前工序下道工序:总报工数量、总不良数量、总报废数量
                            sql = @"select isnull(sum(good_qty),0) as good_qty,isnull(sum(ng_qty),0) as ng_qty,isnull(sum(bad_qty),0) as bad_qty
                                    from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                            dynamicParams.Add("@wo_code", json[i].wo_code);
                            dynamicParams.Add("@step_seq", json[i].step_seq);
                            var dt1 = DapperHelper.selectdata(sql, dynamicParams);
                            if (dt1.Rows.Count > 0)
                            {
                                //判断当前工序:报工总数数量+不良总数数量+报废总数数量<下道工序报工总数量+下道工序不良总数量+下道工序报废总数量
                                decimal last_reportqty = decimal.Parse(dt1.Rows[0]["good_qty"].ToString());  //下道工序报工总数量
                                decimal last_ngqty = decimal.Parse(dt1.Rows[0]["ng_qty"].ToString());  //下道工序不良总数量
                                decimal last_badqty = decimal.Parse(dt1.Rows[0]["bad_qty"].ToString());  //下道工序报废总数量
                                decimal last_updatereportsumqty = last_reportqty + last_ngqty + last_badqty;
                                if (updatereportsumqty < last_updatereportsumqty)
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "自制工序修改报工总数量:【" + updatereportsumqty + "】不能小于下道工序报工总数量:【" + last_updatereportsumqty + "】,请输入合法数值或先修改下道工序报工数量!";
                                    mes.data = null;
                                    return mes;
                                }
                            }
                        }
                        ///////////////////////////////修改报工//////////////////////////////
                        //回写对应的报工记录子表合格数量、不良数量、报废数量
                        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
                        {
                            str = sql,
                            parm = new
                            {
                                m_id = int.Parse(json[i].id),
                                id = int.Parse(json[i].sbid),
                                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
                            }
                        });
                        //回写对应的报工记录主表合格数量、不良数量、报废数量
                        sql = @"update TK_Wrk_Record set good_qty=good_qty+@good_qty,ng_qty=ng_qty+@ng_qty,bad_qty=bad_qty+@bad_qty
                                    where wo_code=@wo_code and step_code=@step_code and id=@id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                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)
                            }
                        });
                        //回写不良
                        sql = @"update CSR_WorkRecord_Defect set defect_qty=defect_qty+@ng_qty,updatereportuser=@updatereportuser,updatereportdate=@updatereportdate
                                    where wo_code=@wo_code and step_code=@step_code and record_id=@id and style='B'";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                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),
                                updatereportuser = username,
                                updatereportdate = date
                            }
                        });
                    }
                    //外协工序
                    if (json[i].flw_type.ToString() == "S")
                    {
                    }
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    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
        #region[生产管理,修改报工审核提交]
        public static ToMessage MesOrderStepVerifySeave(string username, List<UpdateProductReport> json)
        {
            var sql = "";
            List<object> list = new List<object>();
            try
            {
                string date = DateTime.Now.ToString(); //获取系统时间
                list.Clear();
                //循环json数据
                for (int i = 0; i < json.Count; i++)
                {
                    ///////////////////////////////修改报工//////////////////////////////
                    //回写对应的报工记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_RecordSub set verify=@verify,verifyuser=@verifyuser,verifydate=@verifydate
                                where  m_id=@m_id and id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            m_id = int.Parse(json[i].id),
                            id = int.Parse(json[i].sbid),
                            verify="Y",
                            verifyuser = username,
                            verifydate = date
                        }
                    });
                    //回写不良
                    sql = @"update CSR_WorkRecord_Defect set verify=verify,verifyuser=@verifyuser,verifydate=@verifydate
                                    where wo_code=@wo_code and step_code=@step_code and record_id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            wo_code = json[i].wo_code,
                            step_code = json[i].step_code,
                            id = int.Parse(json[i].id),
                            verify="Y",
                            verifyuser = username,
                            verifydate = date
                        }
                    });
                    //写入报工记录审核表
                    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,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,@badmoney_dvalue)";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            report_id=json[i].id.ToString(),
                            report_sbid=json[i].sbid.ToString(),
                            wo_code=json[i].wo_code.ToString(),
                            partnumber=json[i].partnumber.ToString(),
                            task_qty=json[i].task_qty.ToString(),
                            wkshp_code=json[i].wkshp_code.ToString(),
                            eqp_code=json[i].eqp_code.ToString(),
                            route_code=json[i].route_code.ToString(),
                            step_seq=json[i].step_seq.ToString(),
                            step_code=json[i].step_code.ToString(),
                            flw_type=json[i].flw_type.ToString(),
                            first_choke=json[i].first_choke.ToString(),
                            last_choke=json[i].last_choke.ToString(),
                            unprice=json[i].unprice.ToString(),
                            usergroup_code="",
                            usercode=json[i].usercode.ToString(),
                            report_date=json[i].report_date.ToString(),
                            report_qty=json[i].report_qty.ToString(),
                            report_dvalue=json[i].report_dvalue.ToString(),
                            ng_qty=json[i].ng_qty.ToString(),
                            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(),
                            badmoney_dvalue= json[i].badmoney_dvalue.ToString()
                        }
                    });
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    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
        #region[生产管理,修改报工反审核提交]
        public static ToMessage MesOrderStepNoVerifySeave(string username, List<UpdateProductReport> json)
        {
            var sql = "";
            List<object> list = new List<object>();
            try
            {
                string date = DateTime.Now.ToString(); //获取系统时间
                list.Clear();
                //循环json数据
                for (int i = 0; i < json.Count; i++)
                {
                    ///////////////////////////////修改报工//////////////////////////////
                    //回写对应的报工记录子表审核状态、审核人、审核时间
                    sql = @"update TK_Wrk_RecordSub set verify=@verify,verifyuser=@verifyuser,verifydate=@verifydate
                                where  m_id=@m_id and id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            m_id = int.Parse(json[i].id),
                            id = int.Parse(json[i].sbid),
                            verify = "N",
                            verifyuser = "",
                            verifydate = ""
                        }
                    });
                    //回写不良
                    sql = @"update CSR_WorkRecord_Defect set verify=verify,verifyuser=@verifyuser,verifydate=@verifydate
                                    where wo_code=@wo_code and step_code=@step_code and record_id=@id and style='B'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            wo_code = json[i].wo_code,
                            step_code = json[i].step_code,
                            id = int.Parse(json[i].id),
                            verify = "N",
                            verifyuser = "",
                            verifydate = ""
                        }
                    });
                    //删除报工记录审核表
                    sql = @"delete from TK_WorkRecord_Verify where wo_code=@wo_code and report_id=@report_id and report_sbid=@report_sbid and step_seq=@step_seq and step_code=@step_code";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            report_id = json[i].id.ToString(),
                            report_sbid = json[i].sbid.ToString(),
                            wo_code = json[i].wo_code.ToString(),
                            step_seq = json[i].step_seq.ToString(),
                            step_code = json[i].step_code.ToString()
                        }
                    });
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    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
        #region[生产管理,删除报工记录]
        public static ToMessage MesOrderStepDeleteSeave(string username, List<UpdateProductReport> json)
        {
            var sql = "";
            string[] arra1 = new string[] { };
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                string date = DateTime.Now.ToString(); //获取系统时间
                list.Clear();
                //循环json数据
                for (int i = 0; i < json.Count; i++)
                {
                    //自制工序
                    if (json[i].flw_type.ToString() == "Z")
                    {
                        //判断当前工序是否存在下道工序开工记录
                        sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and style='S'  and step_seq=@step_seq+1";
                        dynamicParams.Add("@wo_code", json[i].wo_code);
                        dynamicParams.Add("@step_seq", json[i].step_seq);
                        var dt0 = DapperHelper.selectdata(sql, dynamicParams);
                        if (dt0.Rows.Count > 0)
                        {
                            //判断当前工序是否存在下道工序报工记录
                            sql = @"select * from TK_Wrk_Record where wo_code=@wo_code and style='B'  and step_seq=@step_seq+1";
                            dynamicParams.Add("@wo_code", json[i].wo_code);
                            dynamicParams.Add("@step_seq", json[i].step_seq);
                            var dt = DapperHelper.selectdata(sql, dynamicParams);
                            if (dt.Rows.Count > 0)
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.Message = "当前工序下道工序已报工不允许删除!";
                                mes.data = null;
                                return mes;
                            }
                        }
                        ///////////////////////////////删除报工//////////////////////////////
                        //删除下道工序开工记录(主要处理下道工序已开工未报工)
                        sql = @"delete from TK_Wrk_Record where  wo_code=@wo_code and step_seq=@step_seq+1 and style=@style";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                wo_code=json[i].wo_code.ToString(),
                                step_seq=json[i].step_seq.ToString(),
                                style = "S"
                            }
                        });
                        //删除报工缺陷记录表
                        sql = @"delete from CSR_WorkRecord_Defect where  wo_code=@wo_code and partnumber=@partnumber and step_seq=@step_seq and step_code=@step_code and record_id=@record_id and style=@style ";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                wo_code=json[i].wo_code.ToString(),
                                partnumber = json[i].partnumber.ToString(),
                                step_seq = json[i].step_seq.ToString(),
                                step_code = json[i].step_code.ToString(),
                                record_id = int.Parse(json[i].id),
                                style = "B"
                            }
                        });
                        //删除报工缺陷处理记录表
                        sql = @"delete from CSR_WorkRecord_DefectHandle where  wo_code=@wo_code and partnumber=@partnumber and step_seq=@step_seq and step_code=@step_code and record_subid=@record_subid and style=@style";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                wo_code = json[i].wo_code.ToString(),
                                partnumber = json[i].partnumber.ToString(),
                                step_seq = json[i].step_seq.ToString(),
                                step_code = json[i].step_code.ToString(),
                                record_subid = int.Parse(json[i].id),
                                style = "B"
                            }
                        });
                        //删除报工记录子表
                        sql = @"delete from TK_Wrk_RecordSub where  id=@id and m_id=@m_id and style=@style";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                id = int.Parse(json[i].id),
                                m_id = int.Parse(json[i].sbid),
                                style = "B"
                            }
                        });
                        //删除报工记录主表
                        sql = @"delete from TK_Wrk_Record where  id=@id and style=@style";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                id = int.Parse(json[i].id),
                                m_id = int.Parse(json[i].sbid),
                                style = "B"
                            }
                        });
                        //回写工单工序表(合格数量、不良数量、报废数量)
                        sql = @"update  TK_Wrk_Step set good_qty=good_qty-@report_qty,ng_qty=ng_qty-@ng_qty,bad_qty=bad_qty-@bad_qty where  wo_code=@wo_code and seq=@step_seq and step_code=@step_code";
                        list.Add(new
                        {
                            str = sql,
                            parm = new
                            {
                                wo_code=json[i].wo_code.ToString(),
                                step_seq=json[i].step_seq.ToString(),
                                step_code=json[i].step_code.ToString(),
                                report_qty = decimal.Parse(json[i].report_qty),
                                ng_qty = decimal.Parse(json[i].ng_qty),
                                bad_qty = decimal.Parse(json[i].bad_qty),
                            }
                        });
                    }
                    //外协工序
                    if (json[i].flw_type.ToString() == "S")
                    {
                    }
                }
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
                {
                    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
        #region[MES工单批量关闭查询]
        public static ToMessage MesOrderBitchClosedSearch(string mesorderstus, string mesordercode, string sourceorder, string ordertype, string partcode, string partname, string partspec, int startNum, string creatuser, string createdate, int endNum, string prop, string order)
        {
@@ -2590,7 +3548,7 @@
                                      FROM TWkm_capac_plan_sub t0 where CONVERT(varchar(100), wkdate, 23)>=CONVERT(varchar(100),getdate(), 23) 
                                      GROUP BY t0.m_id  
                             ) E on B.id=E.m_id
                            where C.description='W' ";
                            where C.description='W' " + search;
                var data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total);
                mes.code = "200";
                mes.Message = "查询成功!";
@@ -2616,14 +3574,14 @@
            {
                if (type == "Add")
                {
                    var sql = @"insert into TWkm_capac_plan(wkshop, eqp_typecode, wkshift_code, enable, lm_user, lm_time,classtype)
                            values(@wkshop,@eqp_typecode,@wkshift_code,@enable,@lm_user,@lm_time,@classtype)";
                    var sql = @"insert into TWkm_capac_plan(wkshop, eqp_typecode, wkshift_code, enable, lm_user, lm_date,classtype)
                            values(@wkshop,@eqp_typecode,@wkshift_code,@enable,@lm_user,@lm_date,@classtype)";
                    dynamicParams.Add("@wkshop", wkshopcode);
                    dynamicParams.Add("@eqp_typecode", capunitcode);
                    dynamicParams.Add("@wkshift_code", capsetupcode);
                    dynamicParams.Add("@enable", "Y");
                    dynamicParams.Add("@lm_user", username);
                    dynamicParams.Add("@lm_time", DateTime.Now.ToString());
                    dynamicParams.Add("@lm_date", DateTime.Now.ToString());
                    dynamicParams.Add("@classtype", captplantype);
                    int cont = DapperHelper.SQL(sql, dynamicParams);
                    if (cont > 0)
@@ -2687,10 +3645,10 @@
                sql = @"select CONVERT(varchar(100), wkdate, 23) DataTime,wkshift_code   from TWkm_capac_plan_sub where m_id=@captplanid";
                dynamicParams.Add("@captplanid", captplanid);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dt.Rows.Count; i++)
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    string DataTime = dt.Rows[i]["DataTime"].ToString();//日期
                    string key = dt.Rows[i]["wkshift_code"].ToString(); //方案编码
                    string DataTime = data.Rows[i]["DataTime"].ToString();//日期
                    string key = data.Rows[i]["wkshift_code"].ToString(); //方案编码
                    CapaPlan cmp = new CapaPlan();
                    cmp.name = DataTime;
                    cmp.key = key;
@@ -2728,11 +3686,11 @@
                dynamicParams.Add("@captplanid", captplanid);
                dynamicParams.Add("@datetime", datetime);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dt.Rows.Count; i++)
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    string code = dt.Rows[i]["code"].ToString();//方案编码
                    string name = dt.Rows[i]["name"].ToString();//方案名称
                    string flag = dt.Rows[i]["flag"].ToString();   //选中方案标识
                    string code = data.Rows[i]["code"].ToString();//方案编码
                    string name = data.Rows[i]["name"].ToString();//方案名称
                    string flag = data.Rows[i]["flag"].ToString();   //选中方案标识
                    CapacityPlanSect cmp = new CapacityPlanSect();
                    cmp.CapCode = code;
                    cmp.CapName = name;
@@ -2741,7 +3699,7 @@
                    string sql1 = @"select wktme1_start,wktme2_start,wktme3_start,wktme4_start,wktme5_start  from TBas_wkshift_info where code=@code";
                    dynamicParams.Add("@code", code);
                    var db = DapperHelper.selectdata(sql, dynamicParams);
                    var db = DapperHelper.selectdata(sql1, dynamicParams);
                    for (int j = 0; j < db.Columns.Count; j++) //时间段
                    {
@@ -2855,11 +3813,10 @@
                    List<CapaPlan> list4 = ids1.Except(ids).ToList(); //表示ids1中哪些值是ids中所不存在的;
                    list4 = list3.Union(list4).ToList();
                    //查找关键工序设备、工位群组的所有设备
                    string sql3 = @"select *  from(
                                  select distinct A.code,A.name  from TEqpInfo A
                    string sql3 = @"select distinct A.code,A.name  from TEqpInfo A
                                  left join TFlw_Rteqp B on A.code=B.eqp_code
                                  left join TFlw_Rtdt D on B.step_code=D.step_code                 
                                  where A.wksp_code=@wkshopcode  and D.first_choke='Y'  order by A.code)";
                                  where A.wksp_code=@wkshopcode  and D.first_choke='Y'  order by A.code";
                    dynamicParams.Add("@wkshopcode", wkshopcode);
                    var dt3 = DapperHelper.selectdata(sql3, dynamicParams);
                    if (list4.Count > 0)  //如果日期有变动
@@ -2895,17 +3852,17 @@
                        }
                    }
                    //更新排产生产资源主表
                    sql = @"update gn_wkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_time=@lm_time  where id=@id";
                    sql = @"update TWkm_capac_plan set wkshift_code=@wkshift_code,classtype=@classtype,lm_user=@lm_user,lm_date=@lm_time  where id=@id";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            id=captplanid,
                            id = captplanid,
                            wkshift_code = capsetupcode,
                            classtype = captplantype,
                            lm_user =username,
                            lm_time= DateTime.Now.ToString()
                            lm_user = username,
                            lm_time = DateTime.Now.ToString()
                        }
                    });
                    //删除排产生产资源子表
@@ -2921,7 +3878,7 @@
                    //循环写入排产生产资源子表
                    for (int i = 0; i < objs.Count; i++)
                    {
                        sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values()";
                        sql = @"insert into TWkm_capac_plan_sub(m_id,wkdate,wkshift_code) values(@m_id,@wkdate,@wkshift_code)";
                        list.Add(new
                        {
                            str = sql,
@@ -2929,7 +3886,7 @@
                            {
                                m_id = captplanid,
                                wkdate = objs[i].name,
                                wkshift_code= objs[i].key
                                wkshift_code = objs[i].key
                            }
                        });
                    }
@@ -2960,5 +3917,484 @@
            return mes;
        }
        #endregion
        #region[自动排程工单查询]
        public static ToMessage AdvancedSchedulingSearch(string workshop, string wocode, string partcode, string partname, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (workshop != "" && workshop != null)
                {
                    search += "and A.wkshp_code=@workshop ";
                    dynamicParams.Add("@workshop", workshop);
                }
                if (wocode != "" && wocode != null)
                {
                    search += "and A.wo_code like '%'+@wocode+'%' ";
                    dynamicParams.Add("@wocode", wocode);
                }
                if (partcode != "" && partcode != null)
                {
                    search += "and A.materiel_code like '%'+@partcode+'%' ";
                    dynamicParams.Add("@partcode", partcode);
                }
                if (partname != "" && partname != null)
                {
                    search += "and C.partname like '%'+@partname+'%' ";
                    dynamicParams.Add("@partname", partname);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select
                             A.id              AdvaScheId,
                             A.status          AdvaScheStus,
                             A.wo_code         AdvaScheWorkCode,
                             A.wkshp_code      AdvaScheWorkShopid,
                             M.org_name        AdvaScheWorkShop,
                             A.materiel_code   AdvaSchePartNumber,
                             C.partname        AdvaSchePartName,
                             C.partspec        AdvaSchePartSpec,
                             D.name            AdvaSchePartModel,
                             A.plan_qty        AdvaScheQty,
                             U.name            AdvaScheUom,
                             isnull(E.sched_qty,0)       AdvaScheYPQty,
                            CONVERT(varchar(100), B.planenddate, 23) AdvaScheEndDate,
                            convert(varchar(20),isnull(E.sched_qty,0))+'/'+convert(varchar(20),isnull(A.plan_qty,0)) AdvaScheSpeed,
                             A.route_code    AdvaScheRoutid,
                             F.name        AdvaScheRoutName,
                             E.step_code   AdvaScheBotProcid,
                             G.stepname        AdvaScheBotProcName,
                            CONVERT(varchar(100), H.maxtime, 23) AdvaSchePCEndDate,
                             CONVERT(varchar(100), H.mintime, 23) AdvaSchePCStartDate,
                            (case  when CONVERT(varchar(100), H.maxtime, 23)<=CONVERT(varchar(100), E.plan_enddate, 23) then 'Y'  when H.MAXTime is null  then 'Y'  else 'N' end) Flag,
                            (case when A.PiroQue='1' then '特急' when A.PiroQue='2' then '紧急' when A.PiroQue='3' then '正常' end) AdvaSchePiroQue
                            from TK_Wrk_Man A
                            left join TKimp_Ewo B on A.m_po=B.wo
                            left join TMateriel_Info C on C.partcode= A.materiel_code
                             left join T_Dict D on C.stocktype_code= d.code
                             left join TK_Wrk_Step E on E.wo_code=A.wo_code
                             left join TFlw_Rout F  on A.route_code=F.code
                             left join TStep G  on E.step_code=G.stepcode
                             left join (select wo_code, max(TIME_END) MAXTime,min(time_start) MINTime  from TK_Wrk_EqpAps group by wo_code) H on A.wo_code=H.wo_code
                            left join TUom U on C.uom_code=U.code
                             left join TOrganization M on A.wkshp_code=M.org_code
                            where    E.isbott = 'Y' and A.status='NEW' and A.isaps='Y'";
                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 List<AdvancedSchedulingDevice> OnclickAdvancedSchedulingDevice(string wocode, string wkshpcode, string partcode, string startdate, string enddate, ref ToMessage mes)
        {
            string sql = "", sql0 = "";
            var dynamicParams = new DynamicParameters();
            List<AdvancedSchedulingDevice> list = new List<AdvancedSchedulingDevice>();
            DataTable dt, dt1;
            DateTime beginDate = Convert.ToDateTime(startdate);
            DateTime endDate = DateTime.Parse(enddate);
            try
            {
                if (beginDate > endDate)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "要求交付时间不能小于当前系统时间!";
                    mes.data = null;
                    return list;
                }
                bool IsCap = false;    //是否设置产能
                //通过工单查找工艺路线对应关键工序所关联的设备是否可用
                sql = @"select distinct C.eqp_code ,D.Enable  from TK_Wrk_Man A
                       left join TFlw_Rout K on A.route_code=K.code
                       left join TFlw_Rtdt B on K.code=B.rout_code and B.first_choke='Y'
                       left join TFlw_Rteqp C on B.step_code= C.step_code
                       left join TEqpInfo D on C.eqp_code=D.code
                       where A.wo_code=@wocode and A.materiel_code=@partcode";
                dynamicParams.Add("@wocode", wocode);
                dynamicParams.Add("@partcode", partcode);
                var dt_0 = DapperHelper.selectdata(sql, dynamicParams);
                if (dt_0.Rows.Count > 0)
                {
                    int cout = dt_0.Rows.Count;
                    int num = 0;
                    for (int m = 0; m < dt_0.Rows.Count; m++)
                    {
                        if (dt_0.Rows[m]["Enable"].ToString() == "N")
                        {
                            num = num + 1;
                        }
                    }
                    if (num == cout)
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "设备不可用!";
                        mes.data = null;
                        return list;
                    }
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "工艺路线未关联设备!";
                    mes.data = null;
                    return list;
                }
                //通过工单查找工艺路线对应关键工序所关联的设备所属车间
                sql0 = @"select distinct D.wksp_code  from TK_Wrk_Man A
                         left join TFlw_Rout K on A.route_code=K.code
                         left join TFlw_Rtdt B on K.code=B.rout_code and B.first_choke='Y'
                         left join TFlw_Rteqp C on B.step_code= C.step_code
                         left join TEqpInfo D on C.eqp_code=D.code
                         where A.wo_code=@wocode and A.materiel_code=@partcode ";
                dynamicParams.Add("@wocode", wocode);
                dynamicParams.Add("@partcode", partcode);
                var dt0 = DapperHelper.selectdata(sql0, dynamicParams);
                if (dt0.Rows.Count > 0)
                {
                    string sy = "0";
                    for (int i = 0; i < dt0.Rows.Count; i++)
                    {
                        if (dt0.Rows[i]["WKSHOP"].ToString() == wkshpcode)  //工单创建车间是否等于排产设备 车间
                        {
                            sy = "1";
                            break;
                        }
                        else
                        {
                            sy = "0";
                        }
                    }
                    if (sy == "0")
                    {
                        mes.code = "300";
                        mes.count = 0;
                        mes.Message = "排产设备车间与工单创建的车间不同!";
                        mes.data = null;
                    }
                    else
                    {
                        List<APSList> listData = SchedulingMethod.SchedulingMethodTF(wocode, wkshpcode, partcode);
                        for (DateTime date = beginDate; date <= endDate; date = date.AddDays(1))
                        {
                            AdvancedSchedulingDevice tbj = new AdvancedSchedulingDevice();
                            tbj.YearDate = date.ToString("yyyy-MM-dd");
                            tbj.children = new List<AdvancedSchedulingDeviceCont>();
                            for (int j = 0; j < listData.Count; j++)
                            {
                                if (listData[j].AdvaDevicCropMob.ToString() == "0" || listData[j].AdvaDevicRhythm.ToString() == "")
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "排程设备" + listData[j].eqp_id.ToString() + "稼动率不能为0或为空!";
                                    mes.data = null;
                                    return list;
                                }
                                if (listData[j].AdvaDevicRhythm.ToString() == "0" || listData[j].AdvaDevicRhythm.ToString() == "")
                                {
                                    mes.code = "300";
                                    mes.count = 0;
                                    mes.Message = "排程设备" + listData[j].eqp_id.ToString() + "未设置节拍!";
                                    mes.data = null;
                                    return list;
                                }
                                string sql1 = @"select wktme1_start,wktme2_start,wktme3_start,wktme4_start,wktme5_start,G.name
                                              from  TWkm_capac_plan  E
                                                left join TWkm_capac_plan_sub F on E.id=F.m_id
                                                left join TBas_wkshift_info G on F.wkshift_code=G.code
                                                where E.wkshop='CJ001'and E.eqp_typecode='SBLX001'  and E.ClassType='D'
                                              and CONVERT(varchar(100), F.wkdate, 23)='2022-10-11' and E.enable='Y'";
                                dynamicParams.Add("@wkshop", wkshpcode);
                                dynamicParams.Add("@eqp_typecode", listData[j].Style.ToString());
                                dynamicParams.Add("@classtype", listData[j].ClassType.ToString());
                                dynamicParams.Add("@wkdate", date.ToString("yyyy-MM-dd"));
                                dt1 = DapperHelper.selectdata(sql1, dynamicParams);
                                AdvancedSchedulingDeviceCont tbjson = new AdvancedSchedulingDeviceCont();
                                tbjson.AdvaDevicNumber = listData[j].eqp_id.ToString();
                                tbjson.AdvaDevicName = listData[j].name.ToString();
                                tbjson.AdvaDevicCropMob = listData[j].AdvaDevicCropMob.ToString();  //稼动率
                                tbjson.AdvaDevicRhythm = listData[j].AdvaDevicRhythm.ToString();    //生产节拍
                                if (dt1.Rows.Count > 0)
                                {
                                    tbjson.OneStartDate = dt1.Rows[0]["wktme1_start"].ToString();
                                    tbjson.TwoStartDate = dt1.Rows[0]["wktme2_start"].ToString();
                                    tbjson.ThreeStartDate = dt1.Rows[0]["wktme3_start"].ToString();
                                    tbjson.FourStartDate = dt1.Rows[0]["wktme4_start"].ToString();
                                    tbjson.FiveStartDate = dt1.Rows[0]["wktme5_start"].ToString();
                                    tbj.children.Add(tbjson);
                                    IsCap = true;
                                }
                                else
                                {
                                    tbjson.OneStartDate = "";
                                    tbjson.TwoStartDate = "";
                                    tbjson.ThreeStartDate = "";
                                    tbjson.FourStartDate = "";
                                    tbjson.FiveStartDate = "";
                                    tbj.children.Add(tbjson);
                                }
                            }
                            list.Add(tbj);
                        }
                        if (list.Select(p => p.children).ToList().Count > 0)
                        {
                            int one = list.Where(t => t.children.Select(s => s.OneStartDate).Any(x => x != "")).ToList().Count;
                            int two = list.Where(t => t.children.Select(s => s.TwoStartDate).Any(x => x != "")).ToList().Count;
                            int three = list.Where(t => t.children.Select(s => s.ThreeStartDate).Any(x => x != "")).ToList().Count;
                            int four = list.Where(t => t.children.Select(s => s.FourStartDate).Any(x => x != "")).ToList().Count;
                            int five = list.Where(t => t.children.Select(s => s.FiveStartDate).Any(x => x != "")).ToList().Count;
                            if (one <= 0 && two <= 0 && three <= 0 && four <= 0 && five <= 0)
                            {
                                mes.code = "300";
                                mes.count = 0;
                                mes.Message = "排程设备未设置产能!";
                                mes.data = null;
                            }
                        }
                    }
                }
                else
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "设备没有关联车间!";
                    mes.data = null;
                }
                return list;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return list;
        }
        #endregion
        #region[设备已排程信息]
        public static DataTable AlreadyScheduling(string wocode, string wkshpcode, string partcode, string botproccode, string startdate, string enddate)
        {
            var dynamicParams = new DynamicParameters();
            try
            {
                List<APSList> listData = SchedulingMethod.SchedulingMethodTF(wocode, wkshpcode, partcode);
                string[] empIds = listData.Select(a => a.eqp_id).ToArray();
                string str = string.Join(",", empIds);
                string s1 = string.Format("'{0}'", str.Replace(",", "','"));
                string sql = @"select B.wo_code,  B.eqp_code,B.time_start,B.time_end, 'S' status , B.alloc_qty,D.partname as part_name
                              from TK_Wrk_EqpAps B
                               left join TK_Wrk_Man C on B.wo_code=C.wo_code
                               left join  TMateriel_Info D on C.materiel_code=D.partcode
                               where  B.eqp_code in(@s1)
                              and convert(varchar(100),B.Time_Start,21)>=@startdate and convert(varchar(100),B.Time_End,21)<=@enddate order by time_end";
                dynamicParams.Add("@s1", s1);
                dynamicParams.Add("@startdate", startdate + " 00:00:00");
                dynamicParams.Add("@enddate", enddate + " 23:59:59");
                var dt_0 = DapperHelper.selectdata(sql, dynamicParams);
                if (dt == null || dt.Rows.Count == 0)
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return dt;
        }
        #endregion
        #region[排程数据提交]
        public static ToMessage SubmitAlreadyScheduling(string username, string wocode, string botprocecode, List<AlreadyScheduling> objs)
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                string maxTime = objs.Max(t => Convert.ToDateTime(t.AlreEndDate).ToString("yyyy-MM-dd HH:mm"));  //最大值
                string minTime = objs.Min(t => Convert.ToDateTime(t.AlreEndDate).ToString("yyyy-MM-dd HH:mm"));  //最小值
                sql = @"select
                        A.id, A.status,
                        '0' BottFrointv,  convert(varchar(100),B.plan_enddate-0,21) Plan_end ,
                        convert(varchar(100),B.plan_startdate+0,21) plan_start
                        from TK_Wrk_Step A
                        left join TK_Wrk_Man B on A.wo_code=B.wo_code
                        where A.wo_code=@wocode and A.step_code=@botprocecode and A.isbott='Y'";
                dynamicParams.Add("@wocode", wocode);
                dynamicParams.Add("@botprocecode", botprocecode);
                var dt = DapperHelper.selectdata(sql, dynamicParams);
                string ID = dt.Rows[0]["ID"].ToString();     // mes_tk_wrk_step 表 瓶径工序行ID
                string status = dt.Rows[0]["STATUS"].ToString();
                Decimal nm = 0;                                                     //瓶径工序的前置天数
                Decimal nn = Decimal.Parse(dt.Rows[0]["BottFrointv"].ToString());   //瓶径工序的后置天数
                if (status != "NEW" && status != "SCHED")   //工序任务的状态已经派发(审核)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "当前排程任务已经派发,提交取消!";
                    mes.data = null;
                    return mes;
                }
                if (status == "SCHED")   //工序任务的状态已经排程
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "当前排程任务已经排程,提交取消!";
                    mes.data = null;
                    return mes;
                }
                list.Clear();
                //按工单删除设备任务表(日任务表)
                sql = @"delete TK_Wrk_EqpAps  where wo_code=@wocode";
                list.Add(new { str = sql, parm = new { wocode = wocode } });
                //按工单删除设备任务表(汇总表)
                sql = @"delete TK_Wrk_EqpApsSum  where wo_code=@wocode";
                list.Add(new { str = sql, parm = new { wocode = wocode } });
                //按工单删除设备任务表(汇总表)物料表
                sql = @"delete TK_Wrk_EqpSum_Allo  where wo_code=@wocode";
                list.Add(new { str = sql, parm = new { wocode = wocode } });
                float n = 0;  //累计排产总数
                for (int i = 0; i < objs.Count; i++)        //循环添加每个设备的机台任务
                {
                    sql = @"insert into TK_Wrk_EqpAps (wo_code,step_taid,eqp_code,time_start,time_end,alloc_qty,status)
                            values(@wo_code,@step_taid,@eqp_code,@time_start,@time_end,@alloc_qty,@status)";
                    list.Add(new { str = sql, parm = new { wo_code = wocode, step_taid = ID, eqp_code = objs[i].AlreDevicNumber, time_start = objs[i].AlreStartDate, time_end = objs[i].AlreEndDate, alloc_qty = objs[i].AlreQty, status = "NEW" } });
                    n = n + float.Parse(objs[i].AlreQty.ToString());
                }
                bool aa = DapperHelper.DoTransaction(list); //提交设备任务
                if (!aa)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "先预排,再点击提交!";
                    mes.data = null;
                    return mes;
                }
                list.Clear();
                //生成设备任务汇总表  (根据设备日任务表)
                sql = "select distinct eqp_code from TK_Wrk_EqpAps where wo_code=@wocode";
                dynamicParams.Add("@wocode", wocode);
                var dt1 = DapperHelper.selectdata(sql, dynamicParams);
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    sql = @"insert into  TK_Wrk_EqpApsSum (wo_code,eqp_code,step_taid,p_date, t_date, qty,status)
                           select  min(wo_code),min(eqp_code),min(step_taid),min(time_start),max(time_end),sum(Alloc_Qty),'NEW' from TK_Wrk_EqpAps
                           where wo_code=@wocode and eqp_code=''";
                    list.Add(new { str = sql, parm = new { wocode = wocode, eqp_code = dt1.Rows[i]["EQP_CODE"].ToString() } });
                }
                bool aa1 = DapperHelper.DoTransaction(list); //提交设备任务
                if (!aa1)
                {
                    mes.code = "300";
                    mes.count = 0;
                    mes.Message = "生成设备任务汇总表出错,排产失败!";
                    mes.data = null;
                    return mes;
                }
                list.Clear();
                //写入设备任务(汇总表)用料  计划数量*子件基本用量*(1+损耗率)/母件基本用量
                sql = @"insert into TK_Wrk_EqpSum_Allo(m_id, seq, invcode, qty,wo_code,pn_type)
                        select A.id M_id, B.seq,B.materiel_code,(round(A.qty,2)*BE.Base_Quantity*(1+BE.LOSS_QUANTITY/100))/BM.quantity  qty,A.wo_code,B.materieltype
                        from TK_Wrk_EqpApsSum A
                        left join TK_Wrk_Allo B on A.Wo_Code= B.Wo_Code
                        left join TBom_Deta BE  ON B.bom_id=BE.m_id and B.materiel_code=BE.smateriel_code
                        left join  TBom_Main BM on BE.m_Id=BM.id  where A.wo_code=@wocode";
                list.Add(new { str = sql, parm = new { wocode = wocode } });
                //更新 工序任务单的【瓶径工序】 排产预开工日期、排产预完工日期、状态:NEW===>SCHED 、已排产数量
                sql = @"update TK_Wrk_Step   set plan_startdate =convert(varchar(100),@plan_startdate,21),  plan_enddate =convert(varchar(100),@plan_enddate,21),  status = 'SCHED', sched_qty =@sched_qty where id =@id";
                list.Add(new { str = sql, parm = new { plan_startdate = minTime, plan_enddate = maxTime, sched_qty = n, id = ID } });
                //工单工序的“计划开机日期 = 瓶径工序的预开工日期 - 瓶径工序的前置日期)    主工单:计划完工日期 = 瓶径工序的预完工日期 + 瓶径工序的后置日期
                sql = @"update TK_Wrk_Step   set plan_startdate =convert(varchar(100),@plan_startdate,21),  plan_enddate =convert(varchar(100),@plan_enddate,21),  status = 'SCHED', sched_qty =@sched_qty where wo_code =@wocode and isbott='N'";
                list.Add(new
                {
                    str = sql,
                    parm = new
                    {
                        plan_startdate = Convert.ToDateTime(minTime).AddDays(Convert.ToDouble(-nm)).ToString("yyyy-MM-dd"),
                        plan_enddate = Convert.ToDateTime(maxTime).AddDays(Convert.ToDouble(nn)).ToString("yyyy-MM-dd"),
                        sched_qty = n,
                        wocode = wocode
                    }
                });
                //主工单的“计划开机日期 = 瓶径工序的预开工日期 - 瓶径工序的前置日期)    主工单:计划完工日期 = 瓶径工序的预完工日期 + 瓶径工序的后置日期
                sql = @"update mes_tk_wrk_man set status='SCHED',plan_startdate =convert(varchar(100),@plan_startdate,21),  plan_enddate =convert(varchar(100),@plan_enddate,21), exchag='Y',allocfag='N' where wo_code =@wocode";
                list.Add(new
                {
                    str = sql,
                    parm = new
                    {
                        plan_startdate = Convert.ToDateTime(minTime).AddDays(Convert.ToDouble(-nm)).ToString("yyyy-MM-dd"),
                        plan_enddate = Convert.ToDateTime(maxTime).AddDays(Convert.ToDouble(nn)).ToString("yyyy-MM-dd"),
                        sched_qty = n,
                        wocode = wocode
                    }
                });
                bool aa2 = DapperHelper.DoTransaction(list); //提交设备任务
                if (aa2)
                {
                    mes.code = "200";
                    mes.count = 0;
                    mes.Message = "提交排程成功!";
                }
                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
    }
}