qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS.Jobs
{
    public partial class EquipmentExecutor : SchedulerExecuteBase
    {
        private static int _readFJCBJSignalso = 0;
        /// <summary>
        /// 拆包站逻辑流程
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public static void CBJtask()
        {
            if (Interlocked.Exchange(ref _readFJCBJSignalso, 1) == 0)
            {
                try
                {
                    VOLContext Context = new VOLContext();
                    WebResponseContent responseContent = new WebResponseContent();
                    Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
                    dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
                    Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                    Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
                    Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
                    Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                    Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
 
                    // 抓取PDA主盘表数据
                    var PDAtask = pdaRepository.FindFirst(v => v.ishandle == 1);
                    if (PDAtask != null)
                    {
                        //查询起点站台的路由
                        var routes = routingRepository.Find(v => v.route_began == PDAtask.Devid).ToList();
                        foreach (var route in routes)
                        {
                            //判断终点位置是否可用
                            PLCClient plc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV");
                            //读取PLC信号是否能放货
                            string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), route.route_end).ToString();
                            //查询WCS自己的货位判断是否有货
                            var location = locRepository.FindFirst(v => v.upper_code == route.route_end);
                            if (isWork == "1" && location.location_state == LocationStateEnum.LocationState_Empty.ToString())
                            {
                                //条件通过即可创建AGV任务
                                dt_agvtask agvtask = new dt_agvtask
                                {
                                    agv_materbarcode = PDAtask.BarCode,
                                    agv_barcode = "",
                                    agv_code = "负极1号AGV",
                                    agv_createtime = DateTime.Now,
                                    agv_fromaddress = route.route_began,
                                    agv_grade = 1,
                                    agv_materielid = PDAtask.MaterialType,
                                    agv_qty = 1,
                                    agv_tasknum = "KH-" + tasknumber.GetTaskNumber(tasknumberRep),
                                    agv_taskstate = "Create",
                                    agv_tasktype = "TaskType_Outbound",
                                    agv_toaddress = route.route_end,
                                    agv_userid = "WCS",
                                    agv_worktype = 1
                                };
                                agvRepository.Add(agvtask, true);
                                WriteLog.Info("CBJtask").Write("CBJtask接口" + agvtask.agv_tasknum + DateTime.Now, "CBJtask");
                                //AGV任务生成后修改PDA组盘表
                                PDAtask.ishandle = 0;
                                //pdaRepository.Delete(item, true);
                                //修改终点货架存储状态
                                location.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                locRepository.Update(location, true);
                                //添加库存信息
                                bill_group_stock stock = new bill_group_stock();
                                stock.stock_id = Guid.NewGuid();
                                stock.MaterialType = PDAtask.MaterialType;
                                stock.BarCode = PDAtask.BarCode;
                                stock.MaterialStatus = PDAtask.MaterialStatus;
                                stock.first_tb = 0;
                                stock.TB_Status = "";
                                stock.FQ_Status = "";
                                stock.GY_Status = "";
                                stock.QX_Status = "";
                                stock.created_user = "WCS";
                                stock.created_time = DateTime.Now;
                                stock.updated_user = "WCS";
                                stock.updated_time = DateTime.Now;
                                groupRepository.Add(stock, true);
                                //给MES回传物料移动信息
                                //MESAPIInvoke.BindMaterialDevid(PDAtask.Devid, route.route_end, PDAtask.MaterialType, PDAtask.BarCode, PDAtask.MaterialStatus);
                                break;
                            }
                        }
                    }
                  
                }
 
                catch (Exception ex)
                {
 
                }
                finally
                {
                    Interlocked.Exchange(ref _readCBJSignalso, 0);
                }
                //responseContent = SendTask(client.PLCName, () =>
                //{
                //    //任务下发逻辑编写
                //    throw new Exception();
                //});
            }
 
            }
    }
}