1
z8018
2025-06-10 e46aa927d231af83724683c7286d9db503e24cf7
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
139
140
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar.Extensions;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseController;
using WIDESEAWCS_DTO.PlacedBlockDTO;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_Server.Controllers.BasicInfo
{
    [Route("api/Container")]
    [ApiController]
    public class ContainerController : ApiBaseController<IContainerService, Dt_Container>
    {
        private readonly IContainerRepository _containerRepository;
        private readonly IOrderContainerRepository _orderContainerRepository;
        private readonly IOrderDetailsRepository _orderDetailsRepository;
        private readonly IOrderrowsRepository _orderrowsRepository;
        private readonly IContainerItemRepository _containerItemRepository;
        public ContainerController(IContainerService service, IContainerRepository containerRepository, IOrderContainerRepository orderContainerRepository, IOrderDetailsRepository orderDetailsRepository, IOrderrowsRepository orderrowsRepository, IContainerItemRepository containerItemRepository) : base(service)
        {
            _containerRepository = containerRepository;
            _orderContainerRepository = orderContainerRepository;
            _orderDetailsRepository = orderDetailsRepository;
            _orderrowsRepository = orderrowsRepository;
            _containerItemRepository = containerItemRepository;
        }
 
        [HttpPost, HttpGet, Route("GetTaskPosition"), AllowAnonymous]
        public TaskPosition GetTaskPosition([FromBody] Point3D point3D, int length, int width, int height, int edge)
        {
            PlaceBlockService placeBlockService = new PlaceBlockService(new ContainerSize(), null);
            return placeBlockService.GetTaskPosition(point3D, length, width, height, edge);
        }
 
        [HttpPost, HttpGet, Route("GetPutStations"), AllowAnonymous]
        public WebResponseContent GetPutStations(string deviceCode)
        {
            try
            {
                List<Dt_Container> containers = _containerRepository.QueryData(x => x.DeviceCode == deviceCode && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt());
                List<object> list = new List<object>();
                foreach (var container in containers)
                {
                    List<string> containerItemCodes = _containerItemRepository.QueryData(x => x.ContainerId == container.Id).Select(x => x.ItemCode).ToList();
 
                    Dt_OrderContainer orderContainer = _orderContainerRepository.QueryFirst(x => x.ContainerId == container.Id && x.ContainerCode == container.ContainerCode);
                    if (orderContainer != null)
                    {
                        Orderrows orderrows = _orderrowsRepository.QueryFirst(x => x.id == orderContainer.OrderId);
                        if (orderrows != null)
                        {
                            List<OrderDetails> totalDetails = _orderDetailsRepository.QueryData(x => x.Orderrowsid == orderrows.id);
                            List<OrderDetails> details = totalDetails.Where(x => x.Orderrowsid == orderrows.id && x.Orderdetails_status == PalletingStatusEnmu.PalletingSuccess.ObjToInt() && containerItemCodes.Contains(x.Orderdetails_outid)).ToList();
 
                            int sortedNum = totalDetails.Where(x => x.Orderrowsid == orderrows.id && x.Orderdetails_status == PalletingStatusEnmu.PalletingSuccess.ObjToInt()).Count();
 
                            List<object> orderData = new List<object>();
                            foreach (var item in details)
                            {
                                object obj = new
                                {
                                    name = item.Orderdetails_name,
                                    baseName = item.Orderdetails_productName,
                                    size = $"{item.Orderdetails_length}*{item.Orderdetails_width}*{item.Orderdetails_thickness}",
                                    process = "",
                                };
                                orderData.Add(obj);
                            }
                            object data = new
                            {
                                orderCode = orderrows.Orderrows_orderid,
                                orderName = orderrows.Orderrows_name,
                                cusName = orderrows.Orderrows_customer,
                                stationCode = container.ContainerCode,
                                orderTotalNum = totalDetails.Count,
                                sortedNum = sortedNum,
                                unsortedNum = totalDetails.Count - sortedNum,
                                stationSortedNum = details.Count,
                                orderData = orderData,
                                orderId = orderrows.id
                            };
                            list.Add(data);
                        }
                        else
                        {
                            object data = new
                            {
                                stationSortedNum = 0,
                                stationCode = container.ContainerCode,
                                orderTotalNum = 0,
                                sortedNum = 0,
                                unsortedNum = 0,
                                orderData = new List<object>()
                            };
                            list.Add(data);
                        }
                    }
                    else
                    {
                        object data = new
                        {
                            stationCode = container.ContainerCode,
                            orderTotalNum = 0,
                            sortedNum = 0,
                            unsortedNum = 0,
                            stationSortedNum = 0,
                            orderData = new List<object>()
                        };
                        list.Add(data);
                    }
                }
 
                return WebResponseContent.Instance.OK(data: list);
            }
            catch (Exception ex)
            {
                return new WebResponseContent()
                {
                    Code = 500,
                    Message = ex.Message
                };
            }
        }
 
        [HttpPost, HttpGet, Route("ReleaseContainer"), AllowAnonymous]
        public WebResponseContent ReleaseContainer([FromBody] int[] keys)
        {
            return Service.AutoReleaseContainer(keys);
        }
    }
}