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.
146 lines
4.9 KiB
C#
146 lines
4.9 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.Core.Entity;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Myshipping.Core.Service
|
|
{
|
|
/// <summary>
|
|
/// 用户自定义配置服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Name = "DjyUserConfig", Order = 1)]
|
|
public class DjyUserConfigService : IDjyUserConfigService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<DjyUserConfig> _rep;
|
|
|
|
public DjyUserConfigService(SqlSugarRepository<DjyUserConfig> rep)
|
|
{
|
|
_rep = rep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询用户自定义配置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/DjyUserConfig/page")]
|
|
public async Task<dynamic> Page([FromQuery] QueryDjyUserConfigInput input)
|
|
{
|
|
var entities = await _rep.AsQueryable()
|
|
.Where(m => m.TenantId == UserManager.TENANT_ID)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Type), u => u.Type == input.Type)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ConfigJson), u => u.ConfigJson == input.ConfigJson)
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
return entities.XnPagedResult();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加用户自定义配置(同用户、同类型的会更新)
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/DjyUserConfig/add")]
|
|
public async Task Add(AddDjyUserConfigInput input)
|
|
{
|
|
var entity = _rep.FirstOrDefault(x => x.Type == input.Type && x.CreatedUserId == UserManager.UserId);
|
|
if (entity == null)
|
|
{
|
|
entity = input.Adapt<DjyUserConfig>();
|
|
await _rep.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
entity.ConfigJson = input.ConfigJson;
|
|
await _rep.UpdateAsync(entity);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新用户自定义配置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/DjyUserConfig/edit")]
|
|
public async Task Update(UpdateDjyUserConfigInput input)
|
|
{
|
|
var entity = input.Adapt<DjyUserConfig>();
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除用户自定义配置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/DjyUserConfig/delete")]
|
|
public async Task Delete(GetDjyUserConfigInput input)
|
|
{
|
|
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
await _rep.DeleteAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户自定义配置
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/DjyUserConfig/get")]
|
|
public async Task<DjyUserConfig> Get([FromQuery] string type)
|
|
{
|
|
return await _rep.FirstOrDefaultAsync(u => u.CreatedUserId == UserManager.UserId && u.Type == type);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户自定义配置(批量)
|
|
/// </summary>
|
|
/// <param name="typeArr"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/DjyUserConfig/multi")]
|
|
public async Task<List<DjyUserConfig>> Multi(string[] typeArr)
|
|
{
|
|
|
|
//return await _rep.ToListAsync(u => u.CreatedUserId == UserManager.UserId && typeArr.Contains(u.Type));
|
|
|
|
List<DjyUserConfig> data = new List<DjyUserConfig>();
|
|
|
|
string[] typelist = { "BC", "PER_BILL", "TRUCK_DISPATCH", "CUT_MODIFY", "ROLLING_NOMINATION", "DRAFT", "ROUTE_CUT_CHANGE", "CAUTION_NOTICE", "POD_DISCHARGE_FULL" };
|
|
|
|
|
|
foreach (var type in typeArr)
|
|
{
|
|
|
|
if (typelist.Contains(type))
|
|
{
|
|
var datainfo = _rep.Where(u => u.CreatedUserId == UserManager.UserId && u.Type == type).First();
|
|
if (datainfo == null)
|
|
{
|
|
data.Add(_rep.Where(u =>u.Type ==(type+"_default")).First());
|
|
}
|
|
else
|
|
{
|
|
if (datainfo != null) data.Add(datainfo);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var userconfig = _rep.Where(u => u.CreatedUserId == UserManager.UserId && u.Type == type).First();
|
|
|
|
if (userconfig != null)
|
|
{
|
|
data.Add(userconfig);
|
|
}
|
|
}
|
|
}
|
|
|
|
return data;
|
|
}
|
|
}
|
|
}
|