ExerciseV2Controller.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. using Abp.Auditing;
  2. using Abp.Authorization;
  3. using Abp.Domain.Repositories;
  4. using Abp.Web.Models;
  5. using Abp.Web.Mvc.Authorization;
  6. using IwbZero.ToolCommon.LogHelpers;
  7. using IwbZero.ToolCommon.StringModel;
  8. using System;
  9. using System.Data.Entity;
  10. using System.IO;
  11. using System.Speech.Synthesis;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Web.Mvc;
  15. using WeApp.BaseSystem.Query;
  16. using WeApp.CommonManager.Export;
  17. using WeApp.Configuration;
  18. using WeApp.TrainingCamp;
  19. using WeApp.TrainingCamp.Dto;
  20. using WeApp.TrainingCampGroup.Dto;
  21. using WeApp.TrainingPortrait;
  22. using WeApp.Views.Shared.Camp;
  23. namespace WeApp.Controllers
  24. {
  25. /// <summary>
  26. /// 演练实施
  27. /// </summary>
  28. [AbpAllowAnonymous, DisableAuditing]
  29. public class ExerciseV2Controller : IwbControllerBase
  30. {
  31. public ExerciseV2Controller(QueryAppService queryApp, IRepository<CampGroupInfo, string> groupRepository, IRepository<CampInfo, string> campRepository, PortraitAppService portraitApp, ExportManger exportManger)
  32. {
  33. QueryApp = queryApp;
  34. GroupRepository = groupRepository;
  35. CampRepository = campRepository;
  36. PortraitApp = portraitApp;
  37. _exportManger = exportManger;
  38. }
  39. protected QueryAppService QueryApp { get; }
  40. public const string SelectDataKey = "SELECTDATA";
  41. private int TimeOut = 60 * 5;
  42. protected IRepository<CampInfo, string> CampRepository { get; }
  43. protected IRepository<CampGroupInfo, string> GroupRepository { get; }
  44. protected PortraitAppService PortraitApp { get; }
  45. private readonly ExportManger _exportManger;
  46. public ActionResult Index()
  47. {
  48. Session["GroupNo"] = "";
  49. Session["CampNo"] = "";
  50. return View();
  51. }
  52. public ActionResult Clear()
  53. {
  54. Session["GroupNo"] = "";
  55. Session["CampNo"] = "";
  56. return Content("");
  57. }
  58. public ActionResult Select(int? id)
  59. {
  60. if (id == null)
  61. {
  62. return RedirectToAction("Index");
  63. }
  64. switch (id)
  65. {
  66. case 1:
  67. return RedirectToAction("Student");
  68. case 2:
  69. return RedirectToAction("Leader");
  70. case 3:
  71. return RedirectToAction("Public");
  72. case 4:
  73. return RedirectToAction("Specialist");
  74. case 5:
  75. return RedirectToAction("Manual");
  76. case 6:
  77. return RedirectToAction("Gis");
  78. default:
  79. return RedirectToAction("Index");
  80. }
  81. }
  82. /// <summary>
  83. /// 学员指挥部页面
  84. /// </summary>
  85. /// <returns></returns>
  86. public ActionResult HeadquarterStu()
  87. {
  88. return RedirectToAction("Headquarter");
  89. }
  90. /// <summary>
  91. /// 指挥长组建指挥部
  92. /// </summary>
  93. /// <returns></returns>
  94. public ActionResult HeadquarterLeader()
  95. {
  96. return RedirectToAction("Headquarter", new { id = 1 });
  97. }
  98. /// <summary>
  99. /// 组建指挥部
  100. /// </summary>
  101. /// <param name="id"></param>
  102. /// <returns></returns>
  103. public async Task<ActionResult> Headquarter(int? id)
  104. {
  105. ViewBag.IsLeader = id == 1;
  106. string groupNo = (string)Session["GroupNo"];
  107. if (groupNo.IsEmpty())
  108. {
  109. if (id == 1)
  110. {
  111. TempData[SelectDataKey] = new SelectCampModel
  112. {
  113. PageUrl = "/ExerciseV2/Leader",
  114. PageTitle = "指挥长屏选择培训营",
  115. HasGroup = true
  116. };
  117. return RedirectToAction("SelectCamp");
  118. }
  119. TempData[SelectDataKey] = new SelectCampModel
  120. {
  121. PageUrl = "/ExerciseV2/Student",
  122. PageTitle = "学员屏选择培训营",
  123. HasGroup = true
  124. };
  125. return RedirectToAction("SelectCamp");
  126. }
  127. Session["GroupNo"] = groupNo;
  128. Session.Timeout = 60 * 5;
  129. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  130. if (group == null)
  131. {
  132. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  133. return Content("");
  134. }
  135. if (group.CampInfo.CampState == CampStateDefinition.End)
  136. {
  137. CheckErrors($"培训营已演练结束!");
  138. }
  139. if (group.CampGroupState == CampGroupStateDefinition.End)
  140. {
  141. CheckErrors($"培训营分组已演练结束!");
  142. }
  143. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  144. switch (group.CampGroupState)
  145. {
  146. case CampGroupStateDefinition.New:
  147. return View("Enter");
  148. case CampGroupStateDefinition.Ready:
  149. return View("Enter");
  150. case CampGroupStateDefinition.HeadQuarterBuilding:
  151. ViewBag.HasBuilded = false;
  152. return View();
  153. case CampGroupStateDefinition.HeadQuarterBuilded:
  154. ViewBag.HasBuilded = true;
  155. return View();
  156. }
  157. if (id == 1)
  158. {
  159. return RedirectToAction("Leader");
  160. }
  161. return RedirectToAction("Student");
  162. }
  163. /// <summary>
  164. /// 学员页面
  165. /// </summary>
  166. /// <param name="id"></param>
  167. /// <returns></returns>
  168. public async Task<ActionResult> Student(string id)
  169. {
  170. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  171. if (groupNo.IsEmpty())
  172. {
  173. TempData[SelectDataKey] = new SelectCampModel
  174. {
  175. PageUrl = "/ExerciseV2/Student",
  176. PageTitle = "学员屏选择培训营",
  177. HasGroup = true
  178. };
  179. return RedirectToAction("SelectCamp");
  180. }
  181. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  182. if (group == null)
  183. {
  184. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  185. return Content("");
  186. }
  187. Session["GroupNo"] = groupNo;
  188. Session.Timeout = TimeOut;
  189. if (group.CampGroupState != CampGroupStateDefinition.Run)
  190. {
  191. string text;
  192. switch (group.CampGroupState)
  193. {
  194. case CampGroupStateDefinition.Report:
  195. text = "正在生成演练报告";
  196. break;
  197. case CampGroupStateDefinition.End:
  198. text = "演练报告已生成";
  199. break;
  200. default:
  201. return RedirectToAction("HeadquarterStu");
  202. }
  203. ViewBag.IsLeader = false;
  204. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  205. ViewBag.Text = text;
  206. return View("WaitRport");
  207. }
  208. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  209. return View();
  210. }
  211. /// <summary>
  212. /// 指挥长页面
  213. /// </summary>
  214. /// <param name="id"></param>
  215. /// <returns></returns>
  216. public async Task<ActionResult> Leader(string id)
  217. {
  218. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  219. if (groupNo.IsEmpty())
  220. {
  221. TempData[SelectDataKey] = new SelectCampModel
  222. {
  223. PageUrl = "/ExerciseV2/Leader",
  224. PageTitle = "指挥长屏选择培训营",
  225. HasGroup = true
  226. };
  227. return RedirectToAction("SelectCamp");
  228. }
  229. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  230. if (group == null)
  231. {
  232. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  233. return Content("");
  234. }
  235. Session["GroupNo"] = groupNo;
  236. Session.Timeout = TimeOut;
  237. if (group.CampGroupState != CampGroupStateDefinition.Run)
  238. {
  239. string text;
  240. switch (group.CampGroupState)
  241. {
  242. case CampGroupStateDefinition.Report:
  243. text = "正在生成演练报告";
  244. break;
  245. case CampGroupStateDefinition.End:
  246. text = "演练报告已生成";
  247. break;
  248. default:
  249. return RedirectToAction("HeadquarterLeader");
  250. }
  251. ViewBag.IsLeader = true;
  252. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  253. ViewBag.Text = text;
  254. return View("WaitRport");
  255. }
  256. //if (group.CampGroupState != CampGroupStateDefinition.Run)
  257. //{
  258. // return RedirectToAction("HeadquarterLeader");
  259. //}
  260. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  261. return View();
  262. }
  263. /// <summary>
  264. /// 公共屏页面
  265. /// </summary>
  266. /// <param name="id"></param>
  267. /// <returns></returns>
  268. public async Task<ActionResult> Public(string id)
  269. {
  270. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  271. if (groupNo.IsEmpty())
  272. {
  273. TempData[SelectDataKey] = new SelectCampModel
  274. {
  275. PageUrl = "/ExerciseV2/Public",
  276. PageTitle = "公共屏选择培训营",
  277. HasGroup = true
  278. };
  279. return RedirectToAction("SelectCamp");
  280. }
  281. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  282. if (group == null)
  283. {
  284. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  285. return Content("");
  286. }
  287. Session["GroupNo"] = groupNo;
  288. Session.Timeout = TimeOut;
  289. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  290. if (group.CampGroupState != CampGroupStateDefinition.Run)
  291. {
  292. string text = "";
  293. switch (group.CampGroupState)
  294. {
  295. case CampGroupStateDefinition.New:
  296. text = "";
  297. break;
  298. case CampGroupStateDefinition.Ready:
  299. text = "培训营已就绪";
  300. break;
  301. case CampGroupStateDefinition.HeadQuarterBuilding:
  302. text = "正在组建指挥部";
  303. break;
  304. case CampGroupStateDefinition.HeadQuarterBuilded:
  305. text = "等待演练开始";
  306. break;
  307. case CampGroupStateDefinition.Report:
  308. text = "正在生成演练报告";
  309. break;
  310. case CampGroupStateDefinition.End:
  311. return RedirectToAction("StuReport", new { id = groupNo });
  312. }
  313. ViewBag.State = group.CampGroupState;
  314. ViewBag.Text = text;
  315. return View("PublicWait");
  316. }
  317. return View();
  318. }
  319. /// <summary>
  320. /// 公共屏页面
  321. /// </summary>
  322. /// <param name="id"></param>
  323. /// <returns></returns>
  324. [AccessOriginal]
  325. public async Task<ActionResult> Display(string id)
  326. {
  327. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == id);
  328. if (group == null)
  329. {
  330. CheckErrors($"未查到到编号为【{id}】的培训营分组!");
  331. return Content("");
  332. }
  333. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  334. if (group.CampGroupState != CampGroupStateDefinition.Run)
  335. {
  336. string text = "";
  337. switch (group.CampGroupState)
  338. {
  339. case CampGroupStateDefinition.New:
  340. text = "";
  341. break;
  342. case CampGroupStateDefinition.Ready:
  343. text = "培训营已就绪";
  344. break;
  345. case CampGroupStateDefinition.HeadQuarterBuilding:
  346. text = "正在组建指挥部";
  347. break;
  348. case CampGroupStateDefinition.HeadQuarterBuilded:
  349. text = "等待演练开始";
  350. break;
  351. case CampGroupStateDefinition.Report:
  352. text = "正在生成演练报告";
  353. break;
  354. case CampGroupStateDefinition.End:
  355. return RedirectToAction("StuReport", new { id });
  356. }
  357. ViewBag.State = group.CampGroupState;
  358. ViewBag.Text = text;
  359. return View("PublicWait");
  360. }
  361. return View("_Run/Display");
  362. }
  363. /// <summary>
  364. /// 专家屏页面
  365. /// </summary>
  366. /// <param name="id"></param>
  367. /// <returns></returns>
  368. public async Task<ActionResult> Specialist(string id)
  369. {
  370. CampInfo camp;
  371. if (id == "1")
  372. {
  373. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  374. if (camp == null)
  375. {
  376. CheckErrors("未查询到正在运行的培训营!");
  377. return Content("Error");
  378. }
  379. }
  380. else
  381. {
  382. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  383. if (campNo.IsEmpty())
  384. {
  385. TempData[SelectDataKey] = new SelectCampModel
  386. {
  387. PageUrl = "/ExerciseV2/Specialist",
  388. PageTitle = "专家屏选择培训营",
  389. HasGroup = false
  390. };
  391. return RedirectToAction("SelectCamp");
  392. }
  393. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  394. if (camp == null)
  395. {
  396. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  397. return null;
  398. }
  399. Session["CampNo"] = campNo;
  400. Session.Timeout = TimeOut;
  401. }
  402. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  403. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  404. if (camp.CampState != CampStateDefinition.Run)
  405. {
  406. var text = camp.CampState != CampStateDefinition.End ? "等待演练开始" : "演练已结束";
  407. ViewBag.Text = text;
  408. return View("SpecWait");
  409. }
  410. return View();
  411. }
  412. /// <summary>
  413. /// 主屏页面
  414. /// </summary>
  415. /// <param name="id"></param>
  416. /// <returns></returns>
  417. public async Task<ActionResult> Play(string id)
  418. {
  419. CampInfo camp;
  420. if (id == "1")
  421. {
  422. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  423. if (camp == null)
  424. {
  425. CheckErrors("未查询到正在运行的培训营!");
  426. return Content("Error");
  427. }
  428. }
  429. else
  430. {
  431. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  432. if (campNo.IsEmpty())
  433. {
  434. TempData[ExerciseController.SelectDataKey] = new SelectCampModel
  435. {
  436. PageUrl = "/Play/Index",
  437. PageTitle = "演示屏选择培训营",
  438. HasGroup = false
  439. };
  440. return RedirectToAction("SelectCamp", "ExerciseV2");
  441. }
  442. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  443. if (camp == null)
  444. {
  445. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  446. return null;
  447. }
  448. Session["CampNo"] = campNo;
  449. Session.Timeout = TimeOut;
  450. }
  451. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  452. if (camp.CampState != CampStateDefinition.Run)
  453. {
  454. return View("_Play/Wait");
  455. }
  456. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  457. return View("_Play/Index");
  458. }
  459. /// <summary>
  460. /// 主屏页面
  461. /// </summary>
  462. /// <param name="id"></param>
  463. /// <returns></returns>
  464. public async Task<ActionResult> PlayWithScore(string id)
  465. {
  466. CampInfo camp;
  467. if (id == "1")
  468. {
  469. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  470. if (camp == null)
  471. {
  472. CheckErrors("未查询到正在运行的培训营!");
  473. return Content("Error");
  474. }
  475. }
  476. else
  477. {
  478. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  479. if (campNo.IsEmpty())
  480. {
  481. TempData[ExerciseController.SelectDataKey] = new SelectCampModel
  482. {
  483. PageUrl = "/Play/IndexWithScore",
  484. PageTitle = "演示屏选择培训营",
  485. HasGroup = false
  486. };
  487. return RedirectToAction("SelectCamp", "ExerciseV2" );
  488. }
  489. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  490. if (camp == null)
  491. {
  492. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  493. return null;
  494. }
  495. Session["CampNo"] = campNo;
  496. Session.Timeout = TimeOut;
  497. }
  498. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  499. if (camp.CampState != CampStateDefinition.Run)
  500. {
  501. return View("_Play/Wait");
  502. }
  503. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  504. return View("_Play/IndexWithScore");
  505. }
  506. /// <summary>
  507. /// 演练报告
  508. /// </summary>
  509. /// <param name="id"></param>
  510. /// <returns></returns>
  511. public async Task<ActionResult> StuReport(string id)
  512. {
  513. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  514. if (groupNo.IsEmpty())
  515. {
  516. TempData[SelectDataKey] = new SelectCampModel
  517. {
  518. PageUrl = "/ExerciseV2/StuReport",
  519. PageTitle = "演练报告选择培训营",
  520. HasGroup = true
  521. };
  522. return RedirectToAction("SelectCamp");
  523. }
  524. var group = await PortraitApp.GetGroupReportBase(id);
  525. if (group == null)
  526. {
  527. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  528. return Content("");
  529. }
  530. return View(group);
  531. }
  532. /// <summary>
  533. /// 手动记录演练页面
  534. /// </summary>
  535. /// <param name="id"></param>
  536. /// <returns></returns>
  537. public async Task<ActionResult> Manual(string id)
  538. {
  539. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  540. if (campNo.IsEmpty())
  541. {
  542. TempData[SelectDataKey] = new SelectCampModel
  543. {
  544. PageUrl = "/ExerciseV2/Manual",
  545. PageTitle = "培训营演练情况手动记录",
  546. HasGroup = false
  547. };
  548. return RedirectToAction("SelectCamp");
  549. }
  550. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  551. if (camp == null)
  552. {
  553. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  554. }
  555. if (camp?.CampState == CampStateDefinition.End)
  556. {
  557. CheckErrors($"培训营已结束!");
  558. }
  559. //if (camp?.CampState!=CampStateDefinition.Run)
  560. //{
  561. // CheckErrors($"培训营未开始!");
  562. //}
  563. Session["CampNo"] = campNo;
  564. Session.Timeout = TimeOut;
  565. ViewBag.CampName = camp?.Name;
  566. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  567. return View();
  568. }
  569. /// <summary>
  570. /// GIS页面
  571. /// </summary>
  572. /// <param name="id"></param>
  573. /// <returns></returns>
  574. public async Task<ActionResult> Gis(string id)
  575. {
  576. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  577. if (campNo.IsEmpty())
  578. {
  579. TempData[SelectDataKey] = new SelectCampModel
  580. {
  581. PageUrl = "/ExerciseV2/Gis",
  582. PageTitle = "培训营GIS推演实时路径",
  583. HasGroup = false
  584. };
  585. return RedirectToAction("SelectCamp");
  586. }
  587. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  588. if (camp == null)
  589. {
  590. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  591. }
  592. if (camp?.CampState == CampStateDefinition.End)
  593. {
  594. CheckErrors($"培训营已结束!");
  595. }
  596. //if (camp?.CampState!=CampStateDefinition.Run)
  597. //{
  598. // CheckErrors($"培训营未开始!");
  599. //}
  600. Session["CampNo"] = campNo;
  601. Session.Timeout = TimeOut;
  602. ViewBag.CampNo = camp?.Id;
  603. ViewBag.CampName = camp?.Name;
  604. //ViewBag.Groups = await QueryApp.GetCampGroups(id);
  605. return View();
  606. }
  607. [AbpMvcAuthorize]
  608. public async Task<ActionResult> ExportSql(string id)
  609. {
  610. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  611. if (campNo.IsEmpty())
  612. {
  613. TempData[SelectDataKey] = new SelectCampModel
  614. {
  615. PageUrl = "/ExerciseV2/ExportSql",
  616. PageTitle = "导出SQL选择培训营",
  617. HasGroup = false
  618. };
  619. return RedirectToAction("SelectCampAll");
  620. }
  621. Session["CampNo"] = campNo;
  622. Session.Timeout = TimeOut;
  623. var path = await _exportManger.ExportSql(id);
  624. return Content($"{AppDomain.CurrentDomain.BaseDirectory}{path}");
  625. }
  626. ///// <summary>
  627. ///// 选择培训营页面
  628. ///// </summary>
  629. ///// <param name="url"></param>
  630. ///// <param name="title"></param>
  631. ///// <param name="hasGroup"></param>
  632. ///// <returns></returns>
  633. //public async Task<ActionResult> Select(string url,string title,bool hasGroup)
  634. //{
  635. // string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  636. // ViewBag.Select = new SelectCampModel()
  637. // {
  638. // HasGroup = hasGroup,
  639. // PageTitle = title,
  640. // PageUrl = url,
  641. // CampSelect = str
  642. // };
  643. // return View("_Select");
  644. //}
  645. /// <summary>
  646. /// 选择培训营页面
  647. /// </summary>
  648. /// <returns></returns>
  649. public async Task<ActionResult> SelectCamp()
  650. {
  651. SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
  652. if (model == null)
  653. {
  654. return RedirectToAction("Student");
  655. }
  656. string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  657. model.CampSelect = str;
  658. ViewBag.Select = model;
  659. return View("_Select");
  660. }
  661. /// <summary>
  662. /// 选择培训营页面
  663. /// </summary>
  664. /// <returns></returns>
  665. public async Task<ActionResult> SelectCampAll()
  666. {
  667. SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
  668. if (model == null)
  669. {
  670. return RedirectToAction("Student");
  671. }
  672. string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run, CampStateDefinition.End);
  673. model.CampSelect = str;
  674. ViewBag.Select = model;
  675. return View("_Select");
  676. }
  677. [HttpGet]
  678. [WrapResult(false)]
  679. public ActionResult Voice(string txt, int? rate = null, int? vol = null)
  680. {
  681. using (MemoryStream ms = new MemoryStream())
  682. {
  683. var t = new Thread(() =>
  684. {
  685. using (SpeechSynthesizer sp = new SpeechSynthesizer())
  686. {
  687. try
  688. {
  689. sp.Rate = rate ?? 0;
  690. sp.Volume = vol ?? 90;
  691. sp.SetOutputToWaveStream(ms);
  692. sp.Speak(txt);
  693. }
  694. catch (Exception ex)
  695. {
  696. this.LogError(ex);
  697. throw;
  698. }
  699. }
  700. });
  701. t.Start();
  702. t.Join();
  703. ms.Position = 0;
  704. var buBytes = ms.GetBuffer();
  705. return new FileStreamResult(new MemoryStream(buBytes), "application/wav");
  706. }
  707. }
  708. [HttpGet]
  709. [WrapResult(false)]
  710. public async Task<ActionResult> QueryScore(string id)
  711. {
  712. if (id.IsEmpty())
  713. {
  714. var camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  715. if (camp == null)
  716. {
  717. CheckErrors("未查询到正在运行的培训营!");
  718. return Content("Error");
  719. }
  720. id = camp.Id;
  721. }
  722. var score = await QueryApp.GetScoreInfo(id);
  723. return Json(score, JsonRequestBehavior.AllowGet);
  724. }
  725. }
  726. }