123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using Quartz;
- using System;
- using ProjectBase.Data.BaseDAL;
- using ProjectBase.Data.Logs;
- using SIMDP.Model;
- using System.Threading.Tasks;
- using ProjectBase.Util;
- using System.Data.Common;
- namespace SIMDP.BLL
- {
- public class GetAS400DataJob : IJob
- {
- public async Task Execute(IJobExecutionContext context)
- {
- // if (!SysEnvironment.sign_OnlineMode) return;
- if (BLLFactory<BlMtocData>.Instance.GetRecordCount() > 1500) return;
- await Task.Run(() => GetAS400());
- }
- public bool GetAS400(string specifyVIN = "")
- {
- if (string.IsNullOrEmpty(specifyVIN) && string.IsNullOrEmpty(SysEnvironment.shareUp_PI_NO)) return true;
- try
- {
- AS400Service.GETMAINR ws = new AS400Service.GETMAINR();
- AS400Service.mainInput mainInput = new AS400Service.mainInput();
- mainInput.PI_LINE = "02";
- mainInput.PI_TYPE = "PAOFF";
- mainInput.PI_NO = !string.IsNullOrEmpty(specifyVIN) ? specifyVIN : SysEnvironment.shareUp_PI_NO;
- AS400Service.mainResult mainRes = ws.main(mainInput);
- string[] strs = mainRes.PI_LIST;
- //string[] strs = new string[] { "LHGCV1679N8081023 NTVGHB600 NH904M A 2022/02/1608:38:03" };
- //string[] strs = new string[] { "LHGRV8886P8000183 63F4HA500 B508M L1202211112807:51:31" };
- //if (!CheckPostResult(strs))
- //{
- // LogHelper.log.Info($"无法在AS400中查到车号 {mainInput.PI_NO} 或格式异常");
- // return false;
- //}
- if (strs.Length<1)
- LogHelper.log.Info($"获取AS400数据失败,数组长度小于1");
- LogHelper.log.Debug("【接收数据start】");
- foreach (string s in strs)
- {
- LogHelper.log.Debug($"接收数据行:{s}");
- int iPLCCode = 0;
- int iPaintLine = 0;
- char[] chs = { ' ', '\t' };
- //string sVin = s.Substring(0, 19).Trim();
- //string smodel = sVin.Substring(3, 2);
- //string[] smtoc = s.Substring(19, 22).Split(chs, StringSplitOptions.RemoveEmptyEntries);
- //string scolor = smtoc[1];
- string sVin = "";
- string smodel = "";
- string scolor = "";
- string[] smtoc= s.Split(chs, StringSplitOptions.RemoveEmptyEntries);
- if (smtoc.Length < 3)
- {
- LogHelper.log.Info($"AS400数据格式异常,数组长度小于3,原始数据:{s}");
- return false;
- }
- sVin = smtoc[0].Trim();
- smodel= sVin.Substring(3, 2);
- scolor = smtoc[2].Trim();
- if (CheckArrayContain(SysEnvironment.LastPostResult, s))
- {
- LogHelper.log.Debug($"查询到重复AS400数据!车号 {sVin}");
- continue;
- }
- //获取车型
- iPLCCode = BLLFactory<BlModelContrast>.Instance.GetPLCCodebyModelCode(smodel);
- if (iPLCCode <= 0) LogHelper.log.Error($"接收车型异常 smodel= {smodel}");
- //获取颜色
- iPaintLine = BLLFactory<BlColorContrast>.Instance.GetPaintLinebyColorCard(scolor);
- if (iPaintLine <= 0) LogHelper.log.Error($"接收颜色异常 scolor= {scolor}");
- //存入MTOC表
- MoMtocData model = new MoMtocData();
- model.Vin = sVin;
- model.Model = iPLCCode;
- model.Color = iPaintLine;
- model.Fetch_Time = DateTime.Now;
- using (DbTransaction trans = BLLFactory<BlMtocData>.Instance.CreateTransaction())
- {
- try
- {
- BLLFactory<BlMtocData>.Instance.Insert(model, trans);
- trans.Commit();
- }
- catch (Exception ex)
- {
- SysEnvironment.warn_AS400 = true;
- trans.Rollback();
- LogHelper.log.Error($"存入数据库MTOC表异常:{ex.Message}");
- LogHelper.log.Error($"当前缓存的POST结果:");
- foreach (string str in SysEnvironment.LastPostResult)
- {
- LogHelper.log.Error($"缓存: {str}");
- }
- }
- }
- }
- // SysEnvironment.shareUp_PI_NO = strs[strs.Length - 1].Substring(0, 17);//更新下次查询起始车号
- SysEnvironment.shareUp_PI_NO = strs[strs.Length - 1].Substring(0, 19).Trim();//更新下次查询起始车号
- SysEnvironment.LastPostResult = null;
- SysEnvironment.LastPostResult = (string[])strs.Clone(); //更新本次post结果, 不是车号!
- return true;
- }
- catch (Exception ex)
- {
- SysEnvironment.warn_AS400 = true;
- LogHelper.log.Error($"获取AS400数据出错:{ex.Message}");
- throw ex;
- //return false;
- }
- }
- private bool CheckPostResult(string[] strs)
- {
- if (strs.Length < 1) return false;
- //foreach (string ss in strs)
- //{
- // if (ss.Length != 59)
- // return false;
- //}
- return true;
- }
- /// <summary>
- /// 检查数组是否包含了指定的字符串
- /// </summary>
- /// <param name="strs"></param>
- /// <param name="strMatch"></param>
- /// <returns></returns>
- public bool CheckArrayContain(string[] strs, string strMatch)
- {
- for (int i = 0; i < strs.Length; i++)
- {
- // LogHelper.log.Debug($"校验重复行:{strMatch}/n{strs[i]}");
- if (string.Equals(strs[i], strMatch))
- return true;
- }
- return false;
- }
- }
- }
|