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.
BookingHeChuan/Myshipping.Application/Service/BookingGoodsStatusConfig/BookingGoodsStatusConfigSer...

153 lines
5.2 KiB
C#

using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Myshipping.Application.Entity;
using Microsoft.Extensions.Logging;
using Furion.FriendlyException;
using Myshipping.Application.Enum;
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;
using MiniExcelLibs;
using NPOI.HSSF.UserModel;
using Myshipping.Core.Helper;
using NPOI.SS.UserModel;
using Furion;
using System;
using System.Web;
using System.Text;
using Myshipping.Application.ConfigOption;
using Myshipping.Core.Service;
namespace Myshipping.Application
{
/// <summary>
/// 订舱货物状态服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingGoodsStatusConfig", Order = 1)]
public class BookingGoodsStatusConfigService : IBookingGoodsStatusConfigService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BookingGoodsStatusConfig> _rep;
private readonly ILogger<BookingGoodsStatusConfig> _logger;
private readonly ISysCacheService _cache;
public BookingGoodsStatusConfigService(SqlSugarRepository<BookingGoodsStatusConfig> rep, ILogger<BookingGoodsStatusConfig> logger, ISysCacheService cache)
{
_rep = rep;
_logger = logger;
_cache = cache;
}
/// <summary>
/// 分页查询订舱货物状态
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingGoodsStatusConfig/page")]
public async Task<dynamic> Page([FromQuery] QueryBookingGoodsStatusConfigInput input)
{
//初次使用没有数据,进行初始化
2 years ago
InitGoodsStatusConfig(UserManager.UserId,UserManager.Name);
var entities = await _rep.AsQueryable()
.Where(m => m.CreatedUserId == UserManager.UserId)
.WhereIF(!string.IsNullOrEmpty(input.StatusName), u => u.StatusName.Contains(input.StatusName))
.OrderBy(m => m.Sort)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 保存订舱货物状态
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/BookingGoodsStatusConfig/save")]
public async Task<long> Save(SaveBookingGoodsStatusConfigInput input)
{
BookingGoodsStatusConfig model = null;
if (input.Id > 0)
{
if (_rep.Count(x => x.StatusName == input.StatusName && x.Id != input.Id) > 0)
{
throw Oops.Bah($"已存在相同名称的状态:{input.StatusName}");
}
model = _rep.FirstOrDefault(x => x.Id == input.Id);
input.Adapt(model);
await _rep.UpdateAsync(model);
}
else
{
if (_rep.Count(x => x.StatusName == input.StatusName) > 0)
{
throw Oops.Bah($"已存在相同名称的状态:{input.StatusName}");
}
model = input.Adapt<BookingGoodsStatusConfig>();
await _rep.InsertAsync(model);
}
return model.Id;
}
/// <summary>
/// 删除订舱货物状态
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("/BookingGoodsStatusConfig/delete")]
public async Task Delete(long id)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == id);
entity.IsDeleted = true;
await _rep.UpdateAsync(entity);
}
/// <summary>
/// 获取订舱货物状态
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("/BookingGoodsStatusConfig/detail")]
public async Task<BookingGoodsStatusConfig> Get(long id)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == id);
}
/// <summary>
/// 初始化当前用户的货物状态配置
/// </summary>
[NonAction]
2 years ago
public async void InitGoodsStatusConfig(long userid,string username)
{
2 years ago
if (_rep.AsQueryable().Count(x => x.CreatedUserId == userid) == 0)
{
var dicData = await _cache.GetAllDictData();
var listGoodsStatus = dicData.Where(x => x.TypeCode == "booking_goods_status").ToList();
listGoodsStatus.ForEach(async itm =>
{
await _rep.InsertAsync(new BookingGoodsStatusConfig()
{
StatusName = itm.Value,
Sort = itm.Sort,
2 years ago
SystemCode = itm.Code,
CreatedUserId=userid,
TenantId=UserManager.TENANT_ID,
CreatedUserName= username,
CreatedTime=DateTime.Now
});
});
}
}
}
}