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.

292 lines
11 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Mapster;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.System.Method;
public class TenantApplyService : ITenantApplyService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public TenantApplyService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
#region 企业用户审批
/// <summary>
/// 企业注册用户列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<TenantApplyListRes>> GetListByPage(PageRequest request)
{
// var query = _commonService.GetDataRuleFilter<SysRole>();
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysTenantApply>().ClearFilter<ITenantId>()
.Select<TenantApplyListRes>()
.Where(x=>x.AuditStatus!= AuditStatusEnum.NoAudit)
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 获取注册企业审批信息
/// </summary>
/// <returns></returns>
public DataResult<TenantApplyInfoRes> GetTenantAuditInfo(string id)
{
var data = db.Queryable<SysTenantApply>()
.Where(a => a.Id == long.Parse(id))
.Select<TenantApplyInfoRes>()
.First();
return DataResult<TenantApplyInfoRes>.Success(data);
}
/// <summary>
/// 企业用户审批
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult AuditTenantApply(CommonAuditInput req)
{
var userId = user.UserId;
var apply = db.Queryable<SysTenantApply>().Where(x => x.Id == req.Id).First();
if (apply.IsNull())
{
return DataResult.Failed("企业用户信息不存在!");
}
if (apply.AuditStatus == AuditStatusEnum.Approve)
{
return DataResult.Failed("已审批通过!");
}
if (req.Status == 1)
{
try
{
//开启事务
db.Ado.BeginTran();
apply.AuditStatus = (AuditStatusEnum)(int)req.Status;
apply.AuditNote = req.AuditNote;
db.Updateable(apply).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
//TODO 处理租户相关数据
// 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
{
apply.AuditStatus = (AuditStatusEnum)(int)req.Status;
apply.AuditNote = req.AuditNote;
db.Updateable(req).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("驳回成功!");
}
}
#endregion
#region 企业用户维护信息
/// <summary>
/// 获取注册企业申请信息
/// </summary>
/// <returns></returns>
public DataResult<TenantApplyInfoRes> GetTenantApplyInfo()
{
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
var data = db.Queryable<SysTenantApply>()
.Where(a => a.AdminUserCode == userInfo.UserCode)
.Select<TenantApplyInfoRes>()
.First();
return DataResult<TenantApplyInfoRes>.Success(data);
}
/// <summary>
/// 维护企业用户信息
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditTenantApplyInfo(TenantApplyReq req)
{
var existApply = db.Queryable<SysTenantApply>().First(x => x.Id == req.Id);
if (existApply.AuditStatus == AuditStatusEnum.Approve || existApply.AuditStatus == AuditStatusEnum.Auditing)
{
return DataResult.Failed("审核通过或待审批状态不能提交!");
}
try
{
//开启事务
db.Ado.BeginTran();
var apply = req.Adapt<SysTenantApply>();
db.Updateable(apply).IgnoreColumns(x =>
new
{
x.AdminUserPassword, x.AuditStatus, x.AuditNote
}).ExecuteCommand();
//TO DO 处理附件
// var gid = model.GID; //写入
// #region 处理文件
//
// #region 处理法人身份证
// //先删除 法人身份证
// var existCards = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "法人身份证").Select(n=>n.IMGPATH).ToArray();
// var cardFiles = model.cardfiles.Select(x => x.FilePath).ToArray();
// IEnumerable<string> delCards = existCards.AsQueryable().Except(cardFiles);
// if (delCards.Count()>0)
// {
// foreach (var item in delCards)
// {
// var existInfo = db.Queryable<INFO_FILES>()
// .Where(x => x.PID == gid && x.IMGPATH == item).First();
// db.Deleteable(existInfo).ExecuteCommand();
// }
// }
// //2.添加新的法人身份证
// IEnumerable<string> addCards = cardFiles.AsQueryable().Except(existCards);
// if (addCards.Count()>0)
// {
// foreach (var item in addCards)
// {
// var infoFile = new INFO_FILES
// {
// GID = Guid.NewGuid(),
// PID = gid,
// FILENAME = model.cardfiles.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
// #region 处理营业执照
// //先删除 营业执照
// var existLicenses = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "营业执照").Select(n=>n.IMGPATH).ToArray();
// var licenseFiles = model.licensefiles.Select(x => x.FilePath).ToArray();
// IEnumerable<string> delLicenses = existLicenses.AsQueryable().Except(licenseFiles);
// if (delLicenses.Count()>0)
// {
// foreach (var item in delLicenses)
// {
// var existInfo = db.Queryable<INFO_FILES>()
// .Where(x => x.PID == gid && x.IMGPATH == item).First();
// db.Deleteable(existInfo).ExecuteCommand();
// }
// }
// //2.添加新的营业执照
// IEnumerable<string> addLicenses = licenseFiles.AsQueryable().Except(existLicenses);
// if (addLicenses.Count()>0)
// {
// foreach (var item in addLicenses)
// {
// var infoFile = new INFO_FILES
// {
// GID = Guid.NewGuid(),
// PID = gid,
// FILENAME = model.licensefiles.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
// #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 SubmitTenantApply(string id)
{
var existApply = db.Queryable<SysTenantApply>().First(x => x.Id == long.Parse(id));
if (existApply == null)
{
return DataResult.Failed("企业信息不存在,请先保存再提交!");
}
if (existApply.AuditStatus == AuditStatusEnum.Approve || existApply.AuditStatus == AuditStatusEnum.Auditing)
{
return DataResult.Failed("审核通过或待审批状态不能提交!");
}
// var licensefiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE =="营业执照").ToList();
// if (licensefiles.Count() == 0)
// {
// return DataResult.Failed("营业执照认证资料未上传不能提交!");
// }
// var cardfiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE =="法人身份证").ToList();
// if (cardfiles.Count() == 0)
// {
// return DataResult.Failed("营业执照认证资料未上传不能提交!");
// }
//更新状态为待审批
existApply.AuditStatus = AuditStatusEnum.Auditing;
db.Updateable(existApply).ExecuteCommand();
return DataResult.Successed("提交成功");
}
#endregion
}