|
@@ -37,9 +37,20 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
{
|
|
|
var jw = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
|
|
|
|
|
|
+ // 获取团组名称列表(端口类型为1)
|
|
|
var groupNames = await _groupInfoRep.GetGroupNameList(new Domain.Dtos.Groups.GroupNameDto() { PortType = 1 });
|
|
|
- var tempDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 109).Select(x => new { x.Id, x.Name }).ToListAsync();
|
|
|
- var names = await _sqlSugar.Queryable<Grp_OrderPreInfo>().Where(x => x.IsDel == 0 && x.CreateUserId == userId).OrderByDescending(x => x.Id).Select(x => new { x.Id, x.Name }).ToListAsync();
|
|
|
+
|
|
|
+ var tempDatas = await _sqlSugar.Queryable<Sys_SetData>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.STid == 109)
|
|
|
+ .Select(x => new { x.Id, x.Name })
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var names = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.CreateUserId == userId)
|
|
|
+ .OrderByDescending(x => x.Id)
|
|
|
+ .Select(x => new { x.Id, x.Name })
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
jw.Data = new
|
|
|
{
|
|
|
groupNames = groupNames,
|
|
@@ -53,7 +64,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
/// <summary>
|
|
|
/// 获取模板信息
|
|
|
/// </summary>
|
|
|
- /// <param name="tempId"></param>
|
|
|
+ /// <param name="tempId">模板编号,默认 1404</param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<GrpOrderPreItemView[]> TempInfoById(int tempId = 1404)
|
|
|
{
|
|
@@ -82,22 +93,24 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
/// <summary>
|
|
|
/// 获取团组下单前信息
|
|
|
/// </summary>
|
|
|
- /// <param name="id"></param>
|
|
|
+ /// <param name="id">下单前信息Id</param>
|
|
|
+ /// <param name="tempId">模板编号,默认 1404</param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<JsonView> InfoAsync(int id, int tempId = 1404)
|
|
|
{
|
|
|
var jw = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
|
|
|
var view = new GrpOrderPreInfoView();
|
|
|
- var info = await _sqlSugar.Queryable<Grp_OrderPreInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == id);
|
|
|
+ var info = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
|
|
|
+ .FirstAsync(x => x.IsDel == 0 && x.Id == id);
|
|
|
|
|
|
var temps = await TempInfoById(tempId);
|
|
|
if (info == null)
|
|
|
{
|
|
|
- //view.TempId = tempId;
|
|
|
view.Items = temps;
|
|
|
jw.Data = view;
|
|
|
return jw;
|
|
|
}
|
|
|
+
|
|
|
view.Id = id;
|
|
|
view.Name = info.Name;
|
|
|
view.GroupId = info.GroupId;
|
|
@@ -115,7 +128,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
ParentId = opi.ParentId,
|
|
|
FieldTempId = ft.Id,
|
|
|
FieldName = sd1.Name,
|
|
|
- //FieldTypeName = !string.IsNullOrEmpty(ft.Remark) ? sd2.Name + "-" + ft.Remark : sd2.Name,
|
|
|
FieldTypeName = sd2.Name,
|
|
|
OriginVal = opi.Value,
|
|
|
Remark = opi.Remark,
|
|
@@ -125,23 +137,22 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
})
|
|
|
.ToArrayAsync();
|
|
|
|
|
|
- if (!items.Any()) view.Items = temps;
|
|
|
+ // 如果原始数据不存在或者数量不匹配,则补充模板中缺失的字段
|
|
|
+ if (!items.Any())
|
|
|
+ {
|
|
|
+ view.Items = temps;
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
- if (items.Length != temps.Length)
|
|
|
+ var itemsList = items.ToList();
|
|
|
+ foreach (var temp in temps)
|
|
|
{
|
|
|
- foreach (var item in temps)
|
|
|
+ if (!itemsList.Any(x => x.FieldName.Equals(temp.FieldName)))
|
|
|
{
|
|
|
- if (items.FirstOrDefault(x => x.FieldName.Equals(item.FieldName)) == null)
|
|
|
- {
|
|
|
- var arr = new GrpOrderPreItemView[] { item };
|
|
|
- view.Items.AddRange(arr);
|
|
|
- }
|
|
|
+ itemsList.Add(temp);
|
|
|
}
|
|
|
}
|
|
|
- else view.Items = items;
|
|
|
-
|
|
|
- view.Items = view.Items.Length > 0 ? view.Items.OrderBy(x => x.Index).ToArray() : view.Items;
|
|
|
+ view.Items = itemsList.OrderBy(x => x.Index).ToArray();
|
|
|
}
|
|
|
|
|
|
jw.Data = view;
|
|
@@ -175,10 +186,13 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
GroupId = dto.GroupId,
|
|
|
CreateUserId = currUserId
|
|
|
};
|
|
|
+
|
|
|
var items = new List<Grp_OrderPreItem>();
|
|
|
+ // 处理每一项信息
|
|
|
foreach (var item in dto.Items)
|
|
|
{
|
|
|
var val = "";
|
|
|
+ // 如果新值为 string[] 时,序列化为 JSON 字符串,否则直接转换
|
|
|
if (item.NewValue is Array obj)
|
|
|
{
|
|
|
val = JsonConvert.SerializeObject( (string[])item.NewValue);
|
|
@@ -202,7 +216,10 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
_sqlSugar.BeginTran();
|
|
|
if (dto.Id > 0) //修改
|
|
|
{
|
|
|
- var infoUpd = await _sqlSugar.Updateable(info).UpdateColumns(x => new { x.Name, x.GroupId }).ExecuteCommandAsync();
|
|
|
+ var infoUpd = await _sqlSugar.Updateable(info)
|
|
|
+ .UpdateColumns(x => new { x.Name, x.GroupId })
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
if (infoUpd < 1)
|
|
|
{
|
|
|
_sqlSugar.RollbackTran();
|
|
@@ -232,6 +249,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
return jw;
|
|
|
}
|
|
|
|
|
|
+ // 设置所有项的 ParentId 为新增后的 Id
|
|
|
foreach (var item in items) item.ParentId = addId;
|
|
|
|
|
|
if (items.Any()) await _sqlSugar.Insertable(items).ExecuteCommandAsync();
|