|
@@ -12,6 +12,9 @@ using Hotline.Share.Tools;
|
|
|
using Hotline.Share.Enums.Planlibrary;
|
|
|
using Hotline.Application.ExportWord;
|
|
|
using Hotline.Application.Tools;
|
|
|
+using Hotline.KnowledgeBase;
|
|
|
+using Hotline.Share.Dtos.Knowledge;
|
|
|
+using System.Data;
|
|
|
|
|
|
namespace Hotline.Api.Controllers
|
|
|
{
|
|
@@ -129,6 +132,30 @@ namespace Hotline.Api.Controllers
|
|
|
|
|
|
#region 预案库管理
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 预案库分类列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="IsEnable"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("list/treelist")]
|
|
|
+ public async Task<List<PlanTypeDto>> QueryAllPlanTypeTreeList(bool? IsEnable)
|
|
|
+ {
|
|
|
+ return await _planTypeRepository.Queryable()
|
|
|
+ .WhereIF(IsEnable.HasValue, x => x.IsEnable == IsEnable)
|
|
|
+ .Where(x => SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).Any() ||
|
|
|
+ SqlFunc.Subqueryable<PlanTypeOrg>().Where(to => to.TypeId == x.Id).NotAny()
|
|
|
+ )
|
|
|
+ .Select(x => new PlanTypeDto()
|
|
|
+ {
|
|
|
+ Id = x.Id.SelectAll(),
|
|
|
+ PlanNum = SqlFunc.Subqueryable<PlanRelationType>().LeftJoin<PlanList>((kr, k) => kr.PlanId == k.Id)
|
|
|
+ .Where((kr, k) => kr.PlanTypeSpliceName.StartsWith(x.SpliceName))
|
|
|
+ .DistinctCount(kr => kr.PlanId)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .OrderBy(x => x.Sort).ToTreeAsync(it => it.children, it => it.ParentId, null, it => it.Id);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 预案库列表
|
|
|
/// </summary>
|
|
@@ -146,14 +173,39 @@ namespace Hotline.Api.Controllers
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("list/draft")]
|
|
|
- public async Task<string> AddPlanDraft([FromBody] AddPlanListDto dto)
|
|
|
+ public async Task<string> PlanDraft([FromBody] AddPlanListDto dto)
|
|
|
{
|
|
|
- dto.Status = EPlanStatus.Drafts;
|
|
|
+ dto.Status = EPlanStatus.NewDrafts;
|
|
|
return await _planApplication.AddPlanAsync(dto, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 预案库新增
|
|
|
+ /// 预案库草稿修改
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("list/draftupdate")]
|
|
|
+ public async Task UpdatePlanDraft([FromBody] UpdatePlanListDto dto)
|
|
|
+ {
|
|
|
+ dto.Status = EPlanStatus.NewDrafts;
|
|
|
+ await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 预案库草稿上架到审核
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("list/draftadd")]
|
|
|
+ public async Task AddPlanDraft([FromBody] UpdatePlanListDto dto)
|
|
|
+ {
|
|
|
+ dto.ApplyStatus = EPlanApplyStatus.Add;
|
|
|
+ dto.Status = EPlanStatus.Auditing;
|
|
|
+ await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 预案库新增到审核
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -166,7 +218,7 @@ namespace Hotline.Api.Controllers
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 预案库编辑
|
|
|
+ /// 预案库编辑提交到审核
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -183,7 +235,7 @@ namespace Hotline.Api.Controllers
|
|
|
/// </summary>
|
|
|
/// <param name="Id">预案库ID</param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPut("list/offshelf")]
|
|
|
+ [HttpGet("list/offshelf/{Id}")]
|
|
|
public async Task OffshelfPlan(string Id)
|
|
|
{
|
|
|
UpdatePlanListDto dto = new UpdatePlanListDto();
|
|
@@ -191,29 +243,28 @@ namespace Hotline.Api.Controllers
|
|
|
dto.ApplyStatus = EPlanApplyStatus.Offshelf;
|
|
|
dto.Status = EPlanStatus.Auditing;
|
|
|
|
|
|
- await _planApplication.UpdatePlanAsync(dto, HttpContext.RequestAborted);
|
|
|
+ await _planApplication.AuditPlanAsync(dto, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预案库审核(新增、修改、下架)
|
|
|
/// </summary>
|
|
|
- /// <param name="Id">预案库ID</param>
|
|
|
- /// <param name="state">0不通过 1通过</param>
|
|
|
+ /// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPut("list/examin")]
|
|
|
- public async Task ExaminPlan(string Id, int state)
|
|
|
+ public async Task ExaminPlan([FromBody] AuditPlanListDto dto)
|
|
|
{
|
|
|
- var plan = await _planListRepository.GetAsync(Id);
|
|
|
+ var plan = await _planListRepository.GetAsync(dto.Id);
|
|
|
if (plan == null)
|
|
|
throw UserFriendlyException.SameMessage("预案库查询失败");
|
|
|
|
|
|
var planDto = _mapper.Map<UpdatePlanListDto>(plan);
|
|
|
|
|
|
- if (state == 0)
|
|
|
+ if (dto.State == 0)
|
|
|
{//不同意
|
|
|
- planDto.Status = EPlanStatus.Drafts;
|
|
|
+ planDto.Status = EPlanStatus.Revert;
|
|
|
}
|
|
|
- else if (state == 1)
|
|
|
+ else if (dto.State == 1)
|
|
|
{//同意
|
|
|
if (planDto.ApplyStatus == EPlanApplyStatus.Add)
|
|
|
{
|
|
@@ -222,63 +273,63 @@ namespace Hotline.Api.Controllers
|
|
|
if (planDto.ApplyStatus == EPlanApplyStatus.Update)
|
|
|
{
|
|
|
planDto.Status = EPlanStatus.OnShelf;
|
|
|
+ planDto.UpdateTime = DateTime.Now;
|
|
|
}
|
|
|
if (planDto.ApplyStatus == EPlanApplyStatus.Offshelf)
|
|
|
{
|
|
|
planDto.Status = EPlanStatus.OffShelf;
|
|
|
}
|
|
|
}
|
|
|
- planDto.Id = Id;
|
|
|
+ planDto.Id = dto.Id;
|
|
|
planDto.ExaminTime = DateTime.Now;
|
|
|
planDto.ExaminManId = _sessionContext.UserId;
|
|
|
planDto.ExaminOrganizeId = _sessionContext.OrgId;
|
|
|
|
|
|
- await _planApplication.UpdatePlanAsync(planDto, HttpContext.RequestAborted);
|
|
|
+ await _planApplication.AuditPlanAsync(planDto, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预案库详情
|
|
|
/// </summary>
|
|
|
- /// <param name="Id">预案库ID</param>
|
|
|
- /// <param name="IsAddPv">默认不增加,false不增加,true增加浏览量</param>
|
|
|
+ /// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpGet("list/info/{Id}")]
|
|
|
- public async Task<PlanInfoDto> GetPlan(string Id, bool? IsAddPv)
|
|
|
+ [HttpGet("list/info")]
|
|
|
+ public async Task<PlanInfoDto> GetPlan([FromBody] PvPlanListDto dto)
|
|
|
{
|
|
|
- return await _planApplication.GetPlanAsync(Id, IsAddPv, HttpContext.RequestAborted);
|
|
|
+ return await _planApplication.GetPlanAsync(dto.Id, dto.IsAddPv, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预案库评分
|
|
|
/// </summary>
|
|
|
- /// <param name="Id">预案库ID</param>
|
|
|
- /// <param name="Score">评分</param>
|
|
|
+ /// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPut("list/score")]
|
|
|
- public async Task ScorePlan(string Id, decimal Score)
|
|
|
+ public async Task ScorePlan([FromBody] PvPlanListDto dto)
|
|
|
{
|
|
|
- var collect = await _planCollectRepository.GetAsync(x => x.PlanId == Id && x.CreatorId == _sessionContext.UserId);
|
|
|
+ var collect = await _planCollectRepository.GetAsync(x => x.PlanId == dto.Id && x.CreatorId == _sessionContext.UserId);
|
|
|
if (collect != null)
|
|
|
{
|
|
|
if (collect.Score > 0)
|
|
|
throw UserFriendlyException.SameMessage("当前知识已经评分");
|
|
|
|
|
|
- collect.Score = Score;
|
|
|
+ collect.Score = dto.Score;
|
|
|
await _planCollectRepository.UpdateAsync(collect, HttpContext.RequestAborted);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- collect.PlanId = Id;
|
|
|
- collect.Score = Score;
|
|
|
+ collect = new PlanCollect();
|
|
|
+ collect.PlanId = dto.Id;
|
|
|
+ collect.Score = dto.Score;
|
|
|
await _planCollectRepository.AddAsync(collect, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
//计算总分
|
|
|
- var sugar = _planCollectRepository.Queryable().Where(x => x.PlanId == Id);
|
|
|
+ var sugar = _planCollectRepository.Queryable().Where(x => x.PlanId == dto.Id);
|
|
|
var count = await sugar.CountAsync();
|
|
|
var collects = await sugar.SumAsync(x => x.Score);
|
|
|
var scoreTemp = collects / count;
|
|
|
- var plan = await _planListRepository.GetAsync(x => x.Id == Id);
|
|
|
+ var plan = await _planListRepository.GetAsync(x => x.Id == dto.Id);
|
|
|
if (plan != null)
|
|
|
{
|
|
|
plan.Score = decimal.Round(scoreTemp.Value, 1);
|
|
@@ -324,5 +375,28 @@ namespace Hotline.Api.Controllers
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region 预案库检索
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 预案库列表前10
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("list/top10")]
|
|
|
+ public async Task<List<PlanPageViewDto>> QueryTop10PlanList()
|
|
|
+ {
|
|
|
+ return await _planListRepository.Queryable()
|
|
|
+ .Take(10)
|
|
|
+ .Where(x => x.Status == EPlanStatus.OnShelf)
|
|
|
+ .Select(x => new PlanPageViewDto
|
|
|
+ {
|
|
|
+ Id = x.Id,
|
|
|
+ Title = x.Title,
|
|
|
+ PageView = x.PageView
|
|
|
+ })
|
|
|
+ .OrderBy(x => x.PageView, OrderByType.Desc)
|
|
|
+ .ToListAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|