VoteController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using Azure.Cosmos;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IdentityModel.Tokens.Jwt;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. using TEAMModelOS.Models.Dto;
  12. using TEAMModelOS.SDK.Models;
  13. using TEAMModelOS.SDK;
  14. using TEAMModelOS.SDK.Context.Constant.Common;
  15. using TEAMModelOS.SDK.DI;
  16. using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
  17. using TEAMModelOS.SDK.Extension;
  18. using TEAMModelOS.SDK;
  19. using TEAMModelOS.SDK.Helper.Common.StringHelper;
  20. using TEAMModelOS.Models;
  21. using Microsoft.Extensions.Options;
  22. using TEAMModelOS.SDK.Models.Cosmos;
  23. using Microsoft.AspNetCore.Authorization;
  24. using TEAMModelOS.Filter;
  25. using StackExchange.Redis;
  26. using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
  27. using TEAMModelOS.Services.Common;
  28. using Azure.Messaging.ServiceBus;
  29. using Microsoft.Extensions.Configuration;
  30. namespace TEAMModelOS.Controllers.Learn
  31. {
  32. /// <summary>
  33. /// 投票活动
  34. /// </summary>
  35. [ProducesResponseType(StatusCodes.Status200OK)]
  36. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  37. //[Authorize(Roles = "IES5")]
  38. [Route("common/vote")]
  39. [ApiController]
  40. public class VoteController : ControllerBase
  41. {
  42. private readonly AzureRedisFactory _azureRedis;
  43. private readonly AzureCosmosFactory _azureCosmos;
  44. private readonly SnowflakeId _snowflakeId;
  45. private readonly AzureServiceBusFactory _serviceBus;
  46. private readonly DingDing _dingDing;
  47. private readonly Option _option;
  48. private readonly AzureStorageFactory _azureStorage;
  49. public IConfiguration _configuration { get; set; }
  50. public VoteController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option,
  51. AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IConfiguration configuration)
  52. {
  53. _azureCosmos = azureCosmos;
  54. _serviceBus = serviceBus;
  55. _snowflakeId = snowflakeId;
  56. _dingDing = dingDing;
  57. _option = option?.Value;
  58. _azureRedis = azureRedis;
  59. _azureStorage = azureStorage;
  60. _configuration = configuration;
  61. }
  62. /// <summary>
  63. /// 新增 或 修改投票活动
  64. /// </summary>
  65. /// <param name="request"></param>
  66. /// <returns></returns>
  67. [ProducesDefaultResponseType]
  68. [HttpPost("upsert")]
  69. [AuthToken(Roles = "teacher,admin")]
  70. public async Task<IActionResult> Upsert(Vote request)
  71. {
  72. try
  73. {
  74. //新增Vote
  75. var client = _azureCosmos.GetCosmosClient();
  76. request.code = request.pk + "-" + request.code;
  77. request.ttl = -1;
  78. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  79. request.createTime = now;
  80. //如果设置的时间是小于当前时间则立即发布
  81. if (request.startTime <= 0) {
  82. request.startTime = now;
  83. }
  84. if (string.IsNullOrEmpty(request.id))
  85. {
  86. request.id = Guid.NewGuid().ToString();
  87. if (request.startTime > now)
  88. {
  89. request.progress = "pending";
  90. }
  91. else {
  92. request.progress = "going";
  93. }
  94. var messageBlob = new ServiceBusMessage();
  95. if (request.scope.Equals("school"))
  96. {
  97. request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
  98. messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());
  99. }
  100. else
  101. {
  102. request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
  103. messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "insert", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
  104. }
  105. messageBlob.ApplicationProperties.Add("name", "BlobRoot");
  106. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  107. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
  108. request = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
  109. }
  110. else
  111. {
  112. var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
  113. var messageBlob = new ServiceBusMessage();
  114. if (request.scope.Equals("school"))
  115. {
  116. request.size = await _azureStorage.GetBlobContainerClient(request.school).GetBlobsSize($"vote/{request.id}");
  117. messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.school}" }.ToJsonString());
  118. }
  119. else
  120. {
  121. request.size = await _azureStorage.GetBlobContainerClient(request.creatorId).GetBlobsSize($"vote/{request.id}");
  122. messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "update", root = $"vote/{request.id}", name = $"{request.creatorId}" }.ToJsonString());
  123. }
  124. messageBlob.ApplicationProperties.Add("name", "BlobRoot");
  125. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  126. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
  127. if (response.Status == 200)
  128. {
  129. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  130. var info = json.ToObject<Vote>();
  131. if (info.progress.Equals("going"))
  132. {
  133. return Ok(new { v = "活动正在进行中" });
  134. }
  135. if (request.startTime > now)
  136. {
  137. request.progress = "pending";
  138. }
  139. else
  140. {
  141. request.progress = "going";
  142. }
  143. request.progress = info.progress;
  144. request = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(request, info.id, new PartitionKey($"{info.code}"));
  145. }
  146. else
  147. {
  148. if (request.startTime > now)
  149. {
  150. request.progress = "pending";
  151. }
  152. else
  153. {
  154. request.progress = "going";
  155. }
  156. request = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
  157. }
  158. }
  159. return Ok(new { vote = request });
  160. }
  161. catch (Exception e)
  162. {
  163. await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/save()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
  164. return BadRequest(e.StackTrace);
  165. }
  166. }
  167. /// <summary>
  168. /// 查询投票活动,用于列表,编辑,查看
  169. /// </summary>
  170. /// <data>
  171. ///Vote-学校/教师编码 活动分区 !"code":"hbcn"/1606285227
  172. ///时间筛选范围开始时间 默认30天之前 ?"stime":1608274766154
  173. ///时间筛选范围结束时间 默认当前时间 ?"etime":1608274766666
  174. ///每页大小 ?"count":10/null/Undefined
  175. ///分页Token ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
  176. /// 当前状态 ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束
  177. /// </data>
  178. /// <param name="request"></param>
  179. /// <returns></returns>
  180. [ProducesDefaultResponseType]
  181. [HttpPost("find")]
  182. [AuthToken(Roles = "teacher,admin")]
  183. public async Task<IActionResult> Find(JsonElement requert)
  184. {
  185. try
  186. {
  187. //必须有学校或者教师编码
  188. if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
  189. //开始时间,默认最近三十天
  190. var stimestamp = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds();
  191. if (requert.TryGetProperty("stime", out JsonElement stime)) {
  192. if (!stime.ValueKind.Equals(JsonValueKind.Undefined)&&stime.TryGetInt64(out long data))
  193. {
  194. stimestamp = data;
  195. };
  196. };
  197. //默认当前时间
  198. var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  199. if (requert.TryGetProperty("etime", out JsonElement etime))
  200. {
  201. if (!etime.ValueKind.Equals(JsonValueKind.Undefined)&&etime.TryGetInt64(out long data))
  202. {
  203. etimestamp = data;
  204. };
  205. };
  206. var progresssql = "";
  207. if (!requert.TryGetProperty("progress", out JsonElement progress))
  208. {
  209. if (!progress.ValueKind.Equals(JsonValueKind.Undefined) && !progress.ValueKind.Equals(JsonValueKind.Null) && progress.ValueKind.Equals(JsonValueKind.String))
  210. {
  211. progresssql = $" and c.progress='{progresssql}' ";
  212. }
  213. }
  214. string continuationToken = null;
  215. //默认不指定返回大小
  216. int? topcout=null;
  217. if (requert.TryGetProperty("count", out JsonElement jcount)) {
  218. if(!jcount.ValueKind.Equals(JsonValueKind.Undefined) && jcount.TryGetInt32(out int data))
  219. {
  220. topcout = data;
  221. }
  222. };
  223. //是否需要进行分页查询,默认不分页
  224. bool iscontinuation = false;
  225. //如果指定了返回大小
  226. if (requert.TryGetProperty("continuationToken", out JsonElement continuation))
  227. {
  228. //指定了cancellationToken 表示需要进行分页
  229. if (!continuation.ValueKind.Equals(JsonValueKind.Null) && !continuation.ValueKind.Equals(JsonValueKind.Undefined))
  230. {
  231. continuationToken = continuation.GetString();
  232. iscontinuation = true;
  233. }
  234. };
  235. List<object> votes = new List<object>();
  236. var client = _azureCosmos.GetCosmosClient();
  237. var query =$"select c.id,c.name,c.code,c.startTime,c.endTime,c.progress from c where c.createTime >= {stimestamp} and c.createTime <= {etimestamp} {progresssql } ";
  238. await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query,
  239. requestOptions: new QueryRequestOptions() {MaxItemCount = topcout, PartitionKey = new PartitionKey($"Vote-{code}") }))
  240. {
  241. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  242. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  243. {
  244. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  245. {
  246. votes.Add(obj.ToObject<JsonElement>());
  247. }
  248. //如果需要分页则跳出
  249. if (iscontinuation) {
  250. continuationToken = item.GetContinuationToken();
  251. break;
  252. }
  253. }
  254. }
  255. return Ok(new { votes, continuationToken });
  256. }
  257. catch (Exception ex)
  258. {
  259. await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find()\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  260. return BadRequest(ex.StackTrace);
  261. }
  262. }
  263. ///<summary>
  264. /// 查询投票活动,用于创建者列表,编辑,查看,投票人员查看
  265. /// </summary>
  266. /// <data>
  267. /// ! "id":"3c075347-75ef-4bcb-ae03-68678d02d5ef",
  268. /// ! "code":"Vote-hbcn"/"code":"Vote-1606285227"
  269. /// </data>
  270. /// <param name="request"></param>
  271. /// <returns></returns>
  272. [ProducesDefaultResponseType]
  273. [HttpPost("find-id")]
  274. [AuthToken(Roles = "teacher,admin,student")]
  275. public async Task<IActionResult> FindById(JsonElement requert)
  276. {
  277. Vote vote = null;
  278. //活动id
  279. if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
  280. //活动分区
  281. if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
  282. try
  283. {
  284. var client = _azureCosmos.GetCosmosClient();
  285. vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.GetString(), new PartitionKey($"{code}"));
  286. if (vote != null)
  287. {
  288. return Ok(new { vote, status = 200 });
  289. }
  290. else
  291. {
  292. return Ok(new { vote, status = 404 });
  293. }
  294. }
  295. catch (Exception ex)
  296. {
  297. await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}\n{id}\n{code}", GroupNames.醍摩豆服務運維群組);
  298. return Ok(new { vote,status=404 });
  299. }
  300. }
  301. /// <summary>
  302. /// 删除投票活动 TODO 使用ttl删除,并处理相关事务逻辑
  303. /// </summary>
  304. /// <param name="request"></param>
  305. /// <returns></returns>
  306. [ProducesDefaultResponseType]
  307. [HttpPost("delete")]
  308. [AuthToken(Roles = "admin,teacher")]
  309. public async Task<IActionResult> Delete(JsonElement request)
  310. {
  311. try
  312. {
  313. var (userid, _, _,school) = HttpContext.GetAuthTokenInfo();
  314. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  315. if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
  316. var client = _azureCosmos.GetCosmosClient();
  317. Vote vote =await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(id.GetString(), new PartitionKey($"{code}") );
  318. bool flag = false;
  319. //必须是本人或者这个学校的管理者才能删除
  320. if (vote.creatorId == userid)
  321. {
  322. flag = true;
  323. }
  324. else {
  325. if (vote.scope == "school"&& vote.school.Equals(school)) {
  326. flag = true;
  327. }
  328. }
  329. if (flag)
  330. {
  331. //使用ttl删除,并处理相关事务逻辑
  332. vote.ttl = 1;
  333. vote.status = 404;
  334. vote = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(vote, new PartitionKey($"{vote.code}"));
  335. await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
  336. _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
  337. _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
  338. await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
  339. //删除blob 相关资料
  340. await _azureStorage.GetBlobServiceClient().DelectBlobs(code.ToString(), new List<string> { $"vote/{id}" });
  341. //通知删除信息
  342. var messageBlob = new ServiceBusMessage(new { id = Guid.NewGuid().ToString(), progress = "delete", root = $"vote/{id}", name = $"{code}" }.ToJsonString());
  343. messageBlob.ApplicationProperties.Add("name", "BlobRoot");
  344. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  345. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
  346. return Ok(new { flag });
  347. }
  348. else {
  349. return Ok(new { flag });
  350. }
  351. }
  352. catch (Exception e)
  353. {
  354. return BadRequest(e.StackTrace);
  355. }
  356. }
  357. /// <summary>
  358. /// 投票记录 当活动没结算且没有BlobUrl时则调用此接口
  359. /// </summary>
  360. /// <redis>
  361. /// 投票活动选项计数器 使用SortedSet(有序集合)ZSET 数据集合 使用命令 ZINCRBY key:"Vote:Count:AAA",value:"A",score:1
  362. /// 投票活动 投票记录 使用Hash(哈希表)使用命令 key:"Vote:Record:AAA",feild:15283771540-20210105,value:"{"opt":["A","C","A"],"time":1608274766154}"
  363. /// </redis>
  364. /// <param name="request">
  365. /// !"id":"aaaa"
  366. /// !"code":"Vote-hbcn"/"code":"Vote-1606285227"
  367. /// </param>
  368. /// <returns>
  369. /// </returns>
  370. [ProducesDefaultResponseType]
  371. [HttpPost("record")]
  372. [AuthToken(Roles = "teacher,admin,student")]
  373. public async Task<IActionResult> Record(JsonElement request)
  374. {
  375. if (!request.TryGetProperty("id", out JsonElement id))
  376. {
  377. return BadRequest();
  378. }
  379. //活动分区
  380. if (!request.TryGetProperty("code", out JsonElement code))
  381. {
  382. return BadRequest();
  383. }
  384. //获取投票活动的所有投票记录
  385. var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{id}");
  386. //获取投票活动的选项及投票数
  387. var counts = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Vote:Count:{id}");
  388. List<dynamic> options = new List<dynamic>();
  389. if (counts != null && counts.Length > 0)
  390. {
  391. foreach (var count in counts)
  392. {
  393. options.Add(new { code = count.Element.ToString(), count = (int)count.Score });
  394. }
  395. }
  396. List<JsonElement> res = new List<JsonElement>();
  397. foreach (var rcd in records)
  398. {
  399. var value = rcd.Value.ToString().ToObject<JsonElement>();
  400. res.Add(value);
  401. }
  402. return Ok(new { options, records= res});
  403. }
  404. /// <summary>
  405. /// 个人已投票记录查询
  406. /// </summary>
  407. /// <param name="request"></param>
  408. /// <returns></returns>
  409. [ProducesDefaultResponseType]
  410. [HttpPost("decided")]
  411. [AuthToken(Roles = "teacher,student")]
  412. public async Task<IActionResult> Decided(JsonElement request)
  413. {
  414. var (userid, _, _, _) = HttpContext.GetAuthTokenInfo();
  415. if (!request.TryGetProperty("id", out JsonElement id))
  416. {
  417. return BadRequest();
  418. }
  419. //活动分区
  420. if (!request.TryGetProperty("code", out JsonElement code))
  421. {
  422. return BadRequest();
  423. }
  424. //获取投票活动的所有投票记录
  425. var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Vote:Record:{id}:{userid}");
  426. List<JsonElement> res = new List<JsonElement>();
  427. foreach (var rcd in records)
  428. {
  429. var value = rcd.Value.ToString().ToObject<JsonElement>();
  430. res.Add(value);
  431. }
  432. return Ok(new { records= res });
  433. }
  434. /// <summary>
  435. /// 投票
  436. /// </summary>
  437. /// <redis>
  438. /// 投票活动选项计数器 使用SortedSet(有序集合)ZSET 数据集合 使用命令 ZINCRBY key:"Vote:Count:AAA",value:"A",score:1
  439. /// 投票活动 投票记录 使用Hash(哈希表)使用命令 key:"Vote:Record:AAA",feild:15283771540-20210105,value:"{"opt":["A","C","A"],"time":1608274766154}"
  440. /// </redis>
  441. /// <param name="request">
  442. /// !"id":"aaaa"
  443. /// !"code":"Vote-hbcn"/"code":"Vote-1606285227"
  444. /// !"option":{"A":5,"B":6}/{"1":5,"2":8}
  445. /// </param>
  446. /// <returns>
  447. /// msgid=0投票失败,1投票成功,2不在时间范围内,3不在发布范围内,4投票周期内重复投票,5周期内的可投票数不足
  448. ///
  449. /// </returns>
  450. [ProducesDefaultResponseType]
  451. [HttpPost("decide")]
  452. [AuthToken(Roles = "teacher,student")]
  453. public async Task<IActionResult> Decide(JsonElement request)
  454. {
  455. var (userid, _, _, _) = HttpContext.GetAuthTokenInfo();
  456. int msgid = await ActivityStudentService.Decide(request, _azureCosmos, _azureRedis, userid);
  457. return Ok(new { msgid });
  458. }
  459. /// <summary>
  460. /// 投票
  461. /// </summary>
  462. /// <redis>
  463. /// 投票活动选项计数器 使用SortedSet(有序集合)ZSET 数据集合 使用命令 ZINCRBY key:"Vote:Count:AAA",value:"A",score:1
  464. /// 投票活动 投票记录 使用Hash(哈希表)使用命令 key:"Vote:Record:AAA",feild:15283771540-20210105,value:"{"opt":["A","C","A"],"time":1608274766154}"
  465. /// </redis>
  466. /// <param name="request">
  467. /// !"id":"aaaa"
  468. /// !"code":"Vote-hbcn"/"code":"Vote-1606285227"
  469. /// !"option":{"A":5,"B":6}/{"1":5,"2":8}
  470. /// !"userid":"15283771540"
  471. /// </param>
  472. /// <returns>
  473. /// msgid=0投票失败,1投票成功,2不在时间范围内,3不在发布范围内,4投票周期内重复投票,5周期内的可投票数不足,6未设置投票项
  474. /// </returns>
  475. [ProducesDefaultResponseType]
  476. [HttpPost("decide-mock")]
  477. public async Task<IActionResult> DecideMock(JsonElement request)
  478. {
  479. //var (userid, _, _, _) = HttpContext.GetAuthTokenInfo();
  480. //活动id
  481. if (request.TryGetProperty("userid", out JsonElement userid))
  482. {
  483. int msgid = await ActivityStudentService.Decide(request, _azureCosmos, _azureRedis, $"{userid}");
  484. return Ok(new { msgid });
  485. }
  486. else { return Ok(new { msgid = 0 }); }
  487. }
  488. }
  489. }