WageSheetRepository.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using AutoMapper;
  2. using OASystem.Domain.Dtos.PersonnelModule;
  3. using OASystem.Domain.Entities.PersonnelModule;
  4. using OASystem.Domain.ViewModels.PersonnelModule;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using SqlSugar;
  11. using Result = OASystem.Domain.Result;
  12. using Newtonsoft.Json;
  13. namespace OASystem.Infrastructure.Repositories.PersonnelModule
  14. {
  15. /// <summary>
  16. /// 人事模块 工资表 仓库
  17. /// </summary>
  18. public class WageSheetRepository : BaseRepository<Pm_WageSheet, WageSheetView>
  19. {
  20. private readonly IMapper _mapper;
  21. private Result _result;
  22. public WageSheetRepository(SqlSugarClient sqlSugar, IMapper mapper)
  23. : base(sqlSugar)
  24. {
  25. _mapper = mapper;
  26. _result = new Result();
  27. }
  28. /// <summary>
  29. /// 查询工资 List
  30. /// </summary>
  31. /// <returns></returns>
  32. public async Task<Result> Get_WageSheet_ListByYearMonthAsync(string yearMonth )
  33. {
  34. if (string.IsNullOrEmpty(yearMonth))
  35. {
  36. _result.Msg = "参数为空";
  37. return _result;
  38. }
  39. //不含公司部门
  40. // string sql = string.Format(@"Select sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.LastUpdateDt, pm_ws.Id,pm_ws.YearMonth,pm_ws.StartDate,
  41. //pm_ws.EndDate,pm_ws.WorkDays,pm_ws.RegularDays,pm_ws.UserId,pm_ws.Should,pm_ws.TotalDeductions,
  42. //pm_ws.Ex_ItemsRemark,TotalRealHair,pm_ws.WithholdingTax,pm_ws.AfterTax
  43. // From Pm_WageSheet pm_ws
  44. // Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
  45. // Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
  46. // Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'", yearMonth);
  47. //公司部门
  48. string sql = string.Format(@"Select row_number() over(order by pm_ws.UserId) as Row_Number,
  49. sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
  50. sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
  51. From Pm_WageSheet pm_ws
  52. Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
  53. Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
  54. Left Join Sys_Company sc On sys_u1.companyId = sc.Id
  55. Left Join Sys_Department sd On sys_u1.DepId = sd.Id
  56. Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'
  57. Order By UserId Asc ", yearMonth);
  58. var wageSheetList = await _sqlSugar.SqlQueryable<WageSheetItemInfoView>(sql).ToListAsync();
  59. if (wageSheetList.Count <= 0 )
  60. {
  61. _result.Msg = "暂无数据!";
  62. return _result;
  63. }
  64. wageSheetList = wageSheetList.OrderBy(it => it.Row_Number).ToList();
  65. _result.Code = 0;
  66. _result.Msg = "查询成功!";
  67. _result.Data = wageSheetList;
  68. return _result;
  69. }
  70. /// <summary>
  71. /// 查询工资 Info
  72. /// </summary>
  73. /// <returns></returns>
  74. public async Task<Result> Get_WageSheet_InfoByIdAsync(int id)
  75. {
  76. string sql = string.Format(@"Select sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.* From Pm_WageSheet pm_ws
  77. Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
  78. Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
  79. Where pm_ws.IsDel = 0 And pm_ws.Id = {0}", id);
  80. var wageSheetInfo = await _sqlSugar.SqlQueryable<WageSheetInfoView>(sql).FirstAsync();
  81. if (wageSheetInfo != null)
  82. {
  83. _result.Code = 0;
  84. _result.Msg = "查询成功!";
  85. _result.Data = wageSheetInfo;
  86. }
  87. return _result;
  88. }
  89. /// <summary>
  90. /// 修改
  91. /// </summary>
  92. /// <returns></returns>
  93. public async Task<Result> Post_WageSheet_AddOrEditAsync(WageAddOrEditDto dto,Pm_WageSheet pm_WageSheet)
  94. {
  95. if (dto.Status == 1) //添加
  96. {
  97. //var select = await _sqlSugar.Queryable<Pm_WageSheet>().
  98. // Where(it => it.IsDel == 0 && it.UserId == pm_WageSheet.UserId && it.YearMonth == pm_WageSheet.YearMonth).
  99. // FirstAsync();
  100. //if (select != null)
  101. //{
  102. // _result.Msg = "该用户 "+ pm_WageSheet.YearMonth + " 工资信息已存在,请前往修改!";
  103. // return _result;
  104. //}
  105. int add = await _sqlSugar.Insertable(pm_WageSheet).ExecuteReturnIdentityAsync();
  106. if (add <= 0)
  107. {
  108. _result.Msg = "操作失败!";
  109. return _result;
  110. }
  111. }
  112. else if(dto.Status == 2) //修改
  113. {
  114. int update = await _sqlSugar.Updateable(pm_WageSheet)
  115. .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime,it.DeleteUserId,it.DeleteTime })
  116. .WhereColumns(it => new { it.Id })
  117. .ExecuteCommandAsync();
  118. if (update <= 0)
  119. {
  120. _result.Msg = "操作失败!";
  121. return _result;
  122. }
  123. }
  124. else{
  125. _result.Msg = "请输入操作状态!1 添加 2 修改";
  126. }
  127. _result.Code = 0;
  128. _result.Msg = "操作成功!";
  129. return _result;
  130. }
  131. /// <summary>
  132. /// 删除
  133. /// </summary>
  134. /// <returns></returns>
  135. public async Task<Result> Post_WageSheet_DelAsync(WageDelDto dto)
  136. {
  137. Pm_WageSheet pm_WageSheet = new Pm_WageSheet()
  138. {
  139. Id = dto.Id,
  140. DeleteUserId = dto.UserId,
  141. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  142. LastUpdateUserId = dto.UserId,
  143. IsDel = 1
  144. };
  145. int update = await _sqlSugar.Updateable(pm_WageSheet)
  146. .UpdateColumns(it => new { it.DeleteUserId, it.DeleteTime, it.IsDel, it.LastUpdateUserId, it.LastUpdateDt })
  147. .WhereColumns(it => new { it.Id })
  148. .ExecuteCommandAsync();
  149. if (update <= 0)
  150. {
  151. _result.Msg = "操作失败!";
  152. return _result;
  153. }
  154. _result.Code = 0;
  155. _result.Msg = "操作成功!";
  156. return _result;
  157. }
  158. }
  159. }