| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803 |
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Web.Models;
- using Abp.Web.Mvc.Authorization;
- using IwbZero.ToolCommon.LogHelpers;
- using IwbZero.ToolCommon.StringModel;
- using System;
- using System.Data.Entity;
- using System.IO;
- using System.Speech.Synthesis;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using WeApp.BaseSystem.Query;
- using WeApp.CommonManager.Export;
- using WeApp.Configuration;
- using WeApp.TrainingCamp;
- using WeApp.TrainingCamp.Dto;
- using WeApp.TrainingCampGroup.Dto;
- using WeApp.TrainingPortrait;
- using WeApp.Views.Shared.Camp;
- namespace WeApp.Controllers
- {
- /// <summary>
- /// 演练实施
- /// </summary>
- [AbpAllowAnonymous, DisableAuditing]
- public class ExerciseV2Controller : IwbControllerBase
- {
- public ExerciseV2Controller(QueryAppService queryApp, IRepository<CampGroupInfo, string> groupRepository, IRepository<CampInfo, string> campRepository, PortraitAppService portraitApp, ExportManger exportManger)
- {
- QueryApp = queryApp;
- GroupRepository = groupRepository;
- CampRepository = campRepository;
- PortraitApp = portraitApp;
- _exportManger = exportManger;
- }
- protected QueryAppService QueryApp { get; }
- public const string SelectDataKey = "SELECTDATA";
- private int TimeOut = 60 * 5;
- protected IRepository<CampInfo, string> CampRepository { get; }
- protected IRepository<CampGroupInfo, string> GroupRepository { get; }
- protected PortraitAppService PortraitApp { get; }
- private readonly ExportManger _exportManger;
- public ActionResult Index()
- {
- Session["GroupNo"] = "";
- Session["CampNo"] = "";
- return View();
- }
- public ActionResult Clear()
- {
- Session["GroupNo"] = "";
- Session["CampNo"] = "";
- return Content("");
- }
- public ActionResult Select(int? id)
- {
- if (id == null)
- {
- return RedirectToAction("Index");
- }
- switch (id)
- {
- case 1:
- return RedirectToAction("Student");
- case 2:
- return RedirectToAction("Leader");
- case 3:
- return RedirectToAction("Public");
- case 4:
- return RedirectToAction("Specialist");
- case 5:
- return RedirectToAction("Manual");
- case 6:
- return RedirectToAction("Gis");
- default:
- return RedirectToAction("Index");
- }
- }
- /// <summary>
- /// 学员指挥部页面
- /// </summary>
- /// <returns></returns>
- public ActionResult HeadquarterStu()
- {
- return RedirectToAction("Headquarter");
- }
- /// <summary>
- /// 指挥长组建指挥部
- /// </summary>
- /// <returns></returns>
- public ActionResult HeadquarterLeader()
- {
- return RedirectToAction("Headquarter", new { id = 1 });
- }
- /// <summary>
- /// 组建指挥部
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Headquarter(int? id)
- {
- ViewBag.IsLeader = id == 1;
- string groupNo = (string)Session["GroupNo"];
- if (groupNo.IsEmpty())
- {
- if (id == 1)
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Leader",
- PageTitle = "指挥长屏选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Student",
- PageTitle = "学员屏选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- Session["GroupNo"] = groupNo;
- Session.Timeout = 60 * 5;
- var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
- return Content("");
- }
- if (group.CampInfo.CampState == CampStateDefinition.End)
- {
- CheckErrors($"培训营已演练结束!");
- }
- if (group.CampGroupState == CampGroupStateDefinition.End)
- {
- CheckErrors($"培训营分组已演练结束!");
- }
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- switch (group.CampGroupState)
- {
- case CampGroupStateDefinition.New:
- return View("Enter");
- case CampGroupStateDefinition.Ready:
- return View("Enter");
- case CampGroupStateDefinition.HeadQuarterBuilding:
- ViewBag.HasBuilded = false;
- return View();
- case CampGroupStateDefinition.HeadQuarterBuilded:
- ViewBag.HasBuilded = true;
- return View();
- }
- if (id == 1)
- {
- return RedirectToAction("Leader");
- }
- return RedirectToAction("Student");
- }
- /// <summary>
- /// 学员页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Student(string id)
- {
- string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
- if (groupNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Student",
- PageTitle = "学员屏选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
- return Content("");
- }
- Session["GroupNo"] = groupNo;
- Session.Timeout = TimeOut;
- if (group.CampGroupState != CampGroupStateDefinition.Run)
- {
- string text;
- switch (group.CampGroupState)
- {
- case CampGroupStateDefinition.Report:
- text = "正在生成演练报告";
- break;
- case CampGroupStateDefinition.End:
- text = "演练报告已生成";
- break;
- default:
- return RedirectToAction("HeadquarterStu");
- }
- ViewBag.IsLeader = false;
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- ViewBag.Text = text;
- return View("WaitRport");
- }
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- return View();
- }
- /// <summary>
- /// 指挥长页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Leader(string id)
- {
- string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
- if (groupNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Leader",
- PageTitle = "指挥长屏选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
- return Content("");
- }
- Session["GroupNo"] = groupNo;
- Session.Timeout = TimeOut;
- if (group.CampGroupState != CampGroupStateDefinition.Run)
- {
- string text;
- switch (group.CampGroupState)
- {
- case CampGroupStateDefinition.Report:
- text = "正在生成演练报告";
- break;
- case CampGroupStateDefinition.End:
- text = "演练报告已生成";
- break;
- default:
- return RedirectToAction("HeadquarterLeader");
- }
- ViewBag.IsLeader = true;
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- ViewBag.Text = text;
- return View("WaitRport");
- }
- //if (group.CampGroupState != CampGroupStateDefinition.Run)
- //{
- // return RedirectToAction("HeadquarterLeader");
- //}
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- return View();
- }
- /// <summary>
- /// 公共屏页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Public(string id)
- {
- string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
- if (groupNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Public",
- PageTitle = "公共屏选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == groupNo);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
- return Content("");
- }
- Session["GroupNo"] = groupNo;
- Session.Timeout = TimeOut;
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- if (group.CampGroupState != CampGroupStateDefinition.Run)
- {
- string text = "";
- switch (group.CampGroupState)
- {
- case CampGroupStateDefinition.New:
- text = "";
- break;
- case CampGroupStateDefinition.Ready:
- text = "培训营已就绪";
- break;
- case CampGroupStateDefinition.HeadQuarterBuilding:
- text = "正在组建指挥部";
- break;
- case CampGroupStateDefinition.HeadQuarterBuilded:
- text = "等待演练开始";
- break;
- case CampGroupStateDefinition.Report:
- text = "正在生成演练报告";
- break;
- case CampGroupStateDefinition.End:
- return RedirectToAction("StuReport", new { id = groupNo });
- }
- ViewBag.State = group.CampGroupState;
- ViewBag.Text = text;
- return View("PublicWait");
- }
- return View();
- }
- /// <summary>
- /// 公共屏页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [AccessOriginal]
- public async Task<ActionResult> Display(string id)
- {
- var group = await GroupRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefaultAsync(a => a.Id == id);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{id}】的培训营分组!");
- return Content("");
- }
- ViewBag.Group = ObjectMapper.Map<CampGroupDto>(group);
- if (group.CampGroupState != CampGroupStateDefinition.Run)
- {
- string text = "";
- switch (group.CampGroupState)
- {
- case CampGroupStateDefinition.New:
- text = "";
- break;
- case CampGroupStateDefinition.Ready:
- text = "培训营已就绪";
- break;
- case CampGroupStateDefinition.HeadQuarterBuilding:
- text = "正在组建指挥部";
- break;
- case CampGroupStateDefinition.HeadQuarterBuilded:
- text = "等待演练开始";
- break;
- case CampGroupStateDefinition.Report:
- text = "正在生成演练报告";
- break;
- case CampGroupStateDefinition.End:
- return RedirectToAction("StuReport", new { id });
- }
- ViewBag.State = group.CampGroupState;
- ViewBag.Text = text;
- return View("PublicWait");
- }
- return View("_Run/Display");
- }
- /// <summary>
- /// 专家屏页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Specialist(string id)
- {
- CampInfo camp;
- if (id == "1")
- {
- camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
- if (camp == null)
- {
- CheckErrors("未查询到正在运行的培训营!");
- return Content("Error");
- }
- }
- else
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Specialist",
- PageTitle = "专家屏选择培训营",
- HasGroup = false
- };
- return RedirectToAction("SelectCamp");
- }
- camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
- if (camp == null)
- {
- CheckErrors($"未查到到编号为【{campNo}】的培训营!");
- return null;
- }
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- }
- ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
- ViewBag.Groups = await QueryApp.GetCampGroups(id);
- if (camp.CampState != CampStateDefinition.Run)
- {
- var text = camp.CampState != CampStateDefinition.End ? "等待演练开始" : "演练已结束";
- ViewBag.Text = text;
- return View("SpecWait");
- }
- return View();
- }
- /// <summary>
- /// 主屏页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Play(string id)
- {
- CampInfo camp;
- if (id == "1")
- {
- camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
- if (camp == null)
- {
- CheckErrors("未查询到正在运行的培训营!");
- return Content("Error");
- }
- }
- else
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[ExerciseController.SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/Play/Index",
- PageTitle = "演示屏选择培训营",
- HasGroup = false
- };
- return RedirectToAction("SelectCamp", "ExerciseV2");
- }
- camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
- if (camp == null)
- {
- CheckErrors($"未查到到编号为【{campNo}】的培训营!");
- return null;
- }
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- }
- ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
- if (camp.CampState != CampStateDefinition.Run)
- {
- return View("_Play/Wait");
- }
- ViewBag.Groups = await QueryApp.GetCampGroups(id);
- return View("_Play/Index");
- }
- /// <summary>
- /// 主屏页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> PlayWithScore(string id)
- {
- CampInfo camp;
- if (id == "1")
- {
- camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
- if (camp == null)
- {
- CheckErrors("未查询到正在运行的培训营!");
- return Content("Error");
- }
- }
- else
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[ExerciseController.SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/Play/IndexWithScore",
- PageTitle = "演示屏选择培训营",
- HasGroup = false
- };
- return RedirectToAction("SelectCamp", "ExerciseV2" );
- }
- camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
- if (camp == null)
- {
- CheckErrors($"未查到到编号为【{campNo}】的培训营!");
- return null;
- }
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- }
- ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
- if (camp.CampState != CampStateDefinition.Run)
- {
- return View("_Play/Wait");
- }
- ViewBag.Groups = await QueryApp.GetCampGroups(id);
- return View("_Play/IndexWithScore");
- }
- /// <summary>
- /// 演练报告
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> StuReport(string id)
- {
- string groupNo = id.IsEmpty() ? (string)Session["GroupNo"] : id;
- if (groupNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/StuReport",
- PageTitle = "演练报告选择培训营",
- HasGroup = true
- };
- return RedirectToAction("SelectCamp");
- }
- var group = await PortraitApp.GetGroupReportBase(id);
- if (group == null)
- {
- CheckErrors($"未查到到编号为【{groupNo}】的培训营分组!");
- return Content("");
- }
- return View(group);
- }
- /// <summary>
- /// 手动记录演练页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Manual(string id)
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Manual",
- PageTitle = "培训营演练情况手动记录",
- HasGroup = false
- };
- return RedirectToAction("SelectCamp");
- }
- var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
- if (camp == null)
- {
- CheckErrors($"未查到到编号为【{campNo}】的培训营!");
- }
- if (camp?.CampState == CampStateDefinition.End)
- {
- CheckErrors($"培训营已结束!");
- }
- //if (camp?.CampState!=CampStateDefinition.Run)
- //{
- // CheckErrors($"培训营未开始!");
- //}
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- ViewBag.CampName = camp?.Name;
- ViewBag.Groups = await QueryApp.GetCampGroups(id);
- return View();
- }
- /// <summary>
- /// GIS页面
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ActionResult> Gis(string id)
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/Gis",
- PageTitle = "培训营GIS推演实时路径",
- HasGroup = false
- };
- return RedirectToAction("SelectCamp");
- }
- var camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
- if (camp == null)
- {
- CheckErrors($"未查到到编号为【{campNo}】的培训营!");
- }
- if (camp?.CampState == CampStateDefinition.End)
- {
- CheckErrors($"培训营已结束!");
- }
- //if (camp?.CampState!=CampStateDefinition.Run)
- //{
- // CheckErrors($"培训营未开始!");
- //}
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- ViewBag.CampNo = camp?.Id;
- ViewBag.CampName = camp?.Name;
- //ViewBag.Groups = await QueryApp.GetCampGroups(id);
- return View();
- }
- [AbpMvcAuthorize]
- public async Task<ActionResult> ExportSql(string id)
- {
- string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
- if (campNo.IsEmpty())
- {
- TempData[SelectDataKey] = new SelectCampModel
- {
- PageUrl = "/ExerciseV2/ExportSql",
- PageTitle = "导出SQL选择培训营",
- HasGroup = false
- };
- return RedirectToAction("SelectCampAll");
- }
- Session["CampNo"] = campNo;
- Session.Timeout = TimeOut;
- var path = await _exportManger.ExportSql(id);
- return Content($"{AppDomain.CurrentDomain.BaseDirectory}{path}");
- }
- ///// <summary>
- ///// 选择培训营页面
- ///// </summary>
- ///// <param name="url"></param>
- ///// <param name="title"></param>
- ///// <param name="hasGroup"></param>
- ///// <returns></returns>
- //public async Task<ActionResult> Select(string url,string title,bool hasGroup)
- //{
- // string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
- // ViewBag.Select = new SelectCampModel()
- // {
- // HasGroup = hasGroup,
- // PageTitle = title,
- // PageUrl = url,
- // CampSelect = str
- // };
- // return View("_Select");
- //}
- /// <summary>
- /// 选择培训营页面
- /// </summary>
- /// <returns></returns>
- public async Task<ActionResult> SelectCamp()
- {
- SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
- if (model == null)
- {
- return RedirectToAction("Student");
- }
- string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run);
- model.CampSelect = str;
- ViewBag.Select = model;
- return View("_Select");
- }
- /// <summary>
- /// 选择培训营页面
- /// </summary>
- /// <returns></returns>
- public async Task<ActionResult> SelectCampAll()
- {
- SelectCampModel model = (SelectCampModel)TempData[SelectDataKey];
- if (model == null)
- {
- return RedirectToAction("Student");
- }
- string str = await QueryApp.GetCampSelectStr(CampStateDefinition.Audit, CampStateDefinition.Run, CampStateDefinition.End);
- model.CampSelect = str;
- ViewBag.Select = model;
- return View("_Select");
- }
- [HttpGet]
- [WrapResult(false)]
- public ActionResult Voice(string txt, int? rate = null, int? vol = null)
- {
- using (MemoryStream ms = new MemoryStream())
- {
- var t = new Thread(() =>
- {
- using (SpeechSynthesizer sp = new SpeechSynthesizer())
- {
- try
- {
- sp.Rate = rate ?? 0;
- sp.Volume = vol ?? 90;
- sp.SetOutputToWaveStream(ms);
- sp.Speak(txt);
- }
- catch (Exception ex)
- {
- this.LogError(ex);
- throw;
- }
- }
- });
- t.Start();
- t.Join();
- ms.Position = 0;
- var buBytes = ms.GetBuffer();
- return new FileStreamResult(new MemoryStream(buBytes), "application/wav");
- }
- }
- [HttpGet]
- [WrapResult(false)]
- public async Task<ActionResult> QueryScore(string id)
- {
- if (id.IsEmpty())
- {
- var camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
- if (camp == null)
- {
- CheckErrors("未查询到正在运行的培训营!");
- return Content("Error");
- }
- id = camp.Id;
- }
- var score = await QueryApp.GetScoreInfo(id);
- return Json(score, JsonRequestBehavior.AllowGet);
- }
- }
- }
|