2、审批角色 添加 是否总部【ISHEAD】属性 ,总部会同步到子公司,子公司不能修改总部传入的数据 3、审批明细 添加【ISHEAD】属性 ,功能暂未处理 4、首页获取待办修改 使不过滤ORGID 5、用户添加时,如果是总公司 同步到子公司,同步修改了一些bug 6、审批页面数据获取方法【FullGet】提供修改前提 后续功能待完善 7、HeadHelper.GetIsHead 判断是否总部 ["Tenant"]"0003"
		
			
				
	
	
		
			302 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			302 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using APT.BaseData.Domain.Entities;
 | 
						||
using APT.BaseData.Domain.Entities.FM;
 | 
						||
using APT.BaseData.Domain.Entities.PF;
 | 
						||
using APT.BaseData.Domain.Enums;
 | 
						||
using APT.BaseData.Domain.IServices.OP;
 | 
						||
using APT.Infrastructure.Core;
 | 
						||
using APT.Migrations;
 | 
						||
using APT.MS.Domain.Entities.BS;
 | 
						||
using APT.MS.Domain.Entities.HM;
 | 
						||
using APT.MS.Domain.Entities.PF;
 | 
						||
using APT.MS.Domain.Entities.SC;
 | 
						||
using APT.MS.Domain.Enums;
 | 
						||
using APT.Utility;
 | 
						||
using Microsoft.AspNetCore.Mvc;
 | 
						||
using System;
 | 
						||
using System.Collections.Generic;
 | 
						||
using System.Linq;
 | 
						||
using System.Transactions;
 | 
						||
 | 
						||
