VueWebCoreApi/DLL/DAL/MouldManagerDAL.cs
@@ -66,10 +66,6 @@
                    dynamicParams.Add("@opendate", opendate + " 00:00:00");
                    dynamicParams.Add("@closedate", closedate + " 23:59:59");
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.status,A.usestatus,A.code,A.name,A.spec,A.warehousecode,S.name as warehousename,
@@ -234,6 +230,76 @@
                        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 MoldResumeSearch(string mouldcode, string opendate, string closedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (opendate != "" && opendate != null)
                {
                    search += "and AA.operdate between @opendate and @closedate ";
                    dynamicParams.Add("@opendate", opendate + " 00:00:00");
                    dynamicParams.Add("@closedate", closedate + " 23:59:59");
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select *  from (
                            select '点检' as opertype,chk_user as operuser,chk_date as operdate,chk_result as operresult
                            from TMouldchk_Proc_Main where mould_code='001'
                            union all
                            select '保养' as opertype,maint_user as operuser,maint_date as operdate,maint_result as operresult
                            from TMouldmaint_Proc_Main where mould_code='001'
                            union all
                            select '待维修' as opertype,request_person as operuser,request_date as operdate,'维修申请' as operresult
                            from TMould_RepairRequest where mould_code='001'
                            union all
                            select '已维修' as opertype,repair_person as operuser,repair_date as operdate,'维修完成' as operresult
                            from TMould_RepairRequest A
                            inner join TMould_Repair B on A.docu_code=B.source_wo
                            where A.mould_code='001' and B.repair_person<>''
                            union all
                            select '已验证' as opertype,verify_person as operuser,verify_date as operdate,B.verify_result as operresult
                            from TMould_RepairRequest A
                            inner join TMould_Repair B on A.docu_code=B.source_wo
                            where A.mould_code='001' and B.verify_person<>''
                            union all
                            select '已上机' as opertype,lm_user as operuser,lm_date as operdate,eqp_code as operresult
                            from TMould_UpDownReord  where mould_code='001' and type='UP'
                            union all
                            select '已下机' as opertype,lm_user as operuser,lm_date as operdate,eqp_code as operresult
                            from TMould_UpDownReord  where mould_code='001' and type='DOWN'
                            union all
                            select '已入库' as opertype,lm_user as operuser,lm_date as operdate,warehouse_code as operresult
                            from TMould_InOutReord  where mould_code='001' and type='IN'
                            union all
                            select '已出库' as opertype,lm_user as operuser,lm_date as operdate,warehouse_code as operresult
                            from TMould_InOutReord  where mould_code='001' and type='OUT'
                            union all
                            select '已外借' as opertype,lm_user as operuser,lm_date as operdate,description as operresult
                            from TMould_LendOutReord  where mould_code='001' and type='OUT'
                            union all
                            select '已归还' as opertype,lm_user as operuser,lm_date as operdate,description as operresult
                            from TMould_LendOutReord  where mould_code='001' and type='IN'
                            ) as AA where 1=1 "+search+"  order by AA.operdate desc ";
                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)
            {
@@ -2132,7 +2198,8 @@
                    {
                        IFormFile file = files[i];
                        string imgName = "SQ" + DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString();
                        string filePath = "wwwroot/MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名
                        string filePath = "wwwroot/MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名(存文件地址)
                        string filePath1 = "MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名(存数据表地址)
                        // 生成文件名
                        //var fileName = "SQ" + DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString() + Path.GetExtension(files[i].FileName);
@@ -2155,7 +2222,7 @@
                            {
                                source_wo = sqwo,
                                wo_type = "REPA",
                                img1url = filePath
                                img1url = filePath1
                            }
                        });
                    }
@@ -2287,8 +2354,8 @@
                    {
                        IFormFile file = files[i];
                        string imgName = "WX" + DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString();
                        string filePath = "wwwroot/MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名
                        string filePath = "wwwroot/MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名(存文件地址)
                        string filePath1 = "MouldRecordImage/" + imgName + file.FileName;     //通过此对象获取文件名(存数据表地址)
                        // 生成文件名
                        //var fileName = "WX" + DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString() + Path.GetExtension(files[i].FileName);
@@ -2310,7 +2377,7 @@
                            {
                                source_wo = wxwo,
                                wo_type = "COMP",
                                img1url = filePath
                                img1url = filePath1
                            }
                        });
                    }
