DailyFeePaymentRepository.cs 21 KB

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