1234 lines
47 KiB
C#
1234 lines
47 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using DOAN.Model;
|
|
|
|
using DOAN.Model.MES.product;
|
|
using DOAN.Model.MES.product.Dto;
|
|
|
|
using DOAN.Repository;
|
|
using DOAN.Service.MES.product.IService;
|
|
|
|
using System.Linq;
|
|
using SqlSugar.Extensions;
|
|
using MimeKit.Tnef;
|
|
using DOAN.Model.MES.base_;
|
|
using Microsoft.AspNetCore.Http;
|
|
using DOAN.Model.System;
|
|
using MiniExcelLibs;
|
|
using NPOI.SS.Formula.Functions;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using System.Data.Common;
|
|
using NPOI.XWPF.UserModel;
|
|
using NPOI.HSSF.UserModel;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using System.Globalization;
|
|
using System.ComponentModel;
|
|
using NPOI.Util;
|
|
using DOAN.Model.MES.base_.Dto;
|
|
using Aliyun.OSS;
|
|
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using System.Reflection;
|
|
|
|
using Infrastructure;
|
|
using Infrastructure.Converter;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using DOAN.Model.MES.product;
|
|
|
|
namespace DOAN.Service.MES.product
|
|
{
|
|
/// <summary>
|
|
/// 生产工单Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IProWorkorderService), ServiceLifetime = LifeTime.Transient)]
|
|
public class ProWorkorderService : BaseService<ProWorkorder>, IProWorkorderService
|
|
{
|
|
/// <summary>
|
|
/// 查询生产工单列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<ProWorkorderDto3> GetList(ProWorkorderQueryDto parm)
|
|
{
|
|
if (parm.WorkorderDate != null && parm.WorkorderDate.Length > 0)
|
|
{
|
|
parm.WorkorderDate[0] = parm.WorkorderDate[0].Date;
|
|
parm.WorkorderDate[1] = parm.WorkorderDate[1].Date;
|
|
|
|
}
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.productionName), it => it.productionName.Contains(parm.productionName))
|
|
.AndIF(!string.IsNullOrEmpty(parm.productionCode), it => it.productionCode.Contains(parm.productionCode))
|
|
.AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode)
|
|
.AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode)
|
|
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, it => it.WorkorderDate >= parm.WorkorderDate[0])
|
|
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, it => it.WorkorderDate <= parm.WorkorderDate[1])
|
|
;
|
|
var query = Queryable()
|
|
.Where(predicate.ToExpression());
|
|
var finalQuery = Context.Queryable(query)
|
|
.LeftJoin<BaseMaterialList>((q, m) => q.productionCode == m.Code)
|
|
.LeftJoin<BaseMaterialList>((q, m, m2) => q.productionName == m2.Name)
|
|
.LeftJoin<BaseWorkRoute>((q, m, m2, r) => q.RouteCode == r.Code)
|
|
.LeftJoin<BaseGroup>((q, m, m2, r, g) => q.GroupCode == g.GroupCode)
|
|
.LeftJoin<BaseUnit>((q, m, m2, r, g, u) => q.Unit == u.UnitCode)
|
|
.Select((q, m, m2, r, g, u) => new ProWorkorderDto3()
|
|
{
|
|
IsMatch_material_code = m.Code,
|
|
IsMatch_material_name = m2.Name,
|
|
IsMatch_line = r.Code,
|
|
IsMatch_group = g.GroupCode,
|
|
IsMatch_Unit = u.UnitCode,
|
|
}, true);
|
|
|
|
var response = finalQuery.MergeTable().Distinct().OrderBy(it => it.WorkorderDate).ToPage<ProWorkorderDto3, ProWorkorderDto3>(parm);
|
|
|
|
//var query = Queryable()
|
|
// .Where(predicate.ToExpression());
|
|
////TODO 添加校验
|
|
|
|
//var query1 = Context.Queryable(query).LeftJoin<BaseMaterialList>((q, m) => q.productionCode == m.Code)
|
|
// .Select((q, m) => new ProWorkorderDto3()
|
|
// {
|
|
|
|
// IsMatch_material_code = m.Code
|
|
|
|
// }, true);
|
|
|
|
//var query2 = Context.Queryable(query1).LeftJoin<BaseMaterialList>((q1, m) => q1.productionName == m.Name)
|
|
// .Select((q1, m) => new ProWorkorderDto3()
|
|
// {
|
|
|
|
// IsMatch_material_name = m.Name
|
|
|
|
// }, true);
|
|
|
|
//var query3 = Context.Queryable(query2).LeftJoin<BaseWorkRoute>((q2, r) => q2.RouteCode == r.Code)
|
|
// .Select((q2, r) => new ProWorkorderDto3()
|
|
// {
|
|
// IsMatch_line = r.Code??""
|
|
|
|
// }, true);
|
|
|
|
//var query4 = Context.Queryable(query3).LeftJoin<BaseGroup>((q3, g) => q3.GroupCode == g.GroupCode)
|
|
// .Select((q3, g) => new ProWorkorderDto3()
|
|
// {
|
|
// IsMatch_group = g.GroupCode
|
|
|
|
// }, true);
|
|
//var response = query4.MergeTable().OrderBy(it => it.WorkorderDate).ToPage<ProWorkorderDto3, ProWorkorderDto3>(parm);
|
|
|
|
|
|
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取工单无校验
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<ProWorkorderDto> GetList_NOCheck(ProWorkorderQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<ProWorkorder>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.productionName), it => it.productionName.Contains(parm.productionName))
|
|
.AndIF(!string.IsNullOrEmpty(parm.Workorder), it => it.Workorder.Contains(parm.Workorder))
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.productionCode), it => it.productionCode.Contains(parm.productionCode))
|
|
.AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode)
|
|
.AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode)
|
|
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, it => it.WorkorderDate >= parm.WorkorderDate[0])
|
|
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, it => it.WorkorderDate <= parm.WorkorderDate[1])
|
|
|
|
;
|
|
|
|
var query = Queryable()
|
|
.Where(predicate.ToExpression()).ToPage<ProWorkorder,ProWorkorderDto>(parm);
|
|
|
|
return query;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public ProWorkorder GetInfo(string Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加生产工单
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public ProWorkorder AddProWorkorder(ProWorkorder model)
|
|
{
|
|
model.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改生产工单
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateProWorkorder(ProWorkorder model)
|
|
{
|
|
//增加日志
|
|
/*ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog();
|
|
logObj.Id = XueHua;
|
|
logObj.Workorder = model.Workorder;
|
|
logObj.Log = "修改生产工单";
|
|
logObj.ChangeTime = DateTime.Now;
|
|
logObj.Operator = model.CreatedBy;
|
|
Context.Insertable(logObj).ExecuteCommand();*/
|
|
|
|
var response = Update(model, true);
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生成工单号
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public int Generate_workorder(ProWorkorderQueryDto2 parm)
|
|
{
|
|
DateTime update_time = parm.WorkorderDate.ToLocalTime().Date;
|
|
|
|
List<ProWorkorder> proWorkorderList = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == update_time)
|
|
.Where(it => it.Status == 1)
|
|
.OrderBy(it => it.Sort).ToList();
|
|
string maxs = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == update_time)
|
|
.Where(it => it.Status == 3).Max(it => it.Workorder);
|
|
|
|
|
|
if (proWorkorderList != null && proWorkorderList.Count() > 0)
|
|
{
|
|
|
|
string baseSort = update_time.ToString("yyyyMMdd");
|
|
int index = 1;
|
|
if (!string.IsNullOrEmpty(maxs))
|
|
{
|
|
index = Convert.ToInt32(maxs.Substring(maxs.Length - 3)) + 1;
|
|
|
|
}
|
|
|
|
foreach (ProWorkorder item in proWorkorderList)
|
|
{
|
|
item.Workorder = baseSort + index.ToString("000");
|
|
item.Sort = index * 10;
|
|
index++;
|
|
}
|
|
}
|
|
return Context.Updateable(proWorkorderList).ExecuteCommand();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 插入工单、新增工单
|
|
/// </summary>
|
|
/// <param name="proWorkorder"></param>
|
|
/// <param name="next_id"></param>
|
|
/// <returns></returns>
|
|
///
|
|
public int Insert_workOrder(ProWorkorder proWorkorder, string next_id)
|
|
{
|
|
int result = 0;
|
|
proWorkorder.Id = XueHua;
|
|
proWorkorder.WorkorderDate= DOANConvertDate.ConvertLocalDate(proWorkorder.WorkorderDate??DateTime.MinValue);
|
|
|
|
DateTime handleDate = proWorkorder.WorkorderDate.Value;
|
|
//插入工单
|
|
if (!string.IsNullOrEmpty(next_id) && next_id != "-1")
|
|
{
|
|
// 向前插工单
|
|
UseTran2(() =>
|
|
{
|
|
ProWorkorder maxs = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == handleDate)
|
|
.OrderByDescending(it =>SqlFunc.Right(it.Workorder,3)).First();
|
|
int index = 1;
|
|
if (!string.IsNullOrEmpty(maxs.Workorder))
|
|
{
|
|
index = Convert.ToInt32(maxs.Workorder.Substring(maxs.Workorder.Length - 3)) + 1;
|
|
|
|
}
|
|
proWorkorder.Workorder = "K" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.GroupCode + "_" + proWorkorder.RouteCode + "_" + index.ToString("000");
|
|
|
|
|
|
|
|
int sortNum = Context.Queryable<ProWorkorder>().Where(it => it.Id == next_id).Select(it => it.Sort.Value).First();
|
|
// 调整序号
|
|
Context.Updateable<ProWorkorder>()
|
|
.Where(it => it.WorkorderDate == handleDate)
|
|
.Where(it => it.Sort >= sortNum)
|
|
.SetColumns(it => new ProWorkorder() { Sort = it.Sort + 10 })
|
|
.ExecuteCommand();
|
|
proWorkorder.Sort = sortNum;
|
|
proWorkorder.Status = 1;
|
|
|
|
|
|
|
|
//增加日志
|
|
ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog();
|
|
logObj.Id = XueHua;
|
|
logObj.Workorder = proWorkorder.Workorder;
|
|
logObj.Log = "手动新增";
|
|
logObj.ChangeTime = DateTime.Now;
|
|
logObj.Operator = proWorkorder.CreatedBy;
|
|
logObj.ChangeTime= DateTime.Now;
|
|
logObj.CreatedBy = proWorkorder.CreatedBy;
|
|
UseTran2(() =>
|
|
{
|
|
result = Context.Insertable(proWorkorder).ExecuteCommand();
|
|
Context.Insertable(logObj).ExecuteCommand();
|
|
});
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// 新增工单
|
|
int sortNum = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == handleDate).Max(it => it.Sort.Value);
|
|
|
|
ProWorkorder maxWorkorder = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == handleDate)
|
|
.OrderByDescending(it =>SqlFunc.Right(it.Workorder,3)).First();
|
|
|
|
int index = 0;
|
|
if (maxWorkorder == null)
|
|
{
|
|
index = 1;
|
|
proWorkorder.Sort = 10;
|
|
}
|
|
else
|
|
{
|
|
string maxs = maxWorkorder.Workorder;
|
|
index = Convert.ToInt32(maxs.Substring(maxs.Length - 3)) + 1;
|
|
proWorkorder.Sort = maxWorkorder.Sort + 10;
|
|
}
|
|
proWorkorder.Workorder = "H" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.GroupCode + "_" + proWorkorder.RouteCode + "_" + index.ToString("000");
|
|
|
|
|
|
proWorkorder.Status = 1;
|
|
|
|
|
|
//增加日志
|
|
ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog();
|
|
logObj.Id = XueHua;
|
|
logObj.Workorder = proWorkorder.Workorder;
|
|
logObj.Log = "手动新增";
|
|
logObj.ChangeTime = DateTime.Now;
|
|
logObj.Operator = proWorkorder.CreatedBy;
|
|
logObj.ChangeTime= DateTime.Now;
|
|
logObj.CreatedBy = proWorkorder.CreatedBy;
|
|
UseTran2(() =>
|
|
{
|
|
result = Context.Insertable(proWorkorder).ExecuteCommand();
|
|
Context.Insertable(logObj).ExecuteCommand();
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 移动工单移动工单
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="type"></param>
|
|
/// <returns></returns>
|
|
public int MoveWorkorder(string id, int type)
|
|
{
|
|
int result = 0;
|
|
ProWorkorder toMove = Context.Queryable<ProWorkorder>().Where(it => it.Id == id).First();
|
|
var pervious = Context.Queryable<ProWorkorder>()
|
|
.Where(it => it.WorkorderDate == toMove.WorkorderDate);
|
|
|
|
|
|
//上移动
|
|
if (type == 1)
|
|
{
|
|
|
|
|
|
pervious = pervious.Where(it => it.Sort <= toMove.Sort).OrderByDescending(it => it.Sort);
|
|
|
|
|
|
}
|
|
//下移
|
|
else if (type == 2)
|
|
{
|
|
|
|
|
|
pervious = pervious.Where(it => it.Sort >= toMove.Sort).OrderBy(it => it.Sort);
|
|
}
|
|
ProWorkorder exchange = pervious.Skip(1).Take(1).First();
|
|
if (exchange != null)
|
|
{
|
|
int temp = toMove.Sort.Value;
|
|
toMove.Sort = exchange.Sort;
|
|
exchange.Sort = temp;
|
|
result += Context.Updateable(toMove).ExecuteCommand();
|
|
result += Context.Updateable(exchange).ExecuteCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导入工单 必须整删除 整改
|
|
/// </summary>
|
|
/// <param name="formFile"></param>
|
|
/// <returns></returns>
|
|
public int ImportData(IFormFile formFile, string username)
|
|
{
|
|
int result = 0;
|
|
List<ProWorkorder> workorderList = new();
|
|
DateTime dateValue = DateTime.MinValue;
|
|
using (var stream = formFile.OpenReadStream())
|
|
{
|
|
try
|
|
{
|
|
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;
|
|
#region 读取excel
|
|
// 遍历每一行
|
|
for (int row = 4; row <= sheet.LastRowNum; row++)
|
|
{
|
|
IRow currentRow = sheet.GetRow(row);
|
|
if (currentRow != null) // 确保行不为空
|
|
{
|
|
ProWorkorder workorder = new ProWorkorder();
|
|
|
|
//00主体品名
|
|
NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(0);
|
|
|
|
workorder.productionName = currentCell_01?.ToString();
|
|
if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//01主体型号
|
|
NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(1);
|
|
|
|
workorder.productionCode = currentCell_02?.ToString();
|
|
if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//02单位
|
|
NPOI.SS.UserModel.ICell currentCell_04 = currentRow.GetCell(2);
|
|
|
|
workorder.Unit = currentCell_04?.ToString();
|
|
if (currentCell_04 == null || string.IsNullOrEmpty(workorder.Unit))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
|
|
//3 plan_num
|
|
NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(3);
|
|
workorder.PlanNum = (int)currentCell_07?.NumericCellValue;
|
|
|
|
//4 材料型号
|
|
NPOI.SS.UserModel.ICell currentCell_11 = currentRow.GetCell(4);
|
|
|
|
workorder.MaterialName = currentCell_11?.ToString();
|
|
if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//5 材料编号
|
|
NPOI.SS.UserModel.ICell currentCell_12 = currentRow.GetCell(5);
|
|
|
|
workorder.MaterialCode = currentCell_12?.ToString();
|
|
if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//6 材质
|
|
NPOI.SS.UserModel.ICell currentCell_13 = currentRow.GetCell(6);
|
|
|
|
workorder.MaterialtextureCode = currentCell_13?.ToString();
|
|
if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//7 炉号
|
|
NPOI.SS.UserModel.ICell currentCell_14 = currentRow.GetCell(7);
|
|
|
|
workorder.StoveCode = currentCell_14?.ToString();
|
|
if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//8 图号
|
|
NPOI.SS.UserModel.ICell currentCell_15 = currentRow.GetCell(8);
|
|
|
|
workorder.DrawingCode = currentCell_15?.ToString();
|
|
if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
|
|
//9 版本
|
|
NPOI.SS.UserModel.ICell currentCell_16 = currentRow.GetCell(9);
|
|
|
|
workorder.Version = currentCell_16?.ToString();
|
|
|
|
if (currentCell_16 == null || string.IsNullOrEmpty(workorder.Version))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//10指示日期
|
|
NPOI.SS.UserModel.ICell cell17 = currentRow.GetCell(10);
|
|
|
|
|
|
// 将单元格的数字值转换为DateTime
|
|
workorder.InstructionDate = cell17.DateCellValue.Value;
|
|
|
|
|
|
//装箱容积
|
|
/*NPOI.SS.UserModel.ICell currentCell_0811 = currentRow.GetCell(6);
|
|
workorder.PackageCapacity = (int)currentCell_0811?.NumericCellValue;*/
|
|
|
|
|
|
|
|
// 11车间code
|
|
NPOI.SS.UserModel.ICell currentCell_18 = currentRow.GetCell(11);
|
|
if (currentCell_18 == null)
|
|
{
|
|
workorder.GroupCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_18.CellType == CellType.Numeric)
|
|
{
|
|
workorder.GroupCode = currentCell_18.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.GroupCode = currentCell_18.StringCellValue;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//12 组别code
|
|
NPOI.SS.UserModel.ICell currentCell_19 = currentRow.GetCell(12);
|
|
if (currentCell_19 == null)
|
|
{
|
|
workorder.GroupCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_19.CellType == CellType.Numeric)
|
|
{
|
|
workorder.GroupCode = currentCell_19.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.GroupCode = currentCell_19.StringCellValue;
|
|
}
|
|
|
|
}
|
|
//13 线别code
|
|
NPOI.SS.UserModel.ICell currentCell_20 = currentRow.GetCell(13);
|
|
|
|
if (currentCell_20 == null)
|
|
{
|
|
workorder.RouteCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_20.CellType == CellType.Numeric)
|
|
{
|
|
workorder.RouteCode = currentCell_20.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.RouteCode = currentCell_20.StringCellValue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//14 优先级
|
|
NPOI.SS.UserModel.ICell currentCell_21 = currentRow.GetCell(14);
|
|
if (currentCell_21.StringCellValue == "紧急")
|
|
{
|
|
workorder.Priority = 3;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_21.StringCellValue == "插单")
|
|
{
|
|
workorder.Priority = 2;
|
|
|
|
}
|
|
else if (currentCell_21.StringCellValue == "正常" || string.IsNullOrEmpty(currentCell_11.StringCellValue))
|
|
{
|
|
workorder.Priority = 1;
|
|
|
|
}
|
|
}
|
|
|
|
//15节拍
|
|
NPOI.SS.UserModel.ICell currentCell_22 = currentRow.GetCell(15);
|
|
workorder.Beat = (int)currentCell_22?.NumericCellValue;
|
|
|
|
|
|
//16备注
|
|
NPOI.SS.UserModel.ICell currentCell_010 = currentRow.GetCell(16);
|
|
workorder.Remark01 = currentCell_010.StringCellValue;
|
|
|
|
workorder.Id = XueHua;
|
|
workorder.CreatedBy = username;
|
|
workorder.CreatedTime = DateTime.Now;
|
|
workorder.WorkorderDate = dateValue;
|
|
workorder.Status = 1;
|
|
//工单 2024-9-13-组-线-序号
|
|
int index = (row - 2);
|
|
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.GroupCode + "_" + workorder.RouteCode + "_" + index.ToString("000");
|
|
workorder.Sort = index * 10;
|
|
|
|
|
|
CultureInfo culture = CultureInfo.CurrentCulture;
|
|
|
|
workorderList.Add(workorder);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
UseTran2(() =>
|
|
{
|
|
|
|
Context.Deleteable<ProWorkorder>().Where(it => it.WorkorderDate == dateValue).ExecuteCommand();
|
|
result = Context.Insertable(workorderList).ExecuteCommand();
|
|
});
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分批导入,追加导入
|
|
/// </summary>
|
|
/// <param name="formFile"></param>
|
|
/// <param name="username"></param>
|
|
/// <returns></returns>
|
|
public int ImportDataAppend(IFormFile formFile, string username)
|
|
{
|
|
int result = 0;
|
|
List<ProWorkorder> workorderList = new();
|
|
DateTime dateValue = DateTime.MinValue;
|
|
|
|
|
|
using (var stream = formFile.OpenReadStream())
|
|
{
|
|
try
|
|
{
|
|
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++)
|
|
{
|
|
IRow currentRow = sheet.GetRow(row);
|
|
if (currentRow != null) // 确保行不为空
|
|
{
|
|
ProWorkorder workorder = new ProWorkorder();
|
|
#region 读取excel
|
|
//00主体品名
|
|
NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(0);
|
|
|
|
workorder.productionName = currentCell_01?.ToString();
|
|
if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//01主体型号
|
|
NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(1);
|
|
|
|
workorder.productionCode = currentCell_02?.ToString();
|
|
if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
//02单位
|
|
NPOI.SS.UserModel.ICell currentCell_04 = currentRow.GetCell(2);
|
|
|
|
workorder.Unit = currentCell_04?.ToString();
|
|
if (currentCell_04 == null || string.IsNullOrEmpty(workorder.Unit))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
|
|
//3 plan_num
|
|
NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(3);
|
|
workorder.PlanNum = (int)currentCell_07?.NumericCellValue;
|
|
|
|
//4 材料型号
|
|
NPOI.SS.UserModel.ICell currentCell_11 = currentRow.GetCell(4);
|
|
|
|
workorder.MaterialName = currentCell_11?.ToString();
|
|
if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//5 材料编号
|
|
NPOI.SS.UserModel.ICell currentCell_12 = currentRow.GetCell(5);
|
|
|
|
workorder.MaterialCode = currentCell_12?.ToString();
|
|
if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//6 材质
|
|
NPOI.SS.UserModel.ICell currentCell_13 = currentRow.GetCell(6);
|
|
|
|
workorder.MaterialtextureCode = currentCell_13?.ToString();
|
|
if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//7 炉号
|
|
NPOI.SS.UserModel.ICell currentCell_14 = currentRow.GetCell(7);
|
|
|
|
workorder.StoveCode = currentCell_14?.ToString();
|
|
if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
//8 图号
|
|
NPOI.SS.UserModel.ICell currentCell_15 = currentRow.GetCell(8);
|
|
|
|
workorder.DrawingCode = currentCell_15?.ToString();
|
|
if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
|
|
//9 版本
|
|
NPOI.SS.UserModel.ICell currentCell_16 = currentRow.GetCell(9);
|
|
|
|
workorder.Version = currentCell_16?.ToString();
|
|
|
|
if (currentCell_16 == null || string.IsNullOrEmpty(workorder.Version))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//10指示日期
|
|
NPOI.SS.UserModel.ICell cell17 = secondRow.GetCell(10);
|
|
|
|
|
|
// 将单元格的数字值转换为DateTime
|
|
workorder.InstructionDate = cell17.DateCellValue.Value;
|
|
|
|
|
|
//装箱容积
|
|
/*NPOI.SS.UserModel.ICell currentCell_0811 = currentRow.GetCell(6);
|
|
workorder.PackageCapacity = (int)currentCell_0811?.NumericCellValue;*/
|
|
|
|
|
|
|
|
// 11车间code
|
|
NPOI.SS.UserModel.ICell currentCell_18 = currentRow.GetCell(11);
|
|
if (currentCell_18 == null)
|
|
{
|
|
workorder.GroupCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_18.CellType == CellType.Numeric)
|
|
{
|
|
workorder.GroupCode = currentCell_18.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.GroupCode = currentCell_18.StringCellValue;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//12 组别code
|
|
NPOI.SS.UserModel.ICell currentCell_19 = currentRow.GetCell(12);
|
|
if (currentCell_19 == null)
|
|
{
|
|
workorder.GroupCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_19.CellType == CellType.Numeric)
|
|
{
|
|
workorder.GroupCode = currentCell_19.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.GroupCode = currentCell_19.StringCellValue;
|
|
}
|
|
|
|
}
|
|
//13 线别code
|
|
NPOI.SS.UserModel.ICell currentCell_20 = currentRow.GetCell(13);
|
|
|
|
if (currentCell_20 == null)
|
|
{
|
|
workorder.RouteCode = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_20.CellType == CellType.Numeric)
|
|
{
|
|
workorder.RouteCode = currentCell_20.NumericCellValue.ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
workorder.RouteCode = currentCell_20.StringCellValue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//14 优先级
|
|
NPOI.SS.UserModel.ICell currentCell_21 = currentRow.GetCell(14);
|
|
if (currentCell_21.StringCellValue == "紧急")
|
|
{
|
|
workorder.Priority = 3;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (currentCell_21.StringCellValue == "插单")
|
|
{
|
|
workorder.Priority = 2;
|
|
|
|
}
|
|
else if (currentCell_21.StringCellValue == "正常" || string.IsNullOrEmpty(currentCell_11.StringCellValue))
|
|
{
|
|
workorder.Priority = 1;
|
|
|
|
}
|
|
}
|
|
|
|
//15节拍
|
|
NPOI.SS.UserModel.ICell currentCell_22 = currentRow.GetCell(15);
|
|
workorder.Beat = (int)currentCell_22?.NumericCellValue;
|
|
|
|
|
|
//16备注
|
|
NPOI.SS.UserModel.ICell currentCell_010 = currentRow.GetCell(16);
|
|
workorder.Remark01 = currentCell_010.StringCellValue;
|
|
#endregion
|
|
|
|
|
|
workorder.Id = XueHua;
|
|
workorder.CreatedBy = username;
|
|
workorder.CreatedTime = DateTime.Now;
|
|
workorder.WorkorderDate = dateValue;
|
|
workorder.Status = 1;
|
|
//获取当前日期工单序列号 和序号
|
|
DateTime currentDate = dateValue.Date;
|
|
var MaxWorkorder = Context.Queryable<ProWorkorder>()
|
|
.Where(it => it.WorkorderDate == currentDate)
|
|
.OrderByDescending(it => it.Sort)
|
|
.Select(it => new { it.Workorder, it.Sort })
|
|
.First();
|
|
//工单 2024-9-13-组-线-序号
|
|
int index = (row - 2);
|
|
|
|
int flowNum = index +
|
|
Convert.ToInt16(MaxWorkorder.Workorder.Substring(MaxWorkorder.Workorder.Length - 3, 3));
|
|
|
|
workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.GroupCode + "_" + workorder.RouteCode + "_" + flowNum.ToString("000");
|
|
|
|
|
|
workorder.Sort = index * 10 + Convert.ToInt16(MaxWorkorder.Sort);
|
|
|
|
|
|
CultureInfo culture = CultureInfo.CurrentCulture;
|
|
|
|
workorderList.Add(workorder);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
UseTran2(() =>
|
|
{
|
|
|
|
// Context.Deleteable<ProWorkorder>().Where(it => it.WorkorderDate == dateValue).ExecuteCommand();
|
|
result = Context.Insertable(workorderList).ExecuteCommand();
|
|
});
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 工单导出
|
|
/// </summary>
|
|
/// <param name="exportTime"></param>
|
|
/// <param name="pager"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<ProWorkorder> WorkOrderExport(DateTime exportTime, PagerInfo pager)
|
|
{
|
|
exportTime = exportTime.Date;
|
|
return Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == exportTime).ToPage(pager);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取物料信息
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public List<BaseMaterialList> GetMaterialInfo(BaseMaterialListQueryDto5 parm)
|
|
{
|
|
var predicate = Expressionable.Create<BaseMaterialList>()
|
|
.OrIF(!string.IsNullOrEmpty(parm.Name_or_Code), it => it.Name.Contains(parm.Name_or_Code))
|
|
.OrIF(!string.IsNullOrEmpty(parm.Name_or_Code), it => it.Code.Contains(parm.Name_or_Code))
|
|
;
|
|
|
|
return Context.Queryable<BaseMaterialList>()
|
|
.Where(predicate.ToExpression()).Take(20).ToList();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取客户信息
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public List<BaseCustom> GetCustomInfo(BaseCustomQueryDto2 parm)
|
|
{
|
|
var predicate = Expressionable
|
|
.Create<BaseCustom>()
|
|
.AndIF(
|
|
!string.IsNullOrEmpty(parm.CustomNo),
|
|
it => it.CustomNo.Contains(parm.CustomNo)
|
|
)
|
|
//.AndIF(
|
|
// !string.IsNullOrEmpty(parm.CustomNo),
|
|
// it => it.CustomName.Contains(parm.CustomNo)
|
|
//)
|
|
.And(it => it.Status == 1);
|
|
|
|
var response = Context.Queryable<BaseCustom>()
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(it => it.CustomNo)
|
|
.Take(20)
|
|
.ToList();
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
public List<BaseWorkRoute> GetProcessRoute(DateTime dateTime)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
|
|
/*/// <summary>
|
|
/// 获取工艺路线
|
|
/// </summary>
|
|
/// <param name="dateTime"></param>
|
|
/// <returns></returns>
|
|
public List<BaseWorkRoute> GetProcessRoute(DateTime dateTime)
|
|
{
|
|
DateTime dataTO = dateTime.ToLocalTime().Date;
|
|
var query = Context.Queryable<GroupSchedule>().Where(it => it.ScheduleDate == dataTO);
|
|
|
|
return Context
|
|
.Queryable(query)
|
|
.LeftJoin<BaseWorkRoute>((q, p) => q.FkBelongRouteCode == p.Code)
|
|
.Select((q, p) => p)
|
|
.Distinct()
|
|
.ToList();
|
|
}*/
|
|
|
|
|
|
public List<BaseWorkRoute> GetAllRoute()
|
|
{
|
|
return Context.Queryable<BaseWorkRoute>().ToList();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取班组
|
|
/// </summary>
|
|
/// <param name="route_code"></param>
|
|
/// <returns></returns>
|
|
/*public List<GroupSchedule> GetGroupList(string route_code, DateTime dateTime)
|
|
{
|
|
dateTime = dateTime.ToLocalTime().Date;
|
|
return Context.Queryable<GroupSchedule>().Where(it => it.FkBelongRouteCode == route_code)
|
|
.Where(it => it.ScheduleDate == dateTime)
|
|
.ToList();
|
|
}*/
|
|
|
|
//public List<GroupSchedule> GetGroupList(string route_code, DateTime dateTime)
|
|
//{
|
|
// throw new NotImplementedException();
|
|
//}
|
|
|
|
public List<BaseGroup> GetGroupList()
|
|
{
|
|
return Context.Queryable<BaseGroup>().Where(it => it.Status == 1).ToList();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 查询BOM 及其所需数量
|
|
/// </summary>
|
|
/// <param name="workorder_num"></param>
|
|
/// <returns></returns>
|
|
public List<WorkOrderBom> SearchBOMNum(string workorder_num)
|
|
{
|
|
List<WorkOrderBom> workOrderBoms = new List<WorkOrderBom>();
|
|
List<BaseMaterialBom> baseMaterialBoms = null;
|
|
ProWorkorder proworkorder = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder_num).First();
|
|
if (proworkorder != null)
|
|
{
|
|
baseMaterialBoms = Context.Queryable<BaseMaterialBom>().Where(it => it.InvCode == proworkorder.productionCode).ToList();
|
|
|
|
if (baseMaterialBoms != null && baseMaterialBoms
|
|
.Count() > 0)
|
|
{
|
|
foreach (var item in baseMaterialBoms)
|
|
{
|
|
WorkOrderBom objectMaterial = new WorkOrderBom();
|
|
|
|
objectMaterial.SubInvCode=item.SubInvCode;
|
|
objectMaterial.SubInvName = item.SubInvName;
|
|
objectMaterial.Iusequantity_Single = item.Iusequantity;
|
|
float num = float.Parse(item.Iusequantity) * proworkorder.PlanNum.Value;
|
|
objectMaterial.Iusequantity_All = num.ToString();
|
|
objectMaterial.BOMVersion = item.BOMVersion;
|
|
workOrderBoms.Add(objectMaterial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return workOrderBoms;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 工单日志
|
|
/// </summary>
|
|
/// <param name="workorder"></param>
|
|
/// <param name="log"></param>
|
|
/// <returns></returns>
|
|
public int WorkOrderLog(string workorder, string log, string Operator)
|
|
{
|
|
ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog();
|
|
logObj.Id = XueHua;
|
|
logObj.Workorder = workorder;
|
|
logObj.Log = log;
|
|
logObj.ChangeTime = DateTime.Now;
|
|
logObj.Operator = Operator;
|
|
logObj.ChangeTime= DateTime.Now;
|
|
logObj.CreatedBy = Operator;
|
|
|
|
|
|
return Context.Insertable(logObj).ExecuteCommand();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工单进度跟踪
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<ProWorkorderTranceProgressDto> GetWorkorderTraceProgressList(ProWorkorderQueryDto query)
|
|
{
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder>()
|
|
.AndIF(!string.IsNullOrEmpty(query.productionName), it => it.productionName.Contains(query.productionName))
|
|
.AndIF(!string.IsNullOrEmpty(query.productionCode), it => it.productionCode.Contains(query.productionCode))
|
|
.AndIF(!string.IsNullOrEmpty(query.RouteCode), it => it.RouteCode == query.RouteCode)
|
|
.AndIF(!string.IsNullOrEmpty(query.GroupCode), it => it.GroupCode == query.GroupCode)
|
|
.AndIF(query.WorkorderDate != null && query.WorkorderDate[0] > DateTime.MinValue, it => it.WorkorderDate >= query.WorkorderDate[0])
|
|
.AndIF(query.WorkorderDate != null && query.WorkorderDate[1] > DateTime.MinValue, it => it.WorkorderDate <= query.WorkorderDate[1])
|
|
.AndIF(query.Status>-1,it=>it.Status==query.Status)
|
|
|
|
;
|
|
var query2 = Queryable()
|
|
.Where(predicate.ToExpression());
|
|
|
|
return Context.Queryable(query2).LeftJoin<ProReportwork>((q, r) => q.Workorder == r.FkWorkorder)
|
|
.Select((q, r) => new ProWorkorderTranceProgressDto()
|
|
{
|
|
PlanNum = q.PlanNum,
|
|
ActualNum = r.FinishedNum,
|
|
}, true).ToPage_NO_Convert<ProWorkorderTranceProgressDto>(query);
|
|
|
|
|
|
}
|
|
|
|
public int Insert_workOrder2(ProWorkorder proWorkorder, string next_id)
|
|
{
|
|
int result = 0;
|
|
proWorkorder.Id = XueHua;
|
|
proWorkorder.WorkorderDate = proWorkorder.WorkorderDate.Value.Date;
|
|
if (!string.IsNullOrEmpty(next_id) && next_id != "-1")
|
|
{
|
|
UseTran2(() =>
|
|
{
|
|
|
|
int sortNum = Context.Queryable<ProWorkorder>().Where(it => it.Id == next_id).Select(it => it.Sort.Value).First();
|
|
Context.Updateable<ProWorkorder>()
|
|
.Where(it => it.WorkorderDate == proWorkorder.WorkorderDate)
|
|
.Where(it => it.Sort >= sortNum)
|
|
.SetColumns(it => new ProWorkorder() { Sort = it.Sort + 10 })
|
|
.ExecuteCommand();
|
|
|
|
|
|
proWorkorder.Sort = sortNum;
|
|
proWorkorder.Status = 1;
|
|
|
|
Context.Insertable(proWorkorder).ExecuteCommand();
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
DateTime dateOnly = proWorkorder.WorkorderDate.Value.Date;
|
|
|
|
int sortNum = Context.Queryable<ProWorkorder>().Where(it => it.WorkorderDate == dateOnly).Max(it => it.Sort.Value);
|
|
|
|
proWorkorder.Sort = sortNum + 10;
|
|
|
|
proWorkorder.Status = 1;
|
|
|
|
Context.Insertable(proWorkorder).ExecuteCommand();
|
|
}
|
|
|
|
|
|
|
|
Generate_workorder(new ProWorkorderQueryDto2()
|
|
{
|
|
WorkorderDate = proWorkorder.WorkorderDate.Value
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} |