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.

267 lines
9.7 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.User;
using DS.WMS.Common.Enum;
using DS.WMS.Core.BaseInfo.Dtos;
using DS.WMS.Core.BaseInfo.Entity;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.System.Method;
/// <summary>
///
/// </summary>
public class CodeGoodsAuditService : ICodeGoodsAuditService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CodeGoodsAuditService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
/// <summary>
/// 商品列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<CodeGoodsAuditViewModel>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<code_goods_audit>()
.LeftJoin<code_goodsType>((a, b) => a.GoodsTypeGID == b.GID)
.Select<CodeGoodsAuditViewModel>()
.Where(whereList).Where(a => a.AuditStatus != AuditStatus.NoAudit.ToEnumInt()).ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 获取商品信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<CodeGoodsAuditViewModel> GetGoodsAuditInfo(string id)
{
var goodFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == Guid.Parse(id) && x.FILETYPE == "商品资料")
.Select(it => new fileinfo
{
FileName = it.FILENAME,
FilePath = it.IMGPATH
}).ToArray();
var data = db.Queryable<code_goods_audit>()
.LeftJoin<code_goodsType>((a, b) => a.GoodsTypeGID == b.GID)
.Where(a => a.GID == id)
.Select<CodeGoodsAuditViewModel>()
.Mapper(it =>
{
//只能写在Select后面
it.File = goodFiles;
})
.First();
return DataResult<CodeGoodsAuditViewModel>.Success(data);
}
/// <summary>
/// 维护商品申报信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DataResult EditGoodsAuditInfo(GoodsAuditInput model)
{
if (model.GID.IsNullOrEmpty())
{
var isExist = db.Queryable<code_goods_audit>().Where(x => x.GOODNAME == model.GOODNAME.Trim()).First();
if (isExist != null)
{
return DataResult.Failed("商品申报该名称已存在!");
}
var isGoodsExist = db.Queryable<code_goods>().Where(x => x.GOODNAME == model.GOODNAME.Trim()).First();
if (isGoodsExist != null)
{
return DataResult.Failed("商品信息库中该名称已存在!");
}
try
{
//开启事务
db.Ado.BeginTran();
var gid = Guid.NewGuid();
var data = model.MapTo<GoodsAuditInput, code_goods_audit>();
data.GID = gid.ToString();
data.CompanyId = user.GetCompanyId();
data.AuditStatus = AuditStatus.NoAudit.ToEnumInt();
db.Insertable(data).ExecuteCommand();
var infoList = new List<INFO_FILES>();
if (model.File.IsNotNull())
{
foreach (var item in model.File)
{
var infoFile = new INFO_FILES
{
GID = Guid.NewGuid(),
PID = gid,
FILENAME = item.FileName,
IMGPATH = item.FilePath,
FILETYPE = "商品资料",
CORPID = user.CompanyId.ToString(),
CreateDate = DateTime.Now,
ModifyDate = DateTime.Now,
UPLOADEMPLY = user.UserId
};
infoList.Add(infoFile);
}
if (infoList.Count > 0)
{
db.Insertable(infoList).ExecuteCommand();
}
}
db.Ado.CommitTran();
return DataResult.Successed("添加成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("添加失败!" + ex);
}
}
else
{
var exitGoodAudit = db.Queryable<code_goods_audit>().Where(x => x.GID == model.GID).First();
if (exitGoodAudit.AuditStatus == (short)NomalStatus.Approve)
{
return DataResult.Failed("已审核通过,不能修改!");
}
try
{
//开启事务
db.Ado.BeginTran();
var data = model.MapTo<GoodsAuditInput, code_goods_audit>();
db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand();
var gid =Guid.Parse( model.GID);
var infoList = new List<INFO_FILES>();
if (model.File.IsNotNull())
{
#region 处理商品资料
//先删除 商品资料
var existGoods = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "商品资料").Select(n=>n.IMGPATH).ToArray();
var goodFiles = model.File.Select(x => x.FilePath).ToArray();
IEnumerable<string> delGoods = existGoods.AsQueryable().Except(goodFiles);
if (delGoods.Count()>0)
{
foreach (var item in delGoods)
{
var existInfo = db.Queryable<INFO_FILES>()
.Where(x => x.PID == gid && x.IMGPATH == item).First();
db.Deleteable(existInfo).ExecuteCommand();
}
}
//2.添加新的商品资料
IEnumerable<string> addGoods = goodFiles.AsQueryable().Except(existGoods);
if (addGoods.Count()>0)
{
foreach (var item in addGoods)
{
var infoFile = new INFO_FILES
{
GID = Guid.NewGuid(),
PID = gid,
FILENAME = model.File.Where(x=>x.FilePath ==item).Select(x=>x.FileName).First(),
IMGPATH = item,
FILETYPE = "商品资料",
CORPID = gid.ToString(),
CreateDate = DateTime.Now,
ModifyDate = DateTime.Now,
UPLOADEMPLY = ""
};
db.Insertable(infoFile).ExecuteCommand();
}
}
#endregion
}
db.Ado.CommitTran();
return DataResult.Successed("更新成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("更新失败!" + ex);
}
}
}
/// <summary>
/// 提交审核
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult AuditGoods(CommonAuditInput model)
{
var gid = Guid.Parse(model.Id);
var exitGoods = db.Queryable<code_goods_audit>().First(x=>x.GID == model.Id);
if (exitGoods.IsNull())
{
return DataResult.Failed("商品申报信息不存在!");
}
if (exitGoods.AuditStatus == AuditStatus.Approve.ToEnumInt())
{
return DataResult.Failed("已审批通过!");
}
if (model.Status == 1)
{
try
{
//开启事务
db.Ado.BeginTran();
exitGoods.AuditStatus = model.Status;
exitGoods.AuditNote = model.AuditNote;
db.Updateable(exitGoods).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
var goods = exitGoods.MapTo<code_goods_audit, code_goods>();;
goods.PinYinCode = PinYinUtil.GetFristLetter(exitGoods.GOODNAME);
db.Insertable(goods).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("审批成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("审批失败!" + ",请联系管理员!");
}
}
else
{
exitGoods.AuditStatus = model.Status;
exitGoods.AuditNote = model.AuditNote;
db.Updateable(exitGoods).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("驳回成功!");
}
}
}