using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using AutoMapper;
|
using SqlSugar;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_DTO.Telescopic;
|
using WIDESEAWCS_ITelescopicService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_TelescopicService
|
{
|
public class LoginhsyService : ServiceBase<Dt_Loginhsy, IRepository<Dt_Loginhsy>>, ILoginhsyService
|
{
|
public IRepository<Dt_Loginhsy> Repository => BaseDal;
|
private readonly IRepository<Sys_User> _user;
|
|
public LoginhsyService(IRepository<Sys_User> user, IRepository<Dt_Loginhsy> BaseDal) : base(BaseDal)
|
{
|
_user = user;
|
}
|
|
public WebResponseContent LoginRecord(PaginationDTO pagination)
|
{
|
try
|
{
|
int totalCount = 0;
|
|
var sys = _user.Db.Queryable<Sys_User>();
|
var main = Db.Queryable<Dt_Loginhsy>();
|
|
//模糊查询
|
var query = sys.InnerJoin<Dt_Loginhsy>((a, b) => a.UserName == b.UserName);
|
if (!string.IsNullOrEmpty(pagination.searchKeyword))
|
{
|
query = query.Where((a, b) =>
|
a.UserTrueName.Contains(pagination.searchKeyword) ||
|
a.Userteam.Contains(pagination.searchKeyword) ||
|
b.OpCenten.Contains(pagination.searchKeyword));
|
}
|
|
//时间查询
|
if (pagination.startDate.HasValue && pagination.endDate.HasValue)
|
{
|
query = query.Where((a, b) => b.LoginTiem >= pagination.startDate.Value && b.LoginTiem <= pagination.endDate.Value);
|
}
|
|
// 排序处理
|
if (!string.IsNullOrEmpty(pagination.sortField))
|
{
|
//isAsc:这是一个布尔值,判断排序是升序 (true)"asc" ,还是降序 (false) "desc"
|
var isAsc = pagination.sortOrder?.ToLower() == "asc";//pagination.sortOrder 不为空,则调用 ToLower() 方法将其转为小写字母
|
|
query = pagination.sortField.ToLower() switch
|
{
|
//如果isAsc 为ture就执行query.OrderBy((a, b) => b.LoginTiem, OrderByType.Asc)升序排序,
|
//如果为fales就执行query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc)降序排序
|
"logintiem" => isAsc ? query.OrderBy((a, b) => b.LoginTiem, OrderByType.Asc)
|
: query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc),
|
|
"outtiem" => isAsc ? query.OrderBy((a, b) => b.OutTiem, OrderByType.Asc)
|
: query.OrderBy((a, b) => b.OutTiem, OrderByType.Desc),
|
|
//"usertruename" => isAsc ? query.OrderBy((a, b) => a.UserTrueName, OrderByType.Asc)
|
//: query.OrderBy((a, b) => a.UserTrueName, OrderByType.Desc),
|
_ => query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc) // 默认按登入时间降序
|
};
|
}
|
else
|
{
|
// 默认按 LoginTiem 降序
|
query = query.OrderBy((a, b) => b.LoginTiem, OrderByType.Desc);
|
}
|
|
|
//返回结果
|
var result = query.Select((a, b) => new
|
{
|
a.User_Id,
|
a.UserTrueName,
|
a.Userteam,
|
a.HeadImageUrl,
|
b.ID,
|
b.LoginTiem,
|
b.OutTiem,
|
b.OpCenten,
|
}).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 };
|
}
|
}
|
|
|
|
|
public WebResponseContent OutLoginTime(string account)
|
{
|
try
|
{
|
var log = BaseDal.QueryData(x=>x.UserName== account).OrderByDescending(x=>x.UserName).FirstOrDefault();
|
if (log==null)
|
{
|
return new WebResponseContent { Status = false, Message = "失败" };
|
}
|
log.OutTiem = DateTime.Now;
|
BaseDal.UpdateData(log);
|
return new WebResponseContent { Status = true, Data = log.OutTiem };
|
}
|
catch (Exception ex)
|
{
|
|
return new WebResponseContent { Status = false, Message = "错误信息"+ex };
|
}
|
}
|
}
|
|
}
|