5
This commit is contained in:
parent
fb3a04034b
commit
29e7c07be8
@ -87,56 +87,47 @@ namespace DOAN.Service.Business
|
||||
/// <returns></returns>
|
||||
public PagedInfo<UniqueValueQueryDto> GetUniqueValueList(UniqueDto parm)
|
||||
{
|
||||
// 1. 初始化分页结果
|
||||
var pagedResult = new PagedInfo<UniqueValueQueryDto>
|
||||
{
|
||||
PageIndex = parm.PageNum < 1 ? 1 : parm.PageNum, // 页码最小为1
|
||||
PageSize = parm.PageSize < 1 || parm.PageSize > 100 ? 10 : parm.PageSize // 每页条数限制1-100
|
||||
};
|
||||
// 1. 构建查询条件
|
||||
var predicate = Expressionable.Create<ProcessmodelWorkStep>()
|
||||
.AndIF(!string.IsNullOrEmpty(parm.StepCode), p => p.StepCode == parm.StepCode)
|
||||
.AndIF(!string.IsNullOrEmpty(parm.DeviceCode), p => p.UniqueValue.Contains(parm.DeviceCode))
|
||||
.ToExpression();
|
||||
|
||||
// 2. 校验 StepCode 是否存在(不存在返回空分页)
|
||||
bool stepCodeExists = Context.Queryable<ProcessmodelWorkStep>()
|
||||
.Where(p => p.StepCode == parm.StepCode)
|
||||
.Any();
|
||||
// 2. 查询总记录数
|
||||
int totalCount = Queryable()
|
||||
.Where(predicate)
|
||||
.Count();
|
||||
|
||||
if (!stepCodeExists)
|
||||
{
|
||||
pagedResult.TotalNum = 0;
|
||||
pagedResult.Result = new List<UniqueValueQueryDto>();
|
||||
return pagedResult;
|
||||
}
|
||||
|
||||
// 3. 构建查询
|
||||
var baseQuery = Context.Queryable<ProcessmodelWorkStep>()
|
||||
.Where(p => p.StepCode == parm.StepCode)
|
||||
.Distinct()
|
||||
.LeftJoin<DeviceAccount>((ws, da) => ws.UniqueValue == da.DeviceCode)
|
||||
.Where((ws, da) => da != null)
|
||||
.WhereIF(!string.IsNullOrEmpty(parm.DeviceCode), (ws, da) => da.DeviceCode.Contains(parm.DeviceCode))
|
||||
.WhereIF(!string.IsNullOrEmpty(parm.DeviceName), (ws, da) => da.DeviceName.Contains(parm.DeviceName))
|
||||
.Select((ws, da) => new UniqueValueQueryDto
|
||||
// 3. 查询当前页数据列表
|
||||
int skipCount = (parm.PageNum - 1) * parm.PageSize;
|
||||
var dataList = Queryable()
|
||||
.Where(predicate)
|
||||
.Distinct()
|
||||
.LeftJoin<DeviceAccount>((w, a) => w.UniqueValue == a.DeviceCode)
|
||||
.Select((w, a) => new UniqueValueQueryDto
|
||||
{
|
||||
Id = ws.Id,
|
||||
DeviceCode = ws.UniqueValue,
|
||||
DeviceName = da.DeviceName,
|
||||
Workshop = da.Workshop,
|
||||
Workline = da.Workline,
|
||||
Status = da.Status,
|
||||
DeviceSpecification = da.DeviceSpecification,
|
||||
ResponsiblePerson = da.ResponsiblePerson
|
||||
});
|
||||
|
||||
// 4. 查询总记录数
|
||||
pagedResult.TotalNum = baseQuery.Count();
|
||||
|
||||
// 5. 分页查询数据
|
||||
int skipCount = (pagedResult.PageIndex - 1) * pagedResult.PageSize;
|
||||
pagedResult.Result = baseQuery
|
||||
.Skip(skipCount)
|
||||
.Take(pagedResult.PageSize)
|
||||
Id = w.Id,
|
||||
DeviceCode = w.UniqueValue,
|
||||
DeviceName = a.DeviceName,
|
||||
Workshop = a.Workshop,
|
||||
Workline = a.Workline,
|
||||
Status = a.Status,
|
||||
DeviceSpecification = a.DeviceSpecification,
|
||||
ResponsiblePerson = a.ResponsiblePerson
|
||||
})
|
||||
.Skip(skipCount)
|
||||
.Take(parm.PageSize)
|
||||
.ToList();
|
||||
|
||||
return pagedResult;
|
||||
// 4. 封装分页结果
|
||||
return new PagedInfo<UniqueValueQueryDto>
|
||||
{
|
||||
PageIndex = parm.PageNum,
|
||||
PageSize = parm.PageSize,
|
||||
TotalNum = totalCount,
|
||||
Result = dataList,
|
||||
TotalPage = totalCount > 0 ? (totalCount + parm.PageSize - 1) / parm.PageSize : 0
|
||||
};
|
||||
}
|
||||
|
||||
public List<WorkshopDto> GetAccountList()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user