CutWeldService.cs 8.96 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;

            //更新工单明细
            workOrderDetail.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
            Context.Updateable(workOrderDetail).UpdateColumns(t => new { t.workReportStatus }).ExecuteCommand();


            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,//操作人                   
            };

            return;

            //调用上游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 == EquipmentCode.锯床)
                oprSequenceCode = EnumoprSequenceCode.切割;
            if (equipmentCode == EquipmentCode.端面坡口机)
                oprSequenceCode = EnumoprSequenceCode.坡口;
            if (equipmentCode == EquipmentCode.机器人打磨)
                oprSequenceCode = EnumoprSequenceCode.打磨;
            if (equipmentCode == EquipmentCode.机器人XY焊接)
                oprSequenceCode = EnumoprSequenceCode.组焊;
            if (equipmentCode == EquipmentCode.组焊一体机)
                oprSequenceCode = EnumoprSequenceCode.组焊;
            if (equipmentCode == EquipmentCode.组焊平台)
                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).First();

            //工单明细没有不反馈,已经完工不反馈
            if (workOrderDetail == null) return;
            if(workOrderDetail.state== (int)EnumOrderBodyStatus.已完成) return;

            //更新任务
            if (taskEquipment != null)
            {
                if (taskEquipment.sendStatus == 0)
                    taskEquipment.sendStatus = (int)EnumWeldTechnologyEquipmentStatus.成功;
                taskEquipment.updateTime = DateTime.Now;
                taskEquipment.updateBy = sysUserApi?.Account;

                Context.Updateable(taskEquipment).UpdateColumns(t => new { t.sendStatus, t.updateTime, t.updateBy }).AddQueue();

                workOrderDetail.actualEndTime = taskEquipment.updateTime;
            }
            else {
                workOrderDetail.actualEndTime = DateTime.Now;
            }

            //更新工单明细
            workOrderDetail.state = (int)EnumOrderBodyStatus.已完成;
           
            workOrderDetail.equipmentCode = equipmentCode;
            workOrderDetail.updateBy = sysUserApi?.Account;
            workOrderDetail.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
            Context.Updateable(workOrderDetail).UpdateColumns(t => new { t.state, t.actualEndTime, t.equipmentCode, t.updateBy, t.workReportStatus }).AddQueue();

            //更新工单
            Context.Updateable<bus_workOrder_head>()
                .SetColumns(x => x.state == (int)EnumOrderBodyStatus.已完成)
                .SetColumns(x => x.actualEndTime == DateTime.Now)
                .SetColumns(x => x.updateTime == DateTime.Now)
                .Where(x => x.keys == workOrderDetail.headKeys).AddQueue();

            if (taskEquipment != null)
            {
                Context.Updateable<bus_workOrder_head>()
                .SetColumns(x => x.updateBy == taskEquipment.createBy)
                .Where(x => x.keys == workOrderDetail.headKeys).AddQueue();
            }
            else {
                string userAccount = sysUserApi?.Account;
                Context.Updateable<bus_workOrder_head>()
                .SetColumns(x => x.updateBy == userAccount)
                .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,//操作人                   
            };

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