Exemplo n.º 1
0
        private void ExeResponseData(QXType qx, List <string> lstResponseFiles, ExcuteTaskType et)
        {
            if (qx == QXType.None)
            {
                return;
            }
            if (lstResponseFiles == null || lstResponseFiles.Count <= 0)
            {
                return;
            }
            int istatus = (int)STATUSType.Submiting;

            switch (qx)
            {
            case QXType.QY:
                db   = new Database("qysubmit");
                qxdm = "371423";
                break;

            case QXType.QH:
                db   = new Database("qhsubmit");
                qxdm = "371425";
                break;

            case QXType.PY:

                db = new Database("pysubmit");

                qxdm = "371426";
                break;

            case QXType.XJ:

                db = new Database("xjsubmit");

                qxdm = "371427";
                break;

            default:
                break;
            }
            //ShowDialogForm sdf = null;
            try
            {
                List <BIZANDREP> lstR     = sjdb.Fetch <BIZANDREP>(" where qxdm='" + qxdm + "' and status=" + istatus + "").ToList();
                XElement         config   = XElement.Load(SystemHandler.configFilePath);
                List <City>      lstCity  = SystemHandler.Instance.GetGeneralCitys();
                City             city     = lstCity.Where(p => qxdm.Equals(p.CityCode)).FirstOrDefault();
                List <string>    lstFiles = lstResponseFiles;

                // add by cfl 2019年9月 8日
                string XJGetRepMsg  = city.RepMsgPath + "/XJGetRepMsg";
                string reperrorpath = city.RepMsgPath.Trim().Replace("/RepMsg", "/RepMsgError"); //D:/dzxml/371423/RepMsgError/GetRepMsg
                if (!Directory.Exists(reperrorpath))
                {
                    Directory.CreateDirectory(reperrorpath);
                }
                string XJGetRepMsgError = reperrorpath + "/XJGetRepMsgError"; // D:/dzxml/371423/RepMsgError/GetRepMsg//XJGetRepMsgError
                if (!Directory.Exists(XJGetRepMsgError))
                {
                    Directory.CreateDirectory(XJGetRepMsgError);
                }


                if (!Directory.Exists(XJGetRepMsg))
                {
                    Directory.CreateDirectory(XJGetRepMsg);
                }
                if (lstFiles != null && lstFiles.Count > 0)
                {
                    int totalMain = lstFiles.Count;
                    if (et == ExcuteTaskType.Show)
                    {
                        //sdf = new ShowDialogForm("提示", "正在查找响应报文文件...", "请稍候");
                        //sdf.SetProgress(totalMain);
                    }
                    foreach (var item in lstFiles)
                    {
                        try
                        {
                            if (et == ExcuteTaskType.Hide)
                            {
                            }
                            //sdf.SetMessage("正在获取响应报文:" + item + " 数据");

                            string    bizmsgid = Path.GetFileNameWithoutExtension(item).Replace("Rep", "");
                            BIZANDREP bar      = lstR.Where(p => bizmsgid.Equals(p.BIZMSGID)).FirstOrDefault();
                            if (bar != null)
                            {
                                BIZANDREP qxbar = db.Fetch <BIZANDREP>("where YWH ='" + bar.YWH + "'").FirstOrDefault();//区县
                                if (qxbar != null)
                                {
                                    XElement root    = XElement.Load(item);
                                    string   repCode = root.Element("ResponseCode").Value;
                                    switch (repCode)
                                    {
                                    case "0000":
                                        qxbar.STATUS  = bar.STATUS = (int)STATUSType.RepSuccess;
                                        qxbar.REPTEXT = bar.REPTEXT = root.Element("ResponseInfo").Value;
                                        break;

                                    case "2040":
                                        qxbar.STATUS  = bar.STATUS = (int)STATUSType.RepFailure;
                                        qxbar.REPTEXT = bar.REPTEXT = root.Element("ResponseInfo").Value;
                                        break;

                                    case "1000":
                                        qxbar.STATUS  = bar.STATUS = (int)STATUSType.RepFailure;
                                        qxbar.REPTEXT = bar.REPTEXT = root.Element("AdditionalData").Value;
                                        break;

                                    default:
                                        qxbar.STATUS  = bar.STATUS = (int)STATUSType.RepFailure;
                                        qxbar.REPTEXT = bar.REPTEXT = root.Element("ResponseInfo").Value;
                                        break;
                                    }
                                }
                                bar.REPFILEPATH = item;

                                //更新市级库BIZANDREP
                                sjdb.Update(bar);
                                if (qxbar != null)
                                {
                                    //更新区县库BIZANDREP
                                    db.Update(qxbar);
                                }



                                if (item.Contains("RepMsgError"))
                                {
                                    File.Copy(item, XJGetRepMsgError + "/" + Path.GetFileName(item), true);
                                }
                                else
                                {
                                    File.Copy(item, XJGetRepMsg + "/" + Path.GetFileName(item), true);
                                }

                                File.Delete(item);
                            }
                        }

                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //if (sdf != null)
                //{
                //    sdf.Close(); sdf.Dispose();
                //}
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 数据上报,只上报BIZANDREP.status为1的数据
        /// </summary>
        /// <param name="qx"></param>
        public void DataSubmit(QXType qx, ExcuteTaskType et)
        {
            if (qx == QXType.None)
            {
                return;
            }
            //ShowDialogForm sdf = null;
            try
            {
                switch (qx)
                {
                case QXType.QY:
                    db   = new Database("qysubmit");
                    qxdm = "371423";
                    break;

                case QXType.QH:
                    db   = new Database("qhsubmit");
                    qxdm = "371425";
                    break;

                case QXType.PY:
                    db   = new Database("pysubmit");
                    qxdm = "371426";
                    break;

                case QXType.XJ:
                    db   = new Database("xjsubmit");
                    qxdm = "371427";
                    break;

                default:
                    break;
                }
                sjdb = new Database("sjsubmit");
                int    istatus = (int)STATUSType.DefaultValue;
                string qrySQL  = @"select * from RNANDCN t where exists (select * from BIZANDREP s where s.qxdm='" + qxdm + "' and s.status=" + istatus + " and s.ywh=t.ywh)  and t.qxdm='" + qxdm + "' ";
                //List<BIZANDREP> lstBAR = curContext.GetList<BIZANDREP>(" where qxdm='" + qxdm + "' and status=" + istatus + "").ToList();
                List <RNANDCN> lstRC = sjdb.Fetch <RNANDCN>(qrySQL); // SJbaseHelper.ConvertToList<RNANDCN>(SJbaseHelper.ExecuteDataReader(SJprovider, qrySQL)).ToList();
                                                                     // SJprovider.Close();
                if (!string.IsNullOrEmpty(lcqxdm))
                {
                    if (lstRC != null)
                    {
                        string         qrySQL2 = @"select * from RNANDCN t where exists (select * from BIZANDREP s where s.qxdm='" + lcqxdm + "' and s.status=" + istatus + " and s.ywh=t.ywh)  and t.qxdm='" + lcqxdm + "' ";
                        List <RNANDCN> lstRC2  = sjdb.Fetch <RNANDCN>(qrySQL); //SJbaseHelper.ConvertToList<RNANDCN>(SJbaseHelper.ExecuteDataReader(SJprovider, qrySQL2)).ToList();
                                                                               // SJprovider.Close();
                        if (lstRC2 != null)
                        {
                            lstRC.AddRange(lstRC2);
                        }
                    }
                }
                CheckBusinessTables cbt = XMLHelper.DeserializeByXmlFilePath <CheckBusinessTables>(SystemHandler.CheckBusinessTablesXMLFilePath);

                if (lstRC != null && lstRC.Count > 0)
                {
                    int totalMain = lstRC.Count;
                    if (et == ExcuteTaskType.Show)
                    {
                        //sdf = new ShowDialogForm("提示", "正在生成上报数据...", "请稍候");
                        //sdf.SetProgress(totalMain);
                    }
                    foreach (var rc in lstRC)
                    {
                        Head   hd      = null;
                        string xmlPath = "";
                        try
                        {
                            //
                            BusinessTypeClass btc = cbt.Business.Where(p => rc.JRYWBM.Equals(p.BusinessCode)).FirstOrDefault();
                            if (et == ExcuteTaskType.Show)
                            {
                            }
                            //sdf.SetMessage("正在生成业务号:" + rc.YWH + " 报文数据");
                            if (btc != null)
                            {
                                List <TableClass> lstTables = btc.检查表.Where(p => p.是否必选).ToList();
                                if (lstTables != null)
                                {
                                    hd = HeadHandler.Instance.ConstructHead(rc);
                                    List <dynamic> lstEntitys = new List <dynamic>();
                                    dynamic        entity     = null;
                                    Assembly       pAssembly  = Assembly.LoadFrom(SystemHandler.assPath);

                                    foreach (var item in lstTables)
                                    {
                                        entity = pAssembly.CreateInstance("BDCSubmit.Business.SubmitModel." + item.表名);
                                        if (et == ExcuteTaskType.Show)
                                        {
                                        }
                                        //sdf.SetContentEX("正在生成表:" + item.表名 + "数据");
                                        lstEntitys.AddRange(GetSJInstance(item.表名, rc, db));
                                    }
                                    //生成xml
                                    //1
                                    XElement ele = XMLHelper.CreateBizEX <dynamic>(hd, lstEntitys);

                                    //2
                                    XElement root = XElement.Load(SystemHandler.configFilePath);
                                    //3

                                    List <City> lstCity = SystemHandler.Instance.GetGeneralCitys();
                                    City        city    = lstCity.Where(p => qxdm.Equals(p.CityCode)).FirstOrDefault();

                                    if (city != null)
                                    {
                                        string BizMsgPath = city.BizMsgPath;
                                        if (!string.IsNullOrEmpty(BizMsgPath) && Directory.Exists(BizMsgPath))
                                        {
                                            xmlPath = BizMsgPath + "/" + "Biz" + hd.BizMsgID + ".xml";
                                            ele.Save(xmlPath);
                                            HeadHandler.Instance.CreateMsgWithSignature(xmlPath);  //每次修改完,这要重新保存一下
                                            //修改市级 BIZANDREP.STATUS值
                                            BIZANDREP bar = sjdb.Fetch <BIZANDREP>(" where qxdm='" + qxdm + "' and ywh='" + rc.YWH + "'").FirstOrDefault();
                                            bar.STATUS      = (int)STATUSType.Submiting;
                                            bar.BIZFILEPATH = xmlPath;

                                            bar.BIZMSGID = hd.BizMsgID;
                                            sjdb.Update(bar);
                                            //修改区县 BIZANDREP.STATUS值
                                            BIZANDREP qxbar = db.Fetch <BIZANDREP>(" where qxdm='" + qxdm + "' and ywh='" + rc.YWH + "'").FirstOrDefault();
                                            if (qxbar != null)
                                            {
                                                qxbar.STATUS   = (int)STATUSType.Submiting;
                                                qxbar.BIZMSGID = hd.BizMsgID;
                                                db.Update(qxbar);
                                            }
                                            if (et == ExcuteTaskType.Show)
                                            {
                                            }
                                            //sdf.SetMessageEX("生成业务号:" + rc.YWH + " 报文数据完成");
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                //删除生成的报文
                                if (!string.IsNullOrEmpty(xmlPath) && File.Exists(xmlPath))
                                {
                                    File.Delete(xmlPath);
                                }

                                //
                            }
                            catch
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //if (sdf != null)
                //{
                //    sdf.Close(); sdf.Dispose();
                //}
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 返回有上报信息的响应报文文件完整路径
        /// </summary>
        /// <param name="qx"></param>
        /// <returns></returns>
        public List <string> GetResponseFiles(QXType qx)
        {
            if (qx == QXType.None)
            {
                return(null);
            }
            List <string> lstResultFiles = new List <string>();

            try
            {
                int istatus = (int)STATUSType.Submiting;
                sjdb = new Database("sjsubmit");
                //SJContext = SystemHandler.Instance.SJCommunicationContext;
                switch (qx)
                {
                case QXType.QY:

                    qxdm = "371423";
                    break;

                case QXType.QH:

                    qxdm = "371425";
                    break;

                case QXType.PY:

                    qxdm = "371426";
                    break;

                case QXType.XJ:

                    qxdm = "371427";
                    break;

                default:
                    break;
                }
                List <BIZANDREP> lstR        = sjdb.Fetch <BIZANDREP>(" where qxdm='" + qxdm + "' and status=" + istatus + "").ToList();
                XElement         config      = XElement.Load(SystemHandler.configFilePath);
                List <City>      lstCity     = SystemHandler.Instance.GetGeneralCitys();
                City             city        = lstCity.Where(p => qxdm.Equals(p.CityCode)).FirstOrDefault();
                List <string>    lstFiles    = Directory.GetFiles(city.RepMsgPath, "Rep*.xml").ToList(); //D:/dzxml/371423/RepMsg/GetRepMsg
                string           XJGetRepMsg = city.RepMsgPath + "/XJGetRepMsg";

                string reperrorpath     = city.RepMsgPath.Trim().Replace("/RepMsg", "/RepMsgError"); //D:/dzxml/371423/RepMsgError/GetRepMsg
                string XJGetRepMsgError = reperrorpath + "/XJGetRepMsgError";


                if (!Directory.Exists(reperrorpath))
                {
                    Directory.CreateDirectory(reperrorpath);
                }
                List <string> errorlstFiles = Directory.GetFiles(reperrorpath, "Rep*.xml").ToList();
                List <string> totallstFiles = lstFiles.Union(errorlstFiles).ToList <string>();


                if (!Directory.Exists(XJGetRepMsgError))
                {
                    Directory.CreateDirectory(XJGetRepMsgError);
                }



                if (!Directory.Exists(XJGetRepMsg))
                {
                    Directory.CreateDirectory(XJGetRepMsg);
                }
                List <string> lstXJGetFiles      = Directory.GetFiles(XJGetRepMsg, "Rep*.xml").ToList();
                List <string> errorlstXJGetFiles = Directory.GetFiles(XJGetRepMsgError, "Rep*.xml").ToList();

                List <string> lstXJGetFileName = new List <string>();
                lstXJGetFiles.ForEach(item => { lstXJGetFileName.Add(Path.GetFileNameWithoutExtension(item)); });
                errorlstXJGetFiles.ForEach(item => { lstXJGetFileName.Add(Path.GetFileNameWithoutExtension(item)); });
                if (lstXJGetFileName.Count > 0)
                {
                    totallstFiles.ForEach(item =>
                    {
                        if (!lstXJGetFileName.Contains(Path.GetFileNameWithoutExtension(item)))
                        {
                            string bizmsgid = Path.GetFileNameWithoutExtension(item).Replace("Rep", "");
                            BIZANDREP bar   = lstR.Where(p => bizmsgid.Equals(p.BIZMSGID)).FirstOrDefault();
                            if (bar != null)
                            {
                                lstResultFiles.Add(item);
                            }
                        }
                    });
                }
                else
                {
                    totallstFiles.ForEach(item =>
                    {
                        string bizmsgid = Path.GetFileNameWithoutExtension(item).Replace("Rep", "");
                        BIZANDREP bar   = lstR.Where(p => bizmsgid.Equals(p.BIZMSGID)).FirstOrDefault();
                        if (bar != null)
                        {
                            lstResultFiles.Add(item);
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lstResultFiles);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 数据同步(只同步RNANDCN表中SFSB值为1(数据检查通过)的数据)
        /// </summary>
        /// <param name="qx"></param>
        public void DataExchange(QXType qx, ExcuteTaskType et)
        {
            if (qx == QXType.None)
            {
                return;
            }
            //ShowDialogForm sdf = null;
            try
            {
                switch (qx)
                {
                case QXType.QY:
                    db   = new Database("qysubmit");
                    qxdm = "371423";
                    break;

                case QXType.QH:
                    db   = new Database("qhsubmit");
                    qxdm = "371425";
                    break;

                case QXType.PY:
                    db   = new Database("pysubmit");
                    qxdm = "371426";
                    break;

                case QXType.XJ:
                    db   = new Database("xjsubmit");
                    qxdm = "371427";
                    break;

                default:
                    break;
                }
                int isfsb = (int)SFSBType.CheckSuccess;
                CheckBusinessTables cbt = XMLHelper.DeserializeByXmlFilePath <CheckBusinessTables>(SystemHandler.CheckBusinessTablesXMLFilePath);
                //查询通过检查的数据,才进行同步
                List <RNANDCN> lstRC = db.Fetch <RNANDCN>(" where qxdm='" + qxdm + "' and sfsb=" + isfsb + "").ToList();
                if (!string.IsNullOrEmpty(lcqxdm))
                {
                    if (lstRC != null)
                    {
                        List <RNANDCN> lstRC2 = db.Fetch <RNANDCN>(" where qxdm='" + lcqxdm + "' and sfsb=" + isfsb + "").ToList();
                        if (lstRC2 != null)
                        {
                            lstRC.AddRange(lstRC2);
                        }
                    }
                }
                if (lstRC != null && lstRC.Count > 0)
                {
                    int count = 1, total = lstRC.Count;
                    if (et == ExcuteTaskType.Show)
                    {
                        //sdf = new ShowDialogForm("提示", "正在同步数据...", "请稍候");
                        //sdf.SetProgress(total);
                    }
                    foreach (var rc in lstRC)
                    {
                        BusinessTypeClass btc            = cbt.Business.Where(p => rc.JRYWBM.Equals(p.BusinessCode)).FirstOrDefault();
                        List <TableClass> lstTables      = btc.检查表.Where(p => p.是否必选).ToList();
                        string            strExchangeErr = "";

                        try
                        {
                            sjdb = new Database("sjsubmit");

                            RNANDCN newRC = new RNANDCN();
                            //CopySameField(rc, newRC);
                            newRC      = rc;
                            newRC.SFSB = (int)SFSBType.ExchangeSuccess;
                            //市级库新增RNANDCN
                            int count1 = sjdb.Fetch <RNANDCN>(" where YWH='" + newRC.YWH + "' and QXDM='" + newRC.QXDM + "'").Count;
                            if (count1 == 0)
                            {
                                sjdb.Insert("RNANDCN", "PID", false, newRC);
                            }
                            else
                            {
                                RNANDCN sjRC = sjdb.Fetch <RNANDCN>(" where YWH='" + newRC.YWH + "' and QXDM='" + newRC.QXDM + "'").FirstOrDefault();
                                if (sjRC != null)
                                {
                                    //CopySameField(sjRC, newRC);
                                    sjRC      = newRC;
                                    sjRC.SFSB = newRC.SFSB;
                                    sjdb.Update(sjRC);
                                }
                            }
                            //市级库生成BizAndRep
                            BIZANDREP bar = new BIZANDREP();
                            bar.PID        = Guid.NewGuid().ToString("N");
                            bar.YWH        = rc.YWH;
                            bar.STATUS     = (int)STATUSType.DefaultValue;
                            bar.QXDM       = rc.QXDM;
                            bar.CREATETIME = DateTime.Now;
                            int count2 = sjdb.Fetch <BIZANDREP>(" where YWH='" + bar.YWH + "' and QXDM='" + bar.QXDM + "'").Count;
                            if (count2 == 0)
                            {
                                sjdb.Insert("BIZANDREP", "PID", false, bar);
                            }
                            else
                            {
                                BIZANDREP sjBar = sjdb.Fetch <BIZANDREP>(" where YWH='" + bar.YWH + "' and QXDM='" + bar.QXDM + "'").FirstOrDefault();
                                if (sjBar != null)
                                {
                                    sjBar.YWH    = rc.YWH;
                                    sjBar.STATUS = bar.STATUS;
                                    sjdb.Update(sjBar);
                                }
                            }
                            //县级库生成BizAndRep
                            //curContext.BeginTransaction();
                            int count3 = db.Fetch <BIZANDREP>(" where YWH='" + bar.YWH + "'").Count;
                            if (count3 == 0)
                            {
                                db.Insert("BIZANDREP", "PID", false, bar);
                            }
                            else
                            {
                                BIZANDREP xjBar = db.Fetch <BIZANDREP>(" where YWH='" + bar.YWH + "'").FirstOrDefault();
                                if (xjBar != null)
                                {
                                    xjBar.STATUS = bar.STATUS;
                                    db.Update(xjBar);
                                }
                            }
                            bool isError = false;
                            foreach (var item in lstTables)
                            {
                                List <dynamic> lstobj = GetNewInstance(item.表名, rc, db);



                                if (lstobj != null && lstobj.Count > 0)
                                {
                                    foreach (var sjobj in lstobj)
                                    {
                                        //if (true)
                                        //sjdb.Update(sjobj);
                                        sjdb.Insert(item.表名, "PID", false, sjobj);
                                        //else
                                        //{
                                        //    //UpdateSJobjInTransaction(sjobj);
                                        //    sjdb.Update(sjobj);
                                        //}
                                    }
                                }
                                //如果正常按程序执行,执行数据同步的数据肯定是通过数据检查的
                                //但万一有数据取不到的,写入CHECKMESSAGE
                                else
                                {
                                    if (string.IsNullOrEmpty(rc.CHECKMESSAGE))
                                    {
                                        rc.CHECKMESSAGE = "业务号:" + rc.YWH + "向市局同步失败,原因:" + item.表名 + "未取到数据";
                                    }
                                    else
                                    {
                                        rc.CHECKMESSAGE += ";" + rc.YWH + "向市局同步失败,原因:" + item.表名 + "未取到数据";
                                    }
                                    rc.SFSB = (int)SFSBType.CheckFailure;
                                    db.Update(rc);      // modify by cfl 2018年4月19日

                                    isError = true;
                                    break;
                                }
                            }
                            if (isError)
                            {
                                continue;
                            }
                            //更新区县库RNANDCN状态
                            rc.SFSB = (int)SFSBType.ExchangeSuccess;
                            db.Update(rc);


                            if (et == ExcuteTaskType.Show)
                            {
                            }
                            //sdf.SetMessage("业务号:" + rc.YWH + "相关数据同步成功。(" + count + "/" + total + ")");
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                strExchangeErr = ex.Message;

                                rc.SFSB = (int)SFSBType.ExchangeFailure;
                                if (string.IsNullOrEmpty(rc.CHECKMESSAGE))
                                {
                                    rc.CHECKMESSAGE = "业务号:" + rc.YWH + "向市局同步失败,原因:" + strExchangeErr;
                                }
                                else
                                {
                                    rc.CHECKMESSAGE += ";" + rc.YWH + "向市局同步失败,原因:" + strExchangeErr;
                                }
                                db.Update(rc);
                                if (et == ExcuteTaskType.Show)
                                {
                                }
                                //sdf.SetMessage("业务号:" + rc.YWH + "相关数据向市局同步失败。(" + count + "/" + total + ")");
                            }
                            catch
                            {
                                throw ex;
                            }
                        }

                        count++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //if (sdf != null)
                //{
                //    sdf.Close();
                //    sdf.Dispose();
                //}
            }
        }