颐和api

AppVersion3DController.cs 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using MadRunFabric.Common;
  7. using MessageApi.IRepositories;
  8. using Microsoft.Extensions.Logging;
  9. using MadRunFabric.Model.MessageApi;
  10. using System.Security.Claims;
  11. using MongoDB.Driver;
  12. using Microsoft.AspNetCore.Authorization;
  13. namespace MessageApi.Controllers.Application
  14. {
  15. /// <summary>
  16. /// 3D版本 - 升级提示接口
  17. /// </summary>
  18. [Authorize]
  19. [ApiVersion("6.0")]
  20. [Produces("application/json")]
  21. [Route("api/[controller]")]
  22. public class AppVersion3DController : BaseController
  23. {
  24. private readonly ILogger<AppVersion3DController> _logger;
  25. private readonly IApp_Version3DRepository _app_version3DRepository;
  26. public AppVersion3DController(
  27. ILogger<AppVersion3DController> logger,
  28. IApp_Version3DRepository app_version3DRepository
  29. )
  30. {
  31. _logger = logger;
  32. _app_version3DRepository = app_version3DRepository;
  33. }
  34. /// <summary>
  35. /// 获取3D版本分页
  36. /// </summary>
  37. [HttpGet("getlistbypage")]
  38. public IActionResult GetListsByPageAsync(int apptype, string projectid, string keyword, string stime, string etime, int pageindex = 1, int pagesize = 10)
  39. {
  40. int recordCount = 0;
  41. var result = _app_version3DRepository.GetListsByPage(apptype, projectid, keyword, stime, etime, pageindex, pagesize, out recordCount);
  42. var obj = new
  43. {
  44. rows = result.ToList(),
  45. total = recordCount
  46. };
  47. return Success("获取成功", obj);
  48. }
  49. /// <summary>
  50. /// 获取3D版本详情
  51. /// </summary>
  52. /// <param name="id"></param>
  53. /// <returns></returns>
  54. [HttpGet("getdetailes")]
  55. public IActionResult GetDetailsAsync(string id)
  56. {
  57. var model = _app_version3DRepository.GetDetails(id);
  58. return Success("获取成功", model);
  59. }
  60. /// <summary>
  61. /// 添加3D版本信息
  62. /// </summary>
  63. /// <param name="projectid"></param>
  64. /// <param name="versionname"></param>
  65. /// <param name="versioncode"></param>
  66. /// <param name="ordernum"></param>
  67. /// <param name="downurl"></param>
  68. /// <param name="note"></param>
  69. /// <returns></returns>
  70. [HttpPost("add")]
  71. public async Task<IActionResult> AddAsync(int apptype, string projectid, string versionname, string versioncode, List<FileBaseModel> downurl, string note)
  72. {
  73. string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  74. if (string.IsNullOrEmpty(versionname))
  75. return Error("版本名称不能为空");
  76. if (string.IsNullOrEmpty(versioncode))
  77. return Error("版本号不能为空");
  78. var model = new App_Version3D();
  79. model.apptype = apptype;
  80. model.projectid = projectid;
  81. model.versionname = versionname;
  82. model.versioncode = versioncode;
  83. model.createby = usercode;
  84. model.createtime = DateTime.Now.ToLocalTime();
  85. model.downurl = downurl.ToList<FileBaseModel>();
  86. model.note = note;
  87. model.isdelete = 0;
  88. bool b = await _app_version3DRepository.Add(model);
  89. if (b)
  90. return Success("添加成功");
  91. //日志
  92. _logger.LogError($"版本名称:{versionname},版本号:{versioncode}添加失败");
  93. return Error("添加失败");
  94. }
  95. /// <summary>
  96. /// 修改3D版本信息
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <param name="projectid"></param>
  100. /// <param name="versionname"></param>
  101. /// <param name="versioncode"></param>
  102. /// <param name="ordernum"></param>
  103. /// <param name="downurl"></param>
  104. /// <param name="httpurl"></param>
  105. /// <param name="note"></param>
  106. /// <returns></returns>
  107. [HttpPost("update")]
  108. public async Task<IActionResult> UpdateAsync(string id,int apptype, string projectid, string versionname, string versioncode, int ordernum, List<FileBaseModel> downurl, string httpurl, string note)
  109. {
  110. string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  111. if (string.IsNullOrEmpty(id))
  112. return Error("参数错误");
  113. if (string.IsNullOrEmpty(versionname))
  114. return Error("版本名称不能为空");
  115. if (string.IsNullOrEmpty(versioncode))
  116. return Error("版本号不能为空");
  117. var model = new App_Version3D();
  118. model = await _app_version3DRepository.GetSingle(id);
  119. if (model == null)
  120. return Error("操作失败");
  121. model.apptype = apptype;
  122. model.projectid = projectid;
  123. model.versionname = versionname;
  124. model.versioncode = versioncode;
  125. model.createby = usercode;
  126. model.updatetime = DateTime.Now.ToLocalTime();
  127. model.downurl = downurl.ToList<FileBaseModel>();
  128. model.note = note;
  129. bool b = await _app_version3DRepository.Update(model);
  130. if (b)
  131. return Success("保存成功");
  132. //日志
  133. _logger.LogError($"版本名称:{versionname},版本号:{versioncode}修改失败");
  134. return Error("保存失败");
  135. }
  136. /// <summary>
  137. /// 删除3D版本信息 by ids
  138. /// </summary>
  139. /// <param name="ids">string[] id</param>
  140. /// <returns></returns>
  141. [HttpPost("delete")]
  142. public async Task<IActionResult> DeleteAsync(string[] ids)
  143. {
  144. int num = 0;
  145. if (ids == null && ids.Length <= 0)
  146. return Error("请选择要删除的记录");
  147. foreach (var item in ids)
  148. {
  149. var model = await _app_version3DRepository.GetSingle(item);
  150. model.isdelete = -1;
  151. if (await _app_version3DRepository.Update(model))
  152. num += 1;
  153. }
  154. if (num == ids.Length)
  155. return Success("删除成功");
  156. if (num > 0 && num < ids.Length)
  157. return Error("部分删除失败,请查看后重新操作");
  158. return Error("删除失败,请查看后重新操作");
  159. }
  160. #region App版本升级提示
  161. /// <summary>
  162. /// 获取最新3D版本详情
  163. /// </summary>
  164. /// <returns></returns>
  165. [HttpGet("getnewdetailes")]
  166. public async Task<IActionResult> GetNewDetailsAsync(string projectid, int apptype = 1)
  167. {
  168. #region 判断验证
  169. if (string.IsNullOrEmpty(projectid))
  170. return Error("参数错误");
  171. #endregion
  172. //排序字段
  173. var sort = Builders<App_Version3D>.Sort.Descending("createtime");
  174. var model = await _app_version3DRepository.GetSingle(x => x.isdelete == 0 && x.projectid == projectid && x.apptype == apptype, sort);
  175. //其他方法
  176. //Task<IEnumerable<App_Version3D>> list = _app_version3DRepository.Get(null, null, sort);
  177. //var model = list.Result.SingleOrDefault();
  178. if (model != null)
  179. {
  180. var result = new
  181. {
  182. id = model.id,
  183. apptype = model.apptype,
  184. projectid = model.projectid,
  185. versionname = model.versionname,
  186. versioncode = model.versioncode,
  187. downurl = model.downurl,
  188. createby = model.createby,
  189. createtime = model.createtime,
  190. updatetime = model.updatetime,
  191. note = model.note
  192. };
  193. return Success("获取成功!", result);
  194. }
  195. return Success("获取成功!", null);
  196. }
  197. #endregion
  198. }
  199. }