yantian yue
2023-10-17 487b2f2a353b89ab46cd9b784226b600b7b915b8
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package cn.stylefeng.guns.modular.zsx.pm.salesOrder.controller;
 
import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.view.PoiBaseView;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.entity.SalesOrder;
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.params.SalesOrderParam;
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.SalesOrderService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.core.mutidatasource.annotion.DataSource;
import com.baomidou.mybatisplus.extension.api.R;
import lombok.SneakyThrows;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
 
/**
 * 生产订单控制器
 *
 * @author ruimin
 * @Date 2023-08-26 15:55:23
 */
@Controller
@RequestMapping("/salesOrder")
public class SalesOrderController extends BaseController {
 
    private String PREFIX = "/modular/pm/salesOrder";
 
    @Autowired
    private SalesOrderService salesOrderService;
 
    /**
     * 跳转到主页面
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/salesOrder.html";
    }
 
    /**
     * 新增页面
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/salesOrder_add.html";
    }
 
    /**
     * 编辑页面
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/salesOrder_edit.html";
    }
 
    /**
     * 拆分页面
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/split")
    public String split() {
        return PREFIX + "/split.html";
    }
 
    /**
     * 下发页面
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/bindParam")
    public String bindParam() {
        return PREFIX + "/bindParam.html";
    }
 
    /**
     * 新增接口
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/addItem")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData addItem(SalesOrderParam salesOrderParam) {
        this.salesOrderService.add(salesOrderParam);
        return ResponseData.success();
    }
 
    /**
     * 编辑接口
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/editItem")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData editItem(SalesOrderParam salesOrderParam) {
        this.salesOrderService.update(salesOrderParam);
        return ResponseData.success();
    }
 
    /**
     * 编辑接口
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/updateBySalesOrderId")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData updateBySalesOrderId(SalesOrderParam salesOrderParam) {
        SalesOrder byId = this.salesOrderService.getById(salesOrderParam.getId());
        byId.setState("2");
        this.salesOrderService.saveOrUpdate(byId);
        return ResponseData.success();
    }
 
 
    /**
     * 删除接口
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/delete")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData delete(SalesOrderParam salesOrderParam) {
        this.salesOrderService.delete(salesOrderParam);
        return ResponseData.success();
    }
 
    /**
     * 查看详情接口
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @RequestMapping("/detail")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData detail(SalesOrderParam salesOrderParam) {
        SalesOrder detail = this.salesOrderService.getById(salesOrderParam.getId());
        return ResponseData.success(detail);
    }
 
    /**
     * 查询列表
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @ResponseBody
    @RequestMapping("/list")
    @DataSource(name = "self")
    public LayuiPageInfo list(SalesOrderParam salesOrderParam) {
        return this.salesOrderService.findPageBySpec(salesOrderParam);
    }
 
    /**
     * 拆分订单方法
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @ResponseBody
    @RequestMapping("/breakDownOrders")
    @DataSource(name = "self")
    public LayuiPageInfo breakDownOrders(SalesOrderParam salesOrderParam) {
        return this.salesOrderService.breakDownOrders(salesOrderParam);
    }
 
    /**
     * 拆分绑定下发方法
     *
     * @author ruimin
     * @Date 2023-08-26
     */
    @ResponseBody
    @RequestMapping("/DistributeSalesOrder")
    @DataSource(name = "self")
    public ResponseData DistributeSalesOrder(SalesOrderParam salesOrderParam) {
        this.salesOrderService.DistributeSalesOrder(salesOrderParam);
        return ResponseData.success();
    }
 
