11
tjx
6 天以前 d883e7249dcd37f9bd23ea0c68d6f42bf90e398f
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
using System.Dynamic;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using MES.Service.service.Warehouse;
using MES.Service.util;
using Microsoft.AspNetCore.Mvc;
 
namespace MESApplication.Controllers.Warehouse;
 
[ApiController]
[Route("api/[controller]")]
public class MesInvItemStocksController : ControllerBase
{
    private readonly MesInvItemStocksManager m = new();
 
    /// <summary>
    ///     获取可退货物料库存(旧版本,保留兼容)
    /// </summary>
    /// <returns></returns>
    [HttpPost("GetReturnableStocks")]
    public ResponseResult GetReturnableStocks()
    {
        try
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.GetReturnableStocks();
            return new ResponseResult
            {
                status = 0,
                message = "OK",
                data = resultInfos
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    /// <summary>
    ///     获取可退货物料库存(带分页和搜索)
    /// </summary>
    /// <param name="searchDto">搜索请求参数</param>
    /// <returns></returns>
    [HttpPost("GetReturnableStocksWithPaging")]
    public ResponseResult GetReturnableStocksWithPaging([FromBody] ReturnableStockSearchDto searchDto)
    {
        try
        {
            var result = m.GetReturnableStocks(searchDto);
            return new ResponseResult
            {
                status = 0,
                message = "查询成功",
                data = result
            };
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    /// <summary>
    ///     生成退料请求单
    /// </summary>
    /// <param name="dto">退料请求参数</param>
    /// <returns></returns>
    [HttpPost("CreateReturnMaterialRequest")]
    public ResponseResult CreateReturnMaterialRequest([FromBody] ItemStockQueryDto dto)
    {
        try
        {
            var result = m.CreateReturnMaterialRequest(dto);
            if (result)
            {
                return new ResponseResult
                {
                    status = 0,
                    message = "退料请求单生成成功",
                    data = null
                };
            }
            else
            {
                return new ResponseResult
                {
                    status = 1,
                    message = "退料请求单生成失败",
                    data = null
                };
            }
        }
        catch (Exception ex)
        {
            return ResponseResult.ResponseError(ex);
        }
    }
 
    /// <summary>
    ///     导出可退货物料库存为Excel
    /// </summary>
    /// <param name="searchDto">搜索请求参数</param>
    /// <returns>Excel文件</returns>
    [HttpPost("ExportReturnableStocks")]
    public IActionResult ExportReturnableStocks([FromBody] ReturnableStockSearchDto searchDto)
    {
        try
        {
            var fileBytes = m.ExportReturnableStocksToExcel(searchDto);
            var fileName = $"可退货物料库存_{DateTime.Now:yyyyMMddHHmmss}.xlsx";
            
            return File(fileBytes, 
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
                fileName);
        }
        catch (Exception ex)
        {
            return BadRequest(new ResponseResult
            {
                status = 1,
                message = $"导出失败: {ex.Message}",
                data = null
            });
        }
    }
}