EquipmentInController.java
24.9 KB
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
package com.skua.modules.equipment.controller;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.vo.LoginUser;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.exception.JeecgBootException;
import com.skua.core.query.QueryGenerator;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.modules.common.service.ICommonSqlService;
import com.skua.modules.equipment.dto.EquipmentInDTO;
import com.skua.modules.equipment.entity.EquipmentIn;
import com.skua.modules.equipment.entity.EquipmentInChild;
import com.skua.modules.equipment.entity.EquipmentSparepart;
import com.skua.modules.equipment.service.IEquipmentInChildService;
import com.skua.modules.equipment.service.IEquipmentInService;
import com.skua.modules.equipment.service.IEquipmentSparepartService;
import com.skua.modules.equipment.vo.EquipmentInExcel;
import com.skua.modules.equipment.vo.EquipmentInVO;
import com.skua.modules.flow.utils.ObjectUtil;
import com.skua.modules.supplies.entity.EquipmentSparepartSupplies;
import com.skua.modules.supplies.entity.PurchaseInfo;
import com.skua.modules.supplies.entity.PurchaseInfoDetail;
import com.skua.modules.supplies.entity.SuppliesWarehouse;
import com.skua.modules.supplies.service.IEquipmentSparepartSuppliesService;
import com.skua.modules.supplies.service.IPurchaseInfoDetailService;
import com.skua.modules.supplies.service.IPurchaseInfoService;
import com.skua.modules.supplies.service.ISuppliesWarehouseService;
import com.skua.modules.system.service.ISysDictService;
import com.skua.redis.component.Key2ValueService;
import com.skua.redis.util.CustomRedisUtil;
import com.skua.tool.util.BeanExtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
/**
* 入库
*/
@Slf4j
@Api(tags = "设备管理/库存管理/入库管理")
@RestController
@RequestMapping("/web/equipment/equipmentIn")
public class EquipmentInController {
@Autowired
private ICommonSqlService iCommonSqlService;
@Autowired
private IEquipmentInService equipmentInService;
@Autowired
private IEquipmentInChildService iEquipmentInChildService;
@Autowired
private IEquipmentSparepartService iEquipmentSparepartService;
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private CustomRedisUtil customRedisUtil;
@Autowired
private Key2ValueService key2ValueService;
@Autowired
private IEquipmentSparepartSuppliesService sparepartSuppliesService;
@Autowired
private ISysDictService sysCommonDictService;
@Autowired
private IPurchaseInfoService purchaseInfoService;
@Autowired
private IPurchaseInfoDetailService purchaseInfoDetailService;
@Qualifier("taskExecutor")
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
@Autowired
private ISuppliesWarehouseService suppliesWarehouseService;
@CustomExceptionAnno(description = "入库-详情")
@AutoLog(value = "入库-详情")
@ApiOperation(value = "入库-详情", notes = "入库-详情")
@GetMapping(value = "/detail")
public Result<Object> detailCtrl(EquipmentInDTO equipmentInDTO) {
Result<Object> result = new Result<>();
String inId = equipmentInDTO.getId();
EquipmentIn equipmentIn = equipmentInService.getById(inId);
String sql = "SELECT\n" +
"\teic.id,\n" +
"\tei.id mainId,\n" +
"\tes.sparepart_code AS sparepartCode,\n" +
"\tes.sparepart_name AS sparepartName,\n" +
"\ttp.item_text AS sparepartType_dictText,\n" +
"\tes.sparepart_type AS sparepartType,\n" +
"\tes.specification,\n" +
"\tes.measuring_unit AS measuringUnit,\n" +
"(select item_text from sys_dict_item where dict_id=(select id from sys_dict where dict_code='equipment-sparepart_measuring_unit') and item_value=es.measuring_unit) as measuringUnit_dictText," +
"\teic.in_num AS inNum,\n" +
"\teic.batch_num AS batchNum\n" +
"FROM\n" +
"\tequipment_in AS ei\n" +
"\tINNER JOIN equipment_in_child AS eic ON ei.id = eic.in_id\n" +
"\tLEFT JOIN equipment_sparepart_supplies AS es ON eic.sparepart_id = es.id\n" +
"\tLEFT JOIN equipment_sparepart_type tp ON es.sparepart_type = tp.id\n" +
" WHERE ei.id in( '" + inId + "')";
List<Map<String, Object>> mapList = iCommonSqlService.queryForList(sql);
JSONObject jsonObject = sysCommonDictService.translateTDictValue(equipmentIn);
jsonObject.put("childList", mapList);
result.setResult(jsonObject);
return result;
}
/**
* 分页列表查询
*
* @param equipmentInDTO
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "入库-分页列表查询")
@ApiOperation(value = "入库-分页列表查询", notes = "入库-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<EquipmentInVO>> queryPageList(EquipmentInDTO equipmentInDTO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) throws Exception {
Result<IPage<EquipmentInVO>> result = new Result<>();
EquipmentIn equipmentIn = BeanExtUtils.bean2Bean(equipmentInDTO, EquipmentIn.class);
QueryWrapper<EquipmentIn> queryWrapper = QueryGenerator.initQueryWrapper(equipmentIn, req.getParameterMap());
if (StringUtils.isNotEmpty(equipmentInDTO.getStartTime())) {
queryWrapper.ge("in_date", equipmentInDTO.getStartTime() + " 00:00:00");
}
if (StringUtils.isNotEmpty(equipmentInDTO.getEndTime())) {
queryWrapper.le("in_date", equipmentInDTO.getEndTime() + " 23:59:59");
}
queryWrapper.orderByDesc("in_date");
Map<String, String> sysUserVal2KeyMap = key2ValueService.dictKey2Val("sysUser", false);
Map<String, String> sysDepartVal2KeyMap = key2ValueService.dictKey2Val("sysDepart", false);
Map<String, String> suppliesWarehouseVal2KeyMap = key2ValueService.dictKey2Val("suppliesWarehouse", false);
Map<String, String> rkTypeVal2KeyMap = key2ValueService.dictKey2Val("rkType", false);
Page<EquipmentInVO> voPage = new Page<>(pageNo, pageSize);
Page<EquipmentIn> page = new Page<EquipmentIn>(pageNo, pageSize);
IPage<EquipmentIn> equipmentInIPage = equipmentInService.page(page, queryWrapper);
List<EquipmentIn> equipmentInList = equipmentInIPage.getRecords();
equipmentInList.stream().map(data -> "'" + data.getId() + "'").collect(Collectors.joining(","));
List<EquipmentInVO> equipmentInVOList = BeanExtUtils.beans2Beans(equipmentInList, EquipmentInVO.class, (targetFieldName, srcFieldVal) -> {
if ("departIdName".equals(targetFieldName) && srcFieldVal != null) {
return sysDepartVal2KeyMap.getOrDefault(srcFieldVal, "");
} else if ("sparepartName".equals(targetFieldName)) {
String sql2 = "select es.sparepart_name as sparepartName ,es.sparepart_type from equipment_sparepart_supplies as es inner join (select sparepart_id from equipment_in_child where in_id = '" + srcFieldVal + "') as tmp on es.id = tmp.sparepart_id";
List<Map<String, Object>> sparePartList = iCommonSqlService.queryForList(sql2);
Map<String, Integer> name2CountMap = new HashMap<>();
if (sparePartList != null && !sparePartList.isEmpty() && sparePartList.get(0) != null) {
for (Map<String, Object> it : sparePartList) {
String name = "" + it.get("sparepartName");
name2CountMap.put(name, name2CountMap.getOrDefault(name, 0) + 1);
}
}
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, Integer> item : name2CountMap.entrySet()) {
stringBuilder.append(",").append(item.getKey());
}
return stringBuilder.toString().replaceFirst(",", "");
} else if ("useByName".equals(targetFieldName)) {
return sysUserVal2KeyMap.getOrDefault(srcFieldVal, "");
} else if ("suppliesWarehouseId_dictText".equals(targetFieldName)) {
return suppliesWarehouseVal2KeyMap.getOrDefault(srcFieldVal, "");
} else if ("inType_dictText".equals(targetFieldName)) {
return rkTypeVal2KeyMap.getOrDefault(srcFieldVal, "");
}
return "";
});
if (StringUtils.isNotEmpty(equipmentInDTO.getSparepartName())) {
equipmentInVOList = equipmentInVOList.stream().filter(item -> item.getSparepartName().contains(equipmentInDTO.getSparepartName())).collect(Collectors.toList());
}
voPage.setTotal(equipmentInIPage.getTotal());
voPage.setRecords(equipmentInVOList);
result.setResult(voPage);
return result;
}
/**
* 添加
*
* @param equipmentInDTO
* @return
*/
@CustomExceptionAnno(description = "入库-添加")
@AutoLog(value = "入库-添加")
@ApiOperation(value = "入库-添加", notes = "入库-添加")
@PostMapping(value = "/add")
public Result<Object> add(@RequestBody EquipmentInDTO equipmentInDTO) throws Exception {
List<SuppliesWarehouse> suppliesWarehouseList = suppliesWarehouseService.list();
Map<String, String> warehouseDictMap = suppliesWarehouseList.stream().collect(Collectors.toMap(SuppliesWarehouse::getId, SuppliesWarehouse::getDepartId));
Result<Object> result = new Result<>();
if (equipmentInDTO.getEquipmentInChildList() == null || equipmentInDTO.getEquipmentInChildList().isEmpty()) {
throw new JeecgBootException("请选择入库备件!");
}
if (StringUtils.isBlank(equipmentInDTO.getSuppliesWarehouseId())) {
throw new JeecgBootException("请选择入库仓库!");
}
if (StringUtils.isBlank(equipmentInDTO.getInType())) {
throw new JeecgBootException("请选择入库类型!");
}
// 入库单号
if (StringUtils.isEmpty(equipmentInDTO.getInOrder())) {
String inOrder = "RK-" + DateUtils.format(new Date(), "YYYYMMdd" + "-" + System.currentTimeMillis());
equipmentInDTO.setInOrder(inOrder);
}
// 入库表主键
String inId = UUID.randomUUID().toString().replaceAll("-", "");
equipmentInDTO.setId(inId);
EquipmentIn equipmentIn = BeanExtUtils.bean2Bean(equipmentInDTO, EquipmentIn.class);
equipmentIn.setIsConfirm(1);
transactionTemplate.execute((transactionStatus -> {
equipmentInService.save(equipmentIn);
return 1;
}));
CountDownLatch countDownLatch = new CountDownLatch(equipmentInDTO.getEquipmentInChildList().size());
//如果是采购入库
Map<String, PurchaseInfoDetail> purchaseMap = Maps.newHashMap();
if ("cg".equals(equipmentInDTO.getInType()) && StringUtils.isNotEmpty(equipmentInDTO.getPurchaseCode())) {
String purchaseId = equipmentInDTO.getPurchaseId();
PurchaseInfo purchaseInfo = purchaseInfoService.getById(purchaseId);
List<PurchaseInfoDetail> purchaseInfoDetails = purchaseInfoDetailService.list(new QueryWrapper<PurchaseInfoDetail>().eq("purchase_info_id", purchaseInfo.getId()));
for (PurchaseInfoDetail purchaseInfoDetail : purchaseInfoDetails) {
purchaseMap.put(purchaseInfoDetail.getSparepartId(), purchaseInfoDetail);
}
}
for (EquipmentInChild equipmentInChild : equipmentInDTO.getEquipmentInChildList()) {
equipmentInChild.setInId(inId);
taskExecutor.execute(() -> {
try {
String sparepartId = equipmentInChild.getSparepartId();
String suppliesWarehouseId = equipmentInDTO.getSuppliesWarehouseId();
//根据物资id和仓库id获取库存
QueryWrapper<EquipmentSparepart> sparepartQueryWrapper = new QueryWrapper<>();
sparepartQueryWrapper.eq("supplies_id", sparepartId).eq("supplies_warehouse_id", suppliesWarehouseId);
EquipmentSparepart equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper);
if (ObjectUtil.isEmpty(equipmentSparepart)) {
//物料信息
EquipmentSparepartSupplies supplies = sparepartSuppliesService.getById(sparepartId);
equipmentSparepart = new EquipmentSparepart();
BeanUtils.copyProperties(supplies, equipmentSparepart);
equipmentSparepart.setId(null);
equipmentSparepart.setStorageNum(BigDecimal.ZERO);
equipmentSparepart.setSuppliesId(sparepartId);
equipmentSparepart.setSuppliesWarehouseId(suppliesWarehouseId);
equipmentSparepart.setDepartId(warehouseDictMap.get(suppliesWarehouseId));
//如果没有物料库存信息,新增库存信息为0
iEquipmentSparepartService.saveOrUpdate(equipmentSparepart);
equipmentSparepart = iEquipmentSparepartService.getOne(sparepartQueryWrapper);
}
BigDecimal resetStorageNum = equipmentSparepart.getStorageNum().add(equipmentInChild.getInNum());
equipmentSparepart.setStorageNum(resetStorageNum);
equipmentInChild.setCurStorageNum(resetStorageNum);
Integer version = equipmentSparepart.getVersion();
String id = equipmentSparepart.getId();
Integer executeRes = transactionTemplate.execute(transactionStatus -> {
iEquipmentSparepartService.updateStorageNumById(id, resetStorageNum.doubleValue(), version);
iEquipmentInChildService.saveOrUpdate(equipmentInChild);
//===========
//如果是采购入库
if ("cg".equals(equipmentInDTO.getInType()) && StringUtils.isNotEmpty(equipmentInDTO.getPurchaseCode())) {
BigDecimal inNum = equipmentInChild.getInNum();
PurchaseInfoDetail purchaseInfoDetail = purchaseMap.get(sparepartId);
//剩余采购物料数量
Double realTimeCount = ConvertUtils.getDouble(purchaseInfoDetail.getRealTimeCount(), 0);
Double real = new BigDecimal(realTimeCount).subtract(inNum).doubleValue();
purchaseInfoDetail.setRealTimeCount(real < 0 ? "0" : ConvertUtils.getString(ConvertUtils.getDouble(real, 0, 2)));
//采购数量
String count = purchaseInfoDetail.getCount();
//已经入库数量
purchaseInfoDetail.setInCount(ConvertUtils.getString(ConvertUtils.getDouble(count, 0) - ConvertUtils.getDouble(real, 0)));
UpdateWrapper<PurchaseInfoDetail> purchaseInfoDetailUpdateWrapper = new UpdateWrapper<>();
int detailVersion = purchaseInfoDetail.getVersion();
purchaseInfoDetailUpdateWrapper.eq("version", detailVersion).eq("id", purchaseInfoDetail.getId()).set("version", detailVersion + 1);
purchaseInfoDetailService.update(purchaseInfoDetail, purchaseInfoDetailUpdateWrapper);
}
//=============
return 1;
});
} catch (Exception e) {
e.printStackTrace();
log.error("异常error: {}", e.getMessage());
} finally {
countDownLatch.countDown();
}
});
}
countDownLatch.await();
result.setResult(equipmentInDTO);
return result;
}
/**
* 编辑
*
* @param equipmentIn
* @return
*/
@AutoLog(value = "入库-编辑")
@ApiOperation(value = "入库-编辑", notes = "入库-编辑")
@PutMapping(value = "/edit")
public Result<EquipmentIn> edit(@RequestBody EquipmentIn equipmentIn) {
Result<EquipmentIn> result = new Result<EquipmentIn>();
EquipmentIn equipmentInEntity = equipmentInService.getById(equipmentIn.getId());
if (equipmentInEntity == null) {
result.error500("未找到对应实体");
} else {
boolean ok = equipmentInService.updateById(equipmentIn);
//TODO 返回false说明什么?
if (ok) {
result.success("修改成功!");
}
}
return result;
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "入库-通过id删除")
@ApiOperation(value = "入库-通过id删除", notes = "入库-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id") String id) {
try {
String sql = "delete from equipment_in_child where in_id = '" + id + "'";
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
equipmentInService.removeById(id);
iCommonSqlService.delete(sql);
}
});
} catch (Exception e) {
log.error("删除失败: {}", e.getMessage());
return Result.error("删除失败!");
}
return Result.ok("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "入库-批量删除")
@ApiOperation(value = "入库-批量删除", notes = "入库-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<EquipmentIn> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
Result<EquipmentIn> result = new Result<EquipmentIn>();
if (ids == null || "".equals(ids.trim())) {
result.error500("参数不识别!");
} else {
this.equipmentInService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!");
}
return result;
}
/**
* 通过id查询
*
* @param id
* @return
*/
@AutoLog(value = "入库-通过id查询")
@ApiOperation(value = "入库-通过id查询", notes = "入库-通过id查询")
@GetMapping(value = "/queryById")
public Result<EquipmentIn> queryById(@RequestParam(name = "id", required = true) String id) {
Result<EquipmentIn> result = new Result<EquipmentIn>();
EquipmentIn equipmentIn = equipmentInService.getById(id);
if (equipmentIn == null) {
result.error500("未找到对应实体");
} else {
result.setResult(equipmentIn);
result.setSuccess(true);
}
return result;
}
/**
* 导出excel
*
* @param request
* @param
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(EquipmentInDTO equipmentInDTO, HttpServletRequest request, HttpServletResponse response) throws Exception {
EquipmentIn equipmentIn = BeanExtUtils.bean2Bean(equipmentInDTO, EquipmentIn.class);
QueryWrapper<EquipmentIn> queryWrapper = QueryGenerator.initQueryWrapper(equipmentIn, request.getParameterMap());
List<EquipmentInExcel> dataList;
//获取当前用户
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
try {
if (StringUtils.isNotEmpty(equipmentInDTO.getStartTime())) {
queryWrapper.ge("in_date", equipmentInDTO.getStartTime() + " 00:00:00");
}
if (StringUtils.isNotEmpty(equipmentInDTO.getEndTime())) {
queryWrapper.le("in_date", equipmentInDTO.getEndTime() + " 23:59:59");
}
queryWrapper.groupBy("ei.id");
queryWrapper.orderByDesc("in_date");
dataList = equipmentInService.queryExport(queryWrapper);
} catch (Exception e) {
e.printStackTrace();
dataList = new ArrayList<>();
}
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//导出文件名称
mv.addObject(NormalExcelConstants.FILE_NAME, "入库管理列表");
mv.addObject(NormalExcelConstants.CLASS, EquipmentInExcel.class);
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("入库管理数据", "导出人:"+sysUser.getRealname(), "导出信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, dataList);
return mv;
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<EquipmentIn> listEquipmentIns = ExcelImportUtil.importExcel(file.getInputStream(), EquipmentIn.class, params);
equipmentInService.saveBatch(listEquipmentIns);
return Result.ok("文件导入成功!数据行数:" + listEquipmentIns.size());
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.ok("文件导入失败!");
}
}