增加排班导入功能
This commit is contained in:
parent
dab2a86997
commit
de730d78c6
@ -14,7 +14,7 @@ namespace APT.BaseData.Domain.Entities.FM
|
||||
[Description("节点ID")]
|
||||
|
||||
[DataFieldForeignKey("Nav_DepartMent","Nav_DepartmentScheduling")]
|
||||
public Guid DEPARTMENT_ID { get; set; }
|
||||
public Guid? DEPARTMENT_ID { get; set; }
|
||||
|
||||
[Description("日历配置ID")]
|
||||
[DataFieldForeignKey("Nav_DepartmentCalendarConfig")]
|
||||
@ -33,7 +33,7 @@ namespace APT.BaseData.Domain.Entities.FM
|
||||
|
||||
[Description("班次ID")]
|
||||
[DataFieldForeignKey("Nav_Class")]
|
||||
public Guid CLASS_ID { get; set; }
|
||||
public Guid? CLASS_ID { get; set; }
|
||||
|
||||
[Description("班组ID")]
|
||||
[DataFieldForeignKey("Nav_Team")]
|
||||
|
||||
61925
APT.Data.Migrations/Migrations/20240527032720_wjn202405-2701.Designer.cs
generated
Normal file
61925
APT.Data.Migrations/Migrations/20240527032720_wjn202405-2701.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace APT.Data.Migrations.Migrations
|
||||
{
|
||||
public partial class wjn2024052701 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "DEPARTMENT_ID",
|
||||
table: "T_FM_DEPARTMENT_SCHEDULING",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CLASS_ID",
|
||||
table: "T_FM_DEPARTMENT_SCHEDULING",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "DEPARTMENT_ID",
|
||||
table: "T_FM_DEPARTMENT_SCHEDULING",
|
||||
type: "uniqueidentifier",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CLASS_ID",
|
||||
table: "T_FM_DEPARTMENT_SCHEDULING",
|
||||
type: "uniqueidentifier",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2222,7 +2222,7 @@ namespace APT.Data.Migrations.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("CLASS_ID")
|
||||
b.Property<Guid?>("CLASS_ID")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("CREATER_ID")
|
||||
@ -2237,7 +2237,7 @@ namespace APT.Data.Migrations.Migrations
|
||||
b.Property<Guid?>("DEPARTMENT_CALENDAR_CONFIG_ID")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("DEPARTMENT_ID")
|
||||
b.Property<Guid?>("DEPARTMENT_ID")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("ENABLE_STATUS")
|
||||
@ -46062,8 +46062,7 @@ namespace APT.Data.Migrations.Migrations
|
||||
b.HasOne("APT.BaseData.Domain.Entities.FM.T_FM_CLASS", "Nav_Class")
|
||||
.WithMany()
|
||||
.HasForeignKey("CLASS_ID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("APT.BaseData.Domain.Entities.FM.T_FM_DEPARTMENT_CALENDAR_CONFIG", "Nav_DepartmentCalendarConfig")
|
||||
.WithMany()
|
||||
@ -46073,8 +46072,7 @@ namespace APT.Data.Migrations.Migrations
|
||||
b.HasOne("APT.BaseData.Domain.Entities.FM.T_FM_DEPARTMENT", "Nav_DepartMent")
|
||||
.WithMany("Nav_DepartmentScheduling")
|
||||
.HasForeignKey("DEPARTMENT_ID")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("APT.Infrastructure.Core.T_FM_ORGANIZATION", "Nav_Org")
|
||||
.WithMany()
|
||||
|
||||
@ -10,6 +10,9 @@ using System.Linq;
|
||||
using APT.BaseData.Domain.Enums;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using APT.BaseData.Domain.ApiModel;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
|
||||
namespace APT.FM.WebApi.Controllers.Api.FM
|
||||
{
|
||||
@ -98,6 +101,106 @@ namespace APT.FM.WebApi.Controllers.Api.FM
|
||||
return true;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取导入数据
|
||||
/// 参考 [Route("api/PF/Import")]
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, Route("GetImportData")]
|
||||
public JsonActionResult<ImportDataModel> GetImportDataUser()
|
||||
{
|
||||
return SafeExecute<ImportDataModel>(() =>
|
||||
{
|
||||
var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
|
||||
var httpRequest = this.HttpContext.Request;
|
||||
string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织
|
||||
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, 1);//根据Excel格式数据赋值
|
||||
var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
|
||||
string Msg = string.Empty;
|
||||
|
||||
bool isOK = InsertModelUser(dataTables.Tables[0], orgId, 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="Msg"></param>
|
||||
/// <param name="rowIndex"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public bool InsertModelUser(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1)
|
||||
{
|
||||
if (dtSource == null || dtSource.Rows.Count < rowIndex)
|
||||
{
|
||||
Msg = "未获取到导入数据";
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
int rowAll = dtSource.Rows.Count;
|
||||
if (!string.IsNullOrEmpty(Msg))
|
||||
{
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
List<T_FM_DEPARTMENT_SCHEDULING> items = new List<T_FM_DEPARTMENT_SCHEDULING>();
|
||||
var teams = GetEntities<T_FM_TEAM>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
||||
for (int i = 0; i < rowAll; i++)
|
||||
{
|
||||
T_FM_DEPARTMENT_SCHEDULING item = new T_FM_DEPARTMENT_SCHEDULING();
|
||||
item.ID = Guid.NewGuid();
|
||||
var teamName = dtSource.Rows[i][0].ToString().Trim();
|
||||
var team = teams.FirstOrDefault(t => t.NAME == teamName);
|
||||
if (team == null)
|
||||
{
|
||||
Msg = "未能找到对应班组";
|
||||
throw new Exception(Msg);
|
||||
}
|
||||
item.TEAM_ID = team.ID;
|
||||
item.DATE_TIME = DateTime.Parse(dtSource.Rows[i][1].ToString().Trim());
|
||||
item.START_TIME = DateTime.Parse(dtSource.Rows[i][1].ToString().Trim());
|
||||
item.END_TIME = DateTime.Parse(dtSource.Rows[i][2].ToString().Trim());
|
||||
item.ORG_ID = orgId;
|
||||
items.Add(item);
|
||||
}
|
||||
UnifiedCommit(() =>
|
||||
{
|
||||
if (items != null && items.Any())
|
||||
BantchAddEntityNoCommit(items);
|
||||
});
|
||||
Msg = "导入成功!";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ namespace APT.FM.WebApi.Controllers.Api.FM
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
lastClassId = pageData[index].CLASS_ID;
|
||||
lastClassId = (Guid)pageData[index].CLASS_ID;
|
||||
var nowClass = sh.Nav_DepartmentCalendarConfigDetail.FirstOrDefault(i => i.CLASS_ID == lastClassId);
|
||||
classIndex = sh.Nav_DepartmentCalendarConfigDetail.Count(i => i.NUM < nowClass.NUM);
|
||||
dayIndex++;
|
||||
|
||||
@ -84,7 +84,7 @@ namespace APT.PP.WebApi.Controllers
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
lastClassId = pageData[index].CLASS_ID;
|
||||
lastClassId = (Guid)pageData[index].CLASS_ID;
|
||||
var nowClass = sh.Nav_DepartmentCalendarConfigDetail.FirstOrDefault(i => i.CLASS_ID == lastClassId);
|
||||
classIndex = sh.Nav_DepartmentCalendarConfigDetail.Count(i => i.NUM < nowClass.NUM);
|
||||
dayIndex++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user