username@email.com
2025-08-14 6ab0870590763e83181a47d0e42039be4287329f
Admin.NET/FZCZTB.Net.CustomerSYSTem/Service/FBS_CusExtend/FBS_CusExtendService.cs
@@ -18,6 +18,8 @@
using Admin.NET.Core;
using FZCZTB.NET.MD.CutomerMd.Extend;
using cylsg.utility;
using FZCZTB.NET.MD.CutomerMd;
using Furion.Logging.Extensions;
namespace FZCZTB.Net.CustomerSYSTem;
/// <summary>
@@ -27,19 +29,23 @@
public class FBS_CusExtendService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<FBS_CusExtend> _fBS_CusExtendRep;
    private readonly SqlSugarRepository<FBS_CoutomerExRole> _fBS_CoutomerExRoleRep;
    private readonly ISqlSugarClient _sqlSugarClient;
    private readonly SysDictTypeService _sysDictTypeService;
    private readonly FBS_EnterpriseTypeService _EnterpriseTypeService;
    public FBS_CusExtendService(SqlSugarRepository<FBS_CusExtend> fBS_CusExtendRep,
        ISqlSugarClient sqlSugarClient,
        SysDictTypeService sysDictTypeService,
        FBS_EnterpriseTypeService fBS_EnterpriseTypeService )
        FBS_EnterpriseTypeService fBS_EnterpriseTypeService,
         SqlSugarRepository<FBS_CoutomerExRole> cerRep)
    {
        _fBS_CusExtendRep = fBS_CusExtendRep;
        _sqlSugarClient = sqlSugarClient;
        _sysDictTypeService = sysDictTypeService;
        _EnterpriseTypeService = fBS_EnterpriseTypeService;
        _fBS_CoutomerExRoleRep = cerRep;
    }
    /// <summary>
    /// 
@@ -55,6 +61,7 @@
            StepsTypeItems = CommonHelper.GetEnumItemsWithAttributes<CusExtendStep>()
        };
    }
    /// <summary>
    /// 分页查询企业资料 🔖
    /// </summary>
@@ -92,6 +99,83 @@
            .WhereIF(input.steps != null, u => u.steps == input.steps)
            .Select<FBS_CusExtendOutput>();
      return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
    }
  /// <summary>
  /// 更改审核状态
  /// </summary>
  /// <param name="id">要更改的用户角色资料Id</param>
  /// <param name="step">要更改的状态</param>
  /// <returns></returns>
    [HttpGet]
    public async  Task<bool > ChangeSteps (long id, CusExtendStep step)
    {
        var data=await  _fBS_CusExtendRep.AsQueryable().Includes(x=>x.TransactionRole).Where(x=>x.Id==id).FirstAsync();
        if (data == null)
        {
            throw Oops.Oh("数据不存在");
        };
        if(data.steps== step)
        {
            return true;
        }
        try
        {
            await _fBS_CusExtendRep.AsTenant().BeginTranAsync();
            if (step == CusExtendStep.Pass)
            {
                //是审核通过
                if (data.TransactionRole == null)
                {
                    throw Oops.Oh("用户关联角色失败,用户没有申请该角色,请重新申请角色");
                }
                var exrles = await _fBS_CoutomerExRoleRep.GetFirstAsync(x => x.CustomerId == data.CustomerId && x.ExRoleId == data.TransactionRole.Id);
                if (exrles == null)
                    throw Oops.Oh("用户关联角色失败,用户没有申请该角色,请重新申请角色");
                exrles.HasFlsh = true;
                await _fBS_CoutomerExRoleRep.UpdateAsync(exrles);
            }
            else
                if(data.steps==  CusExtendStep.Pass)
            {
                //更改为未通过
                if (data.TransactionRole == null)
                {
                    throw Oops.Oh("用户关联角色失败,用户没有申请该角色,请重新申请角色");
                }
                var exrles = await _fBS_CoutomerExRoleRep.GetFirstAsync(x => x.CustomerId == data.CustomerId && x.ExRoleId == data.TransactionRole.Id);
                if (exrles == null)
                    throw Oops.Oh("用户关联角色失败,用户没有申请该角色,请重新申请角色");
                exrles.HasFlsh = false;
                await _fBS_CoutomerExRoleRep.UpdateAsync(exrles);
            }
            data.steps = step;
            await _fBS_CusExtendRep.AsUpdateable(data).ExecuteCommandAsync();
            await _fBS_CusExtendRep.AsTenant().CommitTranAsync();
            return true;
        }
        catch (Exception e)
        {
            await _fBS_CusExtendRep.AsTenant().RollbackTranAsync();
            e.Message.LogError();
             throw Oops.Oh("更改审核状态失败"); ;
        }
    }
    /// <summary>
@@ -142,9 +226,31 @@
    [ApiDescriptionSettings(Name = "Delete"), HttpPost]
    public async Task Delete(DeleteFBS_CusExtendInput input)
    {
        var entity = await _fBS_CusExtendRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
        //await _fBS_CusExtendRep.FakeDeleteAsync(entity);   //假删除
        await _fBS_CusExtendRep.DeleteAsync(entity);   //真删除
     await    _fBS_CusExtendRep.AsTenant().BeginTranAsync();
        try
        {
            var entity = await _fBS_CusExtendRep.AsQueryable().Includes(x => x.TransactionRole).Where(x => x.Id == input.Id).FirstAsync() ?? throw Oops.Oh(ErrorCodeEnum.D1002);
            if (entity != null)
            {
                var exrles = await _fBS_CoutomerExRoleRep.GetFirstAsync(x => x.CustomerId == entity.CustomerId && x.ExRoleId == entity.TransactionRole.Id);
                if (exrles != null)
                {
                    await _fBS_CoutomerExRoleRep.DeleteAsync(exrles);
                }
                //await _fBS_CusExtendRep.FakeDeleteAsync(entity);   //假删除
                await _fBS_CusExtendRep.DeleteAsync(entity);   //真删除
            }
          await   _fBS_CusExtendRep.AsTenant().CommitTranAsync();
        }
        catch (Exception)
        {
            await _fBS_CusExtendRep.AsTenant().RollbackTranAsync();
            throw;
        }
    }
    /// <summary>