    /**
     * 导入excel
     *
     * @author liwenya
     * @Date 2021-07-09
     */
    @SneakyThrows
    @RequestMapping(value = "/importIn")
    @ResponseBody
    @DataSource(name = "self")
    public ResponseData importIn(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws IOException {
 
        List<SalesOrder> list = new ArrayList<>();
        XSSFWorkbook sheets = new XSSFWorkbook(file.getInputStream());
        //获取sheet
        XSSFSheet sheet = sheets.getSheet(sheets.getSheetName(0));
        int rows = sheet.getPhysicalNumberOfRows();
        for(int i = 2; i < rows; i++){
            //获取列数
            XSSFRow row = sheet.getRow(i);
            SalesOrder salesOrder = new SalesOrder();
            salesOrder.setSalesOrderCode(String.valueOf(row.getCell(0)).replace(".0", ""));
            salesOrder.setCustomerNo(String.valueOf(row.getCell(1)).replace(".0", ""));
            salesOrder.setCargoNo(row.getCell(2).toString().replace(".0", ""));
            salesOrder.setProductCode(row.getCell(3).toString().replace(".0", ""));
            salesOrder.setProductName(row.getCell(4).toString().replace(".0", ""));
            Cell planNumber = row.getCell(5);
            if(!Objects.equals(planNumber, null) && !Objects.equals(planNumber.toString(),"")){
                double d = planNumber.getNumericCellValue();
                salesOrder.setPlanNumber((int) d);
            }
 
            Cell planStartTime = row.getCell(6);
            if(HSSFDateUtil.isCellDateFormatted(planStartTime)){
                Date d = planStartTime.getDateCellValue();
                salesOrder.setPlanStartTime(d);
            }
 
            Cell planEndTime = row.getCell(7);
            if(HSSFDateUtil.isCellDateFormatted(planEndTime)){
                Date d = planEndTime.getDateCellValue();
                salesOrder.setPlanEndTime(d);
            }
 
            salesOrder.setWorkshopCode(row.getCell(8).toString().replace(".0", ""));
            salesOrder.setLineCode(row.getCell(9).toString().replace(".0", ""));
 
            Cell deliveryTime = row.getCell(10);
            if(HSSFDateUtil.isCellDateFormatted(deliveryTime)){
                Date d = deliveryTime.getDateCellValue();
                salesOrder.setDeliveryTime(d);
            }
 
            salesOrder.setOrderSource(row.getCell(11).toString().replace(".0", ""));
            salesOrder.setRemark(row.getCell(12).toString().replace(".0", ""));
            salesOrder.setState("1");
            list.add(salesOrder);
        }
 
        for(SalesOrder salesOrder : list){
            salesOrderService.save(salesOrder);
        }
        return ResponseData.success("上传成功");
    }
 
    /**
     * excel导出模板
     *
     * @author liwenya
     * @Date 2021年7月9日 17点01分
     */
    @RequestMapping("/exportOut")
    public void exportOut(ModelMap modelMap, HttpServletRequest request,
                          HttpServletResponse response) {
        List<ExcelExportEntity> entity = new ArrayList<>();
        entity.add(new ExcelExportEntity("订单编号", "salesOrderCode"));
        entity.add(new ExcelExportEntity("客户编号", "customerNo"));
        entity.add(new ExcelExportEntity("货号", "cargoNo"));
        entity.add(new ExcelExportEntity("产品编号", "productCode"));
        entity.add(new ExcelExportEntity("产品名称", "productName"));
        entity.add(new ExcelExportEntity("计划数量", "planNumber"));
        entity.add(new ExcelExportEntity("计划开始时间", "planStartTime"));
        entity.add(new ExcelExportEntity("计划结束时间", "planEndTime"));
        entity.add(new ExcelExportEntity("车间编码", "workshopCode"));
        entity.add(new ExcelExportEntity("产线编码", "lineCode"));
        entity.add(new ExcelExportEntity("交货时间", "deliveryTime"));
        entity.add(new ExcelExportEntity("订单来源", "orderSource"));
        entity.add(new ExcelExportEntity("备注", "remark"));
 
        ExportParams params = new ExportParams("生产订单", "生产订单", ExcelType.XSSF);
        modelMap.put(MapExcelConstants.MAP_LIST, new ArrayList<>());
        modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
        modelMap.put(MapExcelConstants.PARAMS, params);
        modelMap.put(MapExcelConstants.FILE_NAME, "生产订单");
        PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
    }
 
 
}