分支自 SuZhouGuanHong/TaiYuanTaiZhong

WMS
dengjunjie
2024-01-16 92b129a783ff748a4e5365803aa862888fa4470e
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
using Newtonsoft.Json;
using System;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Common;
using WIDESEA_Core.ManageUser;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.Mes;
 
namespace WIDESEA_WMS
{
    public partial class ToMesServer
    {
        /// <summary>
        /// 手动移库
        /// </summary>
        /// <param name="requestTemp"></param>
        /// <returns></returns>
        public WebResponseContent AddToFloat3(MesRequestTemp requestTemp)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //var route = freeDB.Select<dt_stationinfo>().Where(t => t.stationCode == requestTemp.from_address && t.route_end == requestTemp.to_address).ToOne();
                var station1 = freeDB.Select<dt_stationinfo>().Where(t => t.stationCode == requestTemp.from_address).First();
                var station2 = freeDB.Select<dt_stationinfo>().Where(t => t.stationCode == requestTemp.to_address).First();
                if (station1 == null || station2 == null)
                {
                    throw new Exception($"路径{requestTemp.from_address}到{requestTemp.to_address},不存在!");
                }
                if (station1.location_state != LocationStateEnum.Stroge.ToString())
                    throw new Exception($"起点{requestTemp.from_address}未找到物料!");
                if (station2.location_state != LocationStateEnum.Empty.ToString())
                    throw new Exception($"终点{requestTemp.to_address}不是空货位!");
                if (string.IsNullOrEmpty(station1.stationType))
                    throw new Exception($"起点{requestTemp.from_address}未绑定物料类型!");
                if (station1.stationType != station2.stationType)
                    throw new Exception($"起点与终点绑定物料类型不一致!");
 
                var haveInTask = freeDB.Select<dt_agvtask>()
                   .Where(t => t.agv_fromaddress == requestTemp.from_address
                   || t.agv_fromaddress == requestTemp.to_address
                   || t.agv_toaddress == requestTemp.from_address
                   || t.agv_toaddress == requestTemp.to_address
                   ).Any();
 
                if (!haveInTask)
                {
                    station2.quantity = station1.quantity;
                    station2.bindSN = station1.bindSN;
                    station2.location_state = station1.location_state;
                    station2.tray_status = station1.tray_status;
                    freeDB.Update(station2);
 
                    station1.quantity = 0;
                    station1.bindSN = string.Empty;
                    station1.location_state = LocationStateEnum.Empty.ToString();
                    station1.tray_status = string.Empty;
                    freeDB.Update(station1);
                }
                else
                {
                    throw new Exception("起始或目的地址,已存在任务!");
                }
                content.OK();
                WriteDBLog.Success($"手动移库", new { 数据 = requestTemp }, "WMS", UserContext.Current.UserTrueName);
            }
            catch (Exception ex)
            {
                WriteDBLog.Error($"手动移库", new { 数据 = requestTemp, 异常信息 = ex.Message }, "WMS", UserContext.Current.UserTrueName);
                content.Error(ex.Message);
            }
            return content;
        }
    }
}