CampApplicationService.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. using Abp.Application.Services.Dto;
  2. using Abp.Auditing;
  3. using Abp.Authorization;
  4. using Abp.Configuration;
  5. using Abp.Domain.Repositories;
  6. using Abp.Domain.Uow;
  7. using Abp.Runtime.Caching;
  8. using IwbZero.AppServiceBase;
  9. using IwbZero.Auditing;
  10. using IwbZero.ToolCommon.StringModel;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data.Entity;
  14. using System.Linq;
  15. using System.Threading.Tasks;
  16. using System.Web.Mvc;
  17. using WeApp.Authorization;
  18. using WeApp.BaseInfo;
  19. using WeApp.BasicInfo;
  20. using WeApp.BasicInfo.PhoneQuestion.Dto;
  21. using WeApp.BasicInfo.StudentTip.Dto;
  22. using WeApp.BasicInfo.TrainingRoleGroup.Dto;
  23. using WeApp.Configuration;
  24. using WeApp.Configuration.Cache;
  25. using WeApp.TrainingCamp.Dto;
  26. using WeApp.TrainingCamp.Dto.Package;
  27. using WeEngine.CommonDto.WeInfo;
  28. namespace WeApp.TrainingCamp
  29. {
  30. [AbpAuthorize, AuditLog("演练培训营管理")]
  31. public class CampAppService : IwbAsyncCrudAppService<CampInfo, CampDto, string, IwbPagedRequestDto, CampCreateDto, CampUpdateDto>, ICampAppService
  32. {
  33. public CampAppService(
  34. ICacheManager cacheManager,
  35. IRepository<CampInfo, string> repository, IRepository<CampGroupInfo, string> groupRepository, IRepository<SysAttachFile> attachRepository, IRepository<CampSceneMapInfo> sceneMapRepository, IRepository<TrainingRoleGroupInfo, string> groupRoleRepository, IRepository<CampRelateGroupRoleInfo> crgRepository, IRepository<PhoneQuestionInfo, string> questionRepository, IRepository<StudentTipInfo, string> studentTipRepository) : base(repository, "Id")
  36. {
  37. GroupRepository = groupRepository;
  38. AttachRepository = attachRepository;
  39. SceneMapRepository = sceneMapRepository;
  40. GroupRoleRepository = groupRoleRepository;
  41. CrgRepository = crgRepository;
  42. QuestionRepository = questionRepository;
  43. StudentTipRepository = studentTipRepository;
  44. CacheManager = cacheManager;
  45. }
  46. private string DataCenterUrl => IwbSettingNames.GetWeDataCenterIp(SettingManager);
  47. protected override bool KeyIsAuto { get; set; } = false;
  48. protected IRepository<CampGroupInfo, string> GroupRepository { get; }
  49. protected IRepository<TrainingRoleGroupInfo, string> GroupRoleRepository { get; }
  50. protected IRepository<CampRelateGroupRoleInfo> CrgRepository { get; }
  51. protected IRepository<SysAttachFile> AttachRepository { get; }
  52. protected IRepository<CampSceneMapInfo> SceneMapRepository { get; }
  53. public IRepository<PhoneQuestionInfo, string> QuestionRepository { get; }
  54. public IRepository<StudentTipInfo, string> StudentTipRepository { get; }
  55. #region GetSelect
  56. [DisableAuditing]
  57. public override async Task<List<SelectListItem>> GetSelectList()
  58. {
  59. var list = await Repository.GetAllListAsync();
  60. var sList = new List<SelectListItem> { new SelectListItem { Text = @"请选择...", Value = "", Selected = true } };
  61. foreach (var l in list)
  62. {
  63. sList.Add(new SelectListItem { Value = l.Id, Text = l.Name });
  64. }
  65. return sList;
  66. }
  67. [DisableAuditing]
  68. public override async Task<string> GetSelectStr()
  69. {
  70. var list = await Repository.GetAllListAsync();
  71. string str = "<option value=\"\" selected>请选择...</option>";
  72. foreach (var l in list)
  73. {
  74. str += $"<option value=\"{l.Id}\">{l.Name}</option>";
  75. }
  76. return str;
  77. }
  78. /// <summary>
  79. /// 方案包select
  80. /// </summary>
  81. /// <returns></returns>
  82. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  83. public Task<string> GetPackageSelectStr()
  84. {
  85. var list = CacheManager.GetPackageInfos(DataCenterUrl);
  86. string str = "<option value=\"\" selected>请选择方案包...</option>";
  87. if (list != null && list.Any())
  88. {
  89. foreach (var l in list)
  90. {
  91. str += $"<option value=\"{l.Id}\" data-model-type=\"{l.EngineModelType}\" data-model-name=\"{l.EngineModelName}\">{l.PackageName}</option>";
  92. }
  93. }
  94. return Task.FromResult(str);
  95. }
  96. /// <summary>
  97. /// 附件select
  98. /// </summary>
  99. /// <returns></returns>
  100. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach)]
  101. public async Task<string> GetAttachSelectStr(string no)
  102. {
  103. var list = await AttachRepository.GetAllListAsync(a => a.TableName == "Train" && a.ColumnName == "CampPackage" && a.SourceKey.StartsWith(no));
  104. string str = "<option value=\"\" selected>请选择附件...</option>";
  105. if (list != null && list.Any())
  106. {
  107. foreach (var l in list)
  108. {
  109. str += $"<option value=\"{l.AttachNo}\" >{l.FileTitle}</option>";
  110. }
  111. }
  112. return str;
  113. }
  114. #endregion GetSelect
  115. #region CURD
  116. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgCreate)]
  117. public override async Task Create(CampCreateDto input)
  118. {
  119. input.Id = await AppGuidManager.GetNextRecordIdAsync(DataLibType.Camp);
  120. input.CampState = CampStateDefinition.New;
  121. if (input.AssessRoleNames.IsEmpty())
  122. {
  123. input.AssessAuto = false;
  124. }
  125. await CreateEntity(input);
  126. }
  127. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgUpdate)]
  128. public override async Task Update(CampUpdateDto input)
  129. {
  130. if (input.AssessRoleNames.IsEmpty())
  131. {
  132. input.AssessAuto = false;
  133. }
  134. var entity = await CheckEntity(input.Id);
  135. if (input.CampState == CampStateDefinition.Audit)
  136. {
  137. if (entity.EvalBehaviorTags.IsEmpty())
  138. {
  139. CheckErrors("请先配置好行为评估标签,再通过审核!");
  140. }
  141. if ((await CrgRepository.CountAsync(a => a.CampNo == entity.Id)) == 0)
  142. {
  143. CheckErrors("请先配置好角色预案,再通过审核!");
  144. }
  145. }
  146. await UpdateEntity(input, entity);
  147. }
  148. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgDelete)]
  149. public override async Task Delete(EntityDto<string> input)
  150. {
  151. await CheckEntity(input.Id);
  152. await base.Delete(input);
  153. }
  154. [DisableAuditing]
  155. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  156. public override async Task<PagedResultDto<CampDto>> GetAll(IwbPagedRequestDto input)
  157. {
  158. var query = CreateFilteredQuery(input);
  159. query = ApplyFilter(query, input);
  160. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  161. query = ApplySorting(query, input);
  162. query = ApplyPaging(query, input);
  163. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  164. var dtoList = new PagedResultDto<CampDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  165. return dtoList;
  166. }
  167. #region GetEntity/Dto
  168. /// <summary>
  169. /// 查询实体Dto
  170. /// </summary>
  171. /// <param name="input"></param>
  172. /// <returns></returns>
  173. [DisableAuditing]
  174. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  175. public override async Task<CampDto> GetDto(EntityDto<string> input)
  176. {
  177. var entity = await GetEntity(input);
  178. return MapToEntityDto(entity);
  179. }
  180. /// <summary>
  181. /// 查询实体Dto
  182. /// </summary>
  183. /// <param name="id"></param>
  184. /// <returns></returns>
  185. [DisableAuditing]
  186. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  187. public override async Task<CampDto> GetDtoById(string id)
  188. {
  189. var entity = await GetEntityById(id);
  190. return MapToEntityDto(entity);
  191. }
  192. /// <summary>
  193. /// 查询实体Dto(需指明自定义字段)
  194. /// </summary>
  195. /// <param name="no"></param>
  196. /// <returns></returns>
  197. [DisableAuditing]
  198. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  199. public override async Task<CampDto> GetDtoByNo(string no)
  200. {
  201. var entity = await GetEntityByNo(no);
  202. return MapToEntityDto(entity);
  203. }
  204. /// <summary>
  205. /// 查询实体
  206. /// </summary>
  207. /// <param name="input"></param>
  208. /// <returns></returns>
  209. [DisableAuditing]
  210. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  211. public override async Task<CampInfo> GetEntity(EntityDto<string> input)
  212. {
  213. var entity = await GetEntityById(input.Id);
  214. return entity;
  215. }
  216. /// <summary>
  217. /// 查询实体
  218. /// </summary>
  219. /// <param name="id"></param>
  220. /// <returns></returns>
  221. [DisableAuditing]
  222. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  223. public override async Task<CampInfo> GetEntityById(string id)
  224. {
  225. return await Repository.FirstOrDefaultAsync(a => a.Id == id);
  226. }
  227. /// <summary>
  228. /// 查询实体(需指明自定义字段)
  229. /// </summary>
  230. /// <param name="no"></param>
  231. /// <returns></returns>
  232. [DisableAuditing]
  233. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  234. public override async Task<CampInfo> GetEntityByNo(string no)
  235. {
  236. //CheckGetPermission();
  237. if (string.IsNullOrEmpty(KeyFiledName))
  238. {
  239. ThrowError("NoKeyFieldName");
  240. }
  241. return await base.GetEntityByNo(no);
  242. }
  243. #endregion GetEntity/Dto
  244. #region Hide
  245. ///// <summary>
  246. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{CampInfo}"/>过滤查询.
  247. ///// </summary>
  248. ///// <param name="input">The input.</param>
  249. //protected override IQueryable<CampInfo> CreateFilteredQuery(IwbPagedRequestDto input)
  250. //{
  251. // var query = Repository.GetAll();
  252. // var pagedInput = input as IIwbPagedRequest;
  253. // if (pagedInput == null)
  254. // {
  255. // return query;
  256. // }
  257. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  258. // {
  259. // object keyWords = pagedInput.KeyWords;
  260. // LambdaObject obj = new LambdaObject()
  261. // {
  262. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  263. // FieldName = pagedInput.KeyField,
  264. // FieldValue = keyWords,
  265. // ExpType = (LambdaExpType)pagedInput.ExpType
  266. // };
  267. // var exp = obj.GetExp<CampInfo>();
  268. // query = exp != null ? query.Where(exp) : query;
  269. // }
  270. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  271. // {
  272. // List<LambdaObject> objList = new List<LambdaObject>();
  273. // foreach (var o in pagedInput.SearchList)
  274. // {
  275. // if (string.IsNullOrEmpty(o.KeyWords))
  276. // continue;
  277. // object keyWords = o.KeyWords;
  278. // objList.Add(new LambdaObject
  279. // {
  280. // FieldType = (LambdaFieldType)o.FieldType,
  281. // FieldName = o.KeyField,
  282. // FieldValue = keyWords,
  283. // ExpType = (LambdaExpType)o.ExpType
  284. // });
  285. // }
  286. // var exp = objList.GetExp<CampInfo>();
  287. // query = exp != null ? query.Where(exp) : query;
  288. // }
  289. // return query;
  290. //}
  291. //protected override IQueryable<CampInfo> ApplySorting(IQueryable<CampInfo> query, IwbPagedRequestDto input)
  292. //{
  293. // return query.OrderBy(a => a.No);
  294. //}
  295. //protected override IQueryable<CampInfo> ApplyPaging(IQueryable<CampInfo> query, IwbPagedRequestDto input)
  296. //{
  297. // if (input is IPagedResultRequest pagedInput)
  298. // {
  299. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  300. // }
  301. // return query;
  302. //}
  303. #endregion Hide
  304. #endregion CURD
  305. #region CampGroup
  306. /// <summary>
  307. /// 检查方案包是否分组
  308. /// </summary>
  309. /// <returns></returns>
  310. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgGroup), DisableAuditing]
  311. public async Task<string> CheckCampGroup(string no)
  312. {
  313. using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete))
  314. {
  315. if ((await GroupRepository.GetAllListAsync(a => a.CampNo == no)).Any())
  316. {
  317. return $"/Train/CampGroup/{no}";
  318. }
  319. }
  320. return "";
  321. }
  322. /// <summary>
  323. /// 方案包分组
  324. /// </summary>
  325. /// <returns></returns>
  326. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgGroup), AuditLog("方案包分组")]
  327. public async Task<string> Group(GroupCreateDto input)
  328. {
  329. var entity = await CheckEntity(input.CampNo);
  330. for (int i = 1; i <= input.Count; i++)
  331. {
  332. var group = new CampGroupInfo()
  333. {
  334. CampNo = input.CampNo,
  335. Id = $"{input.CampNo}_{i.LeftPad(3)}",
  336. Name = $"第{i}组",
  337. CampGroupState = CampGroupStateDefinition.New,
  338. };
  339. await GroupRepository.InsertAsync(group);
  340. }
  341. return $"/Train/CampGroup/{entity.Id}";
  342. }
  343. #endregion CampGroup
  344. #region Attach
  345. /// <summary>
  346. /// 配置附件
  347. /// </summary>
  348. /// <returns></returns>
  349. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach), DisableAuditing]
  350. public async Task<string> CheckAttach(string no)
  351. {
  352. var entity = await CheckEntity(no);
  353. return $"/Train/CampAttach/{entity.Id}";
  354. }
  355. /// <summary>
  356. /// 配置附件
  357. /// </summary>
  358. /// <returns></returns>
  359. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach), AuditLog("配置附件")]
  360. public async Task AttachFile(CampSceneAttachDto input)
  361. {
  362. var entity = await CheckEntity(input.CampNo);
  363. var sceneAttach = await
  364. SceneMapRepository.FirstOrDefaultAsync(a => a.CampNo == entity.Id && a.SceneNo == input.SceneNo);
  365. if (sceneAttach == null)
  366. {
  367. sceneAttach = new CampSceneMapInfo()
  368. {
  369. CampNo = input.CampNo,
  370. SceneNo = input.SceneNo,
  371. SceneName = input.SceneName,
  372. AttachNos = input.AttachNos,
  373. TipNos = input.TipNos,
  374. PhoneQuestionNo = input.PhoneQuestionNos
  375. };
  376. await SceneMapRepository.InsertAsync(sceneAttach);
  377. }
  378. else
  379. {
  380. sceneAttach.AttachNos = input.AttachNos;
  381. sceneAttach.TipNos = input.TipNos;
  382. sceneAttach.PhoneQuestionNo = input.PhoneQuestionNos;
  383. await SceneMapRepository.UpdateAsync(sceneAttach);
  384. await CurrentUnitOfWork.SaveChangesAsync();
  385. await CacheManager.GetCache(IwbCacheNames.SceneInfoCache).RemoveAsync($"{entity.Id}-{input.SceneNo}");
  386. await CacheManager.GetCache(IwbCacheNames.SceneInfoCache).RemoveAsync($"A-{entity.Id}-{input.SceneNo}");
  387. }
  388. }
  389. /// <summary>
  390. /// 删除情景附件
  391. /// </summary>
  392. /// <returns></returns>
  393. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach), AuditLog("删除情景附件")]
  394. public async Task DeleteAttach(string no)
  395. {
  396. var sceneAttach = await SceneMapRepository.FirstOrDefaultAsync(a => a.AttachNos.Contains(no));
  397. if (sceneAttach != null)
  398. {
  399. CheckErrors($"此附件已被配置,无法删除!");
  400. return;
  401. }
  402. await AttachRepository.DeleteAsync(a => a.AttachNo == no);
  403. }
  404. /// <summary>
  405. /// 获取培训营相关附件
  406. /// </summary>
  407. /// <param name="input"></param>
  408. /// <param name="no"></param>
  409. /// <returns></returns>
  410. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach), DisableAuditing]
  411. public async Task<PagedResultDto<CampSceneAttachDto>> GetSceneAttaches(IwbPagedRequestDto input, string no)
  412. {
  413. //var no = input.SearchList?.FirstOrDefault(a=>a.KeyField=="CampNo")?.KeyWords??"";
  414. var entity = await CheckEntity(no);
  415. var sceneAttach = await SceneMapRepository.GetAllListAsync(a => a.CampNo == no);
  416. var package = GetPackageDetail(entity.PackageNo);
  417. var scenes = package.Scenes;
  418. var totalCount = scenes.Count;
  419. var query = scenes.AsQueryable();
  420. scenes = ApplyFilter(query, input).ToList();
  421. scenes = scenes.OrderBy(a => a.Id).Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  422. var dtoList = new List<CampSceneAttachDto>();
  423. foreach (var scene in scenes)
  424. {
  425. var dto = new CampSceneAttachDto()
  426. {
  427. SceneNo = scene.Id,
  428. SceneName = scene.Name,
  429. CampNo = no,
  430. CampName = entity.Name
  431. };
  432. var sceneMap = sceneAttach.FirstOrDefault(a => a.SceneNo == scene.Id);
  433. if (sceneMap != null)
  434. {
  435. dto.AttachNos = sceneMap.AttachNos;
  436. dto.AttachInfos = await AttachRepository.GetAll()
  437. .Where(a => sceneMap.AttachNos.Contains(a.AttachNo)).Select(attach => new CampAttachDto()
  438. {
  439. AttachNo = attach.AttachNo,
  440. CampNo = no,
  441. FileType = attach.FileType,
  442. FileTitle = attach.FileTitle,
  443. FileName = attach.FileName,
  444. FilePath = attach.FilePath
  445. }).ToListAsync();
  446. dto.TipNos = sceneMap.TipNos;
  447. dto.TipInfos = await StudentTipRepository.GetAll().Where(a => sceneMap.TipNos.Contains(a.Id))
  448. .Select(a => new StudentTipDto()
  449. {
  450. Id = a.Id,
  451. Name = a.Name,
  452. RoleName = a.RoleName,
  453. Content = a.Content
  454. }).ToListAsync();
  455. dto.PhoneQuestionNos = sceneMap.PhoneQuestionNo;
  456. dto.QuestionInfo = await QuestionRepository.GetAll().Where(a => a.Id == sceneMap.PhoneQuestionNo).Select(a => new PhoneQuestionDto
  457. {
  458. Id = a.Id,
  459. Name = a.Name,
  460. }).FirstOrDefaultAsync();
  461. }
  462. dtoList.Add(dto);
  463. }
  464. return new PagedResultDto<CampSceneAttachDto>(totalCount, dtoList);
  465. }
  466. /// <summary>
  467. /// 获取培训营相关附件
  468. /// </summary>
  469. /// <param name="input"></param>
  470. /// <param name="no"></param>
  471. /// <returns></returns>
  472. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgAttach), DisableAuditing]
  473. public async Task<PagedResultDto<CampAttachDto>> GetAttachFiles(IwbPagedRequestDto input, string no)
  474. {
  475. //var no = input.SearchList?.FirstOrDefault(a=>a.KeyField=="CampNo")?.KeyWords??"";
  476. var query = AttachRepository.GetAll()
  477. .Where(a => a.TableName == "Train" && a.ColumnName == "CampPackage" && a.SourceKey.StartsWith(no)).Select(a =>
  478. new CampAttachDto()
  479. {
  480. AttachNo = a.AttachNo,
  481. CampNo = a.SourceKey,
  482. FileName = a.FileName,
  483. FilePath = a.FilePath,
  484. FileType = a.FileType,
  485. FileTitle = a.FileTitle,
  486. FileExt = a.FileExt
  487. });
  488. query = ApplyFilter(query, input);
  489. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  490. query = query.OrderBy(a => a.CampNo);
  491. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  492. var entities = await query.ToListAsync();
  493. return new PagedResultDto<CampAttachDto>(totalCount, entities);
  494. }
  495. #endregion Attach
  496. #region Tag
  497. /// <summary>
  498. /// 配置标签
  499. /// </summary>
  500. /// <returns></returns>
  501. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgTag), DisableAuditing]
  502. public async Task<CampTagDto> GetBehaviorTags(string no)
  503. {
  504. var entity = await CheckEntity(no);
  505. var dto = new CampTagDto()
  506. {
  507. CampNo = no,
  508. BehaviorTagNos = entity.EvalBehaviorTags,
  509. };
  510. var package = GetPackageDetail(entity.PackageNo);
  511. dto.AllTags = package.BehaviorTags.IwbDistinct(a => a.TagNo).OrderBy(a => a.TagNo).ToList();
  512. return dto;
  513. }
  514. /// <summary>
  515. /// 配置标签
  516. /// </summary>
  517. /// <returns></returns>
  518. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgTag), AuditLog("配置标签")]
  519. public async Task BehaviorTag(CampTagDto input)
  520. {
  521. if (input.BehaviorTagNos.IsEmpty())
  522. {
  523. CheckErrors("至少选择一个评估标签!");
  524. }
  525. var entity = await CheckEntity(input.CampNo);
  526. entity.EvalBehaviorTags = input.BehaviorTagNos;
  527. await Repository.UpdateAsync(entity);
  528. await CacheManager.GetCache(IwbCacheNames.CampInfoCache).RemoveAsync($"TAG{input.CampNo}");
  529. }
  530. #endregion Tag
  531. #region RoleGroup
  532. /// <summary>
  533. /// 获取全部角色预案
  534. /// </summary>
  535. /// <returns></returns>
  536. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgRole), DisableAuditing]
  537. public async Task<CampRoleGroupDto> GetGroupRoles(string no)
  538. {
  539. var entity = await CheckEntity(no);
  540. var roleGroups = (await GroupRoleRepository.GetAllListAsync()).Select(ObjectMapper.Map<TrainingRoleGroupDto>).ToList();
  541. var roleGroupNos = await CrgRepository.GetAll().Where(a => a.CampNo == entity.Id).Select(a => a.RoleGroupNo)
  542. .ToListAsync();
  543. var dto = new CampRoleGroupDto()
  544. {
  545. AllGroups = roleGroups,
  546. CampNo = no,
  547. GroupNos = roleGroupNos
  548. };
  549. return dto;
  550. }
  551. /// <summary>
  552. /// 角色预案
  553. /// </summary>
  554. /// <returns></returns>
  555. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgRole), AuditLog("角色预案")]
  556. public async Task RoleGroup(CampRoleGroupDto input)
  557. {
  558. var entity = await CheckEntity(input.CampNo);
  559. if (input.GroupNos != null && input.GroupNos.Any())
  560. {
  561. var oldGroupNos = await CrgRepository.GetAll().Where(a => a.CampNo == entity.Id).Select(a => a.RoleGroupNo).ToListAsync();
  562. foreach (var no in input.GroupNos)
  563. {
  564. if (oldGroupNos.Contains(no))
  565. {
  566. oldGroupNos.Remove(no);
  567. }
  568. else
  569. {
  570. var cgr = new CampRelateGroupRoleInfo()
  571. {
  572. CampNo = entity.Id,
  573. RoleGroupNo = no,
  574. };
  575. await CrgRepository.InsertAsync(cgr);
  576. }
  577. }
  578. if (oldGroupNos.Any())
  579. {
  580. await CrgRepository.DeleteAsync(a => oldGroupNos.Contains(a.RoleGroupNo));
  581. }
  582. }
  583. else
  584. {
  585. CheckErrors("至少选择一个角色预案!");
  586. }
  587. }
  588. #endregion RoleGroup
  589. private async Task<CampInfo> CheckEntity(string no)
  590. {
  591. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == no);
  592. if (entity == null)
  593. {
  594. CheckErrors($"未查询编号为【{no}】到培训营!");
  595. return null;
  596. }
  597. if (entity.CampState != CampStateDefinition.New && entity.CampState != CampStateDefinition.Audit)
  598. {
  599. CheckErrors("培训营已运行,不能操作!");
  600. }
  601. return entity;
  602. }
  603. #region Package
  604. /// <summary>
  605. /// 查询方案包配置信息
  606. /// </summary>
  607. /// <param name="id"></param>
  608. /// <param name="packageNo"></param>
  609. /// <returns></returns>
  610. public async Task<PackageSettingDto> GetPackageSetting(string id, string packageNo)
  611. {
  612. var dto = new PackageSettingDto();
  613. if (packageNo.IsEmpty())
  614. {
  615. CheckErrors($"方案包编号不能为空!");
  616. return null;
  617. }
  618. var package = CacheManager.GetPackageInfo(packageNo, DataCenterUrl);
  619. dto.AllRoles = package.AllRoles;
  620. dto.AssessAuto = package.AssessAuto;
  621. dto.AssessRoleNames = package.AssessRoleNames;
  622. dto.RoundScore = 0;
  623. dto.Variable = package.Variable;
  624. if (id.IsNotEmpty() && id != "none")
  625. {
  626. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == id);
  627. if (entity == null)
  628. {
  629. CheckErrors($"未查询编号为【{id}】到培训营!");
  630. return null;
  631. }
  632. if (entity.PackageNo == packageNo)
  633. {
  634. dto.AssessAuto = entity.AssessAuto;
  635. dto.AssessRoleNames = entity.AssessRoleNames;
  636. dto.RoundScore = entity.RoundScore == 0 ? dto.RoundScore : entity.RoundScore;
  637. dto.Variable = entity.Variable.IsEmpty() ? dto.Variable : entity.Variable;
  638. }
  639. }
  640. return dto;
  641. }
  642. /// <summary>
  643. /// 方案包详情
  644. /// </summary>
  645. /// <param name="no"></param>
  646. /// <returns></returns>
  647. [AbpAuthorize(PermissionNames.PagesTrainMgCampMgQuery)]
  648. public WePackageDetailDto GetPackageDetail(string no)
  649. {
  650. var dto = CacheManager.GetPackageDetail(no, DataCenterUrl);
  651. return dto;
  652. }
  653. #endregion Package
  654. }
  655. }