刘磊
2024-12-04 e3b6c01acf7228c009d861c1efea4cbcc7926abe
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
using WIDESEA_DTO.WMS;
using WIDESEA_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    public partial class MCSService
    {
        /// <summary>
        /// 请求移库
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public WebResponseContent RequestChangeLocation(object json)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(json.ToString())) throw new Exception("上传参数为空");
 
                var result = JsonConvert.DeserializeObject<RequestReMove>(json.ToString());
 
                var location = _locationRepository.QueryFirst(x => x.AreaId == result.LocationArea && x.LocationCode == result.LocationID);
 
                if (location == null) throw new Exception("未知库位");
 
                if (result.MoveType == 5)
                {
                    Console.WriteLine($"分容检测柜火警触发:库位{result.LocationID}");
 
                    //查找消防站台
                    var station = _stationManagerRepository.QueryFirst(t => t.Roadway == location.RoadwayNo
                         && t.stationType == (int)StationManager.FireStation
                         /*&& t. == "Enable"*/);
                    if (station == null)
                    {
                        throw new Exception("消防站台未配置!");
                    }
                    //查找库存信息
                    var barcodeData = _stockInfoRepository.QueryFirst(t => t.LocationCode == location.LocationCode);
                    //托盘码
                    string barcode = string.Empty;
                    if (barcodeData != null)
                    {
                        barcode = barcodeData.PalletCode;
                    }
                    else
                    {
                        //无库存信息,生成随机托盘码
                        barcode = "M" + DateTime.Now.ToString("MMddHHmmss") + "-" + new Random().Next(100, 1000);
                    }
                    int taskNum = _taskRepository.GetTaskNo().Result;
                    Dt_Task task = new Dt_Task
                    {
                        CreateDate = DateTime.Now,
                        Creater = "HK",
                        CurrentAddress = result.LocationID,
                        Grade = 1,
                        Dispatchertime = DateTime.Now,
                        PalletCode = result.PalletBarcode,
                        Roadway = location.RoadwayNo,
                        SourceAddress = result.LocationID,
                        TaskState = (int)TaskOutStatusEnum.OutNew,
                        TaskType = 500,
                        TargetAddress = station.stationLocation,
                        NextAddress = station.stationChildCode,
                        TaskNum = taskNum, //_taskRepository.GetTaskNo().Result,
                        TaskId = 0,
                    };
 
                    // 尝试添加新任务
                    WMSTaskDTO taskDTO = new WMSTaskDTO()
                    {
                        TaskNum = task.TaskNum.Value,
                        Grade = 1,
                        PalletCode = task.PalletCode,
                        RoadWay = task.Roadway,
                        SourceAddress = task.SourceAddress,
                        TargetAddress = task.TargetAddress,
                        TaskState = task.TaskState.Value,
                        Id = 0,
                        TaskType = 500,
                    };
                }
                LogFactory.GetLog("分容移库申请").Info(true, $"\r\r--------------------------------------");
                LogFactory.GetLog("分容移库申请").Info(true, result);
                return content.OK();
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }
}