ExerciseController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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 ExerciseController : IwbControllerBase
  30. {
  31. public ExerciseController(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 = "/Exercise/Leader",
  114. PageTitle = "指挥长屏选择培训营",
  115. HasGroup = true
  116. };
  117. return RedirectToAction("SelectCamp");
  118. }
  119. TempData[SelectDataKey] = new SelectCampModel
  120. {
  121. PageUrl = "/Exercise/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 = "/Exercise/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 = "/Exercise/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 = "/Exercise/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 = "/Exercise/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. public async Task<ActionResult> StuReport(string id)
  413. {
  414. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  415. if (groupNo.IsEmpty())
  416. {
  417. TempData[SelectDataKey] = new SelectCampModel
  418. {
  419. PageUrl = "/Exercise/StuReport",
  420. PageTitle = "演练报告选择培训营",
  421. HasGroup = true
  422. };
  423. return RedirectToAction("SelectCamp");
  424. }
  425. var group = await PortraitApp.GetGroupReportBase(id);
  426. if (group == null)
  427. {
  428. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  429. return Content("");
  430. }
  431. return View(group);
  432. }
  433. /// <summary>
  434. /// 手动记录演练页面
  435. /// </summary>
  436. /// <param name="id"></param>
  437. /// <returns></returns>
  438. public async Task<ActionResult> Manual(string id)
  439. {
  440. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  441. if (campNo.IsEmpty())
  442. {
  443. TempData[SelectDataKey] = new SelectCampModel
  444. {
  445. PageUrl = "/Exercise/Manual",
  446. PageTitle = "培训营演练情况手动记录",
  447. HasGroup = false
  448. };
  449. return RedirectToAction("SelectCamp");
  450. }
  451. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  452. if (camp == null)
  453. {
  454. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  455. }
  456. if (camp?.CampState == CampStateDefinition.End)
  457. {
  458. CheckErrors($"培训营已结束!");
  459. }
  460. //if (camp?.CampState!=CampStateDefinition.Run)
  461. //{
  462. // CheckErrors($"培训营未开始!");
  463. //}
  464. Session["CampNo"] = campNo;
  465. Session.Timeout = TimeOut;
  466. ViewBag.CampName = camp?.Name;
  467. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  468. return View();
  469. }
  470. /// <summary>
  471. /// GIS页面
  472. /// </summary>
  473. /// <param name="id"></param>
  474. /// <returns></returns>
  475. public async Task<ActionResult> Gis(string id)
  476. {
  477. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  478. if (campNo.IsEmpty())
  479. {
  480. TempData[SelectDataKey] = new SelectCampModel
  481. {
  482. PageUrl = "/Exercise/Gis",
  483. PageTitle = "培训营GIS推演实时路径",
  484. HasGroup = false
  485. };
  486. return RedirectToAction("SelectCamp");
  487. }
  488. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  489. if (camp == null)
  490. {
  491. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  492. }
  493. if (camp?.CampState == CampStateDefinition.End)
  494. {
  495. CheckErrors($"培训营已结束!");
  496. }
  497. //if (camp?.CampState!=CampStateDefinition.Run)
  498. //{
  499. // CheckErrors($"培训营未开始!");
  500. //}
  501. Session["CampNo"] = campNo;
  502. Session.Timeout = TimeOut;
  503. ViewBag.CampNo = camp?.Id;
  504. ViewBag.CampName = camp?.Name;
  505. //ViewBag.Groups = await QueryApp.GetCampGroups(id);
  506. return View();
  507. }
  508. [AbpMvcAuthorize]
  509. public async Task<ActionResult> ExportSql(string id)
  510. {
  511. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  512. if (campNo.IsEmpty())
  513. {
  514. TempData[SelectDataKey] = new SelectCampModel
  515. {
  516. PageUrl = "/Exercise/ExportSql",
  517. PageTitle = "导出SQL选择培训营",
  518. HasGroup = false
  519. };
  520. return RedirectToAction("SelectCampAll");
  521. }
  522. Session["CampNo"] = campNo;
  523. Session.Timeout = TimeOut;
  524. var path = await _exportManger.ExportSql(id);
  525. return Content($"{AppDomain.CurrentDomain.BaseDirectory}{path}");
  526. }
  527. ///// <summary>
  528. ///// 选择培训营页面
  529. ///// </summary>
  530. ///// <param name="url"></param>
  531. ///// <param name="title"></param>
  532. ///// <param name="hasGroup"></param>
  533. ///// <returns></returns>
  534. //public async Task<ActionResult> Select(string url,string title,bool hasGroup)
  535. //{
  536. // string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  537. // ViewBag.Select = new SelectCampModel()
  538. // {
  539. // HasGroup = hasGroup,
  540. // PageTitle = title,
  541. // PageUrl = url,
  542. // CampSelect = str
  543. // };
  544. // return View("_Select");
  545. //}
  546. /// <summary>
  547. /// 选择培训营页面
  548. /// </summary>
  549. /// <returns></returns>
  550. public async Task<ActionResult> SelectCamp()
  551. {
  552. SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
  553. if (model == null)
  554. {
  555. return RedirectToAction("Student");
  556. }
  557. string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  558. model.CampSelect = str;
  559. ViewBag.Select = model;
  560. return View("_Select");
  561. }
  562. /// <summary>
  563. /// 选择培训营页面
  564. /// </summary>
  565. /// <returns></returns>
  566. public async Task<ActionResult> SelectCampAll()
  567. {
  568. SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
  569. if (model == null)
  570. {
  571. return RedirectToAction("Student");
  572. }
  573. string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run, CampStateDefinition.End);
  574. model.CampSelect = str;
  575. ViewBag.Select = model;
  576. return View("_Select");
  577. }
  578. [HttpGet]
  579. [WrapResult(false)]
  580. public ActionResult Voice(string txt, int? rate = null, int? vol = null)
  581. {
  582. using (MemoryStream ms = new MemoryStream())
  583. {
  584. var t = new Thread(() =>
  585. {
  586. using (SpeechSynthesizer sp = new SpeechSynthesizer())
  587. {
  588. try
  589. {
  590. sp.Rate = rate ?? 0;
  591. sp.Volume = vol ?? 90;
  592. sp.SetOutputToWaveStream(ms);
  593. sp.Speak(txt);
  594. }
  595. catch (Exception ex)
  596. {
  597. this.LogError(ex);
  598. throw;
  599. }
  600. }
  601. });
  602. t.Start();
  603. t.Join();
  604. ms.Position = 0;
  605. var buBytes = ms.GetBuffer();
  606. return new FileStreamResult(new MemoryStream(buBytes), "application/wav");
  607. }
  608. }
  609. [HttpGet]
  610. [WrapResult(false)]
  611. public async Task<ActionResult> QueryScore(string id)
  612. {
  613. if (id.IsEmpty())
  614. {
  615. var camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  616. if (camp == null)
  617. {
  618. CheckErrors("未查询到正在运行的培训营!");
  619. return Content("Error");
  620. }
  621. id = camp.Id;
  622. }
  623. var score = await QueryApp.GetScoreInfo(id);
  624. return Json(score, JsonRequestBehavior.AllowGet);
  625. }
  626. }
  627. }