李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.chinaztt.mes.production.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
import com.chinaztt.mes.production.dto.FeedingDTO;
import com.chinaztt.mes.production.dto.FeedingInDTO;
import com.chinaztt.mes.production.entity.Feeding;
import com.chinaztt.mes.production.service.FeedingService;
import com.chinaztt.mes.warehouse.dto.FeedingStockDTO;
import com.chinaztt.mes.warehouse.service.StockService;
import com.chinaztt.ztt.common.core.util.R;
import com.chinaztt.ztt.common.log.annotation.SysLog;
import com.chinaztt.ztt.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 投料登记
 *
 * @author cxf
 * @date 2020-11-12 10:48:37
 */
@RestController
@AllArgsConstructor
@RequestMapping("/feeding")
@Api(value = "feeding", tags = "投料登记管理")
public class FeedingController {
 
    private final FeedingService feedingService;
    private final StockService stockService;
 
    /**
     * 查询投料信息
     *
     * @param feedingDTO 投料登记
     * @return
     */
    @ApiOperation(value = "查询投料信息", notes = "查询投料信息")
    @GetMapping("/getFeedingByWorkstationId")
    public R getFeedingByWorkstationId(FeedingDTO feedingDTO) {
        return R.ok(feedingService.getFeedingByWorkstationId(QueryWrapperUtil.gen(feedingDTO)));
    }
 
    /**
     * 分页查询
     *
     * @param page    分页对象
     * @param feeding 投料登记
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getOptaskFeedingPage(Page page, Feeding feeding) {
        return R.ok(feedingService.page(page, Wrappers.query(feeding)));
    }
 
    /**
     * 通过id查询投料登记
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(feedingService.getById(id));
    }
 
    /**
     * 投料
     *
     * @param feedingInDTO 投料登记
     * @return R
     */
    @ApiOperation(value = "投料", notes = "投料")
    @SysLog("投料")
    @PostMapping
    public R saveList(@RequestBody FeedingInDTO feedingInDTO) {
        return R.ok(feedingService.feeding(feedingInDTO));
    }
 
    /**
     * 退料
     *
     * @param feedingList 投料登记
     * @return R
     */
    @ApiOperation(value = "退料", notes = "退料")
    @SysLog("退料")
    @PutMapping
    public R update(@RequestBody List<FeedingDTO> feedingList) {
        return R.ok(feedingService.rejectFeeding(feedingList));
    }
 
    /**
     * 通过id删除投料登记
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除投料登记", notes = "通过id删除投料登记")
    @SysLog("通过id删除投料登记")
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return R.ok(feedingService.removeById(id));
    }
 
    /**
     * PDA查询所有
     *
     * @param feedingStockDTO 投料
     * @return
     */
    @ApiOperation(value = "PDA查询所有", notes = "PDA查询所有")
    @GetMapping("/pda/list")
    @Inner(false)
    public R pdaList(FeedingStockDTO feedingStockDTO) {
        return R.ok(stockService.pdaList(QueryWrapperUtil.gen(feedingStockDTO)));
    }
 
    /**
     * PDA投料
     *
     * @param feedingStockDTOList 投料登记
     * @return R
     */
    @ApiOperation(value = "PDA投料", notes = "PDA投料")
    @PostMapping("/pda/add")
    public R pdaAdd(@RequestBody List<FeedingStockDTO> feedingStockDTOList) {
        List<String> result = new ArrayList<String>();
        String msg = "";
        for (FeedingStockDTO feedingStockDTO : feedingStockDTOList) {
            try {
                feedingService.pdaAdd(feedingStockDTO);
            } catch (RuntimeException e) {
                msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":" + e.getMessage() + "\n";
                result.add(feedingStockDTO.getSid());
            } catch (Exception e) {
                msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":系统错误\n";
                result.add(feedingStockDTO.getSid());
            }
        }
        if (CollectionUtil.isNotEmpty(result)) {
            return R.failed(result, msg);
        } else {
            return R.ok();
        }
    }
 
    /**
     * PDA退料
     *
     * @param stockDTOList 投料登记
     * @return R
     */
    @ApiOperation(value = "PDA退料", notes = "PDA退料")
    @PostMapping("/pda/return")
    public R pdaReturn(@RequestBody List<FeedingStockDTO> stockDTOList) {
        List<String> result = new ArrayList<String>();
        String msg = "";
        for (FeedingStockDTO feedingStockDTO : stockDTOList) {
            try {
                feedingService.pdaReturn(feedingStockDTO);
            } catch (RuntimeException e) {
                msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":" + e.getMessage() + "\n";
                result.add(feedingStockDTO.getSid());
            } catch (Exception e) {
                msg += feedingStockDTO.getPartNo() + "#" + feedingStockDTO.getPartBatchNo() + ":系统错误\n";
                result.add(feedingStockDTO.getSid());
            }
        }
        if (CollectionUtil.isNotEmpty(result)) {
            return R.failed(result, msg);
        } else {
            return R.ok();
        }
    }
 
    @GetMapping(value = "/getReturnLocations/{workstationId}")
    public R getReturnLocations(@PathVariable("workstationId") Long workstationId) {
        return R.ok(feedingService.getReturnLocations(workstationId));
    }
}