分支自 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
111
using Newtonsoft.Json;
using System;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
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.IRepositories;
using WIDESEA_WMS.Repositories;
 
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 = LocationStateEnum.Stroge.ToString();
                    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.UserName + UserContext.Current.UserTrueName);
            }
            catch (Exception ex)
            {
                WriteDBLog.Error($"手动移库", new { 数据 = requestTemp, 异常信息 = ex.Message }, "WMS", UserContext.Current.UserName + UserContext.Current.UserTrueName);
                content.Error(ex.Message);
            }
            return content;
        }
 
        /// <summary>
        /// 外协货位扫码确认物料已被取走
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent Confirmedcut(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                string sn = saveModel.MainData["from_address"].ToString();
                var station = stationinfoRepository.Find(x => x.bindSN.Contains(sn) && (x.stationCode.Contains("W01001001") || x.stationCode.Contains("W01001002") || x.stationCode.Contains("W01001003"))).FirstOrDefault();
                if (station == null) throw new Exception($"未找到车轮SN号:{sn}的外协货位信息!");
                station.Number = string.Empty;
                station.billetID = string.Empty;
                station.heatNumber = string.Empty;
                station.stationType = string.Empty;
                station.tray_status = "EmptyTray";
                station.lastUpdateTime = DateTime.Now;
                stationinfoRepository.Update(station, true);
                content.OK();
            }
            catch (Exception ex)
            {
                content.Message = ex.Message;
            }
            return content;
        }
    }
}