/***********************************************************************
|
* 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
|
{
|
/// <summary>
|
/// 推广博主 接口实现
|
/// </summary>
|
public class bloggersInfoServices : BaseServices<bloggersInfo>, 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 实现重写增删改查操作==========================================================
|
|
/// <summary>
|
/// 重写异步插入方法
|
/// </summary>
|
/// <param name="entity">实体数据</param>
|
/// <returns></returns>
|
public async Task<AdminUiCallBack> InsertAsync(bloggersInfo entity)
|
{
|
entity.createTime= DateTime.Now;
|
entity.createBy=$"{_contextUser.Name}";
|
|
return await _dal.InsertAsync(entity);
|
}
|
public async Task<AdminUiCallBack> GetInfo(int id)
|
{
|
var data= await _unitOfWork.GetDbClient().Queryable<bloggersInfo>().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
|
};
|
}
|
|
/// <summary>
|
/// 重写异步更新方法方法
|
/// </summary>
|
/// <param name="entity"></param>
|
/// <returns></returns>
|
public async Task<AdminUiCallBack> 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;
|
var oldMeetings = await db.Queryable<meeting>().Where(x => x.bloggerID == oldmod.id).OrderBy(x=>x.id).ToListAsync();
|
var oldIntentions = await db.Queryable<intention>().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 = "操作失败"
|
|
};
|
|
}
|
}
|
|
/// <summary>
|
/// 重写异步更新方法方法
|
/// </summary>
|
/// <param name="entity"></param>
|
/// <returns></returns>
|
public async Task<AdminUiCallBack> UpdateAsync(List<bloggersInfo> entity)
|
{
|
|
return await _dal.UpdateAsync(entity);
|
}
|
|
/// <summary>
|
/// 重写删除指定ID的数据
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
{
|
return await _dal.DeleteByIdAsync(id);
|
}
|
|
/// <summary>
|
/// 重写删除指定ID集合的数据(批量删除)
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
{
|
return await _dal.DeleteByIdsAsync(ids);
|
}
|
|
#endregion
|
|
#region 获取缓存的所有数据==========================================================
|
|
/// <summary>
|
/// 获取缓存的所有数据
|
/// </summary>
|
/// <returns></returns>
|
public async Task<List<bloggersInfo>> GetCaChe()
|
{
|
return await _dal.GetCaChe();
|
}
|
|
#endregion
|
|
#region 重写根据条件查询分页数据
|
/// <summary>
|
/// 重写根据条件查询分页数据
|
/// </summary>
|
/// <param name="predicate">判断集合</param>
|
/// <param name="orderByType">排序方式</param>
|
/// <param name="pageIndex">当前页面索引</param>
|
/// <param name="pageSize">分布大小</param>
|
/// <param name="orderByExpression"></param>
|
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
/// <returns></returns>
|
public async Task<IPageList<bloggersInfo>> QueryPageAsync(Expression<Func<bloggersInfo, bool>> predicate,
|
Expression<Func<bloggersInfo, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
int pageSize = 20, bool blUseNoLock = false)
|
{
|
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
|
}
|
#endregion
|
|
}
|
}
|