Browse Source

优化插入和更新逻辑以确保精确匹配

在 `EnterExitCostRepository.cs` 中进行了以下更改:
- 使用 `Equals` 方法替代 `Contains` 方法,以确保对省份、国家和城市的精确匹配。
- 在插入新记录时,改用 `await _sqlSugar.Insertable(info).ExecuteCommandAsync();`。
- 在更新现有记录时,改用 `await _sqlSugar.Updateable(info).ExecuteCommandAsync();`,并忽略 `CreateUserId`、`CreateTime` 和 `IsDel` 字段。
- 增加了对 `dto.PortType` 的判断,以便在特定条件下执行相应的逻辑。
LEIYI 1 month ago
parent
commit
16f383a062

+ 8 - 9
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostRepository.cs

@@ -635,33 +635,32 @@ namespace OASystem.Infrastructure.Repositories.Groups
             info.LastUpdateUserId = dto.UserId;
             info.CreateUserId = dto.UserId;
 
+
             if (dto.PortType == 1) //web
             {
-
-                var _nationalTravelFee = _sqlSugar.Storageable(info).ToStorage();
                 if (dto.Id == 0) //新增
                 {
                     var isNul = await _sqlSugar
                         .Queryable<Grp_NationalTravelFee>()
                         .FirstAsync(x => x.IsDel == 0 &&
-                            info.ProvinceId == x.ProvinceId &&
-                            info.Continent.Contains(dto.Continent) &&
-                            info.Country.Contains(dto.Country) &&
-                            info.City.Contains(dto.City));
+                            x.Continent.Equals(dto.Continent) &&
+                            x.Country.Equals(dto.Country) &&
+                            x.City.Equals(dto.City) &&
+                            x.ProvinceId == info.ProvinceId);
                     if (isNul != null)
                     {
                         result.Msg = "该国家或者城市已存在,请勿重复添加!";
                         return result;
                     }
 
-                    _nationalTravelFee.AsInsertable.ExecuteCommand();   //不存在插入
+                    await _sqlSugar.Insertable(info) .ExecuteCommandAsync();   
                 }
                 else
                 {
-                    _nationalTravelFee.AsUpdateable
+                    await _sqlSugar.Updateable(info)
                     .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime, it.IsDel })
                     .WhereColumns(it => it.Id)
-                    .ExecuteCommand();   //存在更新
+                    .ExecuteCommandAsync();  
                 }
 
                 result.Code = 200;