!提交代码

This commit is contained in:
hehaibing-1996
2024-04-15 18:43:28 +08:00
commit e89b64ea3a
232 changed files with 22292 additions and 0 deletions

View File

@ -0,0 +1,240 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.DbModels;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.StoreInfo;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class StoreInfoService : IStoreInfoService
{
public StoreInfoService() { }
public async Task<PageQueryResponse<ShelfInfo>> GetShelves(GetShelvesRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<ShelfInfo>()
.WhereIF(request.ShelfTypeId != 0, t => t.ShelfTypeId == request.ShelfTypeId)
.WhereIF(!string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode));
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * 10 + i + 1;
}
return new PageQueryResponse<ShelfInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<ShelfInfo>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<ShelfInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<ResponseCommon<object>> addOrUpdateShelfInfo(AddShelfInfoRequest<ShelfInfo> request)
{
try
{
var shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.ShelfCode == request.ShelfInfo.ShelfCode)
.FirstAsync();
//修改货架信息
if (request.AddOrUpdate == AddOrUpdate.Update)
{
var existId = shelfnfo == null ? 0 : shelfnfo.Id;
shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.Id == request.ShelfInfo.Id)
.FirstAsync();
if (shelfnfo == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:货架{request.ShelfInfo.ShelfCode}不存在!",
Data = null
};
}
else if (existId != shelfnfo.Id)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:已存在货架编码{request.ShelfInfo.ShelfCode}",
Data = null
};
}
else
{
shelfnfo.ShelfCode = request.ShelfInfo.ShelfCode;
shelfnfo.ShelfTypeId = request.ShelfInfo.ShelfTypeId;
shelfnfo.ShelfTypeName = request.ShelfInfo.ShelfTypeName;
shelfnfo.Rowcounts = request.ShelfInfo.Rowcounts;
shelfnfo.Columncounts = request.ShelfInfo.Columncounts;
shelfnfo.LightId = request.ShelfInfo.LightId;
shelfnfo.ClientIp = request.ShelfInfo.ClientIp;
shelfnfo.GroupName = request.ShelfInfo.GroupName;
shelfnfo.IsBind = request.ShelfInfo.IsBind;
shelfnfo.BindShelfCode = request.ShelfInfo.BindShelfCode;
var rowNum = await DbHelp.db.Updateable(shelfnfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"更新货架信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Add)
{
if (shelfnfo != null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"货架信息失败:货架{request.ShelfInfo.ShelfCode}已存在!",
Data = null
};
}
else
{
var newShelfInfo = new ShelfInfo()
{
ShelfCode = request.ShelfInfo.ShelfCode,
ShelfTypeId = request.ShelfInfo.ShelfTypeId,
ShelfTypeName = request.ShelfInfo.ShelfTypeName,
Rowcounts = request.ShelfInfo.Rowcounts,
Columncounts = request.ShelfInfo.Columncounts,
LightId = request.ShelfInfo.LightId,
ClientIp = request.ShelfInfo.ClientIp,
GroupName = request.ShelfInfo.GroupName,
IsBind = request.ShelfInfo.IsBind,
BindShelfCode = request.ShelfInfo.BindShelfCode,
};
var rowNum = await DbHelp.db.Insertable(newShelfInfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"添加货架信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Delete)
{
shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.Id == request.ShelfInfo.Id)
.FirstAsync();
if (shelfnfo == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除货架信息失败:货架{request.ShelfInfo}不存在!",
Data = null
};
}
else
{
var rowNum = await DbHelp.db.Deleteable(shelfnfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"删除货架信息成功!",
Data = null
};
}
}
}
else
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = "不支持的操作!",
Data = null
};
return response;
}
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
}
}