bklLiudl
2025-04-02 1bbbbc8bb49411b544626996a1370788142300e0
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
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Model.ModelVm.BllTaskVm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Wms.Tools;
using WMS.IBLL.IBllTaskServer;
 
namespace Wms.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class BllTaskController : ControllerBase
    {
        #region 依赖注入
        private readonly ApiUrlConfig _config; //接口交互路径
        private readonly IBllTaskSyncServer _taskSyncSvc;                    // 入库单据Svc 
        #endregion
 
        #region 构造函数
        public BllTaskController(IOptions<ApiUrlConfig> setting, IBllTaskSyncServer taskSyncSvc)
        {
            _config = setting.Value;
            _taskSyncSvc = taskSyncSvc;
        }
        #endregion
 
        /// <summary>
        /// 任务同步列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetTaskSyncList(TaskSyncVm model)
        {
            try
            {
                var bolls = _taskSyncSvc.GetTaskSyncList(model, out int count);
 
                return Ok(new { code = 0, count, msg = "任务同步信息", data = bolls });
            }
            catch (Exception e)
            {
                return Ok(new { code = 1, msg = e.Message });
            }
        }
        /// <summary>
        /// 处理WCS同步过来的任务
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult HandleTaskSync(TaskSyncInfoVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var uId = int.Parse(userId);
                _taskSyncSvc.HandleTaskSync(model.TaskNo, model.OrderNo, _config.WcsHost + _config.IssueComApiUrl, uId);
 
                return Ok(new { data = "", code = 0, msg = "处理成功" });
            }
            catch (Exception e)
            {
                return Ok(new { data = "", code = 1, msg = $"异常:{e.Message}" });
            }
        }
        /// <summary>
        /// 处理WCS同步过来的任务-无需处理
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult NoHandleTaskSync(TaskSyncInfoVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var uId = int.Parse(userId);
                _taskSyncSvc.NoHandleTaskSync(model.TaskNo, uId);
 
                return Ok(new { data = "", code = 0, msg = "处理成功" });
            }
            catch (Exception e)
            {
                return Ok(new { data = "", code = 1, msg = $"异常:{e.Message}" });
            }
        }
        /// <summary>
        /// 获取单据列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetOrderNoList(string type)
        {
            try
            {
                var models = _taskSyncSvc.GetOrderNoList(type);
 
                return Ok(new { code = 0, msg = "入库单信息", data = models });
            }
            catch (Exception e)
            {
                return Ok(new { code = 1, msg = e.Message });
            }
        }
    }
}