/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 2024/3/20 13:18:25
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.baifenbingfa.Promote;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Services
{
///
/// 推广博主 接口实现
///
public class bloggersInfoServices : BaseServices, IbloggersInfoServices
{
private readonly IbloggersInfoRepository _dal;
private readonly IUnitOfWork _unitOfWork;
private readonly IHttpContextUser _contextUser;
public bloggersInfoServices(IUnitOfWork unitOfWork, IbloggersInfoRepository dal,IHttpContextUser contextUser)
{
this._dal = dal;
base.BaseDal = dal;
_unitOfWork = unitOfWork;
_contextUser = contextUser;
}
#region 实现重写增删改查操作==========================================================
///
/// 重写异步插入方法
///
/// 实体数据
///
public async Task InsertAsync(bloggersInfo entity)
{
entity.createTime= DateTime.Now;
entity.createBy=$"{_contextUser.Name}";
return await _dal.InsertAsync(entity);
}
public async Task GetInfo(int id)
{
var data= await _unitOfWork.GetDbClient().Queryable().Where(x=>x.id==id)
.Includes(x=>x.meetings)
.Includes(x=>x.intentions).FirstAsync();
if (data == null)
return new AdminUiCallBack()
{
msg = "没有找到该数据"
};
else
return new AdminUiCallBack()
{
code = 0,
data = data
};
}
///
/// 重写异步更新方法方法
///
///
///
public async Task UpdateAsync(bloggersInfo entity)
{
var db=_unitOfWork.GetDbClient();
var oldmod= await _dal.QueryByIdAsync(entity.id);
if(oldmod==null)
{
return new AdminUiCallBack()
{
data = "没有找到相关数据"
};
}
oldmod.upDataTime = DateTime.Now;
oldmod.upDataBy = $"{_contextUser.Name}";
oldmod.platforms= entity.platforms;
oldmod.phone= entity.phone;
oldmod.address= entity.address;
oldmod.areaCode= entity.areaCode;
oldmod.followersCount= entity.followersCount;
oldmod.mangerName= entity.mangerName;
oldmod.nickname= entity.nickname;
oldmod.intentionDec= entity.intentionDec;
oldmod.reMaker= entity.reMaker;
oldmod.PromoteMoney=entity.PromoteMoney;
var oldMeetings = await db.Queryable().Where(x => x.bloggerID == oldmod.id).OrderBy(x=>x.id).ToListAsync();
var oldIntentions = await db.Queryable().Where(x => x.bloggerID == oldmod.id).OrderBy(x => x.id).ToListAsync();
foreach (var intention in entity.intentions)
{
if (intention.id == 9999999)
{
intention.id = 0;
intention.createBy = $"{_contextUser.Name}";
intention.createTime = DateTime.Now;
intention.isdelete = false;
continue;
}
var old= oldIntentions.Where(x=>x.id== intention.id).SingleOrDefault();
if(old!=null)
{
intention.isdelete = old.isdelete;
intention.createBy = old.createBy;
intention.createTime = old.createTime;
intention.upDataBy = $"{_contextUser.Name}";
intention.upDataTime = DateTime.Now;
}
}
oldmod.intentions = entity.intentions;
foreach (var meetin in entity.meetings)
{
if (meetin.id == 9999999)
{
meetin.id = 0;
meetin.createBy = $"{_contextUser.Name}";
meetin.createTime= DateTime.Now;
meetin.isdelete = false;
continue;
}
var old = oldMeetings.Where(x => x.id == meetin.id).SingleOrDefault();
if (old != null)
{
meetin.isdelete = old.isdelete;
meetin.createBy = old.createBy;
meetin.createTime = old.createTime;
meetin.upDataBy = $"{_contextUser.Name}";
meetin.upDataTime = DateTime.Now;
}
}
oldmod.meetings = entity.meetings;
var bol= await _unitOfWork.GetDbClient().UpdateNav(oldmod).Include(x => x.meetings).Include(x => x.intentions).ExecuteCommandAsync();
if(bol)
{
return new AdminUiCallBack()
{
code = 0,
data = bol,
msg = "操作成功"
};
}
else
{
return new AdminUiCallBack()
{
code = 1,
data = bol,
msg = "操作失败"
};
}
}
///
/// 重写异步更新方法方法
///
///
///
public async Task UpdateAsync(List entity)
{
return await _dal.UpdateAsync(entity);
}
///
/// 重写删除指定ID的数据
///
///
///
public async Task DeleteByIdAsync(object id)
{
return await _dal.DeleteByIdAsync(id);
}
///
/// 重写删除指定ID集合的数据(批量删除)
///
///
///
public async Task DeleteByIdsAsync(int[] ids)
{
return await _dal.DeleteByIdsAsync(ids);
}
#endregion
#region 获取缓存的所有数据==========================================================
///
/// 获取缓存的所有数据
///
///
public async Task> GetCaChe()
{
return await _dal.GetCaChe();
}
#endregion
#region 重写根据条件查询分页数据
///
/// 重写根据条件查询分页数据
///
/// 判断集合
/// 排序方式
/// 当前页面索引
/// 分布大小
///
/// 是否使用WITH(NOLOCK)
///
public async Task> QueryPageAsync(Expression> predicate,
Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
}
#endregion
}
}