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.

131 lines
4.3 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Common.Enum;
using DS.WMS.Core.BaseInfo.Dtos;
using DS.WMS.Core.BaseInfo.Entity;
using DS.WMS.Core.BaseInfo.Interface;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.BaseInfo.Method;
/// <summary>
/// /
/// </summary>
public class ClientAuditService : IClientAuditService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public ClientAuditService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
public DataResult<List<OP_YARD_COMPANY>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<OP_YARD_COMPANY>()
.Where(whereList)
.Where(x => x.AuditStatus != AuditStatus.NoAudit.ToEnumInt())
.ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 获取公司信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult GetClientInfo(string id)
{
var companyId = Guid.Parse(id);
var licenseFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == companyId && x.FILETYPE == "营业执照")
.Select(it => new fileinfo
{
FileName = it.FILENAME,
FilePath = it.IMGPATH
}).ToArray();
var cardFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == companyId && x.FILETYPE == "法人身份证")
.Select(it => new fileinfo
{
FileName = it.FILENAME,
FilePath = it.IMGPATH
}).ToArray();
var data = db.Queryable<OP_YARD_COMPANY>()
.Where(x => x.GID == companyId)
.Select<ClientAuditViewModel>()
.Mapper(it =>
{
//只能写在Select后面
it.licensefiles = licenseFiles;
it.cardfiles = cardFiles;
})
.First();
return DataResult.Successed("获取数据成功", data);
}
public DataResult AuditClient(CommonAuditInput model)
{
var userId = user.UserId;
var clientId = Guid.Parse(model.Id);
var company = db.Queryable<OP_YARD_COMPANY>().Where(x => x.GID == clientId).First();
if (company.IsNull())
{
return DataResult.Failed("公司信息不存在!");
}
if (company.AuditStatus == AuditStatus.Approve.ToEnumInt())
{
return DataResult.Failed("已审批通过!");
}
if (model.Status == 1)
{
try
{
//开启事务
db.Ado.BeginTran();
company.AuditStatus = model.Status;
company.AuditNote = model.AuditNote;
db.Updateable(company).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
var client = company.Adapt<info_client>();;
client.CODENAME = PinYinUtil.GetFristLetter(company.SHORTNAME);
client.GID = clientId.ToString();
client.STATUS = 0;
db.Insertable(client).ExecuteCommand();
db.Ado.CommitTran();
return DataResult.Successed("审批成功!");
}
catch (Exception ex)
{
db.Ado.RollbackTran();
return DataResult.Failed("审批失败!" + ",请联系管理员!");
}
}
else
{
company.AuditStatus = model.Status;
company.AuditNote = model.AuditNote;
db.Updateable(company).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("驳回成功!");
}
}
}