GhbzGhxmCgRepository.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Microsoft.AspNetCore.Http;
  2. using QM.KJGH.CGGL.IRepository;
  3. using QM.KJGH.CGGL.Model.Enums;
  4. using QM.KJGH.CGGL.Model.Ghxms;
  5. using QM.KJGH.Model;
  6. using QM.KJGH.Model.KJGH;
  7. using QM.OrmSqlSugar;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using WS;
  14. using WS.AutoMapper;
  15. using WS.IO;
  16. using WS.IO.Upload;
  17. namespace QM.KJGH.CGGL.Repository
  18. {
  19. public class GhbzGhxmCgRepository : SqlSugarRepository<GhbzGhxmCg>, IGhbzGhxmCgRepository
  20. {
  21. public async Task<bool> Add(GhbzGhxmCg ghbzGhxmCg, IFormFileCollection files, string currUser)
  22. {
  23. if (ghbzGhxmCg == null)
  24. throw new UseArgumentException("请求参数错误");
  25. var db = DbClient();
  26. var list = new List<GhbzGhxmCg>();
  27. foreach (var item in files)
  28. {
  29. var cgmlModel = db.Queryable<GhbzGhxmCgml>().First(u => u.BSM == ghbzGhxmCg.ML_BSM);
  30. if (null == cgmlModel)
  31. throw new UseArgumentException("未找到对应目录");
  32. string path = FileManage.Instance.ToFullPath(@$"{cgmlModel.MLMC}");
  33. var uFile = FileUpload.SaveFile(item, path);
  34. ghbzGhxmCg.BSM = Guid.NewGuid().ToString("N");
  35. ghbzGhxmCg.CTIME = DateTime.Now;
  36. ghbzGhxmCg.CGLJ = uFile.Path;
  37. ghbzGhxmCg.CGMC = uFile.Name;
  38. ghbzGhxmCg.CGKZM = System.IO.Path.GetExtension(uFile.Name);
  39. ghbzGhxmCg.CGDX = (int)uFile.Size;
  40. ghbzGhxmCg.CUSER = currUser;
  41. list.Add(ghbzGhxmCg);
  42. }
  43. var result = await InsertListAsync(list);
  44. return result;
  45. }
  46. public async Task<bool> Delete(List<string> bsmlist)
  47. {
  48. if (bsmlist.Count < 0)
  49. throw new UseArgumentException("请求参数错误");
  50. //Expression<Func<GhbzGhxm, bool>> conditionwhere = i => i.BSM == bsm;
  51. try
  52. {
  53. await UpdateAsync(u => new GhbzGhxmCg { IS_DELETE = EnumDelete.Deleted }, i => bsmlist.Contains(i.BSM));
  54. }
  55. catch (Exception ex)
  56. {
  57. WS.Log.RunLog.Error(ex);
  58. throw new UseArgumentException("服务器错误");
  59. }
  60. return true;
  61. }
  62. public async Task<List<GhbzGhxmCgView>> QueryByXmBsm(string xmbsm, string mlbsm)
  63. {
  64. if (string.IsNullOrEmpty(xmbsm) || string.IsNullOrEmpty(mlbsm))
  65. throw new UseArgumentException("请求参数错误");
  66. var result = (await GetListAsync(u => u.XM_BSM == xmbsm && u.ML_BSM == mlbsm && u.IS_DELETE == EnumDelete.Mormal)).MapTo<GhbzGhxmCg, GhbzGhxmCgView>();
  67. return result;
  68. }
  69. }
  70. }