using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_DTO.Telescopic;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_ITelescopicService
|
{
|
public class MaintenanceTeamService : ServiceBase<Dt_MaintenanceTeam, IRepository<Dt_MaintenanceTeam>>, IMaintenanceTeamService
|
{
|
public IRepository<Dt_MaintenanceTeam> Repository => BaseDal;
|
private readonly IRepository<Sys_User> _user;
|
|
public MaintenanceTeamService(IRepository<Dt_MaintenanceTeam> BaseDal,IRepository<Sys_User> user) : base(BaseDal)
|
{
|
_user = user;
|
}
|
|
|
/// <summary>
|
/// 检修设置记录
|
/// </summary>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent MaintenanceSettingRecord(PaginationDTO pagination)
|
{
|
try
|
{
|
int totalCount = 0;
|
|
var sys = _user.Db.Queryable<Sys_User>();
|
var main = Db.Queryable<Dt_MaintenanceTeam>();
|
|
|
|
var query = sys.InnerJoin<Dt_MaintenanceTeam>((a, b) => a.UserTrueName == b.OperatorName)
|
;
|
|
|
//模糊查询
|
if (!string.IsNullOrEmpty(pagination.searchKeyword))
|
{
|
|
query = query.Where((a, b) =>
|
b.OperatorName.Contains(pagination.searchKeyword) ||
|
b.TeamName.Contains(pagination.searchKeyword) ||
|
b.Modifier.Contains(pagination.searchKeyword)
|
);
|
}
|
//时间查询
|
if (pagination.startDate.HasValue && pagination.endDate.HasValue)
|
{
|
query = query.Where((a, b) => b.DistributionTime >= pagination.startDate && b.DistributionTime <= pagination.endDate);
|
}
|
//排序
|
if (!string.IsNullOrEmpty(pagination.sortField))
|
{
|
var isAsc = pagination.sortOrder?.ToLower() == "asc";
|
query = pagination.sortField.ToLower() switch
|
{
|
//"OperatorName" => isAsc ? query.OrderBy((a, b) => b.OperatorName) : query.OrderByDescending((a, b) => b.OperatorName),
|
|
//"TeamName" => isAsc ? query.OrderBy((a, b) => b.TeamName) : query.OrderByDescending((a, b) => b.TeamName),
|
|
"distributiontime" => isAsc ? query.OrderBy((a, b) => b.DistributionTime) : query.OrderByDescending((a, b) => b.DistributionTime),
|
|
//"Modifier" => isAsc ? query.OrderBy((a, b) => b.Modifier) : query.OrderByDescending((a, b) => b.Modifier),
|
|
_ => query.OrderByDescending((a, b) => b.CreateDate), // 默认按创建时间降序
|
};
|
|
}
|
else
|
{
|
//默认按创建时间降序排序
|
query = query.OrderByDescending((a, b) => b.CreateDate);
|
}
|
|
//// 如果不是管理员,根据部门过滤
|
//if (pagination.account != "admin")
|
//{
|
// var currentUser = _user.Db.Queryable<Sys_User>()
|
// .Where(u => u.UserName == pagination.account)
|
// .First();
|
|
// if (currentUser == null)
|
// {
|
// return new WebResponseContent { Status = false, Data = "未获取到用户信息" };
|
// }
|
|
// int? deptId = currentUser.Dept_Id;
|
|
// query = query.Where((a, b) => a.Dept_Id == deptId);
|
//}
|
|
|
//返回结果
|
var result = query
|
.Select((a, b) => new
|
{
|
b.ID,
|
a.User_Id,
|
a.Dept_Id,//轨道站
|
a.IsLeader,//是否是班长
|
a.Role_Id,
|
a.RoleName,//角色名称
|
a.Unit,//单位
|
b.IPAddress,//电脑ip地址
|
b.OperatorName,
|
b.TeamName,//班组
|
b.MaintenanceStatus,//检修状态
|
b.Creater,
|
a.HeadImageUrl,
|
b.DistributionTime,
|
b.EndTime,
|
b.Modifier,
|
}).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
|
return new WebResponseContent
|
{
|
Status = true,
|
Data = new
|
{
|
TotalCount = totalCount,//总数
|
PageIndex = pagination.pageIndex,//页数
|
PageSize = pagination.pageSize,//一页多少个数据
|
Items = result
|
}
|
};
|
|
}
|
catch (Exception ex)
|
{
|
|
return new WebResponseContent { Status = false, Message = "错误信息:" + ex.Message };
|
}
|
|
}
|
|
}
|
}
|