Blame view

netcore/src/Modularity/Extend/NCC.Extend/LqMonthlyEmployeeFactQueryService.cs 3.98 KB
db9c79c0   “wangming”   feat: punch-based...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using NCC.Common.Filter;
  using NCC.Dependency;
  using NCC.DynamicApiController;
  using NCC.Extend.Models;
  using NCC.FriendlyException;
  using NCC.System.Entitys.Permission;
  using Microsoft.AspNetCore.Mvc;
  using SqlSugar;
  
  namespace NCC.Extend
  {
      /// <summary>
      /// 自然月内有业务事实的员工名单(与算薪扩大加载口径一致,含月中离职仍可能有事实者)。
      /// </summary>
      [ApiDescriptionSettings(Tag = "绿纤月度业务人员", Name = "LqMonthlyEmployeeFact", Order = 202)]
      [Route("api/Extend/LqMonthlyEmployeeFact")]
      public class LqMonthlyEmployeeFactQueryService : IDynamicApiController, ITransient
      {
          private readonly ISqlSugarClient _db;
  
          public LqMonthlyEmployeeFactQueryService(ISqlSugarClient db)
          {
              _db = db;
          }
  
          /// <summary>
          /// 分页查询指定年月中出现过考勤/业绩/消耗/金三角/工资归档等事实的用户(未软删)。
          /// </summary>
          /// <param name="year"></param>
          /// <param name="month"> 1-12</param>
          /// <param name="keyword">按姓名或账号模糊(可选)</param>
          /// <param name="page">分页</param>
          [HttpGet("employees")]
          public async Task<dynamic> GetEmployeesWithMonthFacts(
              [FromQuery] int year,
              [FromQuery] int month,
              [FromQuery] string keyword,
              [FromQuery] PageInputBase page)
          {
              if (year < 1990 || year > 2100 || month < 1 || month > 12)
              {
                  throw NCCException.Oh("year/month 参数不合法");
              }
  
              page ??= new PageInputBase();
              var factIds = await LqMonthlyEmployeeFactHelper.GetUserIdsWithMonthBusinessFactsAsync(_db, year, month);
              if (factIds.Count == 0)
              {
                  return PageResult<MonthlyEmployeeFactRowOutput>.SqlSugarPageResult(
                      new SqlSugarPagedList<MonthlyEmployeeFactRowOutput>
                      {
                          list = new List<MonthlyEmployeeFactRowOutput>(),
                          pagination = new PagedModel
                          {
                              PageIndex = page.currentPage,
                              PageSize = page.pageSize,
                              Total = 0
                          }
                      });
              }
  
              var q = _db.Queryable<UserEntity>()
                  .Where(u => factIds.Contains(u.Id) && u.DeleteMark == null);
              if (!string.IsNullOrWhiteSpace(keyword))
              {
                  var kw = keyword.Trim();
                  q = q.Where(u => u.RealName.Contains(kw) || u.Account.Contains(kw));
              }
  
              var paged = await q
                  .OrderBy(u => u.RealName)
                  .Select(u => new MonthlyEmployeeFactRowOutput
                  {
                      EmployeeId = u.Id,
                      RealName = u.RealName,
                      Account = u.Account,
                      Gw = u.Gw,
                      EnabledMark = u.EnabledMark,
                      IsOnJob = u.IsOnJob
                  })
                  .ToPagedListAsync(page.currentPage, page.pageSize);
  
              return PageResult<MonthlyEmployeeFactRowOutput>.SqlSugarPageResult(paged);
          }
  
          /// <summary>
          /// 返回指定年月事实人员主键列表(不分页,供内部或其它服务联调;数据量大时慎用)。
          /// </summary>
          [HttpGet("employee-ids")]
          public async Task<dynamic> GetEmployeeIdsWithMonthFacts([FromQuery] int year, [FromQuery] int month)
          {
              if (year < 1990 || year > 2100 || month < 1 || month > 12)
              {
                  throw NCCException.Oh("year/month 参数不合法");
              }
  
              var ids = await LqMonthlyEmployeeFactHelper.GetUserIdsWithMonthBusinessFactsAsync(_db, year, month);
              return new { total = ids.Count, employeeIds = ids };
          }
      }
  }