yl
2022-10-25 4f86b3b78b5b638b486b497221a2f1c8fbab3ef6
VueWebApi/DLL/DAL/AppDeviceManageDAL.cs
@@ -466,13 +466,13 @@
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFile file = files[i];
                        string imgName = DateTime.Now.ToString("yyyyMMddhhmmss");
                        string imgName = DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString();
                        string imgPath = "/DeviceImage/image1/" + imgName + file.FileName;     //通过此对象获取文件名
                        string AbsolutePath = System.Web.HttpContext.Current.Server.MapPath(imgPath);
                        file.SaveAs(AbsolutePath); //将上传的东西保存
                        //循环写维修记录对应图片表
                        sql = @"insert into  TEqp_RepairImage(source_wo,wo_type,img1_url)
                                values(@source_wo,@wo_type,@img1_url)";
                        sql = @"insert into  TEqp_RepairImage(source_wo,wo_type,img1url)
                                values(@source_wo,@wo_type,@img1url)";
                        list.Add(new
                        {
                            str = sql,
@@ -480,7 +480,7 @@
                            {
                                source_wo = wxwo,
                                wo_type = "REPA",
                                img1_url = imgPath
                                img1url = imgPath
                            }
                        });
                    }
@@ -538,7 +538,7 @@
        #region[设备维修列表]
        public static ToMessage RepairScanDeviceQrCodeData()
        public static ToMessage RepairScanDeviceQrCodeDataList()
        {
            string sql = "";
            try
@@ -579,7 +579,7 @@
        #endregion
        #region[设备维修提交]
        public static ToMessage RepairScanDeviceSave(string username, string eqpcode, string wkshpcode, string faultdescr, string is_stoprepair, string repaircontent, string replaceparts, HttpFileCollection files)
        public static ToMessage RepairScanDeviceSave(string docu_code, string username, string eqpcode, string wkshpcode, string faultdescr, string is_stoprepair, string repaircontent, string replaceparts, HttpFileCollection files)
        {
            var sql = "";
            string wxwo = "", numvalue = "";
@@ -606,7 +606,7 @@
                    {
                        string imgPath1 = "", imgPath2 = "", AbsolutePath = "";
                        HttpPostedFile file = files[i];
                        string imgName = DateTime.Now.ToString("yyyyMMddhhmmss");
                        string imgName = DateTime.Now.ToString("yyyyMMddhhmmss") + i.ToString();
                        string keyname = files.AllKeys[i].ToString();
                        if (keyname == "files1")
                        {
@@ -621,8 +621,8 @@
                        file.SaveAs(AbsolutePath); //将上传的东西保存
                                                   //循环写维修记录对应图片表
                        sql = @"insert into  TEqp_RepairImage(source_wo,wo_type,img1_url,img2_url)
                                values(@source_wo,@wo_type,@img1_url,@img2_url)";
                        sql = @"insert into  TEqp_RepairImage(source_wo,wo_type,img1url,img2url)
                                values(@source_wo,@wo_type,@img1url,@img2url)";
                        list.Add(new
                        {
                            str = sql,
@@ -630,15 +630,15 @@
                            {
                                source_wo = wxwo,
                                wo_type = "COMP",
                                img1_url = imgPath1,
                                img2_url = imgPath2
                                img1url = imgPath1,
                                img2url = imgPath2
                            }
                        });
                    }
                }
                //写入维修记录表
                sql = @"insert into  TEqp_Repair(repair_code,docu_date,status,wksp_code,eqp_code,repair_person,repair_date,repair_content,repair_part,failure_descript,is_shutdown)
                                values(@repair_code,@docu_date,@status,@wksp_code,@eqp_code,@repair_person,@repair_date,@repair_content,@repair_part,@failure_descript,@is_shutdown)";
                sql = @"insert into  TEqp_Repair(repair_code,docu_date,status,wksp_code,eqp_code,repair_person,repair_date,repair_content,repair_part,failure_descript,is_shutdown,source_wo)
                                values(@repair_code,@docu_date,@status,@wksp_code,@eqp_code,@repair_person,@repair_date,@repair_content,@repair_part,@failure_descript,@is_shutdown,@source_wo)";
                list.Add(new
                {
                    str = sql,
@@ -654,9 +654,13 @@
                        repair_content = repaircontent,
                        repair_part = replaceparts,
                        failure_descript = faultdescr,
                        is_shutdown = is_stoprepair
                        is_shutdown = is_stoprepair,
                        source_wo= docu_code
                    }
                });
                //更新维修申请单状态
                sql = @"update TEqp_RepairRequest set status=@status  where docu_code=@docu_code and wksp_code=@wkshpcode  and eqp_code=@eqpcode";
                list.Add(new { str = sql, parm = new { docu_code = docu_code, wkshpcode = wkshpcode, eqpcode= eqpcode, status= "COMP" } });
                //回写字典表,更新当前流水号
                sql = @"update T_CodeRules set value=@cunm2  where rightcode=@RightCode";
@@ -731,7 +735,7 @@
        #endregion
        #region[维修验证详情信息]
        public static ToMessage RepairVerificationScanDeviceDataSub(string eqpcode, string wkshpcode)
        public static ToMessage RepairVerificationScanDeviceDataSub(string repair_code,string eqpcode, string wkshpcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
@@ -741,7 +745,8 @@
                //根据设备编码\车间编码获取维修详情
                sql = @"select repair_code,failure_descript,is_shutdown,repair_content,repair_part   
                        from TEqp_Repair 
                        where wksp_code=@wkshpcode and eqp_code=@eqpcode";
                        where repair_code=@repair_code and wksp_code=@wkshpcode and eqp_code=@eqpcode";
                dynamicParams.Add("@repair_code", repair_code);
                dynamicParams.Add("@wkshpcode", wkshpcode);
                dynamicParams.Add("@eqpcode", eqpcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -763,7 +768,7 @@
                        dict.Add("repair_part", data.Rows[0]["repair_part"].ToString()); //更换备件
                        //获取更换备件上传图片
                        sql = @"select img1ur2  from TEqp_RepairImage where source_wo=@source_wo and wo_type='COMP'";
                        sql = @"select img2url  from TEqp_RepairImage where source_wo=@source_wo and wo_type='COMP'";
                        dynamicParams.Add("@source_wo", data.Rows[0]["repair_code"].ToString());
                        var data1 = DapperHelper.selectdata(sql, dynamicParams);
                        if (data1.Rows.Count > 0)
@@ -798,9 +803,14 @@
        {
            var sql = "";
            List<object> list = new List<object>();
            var dynamicParams = new DynamicParameters();
            try
            {
                list.Clear();
                //根据设备维修单查找源单(维修申请单)
                sql = @"select source_wo   from TEqp_Repair where repair_code=@repairwo";
                dynamicParams.Add("@repairwo", repairwo);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                //更新设备维修记录验证人员、验证时间、验证结果、验证状态
                sql = @"update TEqp_Repair set status=@status,is_verifi=@is_verifi,verify_result=@verify_result,verify_person=@verify_person,verify_date=@verify_date  
                        where repair_code=@repair_code and wksp_code=@wksp_code and eqp_code=@eqp_code";
@@ -811,14 +821,17 @@
                    {
                        status = "CONFIR",
                        is_verifi = "Y",
                        verify_result=result,
                        verify_person=username,
                        verify_date= DateTime.Now.ToString(),
                        repair_code=repairwo,
                        wksp_code=wkshpcode,
                        eqp_code=eqpcode
                        verify_result = result,
                        verify_person = username,
                        verify_date = DateTime.Now.ToString(),
                        repair_code = repairwo,
                        wksp_code = wkshpcode,
                        eqp_code = eqpcode
                    }
                });
                //更新维修申请单状态
                sql = @"update TEqp_RepairRequest set status=@status  where docu_code=@docu_code and wksp_code=@wkshpcode  and eqp_code=@eqpcode";
                list.Add(new { str = sql, parm = new { docu_code = data.Rows[0]["source_wo"].ToString(), wkshpcode = wkshpcode, eqpcode = eqpcode, status = "CONFIR" } });
                bool aa = DapperHelper.DoTransaction(list);
                if (aa)
@@ -897,10 +910,14 @@
            try
            {
                //根据车间代码查找呼叫类型数据
                sql = @"select A.id,B.code,B.name  from TAnDon_Roul_ConFig A
                sql = @"select A.id,B.code,B.name,(case when F.type is null then 'N' else 'Y' end) flag
                        from TAnDon_Roul_ConFig A
                        inner join TAnDonType B on A.andotype_code=B.code
                        where A.wkshp_code=@wkshpcode and A.enable='N'";
                        inner  join TEqpInfo E on A.wkshp_code=e.wksp_code
                        left join(select type,wkshp_code,eqp_code  from TAnDon_Task_Info where eqp_code=@eqpcode and wkshp_code=@wkshpcode and status='START') F on A.wkshp_code=F.wkshp_code and E.code=F.eqp_code
                        where A.wkshp_code=@wkshpcode and E.code=@eqpcode and A.enable='N'";
                dynamicParams.Add("@wkshpcode", wkshpcode);
                dynamicParams.Add("@eqpcode", eqpcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
@@ -909,6 +926,7 @@
                        AnDnDate mn = new AnDnDate();
                        mn.code = data.Rows[i]["CODE"].ToString();
                        mn.name = data.Rows[i]["NAME"].ToString();
                        mn.flag = data.Rows[i]["FLAG"].ToString();
                        mn.children = new List<AnDnDateSub>();
                        //根据呼叫类型id查找绑定人员
                        sql = @"select U.usercode,U.username   
@@ -955,16 +973,18 @@
        public static ToMessage AppDeviceAnDengCallSave(string username, string eqpcode, string wkshpcode, List<AnDnDate> json)
        {
            string sql = "";
            int AnDnID = 0; //最大id
            var dynamicParams = new DynamicParameters();
            List<object> list = new List<object>();
            ChatHub chthub = new ChatHub();
            try
            {
                list.Clear();
                //执行消息推送
                chthub.SendByGroupList(username, wkshpcode, eqpcode, json);
                for (int i = 1; i <= json.Count; i++)
                //获取主表最大ID
                AnDnID = DapperHelper.insertReturnId("TAnDon_Task_Info");
                for (int i = 0; i < json.Count; i++)
                {
                    AnDnID = AnDnID + 1;//自增1
                    string code = json[i].code.ToString();
                    string name = json[i].name.ToString();
                    sql = @"select *   from TAnDon_Task_Info where wkshp_code=@wkshpcode and eqp_code=@eqpcode and type=@typecode and status='START'";
@@ -981,10 +1001,6 @@
                    }
                    else
                    {
                        //获取主表最大ID
                        sql = @"select ISNULL(IDENT_CURRENT('TK_Wrk_Record')+@num,1) as id";
                        dynamicParams.Add("@num", i);
                        var dt = DapperHelper.selectdata(sql, dynamicParams);
                        //写入安灯呼叫表
                        sql = @"insert into TAnDon_Task_Info(wkshp_code,eqp_code,type,start_date,start_user,status) 
                        values(@wkshp_code,@eqp_code,@type,@start_date,@start_user,@status)";
@@ -1001,21 +1017,23 @@
                                status = "START"
                            }
                        });
                        for (int j = 0; j < json[i].children.Count; j++)
                        {
                            //写入安灯记录推送人员表
                            sql = @"insert into TAnDnMessagePush(m_id,wkshp_code,eqp_code,type,resp_user,status) 
                                    values(@m_id,@wkshp_code,@eqp_code,@type,@start_date,@start_user,@status)";
                                    values(@m_id,@wkshp_code,@eqp_code,@type,@resp_user,@status)";
                            list.Add(new
                            {
                                str = sql,
                                parm = new
                                {
                                    m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
                                    m_id = AnDnID,
                                    //m_id = int.Parse(dt.Rows[0]["ID"].ToString()),
                                    wkshp_code = wkshpcode,
                                    eqp_code = eqpcode,
                                    type = code,
                                    resp_user = json[i].children[i].usercode,
                                    resp_user = json[i].children[j].usercode,
                                    status = "N"
                                }
                            });
@@ -1051,5 +1069,107 @@
        #endregion
        #region[安灯响应扫描工位/设备]
        public static ToMessage AppDeviceAnDengLampResponseScanSearch(string eqpcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取对应设备及所属车间的安灯呼叫记录
                sql = @"select A.eqp_code,B.name as eqp_name,T.org_name,A.type as typecode,D.name as typename
                        from TAnDon_Task_Info A
                        left join  TEqpInfo B on A.eqp_code=B.code
                        left join  TOrganization T on B.wksp_code=T.org_code
                        left join  TAnDonType D on A.type=D.code
                        where A.eqp_code=@eqpcode and A.status='START' and B.enable='Y' and T.description='W' ";
                dynamicParams.Add("@eqpcode", eqpcode);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                if (data.Rows.Count > 0)
                {
                    mes.code = "200";
                    mes.Message = "查询成功!";
                    mes.data = data;
                }
                else
                {
                    mes.code = "300";
                    mes.Message = "当前设备/工位未安灯呼叫!";
                    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 AppDeviceAnDengLampResponseSave(string username, string eqpcode, string wkshpcode, List<ObjectData> json)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            List<object> list = new List<object>();
            ChatHub chthub = new ChatHub();
            try
            {
                list.Clear();
                for (int i = 1; i <= json.Count; i++)
                {
                    string code = json[i].code.ToString();
                    string name = json[i].name.ToString();
                    //更新安灯呼叫表
                    sql = @"update TAnDon_Task_Info set resp_user=@resp_user,resp_date=@resp_date,status='CLOSED',taking=cast ( cast ( datediff ( ss, start_date, @resp_date) / ( 60 * 60 * 24 ) as int ) as varchar ) + '天' +
                            cast ( cast ( datediff ( ss, start_date, @resp_date ) % 86400 / 3600 as int ) as varchar ) + '小时' +
                           cast ( cast ( datediff ( ss, start_date, @resp_date ) % 3600 / 60 as int ) as varchar ) + '分' +
                           cast ( cast ( datediff ( ss, start_date, @resp_date ) % 60 as int ) as varchar ) + '秒'
                            where wkshp_code=@wkshp_code and eqp_code=@eqp_code and type=@type and status='START'";
                    list.Add(new
                    {
                        str = sql,
                        parm = new
                        {
                            wkshp_code = wkshpcode,
                            eqp_code = eqpcode,
                            type = code,
                            resp_date = DateTime.Now.ToString(),
                            resp_user = username,
                            status = "START"
                        }
                    });
                }
                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
    }
}