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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package com.ruoyi.production.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.procurementrecord.dto.ProcurementDto;
import com.ruoyi.production.dto.ProcessSchedulingDto;
import com.ruoyi.production.dto.ProductionDispatchAddDto;
import com.ruoyi.production.dto.SalesLedgerSchedulingDto;
import com.ruoyi.production.dto.SalesLedgerSchedulingProcessDto;
import com.ruoyi.production.mapper.SpeculativeTradingInfoMapper;
import com.ruoyi.production.pojo.SpeculativeTradingInfo;
import com.ruoyi.production.service.impl.SalesLedgerSchedulingServiceImpl;
import com.ruoyi.sales.mapper.LossMapper;
import com.ruoyi.sales.pojo.Loss;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author :yys
 * @date : 2025/7/21 14:43
 */
@RestController
@Api(tags = "生产订单")
@RequestMapping("/salesLedger/scheduling")
public class SalesLedgerSchedulingController extends BaseController {
 
    @Autowired
    private SalesLedgerSchedulingServiceImpl salesLedgerSchedulingService;
 
 
    @Autowired
    private SpeculativeTradingInfoMapper speculativeTradingInfoMapper;
 
    @Autowired
    private LossMapper lossMapper;
 
    @GetMapping("/loss")
    @Log(title = "生产管理-生产派工-损耗率", businessType = BusinessType.OTHER)
    @ApiOperation("生产管理-生产派工-损耗率")
    public AjaxResult loss() {
        return AjaxResult.success(lossMapper.selectList(null));
    }
 
