New file |
| | |
| | | /*********************************************************************** |
| | | * Project: baifenBinfa |
| | | * ProjectName: 百分兵法管理系统 |
| | | * Web: http://chuanyin.com |
| | | * Author: |
| | | * Email: |
| | | * CreateTime: 2024/3/29 11:16:20 |
| | | * 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.Entities.baifenbingfa.Promote.OffLineDistributor; |
| | | using CoreCms.Net.Model.ViewModels.Basics; |
| | | using CoreCms.Net.Model.ViewModels.UI; |
| | | using SqlSugar; |
| | | |
| | | |
| | | namespace CoreCms.Net.Services |
| | | { |
| | | /// <summary> |
| | | /// 线下经销商采集 接口实现 |
| | | /// </summary> |
| | | public class OfflineDistributorServices : BaseServices<OfflineDistributor>, IOfflineDistributorServices |
| | | { |
| | | private readonly IOfflineDistributorRepository _dal; |
| | | private readonly IUnitOfWork _unitOfWork; |
| | | |
| | | private readonly IHttpContextUser _contextUser; |
| | | public OfflineDistributorServices(IUnitOfWork unitOfWork, IOfflineDistributorRepository dal,IHttpContextUser httpContextUser) |
| | | { |
| | | this._dal = dal; |
| | | base.BaseDal = dal; |
| | | _unitOfWork = unitOfWork; |
| | | _contextUser = httpContextUser; |
| | | } |
| | | |
| | | #region 实现重写增删改查操作========================================================== |
| | | |
| | | /// <summary> |
| | | /// 重写异步插入方法 |
| | | /// </summary> |
| | | /// <param name="entity">实体数据</param> |
| | | /// <returns></returns> |
| | | public async Task<AdminUiCallBack> InsertAsync(OfflineDistributor entity) |
| | | { |
| | | entity.createTime = DateTime.Now; |
| | | entity.createBy = $"{_contextUser.Name}"; |
| | | return await _dal.InsertAsync(entity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重写异步插入方法 |
| | | /// </summary> |
| | | /// <param name="entity">实体数据</param> |
| | | /// <returns></returns> |
| | | public async Task<AdminUiCallBack> UserInsertAsync(OfflineDistributor entity) |
| | | { |
| | | entity.createTime = DateTime.Now; |
| | | entity.createBy = $"{_contextUser.Name}"; |
| | | var bol = await _unitOfWork.GetDbClient().InsertNav(entity).Include(x => x.meetings).ExecuteCommandAsync(); |
| | | if (bol) |
| | | { |
| | | return new AdminUiCallBack() |
| | | { |
| | | code = 0, |
| | | data = bol, |
| | | msg = "操作成功" |
| | | |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | |
| | | return new AdminUiCallBack() |
| | | { |
| | | code = 1, |
| | | data = bol, |
| | | msg = "操作失败" |
| | | |
| | | }; |
| | | |
| | | } |
| | | return await _dal.InsertAsync(entity); |
| | | } |
| | | public async Task<AdminUiCallBack> GetInfo(int id) |
| | | { |
| | | var data = await _unitOfWork.GetDbClient().Queryable<OfflineDistributor>().Where(x => x.Id == id) |
| | | .Includes(x => x.meetings) |
| | | .Includes(x => x.Oders).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(OfflineDistributor 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.BusinessManager = entity.BusinessManager; |
| | | oldmod.PhoneNumber = entity.PhoneNumber; |
| | | oldmod.PUserID = entity.PUserID; |
| | | oldmod.Region = entity.Region; |
| | | oldmod.Remake = entity.Remake; |
| | | oldmod.DealerName = entity.DealerName; |
| | | oldmod.UserID = entity.UserID; |
| | | oldmod.IsMeeting = entity.IsMeeting; |
| | | oldmod.StoreLogoUrl = entity.StoreLogoUrl; |
| | | oldmod.Adder = entity.Adder; |
| | | oldmod.ContactPerson = entity.ContactPerson; |
| | | oldmod.Category = entity.Category; |
| | | |
| | | oldmod.School = entity.School; |
| | | var oldMeetings = await db.Queryable<OfflineDistributorMeeting>().Where(x => x.OfflineDistributorID == oldmod.Id).OrderBy(x => x.id).ToListAsync(); |
| | | var oldIntentions = await db.Queryable<OfflineDistributorOder>().Where(x => x.OfflineDistributorID == oldmod.Id).OrderBy(x => x.Id).ToListAsync(); |
| | | |
| | | foreach (var intention in entity.Oders) |
| | | { |
| | | 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.Oders = entity.Oders; |
| | | |
| | | 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.Oders).ExecuteCommandAsync(); |
| | | if (bol) |
| | | { |
| | | return new AdminUiCallBack() |
| | | { |
| | | code = 0, |
| | | data = bol, |
| | | msg = "操作成功" |
| | | |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | |
| | | return new AdminUiCallBack() |
| | | { |
| | | code = 1, |
| | | data = bol, |
| | | msg = "操作失败" |
| | | |
| | | }; |
| | | |
| | | } |
| | | |
| | | //return await _dal.UpdateAsync(entity); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重写异步更新方法方法 |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | public async Task<AdminUiCallBack> UpdateAsync(List<OfflineDistributor> 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<OfflineDistributor>> 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<OfflineDistributor>> QueryPageAsync(Expression<Func<OfflineDistributor, bool>> predicate, |
| | | Expression<Func<OfflineDistributor, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1, |
| | | int pageSize = 20, bool blUseNoLock = false) |
| | | { |
| | | return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock); |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |