1640 lines
77 KiB
C#
1640 lines
77 KiB
C#
using APT.BaseData.Domain.ApiModel;
|
||
using APT.BaseData.Domain.ApiModel.PF;
|
||
using APT.BaseData.Domain.Entities;
|
||
using APT.BaseData.Domain.Entities.FM;
|
||
using APT.BaseData.Domain.Entities.OP;
|
||
using APT.BaseData.Domain.Enums;
|
||
using APT.BaseData.Domain.Enums.OP;
|
||
using APT.BaseData.Domain.IServices;
|
||
using APT.BaseData.Domain.IServices.FM;
|
||
using APT.Infrastructure.Api;
|
||
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.Enums;
|
||
using APT.Utility;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Security.Cryptography;
|
||
|
||
namespace APT.BS.WebApi.Controllers.Api
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
[Route("api/FM/FMUser")]
|
||
public partial class FMUserController : AuthorizeApiController<T_FM_USER>
|
||
{
|
||
|
||
IFMUserService UserService { get; set; }
|
||
|
||
public FMUserController(IFMUserService userService)
|
||
{
|
||
UserService = userService;
|
||
}
|
||
/// <summary>
|
||
/// 正常使用的用户
|
||
/// 重写 api/FM/User/OrderPaged
|
||
/// 目前最多只支持4个生产单元有重叠的
|
||
/// </summary>
|
||
/// <param name="pageFilter"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPagedUseful")]
|
||
public PagedActionResult<T_FM_USER> OrderPagedUseful([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
if (string.IsNullOrEmpty(pageFilter.Parameter1))
|
||
{
|
||
List<int> listMineType = new List<int>();
|
||
Guid DEPARTMENT_ID_WORKSHOP = Guid.Empty;
|
||
Guid DEPARTMENT_ID = Guid.Empty;
|
||
bool isMintype = false;//是否 区分生产单元
|
||
string MineType = string.Empty;
|
||
if (pageFilter.FilterGroup.Rules.Count == 2)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Rules)
|
||
{
|
||
if (item.Field == "DEPARTMENT_ID_WORKSHOP")
|
||
{
|
||
DEPARTMENT_ID_WORKSHOP = new Guid(item.Value.ToString());
|
||
}
|
||
else if (item.Field == "DEPARTMENT_ID")
|
||
{
|
||
DEPARTMENT_ID = new Guid(item.Value.ToString());
|
||
}
|
||
}
|
||
}
|
||
else if (pageFilter.FilterGroup.Rules.Count == 1)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Rules)
|
||
{
|
||
if (item.Field == "MineType")
|
||
{
|
||
isMintype = true;
|
||
MineType = item.Value.ToString();
|
||
pageFilter.FilterGroup.Rules.Clear();
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(MineType))
|
||
{
|
||
listMineType = UserService.GetMineType(MineType);
|
||
}
|
||
}
|
||
if (pageFilter.FilterGroup.Groups != null && pageFilter.FilterGroup.Groups.Any())
|
||
{
|
||
var groups = pageFilter.FilterGroup.Groups.ToList();
|
||
if (groups[0].Rules != null && groups[0].Rules.Any())
|
||
{
|
||
FilterRule ruleType = null;
|
||
foreach (var rule in groups[0].Rules)
|
||
{
|
||
if (rule.Field == "MineType")
|
||
{
|
||
ruleType = rule;
|
||
MineType = rule.Value.ToString();
|
||
isMintype = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(MineType))
|
||
{
|
||
listMineType = UserService.GetMineType(MineType);
|
||
if (ruleType != null)
|
||
{
|
||
groups[0].Rules.Remove(ruleType);
|
||
pageFilter.FilterGroup.Groups = groups;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
var LoginDepID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
||
T_FM_DEPARTMENT dep = null;
|
||
if (LoginDepID.HasValue)
|
||
{
|
||
dep = GetEntity<T_FM_DEPARTMENT>(LoginDepID.Value);
|
||
}
|
||
if (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && LoginDepID.HasValue && dep != null && (dep.DEPARTMENT_TYPE == 1 || dep.DEPARTMENT_TYPE == 2))
|
||
{
|
||
//班组或者车间 向下取值 否则取全部
|
||
//FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3
|
||
if (dep.DEPARTMENT_TYPE == 2)
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
var listDepID = GetEntities<T_FM_DEPARTMENT>(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == LoginDepID.Value, null).Select(e => e.ID);
|
||
if (listDepID != null && listDepID.Any())
|
||
{
|
||
var ListDepID = listDepID.ToList();
|
||
ListDepID.Add(LoginDepID.Value);
|
||
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && ListDepID.Contains(e.DEPARTMENT_ID.Value) && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
}
|
||
else if (isMintype)
|
||
{
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
Expression<Func<T_FM_USER, bool>> expression = e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && !e.CODE.StartsWith("admin");// && e.CODE != "admin";
|
||
//linq 运行不通过 修改为查找后内存中过滤
|
||
//expression = expression.And(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => listMineType.Contains(x.Nav_Enums.VALUE)) != null));
|
||
//PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(expression, pageFilter, "Nav_ProdutionUnit.Nav_Enums");
|
||
//result.Data = orderPageEntities.Data;
|
||
//result.TotalCount = orderPageEntities.TotalCount;
|
||
|
||
//var resultListUser = GetEntities<T_FM_USER>(expression, pageFilter, "Nav_ProdutionUnit.Nav_Enums");//这样不行
|
||
pageFilter.SelectField.Add("Nav_ProdutionUnit.Nav_Enums");
|
||
if (pageFilter.SelectField.Count() == 1)
|
||
{
|
||
pageFilter.SelectField.Add("ID");
|
||
pageFilter.SelectField.Add("NAME");
|
||
pageFilter.SelectField.Add("CODE");
|
||
}
|
||
var resultListUser = GetEntities<T_FM_USER>(expression, pageFilter);
|
||
|
||
if (resultListUser != null && resultListUser.Any())
|
||
{
|
||
IEnumerable<T_FM_USER> resultListUserFilter = null;
|
||
if (listMineType.Count > 0)
|
||
{
|
||
//if (listMineType.Count == 1)
|
||
//{
|
||
// resultListUserFilter = resultListUser.Where(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => x.Nav_Enums != null && listMineType[0] == x.Nav_Enums.VALUE).Any()));// != null
|
||
//}
|
||
//else
|
||
//{
|
||
resultListUserFilter = resultListUser.Where(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => x.Nav_Enums != null && listMineType.Contains(x.Nav_Enums.VALUE)) != null));
|
||
//}
|
||
}
|
||
|
||
if (resultListUserFilter != null && resultListUserFilter.Any())
|
||
{
|
||
result.Data = resultListUserFilter.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit);
|
||
result.TotalCount = resultListUserFilter.Count();
|
||
}
|
||
}
|
||
|
||
if (result.Data == null || !result.Data.Any())
|
||
{
|
||
result.Data = new List<T_FM_USER>();
|
||
result.TotalCount = 0;
|
||
}
|
||
});
|
||
}
|
||
else if (DEPARTMENT_ID_WORKSHOP != Guid.Empty && DEPARTMENT_ID != Guid.Empty)
|
||
{
|
||
pageFilter.FilterGroup.Rules.Clear();
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.CODE != "admin" && e.DEPARTMENT_ID == DEPARTMENT_ID_WORKSHOP || (e.Nav_Department.PARENT_ID.HasValue && e.Nav_Department.PARENT_ID == DEPARTMENT_ID_WORKSHOP), pageFilter, new string[] { "Nav_Department" });
|
||
result.Data = orderPageEntities.Data;
|
||
result.TotalCount = orderPageEntities.TotalCount;
|
||
});
|
||
}
|
||
else
|
||
{
|
||
if (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && LoginDepID.HasValue)
|
||
{
|
||
//班组或者车间 向下取值 否则取全部
|
||
dep = GetEntity<T_FM_DEPARTMENT>(LoginDepID.Value);
|
||
if (dep != null && (dep.DEPARTMENT_TYPE == 1 || dep.DEPARTMENT_TYPE == 2))
|
||
{
|
||
//FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3
|
||
if (dep.DEPARTMENT_TYPE == 2)
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
var listDepID = GetEntities<T_FM_DEPARTMENT>(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == LoginDepID.Value, null).Select(e => e.ID);
|
||
if (listDepID != null && listDepID.Any())
|
||
{
|
||
var ListDepID = listDepID.ToList();
|
||
ListDepID.Add(LoginDepID.Value);
|
||
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && ListDepID.Contains(e.DEPARTMENT_ID.Value) && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && !e.PROJECT_ID.HasValue && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
|
||
#region 旧
|
||
//List<string> listMineType = new List<string>();
|
||
//List<string> listMineTypeTemp = new List<string>();
|
||
//Guid DEPARTMENT_ID_WORKSHOP = Guid.Empty;
|
||
//Guid DEPARTMENT_ID = Guid.Empty;
|
||
//if (pageFilter.FilterGroup.Rules.Count == 2)
|
||
//{
|
||
// foreach (var item in pageFilter.FilterGroup.Rules)
|
||
// {
|
||
// if (item.Field == "DEPARTMENT_ID_WORKSHOP")
|
||
// {
|
||
// DEPARTMENT_ID_WORKSHOP = new Guid(item.Value.ToString());
|
||
// }
|
||
// else if (item.Field == "DEPARTMENT_ID")
|
||
// {
|
||
// DEPARTMENT_ID = new Guid(item.Value.ToString());
|
||
// }
|
||
// }
|
||
//}
|
||
//if (pageFilter.FilterGroup.Groups != null && pageFilter.FilterGroup.Groups.Any())
|
||
//{
|
||
// var groups = pageFilter.FilterGroup.Groups.ToList();
|
||
// string MineType = string.Empty;
|
||
// if (groups[0].Rules != null && groups[0].Rules.Any())
|
||
// {
|
||
// FilterRule ruleType = null;
|
||
// foreach (var rule in groups[0].Rules)
|
||
// {
|
||
// if (rule.Field == "MineType")
|
||
// {
|
||
// ruleType = rule;
|
||
// MineType = rule.Value.ToString();
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
|
||
// if (!string.IsNullOrEmpty(MineType))
|
||
// {
|
||
// if (ruleType != null)
|
||
// {
|
||
// groups[0].Rules.Remove(ruleType);
|
||
// pageFilter.FilterGroup.Groups = groups;
|
||
// }
|
||
// if (MineType.IndexOf(",") > -1)
|
||
// {
|
||
// listMineTypeTemp = MineType.Split(',', StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
|
||
// listMineType.AddRange(listMineTypeTemp);
|
||
// }
|
||
|
||
// string strTemp = string.Empty;
|
||
// if (!listMineType.Contains(MineType))
|
||
// {
|
||
// listMineType.Add(MineType);
|
||
// if (listMineTypeTemp.Count > 2)//多个生产单元
|
||
// {
|
||
// for (int i = 0; i < listMineTypeTemp.Count; i++)
|
||
// {
|
||
// for (int j = 0; j < listMineTypeTemp.Count; j++)
|
||
// {
|
||
// strTemp = listMineTypeTemp[i] + "," + listMineTypeTemp[j];
|
||
// if (!listMineType.Contains(strTemp))
|
||
// {
|
||
// listMineType.Add(strTemp);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// if (listMineTypeTemp.Count > 3)
|
||
// {
|
||
// for (int i = 0; i < listMineTypeTemp.Count; i++)
|
||
// {
|
||
// for (int j = 0; j < listMineTypeTemp.Count; j++)
|
||
// {
|
||
// for (int k = 0; k < listMineTypeTemp.Count; k++)
|
||
// {
|
||
// strTemp = listMineTypeTemp[i] + "," + listMineTypeTemp[j] + "," + listMineTypeTemp[k];
|
||
// if (!listMineType.Contains(strTemp))
|
||
// {
|
||
// listMineType.Add(strTemp);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
//if (listMineType.Count > 0)
|
||
//{
|
||
// return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
// {
|
||
// Expression<Func<T_FM_USER, bool>> expression = e => e.ENABLE_STATUS == 0 && e.CODE != "admin";
|
||
// if (listMineType.Count == 1)
|
||
// {
|
||
// if (!string.IsNullOrEmpty(listMineType[0]))
|
||
// {
|
||
// expression = expression.And(e => e.MineType != null && e.MineType.Contains(listMineType[0]));
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// expression = expression.And(e => e.MineType != null && listMineType.Contains(e.MineType));
|
||
// }
|
||
// PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(expression, pageFilter, null);
|
||
// result.Data = orderPageEntities.Data;
|
||
// result.TotalCount = orderPageEntities.TotalCount;
|
||
// });
|
||
//}
|
||
//else if (DEPARTMENT_ID_WORKSHOP != Guid.Empty && DEPARTMENT_ID != Guid.Empty)
|
||
//{
|
||
// pageFilter.FilterGroup.Rules.Clear();
|
||
// return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
// {
|
||
// PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(e => e.ENABLE_STATUS == 0 && e.CODE != "admin" && e.DEPARTMENT_ID == DEPARTMENT_ID_WORKSHOP || (e.Nav_Department.PARENT_ID.HasValue && e.Nav_Department.PARENT_ID == DEPARTMENT_ID_WORKSHOP), pageFilter, new string[] { "Nav_Department" });
|
||
// result.Data = orderPageEntities.Data;
|
||
// result.TotalCount = orderPageEntities.TotalCount;
|
||
// });
|
||
//}
|
||
//else
|
||
//{
|
||
// return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.CODE != "admin", pageFilter);
|
||
//}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(t => !t.PROJECT_ID.HasValue && t.Nav_BelongRoles.Any(i => i.Nav_BelongRole.NAME.Contains(pageFilter.Parameter1)), pageFilter);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 正常使用的用户 包含外包
|
||
/// </summary>
|
||
/// <param name="pageFilter"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPagedUsefulAll")]
|
||
public PagedActionResult<T_FM_USER> OrderPagedUsefulAll([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
if (string.IsNullOrEmpty(pageFilter.Parameter1))
|
||
{
|
||
List<int> listMineType = new List<int>();
|
||
Guid DEPARTMENT_ID_WORKSHOP = Guid.Empty;
|
||
Guid DEPARTMENT_ID = Guid.Empty;
|
||
bool isMintype = false;//是否 区分生产单元
|
||
string MineType = string.Empty;
|
||
if (pageFilter.FilterGroup.Rules.Count == 2)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Rules)
|
||
{
|
||
if (item.Field == "DEPARTMENT_ID_WORKSHOP")
|
||
{
|
||
DEPARTMENT_ID_WORKSHOP = new Guid(item.Value.ToString());
|
||
}
|
||
else if (item.Field == "DEPARTMENT_ID")
|
||
{
|
||
DEPARTMENT_ID = new Guid(item.Value.ToString());
|
||
}
|
||
}
|
||
}
|
||
else if (pageFilter.FilterGroup.Rules.Count == 1)
|
||
{
|
||
foreach (var item in pageFilter.FilterGroup.Rules)
|
||
{
|
||
if (item.Field == "MineType")
|
||
{
|
||
isMintype = true;
|
||
MineType = item.Value.ToString();
|
||
pageFilter.FilterGroup.Rules.Clear();
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(MineType))
|
||
{
|
||
listMineType = UserService.GetMineType(MineType);
|
||
}
|
||
}
|
||
if (pageFilter.FilterGroup.Groups != null && pageFilter.FilterGroup.Groups.Any())
|
||
{
|
||
var groups = pageFilter.FilterGroup.Groups.ToList();
|
||
if (groups[0].Rules != null && groups[0].Rules.Any())
|
||
{
|
||
FilterRule ruleType = null;
|
||
foreach (var rule in groups[0].Rules)
|
||
{
|
||
if (rule.Field == "MineType")
|
||
{
|
||
ruleType = rule;
|
||
MineType = rule.Value.ToString();
|
||
isMintype = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(MineType))
|
||
{
|
||
listMineType = UserService.GetMineType(MineType);
|
||
if (ruleType != null)
|
||
{
|
||
groups[0].Rules.Remove(ruleType);
|
||
pageFilter.FilterGroup.Groups = groups;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
var LoginDepID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
||
T_FM_DEPARTMENT dep = null;
|
||
if (LoginDepID.HasValue)
|
||
{
|
||
dep = GetEntity<T_FM_DEPARTMENT>(LoginDepID.Value);
|
||
}
|
||
if (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && LoginDepID.HasValue && dep != null && (dep.DEPARTMENT_TYPE == 1 || dep.DEPARTMENT_TYPE == 2))
|
||
{
|
||
//班组或者车间 向下取值 否则取全部
|
||
//FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3
|
||
if (dep.DEPARTMENT_TYPE == 2)
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
var listDepID = GetEntities<T_FM_DEPARTMENT>(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == LoginDepID.Value, null).Select(e => e.ID);
|
||
if (listDepID != null && listDepID.Any())
|
||
{
|
||
var ListDepID = listDepID.ToList();
|
||
ListDepID.Add(LoginDepID.Value);
|
||
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && ListDepID.Contains(e.DEPARTMENT_ID.Value) && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
}
|
||
else if (isMintype)
|
||
{
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
Expression<Func<T_FM_USER, bool>> expression = e => e.ENABLE_STATUS == 0 && !e.CODE.StartsWith("admin");// && e.CODE != "admin";
|
||
//linq 运行不通过 修改为查找后内存中过滤
|
||
//expression = expression.And(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => listMineType.Contains(x.Nav_Enums.VALUE)) != null));
|
||
//PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(expression, pageFilter, "Nav_ProdutionUnit.Nav_Enums");
|
||
//result.Data = orderPageEntities.Data;
|
||
//result.TotalCount = orderPageEntities.TotalCount;
|
||
|
||
//var resultListUser = GetEntities<T_FM_USER>(expression, pageFilter, "Nav_ProdutionUnit.Nav_Enums");//这样不行
|
||
pageFilter.SelectField.Add("Nav_ProdutionUnit.Nav_Enums");
|
||
if (pageFilter.SelectField.Count() == 1)
|
||
{
|
||
pageFilter.SelectField.Add("ID");
|
||
pageFilter.SelectField.Add("NAME");
|
||
pageFilter.SelectField.Add("CODE");
|
||
}
|
||
var resultListUser = GetEntities<T_FM_USER>(expression, pageFilter);
|
||
|
||
if (resultListUser != null && resultListUser.Any())
|
||
{
|
||
IEnumerable<T_FM_USER> resultListUserFilter = null;
|
||
if (listMineType.Count > 0)
|
||
{
|
||
//if (listMineType.Count == 1)
|
||
//{
|
||
// resultListUserFilter = resultListUser.Where(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => x.Nav_Enums != null && listMineType[0] == x.Nav_Enums.VALUE).Any()));// != null
|
||
//}
|
||
//else
|
||
//{
|
||
resultListUserFilter = resultListUser.Where(e => e.Nav_ProdutionUnit == null || (e.Nav_ProdutionUnit.Any() && e.Nav_ProdutionUnit.Where(x => x.Nav_Enums != null && listMineType.Contains(x.Nav_Enums.VALUE)) != null));
|
||
//}
|
||
}
|
||
|
||
if (resultListUserFilter != null && resultListUserFilter.Any())
|
||
{
|
||
result.Data = resultListUserFilter.Skip((pageFilter.PageIndex - 1) * pageFilter.Limit).Take(pageFilter.Limit);
|
||
result.TotalCount = resultListUserFilter.Count();
|
||
}
|
||
}
|
||
|
||
if (result.Data == null || !result.Data.Any())
|
||
{
|
||
result.Data = new List<T_FM_USER>();
|
||
result.TotalCount = 0;
|
||
}
|
||
});
|
||
}
|
||
else if (DEPARTMENT_ID_WORKSHOP != Guid.Empty && DEPARTMENT_ID != Guid.Empty)
|
||
{
|
||
pageFilter.FilterGroup.Rules.Clear();
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(e => e.ENABLE_STATUS == 0 && e.CODE != "admin" && e.DEPARTMENT_ID == DEPARTMENT_ID_WORKSHOP || (e.Nav_Department.PARENT_ID.HasValue && e.Nav_Department.PARENT_ID == DEPARTMENT_ID_WORKSHOP), pageFilter, new string[] { "Nav_Department" });
|
||
result.Data = orderPageEntities.Data;
|
||
result.TotalCount = orderPageEntities.TotalCount;
|
||
});
|
||
}
|
||
else
|
||
{
|
||
if (DataHelper.GetRequestType(HttpContext.Request.Headers) == 2 && LoginDepID.HasValue)
|
||
{
|
||
//班组或者车间 向下取值 否则取全部
|
||
dep = GetEntity<T_FM_DEPARTMENT>(LoginDepID.Value);
|
||
if (dep != null && (dep.DEPARTMENT_TYPE == 1 || dep.DEPARTMENT_TYPE == 2))
|
||
{
|
||
//FMDepartmentType 部门=0, 车间=1, 班组=2, 公司=3
|
||
if (dep.DEPARTMENT_TYPE == 2)
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
var listDepID = GetEntities<T_FM_DEPARTMENT>(e => e.PARENT_ID.HasValue && e.PARENT_ID.Value == LoginDepID.Value, null).Select(e => e.ID);
|
||
if (listDepID != null && listDepID.Any())
|
||
{
|
||
var ListDepID = listDepID.ToList();
|
||
ListDepID.Add(LoginDepID.Value);
|
||
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && ListDepID.Contains(e.DEPARTMENT_ID.Value) && e.CODE != "admin", pageFilter);
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == LoginDepID.Value && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(e => e.ENABLE_STATUS == 0 && e.CODE != "admin", pageFilter);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return WitOrderPaged(t => t.Nav_BelongRoles.Any(i => i.Nav_BelongRole.NAME.Contains(pageFilter.Parameter1)), pageFilter);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 正常使用的用户
|
||
/// 重写 api/FM/User/OrderPaged
|
||
/// 目前最多只支持4个生产单元有重叠的
|
||
/// </summary>
|
||
/// <param name="pageFilter"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPagedUsefulWB")]
|
||
public PagedActionResult<T_FM_USER> OrderPagedUsefulWB([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
Expression<Func<T_FM_USER, bool>> expression = e => e.ENABLE_STATUS == 0;
|
||
if (pageFilter.Parameter1 == "1")
|
||
{
|
||
expression = expression.And(e => e.PROJECT_ID.HasValue);
|
||
}
|
||
else if (pageFilter.Parameter1 == "2")
|
||
{
|
||
if (APT.Infrastructure.Api.AppContext.CurrentSession.UserID.HasValue)
|
||
{
|
||
var login = GetEntity<T_FM_USER>(APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value);
|
||
if (login.PRINTER_ID.HasValue)
|
||
{
|
||
expression = expression.And(e => e.PROJECT_ID.HasValue && e.PROJECT_ID.Value == login.PROJECT_ID);
|
||
}
|
||
}
|
||
}
|
||
PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(expression, pageFilter, null);
|
||
result.Data = orderPageEntities.Data;
|
||
result.TotalCount = orderPageEntities.TotalCount;
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 人员选择 外包人员 选择只有本外包单位人员信息 否则可以选到所有人信息
|
||
/// </summary>
|
||
/// <param name="pageFilter"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("OrderPagedUsefulProject")]
|
||
public PagedActionResult<T_FM_USER> OrderPagedUsefulProject([FromBody] KeywordPageFilter pageFilter)
|
||
{
|
||
return SafeGetPagedData(delegate (PagedActionResult<T_FM_USER> result)
|
||
{
|
||
Expression<Func<T_FM_USER, bool>> expression = e => e.ENABLE_STATUS == 0;
|
||
var login = GetEntity<T_FM_USER>(APT.Infrastructure.Api.AppContext.CurrentSession.UserID.Value);
|
||
if (login.PROJECT_ID.HasValue)
|
||
{
|
||
expression = expression.And(e => e.PROJECT_ID.HasValue && e.PROJECT_ID.Value == login.PROJECT_ID);
|
||
}
|
||
PagedActionResult<T_FM_USER> orderPageEntities = GetOrderPageEntities<T_FM_USER>(expression, pageFilter, null);
|
||
result.Data = orderPageEntities.Data;
|
||
result.TotalCount = orderPageEntities.TotalCount;
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 递归获取部门以及子部门的所有用户
|
||
/// </summary>
|
||
/// <param name="filter"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("GetDepUsersRecursion")]
|
||
public JsonActionResult<IEnumerable<T_FM_USER>> GetDepUsersRecursion([FromBody] KeywordFilter filter)
|
||
{
|
||
return SafeExecute<IEnumerable<T_FM_USER>>(() =>
|
||
{
|
||
var baseFilter = new BaseFilter(filter.GetOrgId());
|
||
baseFilter.SelectField = new string[] { "ID", "PARENT_ID" };
|
||
var departments = this.GetEntities<T_FM_DEPARTMENT>(i => i.ENABLE_STATUS == (int)FMEnableStatusEnum.启用, baseFilter);
|
||
var selectDepatmentIds = new List<Guid>();
|
||
if (!string.IsNullOrEmpty(filter.Keyword))
|
||
{
|
||
var parentid = Guid.Parse(filter.Keyword);
|
||
GetRecursionDepIds(departments, selectDepatmentIds, parentid);
|
||
return this.GetEntities<T_FM_USER>(i => selectDepatmentIds.Contains(i.DEPARTMENT_ID.Value), filter);
|
||
}
|
||
else
|
||
{
|
||
return this.GetEntities<T_FM_USER>(null, filter);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
private static void GetRecursionDepIds(IEnumerable<T_FM_DEPARTMENT> departments, List<Guid> selectDepatmentIds, Guid parentid)
|
||
{
|
||
selectDepatmentIds.Add(parentid);
|
||
if (departments.Any(i => i.PARENT_ID == parentid))
|
||
{
|
||
var childIds = departments.Where(i => i.PARENT_ID == parentid).Select(i => i.ID);
|
||
foreach (var childId in childIds)
|
||
{
|
||
GetRecursionDepIds(departments, selectDepatmentIds, childId);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#region 用户信息导入
|
||
|
||
|
||
/// <summary>
|
||
/// 获取导入数据
|
||
/// 参考 [Route("api/PF/Import")]
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("DataImport")]
|
||
public JsonActionResult<ImportDataModel> DataImport()
|
||
{
|
||
return SafeExecute<ImportDataModel>(() =>
|
||
{
|
||
string telnetCode = Request.Headers["Tenant"];
|
||
var httpRequest = this.HttpContext.Request;
|
||
string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织
|
||
Guid? orgId = null;
|
||
if (!string.IsNullOrEmpty(orgIdStr))
|
||
orgId = new Guid(orgIdStr);
|
||
else
|
||
return null;
|
||
ImportDataModel result = new ImportDataModel();
|
||
var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles");
|
||
if (!Directory.Exists(dic))
|
||
Directory.CreateDirectory(dic);
|
||
foreach (var key in httpRequest.Form.Files) // 文件键
|
||
{
|
||
var postedFile = key; // 获取文件键对应的文件对象
|
||
string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName);
|
||
Byte[] fileData = new Byte[postedFile.Length];
|
||
Stream sr = postedFile.OpenReadStream();//创建数据流对象
|
||
sr.Read(fileData, 0, (int)postedFile.Length);
|
||
using (FileStream fs = new FileStream(filePath, FileMode.CreateNew))
|
||
{
|
||
fs.Write(fileData, 0, fileData.Length);
|
||
fs.Flush();
|
||
fs.Close();
|
||
}
|
||
|
||
//获取数据
|
||
Dictionary<int, int> startRowIndexs = new Dictionary<int, int>();
|
||
startRowIndexs.Add(0, 0);//根据Excel格式数据赋值
|
||
DataSet dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
|
||
string Msg = string.Empty;
|
||
|
||
bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, telnetCode, ref Msg);
|
||
|
||
try
|
||
{
|
||
System.IO.File.Delete(filePath);
|
||
}
|
||
catch { }
|
||
|
||
result.Data = Msg;
|
||
result.MessageList = new List<string> { Msg };
|
||
}
|
||
|
||
return result;
|
||
});
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 数据插入
|
||
/// </summary>
|
||
/// <param name="dtSource"></param>
|
||
/// <param name="OrgID"></param>
|
||
/// <param name="telnetCode"></param>
|
||
/// <param name="Msg"></param>
|
||
/// <param name="rowIndex"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="Exception"></exception>
|
||
public bool InsertModel(DataTable dtSource, Guid OrgID, string telnetCode, ref string Msg, int rowIndex = 3)
|
||
{
|
||
//0:公司名称* 1:部门名称 2:部门编号 3:车间名称 4:车间编号 5:班组名称 6:班组编号
|
||
//7:姓名* 8:工号 * 9:手机号码 * 10:身份证号 11:岗位 12:性别* 13:入职日期 14:工龄 15:审批角色 16:操作角色 *
|
||
|
||
//注意事项:
|
||
//1、公司名称必填,每次导入有且仅有一个公司名称
|
||
//2、人员所在组织(公司、部门、车间、班组)必须确切,例如:公司领导只填【公司名称】,班组员工必须填完整【公司名称、部门名称、车间名称、班组名称】
|
||
//3、姓名、工号、手机号码、岗位、性别、操作角色必填
|
||
//4、字段说明:各组织名称不能重复;【组织编号】如果为空,系统会自动生成;【工号】系统登录唯一标识符,不能重复;初始密码规则:姓名首字母大写 + 工号数字,例句的初始密码为:Wjl00088;【手机号码】:11位数字;【身份证号码】:18位数字;【性别】:男 / 女;【入职日期】必须是yyyy - MM - dd格式(例如:2025 - 01 - 01);【工龄】为正数;【操作角色】必须是系统已配置信息,如有多个用英文分号【;】分割
|
||
//5、此表单导入会自动添加:组织、人员、岗位、审批角色信息
|
||
//6、如果是总部人员,需要自动添加到各子公司:公司名称以{【总部】}结尾,人员只能添加到子公司的公司级,并且组织、角色、岗位等不自动处理
|
||
//7、首行为例句,不能删除,直接从序号【5】开始填写
|
||
|
||
if (dtSource == null || dtSource.Rows.Count < 0 || dtSource.Rows.Count < rowIndex)
|
||
{
|
||
Msg = "未获取到导入数据";
|
||
throw new Exception(Msg);
|
||
}
|
||
List<int> listNotEmpty = new List<int>() { 0, 7, 8, 9, 12, 16 };
|
||
|
||
//使用组织 T_FM_DEPARTMENT
|
||
//物料类型 T_TI_SAFE_PDT_COST_RECORD_TYPE T_TI_COST_TYPE
|
||
//记录人 T_FM_USER
|
||
|
||
#region 定义变量
|
||
|
||
bool isHead = false;//是否总部 新增 是 得全子公司添加登录信息
|
||
bool isAddUser = false;//是否新增人员 是角色信息得新增 否 查询后处理
|
||
bool isAdddep5 = false;//是否新增 公司
|
||
DateTime dtNow = DateTime.Now;
|
||
Dictionary<int, List<int>> dicIndexEmpty = new Dictionary<int, List<int>>();
|
||
List<T_FM_DEPARTMENT> listDepAll = GetEntities<T_FM_DEPARTMENT>(e => e.ENABLE_STATUS == 0, null).ToList();
|
||
List<T_FM_USER> listUSER = GetEntities<T_FM_USER>(e => e.ENABLE_STATUS == 0, null).ToList();
|
||
List<T_FM_PERSON> listPerson = GetEntities<T_FM_PERSON>(null, null).ToList();
|
||
List<T_FM_USER_POST> listUserPost = GetEntities<T_FM_USER_POST>(e => e.STATUS == ((int)FMPostStatusType.启用), null).ToList();
|
||
List<T_PF_APPROVAL_ROLE> listApproveRole = GetEntities<T_PF_APPROVAL_ROLE>(null, null).ToList();//导入自动添加
|
||
List<T_FM_USER_BELONG_ROLE> listUserRole = GetEntities<T_FM_USER_BELONG_ROLE>(null, null).ToList();
|
||
List<T_FM_ROLE> listRole = GetEntities<T_FM_ROLE>(null, null).ToList();//不做添加 平台类型前端不好改
|
||
|
||
|
||
List<T_FM_DEPARTMENT> listDepAdd = new List<T_FM_DEPARTMENT>();//需要新增的组织
|
||
List<T_FM_USER> listUserAdd = new List<T_FM_USER>();//新增用户
|
||
List<T_FM_PERSON> listPersonAdd = new List<T_FM_PERSON>();//新增人员
|
||
List<T_FM_USER_POST> listUserPostAdd = new List<T_FM_USER_POST>();//新增岗位
|
||
List<T_PF_APPROVAL_ROLE> listApproveRoleAdd = new List<T_PF_APPROVAL_ROLE>();//新增审批角色
|
||
List<T_FM_USER_BELONG_ROLE> listUserRoleAdd = new List<T_FM_USER_BELONG_ROLE>();//添加人员角色绑定
|
||
|
||
//公司名称 0
|
||
T_FM_DEPARTMENT dep5 = null;
|
||
string strDep5 = string.Empty;
|
||
//List<string> listStrDepartmentName5 = new List<string>();
|
||
//T_FM_DEPARTMENT modelDep5 = new T_FM_DEPARTMENT();
|
||
//List<string> listDepName5 = new List<string>();
|
||
//List<int> listDepartment5Index = new List<int>();
|
||
|
||
//部门名称 1
|
||
List<T_FM_DEPARTMENT> listDep10 = listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 10).ToList();
|
||
string strDep10 = string.Empty;
|
||
List<string> listStrDepartmentName10 = new List<string>();
|
||
T_FM_DEPARTMENT modelDep10 = new T_FM_DEPARTMENT();
|
||
List<string> listDepName10 = new List<string>();
|
||
List<int> listDepartment10Index = new List<int>();
|
||
|
||
|
||
//车间名称 3
|
||
List<T_FM_DEPARTMENT> listDep15 = listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 15).ToList();
|
||
string strDep15 = string.Empty;
|
||
List<string> listStrDepartmentName15 = new List<string>();
|
||
T_FM_DEPARTMENT modelDep15 = new T_FM_DEPARTMENT();
|
||
List<string> listDepName15 = new List<string>();
|
||
List<int> listDepartment15Index = new List<int>();
|
||
|
||
|
||
//班组名称 5
|
||
List<T_FM_DEPARTMENT> listDep20 = listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 10).ToList();
|
||
string strDep20 = string.Empty;
|
||
List<string> listStrDepartmentName20 = new List<string>();
|
||
T_FM_DEPARTMENT modelDep20 = new T_FM_DEPARTMENT();
|
||
List<string> listDepName20 = new List<string>();
|
||
List<int> listDepartment20Index = new List<int>();
|
||
|
||
//姓名 7
|
||
List<int> listNAMEIndex = new List<int>();
|
||
List<string> listStrNAME = new List<string>();
|
||
string strNAME = string.Empty;
|
||
|
||
T_FM_USER modelUser = new T_FM_USER();
|
||
T_FM_PERSON modelPerson = new T_FM_PERSON();
|
||
|
||
//工号 8
|
||
List<int> listCODEIndex = new List<int>();
|
||
List<string> listStrCODE = new List<string>();
|
||
string strCODE = string.Empty;
|
||
|
||
//手机号码 9
|
||
List<int> listPHONEIndex = new List<int>();
|
||
List<string> listStrPHONE = new List<string>();
|
||
string strPHONE = string.Empty;
|
||
|
||
//身份证号 10
|
||
string strID_CARD = string.Empty;
|
||
List<int> listID_CARDIndex = new List<int>();
|
||
List<string> listStrID_CARD = new List<string>();
|
||
|
||
//岗位 11
|
||
List<int> listPostIndex = new List<int>();
|
||
List<string> listStrPost = new List<string>();
|
||
string strPost = string.Empty;
|
||
List<string> listPostName = new List<string>();
|
||
T_FM_USER_POST modelPost = null;
|
||
|
||
//性别 12
|
||
string strSEX = string.Empty;
|
||
List<int> listSEXIndex = new List<int>();
|
||
List<string> listStrSEX = new List<string>();
|
||
|
||
//入职日期 13
|
||
string strENTRYTIME = string.Empty;
|
||
DateTime? dtENTRYTIME = null;
|
||
List<int> listENTRYTIMEIndex = new List<int>();
|
||
List<string> listStrENTRYTIME = new List<string>();
|
||
|
||
//工龄 14
|
||
string strWORKINGYEAR = string.Empty;
|
||
int? WORKINGYEAR = null;
|
||
List<int> listWORKINGYEARIndex = new List<int>();
|
||
List<string> listStrWORKINGYEAR = new List<string>();
|
||
|
||
//审批角色 15
|
||
string strApproveRole = string.Empty;
|
||
List<string> listStrApproveRole = new List<string>();
|
||
T_PF_APPROVAL_ROLE modelApproveRole = new T_PF_APPROVAL_ROLE();
|
||
List<string> listApproveRoleName = new List<string>();
|
||
List<int> listApproveRoleIndex = new List<int>();
|
||
|
||
//操作角色 16
|
||
string strRole = string.Empty;
|
||
char[] charSplit = new char[] { ';', ';' };
|
||
List<string> listStrRole = new List<string>();
|
||
List<T_FM_ROLE> listRoleItem = new List<T_FM_ROLE>();
|
||
List<string> listRoleName = new List<string>();
|
||
List<int> listRoleIndex = new List<int>();
|
||
T_FM_USER_BELONG_ROLE modelUserRole = null;
|
||
|
||
//0:公司名称* 1:部门名称 2:部门编号 3:车间名称 4:车间编号 5:班组名称 6:班组编号
|
||
//7:姓名* 8:工号 * 9:手机号码 * 10:身份证号 11:岗位 12:性别* 13:入职日期 14:工龄 15:审批角色 16:操作角色 *
|
||
|
||
List<int> listDepartment13Index = new List<int>();//部门为空 车间不为空
|
||
List<int> listDepartment35Index = new List<int>();//车间为空 班组不为空
|
||
|
||
#endregion
|
||
|
||
|
||
#region 数据判断
|
||
|
||
//第一行是标题 跳过
|
||
int rowAll = dtSource.Rows.Count;
|
||
strDep5 = dtSource.Rows[rowIndex][0].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strDep5))
|
||
{
|
||
#region 公司 总部 处理 dep5
|
||
|
||
if (strDep5.EndsWith("【总部】"))
|
||
{
|
||
isHead = true;
|
||
strDep5 = strDep5.Replace("【总部】", "");
|
||
}
|
||
dep5 = listDepAll.FirstOrDefault(e => e.NAME == strDep5 && e.DEPARTMENT_TYPE == 5);
|
||
if (dep5 == null)
|
||
{
|
||
isAdddep5 = true;
|
||
//没有找到初始化信息
|
||
dep5 = new T_FM_DEPARTMENT();
|
||
try
|
||
{
|
||
string strOrgID = OrgID.ToString();
|
||
var listIDs = strOrgID.Split('-');
|
||
string strID = string.Empty;
|
||
for (int i = 0; i < listIDs.Length; i++)
|
||
{
|
||
if (i == 1)
|
||
{
|
||
listIDs[i] = "4" + listIDs[i].Substring(1, listIDs[i].Length - 1);
|
||
}
|
||
strID += listIDs[i];
|
||
}
|
||
dep5.ID = new Guid(strID);
|
||
dep5.CREATE_TIME = dtNow;
|
||
}
|
||
catch
|
||
{
|
||
dep5.ID = Guid.NewGuid();
|
||
dep5.CREATE_TIME = dtNow;
|
||
}
|
||
|
||
dep5.ORG_ID = OrgID;
|
||
dep5.NAME = strDep5;
|
||
dep5.DEPARTMENT_TYPE = 5;
|
||
dep5.CODE = DataHelper.MkPinyinString(dep5.NAME) + "00";
|
||
|
||
listDepAdd.Add(dep5);
|
||
listDepAll.Add(dep5);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
|
||
MD5 md5 = MD5.Create();
|
||
string nameHead = string.Empty;
|
||
string code = string.Empty;
|
||
string NewPwd = string.Empty;
|
||
|
||
for (int i = rowIndex; i < rowAll; i++)
|
||
{
|
||
#region 不能为空
|
||
|
||
List<int> listi = null;
|
||
for (int j = 0; j < 17; j++)
|
||
{
|
||
if (!listNotEmpty.Contains(j))
|
||
continue;
|
||
|
||
if (string.IsNullOrEmpty(dtSource.Rows[i][j].ToString().Trim()))
|
||
{
|
||
if (listi == null)
|
||
{
|
||
listi = new List<int>();
|
||
}
|
||
listi.Add(j);
|
||
}
|
||
}
|
||
if (listi != null)
|
||
dicIndexEmpty.Add(i + rowIndex, listi);//有空的 直接添加
|
||
|
||
#endregion
|
||
|
||
#region 部门名称 1 部门编号 2
|
||
|
||
strDep10 = dtSource.Rows[i][1].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strDep10))
|
||
{
|
||
modelDep10 = listDepAll.FirstOrDefault(e => e.NAME == strDep10);
|
||
if (modelDep10 != null && modelDep10.DEPARTMENT_TYPE != 10)
|
||
{
|
||
if (!listDepName10.Contains(strDep10))
|
||
{
|
||
listDepName10.Add(strDep10);
|
||
}
|
||
listDepartment10Index.Add(i + rowIndex);
|
||
}
|
||
|
||
if ((modelDep10 == null || modelDep10.ID == Guid.Empty) && !listDepartment10Index.Contains(i + rowIndex))
|
||
{
|
||
modelDep10 = new T_FM_DEPARTMENT();
|
||
modelDep10.ID = Guid.NewGuid();
|
||
modelDep10.NAME = strDep10;
|
||
modelDep10.ORG_ID = OrgID;
|
||
modelDep10.CODE = dtSource.Rows[i][2].ToString().Trim();
|
||
modelDep10.PARENT_ID = dep5.ID;
|
||
modelDep10.DEPARTMENT_TYPE = 10;
|
||
modelDep10.ENABLE_STATUS = 0;
|
||
modelDep10.CREATE_TIME = dtNow;
|
||
if (string.IsNullOrEmpty(modelDep10.CODE))
|
||
{
|
||
modelDep10.CODE = dep5.CODE + (listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 10).Count() + 1).ToString().PadLeft(2, '0');
|
||
}
|
||
|
||
listDepAdd.Add(modelDep10);
|
||
listDepAll.Add(modelDep10);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
modelDep10 = null; //数据为空 model 置为 null
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 车间名称 3 车间编号 4
|
||
|
||
strDep15 = dtSource.Rows[i][3].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strDep15))
|
||
{
|
||
if (modelDep10 == null)
|
||
{
|
||
listDepartment13Index.Add(i + rowIndex);
|
||
}
|
||
else
|
||
{
|
||
modelDep15 = listDepAll.FirstOrDefault(e => e.NAME == strDep15);
|
||
if (modelDep15 != null && modelDep15.DEPARTMENT_TYPE != 15)
|
||
{
|
||
if (!listDepName15.Contains(strDep15))
|
||
{
|
||
listDepName15.Add(strDep15);
|
||
}
|
||
listDepartment15Index.Add(i + rowIndex);
|
||
}
|
||
|
||
if ((modelDep15 == null || modelDep15.ID == Guid.Empty) && !listDepartment15Index.Contains(i + rowIndex))
|
||
{
|
||
modelDep15 = new T_FM_DEPARTMENT();
|
||
modelDep15.ID = Guid.NewGuid();
|
||
modelDep15.NAME = strDep15;
|
||
modelDep15.ORG_ID = OrgID;
|
||
modelDep15.CODE = dtSource.Rows[i][4].ToString().Trim();
|
||
modelDep15.PARENT_ID = modelDep10.ID;
|
||
modelDep15.ENABLE_STATUS = 0;
|
||
modelDep15.DEPARTMENT_TYPE = 15;
|
||
modelDep15.CREATE_TIME = dtNow;
|
||
if (string.IsNullOrEmpty(modelDep15.CODE))
|
||
{
|
||
modelDep15.CODE = modelDep10.CODE + (listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 15).Count() + 1).ToString().PadLeft(2, '0');
|
||
}
|
||
|
||
listDepAdd.Add(modelDep15);
|
||
listDepAll.Add(modelDep15);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
modelDep15 = null; //数据为空 model 置为 null
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 班组名称 5 班组编号 6
|
||
|
||
strDep20 = dtSource.Rows[i][5].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strDep20))
|
||
{
|
||
if (modelDep10 == null)
|
||
{
|
||
listDepartment35Index.Add(i + rowIndex);
|
||
}
|
||
else
|
||
{
|
||
modelDep20 = listDepAll.FirstOrDefault(e => e.NAME == strDep20);
|
||
if (modelDep20 != null && modelDep20.DEPARTMENT_TYPE != 20)
|
||
{
|
||
if (!listDepName20.Contains(strDep20))
|
||
{
|
||
listDepName20.Add(strDep20);
|
||
}
|
||
listDepartment20Index.Add(i + rowIndex);
|
||
}
|
||
|
||
if ((modelDep20 == null || modelDep20.ID == Guid.Empty) && !listDepartment20Index.Contains(i + rowIndex))
|
||
{
|
||
modelDep20 = new T_FM_DEPARTMENT();
|
||
modelDep20.ID = Guid.NewGuid();
|
||
modelDep20.NAME = strDep20;
|
||
modelDep20.ORG_ID = OrgID;
|
||
modelDep20.CODE = dtSource.Rows[i][6].ToString().Trim();
|
||
modelDep20.PARENT_ID = modelDep15.ID;
|
||
modelDep20.ENABLE_STATUS = 0;
|
||
modelDep20.DEPARTMENT_TYPE = 20;
|
||
modelDep20.CREATE_TIME = dtNow;
|
||
if (string.IsNullOrEmpty(modelDep20.CODE))
|
||
{
|
||
modelDep20.CODE = modelDep15.CODE + (listDepAll.FindAll(e => e.DEPARTMENT_TYPE == 20).Count() + 1).ToString().PadLeft(2, '0');
|
||
}
|
||
|
||
listDepAdd.Add(modelDep20);
|
||
listDepAll.Add(modelDep20);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
modelDep20 = null; //数据为空 model 置为 null
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 姓名 7 工号 8
|
||
isAddUser = false;
|
||
if (!listDepartment13Index.Contains(i + rowIndex) && !listDepartment35Index.Contains(i + rowIndex))
|
||
{
|
||
//组织信息 对 才进来判断
|
||
strNAME = dtSource.Rows[i][7].ToString().Trim();
|
||
strCODE = dtSource.Rows[i][8].ToString().Trim();
|
||
|
||
#region 手机号码 9 strPHONE
|
||
|
||
strPHONE = dtSource.Rows[i][9].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strPHONE) && strPHONE.Length != 11)
|
||
{
|
||
if (!listStrPHONE.Contains(strPHONE))
|
||
{
|
||
listStrPHONE.Add(strPHONE);
|
||
}
|
||
listPHONEIndex.Add(i + rowIndex);
|
||
}
|
||
#endregion
|
||
|
||
#region strID_CARD 身份证号 10
|
||
|
||
strID_CARD = dtSource.Rows[i][10].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strID_CARD) && strID_CARD.Length != 18)
|
||
{
|
||
if (listStrID_CARD.Contains(strID_CARD))
|
||
{
|
||
listStrID_CARD.Add(strID_CARD);
|
||
}
|
||
listID_CARDIndex.Add(i + rowIndex);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 性别 12 strSEX
|
||
|
||
strSEX = dtSource.Rows[i][12].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strSEX) && strSEX != "男" && strSEX != "女")
|
||
{
|
||
if (!listStrSEX.Contains(strSEX))
|
||
{
|
||
listStrSEX.Add(strSEX);
|
||
}
|
||
listSEXIndex.Add(i + rowIndex);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 岗位 modelPost 11
|
||
|
||
strPost = dtSource.Rows[i][11].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strPost))
|
||
{
|
||
modelPost = listUserPost.FirstOrDefault(e => e.NAME == strPost);
|
||
if (modelPost == null)
|
||
{
|
||
modelPost = new T_FM_USER_POST();
|
||
modelPost.ID = Guid.NewGuid();
|
||
modelPost.ORG_ID = OrgID;
|
||
modelPost.NAME = strPost;
|
||
modelPost.CODE = "POST" + (listUserPost.Count() + 1).ToString().PadLeft(3, '0');
|
||
modelPost.CREATE_TIME = dtNow;
|
||
modelPost.STATUS = (int)FMPostStatusType.启用;
|
||
|
||
listUserPostAdd.Add(modelPost);
|
||
listUserPost.Add(modelPost);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
modelPost = null;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 入职日期 dtENTRYTIME 13
|
||
|
||
strENTRYTIME = dtSource.Rows[i][13].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strENTRYTIME))
|
||
{
|
||
try
|
||
{
|
||
dtENTRYTIME = Convert.ToDateTime(strENTRYTIME);
|
||
}
|
||
catch
|
||
{
|
||
if (!listStrENTRYTIME.Contains(strENTRYTIME))
|
||
{
|
||
listStrENTRYTIME.Add(strENTRYTIME);
|
||
}
|
||
listENTRYTIMEIndex.Add(i + rowIndex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
dtENTRYTIME = null;
|
||
}
|
||
#endregion
|
||
|
||
#region 工龄 WORKINGYEAR 14
|
||
|
||
strWORKINGYEAR = dtSource.Rows[i][14].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strWORKINGYEAR))
|
||
{
|
||
try
|
||
{
|
||
WORKINGYEAR = int.Parse(strWORKINGYEAR);
|
||
}
|
||
catch
|
||
{
|
||
if (!listStrWORKINGYEAR.Contains(strWORKINGYEAR))
|
||
{
|
||
listStrWORKINGYEAR.Add(strWORKINGYEAR);
|
||
}
|
||
listWORKINGYEARIndex.Add(i + rowIndex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
WORKINGYEAR = null;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 审批角色 15
|
||
|
||
strApproveRole = dtSource.Rows[i][15].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strApproveRole))
|
||
{
|
||
modelApproveRole = listApproveRole.FirstOrDefault(e => e.NAME == strApproveRole);
|
||
if (modelApproveRole == null)
|
||
{
|
||
modelApproveRole = new T_PF_APPROVAL_ROLE();
|
||
modelApproveRole.ID = Guid.NewGuid();
|
||
modelApproveRole.ORG_ID = OrgID;
|
||
modelApproveRole.NAME = strPost;
|
||
modelApproveRole.CODE = DataHelper.MkPinyinString(modelApproveRole.NAME) + (listApproveRoleAdd.Count() + 1).ToString().PadLeft(2, '0');
|
||
modelApproveRole.CREATE_TIME = dtNow;
|
||
listApproveRoleAdd.Add(modelApproveRole);
|
||
listApproveRole.Add(modelApproveRole);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
modelApproveRole = null;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 操作角色 16
|
||
|
||
strRole = dtSource.Rows[i][16].ToString().Trim();
|
||
if (!string.IsNullOrEmpty(strRole))
|
||
{
|
||
listStrRole = strRole.Split(charSplit, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
listRoleItem = listRole.FindAll(e => listStrRole.Contains(e.NAME)).ToList();
|
||
}
|
||
else
|
||
{
|
||
listRoleItem = null;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 数据组装
|
||
|
||
|
||
if (!string.IsNullOrEmpty(strNAME) && !string.IsNullOrEmpty(strCODE) && dicIndexEmpty.Count < 1 && listDepartment10Index.Count < 1 && listDepartment15Index.Count < 1 && listDepartment13Index.Count < 1 && listDepartment35Index.Count < 1 && listPHONEIndex.Count < 1 && listID_CARDIndex.Count < 1 && listSEXIndex.Count < 1 && listENTRYTIMEIndex.Count < 1 && listWORKINGYEARIndex.Count < 1)
|
||
{
|
||
modelUser = listUSER.FirstOrDefault(e => e.NAME == strNAME && e.CODE == strCODE);
|
||
modelPerson = listPerson.FirstOrDefault(e => e.NAME == strNAME && e.CODE == strCODE);
|
||
|
||
if (modelUser == null)
|
||
{
|
||
isAddUser = true;
|
||
modelUser = new T_FM_USER();
|
||
modelUser.ID = Guid.NewGuid();
|
||
modelUser.CREATE_TIME = dtNow;
|
||
}
|
||
|
||
//if (modelUser == null)
|
||
//{
|
||
// isAddUser = true;
|
||
// modelUser = new T_FM_USER();
|
||
// modelUser.ID = Guid.NewGuid();
|
||
modelUser.ORG_ID = OrgID;
|
||
modelUser.NAME = strNAME;
|
||
modelUser.CODE = strCODE;
|
||
modelUser.PHONE = strPHONE;
|
||
modelUser.SEX = (strSEX == "男" ? FMSexEnum.男.GetInt() : FMSexEnum.女.GetInt());
|
||
|
||
nameHead = DataHelper.MkPinyinString(modelUser.NAME);
|
||
code = DataHelper.GetCodeNO(modelUser.CODE);
|
||
NewPwd = DataHelper.MD5Encrypt32(md5, nameHead + code);
|
||
modelUser.PASSWORD = NewPwd;
|
||
|
||
|
||
//班组 车间 部门 公司 顺序去找部门
|
||
modelUser.DEPARTMENT_ID = (modelDep20 != null ? modelDep20.ID : (modelDep15 != null ? modelDep15.ID : (modelDep10 != null ? modelDep10.ID : dep5.ID)));
|
||
modelUser.ID_CARD = strID_CARD;
|
||
if (dtENTRYTIME.HasValue)
|
||
{
|
||
modelUser.ENTRYTIME = dtENTRYTIME.Value;
|
||
}
|
||
|
||
modelUser.WORKINGYEAR = (WORKINGYEAR.HasValue ? WORKINGYEAR.Value : 0);
|
||
if (modelApproveRole != null)
|
||
modelUser.APPROVE_ROLE_ID = modelApproveRole.ID;
|
||
|
||
if (isAddUser == true)
|
||
{
|
||
modelUser.PERSON_ID = Guid.NewGuid();//先生成T_FM_PERSON的ID
|
||
modelPerson = new T_FM_PERSON();
|
||
modelPerson.ID = modelUser.PERSON_ID.Value;
|
||
modelPerson.CREATE_TIME = dtNow;
|
||
}
|
||
|
||
modelPerson.ORG_ID = OrgID;
|
||
modelPerson.CREATE_TIME = dtNow;
|
||
modelPerson.NAME = modelUser.NAME;
|
||
modelPerson.CODE = modelUser.CODE;
|
||
modelPerson.SEX = modelUser.SEX;
|
||
modelPerson.DEPARTMENT_ID = modelUser.DEPARTMENT_ID;
|
||
if (modelPost != null)
|
||
{
|
||
modelPerson.POST_ID = modelPost.ID;
|
||
}
|
||
|
||
listUSER.Add(modelUser);
|
||
listPerson.Add(modelPerson);
|
||
//}
|
||
|
||
if (listRoleItem != null && listRoleItem.Count > 0)
|
||
{
|
||
foreach (var item in listRoleItem)
|
||
{
|
||
if (!isAddUser)
|
||
{
|
||
modelUserRole = listUserRole.FirstOrDefault(e => e.USER_ID == modelUser.ID && e.BELONG_ROLE_ID == item.ID);
|
||
}
|
||
|
||
if (modelUserRole == null)
|
||
modelUserRole = new T_FM_USER_BELONG_ROLE();
|
||
|
||
modelUserRole.ID = Guid.NewGuid();
|
||
modelUserRole.ORG_ID = OrgID;
|
||
modelUserRole.USER_ID = modelUser.ID;
|
||
modelUserRole.BELONG_ROLE_ID = item.ID;
|
||
modelUserRole.CREATE_TIME = dtNow;
|
||
|
||
listUserRoleAdd.Add(modelUserRole);
|
||
listUserRole.Add(modelUserRole);
|
||
}
|
||
modelUserRole = null;
|
||
}
|
||
|
||
//姓名 工号不能变 都添加
|
||
listUserAdd.Add(modelUser);
|
||
listPersonAdd.Add(modelPerson);
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 提示 行:1,列:2、3、4;行:2,列:1 不能为空、。。。!
|
||
|
||
string strEmptyError = string.Empty;
|
||
if (dicIndexEmpty.Count > 0)
|
||
{
|
||
int colIndex = 0;
|
||
foreach (var item in dicIndexEmpty)
|
||
{
|
||
strEmptyError += "行:" + item.Key + ",列:";
|
||
colIndex = 0;
|
||
foreach (var itemVal in item.Value)
|
||
{
|
||
strEmptyError += (colIndex > 0 ? "、" : "") + itemVal;
|
||
colIndex++;
|
||
}
|
||
strEmptyError += ";";
|
||
}
|
||
strEmptyError = strEmptyError.Substring(0, strEmptyError.Length - 1) + "不能为空!";
|
||
}
|
||
|
||
string strDepartment10Error = string.Empty;
|
||
if (listDepartment10Index != null && listDepartment10Index.Count > 0)
|
||
{
|
||
strDepartment10Error = "部门名称层级异常:" + string.Join(",", listDepName10) + ",行:" + string.Join(',', listDepartment10Index);
|
||
}
|
||
|
||
string strDepartment15Error = string.Empty;
|
||
if (listDepartment15Index != null && listDepartment15Index.Count > 0)
|
||
{
|
||
strDepartment15Error = "车间名称层级异常:" + string.Join(",", listDepName15) + ",行:" + string.Join(',', listDepartment15Index);
|
||
}
|
||
|
||
string strDepartment13Error = string.Empty;
|
||
if (listDepartment13Index != null && listDepartment13Index.Count > 0)
|
||
{
|
||
strDepartment13Error = "组织数据异常:有车间名称没有部门名称,行:" + string.Join(',', listDepartment13Index);
|
||
}
|
||
|
||
string strDepartment35Error = string.Empty;
|
||
if (listDepartment35Index != null && listDepartment35Index.Count > 0)
|
||
{
|
||
strDepartment35Error = "组织数据异常:有班组名称没有车间名称,行:" + string.Join(',', listDepartment35Index);
|
||
}
|
||
|
||
string strPHONEError = string.Empty;
|
||
if (listPHONEIndex != null && listPHONEIndex.Count > 0)
|
||
{
|
||
strPHONEError = "手机号码格式错误:" + string.Join(",", listStrPHONE) + ",行:" + string.Join(',', listPHONEIndex);
|
||
}
|
||
|
||
string strID_CARDError = string.Empty;
|
||
if (listID_CARDIndex != null && listID_CARDIndex.Count > 0)
|
||
{
|
||
strPHONEError = "身份证号格式错误:" + string.Join(",", strID_CARDError) + ",行:" + string.Join(',', listID_CARDIndex);
|
||
}
|
||
|
||
string strSEXError = string.Empty;
|
||
if (listSEXIndex != null && listSEXIndex.Count > 0)
|
||
{
|
||
strSEXError = "性别错误,只能【男/女】:" + string.Join(",", listStrSEX) + ",行:" + string.Join(',', listSEXIndex);
|
||
}
|
||
|
||
string strENTRYTIMEError = string.Empty;
|
||
if (listENTRYTIMEIndex != null && listENTRYTIMEIndex.Count > 0)
|
||
{
|
||
strENTRYTIMEError = "入职日期:" + string.Join(",", listStrENTRYTIME) + ",行:" + string.Join(',', listENTRYTIMEIndex);
|
||
}
|
||
|
||
string strWORKINGYEARError = string.Empty;
|
||
if (listWORKINGYEARIndex != null && listWORKINGYEARIndex.Count > 0)
|
||
{
|
||
strWORKINGYEARError = "工龄:" + string.Join(",", listStrENTRYTIME) + ",行:" + string.Join(',', listWORKINGYEARIndex);
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strEmptyError))
|
||
{
|
||
Msg += strEmptyError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strDepartment10Error))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strDepartment10Error;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strDepartment15Error))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strDepartment15Error;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strDepartment13Error))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strDepartment13Error;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strDepartment35Error))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strDepartment35Error;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strPHONEError))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strPHONEError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strID_CARDError))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strID_CARDError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strSEXError))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strSEXError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strENTRYTIMEError))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strENTRYTIMEError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strWORKINGYEARError))
|
||
{
|
||
Msg += (Msg.Length > 0 ? ";\r\n" : "") + strWORKINGYEARError;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(Msg))
|
||
{
|
||
throw new Exception(Msg);
|
||
}
|
||
|
||
#endregion
|
||
|
||
this.UnifiedCommit(() =>
|
||
{
|
||
if (listDepAdd != null && listDepAdd.Any())
|
||
BantchSaveEntityNoCommit(listDepAdd);
|
||
if (listPersonAdd != null && listPersonAdd.Any())
|
||
BantchSaveEntityNoCommit(listPersonAdd);
|
||
if (listUserAdd != null && listUserAdd.Any())
|
||
BantchSaveEntityNoCommit(listUserAdd);
|
||
if (listUserPostAdd != null && listUserPostAdd.Any())
|
||
BantchSaveEntityNoCommit(listUserPostAdd);
|
||
if (listApproveRoleAdd != null && listApproveRoleAdd.Any())
|
||
BantchSaveEntityNoCommit(listApproveRoleAdd);
|
||
if (listUserRoleAdd != null && listUserRoleAdd.Any())
|
||
BantchSaveEntityNoCommit(listUserRoleAdd);
|
||
});
|
||
|
||
|
||
#region 总部
|
||
|
||
if (isHead)
|
||
{
|
||
//除了总部 每个子公司都添加 人员信息
|
||
//depID 变成公司的
|
||
//人员的岗位ID变成null
|
||
string conn = string.Empty;
|
||
List<string> listConn = new List<string>();
|
||
using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"]))
|
||
{
|
||
List<Guid> listConnID = context.GetEntities<T_OP_TENANT>(e => e.DB_CONN_ID.HasValue && e.CODE != telnetCode, null, null).Select(e => e.DB_CONN_ID.Value).ToList();
|
||
|
||
var listDbConn = context.GetEntities<T_OP_TENANT_DB_CONN>(e => listConnID.Contains(e.ID), null, null);
|
||
|
||
foreach (var item in listDbConn)
|
||
{
|
||
conn = item.DB_CONN;
|
||
if (ConfigurationManager.AppSettings["Env"] == ((int)EnvType.外网).ToString())
|
||
{
|
||
conn = item.DB_CONN_WAN;
|
||
}
|
||
if (!string.IsNullOrEmpty(conn) && !listConn.Contains(conn))
|
||
{
|
||
listConn.Add(conn);
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach (var itemConn in listConn)
|
||
{
|
||
using (var context = new MigrationContext(itemConn))
|
||
{
|
||
var depCompay = context.GetEntity<T_FM_DEPARTMENT>(e => e.DEPARTMENT_TYPE == (int)FMDepartmentType.Company && e.ENABLE_STATUS == 0 && !e.IS_DELETED, new string[] { "ID", "ORG_ID", "CREATER_ID" }, null);
|
||
if (depCompay.ID != Guid.Empty)
|
||
{
|
||
foreach (var item in listPersonAdd)
|
||
{
|
||
item.POST_ID = null;
|
||
item.DEPARTMENT_ID = depCompay.ID;
|
||
item.CREATER_ID = depCompay.CREATER_ID;
|
||
item.ORG_ID = depCompay.ORG_ID;
|
||
item.POST_ID = null;
|
||
}
|
||
foreach (var item in listUserAdd)
|
||
{
|
||
item.DEPARTMENT_ID = depCompay.ID;
|
||
item.CREATER_ID = depCompay.CREATER_ID;
|
||
item.ORG_ID = depCompay.ORG_ID;
|
||
item.APPROVE_ROLE_ID = null;
|
||
}
|
||
try
|
||
{
|
||
context.AddEntities(listPersonAdd);
|
||
context.AddEntities(listUserAdd);
|
||
context.SaveChanges();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
Msg = "导入成功!\r\n用户信息:" + listUserAdd.Count + "条" + (listDepAdd.Count > 0 ? ("、组织信息:" + listDepAdd.Count + "条") : "") + (listUserPostAdd.Count > 0 ? ("、岗位信息:" + listUserPostAdd.Count + "条") : "") + (listApproveRoleAdd.Count > 0 ? ("、审批角色信息:" + listApproveRoleAdd.Count + "条") : "") + "!";
|
||
|
||
|
||
return true;
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |