Files
wcs/WCS.BLL/Services/Service/MatDetailCurrentInfoService.cs
hehaibing-1996 a4c02a9173 1.PDA绑定相关接口
2.货架存量 后端接口
2025-01-13 20:08:03 +08:00

225 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.Config;
using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.InOutRecord;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.StoreInfo;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class MatDetailCurrentInfoService : IMatDetailCurrentInfoService
{
public async Task<PageQueryResponse<MatDetailCurrentInfo>> GetMatDetailCurrentInfos(GetMatDetailCurrentInfosRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<MatDetailCurrentInfo>()
.LeftJoin<ShelfInfo>((mci, si) => mci.ShlefId == si.Id)
.LeftJoin<LocationInfo>((mci, si, li) => (si.TransStatus == TransStatusEnum. && si.CurrentLocationId == li.Id)
|| (si.TransStatus == TransStatusEnum. && si.DestinationLocationId == li.Id))
.WhereIF(request.LocationAreaId != null && request.LocationAreaId != 0, (mci, si, li) => li.LocationAreaId == request.LocationAreaId)
.WhereIF(!string.IsNullOrEmpty(request.LocationCode), (mci, si, li) => li.LocationCode.Contains(request.LocationCode))
.WhereIF(request.ShelfTypeId != null && request.ShelfTypeId != 0, (mci, si, li) => si.ShelfTypeId == request.ShelfTypeId)
.WhereIF(!string.IsNullOrEmpty(request.ShelfCode), (mci, si, li) => si.ShelfCode.Contains(request.ShelfCode))
.WhereIF(!string.IsNullOrEmpty(request.MatCode), (mci, si, li) => mci.MatCode.Contains(request.MatCode))
.WhereIF(!string.IsNullOrEmpty(request.MatName), (mci, si, li) => mci.MatCode.Contains(request.MatName))
.Select((mci, si, li) => mci);
//分页
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) * request.PageSize + i + 1;
}
return new PageQueryResponse<MatDetailCurrentInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<MatDetailCurrentInfo>()
{
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<MatDetailCurrentInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<ResponseCommon<object>> updateMatDetailCurrentInfo(AddLocaionInfoRequest<MatDetailCurrentInfo> request)
{
return null;
//try
//{
// var MatDetailCurrentInfo = await DbHelp.db.Queryable<MatDetailCurrentInfo>() //.Where(t => t.MatDetailCurrentCode == request.MatDetailCurrentInfo.MatDetailCurrentCode)
// .FirstAsync();
// //修改位置信息
// if (request.AddOrUpdate == AddOrUpdate.Update)
// {
// var existId = MatDetailCurrentInfo == null ? 0 : MatDetailCurrentInfo.Id;
// MatDetailCurrentInfo = await DbHelp.db.Queryable<MatDetailCurrentInfo>()
// //.Where(t => t.Id == request.MatDetailCurrentInfo.Id)
// .FirstAsync();
// if (MatDetailCurrentInfo == null)
// {
// return new ResponseCommon<Object>
// {
// Code = 201,
// Message = $"更新位置信息失败:该位置不存在!",
// Data = null
// };
// }
// else if (existId != 0 && existId != MatDetailCurrentInfo.Id)
// {
// return new ResponseCommon<Object>
// {
// Code = 201,
// Message = $"更新位置信息失败:位置[{MatDetailCurrentInfo.MatDetailCurrentCode}]已存在!",
// Data = null
// };
// }
// else
// {
// request.MatDetailCurrentInfo.ModifyUser = request.UserName;
// request.MatDetailCurrentInfo.ModifyTime = DateTime.Now;
// var rowNum = await DbHelp.db.Updateable(request.MatDetailCurrentInfo).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 (MatDetailCurrentInfo != null)
// {
// return new ResponseCommon<Object>
// {
// Code = 201,
// Message = $"新增位置信息失败:位置[{MatDetailCurrentInfo.MatDetailCurrentCode}]已存在!",
// Data = null
// };
// }
// else
// {
// request.MatDetailCurrentInfo.ModifyUser = request.UserName;
// var rowNum = await DbHelp.db.Insertable(request.MatDetailCurrentInfo).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;
//}
}
public async Task<ResponseCommon<object>> deleteMatDetailCurrentInfo(DeleteInfosRequest request)
{
//先查询出具体的Id
var MatDetailCurrentInfos = await DbHelp.db.Queryable<MatDetailCurrentInfo>()
.Where(t => request.needDeleteIds.Contains(t.Id))
.ToListAsync();
//执行删除
try
{
var deleteRows = await DbHelp.db.Deleteable(MatDetailCurrentInfos).ExecuteCommandAsync();
return new ResponseCommon<Object>
{
Code = 200,
Message = $"已删除{deleteRows}条数据!",
Data = null
};
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
}
}