DailyFeePaymentRepository.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos;
  4. using OASystem.Domain.Dtos.Financial;
  5. using OASystem.Domain.Entities.Financial;
  6. using OASystem.Domain.ViewModels.Financial;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel.Design;
  11. using System.Linq;
  12. using System.Runtime.Intrinsics.Arm;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace OASystem.Infrastructure.Repositories.Financial
  16. {
  17. /// <summary>
  18. /// 财务 - 日付申请
  19. /// </summary>
  20. public class DailyFeePaymentRepository : BaseRepository<Fin_DailyFeePayment, Fin_DailyFeePaymentView>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly System.SetDataTypeRepository _setDataTypeRep;
  24. private readonly System.UsersRepository _UsersRep;
  25. private readonly System.CompanyRepository _CompanyRep;
  26. public DailyFeePaymentRepository(SqlSugarClient sqlSugar, IMapper mapper, System.SetDataTypeRepository setDataTypeRep,
  27. UsersRepository usersRep, CompanyRepository companyRep)
  28. : base(sqlSugar)
  29. {
  30. this._mapper = mapper;
  31. this._setDataTypeRep = setDataTypeRep;
  32. this._UsersRep = usersRep;
  33. this._CompanyRep = companyRep;
  34. }
  35. /// <summary>
  36. /// 日付申请查询 使用的数据源
  37. /// </summary>
  38. /// <param name="dto"></param>
  39. /// <returns></returns>
  40. public async Task<Result> GetPagePriceTypeData(DtoBase dto)
  41. {
  42. Result result = new Result() { Code = -2 };
  43. dynamic? DailyFeePaymentList = null;
  44. if (dto.PortType == 1 || dto.PortType == 2) //web
  45. {
  46. var setTypeData = _setDataTypeRep.QueryDto<Sys_SetDataType, Fin_DailyFeePaymentPagePriceTypeView>().ToList();
  47. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  48. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  49. var priceTypeData = setTypeData.Where(s => s.Id == 48 || s.Id == 49 || s.Id == 50 || s.Id == 51 || s.Id == 55).ToList();
  50. var priceSubTypeData = setData.Where(s => s.STid == 48 || s.STid == 49 || s.STid == 50 || s.STid == 51 || s.STid == 55).ToList();
  51. //员工姓名列表
  52. var userNameData = await _UsersRep.GetUserNameList(dto.PortType);
  53. //62 公转 63 私转
  54. var feeMarkTypeData = setTypeData.Where(s => s.Id == 62 || s.Id == 63).ToList();
  55. var feeMarkSubTypeData = setData.Where(s => s.STid == 62 || s.STid == 63).ToList();
  56. var companyNameData = await _CompanyRep.GetCompanyNameData();
  57. DailyFeePaymentList = new Fin_DailyFeePaymentPagePriceTypeDataView
  58. {
  59. FeeTypeData = priceTypeData,
  60. FeeSubTypeData = priceSubTypeData,
  61. UserNameData = userNameData.Data,
  62. FeeMarkTypeData = feeMarkTypeData,
  63. FeeMarkSubTypeData = feeMarkSubTypeData,
  64. CompanyNameData = companyNameData.Data
  65. };
  66. }
  67. result.Code = 0;
  68. result.Msg = "查询成功!";
  69. result.Data = DailyFeePaymentList;
  70. return result;
  71. }
  72. /// <summary>
  73. /// 日付申请 page 查询
  74. /// </summary>
  75. /// <param name="dto"></param>
  76. /// <returns></returns>
  77. public async Task<Result> GetPageSearchAll(PageDailyFeePaymentDto dto)
  78. {
  79. Result result = new Result() { Code = -2 };
  80. ListViewBase<Fin_DailyFeePaymentPageListView> dailyFeePaymentPageList = new ListViewBase<Fin_DailyFeePaymentPageListView>()
  81. {
  82. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  83. };
  84. #region sql条件处理
  85. string sqlWhere = "";
  86. if (dto.CompanyId != -1) //公司
  87. sqlWhere += string.Format(" And dfp.CompanyId = {0}", dto.CompanyId);
  88. if (dto.FinancialAuditStatus != -1) //财务审核
  89. sqlWhere += string.Format(" And dfp.FAudit = {0}", dto.FinancialAuditStatus);
  90. if (dto.ManagerAuditStatus != -1) //总经理审核
  91. sqlWhere += string.Format(" And dfp.MAudit = {0}", dto.ManagerAuditStatus);
  92. if (dto.FeeTypeId != -1) //费用类型
  93. {
  94. if (dto.FeeSubTypeId != -1) //子类处理
  95. {
  96. sqlWhere += string.Format(" And dfp.PriceTypeId = {0}", dto.FeeSubTypeId);
  97. }
  98. else
  99. {
  100. var setData = _setDataTypeRep.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.FeeTypeId).ToList();
  101. if (setData.Count > 0)
  102. {
  103. string setDataIds = "";
  104. foreach (var item in setData)
  105. {
  106. setDataIds += item.Id + ",";
  107. }
  108. if (setDataIds.Length > 0)
  109. {
  110. setDataIds = setDataIds.Substring(0, setDataIds.Length - 1);
  111. sqlWhere += string.Format(" And dfp.PriceTypeId In ({0})", setDataIds);
  112. }
  113. }
  114. }
  115. }
  116. if (!string.IsNullOrEmpty(dto.FeeDesc))
  117. sqlWhere += string.Format(" And dfp.Instructions Like '%{0}%'", dto.FeeDesc);
  118. if (dto.CreateUserId != -1)
  119. sqlWhere += string.Format(" And dfp.CreateUserId = {0}", dto.CreateUserId);
  120. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  121. int endIndex = startIndex + dto.PageSize - 1;
  122. string sqlPage = string.Format(@"Select * From (
  123. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  124. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  125. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  126. dfp.PriceTypeId
  127. From Fin_DailyFeePayment dfp
  128. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  129. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  130. Where dfp.IsDel=0 {0}
  131. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  132. string sqlCount = string.Format(@"Select COUNT(1) as Count From (
  133. Select dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  134. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  135. dfp.PriceTypeId
  136. From Fin_DailyFeePayment dfp
  137. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  138. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  139. Where dfp.IsDel=0 {0}
  140. ) temp ", sqlWhere);
  141. #endregion
  142. if (dto.PortType == 1 || dto.PortType == 2) //web
  143. {
  144. //Fin_DailyFeePaymentPageCount
  145. var dailyFeePaymentCount = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentPageCount>(sqlCount).FirstAsync();
  146. var DailyFeePaymentData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentPageListView>(sqlPage).ToListAsync();
  147. int totalCount = dailyFeePaymentCount.Count;
  148. dailyFeePaymentPageList = new ListViewBase<Fin_DailyFeePaymentPageListView>
  149. {
  150. CurrPageIndex = dto.PageIndex,
  151. CurrPageSize = dto.PageSize,
  152. DataCount = totalCount,
  153. DataList = DailyFeePaymentData
  154. };
  155. }
  156. result.Code = 0;
  157. result.Msg = "查询成功!";
  158. result.Data = dailyFeePaymentPageList;
  159. return result;
  160. }
  161. /// <summary>
  162. /// 日付申请 single 查询 By Id
  163. /// </summary>
  164. /// <param name="dto"></param>
  165. /// <returns></returns>
  166. public async Task<Result> GetSearchById(SearchDailyFeePaymentDto dto)
  167. {
  168. Result result = new Result() { Code = -2 };
  169. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  170. if (dto.PortType == 1 || dto.PortType == 2) //web
  171. {
  172. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  173. Where IsDel=0 And Id = {0} ", dto.Id);
  174. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  175. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  176. Where IsDel=0 And DFPId = {0} ", dto.Id);
  177. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  178. result.Code = 0;
  179. result.Msg = "查询成功!";
  180. result.Data = feeData;
  181. }
  182. return result;
  183. }
  184. /// <summary>
  185. /// 日付申请 添加
  186. /// </summary>
  187. /// <param name="dto"></param>
  188. /// <returns></returns>
  189. public async Task<Result> Add(AddDailyFeePaymentDto dto)
  190. {
  191. Result result = new Result() { Code = -2 };
  192. _sqlSugar.BeginTran();
  193. try
  194. {
  195. Fin_DailyFeePayment _fee = _mapper.Map<Fin_DailyFeePayment>(dto);
  196. _fee.CreateUserId = dto.UserId;
  197. int? feeId = await _sqlSugar.Insertable(_fee).ExecuteReturnIdentityAsync();
  198. if (dto.FeeContents.Count > 0)
  199. {
  200. List<Fin_DailyFeePaymentContent> _feeContents = _mapper.Map<List<Fin_DailyFeePaymentContent>>(dto.FeeContents);
  201. foreach (var item in _feeContents)
  202. {
  203. item.DFPId = feeId == null ? -1 : Convert.ToInt32(feeId);
  204. item.CreateUserId = dto.UserId;
  205. }
  206. await _sqlSugar.Insertable(_feeContents).ExecuteCommandAsync();
  207. }
  208. _sqlSugar.CommitTran();
  209. result.Code = 0;
  210. }
  211. catch (Exception ex)
  212. {
  213. _sqlSugar.RollbackTran();
  214. result.Msg = ex.Message;
  215. }
  216. return result;
  217. }
  218. /// <summary>
  219. /// 日付申请 编辑
  220. /// </summary>
  221. /// <param name="dto"></param>
  222. /// <returns></returns>
  223. public async Task<Result> Edit(EditDailyFeePaymentDto dto)
  224. {
  225. Result result = new Result() { Code = -2 };
  226. _sqlSugar.BeginTran();
  227. try
  228. {
  229. Fin_DailyFeePayment _fee = _mapper.Map<Fin_DailyFeePayment>(dto);
  230. _fee.CreateUserId = dto.UserId;
  231. int? editFeeStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
  232. .Where(a => a.Id == dto.Id)
  233. .SetColumns(a => new Fin_DailyFeePayment
  234. {
  235. Instructions = dto.Instructions,
  236. SumPrice = dto.SumPrice,
  237. TransferTypeId = dto.TransferTypeId,
  238. PriceTypeId = dto.PriceTypeId,
  239. CompanyId = dto.CompanyId,
  240. }).ExecuteCommandAsync();
  241. List<Fin_DailyFeePaymentContent> _feeContents = _mapper.Map<List<Fin_DailyFeePaymentContent>>(dto.FeeContents);
  242. await _sqlSugar.Updateable<Fin_DailyFeePaymentContent>()
  243. .Where(a => a.DFPId == _fee.Id)
  244. .SetColumns(a => new Fin_DailyFeePaymentContent
  245. {
  246. IsDel = 1,
  247. DeleteUserId = _fee.CreateUserId,
  248. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  249. }).ExecuteCommandAsync();
  250. if (_feeContents.Count > 0)
  251. {
  252. foreach (var item in _feeContents)
  253. {
  254. item.DFPId = _fee.Id;
  255. item.CreateUserId = dto.UserId;
  256. }
  257. if (_feeContents.Count > 0)
  258. {
  259. await _sqlSugar.Insertable(_feeContents).ExecuteCommandAsync();
  260. }
  261. }
  262. _sqlSugar.CommitTran();
  263. result.Code = 0;
  264. }
  265. catch (Exception ex)
  266. {
  267. _sqlSugar.RollbackTran();
  268. result.Msg = ex.Message;
  269. }
  270. return result;
  271. }
  272. /// <summary>
  273. /// 日付申请 删除
  274. /// </summary>
  275. /// <param name="dto"></param>
  276. /// <returns></returns>
  277. public async Task<Result> Del(DelDailyFeePaymentDto dto)
  278. {
  279. Result result = new Result() { Code = -2 };
  280. int? delFeeStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
  281. .Where(a => a.Id == dto.Id)
  282. .SetColumns(a => new Fin_DailyFeePayment
  283. {
  284. IsDel =1,
  285. DeleteUserId = dto.Id,
  286. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  287. }).ExecuteCommandAsync();
  288. result.Code = 0;
  289. return result;
  290. }
  291. /// <summary>
  292. /// 日付申请 审核
  293. /// </summary>
  294. /// <param name="dto"></param>
  295. /// <returns></returns>
  296. public async Task<Result> DelDailyPaymentAudit(DP_AuditStatusDto dto)
  297. {
  298. Result result = new Result() { Code = -2 };
  299. if (dto.AuditType == 1) //财务审核
  300. {
  301. int? auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
  302. .Where(a => a.Id == dto.Id)
  303. .SetColumns(a => new Fin_DailyFeePayment
  304. {
  305. FAudit = dto.AuditStatus,
  306. FAuditDate = DateTime.Now,
  307. }).ExecuteCommandAsync();
  308. if (auditStatus != null && auditStatus > 0)
  309. result.Code = 0;
  310. else
  311. result.Msg = "财务审核操作失败";
  312. }
  313. else if (dto.AuditType == 2) //总经理
  314. {
  315. int? auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
  316. .Where(a => a.Id == dto.Id)
  317. .SetColumns(a => new Fin_DailyFeePayment
  318. {
  319. MAudit = dto.AuditStatus,
  320. MAuditDate = DateTime.Now,
  321. }).ExecuteCommandAsync();
  322. if (auditStatus != null && auditStatus > 0)
  323. result.Code = 0;
  324. else
  325. result.Msg = "总经理审核操作失败";
  326. }
  327. return result;
  328. }
  329. }
  330. }