namespace APT.PF.WebApi.Controllers.Api
 | 
						||
{
 | 
						||
    /// <summary>
 | 
						||
    ///  审批角色
 | 
						||
    /// </summary>
 | 
						||
    [Route("api/PF/PFApprovalRole")]
 | 
						||
    public partial class ApprovalRoleController : AuthorizeApiController<T_PF_APPROVAL_ROLE>
 | 
						||
    {
 | 
						||
        IOPTenantDBConnService OPTenantDBConnService { get; set; }
 | 
						||
        public ApprovalRoleController(IOPTenantDBConnService opTenantDBConnService)
 | 
						||
        {
 | 
						||
            OPTenantDBConnService = opTenantDBConnService;
 | 
						||
        }
 | 
						||
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 更新或新增数据
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="entity">对象实体</param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("FullUpdate")]
 | 
						||
        public JsonActionResult<bool> FullUpdate([FromBody] T_PF_APPROVAL_ROLE entity)
 | 
						||
        {
 | 
						||
            return SafeExecute<bool>(() =>
 | 
						||
          {
 | 
						||
              var isHead = HeadHelper.GetIsHead(this.Request.Headers);
 | 
						||
              if (entity.ISHEAD && !isHead)
 | 
						||
              {
 | 
						||
                  throw new Exception("子公司不能修改总公司角色信息!");
 | 
						||
              }
 | 
						||
 | 
						||
              var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
 | 
						||
              //var roleCodes = this.GetEntities<T_PF_APPROVAL_ROLE>(t => true, new BaseFilter(orgId)).Select(x => x.NAME).ToList();
 | 
						||
              //if (roleCodes.Contains(entity.NAME))
 | 
						||
              //    throw new Exception("系统已存在审批角色编码为" + entity.NAME + "的数据,请勿重复!");
 | 
						||
              var departs = entity.Nav_ApproveDeparts;
 | 
						||
              entity.Nav_ApproveDeparts = null;
 | 
						||
              if (departs != null && departs.Any())
 | 
						||
              {
 | 
						||
                  departs = departs.Where(t => !t.IS_DELETED).ToList();
 | 
						||
              }
 | 
						||
              if (departs != null && departs.Any())
 | 
						||
              {
 | 
						||
                  departs.ForEach(t =>
 | 
						||
                  {
 | 
						||
                      t.ORG_ID = orgId;
 | 
						||
                      t.APPROVAL_ROLE_ID = entity.ID;
 | 
						||
                      t.Nav_Department = null;
 | 
						||
                  });
 | 
						||
              }
 | 
						||
              List<T_PF_APPROVE_OPERATION_ROLE> listRoles = new List<T_PF_APPROVE_OPERATION_ROLE>();
 | 
						||
              var roles = entity.Nav_ApproveRoles;
 | 
						||
              entity.Nav_ApproveRoles = null;
 | 
						||
              if (roles == null)
 | 
						||
              {
 | 
						||
                  var approveRole = this.GetEntity<T_FM_ROLE>(t => t.ENABLE_STATUS == 0 && t.NAME.Contains("负责人"));
 | 
						||
                  if (approveRole != null)
 | 
						||
                  {
 | 
						||
                      var role = new T_PF_APPROVE_OPERATION_ROLE();
 | 
						||
                      role.ORG_ID = orgId;
 | 
						||
                      role.APPROVAL_ROLE_ID = entity.ID;
 | 
						||
                      role.ROLE_ID = approveRole.ID;
 | 
						||
                      listRoles.Add(role);
 | 
						||
                  }
 | 
						||
              }
 | 
						||
              List<Guid> deleteIds = new List<Guid>();
 | 
						||
              if (entity.ROLE_ID != null)
 | 
						||
              {
 | 
						||
                  var datas = this.GetEntities<T_PF_APPROVE_OPERATION_ROLE>(t => t.APPROVAL_ROLE_ID == entity.ID, new BaseFilter(orgId));
 | 
						||
                  if (datas.Any())
 | 
						||
                  {
 | 
						||
                      var ids = datas.Select(t => t.ID).ToList();
 | 
						||
                      deleteIds.AddRange(ids);
 | 
						||
                  }
 | 
						||
                  var role = new T_PF_APPROVE_OPERATION_ROLE();
 | 
						||
                  role.ORG_ID = orgId;
 | 
						||
                  role.APPROVAL_ROLE_ID = entity.ID;
 | 
						||
                  role.ROLE_ID = entity.ROLE_ID;
 | 
						||
                  listRoles.Add(role);
 | 
						||
              }
 | 
						||
              if (listRoles.Any())
 | 
						||
              {
 | 
						||
                  listRoles = listRoles.Distinct(t => t.ROLE_ID).ToList();
 | 
						||
              }
 | 
						||
              Dictionary<Guid, string> dicConn = null;
 | 
						||
              if (isHead)
 | 
						||
              {
 | 
						||
                  dicConn = OPTenantDBConnService.GetConnDictionary(entity.ORG_ID);
 | 
						||
                  if (dicConn == null)
 | 
						||
                  {
 | 
						||
                      throw new Exception("获取子公司链接失败,请关闭页面刷新后再试");
 | 
						||
                  }
 | 
						||
              }
 | 
						||
              UnifiedCommit(() =>
 | 
						||
              {
 | 
						||
                  if (entity != null)
 | 
						||
                      UpdateEntityNoCommit(entity);   //保存主表
 | 
						||
                  if (departs != null && departs.Any())
 | 
						||
                      BantchSaveEntityNoCommit(departs);    //保存子表
 | 
						||
                  if (listRoles != null && listRoles.Any())
 | 
						||
                      BantchSaveEntityNoCommit(listRoles);    //保存子表
 | 
						||
                  if (deleteIds != null && deleteIds.Any())
 | 
						||
                      BantchDeleteEntityNoCommit<T_PF_APPROVE_OPERATION_ROLE>(deleteIds);    //保存子表
 | 
						||
              });
 | 
						||
 | 
						||
              //如果是总部 同时同步到各个子公司
 | 
						||
              if (isHead)
 | 
						||
              {
 | 
						||
                  entity.ISHEAD = true;
 | 
						||
                  entity.ROLE_ID = null;
 | 
						||
                  entity.Nav_Role = null;
 | 
						||
                  entity.Nav_ApproveRoles = null;
 | 
						||
                  int EditC = 0;
 | 
						||
                  //using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
 | 
						||
                  //{
 | 
						||
                  //    try
 | 
						||
                  //    {
 | 
						||
                  foreach (var item in dicConn)
 | 
						||
                  {
 | 
						||
                      try
 | 
						||
                      {
 | 
						||
                          entity.ORG_ID = item.Key;
 | 
						||
                          using (var context = new MigrationContext(item.Value))
 | 
						||
                          {
 | 
						||
                              EditC = context.GetCount<T_PF_APPROVAL_ROLE>(e => e.ID == entity.ID);
 | 
						||
                              if (EditC > 0)
 | 
						||
                              {
 | 
						||
                                  context.UpdateEntity(entity);
 | 
						||
                                  context.SaveChanges();
 | 
						||
                                  //context.SaveChangesAsync();
 | 
						||
                              }
 | 
						||
                              else
 | 
						||
                              {
 | 
						||
                                  context.AddEntity(entity);
 | 
						||
                                  context.SaveChanges();
 | 
						||
                                  //context.AddAsync(entity);
 | 
						||
                                  //context.SaveChangesAsync();
 | 
						||
                              }
 | 
						||
                          }
 | 
						||
                      }
 | 
						||
                      catch (Exception ex)
 | 
						||
                      {
 | 
						||
 | 
						||
                      }
 | 
						||
                  }
 | 
						||
                  //        //// 所有操作成功,提交事务
 | 
						||
                  //        scope.Complete();
 | 
						||
                  //    }
 | 
						||
                  //    catch (Exception ex)
 | 
						||
                  //    {
 | 
						||
                  //        // 发生异常,自动回滚(无需手动调用,scope 释放时未 Complete 则回滚)
 | 
						||
                  //        throw;
 | 
						||
                  //    }
 | 
						||
                  //}
 | 
						||
              }
 | 
						||
              return true;
 | 
						||
          });
 | 
						||
        }
 | 
						||
        /// <summary>
 | 
						||
        /// 批量添加节点
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="keywordFilter">参数</param>
 | 
						||
        /// <returns></returns>
 | 
						||
        [HttpPost, Route("AddApproveRoles")]
 | 
						||
        public JsonActionResult<bool> AddApproveRoles([FromBody] KeywordFilter keywordFilter)
 | 
						||
        {
 | 
						||
            return base.SafeExecute(() =>
 | 
						||
            {
 | 
						||
                if (string.IsNullOrEmpty(keywordFilter.Parameter1))
 | 
						||
                    throw new Exception("当前节点未选择!");
 | 
						||
                if (string.IsNullOrEmpty(keywordFilter.Parameter2) && string.IsNullOrEmpty(keywordFilter.Parameter3))
 | 
						||
                    throw new Exception("上一节点和下一节点至少选择一个");
 | 
						||
                List<T_PF_APPROVE_TEMP_DETAIL> detailNews = new List<T_PF_APPROVE_TEMP_DETAIL>();
 | 
						||
                Guid newID = new Guid(keywordFilter.Parameter1);
 | 
						||
                var approveDetailTemps = this.GetEntities<T_PF_APPROVE_TEMP_DETAIL>(t => !t.IS_DELETED, new BaseFilter(keywordFilter.OrgId));
 | 
						||
                var approveIds = approveDetailTemps.Select(t => t.APPROVE_ID).Distinct().ToList();
 | 
						||
                Guid? preID = null;
 | 
						||
                var approvalRole = this.GetEntity<T_PF_APPROVAL_ROLE>(t => t.ID == newID);
 | 
						||
                if (!string.IsNullOrEmpty(keywordFilter.Parameter2))
 | 
						||
                {
 | 
						||
                    preID = new Guid(keywordFilter.Parameter2);
 | 
						||
                    if (newID == preID)
 | 
						||
                    {
 | 
						||
                        throw new Exception("当前节点和上一节点不能相同");
 | 
						||
                    }
 | 
						||
                }
 | 
						||
                Guid? nextID = null;
 | 
						||
                if (!string.IsNullOrEmpty(keywordFilter.Parameter3))
 | 
						||
                {
 | 
						||
                    nextID = new Guid(keywordFilter.Parameter3);
 | 
						||
                    if (newID == preID)
 | 
						||
                    {
 | 
						||
                        throw new Exception("当前节点和下一节点不能相同");
 | 
						||
                    }
 | 
						||
                }
 | 
						||
                if (preID != null && nextID != null && preID == nextID)
 | 
						||
                {
 | 
						||
                    throw new Exception("上一节点和下一节点不能相同");
 | 
						||
                }
 | 
						||
                if (approveIds != null && approveIds.Any())
 | 
						||
                {
 | 
						||
                    foreach (var item in approveIds)
 | 
						||
                    {
 | 
						||
                        var temps = approveDetailTemps.Where(t => t.APPROVE_ID == item).OrderBy(m => m.NUM).ToList();
 | 
						||
                        if (temps.Any())
 | 
						||
                        {
 | 
						||
                            var isExiest = temps.FirstOrDefault(t => t.APPROVE_ROLE_ID == newID);
 | 
						||
                            if (isExiest == null)
 | 
						||
                            {
 | 
						||
                                if (preID != null && nextID != null)
 | 
						||
                                {
 | 
						||
                                    var pre = temps.FirstOrDefault(t => t.APPROVE_ROLE_ID == preID);
 | 
						||
                                    var next = temps.FirstOrDefault(t => t.APPROVE_ROLE_ID == nextID);
 | 
						||
                                    if (pre != null && next != null)
 | 
						||
                                    {
 | 
						||
                                        var nextTemp = temps.Where(m => m.NUM > pre.NUM).OrderBy(t => t.NUM).FirstOrDefault();
 | 
						||
                                        if (next.NUM == nextTemp.NUM)
 | 
						||
                                        {
 | 
						||
                                            T_PF_APPROVE_TEMP_DETAIL detailNew = new T_PF_APPROVE_TEMP_DETAIL();
 | 
						||
                                            detailNew.ID = Guid.NewGuid();
 | 
						||
                                            detailNew.ORG_ID = keywordFilter.OrgId;
 | 
						||
                                            detailNew.APPROVE_ID = item;
 | 
						||
                                            detailNew.APPROVE_ROLE_ID = newID;
 | 
						||
                                            detailNew.NUM = next.NUM;
 | 
						||
                                            detailNew.DEPARTMENT_TYPE = approvalRole.DEPARTMENT_TYPE;
 | 
						||
                                            detailNew.NAME = approvalRole.NAME;
 | 
						||
                                            temps.Add(detailNew);
 | 
						||
                                            temps.Where(t => t.NUM >= detailNew.NUM && t.APPROVE_ROLE_ID != newID).ForEach(m => { m.NUM = m.NUM + 1; });
 | 
						||
                                            detailNews.AddRange(temps);
 | 
						||
                                        }
 | 
						||
                                    }
 | 
						||
                                }
 | 
						||
                                else if (preID != null && nextID == null)
 | 
						||
                                {
 | 
						||
                                    var pre = temps.FirstOrDefault(t => t.APPROVE_ROLE_ID == preID);
 | 
						||
                                    if (pre != null)
 | 
						||
                                    {
 | 
						||
                                        T_PF_APPROVE_TEMP_DETAIL detailNew = new T_PF_APPROVE_TEMP_DETAIL();
 | 
						||
                                        detailNew.ID = Guid.NewGuid();
 | 
						||
                                        detailNew.ORG_ID = keywordFilter.OrgId;
 | 
						||
                                        detailNew.APPROVE_ID = item;
 | 
						||
                                        detailNew.APPROVE_ROLE_ID = newID;
 | 
						||
                                        detailNew.NUM = pre.NUM + 1;
 | 
						||
                                        detailNew.DEPARTMENT_TYPE = approvalRole.DEPARTMENT_TYPE;
 | 
						||
                                        detailNew.NAME = approvalRole.NAME;
 | 
						||
                                        temps.Add(detailNew);
 | 
						||
                                        temps.Where(t => t.NUM >= detailNew.NUM && t.APPROVE_ROLE_ID != newID).ForEach(m => { m.NUM = m.NUM + 1; });
 | 
						||
                                        detailNews.AddRange(temps);
 | 
						||
                                    }
 | 
						||
                                }
 | 
						||
                                else if (preID == null && nextID != null)
 | 
						||
                                {
 | 
						||
                                    var next = temps.FirstOrDefault(t => t.APPROVE_ROLE_ID == nextID);
 | 
						||
                                    if (next != null)
 | 
						||
                                    {
 | 
						||
                                        T_PF_APPROVE_TEMP_DETAIL detailNew = new T_PF_APPROVE_TEMP_DETAIL();
 | 
						||
                                        detailNew.ID = Guid.NewGuid();
 | 
						||
                                        detailNew.ORG_ID = keywordFilter.OrgId;
 | 
						||
                                        detailNew.APPROVE_ID = item;
 | 
						||
                                        detailNew.APPROVE_ROLE_ID = newID;
 | 
						||
                                        detailNew.NUM = next.NUM;
 | 
						||
                                        detailNew.DEPARTMENT_TYPE = approvalRole.DEPARTMENT_TYPE;
 | 
						||
                                        detailNew.NAME = approvalRole.NAME;
 | 
						||
                                        temps.Add(detailNew);
 | 
						||
                                        temps.Where(t => t.NUM >= detailNew.NUM && t.APPROVE_ROLE_ID != newID).ForEach(m => { m.NUM = m.NUM + 1; });
 | 
						||
                                        detailNews.AddRange(temps);
 | 
						||
                                    }
 | 
						||
                                }
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                }
 | 
						||
                UnifiedCommit(() =>
 | 
						||
                {
 | 
						||
                    if (detailNews != null && detailNews.Any())
 | 
						||
                        this.BantchSaveEntityNoCommit(detailNews);
 | 
						||
                });
 | 
						||
                return true;
 | 
						||
            });
 | 
						||
        }
 | 
						||
    }
 | 
						||
}
 |