@@ -2381,7 +2448,7 @@
            var dynamicParams = new DynamicParameters();
            try
            {
                if (mouldcode == "" || mouldcode == null)
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and B.code=@mouldcode ";
                    dynamicParams.Add("@mouldcode", mouldcode);
@@ -2430,7 +2497,7 @@
                //根据设模具编码获取维修详情
                sql = @"select repair_code,failure_descript,is_shutdown,repair_content,repair_part   
                        from TMould_Repair 
                        where repair_code=@repair_code  and mould_code=mouldcode";
                        where repair_code=@repair_code  and mould_code=@mouldcode";
                dynamicParams.Add("@repair_code", repair_code);
                dynamicParams.Add("@mouldcode", mouldcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -2629,6 +2696,33 @@
        }
        #endregion
        #region[模具上机,选择未上模设备]
        public static ToMessage MouldEqpPermissions()
        {
            var sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                sql = @"select code,name   from TEqpInfo where  enable='Y' and code not in
                        (
                          select distinct eqp_code   from TMould_UpDownReord where is_up='Y'
                        )";
                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[模具上机提交]
        public static ToMessage MouldUpSave(string mouldcode, string eqp_code, string description, User us)
        {
@@ -2767,7 +2861,7 @@
                list.Clear();
                //写入上下机机记录表(下机操作)
                sql = @"insert into  TMould_UpDownReord(mould_code,type,usecount_life,eqp_code,description,is_up,lm_user,lm_date) 
                        values(@mould_code,@type,@eqp_code,@description,@is_up,@lm_user,@lm_date)";
                        values(@mould_code,@type,@usecount_life,@eqp_code,@description,@is_up,@lm_user,@lm_date)";
                list.Add(new
                {
                    str = sql,
@@ -3342,5 +3436,686 @@
            return mes;
        }
        #endregion
        #region[模具点检记录查询]
        public static ToMessage MouldCheckTakeSearch(string mouldcode, string mouldname, string mouldspec, string stanedcode, string stanedname, string checkuser, string checkopendate, string checkclosedate,string checkrequest, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (stanedcode != "" && stanedcode != null)
                {
                    search += "and M.code like '%'+@stanedcode+'%' ";
                    dynamicParams.Add("@stanedcode", stanedcode);
                }
                if (stanedname != "" && stanedname != null)
                {
                    search += "and M.name like '%'+@stanedname+'%' ";
                    dynamicParams.Add("@stanedname", stanedname);
                }
                if (checkuser != "" && checkuser != null)
                {
                    search += "and U.username like '%'+@checkuser+'%' ";
                    dynamicParams.Add("@checkuser", checkuser);
                }
                if (checkrequest != "" && checkrequest != null)
                {
                    search += "and A.chk_result=@checkrequest ";
                    dynamicParams.Add("@checkrequest", checkrequest);
                }
                if (checkopendate != "" && checkopendate != null)
                {
                    search += "and A.chk_date between @checkopendate and @checkclosedate ";
                    dynamicParams.Add("@checkopendate", checkopendate + " 00:00:00");
                    dynamicParams.Add("@checkclosedate", checkclosedate + " 23:59:59");
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.id,A.djwo,A.mould_code,E.name as mould_name,E.spec as mould_spec,M.code as stanedcode,M.name as stanedname,
                            U.username as chk_user,A.chk_result,A.chk_date
                            from TMouldchk_Proc_Main A
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TMouldchk_Main M on A.mouldchkmain_code=M.code
                            left join TUser U on A.chk_user=U.usercode
                            where 1=1 " + 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 MouldCheckSubTakeSearch(string id)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                sql = @"select A.seq,T.code as itemcode,T.name as itemname,A.result,A.chk_value,A.remark
                        from TMouldchk_Proc_Deta A
                        left join TMouldchk_Item T on A.mouldchkdeta_code=T.code
                        where A.m_id=@id";
                dynamicParams.Add("@id", id);
                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[模具点检记录导出]
        public static ToMessage MouldCheckTakeOutExcel(string mouldcode, string mouldname, string mouldspec, string stanedcode, string stanedname, string checkuser, string checkopendate, string checkclosedate,string checkrequest)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (stanedcode != "" && stanedcode != null)
                {
                    search += "and M.code like '%'+@stanedcode+'%' ";
                    dynamicParams.Add("@stanedcode", stanedcode);
                }
                if (stanedname != "" && stanedname != null)
                {
                    search += "and M.name like '%'+@stanedname+'%' ";
                    dynamicParams.Add("@stanedname", stanedname);
                }
                if (checkuser != "" && checkuser != null)
                {
                    search += "and U.username like '%'+@checkuser+'%' ";
                    dynamicParams.Add("@checkuser", checkuser);
                }
                if (checkrequest != "" && checkrequest != null)
                {
                    search += "and A.chk_result=@checkrequest ";
                    dynamicParams.Add("@checkrequest", checkrequest);
                }
                if (checkopendate != "" && checkopendate != null)
                {
                    search += "and A.chk_date between @checkopendate and @checkclosedate ";
                    dynamicParams.Add("@checkopendate", checkopendate + " 00:00:00");
                    dynamicParams.Add("@checkclosedate", checkclosedate + " 23:59:59");
                }
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN A.djwo
                            ELSE ''END AS '点检单号',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN A.mould_code
                            ELSE ''END AS '模具编号',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN E.name
                            ELSE ''END AS '模具名称',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN E.spec
                            ELSE ''END AS '规格型号',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN A.mouldchkmain_code
                            ELSE ''END AS '点检标准编码',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN M.name
                            ELSE ''END AS '点检标准名称',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN U.username
                            ELSE ''END AS '检验人员',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN A.chk_result
                            ELSE ''END AS '检验结果',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.djwo ORDER BY B.mouldchkdeta_code) = 1 THEN A.chk_date
                            END AS '检验时间',
                            B.seq as '点检部位序号',H.code '点检部位编码',H.name '点检部位名称',B.result '点检结果',B.chk_value '数值',B.remark '备注'
                            from TMouldchk_Proc_Main A
                            left join TMouldchk_Proc_Deta B on A.id=B.m_id
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TMouldchk_Main M on A.mouldchkmain_code=M.code
                            left join TMouldchk_Item H on B.mouldchkdeta_code=H.code
                            left join TUser U on A.chk_user=U.usercode
                            where 1=1 " + search;
                DataTable data = DapperHelper.selectdata(sql, dynamicParams);
                data.TableName = "Table"; //设置DataTable的名称
                string msg = DownLoad.DataTableToExcel(data, "模具点检记录报表");
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = msg;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[模具保养记录查询]
        public static ToMessage MouldRepairTakeSearch(string mouldcode, string mouldname, string mouldspec, string stanedcode, string stanedname, string repairuser, string repairopendate, string repairclosedate, string repairresult, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (stanedcode != "" && stanedcode != null)
                {
                    search += "and M.code like '%'+@stanedcode+'%' ";
                    dynamicParams.Add("@stanedcode", stanedcode);
                }
                if (stanedname != "" && stanedname != null)
                {
                    search += "and M.name like '%'+@stanedname+'%' ";
                    dynamicParams.Add("@stanedname", stanedname);
                }
                if (repairuser != "" && repairuser != null)
                {
                    search += "and U.username like '%'+@repairuser+'%' ";
                    dynamicParams.Add("@repairuser", repairuser);
                }
                if (repairopendate != "" && repairopendate != null)
                {
                    search += "and A.maint_date between @repairopendate and @repairclosedate ";
                    dynamicParams.Add("@repairopendate", repairopendate + " 00:00:00");
                    dynamicParams.Add("@repairclosedate", repairclosedate + " 23:59:59");
                }
                if (repairresult != "" && repairresult != null)
                {
                    search += "and A.maint_result=@repairresult ";
                    dynamicParams.Add("@repairresult", repairresult);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.bywo,A.mould_code,E.name as mould_name,E.spec as mould_spec,M.code as stanedcode,M.name as stanedname,
                            U.username as maint_user,A.maint_result,A.maint_date
                            from TMouldmaint_Proc_Main A
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TMouldmai_Main M on A.mouldmaint_code=M.code
                            left join TUser U on A.maint_user=U.usercode
                            where 1=1 " + 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 MouldRepairSubTakeSearch(string id)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                sql = @"select A.seq,T.code as itemcode,T.name as itemname,A.result,A.maint_value,A.remark
                        from TMouldmaint_Proc_Deta A
                        left join TMouldmai_Item T on A.mouldmaideta_code=T.code
                        where A.m_id=@id";
                dynamicParams.Add("@id", id);
                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[模具保养记录导出]
        public static ToMessage MouldRepairTakeOutExcel(string mouldcode, string mouldname, string mouldspec, string stanedcode, string stanedname, string repairuser, string repairopendate, string repairclosedate, string repairresult)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (stanedcode != "" && stanedcode != null)
                {
                    search += "and M.code like '%'+@stanedcode+'%' ";
                    dynamicParams.Add("@stanedcode", stanedcode);
                }
                if (stanedname != "" && stanedname != null)
                {
                    search += "and M.name like '%'+@stanedname+'%' ";
                    dynamicParams.Add("@stanedname", stanedname);
                }
                if (repairuser != "" && repairuser != null)
                {
                    search += "and U.username like '%'+@repairuser+'%' ";
                    dynamicParams.Add("@repairuser", repairuser);
                }
                if (repairopendate != "" && repairopendate != null)
                {
                    search += "and A.maint_date between @repairopendate and @repairclosedate ";
                    dynamicParams.Add("@repairopendate", repairopendate + " 00:00:00");
                    dynamicParams.Add("@repairclosedate", repairclosedate + " 23:59:59");
                }
                if (repairresult != "" && repairresult != null)
                {
                    search += "and A.maint_result=@repairresult ";
                    dynamicParams.Add("@repairresult", repairresult);
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN A.bywo
                            ELSE ''END AS '保养单号',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN A.mould_code
                            ELSE ''END AS '模具编码',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN E.name
                            ELSE ''END AS '模具名称',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN E.spec
                            ELSE ''END AS '规格型号',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN A.mouldmaint_code
                            ELSE ''END AS '保养标准编码',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN M.name
                            ELSE ''END AS '保养标准名称',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN U.username
                            ELSE ''END AS '保养人员',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.bywo ORDER BY B.mouldmaideta_code) = 1 THEN A.maint_result
                            ELSE ''END AS '保养结果',
                            CASE WHEN
                            ROW_NUMBER() OVER (PARTITION BY A.maint_date ORDER BY B.mouldmaideta_code) = 1 THEN A.maint_date
                            END AS '保养时间',
                            B.seq as '保养部位序号',H.code '保养部位编码',H.name '保养部位名称',B.result '保养结果',B.maint_value '数值',B.remark '备注'
                            from TMouldmaint_Proc_Main A
                            left join TMouldmaint_Proc_Deta B on A.id=B.m_id
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TMouldmai_Main M on A.mouldmaint_code=M.code
                            left join TMouldmai_Item H on B.mouldmaideta_code=H.code
                            left join TUser U on A.maint_user=U.usercode
                            where 1=1 " + search;
                DataTable data = DapperHelper.selectdata(sql, dynamicParams);
                data.TableName = "Table"; //设置DataTable的名称
                string msg = DownLoad.DataTableToExcel(data, "模具保养记录报表");
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = msg;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[模具维修记录查询]
        public static ToMessage MouldUpdateSearch(string mouldcode, string mouldname, string mouldspec, string reportuser, string repairuser, string vrifcatuser, string reportopendate, string reportclosedate, string repairopendate, string repairclosedate, string vrifcatopendate, string vrifcatclosedate, int startNum, int endNum, string prop, string order)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (reportuser != "" && reportuser != null)
                {
                    search += "and U.username like '%'+@reportuser+'%' ";
                    dynamicParams.Add("@reportuser", reportuser);
                }
                if (repairuser != "" && repairuser != null)
                {
                    search += "and R.username like '%'+@repairuser+'%' ";
                    dynamicParams.Add("@repairuser", repairuser);
                }
                if (vrifcatuser != "" && vrifcatuser != null)
                {
                    search += "and V.username like '%'+@vrifcatuser+'%' ";
                    dynamicParams.Add("@vrifcatuser", vrifcatuser);
                }
                if (reportopendate != "" && reportopendate != null)
                {
                    search += "and B.request_date between @reportopendate and @reportclosedate ";
                    dynamicParams.Add("@reportopendate", reportopendate + " 00:00:00");
                    dynamicParams.Add("@reportclosedate", reportclosedate + " 23:59:59");
                }
                if (repairopendate != "" && repairopendate != null)
                {
                    search += "and A.repair_date between @repairopendate and @repairclosedate ";
                    dynamicParams.Add("@repairopendate", repairopendate + " 00:00:00");
                    dynamicParams.Add("@repairclosedate", repairclosedate + " 23:59:59");
                }
                if (vrifcatopendate != "" && vrifcatopendate != null)
                {
                    search += "and A.verify_date between @vrifcatopendate and @vrifcatclosedate ";
                    dynamicParams.Add("@vrifcatopendate", vrifcatopendate + " 00:00:00");
                    dynamicParams.Add("@vrifcatclosedate", vrifcatclosedate + " 23:59:59");
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.repair_code,A.mould_code,E.name as mould_name,E.spec as mould_spec,U.username as request_person,B.request_date,
                            R.username as repair_person,A.repair_date,CAST(datediff(minute, B.request_date,A.repair_date)/60.0 AS decimal(9,1)) as cycleDate,
                            V.username as verify_person,A.verify_date,(case when A.verify_result='OK' then '通过' when  A.verify_result='NG' then '不通过' end)as verify_result
                            from TMould_Repair A
                            left join TMould_RepairRequest B on A.source_wo=B.docu_code
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TUser U on B.request_person=U.usercode
                            left join TUser R on A.repair_person=R.usercode
                            left join TUser V on A.verify_person=V.usercode
                            where 1=1 " + 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 MouldUpdateSubSearch(string repair_code)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            Dictionary<object, object> Dict = new Dictionary<object, object>();
            try
            {
                //获取模具报修申请数据
                sql = @"select B.docu_code,
                       (
                       case when B.source='A' then '模具点检'
                       when B.source='B' then '模具保养'
                       when B.source='C' then '手工'
                       end
                       ) as source,B.failure_descript
                       from TMould_Repair A
                       left join TMould_RepairRequest B on A.source_wo=B.docu_code
                       where A.repair_code=@repair_code";
                dynamicParams.Add("@repair_code", repair_code);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                DeviceReport report = new DeviceReport();
                report.faultsource = data.Rows[0]["source"].ToString();
                report.faultdescr = data.Rows[0]["failure_descript"].ToString();
                //获取模具报修申请图片数据
                sql = @"select M.img1url from TMould_Repair A
                        left join TMould_RepairRequest B on A.source_wo=B.docu_code
                        left join TMould_RepairImage M on B.docu_code=M.source_wo
                        where A.repair_code=@repair_code and M.wo_type='REPA'";
                dynamicParams.Add("@repair_code", repair_code);
                var data0 = DapperHelper.selectdata(sql, dynamicParams);
                report.faultimage = data0;
                Dict.Add("data1", report);
                //获取模具维修数据
                sql = @"select A.failure_descript,A.is_shutdown,A.repair_content,A.repair_part
                        from TMould_Repair A
                        left join TMould_RepairRequest B on A.source_wo=B.docu_code
                        where A.repair_code=@repair_code";
                dynamicParams.Add("@repair_code", repair_code);
                var data1 = DapperHelper.selectdata(sql, dynamicParams);
                DeviceRepair repair = new DeviceRepair();
                repair.faultdescr = data1.Rows[0]["failure_descript"].ToString();
                repair.isstoprepair = data1.Rows[0]["is_shutdown"].ToString();
                repair.repaircontent = data1.Rows[0]["repair_content"].ToString();
                repair.repairpart = data1.Rows[0]["repair_part"].ToString();
                //获取模具维修图片数据
                sql = @"select M.img1url from TMould_Repair A
                        left join TMould_RepairImage M on A.repair_code=M.source_wo
                        where A.repair_code=@repair_code and M.wo_type='COMP'";
                dynamicParams.Add("@repair_code", repair_code);
                var data3 = DapperHelper.selectdata(sql, dynamicParams);
                repair.repairimage = data3;
                Dict.Add("data2", repair);
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.data = Dict;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
        #region[模具维修记录导出]
        public static ToMessage MouldUpdateSearch(string mouldcode, string mouldname, string mouldspec, string reportuser, string repairuser, string vrifcatuser, string reportopendate, string reportclosedate, string repairopendate, string repairclosedate, string vrifcatopendate, string vrifcatclosedate)
        {
            var dynamicParams = new DynamicParameters();
            string search = "";
            try
            {
                if (mouldcode != "" && mouldcode != null)
                {
                    search += "and A.mould_code like '%'+@mouldcode+'%' ";
                    dynamicParams.Add("@mouldcode", mouldcode);
                }
                if (mouldname != "" && mouldname != null)
                {
                    search += "and E.name like '%'+@mouldname+'%' ";
                    dynamicParams.Add("@mouldname", mouldname);
                }
                if (mouldspec != "" && mouldspec != null)
                {
                    search += "and E.spec like '%'+@mouldspec+'%' ";
                    dynamicParams.Add("@mouldspec", mouldspec);
                }
                if (reportuser != "" && reportuser != null)
                {
                    search += "and U.username like '%'+@reportuser+'%' ";
                    dynamicParams.Add("@reportuser", reportuser);
                }
                if (repairuser != "" && repairuser != null)
                {
                    search += "and R.username like '%'+@repairuser+'%' ";
                    dynamicParams.Add("@repairuser", repairuser);
                }
                if (vrifcatuser != "" && vrifcatuser != null)
                {
                    search += "and V.username like '%'+@vrifcatuser+'%' ";
                    dynamicParams.Add("@vrifcatuser", vrifcatuser);
                }
                if (reportopendate != "" && reportopendate != null)
                {
                    search += "and B.request_date between @reportopendate and @reportclosedate ";
                    dynamicParams.Add("@reportopendate", reportopendate + " 00:00:00");
                    dynamicParams.Add("@reportclosedate", reportclosedate + " 23:59:59");
                }
                if (repairopendate != "" && repairopendate != null)
                {
                    search += "and A.repair_date between @repairopendate and @repairclosedate ";
                    dynamicParams.Add("@repairopendate", repairopendate + " 00:00:00");
                    dynamicParams.Add("@repairclosedate", repairclosedate + " 23:59:59");
                }
                if (vrifcatopendate != "" && vrifcatopendate != null)
                {
                    search += "and A.verify_date between @vrifcatopendate and @vrifcatclosedate ";
                    dynamicParams.Add("@vrifcatopendate", vrifcatopendate + " 00:00:00");
                    dynamicParams.Add("@vrifcatclosedate", vrifcatclosedate + " 23:59:59");
                }
                if (search == "")
                {
                    search = "and 1=1 ";
                }
                //search = search.Substring(3);//截取索引2后面的字符
                // --------------查询指定数据--------------
                var total = 0; //总条数
                var sql = @"select A.repair_code as '维修单号',A.mould_code as '模具编码',E.name as '模具名称',E.spec as '规格型号',
                            U.username as '报修人员',B.request_date as '报修时间',R.username as '维修人员',A.repair_date as '维修时间',
                            CAST(datediff(minute, B.request_date,A.repair_date)/60.0 AS decimal(9,1)) as '维修时长',
                            V.username as '验证人员',A.verify_date as '验证时间',(case when A.verify_result='OK' then '通过' when  A.verify_result='NG' then '不通过' end) as '验证结果'
                            from TMould_Repair A
                            left join TMould_RepairRequest B on A.source_wo=B.docu_code
                            left join TMouldInfo E on A.mould_code=E.code
                            left join TUser U on B.request_person=U.usercode
                            left join TUser R on A.repair_person=R.usercode
                            left join TUser V on A.verify_person=V.usercode
                            where 1=1 " + search;
                DataTable data = DapperHelper.selectdata(sql, dynamicParams);
                data.TableName = "Table"; //设置DataTable的名称
                string msg = DownLoad.DataTableToExcel(data, "模具维修记录报表");
                mes.code = "200";
                mes.Message = "查询成功!";
                mes.count = total;
                mes.data = msg;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
    }
}