You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
6.1 KiB
204 lines
6.1 KiB
4 years ago
|
using Coldairarrow.Entity.DTO;
|
||
|
using Coldairarrow.Entity.HuiYan;
|
||
|
using Coldairarrow.Util;
|
||
|
using EFCore.Sharding;
|
||
|
using LinqKit;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Linq.Dynamic.Core;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Coldairarrow.Business.HuiYan
|
||
|
{
|
||
|
public class catsBusiness : BaseBusiness<cats>, IcatsBusiness, ITransientDependency
|
||
|
{
|
||
|
public catsBusiness(IDbAccessor db)
|
||
|
: base(db)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
#region 外部接口
|
||
|
|
||
|
public async Task<List<CatTreeDTO>> GetTreeDataListAsync(CatsTreeInputDTO input)
|
||
|
{
|
||
|
var where = LinqHelper.True<cats>();
|
||
|
if (!input.parentId.IsNullOrEmpty())
|
||
|
where = where.And(x => x.ParentId == input.parentId);
|
||
|
|
||
|
var list = await GetIQueryable().Where(where).ToListAsync();
|
||
|
var treeList = list
|
||
|
.Select(x => new CatTreeDTO
|
||
|
{
|
||
|
Id = x.Id,
|
||
|
ParentId = x.ParentId,
|
||
|
Text = x.Name,
|
||
|
Value = x.Id
|
||
|
}).ToList();
|
||
|
|
||
|
return TreeHelper.BuildTree(treeList);
|
||
|
}
|
||
|
|
||
|
|
||
|
public AjaxResult GetParentCatList()
|
||
|
{
|
||
|
var list = GetIQueryable().Where(c => string.IsNullOrEmpty(c.ParentId)).ToList();
|
||
|
return Success(list);
|
||
|
}
|
||
|
|
||
|
|
||
|
public AjaxResult AddKeyWord(CatDto model)
|
||
|
{
|
||
|
var result= Db.RunTransaction(() =>
|
||
|
{
|
||
|
/*
|
||
|
///判断是否需要添加一级类目
|
||
|
*/
|
||
|
cats oneCat = null;
|
||
|
if (!string.IsNullOrEmpty(model.OneCat.Id))
|
||
|
{
|
||
|
oneCat = GetIQueryable().FirstOrDefault(c => c.Id == model.OneCat.Id);
|
||
|
}
|
||
|
|
||
|
if (oneCat == null)
|
||
|
{
|
||
|
oneCat = new cats()
|
||
|
{
|
||
|
Id = IdHelper.GetId(),
|
||
|
CreateTime = DateTime.Now,
|
||
|
CreatorId = "admin",
|
||
|
Deleted = false,
|
||
|
Name = model.OneCat.Text,
|
||
|
ParentId = null
|
||
|
};
|
||
|
|
||
|
int row = Db.Insert(oneCat);
|
||
|
if (row <= 0)
|
||
|
{
|
||
|
throw new Exception("一级类目添加失败!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
///判断是否需要添加二级类目
|
||
|
*/
|
||
|
cats twoCat = null;
|
||
|
if (!string.IsNullOrEmpty(model.TwoCat.Id))
|
||
|
{
|
||
|
twoCat = GetIQueryable().FirstOrDefault(c => c.Id == model.TwoCat.Id);
|
||
|
}
|
||
|
|
||
|
if (twoCat == null)
|
||
|
{
|
||
|
twoCat = new cats()
|
||
|
{
|
||
|
Id = IdHelper.GetId(),
|
||
|
CreateTime = DateTime.Now,
|
||
|
CreatorId = "admin",
|
||
|
Deleted = false,
|
||
|
Name = model.TwoCat.Text,
|
||
|
ParentId = oneCat.Id
|
||
|
};
|
||
|
|
||
|
int row= Db.Insert(twoCat);
|
||
|
if (row <= 0)
|
||
|
{
|
||
|
throw new Exception("二级类目添加失败!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
///判断是否需要添加三级类目
|
||
|
*/
|
||
|
cats lastCat = null;
|
||
|
if (!string.IsNullOrEmpty(model.LastCat.Id))
|
||
|
{
|
||
|
lastCat = GetIQueryable().FirstOrDefault(c => c.Id == model.LastCat.Id);
|
||
|
}
|
||
|
|
||
|
if (lastCat == null)
|
||
|
{
|
||
|
lastCat = new cats()
|
||
|
{
|
||
|
Id = IdHelper.GetId(),
|
||
|
CreateTime = DateTime.Now,
|
||
|
CreatorId = "admin",
|
||
|
Deleted = false,
|
||
|
Name = model.LastCat.Text,
|
||
|
ParentId = twoCat.Id
|
||
|
};
|
||
|
|
||
|
int row = Db.Insert(lastCat);
|
||
|
if (row <= 0)
|
||
|
{
|
||
|
throw new Exception("三级类目添加失败!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var list = new List<cats>();
|
||
|
|
||
|
model.KeyWords.ForEach(key => {
|
||
|
list.Add(new cats() {
|
||
|
Id = IdHelper.GetId(),
|
||
|
CreateTime = DateTime.Now,
|
||
|
CreatorId = "admin",
|
||
|
Deleted = false,
|
||
|
Name = key,
|
||
|
ParentId = lastCat.Id
|
||
|
});
|
||
|
});
|
||
|
|
||
|
Db.BulkInsert(list);
|
||
|
});
|
||
|
if(result.Success)
|
||
|
{
|
||
|
return Success();
|
||
|
}
|
||
|
return Error();
|
||
|
}
|
||
|
|
||
|
public async Task<PageResult<cats>> GetDataListAsync(PageInput<ConditionDTO> input)
|
||
|
{
|
||
|
var q = GetIQueryable();
|
||
|
var where = LinqHelper.True<cats>();
|
||
|
var search = input.Search;
|
||
|
|
||
|
//筛选
|
||
|
if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
|
||
|
{
|
||
|
var newWhere = DynamicExpressionParser.ParseLambda<cats, bool>(
|
||
|
ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
|
||
|
where = where.And(newWhere);
|
||
|
}
|
||
|
|
||
|
return await q.Where(where).GetPageResultAsync(input);
|
||
|
}
|
||
|
|
||
|
public async Task<cats> GetTheDataAsync(string id)
|
||
|
{
|
||
|
return await GetEntityAsync(id);
|
||
|
}
|
||
|
|
||
|
public async Task AddDataAsync(cats data)
|
||
|
{
|
||
|
await InsertAsync(data);
|
||
|
}
|
||
|
|
||
|
public async Task UpdateDataAsync(cats data)
|
||
|
{
|
||
|
await UpdateAsync(data);
|
||
|
}
|
||
|
|
||
|
public async Task DeleteDataAsync(List<string> ids)
|
||
|
{
|
||
|
await DeleteAsync(ids);
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 私有成员
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|