diff --git a/DOAN.Admin.WebApi/Controllers/MES/product/ProWorkorderController.cs b/DOAN.Admin.WebApi/Controllers/MES/product/ProWorkorderController.cs
index 95e6ab5..88c86b1 100644
--- a/DOAN.Admin.WebApi/Controllers/MES/product/ProWorkorderController.cs
+++ b/DOAN.Admin.WebApi/Controllers/MES/product/ProWorkorderController.cs
@@ -177,7 +177,7 @@ namespace DOAN.Admin.WebApi.Controllers
/// 导入
///
/// 使用IFromFile必须使用name属性否则获取不到文件
- /// 导入成功数
+ /// 导入成功数 若-1 则excel读取异常
[HttpPost("importData")]
[Log(Title = "生产工单导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)]
diff --git a/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx b/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx
index b846314..d593acb 100644
Binary files a/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx and b/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx differ
diff --git a/DOAN.Repository/BaseRepository.cs b/DOAN.Repository/BaseRepository.cs
index b33144f..b30211a 100644
--- a/DOAN.Repository/BaseRepository.cs
+++ b/DOAN.Repository/BaseRepository.cs
@@ -17,7 +17,15 @@ namespace DOAN.Repository
///
public class BaseRepository : SimpleClient where T : class, new()
{
- public string XueHua=SnowFlakeSingle.Instance.NextId().ToString();
+
+
+ public string XueHua
+ {
+ get
+ {
+ return SnowFlakeSingle.Instance.NextId().ToString();
+ }
+ }
public ITenant itenant = null;//多租户事务
public BaseRepository(ISqlSugarClient context = null) : base(context)
{
diff --git a/DOAN.Service/MES/product/ProWorkorderService.cs b/DOAN.Service/MES/product/ProWorkorderService.cs
index e8629df..c75666b 100644
--- a/DOAN.Service/MES/product/ProWorkorderService.cs
+++ b/DOAN.Service/MES/product/ProWorkorderService.cs
@@ -24,6 +24,7 @@ using NPOI.XWPF.UserModel;
using NPOI.HSSF.UserModel;
using Microsoft.AspNetCore.Components.Forms;
using System.Globalization;
+using System.ComponentModel;
namespace DOAN.Service.MES.product
{
@@ -185,6 +186,7 @@ namespace DOAN.Service.MES.product
.SetColumns(it => new ProWorkorder() { Sort = it.Sort + 10 })
.ExecuteCommand();
proWorkorder.Sort = sortNum;
+ proWorkorder.Status = 1;
Context.Insertable(proWorkorder).ExecuteCommand();
@@ -252,7 +254,7 @@ namespace DOAN.Service.MES.product
///
///
///
- public int ImportData(IFormFile formFile,string username)
+ public int ImportData2(IFormFile formFile, string username)
{
int result = 0;
List workorderList = new();
@@ -260,36 +262,24 @@ namespace DOAN.Service.MES.product
using (var stream = formFile.OpenReadStream())
{
IWorkbook workbook = new XSSFWorkbook(stream);
- ISheet sheet = workbook.GetSheetAt(1);
+ ISheet sheet = workbook.GetSheetAt(0);
// 处理第2行 获取日期
-
+
IRow secondRow = sheet.GetRow(1);
NPOI.SS.UserModel.ICell cell = secondRow.GetCell(0);
- if (cell.CellType == CellType.Numeric) // 检查单元格是否为数字类型
- {
- if (HSSFDateUtil.IsCellDateFormatted(cell)) // 判断是否为日期格式
- {
- // 将单元格的数字值转换为DateTime
- dateValue = cell.DateCellValue.Value;
- }
- }
- else if (cell.CellType == CellType.String)
- {
- // 处理字符串类型的日期,如果有的话
- string textValue = cell.StringCellValue;
- if (DateTime.TryParse(textValue, out DateTime parsedDate))
- {
- dateValue = parsedDate;
+ // 将单元格的数字值转换为DateTime
+ dateValue = cell.DateCellValue.Value;
+
+
+
- }
- }
// 遍历每一行
- for (int row = 2; row <= sheet.LastRowNum; row++)
+ for (int row = 3; row <= sheet.LastRowNum; row++)
{
IRow currentRow = sheet.GetRow(row);
if (currentRow != null) // 确保行不为空
@@ -333,50 +323,175 @@ namespace DOAN.Service.MES.product
}
}
+ List updates = new();
List inserts = new();
- if (workorderList.Count > 0&& dateValue> DateTime.MinValue)
+ try
{
- List Exists= Context.Queryable().Where(it => it.WorkorderDate == dateValue).Where(it=>it.Status==0).ToList();
-
- foreach (ProWorkorder item in Exists)
+ if (workorderList.Count > 0 && dateValue > DateTime.MinValue)
{
+ List Exists = Context.Queryable().Where(it => it.WorkorderDate == dateValue).Where(it => it.Status == 0).ToList();
+
foreach (ProWorkorder item2 in workorderList)
{
- if(item.ProductionCode==item2.ProductionCode)
+ int index = 0;
+ foreach (ProWorkorder item in Exists)
+ {
+ if (item.ProductionCode == item2.ProductionCode)
+ {
+ item2.Id = item.Id;
+ item2.UpdatedBy = username;
+ item2.UpdatedTime = DateTime.Now;
+ item2.WorkorderDate = dateValue;
+
+ item2.Year = dateValue.Year;
+
+ CultureInfo culture = CultureInfo.CurrentCulture;
+ item2.Week = culture.Calendar.GetWeekOfYear(dateValue, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek);
+ item2.Date = (int)dateValue.DayOfWeek;
+ updates.Add(item2);
+ index++;
+ }
+ continue;
+ }
+
+ if (index == 0)
{
item2.Id = XueHua;
item2.CreatedBy = username;
item2.CreatedTime = DateTime.Now;
item2.WorkorderDate = dateValue;
- item.Status = 0;
- item.Year = dateValue.Year;
-
+ item2.Status = 1;
+ item2.Year = dateValue.Year;
+
CultureInfo culture = CultureInfo.CurrentCulture;
- item.Week = culture.Calendar.GetWeekOfYear(dateValue, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek);
- item.Date =(int) dateValue.DayOfWeek;
+ item2.Week = culture.Calendar.GetWeekOfYear(dateValue, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek);
+ item2.Date = (int)dateValue.DayOfWeek;
inserts.Add(item2);
}
}
+
+
+ }
+ if (inserts.Count > 0 || updates.Count > 0)
+ {
+ UseTran2(() =>
+ {
+ //string[] codes = inserts.Select(it => it.ProductionCode).ToArray();
+ //Context.Deleteable().Where(it => it.WorkorderDate == dateValue)
+ //.Where(it => it.Status == 0).Where(it => codes.Contains(it.ProductionCode))
+ //.ExecuteCommand();
+ result += Context.Insertable(inserts).ExecuteCommand();
+ result += Context.Updateable(updates).IgnoreColumns(true).ExecuteCommand();
+
+
+
+ });
+
+
+
}
+ }
+ catch (Exception ex)
+ {
+ result = -1;
}
- if (inserts.Count > 0) {
- UseTran2(() =>
+
+
+ return result;
+ }
+
+
+ ///
+ /// 导入工单 必须整删除 整改
+ ///
+ ///
+ ///
+ public int ImportData(IFormFile formFile, string username)
+ {
+ int result = 0;
+ List workorderList = new();
+ DateTime dateValue = DateTime.MinValue;
+ using (var stream = formFile.OpenReadStream())
+ {
+ IWorkbook workbook = new XSSFWorkbook(stream);
+ ISheet sheet = workbook.GetSheetAt(0);
+ // 处理第2行 获取日期
+
+ IRow secondRow = sheet.GetRow(1);
+ NPOI.SS.UserModel.ICell cell = secondRow.GetCell(0);
+
+
+ // 将单元格的数字值转换为DateTime
+ dateValue = cell.DateCellValue.Value;
+
+
+
+
+
+
+
+ // 遍历每一行
+ for (int row = 3; row <= sheet.LastRowNum; row++)
{
- string[] codes= inserts.Select(it => it.ProductionCode).ToArray();
- Context.Deleteable().Where(it => it.WorkorderDate == dateValue)
- .Where(it => it.Status == 0).Where(it => codes.Contains(it.ProductionCode))
- .ExecuteCommand();
- result= Context.Insertable(inserts).ExecuteCommand();
+ IRow currentRow = sheet.GetRow(row);
+ if (currentRow != null) // 确保行不为空
+ {
+ ProWorkorder workorder = new ProWorkorder();
+ NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(0);
+ workorder.ProductionCode = currentCell_01.ToString();
+
+ NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(1);
+ workorder.ProductionName = currentCell_02.ToString();
+
+ NPOI.SS.UserModel.ICell currentCell_03 = currentRow.GetCell(2);
+ workorder.CustomCode = currentCell_03.ToString();
+
+ NPOI.SS.UserModel.ICell currentCell_04 = currentRow.GetCell(3);
+ workorder.Unit = currentCell_04.ToString();
+
+ NPOI.SS.UserModel.ICell currentCell_05 = currentRow.GetCell(4);
+ workorder.DeliveryNum = (int)currentCell_05.NumericCellValue;
- });
-
-
-
+ NPOI.SS.UserModel.ICell currentCell_06 = currentRow.GetCell(5);
+ workorder.PackageNum = (int)currentCell_06.NumericCellValue;
+
+
+ NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(6);
+ workorder.GroupId = (int)currentCell_07.NumericCellValue;
+
+
+ NPOI.SS.UserModel.ICell currentCell_08 = currentRow.GetCell(7);
+ workorder.LineId = (int)currentCell_08.NumericCellValue;
+
+
+ NPOI.SS.UserModel.ICell currentCell_09 = currentRow.GetCell(8);
+ workorder.Remark = currentCell_09.StringCellValue;
+
+ workorder.Id = XueHua;
+ workorder.CreatedBy = username;
+ workorder.CreatedTime = DateTime.Now;
+ workorder.WorkorderDate = dateValue;
+ workorder.Status = 1;
+ workorder.Year = dateValue.Year;
+
+ CultureInfo culture = CultureInfo.CurrentCulture;
+ workorder.Week = culture.Calendar.GetWeekOfYear(dateValue, culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek);
+ workorder.Date = (int)dateValue.DayOfWeek;
+ workorderList.Add(workorder);
+
+ }
+ }
+
}
+ UseTran2(() =>
+ {
+ Context.Deleteable().Where(it => it.WorkorderDate == dateValue).ExecuteCommand();
+ result = Context.Insertable(workorderList).ExecuteCommand();
+ });
return result;
}