CutWeldService.cs 7.48 KB
using ApkInfo;
using Hh.Mes.Common;
using Hh.Mes.Common.config;
using Hh.Mes.Common.Json;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Redis;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.Service.Repository;
using Hh.Mes.Service.SystemAuth;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;

namespace Hh.Mes.Service
{
    public class CutWeldService : RepositorySqlSugar<dynamic>
    {
        /// <summary>
        /// 管段工序完工调用
        /// </summary>
        /// <param name="BarCode">追踪码</param>
        /// <param name="processesState">状态</param>
        /// <returns></returns>
        public void SendIWPTechnologylineProcess(string BarCode, int processesState)
        {

            if (string.IsNullOrWhiteSpace(BarCode)) return;

            //切割完成处理,ECS完成时会更新套料方案,工单工序,这里只需要组织数据反馈上游
            var oprSequenceCode = "";
            if (processesState == (int)EnumCutHeadState.已套料)
                oprSequenceCode = EnumoprSequenceCode.套料;
            if (processesState == (int)EnumCutHeadState.切坡完成)
                oprSequenceCode = EnumoprSequenceCode.切割坡口;

            if (processesState == (int)EnumCutHeadState.切割完成)
                oprSequenceCode = EnumoprSequenceCode.切割;
            if (processesState == (int)EnumCutHeadState.坡口完成)
                oprSequenceCode = EnumoprSequenceCode.坡口;

            if (processesState == (int)EnumCutHeadState.打磨完成)
                oprSequenceCode = EnumoprSequenceCode.打磨;
            if (processesState == (int)EnumCutHeadState.组对完成)
                oprSequenceCode = EnumoprSequenceCode.组对;
            if (processesState == (int)EnumCutHeadState.焊接完成)
                oprSequenceCode = EnumoprSequenceCode.焊接;

            if (processesState == (int)EnumCutHeadState.组焊完成)
                oprSequenceCode = EnumoprSequenceCode.组焊;

            if (oprSequenceCode == "") return;

            var workOrderDetail = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.oprSequenceCode == oprSequenceCode && x.barCode == BarCode).First();
            if (workOrderDetail == null) return;

            var data = new
            {
                workOrderCode = workOrderDetail.workOrderCode,//工单
                partCode = workOrderDetail.partCode,//管段号
                barCode = workOrderDetail.barCode,//追踪码(管段码)
                oprSequenceCode = workOrderDetail.oprSequenceCode,//工序
                stationCode = workOrderDetail.stationCode,//工位
                equipmentCode = workOrderDetail.equipmentCode,//生产设备
                actualStartTime = workOrderDetail.actualStartTime,//开始时间
                actualEndTime = workOrderDetail.actualEndTime,// 完成时间
                cutMaterCode = workOrderDetail.cutMaterCode,//管段物料编码
                weldNo = workOrderDetail.weldNo,//组对(焊接)焊口号
                batchNo = workOrderDetail.batchNo,//组对(焊接)批次号
                createBy = workOrderDetail.createBy,//操作人                   
            };

            //调用上游MES工序完工反馈
            var url = GetDictionaryDictValue("UrlProcessFeedback", "GetUrl");
            HttpManVoid(url, data, EnumLog.调用上游MES工序完工反馈.ToString(), method: "post");
        }


        /// <summary>
        /// PDA,ECS调用,任务号设备完工报工
        /// </summary>
        /// <param name="taskCode">任务号</param>
        /// <param name="equipmentCode">设备编码</param>
        /// <returns></returns>
        public void SendTaskEnd(string taskCode, string  equipmentCode)
        {

            if (string.IsNullOrWhiteSpace(taskCode)|| string.IsNullOrWhiteSpace(equipmentCode)) return;

            //切割完成处理,ECS完成时会更新套料方案,工单工序,这里只需要组织数据反馈上游
            var oprSequenceCode = "";
            //锯床
            if (equipmentCode == "Saw") 
                oprSequenceCode = EnumoprSequenceCode.切割;
            //端面坡口机
            if (equipmentCode == "EndFaceBevel") 
                oprSequenceCode = EnumoprSequenceCode.坡口;
            //机器人打磨
            if (equipmentCode == "RobotPolish")
                oprSequenceCode = EnumoprSequenceCode.打磨;
            //机器人焊接
            if (equipmentCode == "RobotWeld")
                oprSequenceCode = EnumoprSequenceCode.焊接;
            //组焊一体机
            if (equipmentCode == "FitupAndWeld")
                oprSequenceCode = EnumoprSequenceCode.组焊;
            //3D组焊平台
            if (equipmentCode == "3DFitupAndWeld")
                oprSequenceCode = EnumoprSequenceCode.组焊;


            if (oprSequenceCode == "") return;

            var workOrderDetail = base.Context.Queryable<bus_workOrder_detail>().Where(x => x.oprSequenceCode == oprSequenceCode && x.barCode == taskCode).First();
            var taskEquipment= base.Context.Queryable<base_task_equipment>().Where(x => x.taskCode == taskCode && x.sendStatus == (int)EnumWeldTechnologyEquipmentStatus.成功).First();
            
            //工单明细 或者 任务没有完成不反馈
            if (workOrderDetail == null|| taskEquipment==null) return;

            workOrderDetail.state = (int)EnumOrderBodyStatus.已完成;
            workOrderDetail.actualStartTime = taskEquipment.createTime;
            workOrderDetail.actualEndTime = taskEquipment.updateTime;
            workOrderDetail.equipmentCode = equipmentCode;
            workOrderDetail.createBy = taskEquipment.createBy;

            //更新工单明细
            Context.Updateable(workOrderDetail).UpdateColumns(t => new { t.state, t.actualStartTime, t.actualEndTime, t.equipmentCode, t.createBy }).AddQueue();
            //更新工单
            Context.Updateable<bus_workOrder_head>().SetColumns(x => x.state == (int)EnumOrderBodyStatus.已完成).Where(x => x.keys == workOrderDetail.headKeys).AddQueue();

            Context.SaveQueues();

            var data = new
            {
                workOrderCode = workOrderDetail.workOrderCode,//工单
                partCode = workOrderDetail.partCode,//管段号
                barCode = workOrderDetail.barCode,//追踪码(管段码)
                oprSequenceCode = workOrderDetail.oprSequenceCode,//工序
                stationCode = workOrderDetail.stationCode,//工位
                equipmentCode = equipmentCode,//生产设备
                actualStartTime = workOrderDetail.actualStartTime,//开始时间
                actualEndTime = workOrderDetail.actualEndTime,// 完成时间
                cutMaterCode = workOrderDetail.cutMaterCode,//管段物料编码
                weldNo = workOrderDetail.weldNo,//组对(焊接)焊口号
                batchNo = workOrderDetail.batchNo,//组对(焊接)批次号
                createBy = workOrderDetail.createBy,//操作人                   
            };

            //调用上游MES工序完工反馈
            var url = GetDictionaryDictValue("UrlProcessFeedback", "GetUrl");
            HttpManVoid(url, data, EnumLog.调用上游MES工序完工反馈.ToString(), method: "post");
        }
    }
}