    @PostMapping("/addLoss")
    @Log(title = "生产管理-生产派工-添加损耗率", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-生产派工-添加损耗率")
    public AjaxResult addLoss(@RequestBody Loss loss) {
        lossMapper.insert(loss);
        return AjaxResult.success("添加损耗率成功");
    }
 
    @PostMapping("/updateLoss")
    @Log(title = "生产管理-生产派工-修改损耗率", businessType = BusinessType.UPDATE)
    @ApiOperation("生产管理-生产派工-修改损耗率")
    public AjaxResult updateLoss(@RequestBody Loss loss) {
        lossMapper.updateById(loss);
        return AjaxResult.success("修改损耗率成功");
    }
 
    @GetMapping("/list")
    @Log(title = "生产管理-生产派工-炒机信息", businessType = BusinessType.OTHER)
    @ApiOperation("生产管理-生产派工-炒机信息")
    public AjaxResult list() {
        List<SpeculativeTradingInfo> result = speculativeTradingInfoMapper.selectList(null);
        result.forEach(item -> {
            item.setCurrentWorkLoad(salesLedgerSchedulingService.getSchedulingNumBySpeculativeTradingName(item.getName()).divide(new BigDecimal(1000),2, RoundingMode.CEILING));
            item.setVacant(item.getWorkLoad().subtract(item.getCurrentWorkLoad()).setScale(2, RoundingMode.HALF_UP)); //保留两位小数
        });
        return AjaxResult.success(result);
    }
 
    @PostMapping("/addSpeculatTrading")
    @Log(title = "生产管理-生产派工-添加炒机信息", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-生产派工-添加炒机信息")
    public AjaxResult addSpeculatTrading(@RequestBody List<SpeculativeTradingInfo> speculativeTradingInfo) {
        if(CollectionUtils.isEmpty(speculativeTradingInfo)) return AjaxResult.error("数据组不能为空");
        speculativeTradingInfo.forEach(item -> {
            speculativeTradingInfoMapper.insert(item);
        });
        return AjaxResult.success("添加炒机信息成功");
    }
 
    @PostMapping("/updateSpeculatTrading")
    @Log(title = "生产管理-生产派工-修改炒机信息", businessType = BusinessType.UPDATE)
    @ApiOperation("生产管理-生产派工-修改炒机信息")
    public AjaxResult updateSpeculatTrading(@RequestBody List<SpeculativeTradingInfo> speculativeTradingInfo) {
        if(CollectionUtils.isEmpty(speculativeTradingInfo)) return AjaxResult.error("数据组不能为空");
        speculativeTradingInfo.forEach(item -> {
            speculativeTradingInfoMapper.updateById(item);
        });
        return AjaxResult.success("修改炒机信息成功");
    }
 
 
    @GetMapping("/listPage")
    @Log(title = "生产管理-生产订单-分页查询", businessType = BusinessType.OTHER)
    @ApiOperation("生产管理-生产订单-分页查询")
    public AjaxResult listPage(Page page, SalesLedgerSchedulingDto salesLedgerSchedulingDto) {
        IPage<SalesLedgerSchedulingDto> result = salesLedgerSchedulingService.listPage(page,salesLedgerSchedulingDto);
        return AjaxResult.success(result);
    }
 
    /**
     * 导出
     * @param response
     */
    @PostMapping("/export")
    @ApiOperation("生产管理-生产订单-导出")
    public void export(HttpServletResponse response) {
        salesLedgerSchedulingService.export(response);
    }
 
 
    /**
     * 导出
     * @param response
     */
    @PostMapping("/exportOne")
    @ApiOperation("生产管理-生产派工-导出")
    public void exportOne(HttpServletResponse response) {
        salesLedgerSchedulingService.exportOne(response);
    }
 
    @PostMapping("/productionDispatch")
    @Log(title = "生产管理-生产订单-生产派工", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-生产订单-生产派工")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult productionDispatch(@RequestBody ProductionDispatchAddDto productionDispatchAddDto) {
        List<ProductionDispatchAddDto> productionDispatchAddDtoList = new ArrayList<>();
        productionDispatchAddDtoList.add(productionDispatchAddDto);
        String result = salesLedgerSchedulingService.productionDispatch(productionDispatchAddDtoList);
        return AjaxResult.success(result);
    }
 
    @PostMapping("/productionDispatchList")
    @Log(title = "生产管理-生产订单-自动派工", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-生产订单-自动派工")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult productionDispatchList(@RequestBody List<ProductionDispatchAddDto> productionDispatchAddDto) {
        String result = salesLedgerSchedulingService.productionDispatch(productionDispatchAddDto);
        return AjaxResult.success(result);
    }
 
    @GetMapping("/listPageProcess")
    @Log(title = "生产管理-工序排产-分页查询", businessType = BusinessType.OTHER)
    @ApiOperation("生产管理-工序排产-分页查询")
    public AjaxResult listPageProcess(Page page, SalesLedgerSchedulingProcessDto salesLedgerSchedulingDto) {
        IPage<SalesLedgerSchedulingProcessDto> result = salesLedgerSchedulingService.listPageProcess(page,salesLedgerSchedulingDto);
        return AjaxResult.success(result);
    }
 
    /**
     * 导出
     * @param response
     */
    @PostMapping("/exportTwo")
    @ApiOperation("生产管理-工序排产-导出")
    public void exportTwo(HttpServletResponse response) {
        Page page = new Page(-1,-1);
        SalesLedgerSchedulingProcessDto salesLedgerSchedulingDto = new SalesLedgerSchedulingProcessDto();
        IPage<SalesLedgerSchedulingProcessDto> result = salesLedgerSchedulingService.listPageProcess(page,salesLedgerSchedulingDto);
        result.getRecords().forEach(item -> {
            item.setStatusName(item.getStatus().toString());
        });
        ExcelUtil<SalesLedgerSchedulingProcessDto> util = new ExcelUtil<>(SalesLedgerSchedulingProcessDto.class);
        util.exportExcel(response, result.getRecords(), "工序排产");
    }
 
 
    @DeleteMapping("/productionDispatchDelete")
    @Log(title = "生产管理-工序排产-取消排产", businessType = BusinessType.DELETE)
    @ApiOperation("生产管理-工序排产-取消排产")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult productionDispatchDelete(@RequestBody List<Long> ids) {
        int result = salesLedgerSchedulingService.productionDispatchDelete(ids);
        return AjaxResult.success(result);
    }
 
 
    @PostMapping("/processScheduling")
    @Log(title = "生产管理-工序排产", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-工序排产")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult processScheduling(@RequestBody List<ProcessSchedulingDto> processSchedulingDto) {
        int result = salesLedgerSchedulingService.processScheduling(processSchedulingDto);
        return AjaxResult.success(result);
    }
 
 
}