| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.mapper.sales.AccountInvoiceApplicationMapper; |
| | | import com.ruoyi.account.mapper.sales.AccountSalesCollectionMapper; |
| | | import com.ruoyi.common.enums.ReviewStatusEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockOutRecordDto; |
| | | import com.ruoyi.stock.dto.StockOutRecordImportDto; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.execl.StockOutRecordExportData; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | private final StockOutRecordMapper stockOutRecordMapper; |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final StockUninventoryMapper stockUninventoryMapper; |
| | | private final AccountSalesCollectionMapper accountSalesCollectionMapper; |
| | | private final AccountInvoiceApplicationMapper accountInvoiceApplicationMapper; |
| | | private final ProductModelMapper productModelMapper; |
| | | |
| | | @Override |
| | | public IPage<StockOutRecordDto> listPage(Page page, StockOutRecordDto stockOutRecordDto) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int add(StockOutRecordDto stockOutRecordDto) { |
| | | public StockOutRecordDto add(StockOutRecordDto stockOutRecordDto) { |
| | | String no = OrderUtils.countTodayByCreateTime(stockOutRecordMapper, "CK","outbound_batches"); |
| | | stockOutRecordDto.setOutboundBatches(no); |
| | | if (StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode().equals(stockOutRecordDto.getRecordType())){ |
| | | stockOutRecordDto.setApprovalStatus(3); |
| | | } |
| | | return stockOutRecordMapper.insert(stockOutRecordDto); |
| | | stockOutRecordMapper.insert(stockOutRecordDto); |
| | | return stockOutRecordDto; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public int batchDelete(List<Long> ids) { |
| | | //todo 如果出库与开票收款有关联则无法删除 |
| | | if (accountSalesCollectionMapper.existsByStockOutRecordId(ids) || |
| | | accountInvoiceApplicationMapper.existsByStockOutRecordId(ids)) { |
| | | throw new BaseException("出库记录存在开票收款关联数据,无法删除!!!"); |
| | | } |
| | | for (Long id : ids) { |
| | | StockOutRecord stockOutRecord = stockOutRecordMapper.selectById(id); |
| | | if (stockOutRecord.getType().equals("0")) { |
| | |
| | | stockInRecordDto.setBatchNo(stockInventory.getBatchNo()); |
| | | stockInventoryMapper.updateAddStockInventory(stockInRecordDto); |
| | | } |
| | | }else if (stockOutRecord.getType().equals("1")) { |
| | | } |
| | | else if (stockOutRecord.getType().equals("1")) { |
| | | LambdaQueryWrapper<StockUninventory> wrapper = new LambdaQueryWrapper<StockUninventory>() |
| | | .eq(StockUninventory::getProductModelId, stockOutRecord.getProductModelId()); |
| | | if (StringUtils.isEmpty(stockOutRecord.getBatchNo())) { |
| | |
| | | if (stockOutRecord == null) { |
| | | throw new BaseException("出库记录不存在,无法审批!!!"); |
| | | } |
| | | if (stockOutRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockOutRecord.getApprovalStatus())) { |
| | | throw new BaseException("只有待审批状态的记录才能审批,出库批次:" + stockOutRecord.getOutboundBatches()); |
| | | } |
| | | //if (stockOutRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockOutRecord.getApprovalStatus())) { |
| | | // throw new BaseException("只有待审批状态的记录才能审批,出库批次:" + stockOutRecord.getOutboundBatches()); |
| | | //} |
| | | stockOutRecord.setApprovalStatus(approvalStatus); |
| | | stockOutRecordMapper.updateById(stockOutRecord); |
| | | // 审批通过时,扣减库存 |
| | |
| | | } |
| | | return stockUninventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult importData(MultipartFile file, String type) { |
| | | List<StockOutRecordImportDto> rows; |
| | | try { |
| | | ExcelUtil<StockOutRecordImportDto> util = new ExcelUtil<>(StockOutRecordImportDto.class); |
| | | rows = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | return AjaxResult.error("解析Excel失败:" + e.getMessage()); |
| | | } |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return AjaxResult.error("导入文件无数据"); |
| | | } |
| | | String stockType = StringUtils.isEmpty(type) ? "0" : type.trim(); |
| | | String recordType = "1".equals(stockType) |
| | | ? StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode() |
| | | : StockOutQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_OUT.getCode(); |
| | | |
| | | int success = 0; |
| | | List<String> errors = new ArrayList<>(); |
| | | for (int i = 0; i < rows.size(); i++) { |
| | | StockOutRecordImportDto row = rows.get(i); |
| | | int rowNo = i + 2; // 首行为表头 |
| | | try { |
| | | String productName = trim(row.getProductName()); |
| | | String model = trim(row.getModel()); |
| | | if (StringUtils.isEmpty(productName)) { |
| | | errors.add("第" + rowNo + "行:产品大类为空"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isEmpty(model)) { |
| | | errors.add("第" + rowNo + "行:规格型号为空"); |
| | | continue; |
| | | } |
| | | if (row.getStockOutNum() == null) { |
| | | errors.add("第" + rowNo + "行:出库数量为空"); |
| | | continue; |
| | | } |
| | | ProductModel productModel = productModelMapper.selectByProductNameAndModel(productName, model); |
| | | if (productModel == null) { |
| | | errors.add("第" + rowNo + "行:未找到产品[" + productName + " / " + model + "]"); |
| | | continue; |
| | | } |
| | | StockOutRecordDto dto = new StockOutRecordDto(); |
| | | dto.setProductModelId(productModel.getId()); |
| | | dto.setBatchNo(trim(row.getBatchNo())); |
| | | dto.setStockOutNum(row.getStockOutNum()); |
| | | dto.setRemark(row.getRemark()); |
| | | dto.setType(stockType); |
| | | dto.setRecordType(recordType); |
| | | dto.setApprovalStatus(ReviewStatusEnum.PENDING_REVIEW.getCode()); |
| | | add(dto); |
| | | success++; |
| | | } catch (Exception e) { |
| | | errors.add("第" + rowNo + "行:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | AjaxResult result = AjaxResult.success(); |
| | | result.put("totalCount", rows.size()); |
| | | result.put("successCount", success); |
| | | result.put("failCount", rows.size() - success); |
| | | result.put("errors", errors); |
| | | result.put("msg", "导入完成:成功 " + success + " 条,失败 " + (rows.size() - success) + " 条"); |
| | | return result; |
| | | } |
| | | |
| | | private String trim(String value) { |
| | | return value == null ? null : value.trim(); |
| | | } |
| | | } |