using APT.BaseData.Domain.ApiModel; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.IServices.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.BS; using APT.MS.Domain.Entities.HM; using APT.MS.Domain.Enums; using APT.Utility; using APT.WebApi.Models; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; namespace APT.BS.WebApi.Controllers.Api { [Route("api/BS/BSCheckContents")] public partial class BSCheckContentsController : AuthorizeApiController { IFMUserService UserService { get; set; } public BSCheckContentsController(IFMUserService userService) { UserService = userService; } /// /// 配合检查类型 检查层级 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedObject")] public PagedActionResult OrderPagedLevel([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { PagedActionResult orderPageEntities = null; List listMineType = UserService.GetMineType(); if (listMineType == null || listMineType.Count < 1) { orderPageEntities = GetOrderPageEntities(null, pageFilter, null); } else { List listMineEnums = new List(); try { listMineEnums.Add(BSMineTypeEnum.All); listMineType.ForEach(m => listMineEnums.Add((BSMineTypeEnum)m)); } catch { } orderPageEntities = GetOrderPageEntities(e => listMineEnums.Contains(e.CHECKOBJECT), pageFilter, null); } //BSMineTypeEnum? CHECKOBJECT = null; //if (APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID.HasValue) //{ // var dep = GetEntity(e => e.ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID); // if (dep != null) // { // if (dep.DEPARTMENT_STATUS == 2) // { // CHECKOBJECT = BSMineTypeEnum.All; //安环部门 可以选择所有 // } // else // { // var depObj = GetEntity(e => e.DEPARTMENTID == dep.ID); // if (depObj != null) // { // //对应范围 // CHECKOBJECT = depObj.CHECKOBJECT; // } // else // { // //未设置 所有 // CHECKOBJECT = BSMineTypeEnum.All; // } // } // } //} //if (CHECKOBJECT.Value != BSMineTypeEnum.All) //{ // orderPageEntities = GetOrderPageEntities(e => e.CHECKOBJECT == CHECKOBJECT.Value, pageFilter, null); //} //else //{ // orderPageEntities = GetOrderPageEntities(null, pageFilter, null); //} result.Data = orderPageEntities.Data; result.TotalCount = orderPageEntities.TotalCount; }); } /// /// 获取责任对象 /// /// /// /// public BSPLANCHECKOBJECTEnum GetBSPLANCHECKOBJECTEnum(string strObj, bool? isClass) { BSPLANCHECKOBJECTEnum result = BSPLANCHECKOBJECTEnum.Head; if (string.IsNullOrEmpty(strObj)) { if (isClass.HasValue && isClass.Value) { result = BSPLANCHECKOBJECTEnum.ClassMonitor; } } else { var enumsObjV = Enum.GetValues(); foreach (var item in enumsObjV) { if (item.GetDescription() == strObj) { result = item; } } } return result; } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_BS_CHECK_CONTENT entity) { return SafeExecute(() => { var listQuestions = entity.Nav_ListContentQuestions; var listAreas = entity.Nav_ListContentAreas; var listCheckTypes = entity.Nav_ListContentCheckTypes; this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (listQuestions != null && listQuestions.Any()) BantchSaveEntityNoCommit(listQuestions); if (listAreas != null && listAreas.Any()) BantchSaveEntityNoCommit(listAreas); if (listCheckTypes != null && listCheckTypes.Any()) BantchSaveEntityNoCommit(listCheckTypes); }); return true; }); } /// /// 更新或新增数据 /// /// 对象实体 /// [HttpPost, Route("FullUpdateS")] public JsonActionResult FullUpdateS([FromBody] T_BS_CHECK_CONTENTS entity) { return SafeExecute(() => { if (entity.Nav_ListCheckQuestion == null || !entity.Nav_ListCheckQuestion.Any()) { throw new Exception("检查问题不能为空!"); } var listQuestions = entity.Nav_ListCheckQuestion; entity.Nav_ListCheckQuestion = null; if (!string.IsNullOrEmpty(entity.StrCheckObject)) { List list = entity.StrCheckObject.Split('_', StringSplitOptions.RemoveEmptyEntries).ToList(); for (int i = 0; i < list.Count; i++) { try { entity.CHECKOBJECT = (BSMineTypeEnum)int.Parse(list[i]); if (i > 0) { entity.ID = Guid.NewGuid(); foreach (var item in listQuestions) { item.CHECK_CONTENTS_ID = entity.ID; } } this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (listQuestions != null && listQuestions.Any()) BantchSaveEntityNoCommit(listQuestions); }); } catch { } } } else { this.UnifiedCommit(() => { if (entity != null) UpdateEntityNoCommit(entity); if (listQuestions != null && listQuestions.Any()) BantchSaveEntityNoCommit(listQuestions); }); } return true; }); } /// /// 排序分页查询数据 BS032 /// 如果选的是 检查区域:全公司 CHECKOBJECT 不过滤 /// /// 分页过滤实体 /// [HttpPost, Route("OrderPagedSuitAll")] public PagedActionResult OrderPagedSuitAll([FromBody] KeywordPageFilter pageFilter) { return SafeGetPagedData(delegate (PagedActionResult result) { if (pageFilter.FilterGroup != null && pageFilter.FilterGroup.Rules != null && pageFilter.FilterGroup.Rules.Any()) { foreach (var item in pageFilter.FilterGroup.Rules) { if (item.Field == "CHECKOBJECT" && item.Value != null && item.Value.ToString() == "0") { pageFilter.FilterGroup.Rules.Remove(item); break; } } } PagedActionResult orderPageEntities = GetOrderPageEntities(null, pageFilter, null); result.Data = orderPageEntities.Data; result.TotalCount = orderPageEntities.TotalCount; }); } } }