private async Task <List <ViolationErrorInfo> > CheckError(List <BatchTableModelDto> batchTableModels) { var violationErrorInfos = new List <ViolationErrorInfo>(); try { if (batchTableModels != null && batchTableModels.Count > 0) { //查询代办人列表 var agentNames = batchTableModels.Where(x => !string.IsNullOrEmpty(x.代办方)).Select(x => x.代办方).ToList(); var users = new List <Users>(); if (agentNames.Any()) { users = await _userServices.GetUsersByKeys(agentNames, AbpSession.WebSiteId); } var carTypeNames = EnumExtension.GetDescriptions <CarTypeEnum>(); #region 数据判断 foreach (var item in batchTableModels) { string ret = ""; bool checkSucssful = true; if (string.IsNullOrEmpty(item.序号)) { checkSucssful = false; ret += "序号不能为空!"; } else if (batchTableModels.Where(x => x.序号 == item.序号).Count() >= 2) { checkSucssful = false; ret += $"序号:{item.序号}重复!"; } if (string.IsNullOrEmpty(item.车牌号)) { checkSucssful = false; ret += "车牌不能为空!"; } if (string.IsNullOrEmpty(item.车型名称)) { item.车型名称 = "小型汽车"; } if (string.IsNullOrEmpty(item.车辆性质)) { item.车辆性质 = "单位车"; } #region 获取车型代码 string carTypeName = item.车型名称; carTypeName = carTypeNames.Where(x => x == carTypeName).FirstOrDefault(); if (carTypeName == null) { checkSucssful = false; ret += "车型名称 格式有误!"; } var carCodeResult = carTypeName.GetEnumByDesc <CarTypeEnum>(); item.车型代码 = ((int)carCodeResult).ToString().PadLeft(2, '0'); #endregion if (string.IsNullOrEmpty(item.车架号)) { checkSucssful = false; ret += "车架号不能为空!"; } if (string.IsNullOrEmpty(item.发动机号)) { checkSucssful = false; ret += "发动机号不能为空!"; } if (string.IsNullOrWhiteSpace(item.是否超证)) { checkSucssful = false; ret += "是否超证不能为空!"; } //有违章 if (!string.IsNullOrWhiteSpace(item.违章时间) && !string.IsNullOrWhiteSpace(item.扣分)) { if (!item.违章时间.IsDate()) { checkSucssful = false; ret += "违章时间不是正确的日期格式!"; } if (!item.扣分.IsNumber()) { checkSucssful = false; ret += "扣分不是整数!"; } if (string.IsNullOrWhiteSpace(item.违章城市)) { checkSucssful = false; ret += "违章城市不能为空!"; } else { #region 用违章城市进行反算城市代码 var cityQuery = CommonHelper.InByCityName(item.违章城市.ToString()); if (cityQuery != null) { string Code = cityQuery.ID; if (Code.Length != 4) { Code = Code.PadRight(4, '0'); } item.违章城市代码 = Code; } #endregion } if (string.IsNullOrEmpty(item.违章地点)) { checkSucssful = false; ret += "违章地点不能为空!"; } if (string.IsNullOrEmpty(item.违章原因)) { checkSucssful = false; ret += "违章原因不能为空!"; } if (string.IsNullOrEmpty(item.违法代码)) { item.违法代码 = ""; } else { if (!item.违法代码.IsDigitOrNumber()) { checkSucssful = false; ret += "违法代码错误!"; } if (item.违法代码.Length > 10) { checkSucssful = false; ret += "违法代码错误!"; } } if (string.IsNullOrEmpty(item.罚金)) { checkSucssful = false; ret += "罚金不能为空!"; } else { if (item.罚金.ToDecimal() == null) { checkSucssful = false; ret += "罚金格式错误!"; } } if (string.IsNullOrWhiteSpace(item.滞纳金)) { checkSucssful = false; ret += "滞纳金不能为空!"; } else { if (item.滞纳金.ToDecimal() == null) { checkSucssful = false; ret += "滞纳金格式错误!"; } } if (!item.文书号.IsNullOrEmpty() && item.文书号.Length > 32) { checkSucssful = false; ret += "文书号长度超过32位!"; } } //人工报价—服务费 if (!string.IsNullOrEmpty(item.手续费) && item.手续费.ToInt() > 0) { if (item.代办方.IsNullOrEmpty()) { checkSucssful = false; ret += "代办方不能为空!"; } else if (item.代办成本.IsNullOrEmpty()) { checkSucssful = false; ret += "代办成本不能为空!"; } } if (!string.IsNullOrEmpty(item.代办成本) && decimal.TryParse(item.代办成本, out decimal dbcb)) { if (item.代办方.IsNullOrEmpty()) { checkSucssful = false; if (!ret.Contains("代办方不能为空!")) { ret += "代办方不能为空!"; } } } if (!string.IsNullOrEmpty(item.代办方)) { var userId = users.FirstOrDefault(x => (x.Shortname == item.代办方 || x.LoginName == item.代办方))?.Id; if (string.IsNullOrEmpty(userId)) { checkSucssful = false; ret += $"代办方:{item.代办方}信息有误!"; } if (item.代办成本.IsNullOrEmpty() || !decimal.TryParse(item.代办成本, out dbcb)) { checkSucssful = false; if (!ret.Contains("代办成本不能为空!")) { ret += "代办成本不能为空!"; } } } #region 正确与错误记录 if (!checkSucssful) { item.DataStatus = (int)ViolationDataStatusEnum.Error; violationErrorInfos.Add(new ViolationErrorInfo { Index = item.序号, Type = "错误", Reason = ret }); } #endregion var count = batchTableModels.Where(x => x.车牌号 == item.车牌号 && x.是否挑单 != item.是否挑单).Count(); if (count > 0) { violationErrorInfos.Add(new ViolationErrorInfo { Index = item.序号, Type = "错误", Reason = "车辆:" + item.车牌号 + "存在多种挑单方式!" }); } } #endregion } else { violationErrorInfos.Add(new ViolationErrorInfo { Index = "", Type = "错误", Reason = "导入的有效数据为空或者模板不正确" }); } } catch (Exception ex) { _logger.Error($"BatchCarViolationService.CheckError:{ex.Message}"); return(null); } return(violationErrorInfos); }