148 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using APT.BaseData.Domain.Entities;
 | 
						|
using APT.BaseData.Domain.Entities.FM;
 | 
						|
using APT.BaseData.Domain.Enums;
 | 
						|
using APT.BaseData.Domain.IServices;
 | 
						|
using APT.BaseData.Domain.IServices.FM;
 | 
						|
using APT.BaseData.Services.Services.FM;
 | 
						|
using APT.Infrastructure.Core;
 | 
						|
using APT.MS.Domain.Entities.BS;
 | 
						|
using APT.MS.Domain.Entities.DM;
 | 
						|
using APT.MS.Domain.Entities.HM;
 | 
						|
using APT.MS.Domain.Entities.LR;
 | 
						|
using APT.MS.Domain.Entities.SC.BI;
 | 
						|
using APT.MS.Domain.Enums;
 | 
						|
using APT.Utility;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using Microsoft.Extensions.Logging;
 | 
						|
using NPOI.SS.Formula.Functions;
 | 
						|
using System;
 | 
						|
using System.Collections;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Linq.Expressions;
 | 
						|
 | 
						|
namespace APT.HM.WebApi.Controllers.Api
 | 
						|
{
 | 
						|
    [Route("api/HM/HMRiskArea")]
 | 
						|
    public partial class RiskAreaController : AuthorizeTreeApiController<T_HM_RISK_AREA>
 | 
						|
    {
 | 
						|
        /// 排序分页查询数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="pageFilter">分页过滤实体</param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("OrderPagedArea")]
 | 
						|
        public PagedActionResult<T_HM_RISK_AREA> OrderPagedArea([FromBody] KeywordPageFilter pageFilter)
 | 
						|
        {
 | 
						|
            Expression<Func<T_HM_RISK_AREA, bool>> uExpress = t => t.IS_DELETED == false;
 | 
						|
            if (pageFilter.Keyword != "")
 | 
						|
            {
 | 
						|
                List<Guid> ids = new List<Guid>();
 | 
						|
                var tempids = pageFilter.Keyword.Split(",");
 | 
						|
                foreach (var id in tempids)
 | 
						|
                {
 | 
						|
                    ids.Add(Guid.Parse(id));
 | 
						|
                }
 | 
						|
                uExpress = uExpress.And(t => ids.Contains(t.ID));
 | 
						|
            }
 | 
						|
 | 
						|
            return WitOrderPaged(uExpress, pageFilter);
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 更新
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="entity"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("FullUpdate")]
 | 
						|
        public JsonActionResult<bool> FullUpdate([FromBody] T_HM_RISK_AREA entity)
 | 
						|
        {
 | 
						|
            return SafeExecute<bool>(() =>
 | 
						|
            {
 | 
						|
                var area = this.GetEntity<T_BI_AREA_TREE>(t => t.CODE == entity.CODE && t.NAME == entity.NAME);
 | 
						|
                if (area == null)
 | 
						|
                {
 | 
						|
                    area = new T_BI_AREA_TREE();
 | 
						|
                    area.ID = entity.ID;
 | 
						|
                    area.ORG_ID = entity.ORG_ID;
 | 
						|
                    area.DEPARTMENT_ID = entity.DEPARTMENT_ID;
 | 
						|
                    area.CODE = entity.CODE;
 | 
						|
                    area.NAME = entity.NAME;
 | 
						|
                    area.LEVEL = entity.LEVEL;
 | 
						|
                    area.NUM = this.GetCount<T_BI_AREA_TREE>(null, new BaseFilter(entity.ORG_ID)) + 1;
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    area.DEPARTMENT_ID = entity.DEPARTMENT_ID;
 | 
						|
                    area.CODE = entity.CODE;
 | 
						|
                    area.NAME = entity.NAME;
 | 
						|
                    area.LEVEL = entity.LEVEL;
 | 
						|
                }
 | 
						|
                this.UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (entity != null)
 | 
						|
                        UpdateEntityNoCommit(entity);
 | 
						|
                    if (area != null)
 | 
						|
                        UpdateEntityNoCommit(area);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="filter"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("GetAll")]
 | 
						|
        public JsonActionResult<T_HM_RISK_AREA> GetAll([FromBody] KeywordFilter filter)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                T_HM_RISK_AREA main = new T_HM_RISK_AREA();
 | 
						|
                var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
 | 
						|
                if (string.IsNullOrEmpty(id))
 | 
						|
                    throw new Exception("未选中区域");
 | 
						|
                var entity = this.GetEntity<T_HM_RISK_AREA>(id, "Nav_Department");
 | 
						|
                if (entity != null)
 | 
						|
                {
 | 
						|
                    if (entity.DEPARTMENT_ID != null)
 | 
						|
                    {
 | 
						|
                        var users = this.GetEntities<T_FM_USER>(t => t.DEPARTMENT_ID == entity.DEPARTMENT_ID, new BaseFilter(entity.ORG_ID), "Nav_Department", "Nav_Person", "Nav_Person.Nav_Post");
 | 
						|
                        if (users != null && users.Any())
 | 
						|
                        {
 | 
						|
                            entity.Nav_User = users.ToList();
 | 
						|
                        }
 | 
						|
                        var postIds = users.Where(m => m.Nav_Person != null).Select(t => t.Nav_Person.POST_ID).ToList();
 | 
						|
                        var posts = this.GetEntities<T_FM_USER_POST>(t => postIds.Contains(t.ID), new BaseFilter(entity.ORG_ID));
 | 
						|
                        if (posts != null && posts.Any())
 | 
						|
                        {
 | 
						|
                            entity.Nav_Post = posts.ToList();
 | 
						|
                        }
 | 
						|
                        var devices = this.GetEntities<T_DM_DEVICE_BASE>(t => t.DEPARTMENT_ID == entity.DEPARTMENT_ID && postIds.Contains(t.USER_POST_ID), new BaseFilter(entity.ORG_ID));
 | 
						|
                        if (devices != null && devices.Any())
 | 
						|
                        {
 | 
						|
                            entity.Nav_Device = devices.ToList();
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    var risks = this.GetEntities<T_HM_EVALUATE_RISK>(t => t.AREA_ID == entity.ID, new BaseFilter(entity.ORG_ID));
 | 
						|
                    if (risks != null && risks.Any())
 | 
						|
                    {
 | 
						|
                        entity.Nav_Risk = risks.ToList();
 | 
						|
                    }
 | 
						|
                    var submits = this.GetEntities<T_BS_RISK_SUBMIT_CONTENT>(t => t.RISK_AREA_ID == entity.ID, new BaseFilter(entity.ORG_ID));
 | 
						|
                    if (submits != null && submits.Any())
 | 
						|
                    {
 | 
						|
                        entity.Nav_Submit = submits.ToList();
 | 
						|
                    }
 | 
						|
                    var checkAeas = this.GetEntities<T_BS_SAFE_CHECK_RISK_AREA>(t => t.RISK_AREA_ID == entity.ID, new BaseFilter(entity.ORG_ID));
 | 
						|
                    var checkIds = checkAeas.Select(t => t.SAFE_CHECK_ID).Distinct().ToList();
 | 
						|
                    var checks = this.GetEntities<T_BS_SAFE_CHECK>(t => checkIds.Contains(t.ID), new BaseFilter(entity.ORG_ID));
 | 
						|
                    if (checks != null && checks.Any())
 | 
						|
                    {
 | 
						|
                        entity.Nav_Check = checks.ToList();
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                return entity;
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |