分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-27 0b5ccdca6263cf7a2cee460f30c76ef1efea2811
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.MES_Info;
using WIDESEA_Comm.MES_Info.Request;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.ManageUser;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.Mes;
using WIDESEA_WMS.Common;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static WIDESEA_Comm.MES_Info.BasicSN;
 
namespace WIDESEA_WMS
{
    public partial class ToMesServer
    {
        /// <summary>
        /// 空盘操作  (外协空盘入库,空盘补送)
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent SendEpmtyTask(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string cacheNo = saveModel.MainData["cacheNo"].ToString();  //缓存架编号
                string user = saveModel.MainData["creator"].ToString();
                string type = saveModel.MainData["radio"].ToString();   //1为空盘入库 2为空盘出库
                int number = Convert.ToInt32(saveModel.MainData["number"].ToString());
                return content.Error($"{user}无操作权限!");
                if (type == "1")  //空盘入库
                {
                    //寻找空盘库位
                    dt_stationinfo emptyLocation = GetEmptyLocation();
 
                    dt_agvtask agvtask = new dt_agvtask
                    {
                        //agv_barcode = cacheNo,
                        //agv_code = user,
                        agv_createtime = DateTime.Now,
                        agv_fromaddress = cacheNo,
                        agv_qty = number,
                        agv_grade = 1,
                        agv_tasktype = AGVTaskTypeEnum.TaskType_Inbound.ToString(),
                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                        agv_toaddress = emptyLocation.stationCode,
                    };
                    freeDB.Add(agvtask);
                }
                else
                {
                    //根据库存查询空盘库存信息
                    dt_inventory inventory = freeDB.Select<dt_inventory>().Where(x => x.area == "11").OrderByDescending(x => x.OnlineTime).First(); //取最晚的入库车轮
 
                    //数量?
                    //var stationinfo = freeDB.Select<dt_stationinfo>().Where(x => x.stationCode == inventory.stationCode).First();
                    //int num = Convert.ToInt16(stationinfo.quantity);
 
 
                    dt_agvtask agvtask = new dt_agvtask
                    {
                        //agv_barcode = cacheNo,
                        //agv_code = user,
                        agv_createtime = DateTime.Now,
                        agv_fromaddress = inventory.stationCode,
                        agv_qty = 5,   //inventory.,   //告诉AGV取第几个车轮?
                        agv_grade = 1,
                        agv_tasktype = AGVTaskTypeEnum.TaskType_Inbound.ToString(),
                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                        agv_toaddress = cacheNo,
                    };
                    freeDB.Add(agvtask);
                }
 
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error($"呼叫AGV失败:{ ex.Message}");
            }
        }
 
        private dt_stationinfo GetEmptyLocation()
        {
            VOLContext context = new VOLContext();
            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
            var station = stationinfoRepository.Find(x => x.line == 9 && x.location_state == LocationStateEnum.Empty.ToString() && x.area == "11").FirstOrDefault();
 
            //  todo区分大小托盘
 
            if (station != null)
            {
                return station;
            }
            else
            {
                throw new Exception("空盘库位已满,无法入库!");
            }
 
        }
    }
}