CampApplicationService.cs 31 KB

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