ProcessFeedbackService.cs 28.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
using Hh.Mes.Common.log;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.POJO.WebEntity.bus;
using Hh.Mes.Service.Logs;
using Hh.Mes.Service.Repository;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Hh.Mes.Service
{
    /// <summary>
    /// 工序开工 完工 反馈
    /// </summary>
    public class ProcessFeedbackService : RepositorySqlSugar<dynamic>
    {
        /// <summary>
        /// 工序开工完工状态更新
        /// </summary>
        /// <param name="bodyKeys"></param>
        /// <param name="headKeys"></param>
        /// <param name="enumCutHeadState">完工状态</param>
        /// <returns></returns>
        public Response UpdateBusWorkOrderStatus(Guid bodyKeys, Guid headKeys, EnumCutHeadState enumCutHeadState)
        {
            var response = new Response();
            try
            {
                //工序头
                var busWorkOrderHead = Context.Queryable<bus_workOrder_head>().First(x => x.keys == headKeys);
                if (busWorkOrderHead == null)
                {
                    var msg = $"工序任务头表查询无数据:{headKeys}";
                    QueueInterLog.GetInstance.EnqueueInterLog(null, null, EnumLog.工序执行反馈.ToString(), msg, 0, user: "CutWeldService-coupleBack", system: "CutWeldService-coupleBack");
                    return response.ResponseError(msg);
                }

                //工序明细
                if (!Context.Queryable<bus_workOrder_detail>().Where(x => x.bodyKeys == bodyKeys).Any())
                {
                    var msg = $"工序任务明细查询无数据:{bodyKeys}";
                    QueueInterLog.GetInstance.EnqueueInterLog(null, null, EnumLog.工序执行反馈.ToString(), msg, 0, user: "CutWeldService-coupleBack", system: "CutWeldService-coupleBack");
                    return response.ResponseError(msg);
                }

                var busWorkOrderDetails = Context.Queryable<bus_workOrder_detail>().Where(x => x.headKeys == headKeys).ToList();

                //bus_workOrder_Top
                var busWorkOrderTop = Context.Queryable<bus_workOrder_top>().Where(x => x.topKeys == busWorkOrderHead.topKeys).First();

                #region 更新bus_workOrder_Topbus_workOrder_head状态

                //开始
                if (busWorkOrderDetails.Where(x => x.state > (int)EnumOrderBodyStatus.初始化).Count() == 1 && !busWorkOrderDetails.Where(x => x.state >= (int)EnumOrderBodyStatus.已完成).Any())
                {
                    busWorkOrderHead.actualStartTime = DateTime.Now;
                    busWorkOrderHead.state = (int)EnumOrderHeadStatus.生产中;
                    busWorkOrderHead.updateTime = DateTime.Now;
                    Context.Updateable(busWorkOrderHead).UpdateColumns(t => new
                    {
                        t.state,
                        t.actualStartTime,
                        t.updateTime,
                    }).ExecuteCommand();

                    //第一次开工
                    if (Context.Queryable<bus_workOrder_head>().Where(x => x.state > (int)EnumOrderBodyStatus.初始化).Count() == 1 && !Context.Queryable<bus_workOrder_head>().Where(x => x.state >= (int)EnumOrderBodyStatus.已完成).Any())
                    {
                        busWorkOrderTop.state = (int)EnumOrderTopStatus.生产中;
                        busWorkOrderTop.actualStartTime = DateTime.Now;
                        busWorkOrderTop.updateTime = DateTime.Now;
                        Context.Updateable(busWorkOrderTop).UpdateColumns(t => new
                        {
                            t.state,
                            t.actualStartTime,
                            t.updateTime,
                        }).ExecuteCommand();
                    }
                }

                //结束
                if (busWorkOrderDetails.All(x => x.state >= (int)EnumOrderBodyStatus.已完成))
                {
                    busWorkOrderHead.state = (int)EnumOrderHeadStatus.已完成;
                    busWorkOrderHead.actualEndTime = DateTime.Now;
                    busWorkOrderHead.updateTime = DateTime.Now;
                    Context.Updateable(busWorkOrderHead)
                        .UpdateColumns(t => new
                        {
                            t.state,
                            t.actualEndTime,
                            t.updateTime,
                        }).ExecuteCommand();

                    if (!Context.Queryable<bus_workOrder_head>().Where(x => x.topKeys == busWorkOrderHead.topKeys && x.state < (int)EnumOrderHeadStatus.已完成).Any())
                    {
                        busWorkOrderTop.state = (int)EnumOrderTopStatus.已完成;
                        busWorkOrderTop.actualEndTime = DateTime.Now;
                        busWorkOrderTop.updateTime = DateTime.Now;
                        Context.Updateable(busWorkOrderTop).UpdateColumns(t => new
                        {
                            t.state,
                            t.actualEndTime,
                            t.updateTime,
                        }).ExecuteCommand();
                    }
                }

                #endregion

                //工序明细列表,中间过程无需报工
                foreach (var item in busWorkOrderDetails.GroupBy(x => x.workCenterCode))
                {
                    if (item.Count() > 2)
                    {
                        var firstItemKeys = item.Where(x => x.state >= (int)EnumOrderBodyStatus.生产中).OrderBy(x => x.actualStartTime).ThenBy(x => x.id).Select(x => x.bodyKeys).FirstOrDefault();
                        if (firstItemKeys == null)
                        {
                            continue;
                        }

                        var lastItemKeys = Guid.Empty;
                        if (item.All(x => x.state >= (int)EnumOrderBodyStatus.已完成))
                        {
                            lastItemKeys = item.Where(x => x.state >= (int)EnumOrderBodyStatus.已完成).OrderByDescending(x => x.actualEndTime).ThenByDescending(x => x.id).Select(x => x.bodyKeys).First();
                        }
                        else
                        {
                            lastItemKeys = item.Where(x => x.state < (int)EnumOrderBodyStatus.已完成).OrderByDescending(x =>
                            {
                                if (x.actualStartTime == new DateTime(1900, 1, 1))
                                {
                                    return long.MaxValue;
                                }
                                return x.actualStartTime.Ticks;
                            }).ThenByDescending(x => x.id).Select(x => x.bodyKeys).First();
                        }

                        var detailItem = busWorkOrderDetails.Where(x => x.bodyKeys == bodyKeys).First();
                        if (detailItem.bodyKeys != firstItemKeys && detailItem.bodyKeys != lastItemKeys)
                        {
                            detailItem.workReportStatus = (int)EnumWorkReportStatus.无需报工;
                            Context.Updateable(detailItem).UpdateColumns(t => new { t.workReportStatus }).ExecuteCommand();
                        }
                    }
                }
                return response.ResponseSuccess();
            }
            catch (Exception ex)
            {
                return response.ResponseError($"方法[UpdateBusWorkOrderStatus]异常:{ex.Message}");
            }
        }

        /// <summary>
        /// 工序报工
        /// </summary>
        /// <param name="headKeys"><see cref="bus_workOrder_head"/></param>
        /// <remarks>
        /// <para>在定时器中执行</para>
        /// <para>组队工序需要报工两次,组队开始报开工,所有组队工序结束报完工</para>
        /// <para>焊接工序需要报工两次,焊接开始报开工,所有焊接工序结束报完工</para>
        /// </remarks>
        /// <returns></returns>
        public Response SigningUpForWorkToMES(Guid headKeys)
        {
            var response = new Response();
            var busWorkOrderHead = Context.Queryable<bus_workOrder_head>().Where(x => x.keys == headKeys).First();
            if (busWorkOrderHead == null)
            {
                response.ResponseErr($"{nameof(bus_workOrder_head)}不存在keys为{headKeys}的数据!");
                return response;
            }

            //bus_workOrder_Top
            var busWorkOrderTop = Context.Queryable<bus_workOrder_top>().Where(x => x.topKeys == busWorkOrderHead.topKeys).First();

            var busWorkOrderDetails = Context.Queryable<bus_workOrder_detail>().Where(x => x.headKeys == headKeys).ToList();

            //调用上游MES工序完工反馈
            var url = GetDictionaryDictValue("UrlProcessFeedback", "GetUrl");

            foreach (var item in busWorkOrderDetails.OrderBy(x => x.serialNumber).GroupBy(x => x.workCenterCode))
            {
                //开工报工
                //存在已完成的工序,但无开工报工记录
                if (item.Where(x => x.state >= (int)EnumOrderBodyStatus.生产中).Any() && !item.Where(x => x.workReportStatus == (int)EnumWorkReportStatus.开工已报工 || x.workReportStatus == (int)EnumWorkReportStatus.完工已报工).Any())
                {
                    var temp = item.Where(x => x.state >= (int)EnumOrderBodyStatus.生产中 && x.actualStartTime != DateTime.MinValue).OrderBy(x => x.actualStartTime).First();
                    var feedbackModel = new ProcessFeedbackModel
                    {
                        plmeid = Guid.NewGuid().ToString(),
                        workorder_code = busWorkOrderHead.workOrderCode,
                        serial_number = busWorkOrderHead.projectSerialNumber,
                        oprsequence_code = temp.oprSequenceCode,
                        star_time = temp.actualStartTime,
                        timesum = 0,
                        createby = temp.createBy,
                        flag = (int)EnumOrderBodyType.开工,
                        type = EnumAction.I.ToString()
                    };
                    response = HttpMan(url, feedbackModel, EnumLog.工序执行反馈.ToString(), method: "post");
                    //状态码为200:推送成功
                    //状态码为210:上游MES已手动完工,
                    //其他:失败
                    if (!response.Status && response.Code != 210)
                    {
                        var json1 = JsonConvert.SerializeObject(feedbackModel);
                        var json2 = JsonConvert.SerializeObject(response);
                        AddWorkOrderFailRecord(busWorkOrderHead, temp, EnumWorkOrderReportFail.MES原因, json1, json2, response.Message);
                        return response;
                    }

                    temp.workReportStatus = (int)EnumWorkReportStatus.开工已报工;
                    Context.Updateable(temp).UpdateColumns(t => new { t.workReportStatus }).ExecuteCommand();

                    var operation = new bus_workOrder_detail_operation
                    {
                        busOrderDetail_Id = temp.id,
                        content = $"开工报工完成",
                        createTime = DateTime.Now,
                    };
                    Context.Insertable(operation).ExecuteCommand();

                    busWorkOrderTop.workReportStatus = (int)EnumWorkReportTopStatus.部分已报工;
                    busWorkOrderTop.updateTime = DateTime.Now;
                    Context.Updateable(busWorkOrderTop).UpdateColumns(t => new
                    {
                        t.workReportStatus,
                        t.updateTime,
                    }).ExecuteCommand();
                }

                //完工报工
                //所有工序均已完成,且已经存在开工报工的记录,无完工报工记录
                if (item.All(x => x.state == (int)EnumOrderBodyStatus.已完成) && item.Where(x => x.workReportStatus == (int)EnumWorkReportStatus.开工已报工).Any() && !item.Where(x => x.workReportStatus == (int)EnumWorkReportStatus.完工已报工).Any())
                {
                    bus_workOrder_detail lastTemp;
                    //工序明细有多条的时候,需要更新不同的工序状态
                    if (item.Count() > 1)
                    {
                        //正常情况
                        if (item.Where(x => x.workReportStatus == (int)EnumWorkReportStatus.未报工).Any())
                        {
                            lastTemp = item.Where(x => x.workReportStatus == (int)EnumWorkReportStatus.未报工).First();
                        }
                        //异常情况
                        else
                        {
                            lastTemp = item.OrderByDescending(x => x.workReportStatus).ThenByDescending(x => x.actualEndTime).First();
                        }
                    }
                    else
                    {
                        lastTemp = item.First();
                    }

                    var actualStartTime = item.Where(x => x.actualStartTime != DateTime.MinValue).Min(x => x.actualStartTime);
                    var actualEndTime = item.Max(x => x.actualEndTime);

                    var timeSum = Convert.ToInt32(item.Sum(x => (x.actualEndTime - x.actualStartTime).TotalMinutes));
                    var feedbackModel = new ProcessFeedbackModel
                    {
                        plmeid = Guid.NewGuid().ToString(),
                        workorder_code = busWorkOrderHead.workOrderCode,
                        serial_number = busWorkOrderHead.projectSerialNumber,
                        oprsequence_code = lastTemp.oprSequenceCode,
                        star_time = actualStartTime,
                        end_time = actualEndTime,
                        timesum = timeSum == 0 ? 1 : timeSum,
                        createby = lastTemp.createBy,
                        flag = (int)EnumOrderBodyType.完工,
                        type = EnumAction.I.ToString()
                    };

                    //焊接信息,焊接工艺 调用电气接口查询
                    if (item.Key == WorkCenterCode.焊接)
                    {
                        var weldParams = new List<weldParam>();
                        //全位置焊接调用电气接口获取
                        foreach (var detailItem in item.Where(x => x.stationCode == "Weld1_3"))
                        {
                            //地址后期需配置到数据库
                            var url2 = GetDictionaryDictValue("WeldParameter", "GetUrl");
                            if (string.IsNullOrWhiteSpace(url2))
                            {
                                var msg = $"[获取焊接参数]的url请求地址失败,请检查地址是否已配置!";
                                AddWorkOrderFailRecord(busWorkOrderHead, detailItem, EnumWorkOrderReportFail.华恒原因_焊接工艺, $"tasknum={busWorkOrderHead.id}", string.Empty, $"获取工艺参数失败:{msg}");
                                return response.ResponseError(msg);
                            }

                            //http://172.16.35.172:80/api/DeviceInfo/GetTaskRecord?tasknum=10
                            var result = WeldHttpGet<WeldParameterDto>($"{url2}?tasknum={detailItem.id}", EnumLog.焊接参数获取);
                            if (!result.Status || result.Result.WeldProgram == null)
                            {
                                var json = JsonConvert.SerializeObject(result);
                                AddWorkOrderFailRecord(busWorkOrderHead, detailItem, EnumWorkOrderReportFail.华恒原因_焊接工艺, $"tasknum={detailItem.id}", json, $"获取工艺参数失败:{result.Message}");
                                return result;
                            }

                            var data = result.Result;
                            var weldParamItem = new weldParam
                            {
                                weld_no = detailItem.weldNo,
                                program_number = data.WeldProgram.ProgramNumber.ToString(),
                                nowpass_number = data.WeldProgram.NowPassNumber,
                                sector_number = data.WeldProgram.PassWeldPara.SectorNumber,
                                diameter = data.WeldProgram.OD,
                                thickness = data.WeldProgram.Wall,
                                pegas = data.WeldProgram.PassWeldPara.PreGas,
                                postgas = data.WeldProgram.PassWeldPara.PostGas,
                                preweld_current = data.WeldProgram.PassWeldPara.PreWeldCurrent,
                                preweld_time = data.WeldProgram.PassWeldPara.PreWeldTime,
                                preheat_temp = "",
                                layer_temp = "",
                                back_gasflow = "",
                                current_value = data.WeldProgram.PassWeldPara.SecCurrentPT.First().ToString(),
                                voltage_value = data.WeldProgram.PassWeldPara.SecAvcP.First().ToString(),
                                weld_speed = data.WeldProgram.PassWeldPara.SecRotP.First().ToString(),
                                protect_gasflow = data.WeldProgram.PassWeldPara.GasFlow.ToString(),
                            };
                            weldParams.Add(weldParamItem);
                        }
                        //其他设备,从数据库获取焊接工艺
                        foreach (var detailItem in item.Where(x => x.stationCode != "Weld1_3"))
                        {
                            var equipmentinformations = Context.Queryable<read_equipmentinformation_ecs>().Where(x => x.taskNo == $"{detailItem.id}").OrderBy(x => x.count).ToList();
                            if (equipmentinformations.Count == 0)
                            {
                                continue;
                            }

                            var weldParamTemps = equipmentinformations.GroupBy(x => x.count).Select(e =>
                            {
                                var program_number = e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.weld_no.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault();

                                int.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.nowpass_number.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var nowpass_number);

                                int.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.sector_number.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var sector_number);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.diameter.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var diameter);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.thickness.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var thickness);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.pegas.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var pegas);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.postgas.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var postgas);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.preweld_current.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var preweld_current);

                                double.TryParse(e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.preweld_time.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault(), out var preweld_time);

                                var current_value = e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.current_value.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault();

                                var voltage_value = e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.voltage_value.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault();

                                var weld_speed = e.Where(x => x.equipmentTypeTemplateCode.Equals(WeldParamProp.weld_speed.ToString(), StringComparison.OrdinalIgnoreCase)).Select(x => x.informationValue).FirstOrDefault();
                                var paramData = new weldParam
                                {
                                    weld_no = detailItem.weldNo,
                                    program_number = program_number,
                                    nowpass_number = nowpass_number,
                                    sector_number = sector_number,
                                    diameter = diameter,
                                    thickness = thickness,
                                    pegas = pegas,
                                    postgas = postgas,
                                    preweld_current = preweld_current,
                                    preweld_time = preweld_time,
                                    preheat_temp = "",
                                    layer_temp = "",
                                    back_gasflow = "",
                                    current_value = current_value,
                                    voltage_value = voltage_value,
                                    weld_speed = weld_speed,
                                    protect_gasflow = "0",//无数据
                                };
                                return paramData;
                            }).ToList();
                            weldParams.AddRange(weldParamTemps);
                        }

                        feedbackModel.weldParamList = weldParams;
                    }

                    response = HttpMan(url, feedbackModel, EnumLog.工序执行反馈.ToString(), method: "post");
                    //状态码为200:推送成功
                    //状态码为210:上游MES已手动完工,
                    //其他:失败
                    if (!response.Status && response.Code != 210)
                    {
                        var json1 = JsonConvert.SerializeObject(feedbackModel);
                        var json2 = JsonConvert.SerializeObject(response);
                        AddWorkOrderFailRecord(busWorkOrderHead, lastTemp, EnumWorkOrderReportFail.MES原因, json1, json2, response.Message);
                        return response;
                    }
                    lastTemp.workReportStatus = (int)EnumWorkReportStatus.完工已报工;
                    Context.Updateable(lastTemp).UpdateColumns(t => new { t.workReportStatus }).ExecuteCommand();

                    var itemIds = item.Select(x => x.id.ToString()).ToList();

                    if (item.Key == WorkCenterCode.焊接)
                    {
                        //报工成功后,更新焊接工艺状推送状态
                        Context.Updateable<read_equipmentinformation_ecs>().SetColumns(x => x.isSend == 1).Where(x => itemIds.Contains(x.taskNo)).ExecuteCommand();
                    }

                    var operation = new bus_workOrder_detail_operation
                    {
                        busOrderDetail_Id = lastTemp.id,
                        content = $"完工报工完成",
                        createTime = DateTime.Now,
                    };
                    Context.Insertable(operation).ExecuteCommand();
                }
            }

            //更新bus_workOrder_top已完工状态
            var allBusWorkOrderDetails = Context.Queryable<bus_workOrder_detail>()
                .Where(x => x.topKeys == busWorkOrderTop.topKeys)
                .Select(x => new bus_workOrder_detail
                {
                    id = x.id,
                    headKeys = x.headKeys,
                    workCenterCode = x.workCenterCode,
                    state = x.state,
                    workReportStatus = x.workReportStatus,
                    createTime = x.createTime,
                })
                .ToList();

            var isSuccess = allBusWorkOrderDetails.GroupBy(x => x.headKeys).All(item =>
            {
                if (item.Where(x => x.state < (int)EnumOrderBodyStatus.已完成).Any())
                {
                    return false;
                }

                var weldTemps = item.Where(x => x.workCenterCode == WorkCenterCode.焊接).ToList();
                var fitUpTemps = item.Where(x => x.workCenterCode == WorkCenterCode.组对).ToList();

                if (weldTemps.Count == 1 && fitUpTemps.Count == 1)
                {
                    return !item.Where(x => x.workReportStatus < (int)EnumWorkReportStatus.完工已报工).Any();
                }

                if (weldTemps.Count >= 2 || fitUpTemps.Count >= 2)
                {
                    return item.Where(x => x.workReportStatus != (int)EnumWorkReportStatus.未报工).Any();
                }

                return false;
            });
            if (isSuccess)
            {
                busWorkOrderTop.workReportStatus = (int)EnumWorkReportTopStatus.已报工;
                busWorkOrderTop.updateTime = DateTime.Now;
                Context.Updateable(busWorkOrderTop).UpdateColumns(t => new
                {
                    t.workReportStatus,
                    t.updateTime,
                }).ExecuteCommand();
            }

            return response;
        }

        /// <summary>
        /// 新增报工失败记录
        /// </summary>
        /// <param name="head"></param>
        /// <param name="detail"></param>
        /// <param name="type"></param>
        /// <param name="requestJson"></param>
        /// <param name="responseJson"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private void AddWorkOrderFailRecord(bus_workOrder_head head, bus_workOrder_detail detail, EnumWorkOrderReportFail type, string requestJson, string responseJson, string message)
        {
            try
            {
                var record = Context.Queryable<bus_workOrder_report_fail>().Where(x => x.workOrderTopKeys == detail.topKeys && x.workOrderHeadKeys == detail.headKeys && x.workOrderBodyKeys == detail.bodyKeys).First();
                if (record == null)
                {
                    record = new bus_workOrder_report_fail
                    {
                        workOrderTopKeys = detail.topKeys,
                        workOrderHeadKeys = detail.headKeys,
                        workOrderBodyKeys = detail.bodyKeys,
                        workOrderCode = detail.workOrderCode,
                        failType = type,
                        projectSerialNumber = detail.projectSerialNumber,
                        workCenterCode = detail.workCenterCode,
                        stationCode = detail.stationCode,
                        oprSequenceCode = detail.oprSequenceCode,
                        oprSequenceName = detail.oprSequenceName,
                        actualStartTime = detail.actualStartTime,
                        actualEndTime = head.actualEndTime,
                        requestJson = requestJson,
                        responseJson = responseJson,
                        remark = message,
                        createTime = DateTime.Now,
                    };
                    Context.Insertable(record).ExecuteCommand();
                    return;
                }

                record.failType = type;
                record.requestJson = requestJson;
                record.responseJson = responseJson;
                record.remark = message;
                record.createTime = DateTime.Now;
                Context.Updateable(record).UpdateColumns(x => new
                {
                    x.failType,
                    x.requestJson,
                    x.responseJson,
                    x.remark,
                    x.createTime,
                }).ExecuteCommand();
            }
            catch (Exception ex)
            {
                Log4NetHelper.Instance.Error($"新增报工日志失败:{ex.Message}");
            }
        }
    }
}