CampApplicationService.cs 31 KB

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