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.Op.Interface;
using DS.WMS.Core.TaskPlat.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace DS.WMS.OpApi.Controllers
{
///
/// 大简云服务项目服务 模块
///
public class DjyServiceStatusController : ApiController
{
private readonly IDjyServiceStatusService _invokeService;
private readonly IServiceProvider serviceProvider;
private readonly IUser user;
private readonly ISaasDbService saasDbService;
private readonly ISeaExportCommonService _seaComService;
///
/// 构造函数
///
public DjyServiceStatusController(IDjyServiceStatusService invokeService,
IServiceProvider serviceProvider,
IUser user,
ISaasDbService saasDbService)
{
_invokeService = invokeService;
this.serviceProvider = serviceProvider;
this.user = user;
this.saasDbService = saasDbService;
this._seaComService = serviceProvider.GetRequiredService();
}
///
/// 保存服务项目
///
///
/// 返回回执
[HttpPost]
[Route("SaveServiceProject")]
public async Task SaveServiceProject([FromBody] EmbedServiceProjectDto req)
{
//手动更新海运出口服务项目
_seaComService.UpdateSeaExportServiceItem(long.Parse(req.BusinessId), req.ProjectCodes[0], true);
return await _invokeService.SaveServiceProject(req);
}
///
/// 取消服务项目
///
///
/// 返回回执
[HttpPost]
[Route("CancelServiceProject")]
public async Task CancelServiceProject([FromBody] EmbedServiceProjectDto req)
{
//手动更新海运出口服务项目
_seaComService.UpdateSeaExportServiceItem(long.Parse(req.BusinessId), req.ProjectCodes[0], false);
return await _invokeService.CancelServiceProject(req);
}
///
/// 获取服务项目列表
///
///
/// 返回回执
[HttpPost]
[Route("GetServiceProjectList")]
public async Task GetServiceProjectList([FromBody] EmbedQueryServiceProjectWithStatus req)
{
return await _invokeService.GetServiceProjectList(req);
}
///
/// 获取服务项目下的状态列表
///
///
/// 返回回执
[HttpPost]
[Route("GetServiceStatusList")]
public async Task 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()
.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;
}
///
/// 保存服务状态
///
///
/// 返回回执
[HttpPost]
[Route("SaveServiceStatus")]
public async Task SaveServiceStatus([FromBody] EmbedServiceProjectStatusDto req)
{
if (req.StatusCodes[0].StatusCode.Contains("BG")|| req.StatusCodes[0].StatusCode.Contains("YPC")|| req.StatusCodes[0].StatusCode.Contains("YDC") || req.StatusCodes[0].StatusCode.Contains("YFVGM") )
{
_seaComService.UpdateSeaExportTag(long.Parse(req.businessId), req.StatusCodes[0].StatusCode,true);
}
return await _invokeService.SaveServiceStatus(req);
}
///
/// 取消服务状态
///
///
/// 返回回执
[HttpPost]
[Route("CancelServiceStatus")]
public async Task CancelServiceStatus([FromBody] EmbedServiceProjectStatusDto req)
{
if (req.StatusCodes[0].StatusCode.Contains("BG") || req.StatusCodes[0].StatusCode.Contains("YPC") || req.StatusCodes[0].StatusCode.Contains("YDC") || req.StatusCodes[0].StatusCode.Contains("YFVGM"))
{
_seaComService.UpdateSeaExportTag(long.Parse(req.businessId), req.StatusCodes[0].StatusCode, false);
}
return await _invokeService.CancelServiceStatus(req);
}
///
/// 获取可用的服务项目字典列表
///
/// 是否重新加载缓存
///
[HttpGet]
[Route("GetEnableProjectDictTreeList")]
public async Task GetEnableProjectDictTreeList([FromQuery] bool isAvoidCache = false)
{
return await _invokeService.GetEnableProjectDictTreeList(isAvoidCache);
}
}
}