You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.7 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Common.Enum;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.System.Method;
/// <summary>
/// 公告
/// </summary>
public class AnnouncementService:IAnnouncementService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public AnnouncementService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<AnnouncementViewModel>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<Announcement>()
.LeftJoin<AnnouncementCompany>((a,b)=>a.Gid == b.AnnouncementId)
.Where((a,b)=> a.SendStatus == SendStatus.Send.ToEnumInt())
.Where(whereList).Select<AnnouncementViewModel>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<AnnouncementViewModel> GetAnnouncementInfo(int id)
{
var data = db.Queryable<Announcement>()
.LeftJoin<AnnouncementCompany>((a, b) => a.Gid == b.AnnouncementId)
.Where((a,b) => a.SendStatus == SendStatus.Send.ToEnumInt() && b.Id == id)
.Select<AnnouncementViewModel>().First();
return DataResult<AnnouncementViewModel>.Success(data);
}
/// <summary>
/// 设置公告已读
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public DataResult ReadAnnouncement(int id)
{
var info = db.Queryable<AnnouncementCompany>().First(x => x.Id == id);
if (info == null)
{
return DataResult.Failed("公告信息不存在!");
}
if ((bool)info.IsRead)
{
return DataResult.Failed("公告信息已读!");
}
info.IsRead = true;
db.Updateable(info).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
/// <summary>
/// 获取未读消息列表
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult GetNoReadList(string id)
{
var data0 = db.Queryable<Announcement>()
.LeftJoin<AnnouncementCompany>((a, b) => a.Gid == b.AnnouncementId)
.Where((a,b) => a.SendStatus == SendStatus.Send.ToEnumInt() && b.CompanyId == id && b.IsRead == false
&& a.AnnouncementType == AnnouncementType.Announcement.ToEnumInt())
.Select<AnnouncementViewModel>().ToList();
var data1 = db.Queryable<Announcement>()
.LeftJoin<AnnouncementCompany>((a, b) => a.Gid == b.AnnouncementId)
.Where((a,b) => a.SendStatus == SendStatus.Send.ToEnumInt() && b.CompanyId == id && b.IsRead == false
&& a.AnnouncementType == AnnouncementType.Message.ToEnumInt())
.Select<AnnouncementViewModel>().ToList();
var data = new List<object>();
data.Add(data0);
data.Add(data1);
return DataResult.Successed("查询成功!", data);
}
}