diff --git a/.vs/QualityControlPlatform/DesignTimeBuild/.dtbcache.v2 b/.vs/QualityControlPlatform/DesignTimeBuild/.dtbcache.v2
index f020e68..089465c 100644
Binary files a/.vs/QualityControlPlatform/DesignTimeBuild/.dtbcache.v2 and b/.vs/QualityControlPlatform/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/.vs/QualityControlPlatform/v17/.futdcache.v1 b/.vs/QualityControlPlatform/v17/.futdcache.v1
index 29c9bc7..9310769 100644
Binary files a/.vs/QualityControlPlatform/v17/.futdcache.v1 and b/.vs/QualityControlPlatform/v17/.futdcache.v1 differ
diff --git a/.vs/QualityControlPlatform/v17/.suo b/.vs/QualityControlPlatform/v17/.suo
index 3fd5fd0..fc7b12b 100644
Binary files a/.vs/QualityControlPlatform/v17/.suo and b/.vs/QualityControlPlatform/v17/.suo differ
diff --git a/QualityControlPlatform/Controllers/Base/ErrorController.cs b/QualityControlPlatform/Controllers/Base/ErrorController.cs
new file mode 100644
index 0000000..56ac330
--- /dev/null
+++ b/QualityControlPlatform/Controllers/Base/ErrorController.cs
@@ -0,0 +1,33 @@
+using Microsoft.AspNetCore.Diagnostics;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using QualityControlPlatform.Helpers.Nlog;
+using QualityControlPlatform.Helpers.Response;
+
+namespace QualityControlPlatform.Controllers.Base
+{
+ ///
+ /// 全局异常返回
+ ///
+ [Route("error")]
+ [ApiController]
+ public class ErrorController : ControllerBase
+ {
+ ///
+ /// 全局错误返回
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Index()
+ {
+ //UseExceptionHandler中间件中拦截到异常时,会将异常信息保存在请求上下文中,所以我们可以从HttpContext中拿到ExceptionHandler的异常信息:
+ var feature = HttpContext.Features.Get();
+ if (feature == null) return ResponseHelper.ServerError();
+ var exception = feature.Error;
+ LogHelper.Log.Error(exception);
+ Console.WriteLine("【ERROR】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + exception.Message);
+ // todo:调用日志组件记录异常信息,或对异常做多路判断
+ return ResponseHelper.ServerError();
+ }
+ }
+}
\ No newline at end of file
diff --git a/QualityControlPlatform/Controllers/Diseases/AnswerController.cs b/QualityControlPlatform/Controllers/Diseases/AnswerController.cs
new file mode 100644
index 0000000..bc84bc9
--- /dev/null
+++ b/QualityControlPlatform/Controllers/Diseases/AnswerController.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Auth;
+using QualityControlPlatform.Helpers.Nlog;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+
+namespace QualityControlPlatform.Controllers.Diseases
+{
+
+ ///
+ /// 内容上报
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class AnswerController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+ ///
+ /// 上报内容填报
+ ///
+ /// ReportId,UserId,ReportTime不需要填
+ ///
+ [HttpPost]
+ public ActionResult Add([FromBody]List reports)
+ {
+ try
+ {
+ var time = DateTime.Now;
+ foreach (var report in reports)
+ {
+ _db.Reports.Add(new Report()
+ {
+ DiseasesId = report.DiseasesId,
+ ReportTemplateId = report.ReportTemplateId,
+ UserId = this.CurUserId(),
+ ReportContent = report.ReportContent,
+ ReportTime = time,
+ });
+ }
+ _db.SaveChanges();
+ }
+ catch (Exception e)
+ {
+ LogHelper.Log.Error($"问题上报出错:{e}");
+ ResponseHelper.ServerError();
+ }
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 该病种下所有的填报信息
+ ///
+ /// 病种Id
+ /// 用户Id
+ /// 页码
+ /// 数量
+ ///
+ [HttpGet]
+ public ActionResult List(int diseasesId, int userId, int? page, int number)
+ {
+ var report = _db.Reports.Where(p => p.DiseasesId == diseasesId && p.UserId == userId).Select(s=> new
+ {
+ s.DiseasesId,
+ s.UserId,
+ s.ReportContent,
+ s.ReportTime,
+ s.ReportTemplate
+ }).ToList();
+ return ResponseHelper.Success(
+ PageHelper.Pagination(report.GroupBy(q => q.ReportTime).Select(t => new
+ {
+ ReportTime = t.Key,
+ Reports = report.Where(p => p.ReportTime == t.Key).Select(r => new
+ {
+ r.DiseasesId,
+ r.UserId,
+ r.ReportContent,
+ r.ReportTime,
+ r.ReportTemplate
+ })
+ }).ToList(), Convert.ToInt32(page), number));
+ }
+ }
+}
diff --git a/QualityControlPlatform/Controllers/Diseases/DiseasesController.cs b/QualityControlPlatform/Controllers/Diseases/DiseasesController.cs
new file mode 100644
index 0000000..7b303ff
--- /dev/null
+++ b/QualityControlPlatform/Controllers/Diseases/DiseasesController.cs
@@ -0,0 +1,101 @@
+using System;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+using System.Linq;
+using QualityControlPlatform.Helpers.StringText;
+
+namespace QualityControlPlatform.Controllers.Diseases
+{
+ ///
+ ///
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class DiseasesController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+
+ ///
+ /// 获取病种列表
+ ///
+ /// 页码
+ /// 每页数量
+ /// 是否启用,默认启用列表
+ ///
+ [HttpGet]
+ public ActionResult List(int? page, int number, bool isUsing=true)
+ {
+ var diseases = _db.Diseases.Select(q => new DiseaseModel()
+ {
+ DiseasesId = q.DiseasesId,
+ Description = q.Description,
+ DiseasesCode = q.DiseasesCode,
+ DiseasesName = q.DiseasesName,
+ IsUsing = q.IsUsing,
+ }).ToList();
+ if (isUsing)
+ diseases = _db.Diseases.Where(p=>p.IsUsing==isUsing).Select(q => new DiseaseModel()
+ {
+ DiseasesId = q.DiseasesId,
+ Description = q.Description,
+ DiseasesCode = q.DiseasesCode,
+ DiseasesName = q.DiseasesName,
+ IsUsing = q.IsUsing,
+ }).ToList();
+ return ResponseHelper.Success(
+ PageHelper.Pagination(diseases, Convert.ToInt32(page), number));
+ }
+
+ ///
+ /// 添加病种 DiseaseId, DiseasesCode 不需要填
+ ///
+ ///
+ ///
+ [HttpPost]
+ public ActionResult Add([FromBody]DiseaseModel diseaseModel)
+ {
+ _db.Diseases.Add(new Disease()
+ {
+ DiseasesName = diseaseModel.DiseasesName, Description = diseaseModel.Description, DiseasesCode =new CodeHelper().GetCode(diseaseModel.DiseasesName,10),IsUsing = diseaseModel.IsUsing,
+ });
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ ///
+ /// 编辑病种信息 DiseaseId,DiseasesName,Description(没有更改就把原来的传过来) 必填, DiseasesCode不需要填
+ ///
+ ///
+ ///
+ [HttpPost]
+ public ActionResult Edit([FromBody]DiseaseModel diseaseModel)
+ {
+ var disease = _db.Diseases.Find(diseaseModel.DiseasesId);
+ disease.Description = diseaseModel.Description;
+ disease.DiseasesName = diseaseModel.DiseasesName;
+ disease.DiseasesCode = new CodeHelper().GetCode(diseaseModel.DiseasesName, 10);
+ disease.IsUsing = diseaseModel.IsUsing;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ ///
+ /// 修改病种状态(是否停用)
+ ///
+ /// 病种Id
+ ///
+ [HttpGet]
+ public ActionResult Change(int diseaseId)
+ {
+ var disease = _db.Diseases.Find(diseaseId);
+ disease.IsUsing = !disease.IsUsing;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+
+ }
+}
diff --git a/QualityControlPlatform/Controllers/Diseases/QuestionController.cs b/QualityControlPlatform/Controllers/Diseases/QuestionController.cs
new file mode 100644
index 0000000..988d503
--- /dev/null
+++ b/QualityControlPlatform/Controllers/Diseases/QuestionController.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+
+namespace QualityControlPlatform.Controllers.Diseases
+{
+ ///
+ /// 预设病种的问题
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class QuestionController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+ ///
+ /// 添加预设问题
+ ///
+ /// ReportTemplateId 不填
+ ///
+ [HttpPost]
+ public ActionResult Add([FromBody]List reportTemplates)
+ {
+ try
+ {
+ foreach (var reportTemplate in reportTemplates)
+ {
+ _db.ReportTemplates.Add(new ReportTemplate()
+ {
+ DiseasesId = reportTemplate.DiseasesId,
+ Question = reportTemplate.Question,
+ IfMust = reportTemplate.IfMust,
+ Type = reportTemplate.Type,
+ });
+ }
+ _db.SaveChanges();
+ }
+ catch
+ {
+ return ResponseHelper.ServerError();
+ }
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 删除预设问题
+ ///
+ /// 预设问题Id(必须是没有上报过的问题才可以删除)
+ ///
+ [HttpGet]
+ public ActionResult Delete(int reportTemplateId)
+ {
+ if (_db.Reports.Count(p => p.ReportTemplateId == reportTemplateId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DeletionIsProhibited);
+ var report = _db.ReportTemplates.Find(reportTemplateId);
+ _db.ReportTemplates.Remove(report);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 相关病种的问题
+ ///
+ /// 病种Id
+ /// 页码
+ /// 每页数量
+ ///
+ [HttpGet]
+ public ActionResult List(int diseasesId, int? page,int number)
+ {
+ return ResponseHelper.Success(
+ PageHelper.Pagination(_db.ReportTemplates.Where(p=>p.DiseasesId==diseasesId).Select(q => new
+ {
+ q.DiseasesId,
+ q.ReportTemplateId,
+ q.Question,
+ q.IfMust,
+ q.Type,
+ q.Diseases.DiseasesName
+ }).ToList(), Convert.ToInt32(page), number));
+ }
+
+ ///
+ /// 修改问题内容
+ ///
+ /// 需要传ReportTemplateId,IfMust,Question,Type(没做修改的把原来的值传过来) 如果已经有上报内容的预设问题将不允许修改
+ ///
+ [HttpPost]
+ public ActionResult Edit([FromBody]ReportTemplateModel reportTemplate)
+ {
+ if (_db.Reports.Count(p => p.ReportTemplateId == reportTemplate.ReportTemplateId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.EditIsProhibited);
+ var reportTemplateEntity = _db.ReportTemplates.Find(reportTemplate.ReportTemplateId);
+ reportTemplateEntity.IfMust = reportTemplate.IfMust;
+ reportTemplateEntity.Question = reportTemplate.Question;
+ reportTemplateEntity.Type = reportTemplate.Type;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ }
+}
diff --git a/QualityControlPlatform/Controllers/Menus/MenuController.cs b/QualityControlPlatform/Controllers/Menus/MenuController.cs
new file mode 100644
index 0000000..0020591
--- /dev/null
+++ b/QualityControlPlatform/Controllers/Menus/MenuController.cs
@@ -0,0 +1,44 @@
+using System.Linq;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Menu;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.DbContext;
+
+namespace QualityControlPlatform.Controllers.Menus
+{
+ ///
+ /// 菜单相关操作
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class MenuController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+ ///
+ /// 获取菜单列表
+ ///
+ ///
+ [HttpGet]
+ public ActionResult List()
+ {
+ return ResponseHelper.Success(MenuHelper.Serialization(_db.Menus.ToList()));
+ }
+
+ ///
+ /// 更新菜单名称
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Update(int menuId, string menuName)
+ {
+ var menu = _db.Menus.Find(menuId);
+ menu.MenuName = menuName;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ }
+}
diff --git a/QualityControlPlatform/Controllers/NewController.cs b/QualityControlPlatform/Controllers/NewController.cs
deleted file mode 100644
index a4ec939..0000000
--- a/QualityControlPlatform/Controllers/NewController.cs
+++ /dev/null
@@ -1,206 +0,0 @@
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using QualityControlPlatform.Helpers.Pagination;
-using QualityControlPlatform.Helpers.Response;
-using System.Linq;
-using QualityControlPlatform.Helpers.Auth;
-using QualityControlPlatform.Models.ControllerModels;
-using QualityControlPlatform.Models.DbContext;
-
-namespace QualityControlPlatform.Controllers
-{
- ///
- /// 新闻相关接口
- ///
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class NewController : ControllerBase
- {
- private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
-
- ///
- /// 获取栏目列表
- ///
- /// 当前页码,为空则表示0
- ///
- [HttpGet]
- public ActionResult PartList(int? page)
- {
- return ResponseHelper.Success(
- PageHelper.Pagination(_db.Parts.ToList(), Convert.ToInt32(page), 8));
- }
-
- ///
- /// 添加栏目
- ///
- ///
- ///
- [HttpPost]
- public ActionResult AddPart([FromBody]PartModel partModel)
- {
- var part = new Part()
- {
- PartName = partModel.PartName,
- PartCode = partModel.PartCode,
- Description = partModel.Description,
- };
- _db.Parts.Add(part);
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
-
- ///
- /// 删除栏目
- ///
- /// 需删除栏目Id
- ///
- [HttpGet]
- public ActionResult DeletePart(int partId)
- {
- var part = _db.Parts.Find(partId);
- if(part.News.Count>0)
- return ResponseHelper.Success(ResponseHelper.ErrorEnum.DeletionIsProhibited);
- _db.Parts.Remove(part);
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
- ///
- /// 新闻列表
- ///
- ///
- /// 当前页码,为空则表示0
- ///
- [HttpGet]
- public ActionResult NewList(int partId,int? page)
- {
- return ResponseHelper.Success(PageHelper.Pagination(_db.News.Where(p => p.PartId == partId).ToList(),
- Convert.ToInt32(page), 8));
- }
-
- ///
- /// 新闻详情
- ///
- ///
- [HttpGet]
- public ActionResult NewInfo(int newId)
- {
- var newSingle = _db.News.Find(newId);
- newSingle.User = null;
- return ResponseHelper.Success(newSingle);
- }
- ///
- /// 添加新闻
- ///
- /// 数据集
- ///
- [HttpPost]
- public ActionResult AddNew([FromBody]NewsModel newsModel)
- {
- var newEntity = new News()
- {
- PartId = newsModel.PartId,
- UserId = this.CurUserId(),
- Title= newsModel.Title,
- Content = newsModel.Content,
- Time=DateTime.Now,
- };
- _db.News.Add(newEntity);
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
- ///
- /// 编辑新闻
- ///
- /// 数据集(NewId 必填)
- ///
- [HttpPost]
- public ActionResult EditNew([FromBody]NewsModel newsModel)
- {
- var newEntity = _db.News.Find(newsModel.NewId);
- newEntity.Title = newsModel.Title;
- newEntity.Content = newsModel.Content;
- newEntity.UserId = this.CurUserId();
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
- ///
- /// 添加附件
- ///
- /// 新闻Id
- ///
- [HttpGet]
- public ActionResult AddAttached(int newId)
- {
- try
- {
- foreach (var file in Request.Form.Files)
- {
- using var stream =
- new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", file.FileName),
- FileMode.Create);
- file.CopyTo(stream);
- var fileEntity = new Attached()
- {
- NewId = newId,
- FileName = file.FileName,
- UserId = this.CurUserId(),
- AttachedTime = DateTime.Now,
- FileSize = $"{file.Length / 1024.0}M",
- };
- _db.Attacheds.Add(fileEntity);
- }
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
- catch (Exception)
- {
- return ResponseHelper.ServerError();
- }
- }
- ///
- /// 获取附件列表
- ///
- /// 新闻Id
- ///
- [HttpGet]
- public ActionResult AttachedList(int newId)
- {
- return ResponseHelper.Success(_db.News.Find(newId).Attacheds);
- }
- ///
- /// 下载附件
- ///
- /// 附件id
- ///
- [HttpGet]
- public ActionResult DownloadAttached(int attachedId)
- {
- var attached = _db.Attacheds.Find(attachedId);
- var path = Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", attached.FileName);
-
- //Read the File data into Byte Array.
- var bytes = System.IO.File.ReadAllBytes(path);
- //Send the File to Download.
- return File(bytes, "application/octet-stream", attached.FileName);
- }
- ///
- /// 删除附件
- ///
- /// 附件Id
- ///
- [HttpGet]
- public ActionResult DeleteAttached(int attachedId)
- {
- var attached = _db.Attacheds.Find(attachedId);
- if (System.IO.File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile",attached.FileName)))
- System.IO.File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", attached.FileName));
- _db.Attacheds.Remove(attached);
- _db.SaveChanges();
- return ResponseHelper.Success();
- }
- }
-}
diff --git a/QualityControlPlatform/Controllers/News/NewController.cs b/QualityControlPlatform/Controllers/News/NewController.cs
new file mode 100644
index 0000000..9d74161
--- /dev/null
+++ b/QualityControlPlatform/Controllers/News/NewController.cs
@@ -0,0 +1,318 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Auth;
+using QualityControlPlatform.Helpers.File;
+using QualityControlPlatform.Helpers.Nlog;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Helpers.StringText;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+
+namespace QualityControlPlatform.Controllers.News
+{
+ ///
+ /// 新闻相关接口
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class NewController : ControllerBase
+ {
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+
+ ///
+ /// 获取栏目列表
+ ///
+ /// 当前页码,为空则表示0
+ /// 每页数量
+ ///
+ [HttpGet]
+ public ActionResult PartList(int? page,int number)
+ {
+ return ResponseHelper.Success(
+ PageHelper.Pagination(_db.Parts.Select(q=>new PartModel()
+ {
+ PartId = q.PartId,
+ PartCode = q.PartCode,
+ Description = q.Description,
+ PartName = q.PartName,
+ }).ToList(), Convert.ToInt32(page), number));
+ }
+
+ ///
+ /// 添加栏目
+ ///
+ ///
+ ///
+ [HttpPost]
+ public ActionResult AddPart([FromBody]PartModel partModel)
+ {
+ if (_db.Parts.Count(p => p.PartName == partModel.PartName) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DataRepeat);
+ var part = new Part()
+ {
+ PartName = partModel.PartName,
+ PartCode = new CodeHelper().GetCode(partModel.PartName,10),
+ Description = partModel.Description,
+ };
+ _db.Parts.Add(part);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 删除栏目
+ ///
+ /// 需删除栏目Id
+ ///
+ [HttpGet]
+ public ActionResult DeletePart(int partId)
+ {
+ if (_db.News.Count(p => p.PartId == partId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DeletionIsProhibited);
+ var part = _db.Parts.Find(partId);
+ _db.Parts.Remove(part);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 编辑栏目
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult EditPart(int partId, string description, string partName)
+ {
+ var part = _db.Parts.Find(partId);
+ part.Description = description;
+ part.PartName = partName;
+ part.PartCode = new CodeHelper().GetCode(part.PartName, 10);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ ///
+ /// 新闻列表
+ ///
+ ///
+ /// 当前页码,为空则表示0
+ /// 每页数量
+ /// 是否发布,不传为true(默认已发布)
+ ///
+ [HttpGet]
+ public ActionResult NewList(int partId,int? page,int number, bool ifRelease=true)
+ {
+ var news = _db.News.Where(p => p.PartId == partId).Select(q => new NewsModel()
+ {
+ PartId = partId,
+ NewId = q.NewId,
+ Content = q.Content,
+ Title = q.Title,
+ AttachedId = q.Attacheds.Select(p => p.AttachedId).ToList(),
+ UserName = q.User.UserName,
+ IfRelease = q.IfRelease
+ }).ToList();
+ if (ifRelease)
+ news = _db.News.Where(p => p.PartId == partId && p.IfRelease == ifRelease).Select(q => new NewsModel()
+ {
+ PartId = partId,
+ NewId = q.NewId,
+ Content = q.Content,
+ Title = q.Title,
+ AttachedId = q.Attacheds.Select(p => p.AttachedId).ToList(),
+ UserName = q.User.UserName,
+ IfRelease = q.IfRelease
+ }).ToList();
+ return ResponseHelper.Success(PageHelper.Pagination(news,
+ Convert.ToInt32(page),number ));
+ }
+
+ ///
+ /// 新闻详情
+ ///
+ ///
+ [HttpGet]
+ public ActionResult NewInfo(int newId)
+ {
+ var newSingle = _db.News.Find(newId);
+ newSingle.User = null;
+ return ResponseHelper.Success(new
+ {
+ newSingle.NewId,
+ newSingle.User,
+ newSingle.Title,
+ newSingle.Content,
+ newSingle.IfRelease,
+ newSingle.Time,
+ AttachedList = _db.Attacheds.Where(p=>p.NewId==newId).Select(q=>new
+ {
+ q.FileName,
+ q.FileSize,
+ q.AttachedTime,
+ q.AttachedId
+ })
+ });
+ }
+ ///
+ /// 添加新闻
+ ///
+ /// 数据集PartId,Title,Content必传
+ ///
+ [HttpPost]
+ public ActionResult AddNew([FromBody] NewsModel newsModel)
+ {
+ var newEntity = new Models.DbContext.News()
+ {
+ PartId = newsModel.PartId,
+ UserId = this.CurUserId(),
+ Title= newsModel.Title,
+ IfRelease = newsModel.IfRelease,
+ Content = newsModel.Content,
+ Time=DateTime.Now,
+ };
+ _db.News.Add(newEntity);
+ _db.SaveChanges();
+ newsModel.NewId = newEntity.NewId;
+ newsModel.Homology();
+ return ResponseHelper.Success();
+ }
+ ///
+ /// 编辑新闻
+ ///
+ /// 数据集(NewId,Title,Content 必填)
+ ///
+ [HttpPost]
+ public ActionResult EditNew([FromBody] NewsModel newsModel)
+ {
+ var newEntity = _db.News.Find(newsModel.NewId);
+ newEntity.Title = newsModel.Title;
+ newEntity.Content = newsModel.Content;
+ newEntity.UserId = this.CurUserId();
+ newEntity.IfRelease = newsModel.IfRelease;
+ _db.SaveChanges();
+ newsModel.NewId = newEntity.NewId;
+ newsModel.Homology();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 删除新闻信息(只能删除未发布的)
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Delete(int newId)
+ {
+ var newEntity = _db.News.Find(newId);
+ if (newEntity.IfRelease == true)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DeletionIsProhibited);
+ _db.News.Remove(newEntity);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 修改当前新闻发布状态
+ ///
+ /// 新闻Id
+ ///
+ [HttpGet]
+ public ActionResult Change(int newId)
+ {
+ var news= _db.News.Find(newId);
+ news.IfRelease = !news.IfRelease;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 添加附件
+ ///
+ ///
+ [HttpPost]
+ public ActionResult AddAttached()
+ {
+ try
+ {
+ var attachedList = new List();
+ foreach (var file in Request.Form.Files)
+ {
+ FileHelper.CreateFile(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile"));
+ using var stream =
+ new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", file.FileName),
+ FileMode.Create);
+ file.CopyTo(stream);
+ var fileEntity = new Attached()
+ {
+ FileName = file.FileName,
+ UserId = this.CurUserId(),
+ AttachedTime = DateTime.Now,
+ FileSize = FileHelper.FileSize(file.Length),
+ };
+ _db.Attacheds.Add(fileEntity);
+ _db.SaveChanges();
+ attachedList.Add(fileEntity.AttachedId);
+ }
+ return ResponseHelper.Success(attachedList);
+ }
+ catch (Exception e)
+ {
+ LogHelper.Log.Error(e.ToString());
+ return ResponseHelper.ServerError();
+ }
+ }
+ ///
+ /// 获取附件列表
+ ///
+ /// 新闻Id
+ ///
+ [HttpGet]
+ public ActionResult AttachedList(int newId)
+ {
+ return ResponseHelper.Success(_db.Attacheds.Where(p=>p.NewId==newId).Select(p=>new
+ {
+ p.User.UserName,
+ p.AttachedId,
+ p.AttachedTime,
+ p.FileName,
+ p.FileSize,
+ }));
+ }
+ ///
+ /// 下载附件
+ ///
+ /// 附件id
+ ///
+ [HttpGet]
+ public ActionResult DownloadAttached(int attachedId)
+ {
+ var attached = _db.Attacheds.Find(attachedId);
+ var path = Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", attached.FileName);
+
+ //Read the File data into Byte Array.
+ var bytes = System.IO.File.ReadAllBytes(path);
+ //Send the File to Download.
+ return File(bytes, "application/octet-stream", attached.FileName);
+ }
+ ///
+ /// 删除附件
+ ///
+ /// 附件Id
+ ///
+ [HttpGet]
+ public ActionResult DeleteAttached(int attachedId)
+ {
+ var attached = _db.Attacheds.Find(attachedId);
+ if (System.IO.File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile",attached.FileName)))
+ System.IO.File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "UploadFile", attached.FileName));
+ _db.Attacheds.Remove(attached);
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ }
+}
diff --git a/QualityControlPlatform/Controllers/User/HospitalController.cs b/QualityControlPlatform/Controllers/User/HospitalController.cs
new file mode 100644
index 0000000..1ae136f
--- /dev/null
+++ b/QualityControlPlatform/Controllers/User/HospitalController.cs
@@ -0,0 +1,142 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.DbContext;
+using System.Linq;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.StringText;
+
+namespace QualityControlPlatform.Controllers.User
+{
+ ///
+ /// 医院基础信息
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class HospitalController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+ ///
+ /// 医院列表
+ ///
+ /// 页码
+ /// 数量
+ ///
+ [HttpGet]
+ public ActionResult List(int page, int number)
+ {
+ return ResponseHelper.Success(PageHelper.Pagination(_db.Hospitals.Select(p=> new
+ {
+ p.HospitalId,
+ p.HospitalName,
+ p.Address,
+ p.Phone,
+ p.HospitalCode
+ }).ToList(), page, number));
+ }
+
+ ///
+ /// 该医院下的用户
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult UserList(int hospitalId,int page, int number)
+ {
+ return ResponseHelper.Success(PageHelper.Pagination(_db.Users.Where(p=>p.HospitalId==hospitalId).Select(p=>new
+ {
+ p.UserName,
+ p.Phone,
+ p.UserCode,
+ p.UserId,
+ p.Department,
+ p.DepartCode
+ }).ToList(), page, number));
+ }
+
+ ///
+ /// 该医院下上报过该病种的用户
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult AnswerUsers(int hospitalId, int diseasesId, int page, int number)
+ {
+ return ResponseHelper.Success(PageHelper.Pagination(_db.Reports.Where(p => p.DiseasesId == diseasesId && p.User.HospitalId == hospitalId).Select(s => s.User).Select(p => new
+ {
+ p.UserName,
+ p.Phone,
+ p.UserCode,
+ p.UserId,
+ p.Department,
+ p.DepartCode
+ }).Distinct().ToList(),page,number));
+ }
+
+ ///
+ /// 添加医院信息
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Add(string hospitalName, string address, string phone)
+ {
+ if (_db.Hospitals.Count(p => p.HospitalName == hospitalName) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DataRepeat);
+ _db.Hospitals.Add(new Hospital()
+ {
+ HospitalName = hospitalName,
+ Address=address,
+ Phone =phone,
+ HospitalCode =new CodeHelper().GetCode(hospitalName,hospitalName.Length+1)
+ });
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+
+ }
+
+ ///
+ /// 修改医院信息
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Edit(int hospitalId, string hospitalName, string address, string phone, string hospitalCode)
+ {
+ var hospital = _db.Hospitals.Find(hospitalId);
+ hospital.Address = address;
+ hospital.Phone = phone;
+ hospital.HospitalCode = hospitalCode;
+ hospital.HospitalName= hospitalName;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 删除医院信息
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult Delete(int hospitalId)
+ {
+ if (_db.Users.Count(p => p.HospitalId == hospitalId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DeletionIsProhibited);
+ _db.Hospitals.Remove(_db.Hospitals.Find(hospitalId));
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ }
+}
diff --git a/QualityControlPlatform/Controllers/User/RoleController.cs b/QualityControlPlatform/Controllers/User/RoleController.cs
new file mode 100644
index 0000000..4019b3f
--- /dev/null
+++ b/QualityControlPlatform/Controllers/User/RoleController.cs
@@ -0,0 +1,142 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using QualityControlPlatform.Helpers.StringText;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+using System.Linq;
+using QualityControlPlatform.Helpers.Menu;
+using QualityControlPlatform.Helpers.Pagination;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Models.LogicModel;
+
+namespace QualityControlPlatform.Controllers.User
+{
+ ///
+ /// 角色控制
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class RoleController : ControllerBase
+ {
+
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+ ///
+ /// 添加角色
+ ///
+ ///
+ ///
+ [HttpPost]
+ public ActionResult Add([FromBody]RoleModel roleModel)
+ {
+ if (_db.Roles.Count(p => p.RoleName == roleModel.RoleName) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DataRepeat);
+ _db.Roles.Add(new Role()
+ {
+ RoleCode = new CodeHelper().GetCode(roleModel.RoleName, 8),
+ RoleName = roleModel.RoleName,
+ Description = roleModel.Description,
+ });
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 删除角色
+ ///
+ /// 角色Id
+ ///
+ [HttpGet]
+ public ActionResult Delete(int roleId)
+ {
+ if (_db.UserRoles.Count(p => p.RoleId == roleId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DeletionIsProhibited);
+ _db.Roles.Remove(_db.Roles.Find(roleId));
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 编辑角色
+ ///
+ /// RoleId,Description,RoleName,RoleCode必传 没有修改传原来的值
+ ///
+ [HttpPost]
+ public ActionResult Edit([FromBody]RoleModel roleModel)
+ {
+ var role = _db.Roles.Find(roleModel.RoleId);
+ role.Description = roleModel.Description;
+ role.RoleName = roleModel.RoleName;
+ role.RoleCode = roleModel.RoleCode;
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+ ///
+ /// 角色列表
+ ///
+ /// 页码
+ /// 数量
+ ///
+ [HttpGet]
+ public ActionResult List(int page, int number)
+ {
+ return ResponseHelper.Success(PageHelper.Pagination(_db.Roles.Select(p=>new
+ {
+ p.Description,
+ p.RoleCode,
+ p.RoleName,
+ p.RoleId
+ }).ToList(),page,number));
+ }
+
+ ///
+ /// 给用户分配角色
+ ///
+ /// 角色Id
+ /// 用户Id
+ ///
+ [HttpGet]
+ public ActionResult Distribute(int roleId, int userId)
+ {
+ if (_db.UserRoles.Count(p => p.RoleId == roleId && p.UserId == userId) > 0)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.DataRepeat);
+ _db.UserRoles.Add(new UserRole()
+ {
+ UserId = userId,
+ RoleId = roleId,
+ });
+ _db.SaveChanges();
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 添加权限, 编辑权限,删除权限
+ ///
+ /// 角色Id,跟权限Id数组
+ ///
+ [HttpPost]
+ public ActionResult Permission([FromBody] PermissionModel permissionModel)
+ {
+ var roleMenus = _db.Rolemenus.Where(p => p.RoleId == permissionModel.RoleId).ToList();
+ _db.Rolemenus.RemoveRange(roleMenus);
+ _db.SaveChanges();
+ foreach (var menId in permissionModel.MenuIdList)
+ {
+ _db.Rolemenus.Add(new Rolemenu() { RoleId = permissionModel.RoleId, MenuId = menId });
+ _db.SaveChanges();
+ }
+ return ResponseHelper.Success();
+ }
+
+ ///
+ /// 获取角色所有权限
+ ///
+ ///
+ ///
+ [HttpGet]
+ public ActionResult PermissionList(int roleId)
+ {
+ var roleMenus = _db.Rolemenus.Where(p => p.RoleId == roleId).Select(q=>q.Menu).ToList();
+ return ResponseHelper.Success(MenuHelper.Serialization(roleMenus));
+ }
+ }
+}
diff --git a/QualityControlPlatform/Controllers/User/UserController.cs b/QualityControlPlatform/Controllers/User/UserController.cs
new file mode 100644
index 0000000..938b284
--- /dev/null
+++ b/QualityControlPlatform/Controllers/User/UserController.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
+using System.Net.Http;
+using System.Security.Claims;
+using System.Text;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.Extensions.Configuration;
+using Microsoft.IdentityModel.Tokens;
+using QualityControlPlatform.Helpers.Cache;
+using QualityControlPlatform.Helpers.Menu;
+using QualityControlPlatform.Helpers.Response;
+using QualityControlPlatform.Helpers.StringText;
+using QualityControlPlatform.Models.ControllerModels;
+using QualityControlPlatform.Models.DbContext;
+using QualityControlPlatform.Models.SmsModel;
+
+namespace QualityControlPlatform.Controllers.User
+{
+ ///
+ /// 用户相关操作控制类
+ ///
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class UserController : ControllerBase
+ {
+
+ private readonly IHttpClientFactory _clientFactory;
+
+ private readonly IMemoryCache _memoryCache;
+ private readonly QualityControlPlatformContext _db = new QualityControlPlatformContext();
+
+
+ ///
+ /// 用户相关
+ ///
+ ///
+ ///
+ public UserController(IHttpClientFactory clientFactory, IMemoryCache memoryCache)
+ {
+ _clientFactory = clientFactory;
+ _memoryCache = memoryCache;
+ }
+
+ private IConfiguration Configuration { get; set; }
+ ///
+ /// 用户登录
+ ///
+ /// 用户代码
+ /// 密码
+ ///
+ [HttpGet]
+ public ActionResult Login(string userCode, string passWord)
+ {
+ var userInfo = _db.Users.FirstOrDefault(p => (p.UserCode == userCode||p.Phone==userCode) && p.Password == passWord);
+ if (userInfo == null)
+ return ResponseHelper.Fail(ResponseHelper.ErrorEnum.UserAndPwError);
+ var userRoles = userInfo.Userroles.Select(x => x.Role).Select(r=>r.Rolemenus).ToList();
+ var menuList = new List