FinancialController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using OASystem.API.OAMethodLib;
  4. using OASystem.API.OAMethodLib.File;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Dtos.Financial;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Infrastructure.Repositories.Financial;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using System.Data;
  13. namespace OASystem.API.Controllers
  14. {
  15. /// <summary>
  16. /// 财务模块
  17. /// </summary>
  18. [Route("api/[controller]/[action]")]
  19. [ApiController]
  20. public class FinancialController : ControllerBase
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly IConfiguration _config;
  24. private readonly SqlSugarClient _sqlSugar;
  25. private readonly SetDataTypeRepository _setDataTypeRep;
  26. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  27. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  28. /// <summary>
  29. /// 初始化
  30. /// </summary>
  31. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep, TeamRateRepository teamRateRep)
  32. {
  33. _mapper = mapper;
  34. _config = configuration;
  35. _daiRep = daiRep;
  36. _sqlSugar = sqlSugar;
  37. _setDataTypeRep = setDataTypeRep;
  38. _teamRateRep = teamRateRep;
  39. }
  40. #region 日付申请
  41. /// <summary>
  42. /// 获取日付申请 基础数据源
  43. /// </summary>
  44. /// <param name="dto"> 日付申请 分页 dto</param>
  45. /// <returns></returns>
  46. [HttpPost]
  47. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  48. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(DtoBase dto)
  49. {
  50. var result = await _daiRep.GetPagePriceTypeData(dto);
  51. if (result == null || result.Code != 0)
  52. {
  53. return Ok(JsonView(false, result.Msg));
  54. }
  55. var data = result.Data;
  56. return Ok(JsonView(data));
  57. }
  58. /// <summary>
  59. /// 日付申请 Page Search
  60. /// </summary>
  61. /// <param name="dto"> 日付申请 分页 dto</param>
  62. /// <returns></returns>
  63. [HttpPost]
  64. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  65. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  66. {
  67. var result = await _daiRep.GetPageSearchAll(dto);
  68. if (result == null || result.Code != 0)
  69. {
  70. return Ok(JsonView(false, result.Msg));
  71. }
  72. var data = result.Data;
  73. if (data == null)
  74. {
  75. return Ok(JsonView(false, result.Msg));
  76. }
  77. return Ok(JsonView(data));
  78. }
  79. /// <summary>
  80. /// 日付申请 Single Search By Id
  81. /// </summary>
  82. /// <param name="dto"></param>
  83. /// <returns></returns>
  84. [HttpPost]
  85. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  86. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  87. {
  88. var result = await _daiRep.GetSearchById(dto);
  89. if (result == null || result.Code != 0)
  90. {
  91. return Ok(JsonView(false, result.Msg));
  92. }
  93. return Ok(JsonView(result.Data));
  94. }
  95. /// <summary>
  96. /// 日付申请 添加
  97. /// </summary>
  98. /// <param name="dto"> 日付申请 添加 dto</param>
  99. /// <returns></returns>
  100. [HttpPost]
  101. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  102. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  103. {
  104. var result = await _daiRep.Add(dto);
  105. if (result == null || result.Code != 0)
  106. {
  107. return Ok(JsonView(false, result.Msg));
  108. }
  109. return Ok(JsonView(true));
  110. }
  111. /// <summary>
  112. /// 日付申请 Update
  113. /// </summary>
  114. /// <param name="dto"> 日付申请 修改 dto</param>
  115. /// <returns></returns>
  116. [HttpPost]
  117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  118. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  119. {
  120. var result = await _daiRep.Edit(dto);
  121. if (result == null || result.Code != 0)
  122. {
  123. return Ok(JsonView(false, result.Msg));
  124. }
  125. return Ok(JsonView(true));
  126. }
  127. /// <summary>
  128. /// 日付申请 Del
  129. /// </summary>
  130. /// <param name="dto"> 日付申请 删除 dto</param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  134. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  135. {
  136. var result = await _daiRep.Del(dto);
  137. if (result == null || result.Code != 0)
  138. {
  139. return Ok(JsonView(false, result.Msg));
  140. }
  141. return Ok(JsonView(true));
  142. }
  143. /// <summary>
  144. /// 日付申请 财务审核
  145. /// </summary>
  146. /// <param name="dto"> dto </param>
  147. /// <returns></returns>
  148. [HttpPost]
  149. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  150. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  151. {
  152. var result = await _daiRep.DelDailyPaymentAudit(dto);
  153. if (result == null || result.Code != 0)
  154. {
  155. return Ok(JsonView(false, result.Msg));
  156. }
  157. return Ok(JsonView(true));
  158. }
  159. /// <summary>
  160. /// 日付申请 Single Excel Download
  161. /// </summary>
  162. /// <param name="dto"> dto </param>
  163. /// <returns></returns>
  164. [HttpPost]
  165. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  166. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  167. {
  168. if (dto.PortType == 1 || dto.PortType == 2)
  169. {
  170. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  171. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  172. Where IsDel=0 And Id = {0} ", dto.Id);
  173. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  174. if (feeData == null)
  175. {
  176. return Ok(JsonView(false, "暂无数据!"));
  177. }
  178. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  179. Where IsDel=0 And DFPId = {0} ", dto.Id);
  180. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  181. if (feeData != null)
  182. {
  183. string userName = string.Empty;
  184. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  185. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  186. if (user != null) { userName = user.CnName; }
  187. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  188. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  189. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  190. Dictionary<string, object> pairs = new Dictionary<string, object>();
  191. List<DataTable> datas = new List<DataTable>();
  192. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  193. //{
  194. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  195. // // pairs, datas);
  196. //}
  197. //else //日付常规模板
  198. //{
  199. pairs.Clear();
  200. pairs.Add("Opertor", userName);
  201. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  202. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  203. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  204. pairs.Add("SumPrice", feeData.SumPrice);
  205. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  206. datas.Clear();
  207. datas.Add(data);
  208. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  209. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  210. return Ok(JsonView(true, msg));
  211. //}
  212. }
  213. else
  214. {
  215. return Ok(JsonView(false, "暂无数据!"));
  216. }
  217. }
  218. return Ok(JsonView(true));
  219. }
  220. #endregion
  221. #region 团组提成
  222. /// <summary>
  223. /// 提成 Page Search
  224. /// </summary>
  225. /// <param name="dto"> 提成 分页 dto</param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  229. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  230. {
  231. var data = await GroupCommission.GetCommissionPageList(dto);
  232. return Ok(JsonView(data.Data));
  233. }
  234. #endregion
  235. #region 团组汇率
  236. /// <summary>
  237. /// 团组汇率 Select数据源(团组列,汇率列)
  238. /// </summary>
  239. /// <param name="dto"></param>
  240. /// <returns></returns>
  241. [HttpPost]
  242. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  243. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  244. {
  245. try
  246. {
  247. Result teamRateData = await _teamRateRep.GetGroupRateDataSource(dto);
  248. if (teamRateData.Code != 0)
  249. {
  250. return Ok(JsonView(false, teamRateData.Msg));
  251. }
  252. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  253. }
  254. catch (Exception ex)
  255. {
  256. return Ok(JsonView(false, ex.Message));
  257. throw;
  258. }
  259. }
  260. /// <summary>
  261. /// 团组汇率 changge
  262. /// </summary>
  263. /// <returns></returns>
  264. [HttpPost]
  265. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  266. public async Task<IActionResult> ChangeGroupRateInfo()
  267. {
  268. try
  269. {
  270. Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  271. if (teamRateData.Code != 0)
  272. {
  273. return Ok(JsonView(false, teamRateData.Msg));
  274. }
  275. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  276. }
  277. catch (Exception ex)
  278. {
  279. return Ok(JsonView(false, ex.Message));
  280. throw;
  281. }
  282. }
  283. /// <summary>
  284. /// 团组汇率 Select汇率详情
  285. /// </summary>
  286. /// <param name="dto"></param>
  287. /// <returns></returns>
  288. [HttpPost]
  289. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  290. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  291. {
  292. try
  293. {
  294. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  295. if (teamRateData.Code != 0)
  296. {
  297. return Ok(JsonView(false, teamRateData.Msg));
  298. }
  299. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  300. }
  301. catch (Exception ex)
  302. {
  303. return Ok(JsonView(false, ex.Message));
  304. throw;
  305. }
  306. }
  307. #endregion
  308. }
  309. }