DailyFeePaymentRepository.cs 21 KB

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