using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading.Tasks;
|
using SqlSugar;
|
using WIDESEA_ISerialPortRepository;
|
using WIDESEA_SerialPortRepository;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_DTO.SerialPort;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public class ProcessServer : ServiceBase<Dt_Process, IProcessRepository>, IProcessServer
|
{
|
private IPutakeRepository _putakeRepository;
|
private IUnitOfWorkManage _unitOfWorkManage;
|
private ITorqueOpRepository _torqueOpRepository;
|
public ProcessServer(IProcessRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IPutakeRepository putakeRepository, ITorqueOpRepository torqueOpRepository) : base(BaseDal)
|
{
|
_putakeRepository = putakeRepository;
|
_unitOfWorkManage = unitOfWorkManage;
|
_torqueOpRepository = torqueOpRepository;
|
}
|
|
public override PageGridData<Dt_Process> GetPageData(PageDataOptions options)
|
{
|
OrderByParameters = new Dictionary<string, OrderByType>
|
{
|
{ nameof(Dt_Process.ArticleOne), OrderByType.Asc },//按什么字段排序
|
};
|
return base.GetPageData(options);
|
}
|
|
public WebResponseContent GetProcess(string gruop)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var proce = BaseDal.QueryData(i => i.CraftType == gruop);
|
|
|
_unitOfWorkManage.CommitTran();
|
if (proce != null)
|
{
|
return new WebResponseContent { Status = true, Data = proce };
|
}
|
else
|
{
|
return new WebResponseContent { Status = false, Message = "数据为空" };
|
}
|
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return new WebResponseContent { Status = false, Message = "失败" + ex.Message };
|
}
|
}
|
|
public WebResponseContent GetSleeveandStep(string gruops)
|
{
|
try
|
{
|
_unitOfWorkManage.BeginTran();
|
var result = BaseDal.QueryData(x => x.CraftType == gruops) // 先筛选 CraftType
|
.GroupBy(x => x.CraftType) // 按 CraftType 分组
|
.Select(g => new
|
{
|
maxNodal = g.Max(a => a.Nodal),
|
sumTorqueSum = g.Sum(a => a.TorqueSum)
|
}).ToList();
|
_unitOfWorkManage.CommitTran();
|
return new WebResponseContent { Status = true, Data = result };
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
|
}
|
}
|
|
|
public WebResponseContent AddProcess(AddProcessDTO addProcessDTO)
|
{
|
try
|
{
|
var proces = new Dt_Process();
|
proces.Nodal = addProcessDTO.nodal;
|
proces.CraftType = addProcessDTO.craftstype;
|
proces.CraftsStep = addProcessDTO.craftsstep;
|
proces.CraftContent = addProcessDTO.craftcontent;
|
proces.TorqueSum = addProcessDTO.sleeveNum;
|
proces.Tools = addProcessDTO.tools;
|
_unitOfWorkManage.BeginTran();
|
BaseDal.AddData(proces);
|
_unitOfWorkManage.CommitTran();
|
return new WebResponseContent { Status = true, Data = proces };
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
|
}
|
}
|
|
public WebResponseContent Upprocess(PutProcessDTO addProcessDTO)
|
{
|
try
|
{
|
var proces = BaseDal.QueryData(x => x.CraftID == addProcessDTO.id).FirstOrDefault();
|
if (proces == null)
|
{
|
return new WebResponseContent { Status = false, Message = "没有找到" };
|
}
|
proces.Nodal = addProcessDTO.nodal;
|
proces.CraftType = addProcessDTO.craftstype;
|
proces.CraftsStep = addProcessDTO.craftsstep;
|
proces.CraftContent = addProcessDTO.craftcontent;
|
proces.TorqueSum = addProcessDTO.sleeveNum;
|
proces.Tools = addProcessDTO.tools;
|
_unitOfWorkManage.BeginTran();
|
BaseDal.UpdateData(proces);
|
_unitOfWorkManage.CommitTran();
|
return new WebResponseContent { Status = true, Data = proces };
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
|
}
|
}
|
|
public WebResponseContent Getcircuit(string group, string takeid)
|
{
|
try
|
{
|
///如果这个存值表中没有步骤一这么搞?我这么显示给前端看
|
|
|
// 先查到这条任务
|
var putake = _putakeRepository.QueryData(x => x.Njtakeid == takeid && x.Grouptype == group).OrderBy(x => x.Dispatchtime).FirstOrDefault();
|
if (putake==null)
|
{
|
return new WebResponseContent { Status = false, Message = "没有找到" };
|
}
|
//获取到当前完成的步骤
|
var nowNum = _torqueOpRepository.QueryData(x => x.GroupOp == group && x.TakeId == takeid).Max(x => x.ProcessSte);
|
|
|
|
//根据分组和步骤找到该条数据
|
var process = BaseDal.QueryData(x => x.CraftType == group&&x.SetpNum== nowNum).FirstOrDefault();
|
|
|
//返回当前工艺的最大步骤
|
var maxproce = BaseDal.QueryData(x => x.CraftType == group).Max(x => x.SetpNum);
|
|
//一共要有多少条数据(目标数量)
|
int TargetCount = process.TorqueOneQuantity + process.TorqueTwoQuantity;
|
|
|
|
// 查询当前步骤的 TorqueOp 记录,匹配 ProcessSte和组,任务号,检查是否达到要求(实际数量)
|
int practiceCount = _torqueOpRepository.QueryData(x => x.GroupOp == group&&x.TakeId== takeid).Count();
|
|
|
|
if (practiceCount < TargetCount)
|
{
|
return new WebResponseContent { Status = false, Message = "没有完成当前步骤",Data= process };
|
}
|
if (maxproce== nowNum)
|
{
|
return new WebResponseContent { Status = false, Message = "你完成了当前作业" };
|
}
|
int num = nowNum + 1;
|
|
var nex = BaseDal.QueryFirst(x => x.CraftType == group && x.SetpNum == num);
|
|
return new WebResponseContent { Status = true, Data = nex };
|
}
|
catch (Exception ex)
|
{
|
return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
|
}
|
}
|
}
|
|
|
}
|