DailyFeePaymentRepository.cs 23 KB

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