ExerciseController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. using System.Data.Entity;
  2. using System.Threading.Tasks;
  3. using System.Web.Mvc;
  4. using Abp.Auditing;
  5. using Abp.Authorization;
  6. using Abp.Domain.Repositories;
  7. using Abp.Web.Models;
  8. using IwbZero.ToolCommon.StringModel;
  9. using WeApp.BaseSystem.Query;
  10. using WeApp.Configuration;
  11. using WeApp.TrainingCamp;
  12. using WeApp.TrainingCamp.Dto;
  13. using WeApp.TrainingCampGroup.Dto;
  14. using WeApp.TrainingPortrait;
  15. using WeApp.Views.Shared.Camp;
  16. namespace WeApp.Controllers
  17. {
  18. /// <summary>
  19. /// 演练实施
  20. /// </summary>
  21. [AbpAllowAnonymous, DisableAuditing]
  22. public class ExerciseController : IwbControllerBase
  23. {
  24. public ExerciseController(QueryAppService queryApp, IRepository<CampGroupInfo, string> groupRepository, IRepository<CampInfo, string> campRepository, PortraitAppService portraitApp)
  25. {
  26. QueryApp = queryApp;
  27. GroupRepository = groupRepository;
  28. CampRepository = campRepository;
  29. PortraitApp = portraitApp;
  30. }
  31. protected QueryAppService QueryApp { get; }
  32. private const string SelectDataKey = "SELECTDATA";
  33. private int TimeOut = 60 * 5;
  34. protected IRepository<CampInfo, string> CampRepository { get; }
  35. protected IRepository<CampGroupInfo, string> GroupRepository { get; }
  36. protected PortraitAppService PortraitApp { get; }
  37. public ActionResult Index()
  38. {
  39. Session["GroupNo"] = "";
  40. Session["CampNo"] = "";
  41. return View();
  42. }
  43. public ActionResult Select(int? id)
  44. {
  45. if (id == null)
  46. {
  47. return RedirectToAction("Index");
  48. }
  49. switch (id)
  50. {
  51. case 1:
  52. return RedirectToAction("Student");
  53. case 2:
  54. return RedirectToAction("Leader");
  55. case 3:
  56. return RedirectToAction("Public");
  57. case 4:
  58. return RedirectToAction("Specialist");
  59. case 5:
  60. return RedirectToAction("Manual");
  61. case 6:
  62. return RedirectToAction("Gis");
  63. default:
  64. return RedirectToAction("Index");
  65. }
  66. }
  67. /// <summary>
  68. /// 学员指挥部页面
  69. /// </summary>
  70. /// <returns></returns>
  71. public ActionResult HeadquarterStu()
  72. {
  73. return RedirectToAction("Headquarter");
  74. }
  75. /// <summary>
  76. /// 指挥长组建指挥部
  77. /// </summary>
  78. /// <returns></returns>
  79. public ActionResult HeadquarterLeader()
  80. {
  81. return RedirectToAction("Headquarter", new { id = 1 });
  82. }
  83. /// <summary>
  84. /// 组建指挥部
  85. /// </summary>
  86. /// <param name="id"></param>
  87. /// <returns></returns>
  88. public async Task<ActionResult> Headquarter(int? id)
  89. {
  90. ViewBag.IsLeader = id == 1;
  91. string groupNo = (string)Session["GroupNo"];
  92. if (groupNo.IsEmpty())
  93. {
  94. if (id == 1)
  95. {
  96. TempData[SelectDataKey] = new SelectCampModel
  97. {
  98. PageUrl = "/Exercise/Leader",
  99. PageTitle = "指挥长屏选择培训营",
  100. HasGroup = true
  101. };
  102. return RedirectToAction("SelectCamp");
  103. }
  104. TempData[SelectDataKey] = new SelectCampModel
  105. {
  106. PageUrl = "/Exercise/Student",
  107. PageTitle = "学员屏选择培训营",
  108. HasGroup = true
  109. };
  110. return RedirectToAction("SelectCamp");
  111. }
  112. Session["GroupNo"] = groupNo;
  113. Session.Timeout = 60 * 5;
  114. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  115. if (group == null)
  116. {
  117. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  118. return Content("");
  119. }
  120. if (group.CampInfo.CampState == CampStateDefinition.End)
  121. {
  122. CheckErrors($"培训营已演练结束!");
  123. }
  124. if (group.CampGroupState == CampGroupStateDefinition.End)
  125. {
  126. CheckErrors($"培训营分组已演练结束!");
  127. }
  128. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  129. switch (group.CampGroupState)
  130. {
  131. case CampGroupStateDefinition.New:
  132. return View("Enter");
  133. case CampGroupStateDefinition.Ready:
  134. return View("Enter");
  135. case CampGroupStateDefinition.HeadQuarterBuilding:
  136. ViewBag.HasBuilded = false;
  137. return View();
  138. case CampGroupStateDefinition.HeadQuarterBuilded:
  139. ViewBag.HasBuilded = true;
  140. return View();
  141. }
  142. if (id == 1)
  143. {
  144. return RedirectToAction("Leader");
  145. }
  146. return RedirectToAction("Student");
  147. }
  148. /// <summary>
  149. /// 学员页面
  150. /// </summary>
  151. /// <param name="id"></param>
  152. /// <returns></returns>
  153. public async Task<ActionResult> Student(string id)
  154. {
  155. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  156. if (groupNo.IsEmpty())
  157. {
  158. TempData[SelectDataKey] = new SelectCampModel
  159. {
  160. PageUrl = "/Exercise/Student",
  161. PageTitle = "学员屏选择培训营",
  162. HasGroup = true
  163. };
  164. return RedirectToAction("SelectCamp");
  165. }
  166. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  167. if (group == null)
  168. {
  169. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  170. return Content("");
  171. }
  172. Session["GroupNo"] = groupNo;
  173. Session.Timeout = TimeOut;
  174. if (group.CampGroupState != CampGroupStateDefinition.Run)
  175. {
  176. string text;
  177. switch (group.CampGroupState)
  178. {
  179. case CampGroupStateDefinition.Report:
  180. text = "正在生成演练报告";
  181. break;
  182. case CampGroupStateDefinition.End:
  183. text = "演练报告已生成";
  184. break;
  185. default:
  186. return RedirectToAction("HeadquarterStu");
  187. }
  188. ViewBag.IsLeader = false;
  189. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  190. ViewBag.Text = text;
  191. return View("WaitRport");
  192. }
  193. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  194. return View();
  195. }
  196. /// <summary>
  197. /// 指挥长页面
  198. /// </summary>
  199. /// <param name="id"></param>
  200. /// <returns></returns>
  201. public async Task<ActionResult> Leader(string id)
  202. {
  203. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  204. if (groupNo.IsEmpty())
  205. {
  206. TempData[SelectDataKey] = new SelectCampModel
  207. {
  208. PageUrl = "/Exercise/Leader",
  209. PageTitle = "指挥长屏选择培训营",
  210. HasGroup = true
  211. };
  212. return RedirectToAction("SelectCamp");
  213. }
  214. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  215. if (group == null)
  216. {
  217. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  218. return Content("");
  219. }
  220. Session["GroupNo"] = groupNo;
  221. Session.Timeout = TimeOut;
  222. if (group.CampGroupState != CampGroupStateDefinition.Run)
  223. {
  224. string text;
  225. switch (group.CampGroupState)
  226. {
  227. case CampGroupStateDefinition.Report:
  228. text = "正在生成演练报告";
  229. break;
  230. case CampGroupStateDefinition.End:
  231. text = "演练报告已生成";
  232. break;
  233. default:
  234. return RedirectToAction("HeadquarterLeader");
  235. }
  236. ViewBag.IsLeader = true;
  237. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  238. ViewBag.Text = text;
  239. return View("WaitRport");
  240. }
  241. //if (group.CampGroupState != CampGroupStateDefinition.Run)
  242. //{
  243. // return RedirectToAction("HeadquarterLeader");
  244. //}
  245. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  246. return View();
  247. }
  248. /// <summary>
  249. /// 公共屏页面
  250. /// </summary>
  251. /// <param name="id"></param>
  252. /// <returns></returns>
  253. public async Task<ActionResult> Public(string id)
  254. {
  255. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  256. if (groupNo.IsEmpty())
  257. {
  258. TempData[SelectDataKey] = new SelectCampModel
  259. {
  260. PageUrl = "/Exercise/Public",
  261. PageTitle = "公共屏选择培训营",
  262. HasGroup = true
  263. };
  264. return RedirectToAction("SelectCamp");
  265. }
  266. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
  267. if (group == null)
  268. {
  269. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  270. return Content("");
  271. }
  272. Session["GroupNo"] = groupNo;
  273. Session.Timeout = TimeOut;
  274. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  275. if (group.CampGroupState != CampGroupStateDefinition.Run)
  276. {
  277. string text = "";
  278. switch (group.CampGroupState)
  279. {
  280. case CampGroupStateDefinition.New:
  281. text = "";
  282. break;
  283. case CampGroupStateDefinition.Ready:
  284. text = "培训营已就绪";
  285. break;
  286. case CampGroupStateDefinition.HeadQuarterBuilding:
  287. text = "正在组建指挥部";
  288. break;
  289. case CampGroupStateDefinition.HeadQuarterBuilded:
  290. text = "等待演练开始";
  291. break;
  292. case CampGroupStateDefinition.Report:
  293. text = "正在生成演练报告";
  294. break;
  295. case CampGroupStateDefinition.End:
  296. return RedirectToAction("StuReport", new { id = groupNo });
  297. }
  298. ViewBag.State = group.CampGroupState;
  299. ViewBag.Text = text;
  300. return View("PublicWait");
  301. }
  302. return View();
  303. }
  304. /// <summary>
  305. /// 公共屏页面
  306. /// </summary>
  307. /// <param name="id"></param>
  308. /// <returns></returns>
  309. [AccessOriginal]
  310. public async Task<ActionResult> Display(string id)
  311. {
  312. var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == id);
  313. if (group == null)
  314. {
  315. CheckErrors($"未查到到编号为【{id}】的培训营分组!");
  316. return Content("");
  317. }
  318. ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
  319. if (group.CampGroupState != CampGroupStateDefinition.Run)
  320. {
  321. string text = "";
  322. switch (group.CampGroupState)
  323. {
  324. case CampGroupStateDefinition.New:
  325. text = "";
  326. break;
  327. case CampGroupStateDefinition.Ready:
  328. text = "培训营已就绪";
  329. break;
  330. case CampGroupStateDefinition.HeadQuarterBuilding:
  331. text = "正在组建指挥部";
  332. break;
  333. case CampGroupStateDefinition.HeadQuarterBuilded:
  334. text = "等待演练开始";
  335. break;
  336. case CampGroupStateDefinition.Report:
  337. text = "正在生成演练报告";
  338. break;
  339. case CampGroupStateDefinition.End:
  340. return RedirectToAction("StuReport", new { id });
  341. }
  342. ViewBag.State = group.CampGroupState;
  343. ViewBag.Text = text;
  344. return View("PublicWait");
  345. }
  346. return View("_Run/Display");
  347. }
  348. /// <summary>
  349. /// 专家屏页面
  350. /// </summary>
  351. /// <param name="id"></param>
  352. /// <returns></returns>
  353. public async Task<ActionResult> Specialist(string id)
  354. {
  355. CampInfo camp;
  356. if (id == "1")
  357. {
  358. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  359. if (camp == null)
  360. {
  361. CheckErrors("未查询到正在运行的培训营!");
  362. return Content("Error");
  363. }
  364. }
  365. else
  366. {
  367. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  368. if (campNo.IsEmpty())
  369. {
  370. TempData[SelectDataKey] = new SelectCampModel
  371. {
  372. PageUrl = "/Exercise/Specialist",
  373. PageTitle = "专家屏选择培训营",
  374. HasGroup = false
  375. };
  376. return RedirectToAction("SelectCamp");
  377. }
  378. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  379. if (camp == null)
  380. {
  381. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  382. return null;
  383. }
  384. Session["CampNo"] = campNo;
  385. Session.Timeout = TimeOut;
  386. }
  387. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  388. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  389. if (camp.CampState != CampStateDefinition.Run)
  390. {
  391. var text = camp.CampState != CampStateDefinition.End ? "等待演练开始" : "演练已结束";
  392. ViewBag.Text = text;
  393. return View("SpecWait");
  394. }
  395. return View();
  396. }
  397. public async Task<ActionResult> StuReport(string id)
  398. {
  399. string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
  400. if (groupNo.IsEmpty())
  401. {
  402. TempData[SelectDataKey] = new SelectCampModel
  403. {
  404. PageUrl = "/Exercise/StuReport",
  405. PageTitle = "演练报告选择培训营",
  406. HasGroup = true
  407. };
  408. return RedirectToAction("SelectCamp");
  409. }
  410. var group = await PortraitApp.GetGroupReportBase(id);
  411. if (group == null)
  412. {
  413. CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
  414. return Content("");
  415. }
  416. return View(group);
  417. }
  418. /// <summary>
  419. /// 手动记录演练页面
  420. /// </summary>
  421. /// <param name="id"></param>
  422. /// <returns></returns>
  423. public async Task<ActionResult> Manual(string id)
  424. {
  425. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  426. if (campNo.IsEmpty())
  427. {
  428. TempData[SelectDataKey] = new SelectCampModel
  429. {
  430. PageUrl = "/Exercise/Manual",
  431. PageTitle = "培训营演练情况手动记录",
  432. HasGroup = false
  433. };
  434. return RedirectToAction("SelectCamp");
  435. }
  436. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  437. if (camp == null)
  438. {
  439. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  440. }
  441. if (camp?.CampState == CampStateDefinition.End)
  442. {
  443. CheckErrors($"培训营已结束!");
  444. }
  445. //if (camp?.CampState!=CampStateDefinition.Run)
  446. //{
  447. // CheckErrors($"培训营未开始!");
  448. //}
  449. Session["CampNo"] = campNo;
  450. Session.Timeout = TimeOut;
  451. ViewBag.CampName = camp?.Name;
  452. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  453. return View();
  454. }
  455. /// <summary>
  456. /// GIS页面
  457. /// </summary>
  458. /// <param name="id"></param>
  459. /// <returns></returns>
  460. public async Task<ActionResult> Gis(string id)
  461. {
  462. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  463. if (campNo.IsEmpty())
  464. {
  465. TempData[SelectDataKey] = new SelectCampModel
  466. {
  467. PageUrl = "/Exercise/Gis",
  468. PageTitle = "培训营GIS推演实时路径",
  469. HasGroup = false
  470. };
  471. return RedirectToAction("SelectCamp");
  472. }
  473. var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  474. if (camp == null)
  475. {
  476. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  477. }
  478. if (camp?.CampState == CampStateDefinition.End)
  479. {
  480. CheckErrors($"培训营已结束!");
  481. }
  482. //if (camp?.CampState!=CampStateDefinition.Run)
  483. //{
  484. // CheckErrors($"培训营未开始!");
  485. //}
  486. Session["CampNo"] = campNo;
  487. Session.Timeout = TimeOut;
  488. ViewBag.CampNo = camp?.Id;
  489. ViewBag.CampName = camp?.Name;
  490. //ViewBag.Groups = await QueryApp.GetCampGroups(id);
  491. return View();
  492. }
  493. ///// <summary>
  494. ///// 选择培训营页面
  495. ///// </summary>
  496. ///// <param name="url"></param>
  497. ///// <param name="title"></param>
  498. ///// <param name="hasGroup"></param>
  499. ///// <returns></returns>
  500. //public async Task<ActionResult> Select(string url,string title,bool hasGroup)
  501. //{
  502. // string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  503. // ViewBag.Select = new SelectCampModel()
  504. // {
  505. // HasGroup = hasGroup,
  506. // PageTitle = title,
  507. // PageUrl = url,
  508. // CampSelect = str
  509. // };
  510. // return View("_Select");
  511. //}
  512. /// <summary>
  513. /// 选择培训营页面
  514. /// </summary>
  515. /// <returns></returns>
  516. public async Task<ActionResult> SelectCamp()
  517. {
  518. SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
  519. if (model == null)
  520. {
  521. return RedirectToAction("Student");
  522. }
  523. string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
  524. model.CampSelect = str;
  525. ViewBag.Select = model;
  526. return View("_Select");
  527. }
  528. [HttpGet]
  529. [WrapResult(false)]
  530. public async Task<ActionResult> QueryScore(string id)
  531. {
  532. if (id.IsEmpty())
  533. {
  534. var camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  535. if (camp == null)
  536. {
  537. CheckErrors("未查询到正在运行的培训营!");
  538. return Content("Error");
  539. }
  540. id = camp.Id;
  541. }
  542. var score = await QueryApp.GetScoreInfo(id);
  543. return Json(score, JsonRequestBehavior.AllowGet);
  544. }
  545. }
  546. }