87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
using Nirvana.Common;
|
|
using Nirvana.Common.ApiBase;
|
|
using Nirvana.Data;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using YBDevice.Entity;
|
|
|
|
namespace YBDevice.Api.DBServices
|
|
{
|
|
/// <summary>
|
|
/// 科普资讯、轮播图、开屏广告管理
|
|
/// </summary>
|
|
public partial class InfoApp : BaseApp
|
|
{
|
|
/// <summary>
|
|
/// 科普资讯列表
|
|
/// </summary>
|
|
/// <param name="param"></param>
|
|
/// <returns></returns>
|
|
public async Task<ParamReturnData<YB_SecInfo>> GetInfoListAsync(ParamQuery param)
|
|
{
|
|
RefAsync<int> totalnum = 0;
|
|
using (var dbClient = ReadDbContext.GetInstance())
|
|
{
|
|
var temquery = dbClient.Queryable<YB_SecInfo>().Where(x=>x.Status == 1);
|
|
if (!string.IsNullOrEmpty(param.keyword))
|
|
{
|
|
int tagid = param.keyword.ToInt();
|
|
if (tagid > 0)
|
|
{
|
|
temquery = temquery.Where(x => x.TagId == tagid);
|
|
}
|
|
}
|
|
string sorts = string.Format("{0} {1}", param.sort, param.order);
|
|
var query = await temquery.OrderBy(sorts)
|
|
.Mapper((it, cache) =>
|
|
{
|
|
it.HeadImg = $"{CDNURL}{it.HeadImg}";
|
|
})
|
|
.ToPageListAsync(param.page, param.pagesize, totalnum);
|
|
return new ParamReturnData<YB_SecInfo>
|
|
{
|
|
page = param.page,
|
|
items = query,
|
|
totalnum = totalnum,
|
|
pagesize = param.pagesize
|
|
};
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 科普资讯详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<ResultInfo> InfoDetailAsync(int id)
|
|
{
|
|
using (var dbClient = ReadDbContext.GetInstance())
|
|
{
|
|
var data = await dbClient.Queryable<YB_SecInfo>().FirstAsync(x => x.Id == id);
|
|
if (data == null)
|
|
{
|
|
return new ResultInfo(ResultState.FAIL, "记录未找到");
|
|
}
|
|
//返回内容
|
|
var contentdata = await dbClient.Queryable<YB_SecInfoContent>().FirstAsync(x => x.InfoId == data.Id);
|
|
return new ResultInfo(ResultState.SUCCESS, "success", contentdata);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 类型列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<ResultInfo> GetInfoTagListAsync()
|
|
{
|
|
using (var dbClient = ReadDbContext.GetInstance())
|
|
{
|
|
var list= await dbClient.Queryable<YB_SecInfoType>().Where(x=>x.Status == 1).OrderBy(x => x.SortCode, OrderByType.Asc).ToListAsync();
|
|
return new ResultInfo(ResultState.SUCCESS, "success", list);
|
|
}
|
|
}
|
|
}
|
|
}
|