|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.User;
|
|
|
|
using DS.WMS.Common.Enum;
|
|
|
|
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 SubmitGoodsAudit(string id)
|
|
|
|
{
|
|
|
|
var exitGoods = db.Queryable<code_goods_audit>().First(x=>x.GID == id);
|
|
|
|
|
|
|
|
if (exitGoods.AuditStatus == AuditStatus.Approve.ToEnumInt() || exitGoods.AuditStatus == AuditStatus.Auditing.ToEnumInt())
|
|
|
|
{
|
|
|
|
return DataResult.Failed("审核通过或待审批状态不能提交!");
|
|
|
|
}
|
|
|
|
var files = db.Queryable<INFO_FILES>().Where(x => x.PID == Guid.Parse(id) && x.FILETYPE == "商品资料").ToList();
|
|
|
|
if (files.Count() == 0)
|
|
|
|
{
|
|
|
|
return DataResult.Failed("商品资料未上传不能提交!");
|
|
|
|
}
|
|
|
|
|
|
|
|
//更新状态为待审批
|
|
|
|
exitGoods.AuditStatus = AuditStatus.Auditing.ToEnumInt();
|
|
|
|
db.Updateable(exitGoods).ExecuteCommand();
|
|
|
|
|
|
|
|
return DataResult.Successed("提交成功");
|
|
|
|
}
|
|
|
|
}
|