using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; using DS.WMS.Common.Enum; using DS.WMS.Core.System.Dtos; using DS.WMS.Core.System.Entity; using DS.WMS.Core.System.Interface; using DS.WMS.Core.WmsModule.Entity; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.System.Method; /// /// /// public class SysNoticeService:ISysNoticeService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; /// /// /// /// public SysNoticeService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); } /// /// 列表查询 /// /// /// public DataResult> GetListByPage(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable() .Where(whereList) .Select() // .Where(x=>x.AuditStatus != AuditStatus.NoAudit.ToEnumInt()) .ToQueryPage(request.PageCondition); return data; } /// /// 获取信息 /// /// /// public DataResult GetInfo(string id) { var data = db.Queryable() .Where(x => x.Id == id) .Select() // .Mapper(it => // { // //只能写在Select后面 // it.licensefiles = licenseFiles; // it.cardfiles = cardFiles; // }) .First(); return DataResult.Success(data); } /// /// 编辑信息 /// /// /// public DataResult EditNotice(NoticeInput model) { if (model.Id.IsNullOrEmpty()) { var isExist = db.Queryable().Where(x => x.Title == model.Title).First(); if (isExist != null) { return DataResult.Failed("公告标题已存在!"); } var data = model.MapTo(); db.Insertable(data).ExecuteCommand(); return DataResult.Successed("添加成功!"); } else { var info = db.Queryable().Where(x => x.Id == model.Id).First(); info = model.MapTo(); db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); return DataResult.Successed("更新成功!"); } } /// /// 发布公告 /// /// /// public DataResult SendNotice(string id) { var notice = db.Queryable().Where(x => x.Id == id).First(); if (notice.SendStatus == SendStatus.Send.ToEnumInt()) { return DataResult.Failed("已发布!"); } var clients = db.Queryable().Where(x=>x.AuditStatus == AuditStatus.Approve.ToEnumInt()).ToList(); try { //开启事务 db.Ado.BeginTran(); notice.SendStatus = SendStatus.Send.ToEnumInt(); notice.SendTime =DateTime.Now; db.Updateable(notice).ExecuteCommand(); var clientNotices = new List(); foreach (var item in clients) { var info= new SysNoticeClient { NoticeId = id, ClientId = item.GID.ToString(), IsRead = false }; clientNotices.Add(info); } db.Insertable(clientNotices).ExecuteCommand(); db.Ado.CommitTran(); return DataResult.Successed("公告发布成功!"); } catch (Exception ex) { db.Ado.RollbackTran(); return DataResult.Failed("公告发布失败!" + ex); } } /// /// 撤销公告 /// /// /// public DataResult CancelNotice(string id) { var notice = db.Queryable().Where(x => x.Id == id).First(); if (notice.SendStatus == SendStatus.Cancel.ToEnumInt()) { return DataResult.Failed("已撤销!"); } try { //开启事务 db.Ado.BeginTran(); notice.SendStatus = SendStatus.Cancel.ToEnumInt(); notice.CancelTime =DateTime.Now; db.Updateable(notice).ExecuteCommand(); var cancelNotices = db.Queryable().Where(x=>x.NoticeId == id).ToList(); db.Deleteable(cancelNotices).ExecuteCommand(); db.Ado.CommitTran(); return DataResult.Successed("公告撤销成功!"); } catch (Exception ex) { db.Ado.RollbackTran(); return DataResult.Failed("公告撤销失败!" + ex); } } }