提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.modular.zsx.pm.salesOrder.controller; |
懒 |
2 |
|
|
3 |
import cn.afterturn.easypoi.entity.vo.MapExcelConstants; |
|
4 |
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
5 |
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; |
|
6 |
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; |
|
7 |
import cn.afterturn.easypoi.view.PoiBaseView; |
|
8 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
9 |
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.entity.SalesOrder; |
|
10 |
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.params.SalesOrderParam; |
|
11 |
import cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.SalesOrderService; |
|
12 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
13 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
14 |
import cn.stylefeng.roses.core.mutidatasource.annotion.DataSource; |
|
15 |
import com.baomidou.mybatisplus.extension.api.R; |
|
16 |
import lombok.SneakyThrows; |
|
17 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil; |
|
18 |
import org.apache.poi.ss.usermodel.Cell; |
|
19 |
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
20 |
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
21 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
22 |
import org.springframework.beans.factory.annotation.Autowired; |
|
23 |
import org.springframework.stereotype.Controller; |
|
24 |
import org.springframework.ui.ModelMap; |
|
25 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
26 |
import org.springframework.web.bind.annotation.RequestPart; |
|
27 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
28 |
import org.springframework.web.multipart.MultipartFile; |
|
29 |
|
|
30 |
import javax.servlet.http.HttpServletRequest; |
|
31 |
import javax.servlet.http.HttpServletResponse; |
|
32 |
import java.io.IOException; |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.Date; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Objects; |
|
37 |
|
|
38 |
|
|
39 |
/** |
|
40 |
* 生产订单控制器 |
|
41 |
* |
|
42 |
* @author ruimin |
|
43 |
* @Date 2023-08-26 15:55:23 |
|
44 |
*/ |
|
45 |
@Controller |
|
46 |
@RequestMapping("/salesOrder") |
|
47 |
public class SalesOrderController extends BaseController { |
|
48 |
|
|
49 |
private String PREFIX = "/modular/pm/salesOrder"; |
|
50 |
|
|
51 |
@Autowired |
|
52 |
private SalesOrderService salesOrderService; |
|
53 |
|
|
54 |
/** |
|
55 |
* 跳转到主页面 |
|
56 |
* |
|
57 |
* @author ruimin |
|
58 |
* @Date 2023-08-26 |
|
59 |
*/ |
|
60 |
@RequestMapping("") |
|
61 |
public String index() { |
|
62 |
return PREFIX + "/salesOrder.html"; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* 新增页面 |
|
67 |
* |
|
68 |
* @author ruimin |
|
69 |
* @Date 2023-08-26 |
|
70 |
*/ |
|
71 |
@RequestMapping("/add") |
|
72 |
public String add() { |
|
73 |
return PREFIX + "/salesOrder_add.html"; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* 编辑页面 |
|
78 |
* |
|
79 |
* @author ruimin |
|
80 |
* @Date 2023-08-26 |
|
81 |
*/ |
|
82 |
@RequestMapping("/edit") |
|
83 |
public String edit() { |
|
84 |
return PREFIX + "/salesOrder_edit.html"; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* 拆分页面 |
|
89 |
* |
|
90 |
* @author ruimin |
|
91 |
* @Date 2023-08-26 |
|
92 |
*/ |
|
93 |
@RequestMapping("/split") |
|
94 |
public String split() { |
|
95 |
return PREFIX + "/split.html"; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* 下发页面 |
|
100 |
* |
|
101 |
* @author ruimin |
|
102 |
* @Date 2023-08-26 |
|
103 |
*/ |
|
104 |
@RequestMapping("/bindParam") |
|
105 |
public String bindParam() { |
|
106 |
return PREFIX + "/bindParam.html"; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* 新增接口 |
|
111 |
* |
|
112 |
* @author ruimin |
|
113 |
* @Date 2023-08-26 |
|
114 |
*/ |
|
115 |
@RequestMapping("/addItem") |
|
116 |
@ResponseBody |
|
117 |
@DataSource(name = "self") |
|
118 |
public ResponseData addItem(SalesOrderParam salesOrderParam) { |
|
119 |
this.salesOrderService.add(salesOrderParam); |
|
120 |
return ResponseData.success(); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* 编辑接口 |
|
125 |
* |
|
126 |
* @author ruimin |
|
127 |
* @Date 2023-08-26 |
|
128 |
*/ |
|
129 |
@RequestMapping("/editItem") |
|
130 |
@ResponseBody |
|
131 |
@DataSource(name = "self") |
|
132 |
public ResponseData editItem(SalesOrderParam salesOrderParam) { |
|
133 |
this.salesOrderService.update(salesOrderParam); |
|
134 |
return ResponseData.success(); |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* 编辑接口 |
|
139 |
* |
|
140 |
* @author ruimin |
|
141 |
* @Date 2023-08-26 |
|
142 |
*/ |
|
143 |
@RequestMapping("/updateBySalesOrderId") |
|
144 |
@ResponseBody |
|
145 |
@DataSource(name = "self") |
|
146 |
public ResponseData updateBySalesOrderId(SalesOrderParam salesOrderParam) { |
|
147 |
SalesOrder byId = this.salesOrderService.getById(salesOrderParam.getId()); |
|
148 |
byId.setState("2"); |
|
149 |
this.salesOrderService.saveOrUpdate(byId); |
|
150 |
return ResponseData.success(); |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
/** |
|
155 |
* 删除接口 |
|
156 |
* |
|
157 |
* @author ruimin |
|
158 |
* @Date 2023-08-26 |
|
159 |
*/ |
|
160 |
@RequestMapping("/delete") |
|
161 |
@ResponseBody |
|
162 |
@DataSource(name = "self") |
|
163 |
public ResponseData delete(SalesOrderParam salesOrderParam) { |
|
164 |
this.salesOrderService.delete(salesOrderParam); |
|
165 |
return ResponseData.success(); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* 查看详情接口 |
|
170 |
* |
|
171 |
* @author ruimin |
|
172 |
* @Date 2023-08-26 |
|
173 |
*/ |
|
174 |
@RequestMapping("/detail") |
|
175 |
@ResponseBody |
|
176 |
@DataSource(name = "self") |
|
177 |
public ResponseData detail(SalesOrderParam salesOrderParam) { |
|
178 |
SalesOrder detail = this.salesOrderService.getById(salesOrderParam.getId()); |
|
179 |
return ResponseData.success(detail); |
|
180 |
} |
|
181 |
|
|
182 |
/** |
|
183 |
* 查询列表 |
|
184 |
* |
|
185 |
* @author ruimin |
|
186 |
* @Date 2023-08-26 |
|
187 |
*/ |
|
188 |
@ResponseBody |
|
189 |
@RequestMapping("/list") |
|
190 |
@DataSource(name = "self") |
|
191 |
public LayuiPageInfo list(SalesOrderParam salesOrderParam) { |
|
192 |
return this.salesOrderService.findPageBySpec(salesOrderParam); |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* 拆分订单方法 |
|
197 |
* |
|
198 |
* @author ruimin |
|
199 |
* @Date 2023-08-26 |
|
200 |
*/ |
|
201 |
@ResponseBody |
|
202 |
@RequestMapping("/breakDownOrders") |
|
203 |
@DataSource(name = "self") |
|
204 |
public LayuiPageInfo breakDownOrders(SalesOrderParam salesOrderParam) { |
|
205 |
return this.salesOrderService.breakDownOrders(salesOrderParam); |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* 拆分绑定下发方法 |
|
210 |
* |
|
211 |
* @author ruimin |
|
212 |
* @Date 2023-08-26 |
|
213 |
*/ |
|
214 |
@ResponseBody |
|
215 |
@RequestMapping("/DistributeSalesOrder") |
|
216 |
@DataSource(name = "self") |
|
217 |
public ResponseData DistributeSalesOrder(SalesOrderParam salesOrderParam) { |
|
218 |
this.salesOrderService.DistributeSalesOrder(salesOrderParam); |
|
219 |
return ResponseData.success(); |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* 导入excel |
|
224 |
* |
|
225 |
* @author liwenya |
|
226 |
* @Date 2021-07-09 |
|
227 |
*/ |
|
228 |
@SneakyThrows |
|
229 |
@RequestMapping(value = "/importIn") |
|
230 |
@ResponseBody |
|
231 |
@DataSource(name = "self") |
|
232 |
public ResponseData importIn(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws IOException { |
|
233 |
|
|
234 |
List<SalesOrder> list = new ArrayList<>(); |
|
235 |
XSSFWorkbook sheets = new XSSFWorkbook(file.getInputStream()); |
|
236 |
//获取sheet |
|
237 |
XSSFSheet sheet = sheets.getSheet(sheets.getSheetName(0)); |
|
238 |
int rows = sheet.getPhysicalNumberOfRows(); |
|
239 |
for(int i = 2; i < rows; i++){ |
|
240 |
//获取列数 |
|
241 |
XSSFRow row = sheet.getRow(i); |
|
242 |
SalesOrder salesOrder = new SalesOrder(); |
|
243 |
salesOrder.setSalesOrderCode(String.valueOf(row.getCell(0)).replace(".0", "")); |
|
244 |
salesOrder.setCustomerNo(String.valueOf(row.getCell(1)).replace(".0", "")); |
|
245 |
salesOrder.setCargoNo(row.getCell(2).toString().replace(".0", "")); |
|
246 |
salesOrder.setProductCode(row.getCell(3).toString().replace(".0", "")); |
|
247 |
salesOrder.setProductName(row.getCell(4).toString().replace(".0", "")); |
|
248 |
Cell planNumber = row.getCell(5); |
|
249 |
if(!Objects.equals(planNumber, null) && !Objects.equals(planNumber.toString(),"")){ |
|
250 |
double d = planNumber.getNumericCellValue(); |
|
251 |
salesOrder.setPlanNumber((int) d); |
|
252 |
} |
|
253 |
|
|
254 |
Cell planStartTime = row.getCell(6); |
|
255 |
if(HSSFDateUtil.isCellDateFormatted(planStartTime)){ |
|
256 |
Date d = planStartTime.getDateCellValue(); |
|
257 |
salesOrder.setPlanStartTime(d); |
|
258 |
} |
|
259 |
|
|
260 |
Cell planEndTime = row.getCell(7); |
|
261 |
if(HSSFDateUtil.isCellDateFormatted(planEndTime)){ |
|
262 |
Date d = planEndTime.getDateCellValue(); |
|
263 |
salesOrder.setPlanEndTime(d); |
|
264 |
} |
|
265 |
|
|
266 |
salesOrder.setWorkshopCode(row.getCell(8).toString().replace(".0", "")); |
|
267 |
salesOrder.setLineCode(row.getCell(9).toString().replace(".0", "")); |
|
268 |
|
|
269 |
Cell deliveryTime = row.getCell(10); |
|
270 |
if(HSSFDateUtil.isCellDateFormatted(deliveryTime)){ |
|
271 |
Date d = deliveryTime.getDateCellValue(); |
|
272 |
salesOrder.setDeliveryTime(d); |
|
273 |
} |
|
274 |
|
|
275 |
salesOrder.setOrderSource(row.getCell(11).toString().replace(".0", "")); |
|
276 |
salesOrder.setRemark(row.getCell(12).toString().replace(".0", "")); |
|
277 |
salesOrder.setState("1"); |
|
278 |
list.add(salesOrder); |
|
279 |
} |
|
280 |
|
|
281 |
for(SalesOrder salesOrder : list){ |
|
282 |
salesOrderService.save(salesOrder); |
|
283 |
} |
|
284 |
return ResponseData.success("上传成功"); |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* excel导出模板 |
|
289 |
* |
|
290 |
* @author liwenya |
|
291 |
* @Date 2021年7月9日 17点01分 |
|
292 |
*/ |
|
293 |
@RequestMapping("/exportOut") |
|
294 |
public void exportOut(ModelMap modelMap, HttpServletRequest request, |
|
295 |
HttpServletResponse response) { |
|
296 |
List<ExcelExportEntity> entity = new ArrayList<>(); |
|
297 |
entity.add(new ExcelExportEntity("订单编号", "salesOrderCode")); |
|
298 |
entity.add(new ExcelExportEntity("客户编号", "customerNo")); |
|
299 |
entity.add(new ExcelExportEntity("货号", "cargoNo")); |
|
300 |
entity.add(new ExcelExportEntity("产品编号", "productCode")); |
|
301 |
entity.add(new ExcelExportEntity("产品名称", "productName")); |
|
302 |
entity.add(new ExcelExportEntity("计划数量", "planNumber")); |
|
303 |
entity.add(new ExcelExportEntity("计划开始时间", "planStartTime")); |
|
304 |
entity.add(new ExcelExportEntity("计划结束时间", "planEndTime")); |
|
305 |
entity.add(new ExcelExportEntity("车间编码", "workshopCode")); |
|
306 |
entity.add(new ExcelExportEntity("产线编码", "lineCode")); |
|
307 |
entity.add(new ExcelExportEntity("交货时间", "deliveryTime")); |
|
308 |
entity.add(new ExcelExportEntity("订单来源", "orderSource")); |
|
309 |
entity.add(new ExcelExportEntity("备注", "remark")); |
|
310 |
|
|
311 |
ExportParams params = new ExportParams("生产订单", "生产订单", ExcelType.XSSF); |
|
312 |
modelMap.put(MapExcelConstants.MAP_LIST, new ArrayList<>()); |
|
313 |
modelMap.put(MapExcelConstants.ENTITY_LIST, entity); |
|
314 |
modelMap.put(MapExcelConstants.PARAMS, params); |
|
315 |
modelMap.put(MapExcelConstants.FILE_NAME, "生产订单"); |
|
316 |
PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW); |
|
317 |
} |
|
318 |
|
|
319 |
|
|
320 |
} |
|
321 |
|
|
322 |
|