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.
185 lines
5.5 KiB
C#
185 lines
5.5 KiB
C#
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 Mapster;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.System.Method;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class SysNoticeService:ISysNoticeService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly ISqlSugarClient db;
|
|
private readonly IUser user;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public SysNoticeService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表查询
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public DataResult<List<NoticeViewModel>> GetListByPage(PageRequest request)
|
|
{
|
|
//序列化查询条件
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
var data = db.Queryable<SysNotice>()
|
|
.Where(whereList)
|
|
.Select<NoticeViewModel>()
|
|
// .Where(x=>x.AuditStatus != AuditStatus.NoAudit.ToEnumInt())
|
|
.ToQueryPage(request.PageCondition);
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public DataResult<NoticeViewModel> GetInfo(string id)
|
|
{
|
|
var data = db.Queryable<SysNotice>()
|
|
.Where(x => x.Id == id)
|
|
.Select<NoticeViewModel>()
|
|
// .Mapper(it =>
|
|
// {
|
|
// //只能写在Select后面
|
|
// it.licensefiles = licenseFiles;
|
|
// it.cardfiles = cardFiles;
|
|
// })
|
|
.First();
|
|
return DataResult<NoticeViewModel>.Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑信息
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public DataResult EditNotice(NoticeInput model)
|
|
{
|
|
if (model.Id.IsNullOrEmpty())
|
|
{
|
|
var isExist = db.Queryable<SysNotice>().Where(x => x.Title == model.Title).First();
|
|
if (isExist != null)
|
|
{
|
|
return DataResult.Failed("公告标题已存在!");
|
|
}
|
|
|
|
var data = model.Adapt<SysNotice>();
|
|
|
|
db.Insertable(data).ExecuteCommand();
|
|
|
|
return DataResult.Successed("添加成功!");
|
|
}
|
|
else
|
|
{
|
|
var info = db.Queryable<SysNotice>().Where(x => x.Id == model.Id).First();
|
|
|
|
var data = model.Adapt(info);
|
|
|
|
db.Updateable(data).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
return DataResult.Successed("更新成功!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布公告
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public DataResult SendNotice(string id)
|
|
{
|
|
var notice = db.Queryable<SysNotice>().Where(x => x.Id == id).First();
|
|
|
|
if (notice.SendStatus == SendStatus.Send.ToEnumInt())
|
|
{
|
|
return DataResult.Failed("已发布!");
|
|
}
|
|
|
|
var clients = db.Queryable<OP_YARD_COMPANY>().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<SysNoticeClient>();
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 撤销公告
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public DataResult CancelNotice(string id)
|
|
{
|
|
var notice = db.Queryable<SysNotice>().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<SysNoticeClient>().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);
|
|
}
|
|
}
|
|
|
|
} |