kazelee
20 小时以前 fc25dda9baf3b5f4df23d35914f3dd343cf492e3
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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using HH.WCS.Mobox3.DSZSH.models;
using HH.WCS.Mobox3.DSZSH.util;
using HH.WCS.Mobox3.DSZSH.wms;
 
using static HH.WCS.Mobox3.DSZSH.api.ApiModel;
using static HH.WCS.Mobox3.DSZSH.util.Config;
 
namespace HH.WCS.Mobox3.DSZSH.api {
    /// <summary>
    /// 应急/特殊情况的强制操作流程
    /// </summary>
    [RoutePrefix("force")]
    public class ForceController : ApiController {
        /// <summary>
        /// 强制创建任务并下发
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("ForceInbound")]
        public SimpleResult ForceCreateTask(ForceModel.ForceCreateTaskInfo model) {
            return ForceService.ForceCreateTask(model);
        }
 
        public SimpleResult ForceAddCgDetail() {
            return NewSimpleResult(0, "");
        }
    }
 
    public class ForceService {
        public static SimpleResult ForceCreateTask(ForceModel.ForceCreateTaskInfo model) {
            var db = new SqlHelper<object>().GetInstance();
            var (ok, msg) = (false, string.Empty);
            var taskInfo = ETask.M满箱下线入库.Info();
            const string preLog = "DEBUG:强制创建任务:";
 
            try {
                var startLoc = db.Queryable<TN_Location>().Where(DbExpr.StartLocUnbind(model.StartLoc, taskInfo.StartAreas)).First();
                if (startLoc == null) {
                    return NewSimpleResult(2, preLog + LogMsg.StartLocUnbindNotFound(model.StartLoc, taskInfo.StartAreas));
                }
 
                var endLoc = db.Queryable<TN_Location>().Where(DbExpr.EndLoc(areas: taskInfo.EndAreas))
                    .OrderBy(l => new { l.N_LAYER }).First();
                if (endLoc == null) {
                    return NewSimpleResult(3, preLog + LogMsg.EndLocNotFound(areas: taskInfo.EndAreas));
                }
 
                var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, model.CntId, taskInfo.TaskName);
 
                (ok, msg) = DbTran.CreateTask(new CreateTaskObj {
                    StartLocToUpdate = startLoc,
                    EndLocToUpdate = endLoc,
                    TaskToInsert = task,
                });
                return NewSimpleResult(ok ? 0 : 500, preLog + msg);
            }
            catch (Exception ex) {
                return NewSimpleResult(ex, preLog);
            }
        }
    }
 
    public class ForceModel {
        public class ForceCreateTaskInfo {
            public string StartLoc { get; set; }
            public string EndLoc { get; set; }
            public string CntId { get; set; } // 可为空
        }
    }
}