2025-11-04 20:56:03 +08:00
|
|
|
|
using Aliyun.OSS;
|
|
|
|
|
|
using DOAN.Model;
|
|
|
|
|
|
using DOAN.Model.Business;
|
|
|
|
|
|
using DOAN.Model.Dto;
|
2025-11-05 15:42:30 +08:00
|
|
|
|
using DOAN.Model.MES.dev;
|
|
|
|
|
|
using DOAN.Model.MES.dev.Dto;
|
2025-11-04 20:56:03 +08:00
|
|
|
|
using DOAN.Model.MES.process;
|
|
|
|
|
|
using DOAN.Repository;
|
|
|
|
|
|
using DOAN.Service.Business.IBusinessService;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
using Infrastructure.Extensions;
|
2025-11-05 15:42:30 +08:00
|
|
|
|
using JinianNet.JNTemplate;
|
2025-11-04 20:56:03 +08:00
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
using NPOI.XSSF.Streaming.Values;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2025-11-05 15:42:30 +08:00
|
|
|
|
using UAParser;
|
2025-11-04 20:56:03 +08:00
|
|
|
|
|
|
|
|
|
|
namespace DOAN.Service.Business
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Service业务层处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AppService(ServiceType = typeof(IProcessmodelWorkStepService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class ProcessmodelWorkStepService : BaseService<ProcessmodelWorkStep>, IProcessmodelWorkStepService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public PagedInfo<ProcessmodeWorkStepDto> GetList(ProcessmodelWorkStepQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
var predicate = Expressionable.Create<ProcessmodelWorkStep>()
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.StepCode), p => parm.StepCode.Contains(p.StepCode))
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.StepName), p => parm.StepName.Contains(p.StepName));
|
|
|
|
|
|
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
|
|
|
|
|
.GroupBy(p => p.StepCode)
|
|
|
|
|
|
.ToPage<ProcessmodelWorkStep, ProcessmodeWorkStepDto>(parm);
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public ProcessmodelWorkStep GetInfo(long Id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(x => x.Id == Id)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public ProcessmodelWorkStep AddProcessmodelWorkStep(ProcessmodelWorkStep model)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateProcessmodelWorkStep(ProcessmodelWorkStep model)
|
|
|
|
|
|
{
|
|
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new ProcessmodelOperationStep()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// OperationStepCode = model.OperationStepCode,
|
|
|
|
|
|
// OperationStepName = model.OperationStepName,
|
|
|
|
|
|
// OperationCode = model.OperationCode,
|
|
|
|
|
|
// Description = model.Description,
|
|
|
|
|
|
// IsActive = model.IsActive,
|
|
|
|
|
|
// UpdateTime = model.UpdateTime,
|
|
|
|
|
|
// UpdateBy = model.UpdateBy,
|
|
|
|
|
|
// Remark = model.Remark,
|
|
|
|
|
|
//});
|
|
|
|
|
|
//return response;
|
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 15:42:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取设备列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="stepCode"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2025-11-04 20:56:03 +08:00
|
|
|
|
public List<UniqueValueQueryDto> GetUniqueValueList(string stepCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool stepCodeExists = Context.Queryable<ProcessmodelWorkStep>()
|
2025-11-05 15:42:30 +08:00
|
|
|
|
.Where(p => p.StepCode == stepCode)
|
|
|
|
|
|
.Any();
|
2025-11-04 20:56:03 +08:00
|
|
|
|
|
|
|
|
|
|
if (!stepCodeExists)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<UniqueValueQueryDto>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 15:42:30 +08:00
|
|
|
|
var uniqueValues = Context.Queryable<ProcessmodelWorkStep>()
|
2025-11-04 20:56:03 +08:00
|
|
|
|
.Where(p => p.StepCode == stepCode)
|
|
|
|
|
|
.Distinct()
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
2025-11-05 15:42:30 +08:00
|
|
|
|
List<UniqueValueQueryDto> result = [];
|
|
|
|
|
|
foreach (var uniqueValue in uniqueValues)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dictionary = Context.Queryable<DeviceAccount>().First(d => d.DeviceCode == uniqueValue.UniqueValue);
|
2025-11-05 18:12:05 +08:00
|
|
|
|
if (dictionary == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<UniqueValueQueryDto>();
|
|
|
|
|
|
}
|
2025-11-05 15:42:30 +08:00
|
|
|
|
result.Add(new UniqueValueQueryDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = uniqueValue.Id,
|
2025-11-05 15:50:22 +08:00
|
|
|
|
DeviceCode = uniqueValue.UniqueValue,
|
2025-11-05 16:09:21 +08:00
|
|
|
|
DeviceName = dictionary.DeviceName,
|
|
|
|
|
|
Workshop = dictionary.Workshop,
|
|
|
|
|
|
Workline = dictionary.Workline,
|
|
|
|
|
|
Status = dictionary.Status,
|
|
|
|
|
|
DeviceSpecification = dictionary.DeviceSpecification,
|
|
|
|
|
|
ResponsiblePerson = dictionary.ResponsiblePerson
|
2025-11-05 15:42:30 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<WorkshopDto> GetAccountList()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 1. SqlSugar 链式查询:先查平数据(数据库端过滤,性能不浪费)
|
|
|
|
|
|
var flatData = Context.Queryable<DeviceAccount>()
|
|
|
|
|
|
// 过滤空值,避免分组垃圾数据
|
|
|
|
|
|
.Where(d => !string.IsNullOrEmpty(d.Workshop) && !string.IsNullOrEmpty(d.Workline))
|
|
|
|
|
|
// 只取需要的字段,减少数据传输
|
|
|
|
|
|
.Select(d => new
|
|
|
|
|
|
{
|
|
|
|
|
|
d.Workshop,
|
|
|
|
|
|
d.Workline,
|
|
|
|
|
|
d.DeviceCode,
|
|
|
|
|
|
d.DeviceName
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList(); // 加载到内存,后续内存分组(SqlSugar 内存分组不会报错)
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 手动构建 DTO 结构(最稳妥,不会有任何翻译问题)
|
|
|
|
|
|
var result = new List<WorkshopDto>();
|
|
|
|
|
|
|
|
|
|
|
|
// 先获取所有不重复的车间
|
|
|
|
|
|
var allWorkshops = flatData.Select(d => d.Workshop).Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var workshop in allWorkshops)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 构建当前车间 DTO
|
|
|
|
|
|
var workshopDto = new WorkshopDto { Workshop = workshop };
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前车间下的所有数据
|
|
|
|
|
|
var workshopData = flatData.Where(d => d.Workshop == workshop).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前车间下不重复的产线
|
|
|
|
|
|
var allWorklines = workshopData.Select(d => d.Workline).Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var workline in allWorklines)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 构建当前产线 DTO
|
|
|
|
|
|
var worklineDto = new WorklineDto { Workline = workline };
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前产线下的所有设备
|
|
|
|
|
|
var devices = workshopData
|
|
|
|
|
|
.Where(d => d.Workline == workline)
|
|
|
|
|
|
.Select(d => new DeviceDto
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceCode = d.DeviceCode,
|
|
|
|
|
|
DeviceName = d.DeviceName
|
|
|
|
|
|
})
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
worklineDto.Devices = devices;
|
|
|
|
|
|
workshopDto.Worklines.Add(worklineDto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result.Add(workshopDto);
|
|
|
|
|
|
}
|
2025-11-04 20:56:03 +08:00
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:22:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增设备
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
|
public int AddUniqueValue(UniqueQueryDto parm)
|
2025-11-04 20:56:03 +08:00
|
|
|
|
{
|
2025-11-05 10:22:05 +08:00
|
|
|
|
|
2025-11-05 15:42:30 +08:00
|
|
|
|
// 查询工步基础信息
|
2025-11-05 10:22:05 +08:00
|
|
|
|
var workStep = Context.Queryable<ProcessmodelWorkStep>()
|
|
|
|
|
|
.Where(x => x.StepCode == parm.StepCode && x.ProcessCode == parm.ProcessCode)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
if (workStep == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("未找到对应的工步信息");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 15:42:30 +08:00
|
|
|
|
// 插入新的工步记录
|
2025-11-05 10:22:05 +08:00
|
|
|
|
var newWorkStep = new ProcessmodelWorkStep
|
|
|
|
|
|
{
|
|
|
|
|
|
StepCode = workStep.StepCode,
|
|
|
|
|
|
StepName = workStep.StepName,
|
|
|
|
|
|
ProcessCode = workStep.ProcessCode,
|
|
|
|
|
|
Description = workStep.Description,
|
|
|
|
|
|
IsActive = workStep.IsActive,
|
2025-11-05 15:42:30 +08:00
|
|
|
|
UniqueValue = parm.DeviceCode,
|
2025-11-05 10:22:05 +08:00
|
|
|
|
CreateTime = DateTime.Now
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Insertable(newWorkStep).ExecuteCommand();
|
2025-11-04 20:56:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-05 10:22:05 +08:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 删除设备
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <param name="id"></param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
///// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
|
//public int DeleteUniqueValue(long id)
|
|
|
|
|
|
//{
|
2025-11-05 13:40:57 +08:00
|
|
|
|
// Context.Deleteable<ProcessmodelWorkStep>()
|
2025-11-05 10:22:05 +08:00
|
|
|
|
//}
|
2025-11-04 20:56:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|