You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.7 KiB
C#

using DS.Module.Core;
using DS.Module.DjyServiceStatus;
using DS.Module.ExcelModule;
using DS.Module.ExcelModule.Model;
using DS.Module.PrintModule;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.TaskPlat.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace DS.WMS.OpApi.Controllers
{
/// <summary>
/// 大简云服务项目服务 模块
/// </summary>
public class DjyServiceStatusController : ApiController
{
private readonly IDjyServiceStatusService _invokeService;
private readonly IServiceProvider serviceProvider;
private readonly IUser user;
private readonly ISaasDbService saasDbService;
/// <summary>
/// 构造函数
/// </summary>
public DjyServiceStatusController(IDjyServiceStatusService invokeService,
IServiceProvider serviceProvider,
IUser user,
ISaasDbService saasDbService)
{
_invokeService = invokeService;
this.serviceProvider = serviceProvider;
this.user = user;
this.saasDbService = saasDbService;
}
/// <summary>
/// 保存服务项目
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("SaveServiceProject")]
public async Task<DjyResult> SaveServiceProject([FromBody] EmbedServiceProjectDto req)
{
return await _invokeService.SaveServiceProject(req);
}
/// <summary>
/// 取消服务项目
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("CancelServiceProject")]
public async Task<DjyResult> CancelServiceProject([FromBody] EmbedServiceProjectDto req)
{
return await _invokeService.CancelServiceProject(req);
}
/// <summary>
/// 获取服务项目列表
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("GetServiceProjectList")]
public async Task<DjyResult> GetServiceProjectList([FromBody] EmbedQueryServiceProjectWithStatus req)
{
return await _invokeService.GetServiceProjectList(req);
}
/// <summary>
/// 获取服务项目下的状态列表
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("GetServiceStatusList")]
public async Task<DjyResult> GetServiceStatusList([FromBody] EmbedQueryServiceProjectWithStatus req)
{
var result = await _invokeService.GetServiceStatusList(req);
if (result?.data != null
&& ((JObject)result.data)["ext"] is JArray extArray
&& extArray.Count > 0
&& long.TryParse(req.BusinessId, out long businessId))
{
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
var skuCodeList = extArray.Select(x => x["statusSKUCode"]?.ToString()).Distinct().ToList();
if (skuCodeList.Count > 0)
{
var allotDataList = await tenantDb.Queryable<TaskBaseAllocation>()
.Where(x => x.BusinessId == businessId && skuCodeList.Contains(x.GoodStatusCode))
.OrderBy(x => x.Id)
.Select(x => new { x.GoodStatusCode, x.UserName, x.StatusName, x.StatusTime })
.ToListAsync();
foreach (JToken item in extArray)
{
var skuCode = item["statusSKUCode"]?.ToString();
if (skuCode != null)
{
var allotData = allotDataList.Where(x => x.GoodStatusCode == skuCode).ToList();
if (allotData.Count > 0)
{
item["allotUserList"] = JArray.FromObject(allotData);
}
}
}
}
}
return result;
}
/// <summary>
/// 保存服务状态
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("SaveServiceStatus")]
public async Task<DjyResult> SaveServiceStatus([FromBody] EmbedServiceProjectStatusDto req)
{
return await _invokeService.SaveServiceStatus(req);
}
/// <summary>
/// 取消服务状态
/// </summary>
/// <param name="req"></param>
/// <returns>返回回执</returns>
[HttpPost]
[Route("CancelServiceStatus")]
public async Task<DjyResult> CancelServiceStatus([FromBody] EmbedServiceProjectStatusDto req)
{
return await _invokeService.CancelServiceStatus(req);
}
/// <summary>
/// 获取可用的服务项目字典列表
/// </summary>
/// <param name="isAvoidCache">是否重新加载缓存</param>
/// <returns></returns>
[HttpGet]
[Route("GetEnableProjectDictTreeList")]
public async Task<DjyResult> GetEnableProjectDictTreeList([FromQuery] bool isAvoidCache = false)
{
return await _invokeService.GetEnableProjectDictTreeList(isAvoidCache);
}
}
}