177 lines
6.9 KiB
C#
177 lines
6.9 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Infrastructure;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Service.Business.IBusinessService.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Model.Dto.Business.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Model.Models.Business.LogisticsManage.LogisticsCompanys;
|
|
using ARW.Model.Vo.Business.LogisticsManage.LogisticsCompanys;
|
|
|
|
namespace ARW.Service.Business.BusinessService.LogisticsManage.LogisticsCompanys
|
|
{
|
|
/// <summary>
|
|
/// 物流公司接口实现类
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-06-18
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(ILogisticsCompanyService), ServiceLifetime = LifeTime.Transient)]
|
|
public class LogisticsCompanyServiceImpl : BaseService<LogisticsCompany>, ILogisticsCompanyService
|
|
{
|
|
private readonly LogisticsCompanyRepository _LogisticsCompanyRepository;
|
|
|
|
public LogisticsCompanyServiceImpl(LogisticsCompanyRepository LogisticsCompanyRepository)
|
|
{
|
|
this._LogisticsCompanyRepository = LogisticsCompanyRepository;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询物流公司分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<LogisticsCompanyVo>> GetLogisticsCompanyList(LogisticsCompanyQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<LogisticsCompany>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LogisticsCompanyName), s => s.LogisticsCompanyName.Contains(parm.LogisticsCompanyName));
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LogisticsCompanyCode), s => s.LogisticsCompanyCode.Contains(parm.LogisticsCompanyCode));
|
|
var query = _LogisticsCompanyRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.LogisticsCompanySort, OrderByType.Asc)
|
|
.Select(s => new LogisticsCompanyVo
|
|
{
|
|
LogisticsCompanyId = s.LogisticsCompanyId,
|
|
LogisticsCompanyGuid = s.LogisticsCompanyGuid,
|
|
LogisticsCompanyName = s.LogisticsCompanyName,
|
|
LogisticsCompanyCode = s.LogisticsCompanyCode,
|
|
LogisticsCompanySort = s.LogisticsCompanySort,
|
|
CreateTime = s.Create_time.ToString("yyyy-MM-dd HH:mm")
|
|
});
|
|
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改物流公司
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateLogisticsCompany(LogisticsCompany model)
|
|
{
|
|
if (model.LogisticsCompanyId != 0)
|
|
{
|
|
var response = await _LogisticsCompanyRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
|
|
var response = await _LogisticsCompanyRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
#region Excel处理
|
|
/// <summary>
|
|
/// 数据导入处理
|
|
/// </summary>
|
|
public async Task<LogisticsCompanyVo> HandleImportData(LogisticsCompanyVo LogisticsCompany)
|
|
{
|
|
return LogisticsCompany;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Excel导入
|
|
/// </summary>
|
|
public async Task<string> ImportExcel(LogisticsCompany LogisticsCompany, int index, bool isUpdateSupport, string user)
|
|
{
|
|
try
|
|
{
|
|
// 空值判断
|
|
// if (LogisticsCompany.LogisticsCompanyId == null) throw new CustomException("物流公司不能为空");
|
|
var company = await GetFirstAsync(s => s.LogisticsCompanyName == LogisticsCompany.LogisticsCompanyName);
|
|
if (company != null) throw new CustomException("已存在!");
|
|
|
|
if (isUpdateSupport)
|
|
{
|
|
// 判断唯一值
|
|
var model = await GetFirstAsync(s => s.LogisticsCompanyId == LogisticsCompany.LogisticsCompanyId);
|
|
|
|
// 如果为空就新增数据
|
|
if (model == null)
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateLogisticsCompany(LogisticsCompany);
|
|
});
|
|
var addStr = $"第 {index} 行 => 物流公司:【{LogisticsCompany.LogisticsCompanyName}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
else
|
|
{
|
|
// 如果有数据就进行修改
|
|
// 开启事务
|
|
await UseTranAsync(async () =>
|
|
{
|
|
LogisticsCompany.LogisticsCompanyId = model.LogisticsCompanyId;
|
|
LogisticsCompany.LogisticsCompanyGuid = model.LogisticsCompanyGuid;
|
|
LogisticsCompany.Update_by = user;
|
|
LogisticsCompany.Update_time = DateTime.Now;
|
|
var editRes = await AddOrUpdateLogisticsCompany(LogisticsCompany);
|
|
});
|
|
var editStr = $"第 {index} 行 => 物流公司:【{LogisticsCompany.LogisticsCompanyName}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
|
return editStr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateLogisticsCompany(LogisticsCompany);
|
|
});
|
|
//Console.WriteLine(res.IsSuccess);
|
|
var addStr = $"第 {index} 行 => 物流公司:【{LogisticsCompany.LogisticsCompanyName}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var errorRes = $"第 {index} 行 => 物流公司:【{LogisticsCompany.LogisticsCompanyName}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
|
return errorRes;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Excel数据导出处理
|
|
/// </summary>
|
|
public async Task<List<LogisticsCompanyVo>> HandleExportData(List<LogisticsCompanyVo> data)
|
|
{
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|