1.Afr保存时,对字符串Trim 2.判重添加IsDel条件

master
zhangxiaofeng 9 months ago
parent 7ef3c4c30d
commit 3a5948c0e7

@ -0,0 +1,40 @@
using System;
using System.Reflection;
namespace Common.Helpers
{
public class StringTrimmer
{
// 定义一个通用方法用于遍历对象的属性并将string类型字段进行Trim操作
public static void TrimStringProperties(object obj)
{
if (obj == null)
{
return;
}
// 获取对象的类型信息
Type type = obj.GetType();
// 遍历对象的所有属性
foreach (PropertyInfo prop in type.GetProperties())
{
// 检查属性的类型是否为string
if (prop.PropertyType == typeof(string))
{
// 获取属性的值
string value = (string)prop.GetValue(obj);
// 如果属性的值不为null则进行Trim操作
if (value != null && (value.StartsWith(' ') || value.EndsWith(' ')))
{
// Trim操作
string trimmedValue = value.Trim();
// 设置属性的值为Trim后的值
prop.SetValue(obj, trimmedValue);
}
}
}
}
}
}

@ -245,7 +245,7 @@ namespace djy.Service.AFR
var select = DbAMS.Select<AFRMaster, AFRHouse>()
.InnerJoin<AFRHouse>((m, h) => m.GID == h.PID);
select.Where((m, h) => m.IsDel == false && m.StateIsSend == true)
select.Where((m, h) => m.IsDel == false && h.IsDel == false && m.StateIsSend == true)
//下面两个是Controller中传来的条件
.WhereIf(!string.IsNullOrEmpty(input.CompanyId), (m, h) => m.CompID == input.CompanyId)
.WhereIf(!string.IsNullOrEmpty(input.UserId), (m, h) => m.UserID == input.UserId)
@ -335,6 +335,8 @@ namespace djy.Service.AFR
AFRMaster oldMaster = null;
var nowTime = DateTime.Now;
StringTrimmer.TrimStringProperties(input);
#region 数据校验
if (string.IsNullOrWhiteSpace(input.MBLNO))
{
@ -368,23 +370,25 @@ namespace djy.Service.AFR
input.CreateTime = nowTime;
input.StateIsSend = false;
if (await DbAMS.Select<AFRMaster>().AnyAsync(m => m.MBLNO == input.MBLNO))
if (await DbAMS.Select<AFRMaster>().AnyAsync(m => m.MBLNO == input.MBLNO && m.IsDel == false))
{
throw new Exception("已存在相同的船东提单号");
}
var hblNoList = input.HouseList.Select(h => h.HouseBillNo).ToList();
var hblNoList = input.HouseList.Select(h => h.HouseBillNo.Trim()).ToList();
if (hblNoList.Any(h => string.IsNullOrWhiteSpace(h)))
{
throw new Exception("货代提单号不能为空");
}
if (hblNoList.Any() && await DbAMS.Select<AFRHouse>().AnyAsync(h => hblNoList.Contains(h.HouseBillNo)))
if (hblNoList.Any() && await DbAMS.Select<AFRHouse>().AnyAsync(h => hblNoList.Contains(h.HouseBillNo) && h.IsDel == false))
{
throw new Exception("已存在相同的货代提单号");
}
input.HouseList.ForEach(house =>
{
StringTrimmer.TrimStringProperties(house);
house.GID = Guid.NewGuid().ToString();
house.PID = input.GID;
house.LastUpdateUserID = User.GID;
@ -399,6 +403,8 @@ namespace djy.Service.AFR
house.CntrList ??= new List<AFRCntrno>();
house.CntrList.ForEach(cntr =>
{
StringTrimmer.TrimStringProperties(cntr);
cntr.GID = Guid.NewGuid().ToString();
cntr.PID = house.GID;
cntr.CreateTime = nowTime;
@ -427,7 +433,7 @@ namespace djy.Service.AFR
// 修改
else
{
if (await DbAMS.Select<AFRMaster>().AnyAsync(m => m.MBLNO == input.MBLNO && m.GID != input.GID))
if (await DbAMS.Select<AFRMaster>().AnyAsync(m => m.MBLNO == input.MBLNO && m.GID != input.GID && m.IsDel == false))
{
throw new Exception("已存在相同的船东提单号");
}
@ -444,6 +450,8 @@ namespace djy.Service.AFR
{
foreach (var house in input.HouseList)
{
StringTrimmer.TrimStringProperties(house);
house.LastUpdate = nowTime;
house.LastUpdateUserID = User.GID;
house.LastUpdateUserName = User.ShowName;
@ -456,14 +464,14 @@ namespace djy.Service.AFR
house.StateIsAccept = house.StateIsMatched = house.StateIsSend = house.StateIsDelete = false;
house.NewNotice = "";
if (await DbAMS.Select<AFRHouse>().AnyAsync(h => h.HouseBillNo == house.HouseBillNo))
if (await DbAMS.Select<AFRHouse>().AnyAsync(h => h.HouseBillNo == house.HouseBillNo && h.IsDel == false))
{
throw new Exception("已存在相同的货代提单号");
}
}
else
{
if (await DbAMS.Select<AFRHouse>().AnyAsync(h => h.HouseBillNo == house.HouseBillNo && h.GID != house.GID))
if (await DbAMS.Select<AFRHouse>().AnyAsync(h => h.HouseBillNo == house.HouseBillNo && h.GID != house.GID && h.IsDel == false))
{
throw new Exception("已存在相同的货代提单号");
}
@ -480,6 +488,8 @@ namespace djy.Service.AFR
cntr.LastUpdate = nowTime;
if (string.IsNullOrEmpty(cntr.GID))
{
StringTrimmer.TrimStringProperties(cntr);
cntr.GID = Guid.NewGuid().ToString();
cntr.PID = house.GID;
cntr.CreateTime = nowTime;

@ -248,6 +248,24 @@ namespace djy_AmsApi.Controllers.AMS
return req;
}
/// <summary>
/// 获取服务器当前时间
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("[action]")]
public Response GetTime()
{
var result = new Response()
{
Code = 200,
Message = "操作成功",
data = DateTime.Now.ToString()
};
return result;
}
}
}

File diff suppressed because one or more lines are too long

@ -3,7 +3,7 @@
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<NameOfLastUsedPublishProfile>C:\Project\DJYAMS\djyweb_ams\web\djy.WebApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>D:\DJY\Code\djyweb_ams\web\djy.WebApi\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<ActiveDebugProfile>djy_AmsApi</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Loading…
Cancel
Save