110 lines
3.9 KiB
Java
110 lines
3.9 KiB
Java
package com.wms.controller;
|
||
|
||
import com.alibaba.fastjson2.JSON;
|
||
import com.wms.constants.enums.KateTaskStatus;
|
||
import com.wms.constants.enums.ResponseCode;
|
||
import com.wms.entity.app.ResponseEntity;
|
||
import com.wms.entity.table.*;
|
||
import com.wms.service.*;
|
||
import com.wms.utils.HttpUtils;
|
||
import com.wms.utils.StringUtils;
|
||
import com.wms.utils.WmsUtils;
|
||
import com.wms.utils.excel.ExcelUtils;
|
||
import jakarta.servlet.http.HttpServletRequest;
|
||
import jakarta.servlet.http.HttpServletResponse;
|
||
import lombok.RequiredArgsConstructor;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.transaction.annotation.Isolation;
|
||
import org.springframework.transaction.annotation.Propagation;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import java.util.*;
|
||
|
||
/**
|
||
*
|
||
*/
|
||
@Controller
|
||
@CrossOrigin
|
||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||
@RequestMapping(value = "/wms/excel")
|
||
public class ExcelController extends BaseController {
|
||
private final StockService stockService;// 库存服务
|
||
private final PartInfoService partInfoService;// 零件服务
|
||
private final HttpServletRequest servletRequest;// 请求服务
|
||
private final TaskRecordService taskRecordService;// 任务记录服务
|
||
|
||
/**
|
||
* 导入零件信息
|
||
*
|
||
* @param file 文件
|
||
* @return 导入结果
|
||
*/
|
||
@PostMapping("/uploadPartInfos")
|
||
@ResponseBody
|
||
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||
public String uploadPartInfos(@RequestPart("file") MultipartFile file) {
|
||
logger.info("接收到导入零件信息请求,ip地址:{}", HttpUtils.getIpAddr(servletRequest));
|
||
ResponseEntity response = new ResponseEntity();
|
||
try {
|
||
List<PartInfo> files = ExcelUtils.readMultipartFile(file, PartInfo.class);
|
||
// 添加进物料表
|
||
for (PartInfo pageInfo : files) {
|
||
if (partInfoService.selPartByPartNo(pageInfo.getMaterial()) != null) {// 当前零件号的数据已经存在过
|
||
partInfoService.modifyPart(pageInfo);
|
||
} else {// 新零件
|
||
partInfoService.addPart(pageInfo);
|
||
}
|
||
}
|
||
response.setCode(ResponseCode.OK.getCode());
|
||
response.setMessage("导入excel成功");
|
||
response.setReturnData(files);
|
||
} catch (Exception e) {
|
||
// 回滚事务
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
response.setCode(ResponseCode.ERROR.getCode());
|
||
response.setMessage(e.getMessage());
|
||
}
|
||
return JSON.toJSONString(response);
|
||
}
|
||
|
||
/**
|
||
* 导出库存数据
|
||
*
|
||
* @param response 请求
|
||
*/
|
||
@GetMapping("/downloadStockExcel")
|
||
@ResponseBody
|
||
public void downloadStockExcel(HttpServletResponse response) {
|
||
List<Stock> stocks = stockService.selStocks(new Stock());
|
||
ExcelUtils.export(response, "库存报表", stocks, Stock.class);
|
||
}
|
||
|
||
/**
|
||
* 导出入库记录
|
||
*
|
||
* @param response 请求
|
||
*/
|
||
@GetMapping("/downloadRukuExcel")
|
||
@ResponseBody
|
||
public void downloadRukuExcel(HttpServletResponse response) {
|
||
List<Task> ruku = taskRecordService.selTasks(new Task());
|
||
ExcelUtils.export(response, "入库记录报表", ruku, Task.class);
|
||
}
|
||
|
||
/**
|
||
* 导出物料信息
|
||
*
|
||
* @param response 请求
|
||
*/
|
||
@GetMapping("/downloadMaterialExcel")
|
||
@ResponseBody
|
||
public void downloadMaterialExcel(HttpServletResponse response) {
|
||
List<PartInfo> Material = partInfoService.selParts(new PartInfo());
|
||
ExcelUtils.export(response, "物料信息", Material, PartInfo.class);
|
||
}
|
||
|
||
} |