Admin
5 天以前 bd6818fc9d40f343547bafca0743658f3c0379dc
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
128
129
130
131
132
133
134
135
136
137
138
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WIDESEA.Common;
using WIDESEA.Core.ManageUser;
using WIDESEA.Core.Services;
using WIDESEA.Core.Utilities;
using WIDESEA.Entity.DomainModels;
using WIDESEA.Services.IRepositories;
using WIDESEA.Services.Repositories;
using WIDESEA_Common.LogEnum;
using WIDESEA_Services;
 
namespace WIDESEA.Services.Services
{
    public partial class CommonFunction
    {
 
        /// <summary>
        /// 移库出库
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent AddCheckTaskAction(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_general_info general_Info = Dt_general_infoRepository.Instance.FindFirst(x => true);
                if ("应急模式".Equals(general_Info.general_inline_current_model))
                {
                    Dt_taskinfo task = Dt_taskinfoRepository.Instance.FindFirst(r => LayerToStation.inboundStations.Contains(r.task_endstation)
                 || LayerToStation.outboundStations.Contains(r.task_beginstation));
                    if (null != task || saveModel.DelKeys.Count > 1)
                        return content.Error("应急模式只能出1个任务.");
                }
                IVV_ContainerInfoRepository repository = VV_ContainerInfoRepository.Instance;
                List<string> locationState = new List<string>()
                {
                    LocationState.LocationState_Stored.ToString(),
                    LocationState.LocationState_Error.ToString(),
                };
                List<VV_ContainerInfo> listContainer = new List<VV_ContainerInfo>();
                foreach (var item in saveModel.DelKeys)
                {
                    Guid id = new Guid(item.ToString());
                    VV_ContainerInfo containerInfo = repository.FindFirst(x => x.containerdtl_id == id);
                    if (null != containerInfo)
                    {
                        if (!locationState.Contains(containerInfo.location_state) || containerInfo.location_islocked)
                            throw new Exception($"只能复核有货状态和解锁的库存,货位号:{containerInfo.location_id}");
                        listContainer.Add(containerInfo);
                    }
                }
                content = repository.DbContextBeginTransaction(() =>
                {
                    List<Dt_taskinfo> listTask = new List<Dt_taskinfo>();
                    foreach (var containerInfo in listContainer)
                    {
                        //更改货位状态
                        Dt_locationinfo locationinfo = Dt_locationinfoRepository.Instance.FindFirst(x => x.location_id == containerInfo.location_id);
                        if (containerInfo.location_state.Equals(LocationState.LocationState_Stored.ToString()))
                            locationinfo.location_state = LocationState.LocationState_CheckOutbound.ToString();
                        else if (containerInfo.location_state.Equals(LocationState.LocationState_Error.ToString()))
                            locationinfo.location_state = LocationState.LocationState_ErrorCheckOutbound.ToString();
                        else
                            throw new Exception("无效货位状态." + containerInfo.location_state);
 
                        Dt_locationinfoRepository.Instance.Update(locationinfo, x => x.location_state, true);
                        string target = CommonFunction.GetOutboundAddress(general_Info, locationinfo.location_layer);
                        //生成WMS任务
                        Dt_taskinfo taskinfo = new Dt_taskinfo();
                        taskinfo.task_id = Guid.NewGuid();
                        taskinfo.task_type = TaskType.TaskType_CheckOutbound.ToString();
                        taskinfo.task_state = TaskState.TaskState_Create.ToString();
                        taskinfo.task_barcode = containerInfo.containerdtl_barcode;
                        taskinfo.task_materielid = containerInfo.materiel_id;
                        taskinfo.task_weight = containerInfo.containerdtl_goodsWeight;
                        taskinfo.task_sn = containerInfo.containerdtl_goodsCode;
                        taskinfo.task_materielType = containerInfo.containerdtl_type;
                        //起始货位
                        taskinfo.task_fromlocationid = containerInfo.location_id;
                        //目的货位,应该是穿梭车的放货站台 (50301-50308)
                        taskinfo.task_tolocationid = target;
                        //测量出库任务穿梭车的放货站台(50301-50308)
                        taskinfo.task_beginstation = target;
                        //目的站台
                        taskinfo.task_endstation = "20101";
                        taskinfo.task_grade = 0;
                        taskinfo.task_creator = UserContext.Current.UserTrueName;
                        taskinfo.task_createtime = DateTime.Now;
                        taskinfo.task_weight = containerInfo.containerdtl_goodsWeight;
                        taskinfo.task_materielType = containerInfo.containerdtl_type;
                        taskinfo.task_sn = containerInfo.containerdtl_number;
                        Dt_taskinfoRepository.Instance.Add(taskinfo, true);
                        dt_checkRecord checkRecord = new dt_checkRecord()
                        {
                            record_barcode = containerInfo.containerdtl_barcode,
                            record_createTime = DateTime.Now,
                            record_id = Guid.NewGuid(),
                            record_locationId = containerInfo.location_id,
                            record_madeUnit = containerInfo.containerdtl_madeUnit,
                            record_materielId = containerInfo.materiel_id,
                            record_materielNumber = containerInfo.containerdtl_number,
                            record_materielType = containerInfo.containerdtl_type,
                            record_result = "",
                            record_standa = containerInfo.containerdtl_standard,
                            record_userName = UserContext.Current.UserTrueName,
                            record_weight = string.IsNullOrEmpty(containerInfo.containerdtl_goodsWeight) ? 0 : decimal.Parse(containerInfo.containerdtl_goodsWeight)
                        };
                        dt_checkRecordRepository.Instance.Add(checkRecord, true);
                        listTask.Add(taskinfo);
                        LogRecord.WriteLog((int)LogEnum.Check, $"{UserContext.Current.UserName}【手动添加复核任务】给货位:【{locationinfo.location_id}】、托盘号:【{containerInfo.containerdtl_barcode}】的轴承添加了复核任务");
                    }
                    content = WCSApi.SendTaskToWCS(listTask);
                    if (content.Status)
                        content.OK($"测量复核回库任务下发给WCS成功.");
                    else
                        content.Error($"测量复核回库任务下发给WCS失败,原因 => {content.Message}");
                    return content.OK("手动增加测量任务成功.");
                });
            }
            catch (Exception ex)
            {
                content.Error("创建复核任务失败:" + ex.Message);
            }
            finally
            {
                Logger.AddLog(Core.Enums.LoggerType.Add, saveModel, content, content);
            }
            return content;
 
        }
 
    }
}