Commit 83a5509c authored by liudong1993's avatar liudong1993

公告管理

parent 9ab267fa
using Edu.Common.Plugin;
namespace Edu.Common.Enum.User
{
/// <summary>
/// 公告编码规则类型
/// </summary>
public enum NoticeRuleEnum
{
/// <summary>
/// yyyy-[a-z]-[001-999]
/// </summary>
[EnumField("yyyy-[a-z]-[001-999]")]
One = 1,
}
}
using Edu.Common.Plugin;
namespace Edu.Common.Enum.User
{
/// <summary>
/// 公告状态类型
/// </summary>
public enum NoticeStateEnum
{
/// <summary>
/// 发布
/// </summary>
[EnumField("发布")]
Publish = 1,
/// <summary>
/// 草稿
/// </summary>
[EnumField("草稿")]
Draft = 2,
/// <summary>
/// 撤回
/// </summary>
[EnumField("撤回")]
Cancel = 3,
}
}
using Edu.Common.Enum;
using Edu.Common.Enum.User;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.User
{
/// <summary>
/// 公告实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Notice
{
/// <summary>
/// 主键
/// </summary>
public int Id { get; set; }
/// <summary>
/// 来源
/// </summary>
public string From { get; set; }
/// <summary>
/// 发送
/// </summary>
public string To { get; set; }
/// <summary>
/// 抄送人
/// </summary>
public string CopyPeople { get; set; }
/// <summary>
/// 编号
/// </summary>
public string Number { get; set; }
/// <summary>
/// 编码规则 枚举
/// </summary>
public NoticeRuleEnum NumberRule { get; set; }
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 富文本内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 附件 json格式
/// </summary>
public string File { get; set; }
/// <summary>
/// 公告状态
/// </summary>
public NoticeStateEnum NoticeState { get; set; }
/// <summary>
/// 是否置顶 1是 2否
/// </summary>
public int Is_Top { get; set; }
/// <summary>
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 学校编号
/// </summary>
public int School_Id { get; set; }
/// <summary>
/// 删除状态
/// </summary>
public DateStateEnum Status { get; set; }
/// <summary>
/// 创建人
/// </summary>
public int CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 修改人
/// </summary>
public int UpdateBy { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? UpdateTime { get; set; }
}
}
using Edu.Common.Enum;
using Edu.Common.Enum.User;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.User
{
/// <summary>
/// 公告基本配置实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Notice_Base
{
/// <summary>
/// 主键
/// </summary>
public int Id { get; set; }
/// <summary>
/// 抬头图片
/// </summary>
public string Image { get; set; }
/// <summary>
/// 来源
/// </summary>
public string From { get; set; }
/// <summary>
/// 抄送人
/// </summary>
public string CopyPeople { get; set; }
/// <summary>
/// 编号规则 枚举
/// </summary>
public NoticeRuleEnum NumberRule { get; set; }
/// <summary>
/// 集团编号
/// </summary>
public int Group_Id { get; set; }
/// <summary>
/// 学校编号
/// </summary>
public int School_Id { get; set; }
/// <summary>
/// 删除状态
/// </summary>
public DateStateEnum Status { get; set; }
/// <summary>
/// 创建人
/// </summary>
public int CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 修改人
/// </summary>
public int UpdateBy { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? UpdateTime { get; set; }
}
}
using Edu.Common.Enum;
using Edu.Common.Enum.User;
using System;
using VT.FW.DB;
namespace Edu.Model.Entity.User
{
/// <summary>
/// 公告阅读实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Notice_Read
{
/// <summary>
/// 主键
/// </summary>
public int Id { get; set; }
/// <summary>
/// 公告id
/// </summary>
public int NoticeId { get; set; }
/// <summary>
/// 账号id
/// </summary>
public int AccountId { get; set; }
/// <summary>
/// 阅读时间
/// </summary>
public DateTime? ReadTime { get; set; }
}
}
using System;
namespace Edu.Model.ViewModel.User
{
/// <summary>
/// 公告基础实体类
/// </summary>
[Serializable]
public class RB_Notice_Base_ViewModel : Model.Entity.User.RB_Notice_Base
{
}
}
\ No newline at end of file
using System;
namespace Edu.Model.ViewModel.User
{
/// <summary>
/// 公告阅读实体类
/// </summary>
[Serializable]
public class RB_Notice_Read_ViewModel : Model.Entity.User.RB_Notice_Read
{
/// <summary>
/// 阅读数量
/// </summary>
public int ReadNum { get; set; }
}
}
\ No newline at end of file
using Edu.Model.Public;
using System;
using System.Collections.Generic;
namespace Edu.Model.ViewModel.User
{
/// <summary>
/// 公告视图实体类
/// </summary>
[Serializable]
public class RB_Notice_ViewModel : Model.Entity.User.RB_Notice
{
/// <summary>
/// 阅读数量
/// </summary>
public int ReadNum { get; set; }
/// <summary>
/// 文件列表
/// </summary>
public List<FileModel> FileList { get; set; }
}
}
\ No newline at end of file
using Edu.Common.Enum;
using Edu.Common.Enum.User;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.User
{
/// <summary>
/// 公告仓储层
/// </summary>
public class RB_NoticeRepository : BaseRepository<RB_Notice>
{
/// <summary>
/// 分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_Notice_ViewModel> GetPageList(int pageIndex,int pageSize, out long count,RB_Notice_ViewModel demodel)
{
string where = $@" 1=1 and {nameof(RB_Notice.Status)}=0 ";
if (demodel.Group_Id > 0)
{
where += $@" and {nameof(RB_Notice.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id > 0)
{
where += $@" and {nameof(RB_Notice.School_Id)} ={demodel.School_Id}";
}
if (!string.IsNullOrEmpty(demodel.Title))
{
where += $@" and {nameof(RB_Notice.Title)} like '%{demodel.Title}%'";
}
if (!string.IsNullOrEmpty(demodel.Number))
{
where += $@" and {nameof(RB_Notice.Number)} like '%{demodel.Number}%'";
}
if (demodel.NoticeState > 0)
{
where += $@" and {nameof(RB_Notice.NoticeState)} ={(int)demodel.NoticeState}";
}
if (demodel.Is_Top > 0)
{
where += $@" and {nameof(RB_Notice.Is_Top)} ={demodel.Is_Top}";
}
if (demodel.UpdateBy > 0) {
where += $@" and {nameof(RB_Notice.UpdateBy)} ={demodel.UpdateBy}";
}
string sql = $@" select * from RB_Notice where {where} order by Id desc";
return GetPage<RB_Notice_ViewModel>(pageIndex, pageSize, out count, sql).ToList();
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_Notice_ViewModel> GetList(RB_Notice_ViewModel demodel)
{
string where = $@" 1=1 and {nameof(RB_Notice.Status)}=0 ";
if (demodel.Group_Id > 0)
{
where += $@" and {nameof(RB_Notice.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id > 0)
{
where += $@" and {nameof(RB_Notice.School_Id)} ={demodel.School_Id}";
}
if (!string.IsNullOrEmpty(demodel.Title)) {
where += $@" and {nameof(RB_Notice.Title)} like '%{demodel.Title}%'";
}
if (demodel.NoticeState > 0) {
where += $@" and {nameof(RB_Notice.NoticeState)} ={(int)demodel.NoticeState}";
}
if (demodel.Is_Top > 0) {
where += $@" and {nameof(RB_Notice.Is_Top)} ={demodel.Is_Top}";
}
string sql = $@" select * from RB_Notice where {where}";
return Get<RB_Notice_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取最大的编码
/// </summary>
/// <param name="numberRule"></param>
/// <returns></returns>
public string GetNoticeNumberMax(NoticeRuleEnum numberRule, int GroupId)
{
string sql = $@" select Number from RB_Notice where NumberRule ={(int)numberRule} and Group_Id ={GroupId} and Status=0 order by Id desc limit 1";
var obj = ExecuteScalar(sql);
if (obj == null)
{
return "";
}
else
{
return obj.ToString();
}
}
}
}
\ No newline at end of file
using Edu.Common.Enum;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.User
{
/// <summary>
/// 公告基础仓储层
/// </summary>
public class RB_Notice_BaseRepository : BaseRepository<RB_Notice_Base>
{
public List<RB_Notice_Base_ViewModel> GetList(RB_Notice_Base_ViewModel demodel)
{
string where = $@" 1=1 and Status=0 ";
if (demodel.Group_Id > 0)
{
where += $@" and {nameof(RB_Notice_Base.Group_Id)} ={demodel.Group_Id}";
}
if (demodel.School_Id > 0)
{
where += $@" and {nameof(RB_Notice_Base.School_Id)} ={demodel.School_Id}";
}
string sql = $@" select * from RB_Notice_Base where {where}";
return Get<RB_Notice_Base_ViewModel>(sql).ToList();
}
}
}
\ No newline at end of file
using Edu.Common.Enum;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;
namespace Edu.Repository.User
{
/// <summary>
/// 公告阅读仓储层
/// </summary>
public class RB_Notice_ReadRepository : BaseRepository<RB_Notice_Read>
{
public List<RB_Notice_Read_ViewModel> GetList(RB_Notice_Read_ViewModel demodel)
{
string where = $@" 1=1 and Status=0 ";
if (demodel.NoticeId > 0)
{
where += $@" and {nameof(RB_Notice_Read.NoticeId)} ={demodel.NoticeId}";
}
if (demodel.AccountId > 0)
{
where += $@" and {nameof(RB_Notice_Read.AccountId)} ={demodel.AccountId}";
}
string sql = $@" select * from RB_Notice_Read where {where}";
return Get<RB_Notice_Read_ViewModel>(sql).ToList();
}
/// <summary>
/// 获取阅读数量列表
/// </summary>
/// <param name="noticeIds"></param>
/// <returns></returns>
public List<RB_Notice_Read_ViewModel> GetNoticeReadNumList(string noticeIds)
{
string sql = $@" select NoticeId,count(0) as ReadNum from RB_Notice_Read where NoticeId in ({noticeIds}) group by NoticeId";
return Get<RB_Notice_Read_ViewModel>(sql).ToList();
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using Edu.AOP;
using Edu.Cache.User;
using Edu.Common.API;
using Edu.Common.Enum.User;
using Edu.Common.Plugin;
using Edu.Model.CacheModel;
using Edu.Model.ViewModel.User;
using Edu.Module.User;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Edu.WebApi.Controllers.User
{
[Route("api/[controller]/[action]")]
[ApiExceptionFilter]
[ApiController]
[EnableCors("AllowCors")]
public class UserCenterController : BaseController
{
/// <summary>
/// 助教处理类对象
/// </summary>
private readonly NoticeModule noticeModule = AOPHelper.CreateAOPObject<NoticeModule>();
#region 公告管理
/// <summary>
/// 获取公告基础信息
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticeBaseInfo()
{
var Robj = noticeModule.GetNoticeBaseInfo(base.UserInfo.Group_Id);
return ApiResult.Success("", Robj);
}
/// <summary>
/// 新增修改公告基础
/// </summary>
/// <returns></returns>
public ApiResult SetNoticeBaseInfo() {
var demodel = JsonHelper.DeserializeObject<RB_Notice_Base_ViewModel>(RequestParm.Msg.ToString());
demodel.Group_Id = base.UserInfo.Group_Id;
demodel.School_Id = base.UserInfo.School_Id;
demodel.CreateBy = base.UserInfo.Id;
demodel.CreateTime = DateTime.Now;
demodel.UpdateBy = base.UserInfo.Id;
demodel.UpdateTime = DateTime.Now;
string msg = noticeModule.SetNoticeBaseInfo(demodel);
if (msg == "")
{
return ApiResult.Success();
}
else {
return ApiResult.Failed();
}
}
/// <summary>
/// 获取枚举列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticeRuleEnumList()
{
var list = EnumHelper.EnumToList(typeof(NoticeRuleEnum));
return ApiResult.Success("", list.Select(x => new
{
x.Name,
x.Id
}));
}
/// <summary>
/// 获取公告分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticePageList()
{
var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
var query = JsonHelper.DeserializeObject<RB_Notice_ViewModel>(RequestParm.Msg.ToString());
query.Group_Id = base.UserInfo.Group_Id;
var list = noticeModule.GetNoticePageList(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
pageModel.Count = rowsCount;
pageModel.PageData = list.Select(x => new
{
x.Id,
x.From,
x.Number,
x.Title,
x.NoticeState,
NoticeStateName = x.NoticeState.ToName(),
x.Is_Top,
x.ReadNum,
x.UpdateBy,
UpdateByName = UserReidsCache.GetUserLoginInfo(x.UpdateBy)?.AccountName ?? "",
UpdateTime = x.UpdateTime.HasValue ? x.UpdateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""
});
return ApiResult.Success("", pageModel);
}
/// <summary>
/// 获取公告信息
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticeInfo() {
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int NoticeId = parms.GetInt("NoticeId", 0);
if (NoticeId <= 0) {
return ApiResult.ParamIsNull("请传递公告id");
}
return noticeModule.GetNoticeInfo(NoticeId);
}
/// <summary>
/// 新增修改公告
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetNoticeInfo()
{
UserInfo userInfo = base.UserInfo;
RB_Notice_ViewModel demodel = JsonHelper.DeserializeObject<RB_Notice_ViewModel>(RequestParm.Msg.ToString());
if (string.IsNullOrEmpty(demodel.From))
{
return ApiResult.ParamIsNull("请传递来源");
}
if (string.IsNullOrEmpty(demodel.To))
{
return ApiResult.ParamIsNull("请传递发送部门");
}
if (string.IsNullOrEmpty(demodel.CopyPeople))
{
return ApiResult.ParamIsNull("请选择抄送人");
}
if (string.IsNullOrEmpty(demodel.Title))
{
return ApiResult.ParamIsNull("请输入标题");
}
demodel.FileList ??= new List<Model.Public.FileModel>();
demodel.File = JsonHelper.Serialize(demodel.FileList.Select(x => new { x.FileName, x.FileUrl }));
if (demodel.NoticeState != NoticeStateEnum.Publish && demodel.NoticeState != NoticeStateEnum.Draft)
{
return ApiResult.ParamIsNull("公告状态不正确");
}
demodel.Is_Top = demodel.Is_Top == 0 ? 2 : demodel.Is_Top;
demodel.Status = Common.Enum.DateStateEnum.Normal;
demodel.Group_Id = userInfo.Group_Id;
demodel.School_Id = userInfo.School_Id;
demodel.CreateBy = userInfo.Id;
demodel.CreateTime = DateTime.Now;
demodel.UpdateBy = userInfo.Id;
demodel.UpdateTime = DateTime.Now;
bool flag = noticeModule.SetNoticeInfo(demodel);
if (flag)
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed();
}
}
/// <summary>
/// 公告操作
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetNoticeOperation() {
UserInfo userInfo = base.UserInfo;
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int NoticeId = parms.GetInt("NoticeId", 0);
int Type = parms.GetInt("Type", 1);// 类型 1置顶 2取消置顶 3撤回 4删除 5公告阅读
if (NoticeId <= 0) {
return ApiResult.ParamIsNull("公告id");
}
bool flag = noticeModule.SetNoticeOperation(NoticeId, Type, userInfo);
if (flag)
{
return ApiResult.Success();
}
else {
return ApiResult.Failed();
}
}
/// <summary>
/// 获取枚举列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoticeStateEnumList() {
var list = EnumHelper.EnumToList(typeof(NoticeStateEnum));
return ApiResult.Success("", list.Select(x => new
{
x.Name,
x.Id
}));
}
#endregion
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment