| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.StockOutParam; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.LocDto; |
| | | import com.zy.common.model.OrderDto; |
| | | import com.zy.common.model.OrderMergeVo; |
| | | import com.zy.common.model.TaskDto; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.DataFormatter; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 2022/3/26 |
| | | */ |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | public class OutController extends BaseController { |
| | | |
| | |
| | | // 订单预校验 ===>> 1.订单状态; 2.订单带出数量 |
| | | List<OrderDto> orderDtos = new ArrayList<>(); |
| | | for (LocDto locDto : locDtos) { |
| | | if (isJSON(locDto.getOrderNo())) { |
| | | if (!isJSON(locDto.getOrderNo())) { |
| | | if (Cools.isEmpty(locDto.getOrderNo())) { continue; } |
| | | OrderDto orderDto = new OrderDto(locDto.getOrderNo(), locDto.getMatnr(), locDto.getAnfme()); |
| | | if (OrderDto.has(orderDtos, orderDto)) { |
| | |
| | | } |
| | | } else { |
| | | // 订单合并出库 |
| | | // List<OrderDto> orderDtoList = JSON.parseArray(locDto.getOrderNo(), OrderDto.class); |
| | | |
| | | List<OrderDto> orderDtoList = JSON.parseArray(locDto.getOrderNo(), OrderDto.class); |
| | | |
| | | for (OrderDto one : orderDtoList) { |
| | | OrderDto orderDto = new OrderDto(one.getOrderNo(), locDto.getMatnr(), one.getAnfme()); |
| | | if (OrderDto.has(orderDtos, orderDto)) { |
| | |
| | | taskDtos.add(taskDto); |
| | | } |
| | | } |
| | | |
| | | List<String> locNos = new ArrayList<>(); |
| | | for (TaskDto taskDto : taskDtos) { |
| | | if (!locNos.contains(taskDto.getLocNo())){ |
| | | locNos.add(taskDto.getLocNo()); |
| | | } |
| | | } |
| | | List<TaskDto> taskDtos1 = new ArrayList<>(); |
| | | for (TaskDto taskDto : taskDtos) { |
| | | String locNo = taskDto.getLocNo(); |
| | | List<String> groupOuterSingleLoc = Utils.getGroupOuterSingleLoc(locNo); |
| | | LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo)); |
| | | if (locMast1.getLocType2().equals((short)3)){ |
| | | groupOuterSingleLoc = Utils.getGroupOuterSingleLocLowFrequency(locNo); |
| | | } |
| | | for (String locNo1 : groupOuterSingleLoc){ |
| | | if (!locNos.contains(locNo1)){ |
| | | locNos.add(locNo1); |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locNo1)); |
| | | if (locMast.getLocSts().equals("F")){ |
| | | List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locNo1)); |
| | | if (Cools.isEmpty(locDetls) || locDetls.size()==0) { |
| | | TaskDto taskDto1 = new TaskDto(locNo1, taskDto.getStaNo()); |
| | | taskDtos1.add(taskDto1); |
| | | }else { |
| | | List<LocDto> locDtos1 = new ArrayList<>(); |
| | | for (LocDetl locDetl:locDetls){ |
| | | LocDto locDto = new LocDto(locDetl,taskDto.getLocDtos().get(0),"伴生出库"); |
| | | locDtos1.add(locDto); |
| | | } |
| | | TaskDto taskDto1 = new TaskDto(locNo1, taskDto.getStaNo(),locDtos1); |
| | | taskDtos1.add(taskDto1); |
| | | } |
| | | }else if (locMast.getLocSts().equals("D")){ |
| | | TaskDto taskDto1 = new TaskDto(locNo1, taskDto.getStaNo()); |
| | | taskDtos1.add(taskDto1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | taskDtos.addAll(taskDtos1); |
| | | // ----------------------------------------------------------------------------------------------- |
| | | List<String> excludeLocNos = taskDtos.stream().map(TaskDto::getLocNo).distinct().collect(Collectors.toList()); |
| | | for (TaskDto taskDto : taskDtos) { |
| | | BasDevp staNo = basDevpService.checkSiteStatus(taskDto.getStaNo()); |
| | | workService.stockOut(staNo, taskDto, getUserId()); |
| | | locMastService.breakUp(taskDto.getLocNo(), excludeLocNos); |
| | | // locMastService.breakUp(taskDto.getLocNo(), excludeLocNos); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | return R.ok().add(locDtos); |
| | | } |
| | | |
| | | /** |
| | | * excel导入 |
| | | */ |
| | | @PostMapping(value = "/checkout/excel/import/auth") |
| | | @ManagerAuth(memo = "盘点导入") |
| | | @Transactional |
| | | public R cstmrExcelImport(MultipartFile file) throws IOException { |
| | | InputStream inStream = file.getInputStream(); |
| | | String fileMime = file.getContentType(); |
| | | int excelVersion = 2007; |
| | | if ("application/vnd.ms-excel".equals(fileMime)) { |
| | | excelVersion = 2003; |
| | | } |
| | | Workbook book = null; |
| | | try { |
| | | if (excelVersion == 2003) { |
| | | book = new HSSFWorkbook(inStream); |
| | | } |
| | | else { // 当 excel 是 2007 时 |
| | | book = new XSSFWorkbook(inStream); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | return R.error("导入文件格式错误,请使用xls后缀的文件!"); |
| | | } |
| | | |
| | | Sheet sheet = book.getSheetAt(0); |
| | | int totalRows = sheet.getLastRowNum() + 1; // 总 |
| | | Long userId = getUserId(); |
| | | Date now = new Date(); |
| | | DataFormatter dataFormatter = new DataFormatter(); |
| | | for (int i = 1; i < totalRows; i++) { |
| | | Row row = sheet.getRow(i); |
| | | // 库位号 |
| | | String locno = dataFormatter.formatCellValue(row.getCell(0)); |
| | | // 出库站 |
| | | Integer outSite = Integer.parseInt(dataFormatter.formatCellValue(row.getCell(1))); |
| | | |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", locno)); |
| | | StockOutParam param = new StockOutParam(); |
| | | |
| | | if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")) { |
| | | List<LocDetl> locDetls = locDetlService.selectByLocNo(locno); |
| | | List<StockOutParam.LocDetl> locDes = new ArrayList<>(); |
| | | for (LocDetl locDetl : locDetls) { |
| | | StockOutParam.LocDetl SOlocDetl = new StockOutParam.LocDetl(locDetl.getLocNo(),locDetl.getMatnr(),locDetl.getBatch(),locDetl.getAnfme()); |
| | | locDes.add(SOlocDetl); |
| | | } |
| | | param.setLocDetls(locDes); |
| | | param.setOutSite(outSite); |
| | | workService.locCheckOut(param, getUserId()); |
| | | } else { |
| | | return R.error("出库失败"); |
| | | } |
| | | } |
| | | return R.ok("出库完成"); |
| | | } |
| | | |
| | | } |