DailyFeePaymentRepository.cs 23 KB

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