1
This commit is contained in:
parent
efcb774a64
commit
f69928e437
@ -143,7 +143,7 @@ namespace APT.BaseData.Domain.Enums
|
||||
/// <summary>
|
||||
/// 班组 20
|
||||
/// </summary>
|
||||
[Description("车间")]
|
||||
[Description("班组")]
|
||||
Class = 20,
|
||||
}
|
||||
|
||||
|
||||
@ -13,9 +13,14 @@ 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.BI;
|
||||
using APT.MS.Domain.Entities.SK;
|
||||
using APT.MS.Domain.Enums;
|
||||
using APT.MS.Domain.Enums.SK;
|
||||
using APT.Utility;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@ -23,6 +28,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Security.Cryptography;
|
||||
using static NPOI.HSSF.Util.HSSFColor;
|
||||
|
||||
namespace APT.BS.WebApi.Controllers.Api
|
||||
{
|
||||
@ -733,12 +739,12 @@ namespace APT.BS.WebApi.Controllers.Api
|
||||
|
||||
//获取数据
|
||||
Dictionary<int, int> startRowIndexs = new Dictionary<int, int>();
|
||||
startRowIndexs.Add(0, 0);//根据Excel格式数据赋值
|
||||
startRowIndexs.Add(0, 1);//根据Excel格式数据赋值
|
||||
DataSet dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
|
||||
string Msg = string.Empty;
|
||||
|
||||
bool isOK = InsertModel(dataTables.Tables[0], orgId.Value, telnetCode, ref Msg);
|
||||
|
||||
//bool isOK = InsertModel2(dataTables.Tables[0], orgId.Value, telnetCode, ref Msg);
|
||||
try
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
@ -1670,6 +1676,196 @@ namespace APT.BS.WebApi.Controllers.Api
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InsertModel2(DataTable dtSource, Guid? orgId, string telnetCode, ref string Msg, int rowIndex = 1)
|
||||
{
|
||||
var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
||||
if (dtSource == null || dtSource.Rows.Count < rowIndex)
|
||||
{
|
||||
Msg = "未获取到导入数据";
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
int rowAll = dtSource.Rows.Count;
|
||||
List<T_FM_USER> userLists = new List<T_FM_USER>();
|
||||
List<T_FM_PERSON> userPersonLists = new List<T_FM_PERSON>();
|
||||
List<T_FM_USER_BELONG_ROLE> userRoleLists = new List<T_FM_USER_BELONG_ROLE>();
|
||||
List<T_FM_USER_PRODUCTION_UNIT> userUnitLists = new List<T_FM_USER_PRODUCTION_UNIT>();
|
||||
if (rowAll == 1)
|
||||
{
|
||||
throw new Exception("导入必须两条以上,一条请直接新增");
|
||||
}
|
||||
var departs = this.GetEntities<T_FM_DEPARTMENT>(t => t.ENABLE_STATUS == 0, new BaseFilter(orgId));
|
||||
var roles = this.GetEntities<T_FM_ROLE>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
||||
var units = this.GetEntities<T_FM_ENUMS>(t => t.CODE == "BSMineTypeEnum", new BaseFilter(orgId));
|
||||
var posts = this.GetEntities<T_FM_USER_POST>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
||||
var approves = this.GetEntities<T_PF_APPROVAL_ROLE>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
||||
for (int i = 0; i < rowAll; i++)
|
||||
{
|
||||
var company = departs.FirstOrDefault(t => t.NAME == dtSource.Rows[i][0].ToString().Trim());
|
||||
var depart = departs.FirstOrDefault(t => t.NAME == dtSource.Rows[i][1].ToString().Trim());
|
||||
var shop = departs.FirstOrDefault(t => t.NAME == dtSource.Rows[i][2].ToString().Trim());
|
||||
var classFirst = departs.FirstOrDefault(t => t.NAME == dtSource.Rows[i][3].ToString().Trim());
|
||||
var post = posts.FirstOrDefault(t => t.NAME == dtSource.Rows[i][8].ToString().Trim());
|
||||
Guid? depId = null;
|
||||
int? minetype = 0;
|
||||
if (classFirst != null)
|
||||
{
|
||||
depId = classFirst.ID;
|
||||
minetype=classFirst.MineType;
|
||||
}
|
||||
else if (shop != null)
|
||||
{
|
||||
depId = shop.ID;
|
||||
minetype = shop.MineType;
|
||||
}
|
||||
else if (depart != null)
|
||||
{
|
||||
depId = depart.ID;
|
||||
minetype = depart.MineType;
|
||||
}
|
||||
else
|
||||
{
|
||||
depId = company.ID;
|
||||
minetype = company.MineType;
|
||||
}
|
||||
var sex = dtSource.Rows[i][9].ToString().Trim();
|
||||
T_FM_PERSON person = new T_FM_PERSON();
|
||||
person.ID = Guid.NewGuid();
|
||||
person.ORG_ID = orgId;
|
||||
person.NAME = dtSource.Rows[i][4].ToString().Trim();
|
||||
person.CODE = dtSource.Rows[i][5].ToString().Trim();
|
||||
person.TEL = dtSource.Rows[i][6].ToString().Trim();
|
||||
person.SEX = sex == "男" ? 1 : 0;
|
||||
person.DEPARTMENT_ID = depId;
|
||||
person.POST_ID = post?.ID;
|
||||
userPersonLists.Add(person);
|
||||
T_FM_USER user = new T_FM_USER();
|
||||
user.ID = Guid.NewGuid();
|
||||
user.ORG_ID = orgId;
|
||||
user.PERSON_ID = person.ID;
|
||||
user.NAME = dtSource.Rows[i][4].ToString().Trim();
|
||||
user.CODE = dtSource.Rows[i][5].ToString().Trim();
|
||||
user.PHONE = dtSource.Rows[i][6].ToString().Trim();
|
||||
user.ID_CARD = dtSource.Rows[i][7].ToString().Trim();
|
||||
user.DEPARTMENT_ID = depId;
|
||||
user.SEX = sex == "男" ? 1 : 0;
|
||||
user.MineType = minetype.ToString();
|
||||
var inTime = dtSource.Rows[i][10].ToString().Trim();
|
||||
if (string.IsNullOrEmpty(inTime))
|
||||
{
|
||||
inTime = DateTime.Now.ToShortTimeString();
|
||||
}
|
||||
user.ENTRYTIME = DateTime.Parse(inTime);
|
||||
var yearInt = dtSource.Rows[i][11].ToString().Trim();
|
||||
if (string.IsNullOrEmpty(yearInt))
|
||||
{
|
||||
yearInt = "0";
|
||||
}
|
||||
user.WORKINGYEAR = int.Parse(yearInt);
|
||||
var approve = approves.FirstOrDefault(t => t.NAME == dtSource.Rows[i][12].ToString().Trim());
|
||||
user.APPROVE_ROLE_ID = approve?.ID;
|
||||
//if (!string.IsNullOrEmpty(user.NAME) && !string.IsNullOrEmpty(user.CODE))
|
||||
//{
|
||||
// MD5 md5 = MD5.Create();
|
||||
// string code = DataHelper.GetCodeNO(user.CODE);
|
||||
// string nameHead = DataHelper.MkPinyinString(user.NAME);
|
||||
// string NewPwd = DataHelper.MD5Encrypt32(md5, nameHead + code);
|
||||
// user.PASSWORD = NewPwd;
|
||||
//}
|
||||
userLists.Add(user);
|
||||
#region 增加新增人员到ops表
|
||||
using (var context = new MigrationContext(ConfigurationManager.ConnectionStrings["default"]))
|
||||
{
|
||||
var tennant = context.GetEntity<T_OP_TENANT>(t => t.ID == orgId, new string[] { "CODE" }).CODE;
|
||||
T_OP_ALLUSER alluser = new T_OP_ALLUSER();
|
||||
alluser.ID = user.ID;
|
||||
alluser.CODE = user.CODE;
|
||||
alluser.TENANT = tennant;
|
||||
alluser.ORG_ID = orgId;
|
||||
alluser.PHONE = user.PHONE;
|
||||
context.AddEntity(alluser);
|
||||
context.SaveChanges();
|
||||
}
|
||||
#endregion
|
||||
if (user.APPROVE_ROLE_ID != null)
|
||||
{
|
||||
var role1 = roles.FirstOrDefault(t => t.NAME == "负责人");
|
||||
var role2 = roles.FirstOrDefault(t => t.NAME == "App用户");
|
||||
if (role1 != null)
|
||||
{
|
||||
T_FM_USER_BELONG_ROLE belongRole = new T_FM_USER_BELONG_ROLE();
|
||||
belongRole.ID = Guid.NewGuid();
|
||||
belongRole.USER_ID = user.ID;
|
||||
belongRole.BELONG_ROLE_ID = role1.ID;
|
||||
belongRole.ORG_ID = orgId;
|
||||
userRoleLists.Add(belongRole);
|
||||
}
|
||||
if (role2 != null)
|
||||
{
|
||||
T_FM_USER_BELONG_ROLE belongRole = new T_FM_USER_BELONG_ROLE();
|
||||
belongRole.ID = Guid.NewGuid();
|
||||
belongRole.USER_ID = user.ID;
|
||||
belongRole.BELONG_ROLE_ID = role2.ID;
|
||||
belongRole.ORG_ID = orgId;
|
||||
userRoleLists.Add(belongRole);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var role1 = roles.FirstOrDefault(t => t.NAME == "作业员");
|
||||
var role2 = roles.FirstOrDefault(t => t.NAME == "App用户");
|
||||
if (role1 != null)
|
||||
{
|
||||
T_FM_USER_BELONG_ROLE belongRole = new T_FM_USER_BELONG_ROLE();
|
||||
belongRole.ID = Guid.NewGuid();
|
||||
belongRole.USER_ID = user.ID;
|
||||
belongRole.BELONG_ROLE_ID = role1.ID;
|
||||
belongRole.ORG_ID = orgId;
|
||||
userRoleLists.Add(belongRole);
|
||||
}
|
||||
if (role2 != null)
|
||||
{
|
||||
T_FM_USER_BELONG_ROLE belongRole = new T_FM_USER_BELONG_ROLE();
|
||||
belongRole.ID = Guid.NewGuid();
|
||||
belongRole.USER_ID = user.ID;
|
||||
belongRole.BELONG_ROLE_ID = role2.ID;
|
||||
belongRole.ORG_ID = orgId;
|
||||
userRoleLists.Add(belongRole);
|
||||
}
|
||||
}
|
||||
var unit = units.FirstOrDefault(t => t.VALUE == minetype);
|
||||
if (unit != null)
|
||||
{
|
||||
T_FM_USER_PRODUCTION_UNIT pro = new T_FM_USER_PRODUCTION_UNIT();
|
||||
pro.ID = Guid.NewGuid();
|
||||
pro.ORG_ID = orgId;
|
||||
pro.USER_ID = user.ID;
|
||||
pro.ENUMS_ID = unit.ID;
|
||||
userUnitLists.Add(pro);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Msg))
|
||||
{
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
if (userLists != null && userLists.Any())
|
||||
BantchAddEntityNoCommit(userLists);
|
||||
if (userUnitLists != null && userUnitLists.Any())
|
||||
BantchAddEntityNoCommit(userUnitLists);
|
||||
if (userRoleLists != null && userRoleLists.Any())
|
||||
BantchAddEntityNoCommit(userRoleLists);
|
||||
if (userPersonLists != null && userPersonLists.Any())
|
||||
BantchAddEntityNoCommit(userPersonLists);
|
||||
});
|
||||
Msg = "导入成功!";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user