111
tjx
2025-12-05 e2778527b8db64879a5080a64669e5dd9ab016d2
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
using MES.Service.Dto.service;
using MES.Service.Modes;
using MES.Service.service;
using MES.Service.service.Warehouse;
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
 
namespace MESApplication.Controllers.Warehouse
{
    [ApiController]
    [Route("api/[controller]")]
    public class MesPalletBinding1Controller : ControllerBase
    {
        private readonly MessageCenterManager _manager = new();
        private readonly MesPalletBinding1Manager m = new();
        private readonly string METHOD = "POST";
        private readonly string TableName = "mespalletbinding1";
 
        private readonly string URL =
            "http://localhost:10054/api/mespalletbinding1/";
 
        /// <summary>
        /// 从外部接口获取栈板绑定信息并保存到数据库
        /// </summary>
        /// <param name="palletBinding">栈板绑定信息</param>
        /// <returns></returns>
        [HttpPost("SavePalletBindingData")]
        public ResponseResult SavePalletBindingData([FromBody] MesPalletBinding palletBinding)
        {
            try
            {
                // 调用业务逻辑层方法将数据保存到数据库
                int insertedCount = m.InsertPalletBindingData(palletBinding);
 
                if (insertedCount > 0)
                {
                    return new ResponseResult
                    {
                        status = 0,
                        message = $"成功插入 {insertedCount} 条栈板绑定数据",
                        data = insertedCount
                    };
                }
                else
                {
                    return new ResponseResult
                    {
                        status = 1,
                        message = "未插入任何数据,可能是因为接口返回的数据为空",
                        data = null
                    };
                }
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
 
        /// <summary>
        /// 检查栈板码在数据库中是否存在
        /// </summary>
        /// <param name="stackCode">栈板码</param>
        /// <returns></returns>
        [HttpPost("CheckStackCodeExists")]
        public ResponseResult CheckStackCodeExists([FromBody] dynamic request)
        {
            try
            {
                string stackCode = request.stackCode;
                bool exists = m.CheckStackCodeExists(stackCode);
 
                return new ResponseResult
                {
                    status = 0,
                    message = exists ? "栈板码已存在" : "栈板码不存在",
                    data = exists
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
 
        /// <summary>
        /// 从外部接口获取栈板绑定信息并保存到数据库(带存在性检查)
        /// </summary>
        /// <param name="palletBinding">栈板绑定信息</param>
        /// <returns></returns>
        [HttpPost("SavePalletBindingDataWithCheck")]
        public async Task<ResponseResult> SavePalletBindingDataWithCheck([FromBody] MesPalletBinding palletBinding)
        {
            try
            {
                // 调用业务逻辑层方法将数据保存到数据库(带存在性检查)
                int result = await m.InsertPalletBindingDataWithCheckAsync(palletBinding);
 
                return new ResponseResult
                {
                    status = 0,
                    message = result > 0 ? $"成功处理 {result} 条栈板绑定数据" : "未处理任何数据,可能是因为接口返回的数据为空",
                    data = result
                };
            }
            catch (Exception ex)
            {
                return ResponseResult.ResponseError(ex);
            }
        }
    }
}