| | |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | return R.ok(stockInventoryDtoIPage); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/pageListCombinedStockInventory") |
| | | @Operation(summary = "分页查询联合库存列表") |
| | | public R pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | | IPage<StockInventoryDto> stockInventoryDtoIPage = stockInventoryService.pageListCombinedStockInventory(page, stockInventoryDto); |
| | | return R.ok(stockInventoryDtoIPage); |
| | | } |
| | | |
| | | @PostMapping("/addstockInventory") |
| | | @PreAuthorize("@ss.hasPermi('add:stockInventory')") |
| | | @ApiOperation("新增库存") |
| | |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.stock.pojo.StockInventory; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | |
| | | |
| | | //产品id |
| | | private Long productId; |
| | | } |
| | | |
| | | @Schema(description = "顶部父产品id") |
| | | private Long topParentProductId; |
| | | |
| | | @Schema(description = "库存类型:qualified(合格)、unqualified(不合格)") |
| | | private String stockType; |
| | | |
| | | @Schema(description = "合格库存数量") |
| | | private BigDecimal qualifiedQuantity; |
| | | |
| | | @Schema(description = "不合格库存数量") |
| | | private BigDecimal unQualifiedQuantity; |
| | | |
| | | @Schema(description = "合格库存冻结数量") |
| | | private BigDecimal qualifiedLockedQuantity; |
| | | |
| | | @Schema(description = "不合格库存冻结数量") |
| | | private BigDecimal unQualifiedLockedQuantity; |
| | | |
| | | @Schema(description = "合格库存未冻结数量") |
| | | private BigDecimal qualifiedUnLockedQuantity; |
| | | |
| | | @Schema(description = "不合格库存未冻结数量") |
| | | private BigDecimal unQualifiedUnLockedQuantity; |
| | | |
| | | @Schema(description = "合格库存ID") |
| | | private Long qualifiedId; |
| | | |
| | | @Schema(description = "不合格库存ID") |
| | | private Long unQualifiedId; |
| | | |
| | | @Schema(description = "合格库存批号") |
| | | private String qualifiedBatchNo; |
| | | |
| | | @Schema(description = "不合格库存批号") |
| | | private String unQualifiedBatchNo; |
| | | } |
| | |
| | | |
| | | @Data |
| | | public class StockInventoryExportData { |
| | | |
| | | |
| | | |
| | | @Excel(name = "产品名称") |
| | | private String productName; |
| | | |
| | |
| | | @Excel(name = "料号") |
| | | private String materialCode; |
| | | |
| | | @Excel(name = "库存数量") |
| | | private BigDecimal qualitity; |
| | | @Excel(name = "合格库存批号") |
| | | private String qualifiedBatchNo; |
| | | |
| | | @Excel(name = "不合格库存批号") |
| | | private String unQualifiedBatchNo; |
| | | |
| | | @Excel(name = "合格库存数量") |
| | | private BigDecimal qualifiedQuantity; |
| | | |
| | | @Excel(name = "不合格库存数量") |
| | | private BigDecimal unQualifiedQuantity; |
| | | |
| | | @Excel(name = "预警数量") |
| | | private BigDecimal warnNum; |
| | | |
| | | @Excel(name = "冻结数量") |
| | | private BigDecimal lockedQuantity; |
| | | @Excel(name = "合格冻结数量") |
| | | private BigDecimal qualifiedLockedQuantity; |
| | | |
| | | @Excel(name = "不合格冻结数量") |
| | | private BigDecimal unQualifiedLockedQuantity; |
| | | |
| | | @Excel(name = "备注") |
| | | private String remark; |
| | |
| | | // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // private LocalDateTime updateTime; |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | IPage<StockInventoryDto> pagestockInventory(Page page, @Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | | IPage<StockInventoryDto> pageListCombinedStockInventory(Page page, @Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | | int updateAddStockInventory(@Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | |
| | | @ApiModelProperty("被订单锁定数量") |
| | | private BigDecimal lockedQuantity; |
| | | |
| | | @ApiModelProperty("批号") |
| | | private String batchNo; |
| | | } |
| | |
| | | |
| | | IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto); |
| | | |
| | | IPage<StockInventoryDto> pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto); |
| | | |
| | | Boolean addstockInventory(StockInventoryDto stockInventoryDto); |
| | | |
| | | Boolean subtractStockInventory(StockInventoryDto stockInventoryDto); |
| | |
| | | package com.ruoyi.stock.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockOutRecordDto; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.execl.StockInventoryExportData; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.pojo.StockInRecord; |
| | |
| | | import com.ruoyi.stock.service.StockInRecordService; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import com.ruoyi.stock.service.StockOutRecordService; |
| | | import com.ruoyi.stock.service.StockUninventoryService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | |
| | | private ProductModelMapper productModelMapper; |
| | | @Autowired |
| | | private ProductMapper productMapper; |
| | | @Autowired |
| | | private StockUninventoryService stockUninventoryService; |
| | | |
| | | @Override |
| | | public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | | return stockInventoryMapper.pagestockInventory(page, stockInventoryDto); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<StockInventoryDto> pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | | return stockInventoryMapper.pageListCombinedStockInventory(page, stockInventoryDto); |
| | | } |
| | | |
| | | //入库调用-添加入库记录 |
| | |
| | | String seqStr = String.format("%03d", newSeq); |
| | | |
| | | // 组装batchNo |
| | | batchNo = stockInventoryDto.getMaterialCode() + stockInventoryDto.getProductModelName() + "P" + monthFlag + seqStr; |
| | | ProductModel productModel = productModelMapper.selectById(stockInventoryDto.getProductModelId()); |
| | | batchNo = stockInventoryDto.getMaterialCode() + productModel.getModel() + "P" + monthFlag + seqStr; |
| | | stockInRecordDto.setBatchNo(batchNo); |
| | | } else { |
| | | stockInRecordDto.setBatchNo(stockInventoryDto.getBatchNo()); |
| | |
| | | */ |
| | | public void updateOrCreateStockInventory(StockInRecord stockInRecord) { |
| | | // 先查询库存表中的产品是否存在 |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne( |
| | | new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()) |
| | | .eq(StockInventory::getBatchNo, stockInRecord.getBatchNo()) |
| | | ); |
| | | LambdaQueryWrapper<StockInventory> queryWrapper = new QueryWrapper<StockInventory>().lambda() |
| | | .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | |
| | | // 根据 batchNo 是否为空构建不同的查询条件 |
| | | if (stockInRecord.getBatchNo() != null && !stockInRecord.getBatchNo().isEmpty()) { |
| | | queryWrapper.eq(StockInventory::getBatchNo, stockInRecord.getBatchNo()); |
| | | } else { |
| | | queryWrapper.isNull(StockInventory::getBatchNo); |
| | | } |
| | | |
| | | StockInventory oldStockInventory = stockInventoryMapper.selectOne(queryWrapper); |
| | | |
| | | if (ObjectUtils.isEmpty(oldStockInventory)) { |
| | | // 不存在则新增 |
| | |
| | | // 存在则更新 |
| | | LambdaUpdateWrapper<StockInventory> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper |
| | | .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()) |
| | | .eq(StockInventory::getBatchNo, stockInRecord.getBatchNo()) |
| | | .eq(StockInventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | |
| | | // 根据 batchNo 是否为空构建不同的更新条件 |
| | | if (stockInRecord.getBatchNo() != null && !stockInRecord.getBatchNo().isEmpty()) { |
| | | updateWrapper.eq(StockInventory::getBatchNo, stockInRecord.getBatchNo()); |
| | | } else { |
| | | updateWrapper.isNull(StockInventory::getBatchNo); |
| | | } |
| | | |
| | | updateWrapper |
| | | .setSql(stockInRecord.getStockInNum() != null, |
| | | "qualitity = qualitity + " + stockInRecord.getStockInNum()) |
| | | .setSql(true, "version = version + 1") |
| | |
| | | @Override |
| | | public R importStockInventory(MultipartFile file) { |
| | | try { |
| | | // 查询所有的产品 |
| | | // 查询所有的产品并构建映射,提高查找效率 |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct(); |
| | | Map<String, SalesLedgerProduct> productMap = new HashMap<>(); |
| | | for (SalesLedgerProduct product : salesLedgerProducts) { |
| | | // 使用产品类别和规格型号作为键 |
| | | String key = product.getProductCategory() + "|" + product.getSpecificationModel(); |
| | | productMap.put(key, product); |
| | | } |
| | | |
| | | ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class); |
| | | List<StockInventoryExportData> list = util.importExcel(file.getInputStream()); |
| | | |
| | | // 记录未找到匹配项的数据 |
| | | List<String> unmatchedRecords = new ArrayList<>(); |
| | | // 记录处理结果 |
| | | int successCount = 0; |
| | | |
| | | list.forEach(dto -> { |
| | | boolean matched = false; |
| | | for (SalesLedgerProduct item : salesLedgerProducts) { |
| | | if (item.getProductCategory().equals(dto.getProductName()) && |
| | | item.getSpecificationModel().equals(dto.getModel())) { |
| | | for (StockInventoryExportData dto : list) { |
| | | // 构建查找键 |
| | | String key = dto.getProductName() + "|" + dto.getModel(); |
| | | SalesLedgerProduct matchedProduct = productMap.get(key); |
| | | |
| | | if (matchedProduct != null) { |
| | | // 处理合格库存 |
| | | if (dto.getQualifiedQuantity() != null && dto.getQualifiedQuantity().compareTo(BigDecimal.ZERO) > 0) { |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(0L); |
| | | stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode()); |
| | | stockInventoryDto.setQualitity(dto.getQualitity()); |
| | | stockInventoryDto.setQualitity(dto.getQualifiedQuantity()); |
| | | stockInventoryDto.setRemark(dto.getRemark()); |
| | | stockInventoryDto.setWarnNum(dto.getWarnNum()); |
| | | if (ObjectUtils.isNotEmpty(dto.getLockedQuantity()) && dto.getLockedQuantity().compareTo(dto.getQualitity()) > 0) { |
| | | throw new RuntimeException("冻结数量不能超过本次导入的库存数量"); |
| | | stockInventoryDto.setBatchNo(dto.getQualifiedBatchNo()); |
| | | |
| | | // 验证合格冻结数量 |
| | | if (ObjectUtils.isNotEmpty(dto.getQualifiedLockedQuantity())) { |
| | | if (dto.getQualifiedLockedQuantity().compareTo(dto.getQualifiedQuantity()) > 0) { |
| | | throw new RuntimeException("合格冻结数量不能超过本次导入的合格库存数量"); |
| | | } |
| | | stockInventoryDto.setLockedQuantity(dto.getQualifiedLockedQuantity()); |
| | | } else { |
| | | stockInventoryDto.setLockedQuantity(BigDecimal.ZERO); |
| | | } |
| | | stockInventoryDto.setLockedQuantity(dto.getLockedQuantity()); |
| | | stockInventoryDto.setProductModelId(item.getProductModelId()); |
| | | |
| | | stockInventoryDto.setProductModelId(matchedProduct.getProductModelId()); |
| | | this.addstockInventory(stockInventoryDto); |
| | | matched = true; |
| | | break; // 找到匹配项后跳出循环 |
| | | successCount++; |
| | | } |
| | | |
| | | // 处理不合格库存 |
| | | if (dto.getUnQualifiedQuantity() != null && dto.getUnQualifiedQuantity().compareTo(BigDecimal.ZERO) > 0) { |
| | | StockUninventoryDto stockUninventoryDto = new StockUninventoryDto(); |
| | | stockUninventoryDto.setRecordId(0L); |
| | | stockUninventoryDto.setRecordType(StockInUnQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_IN.getCode()); |
| | | stockUninventoryDto.setQualitity(dto.getUnQualifiedQuantity()); |
| | | stockUninventoryDto.setRemark(dto.getRemark()); |
| | | stockUninventoryDto.setBatchNo(dto.getUnQualifiedBatchNo()); |
| | | |
| | | // 验证不合格冻结数量 |
| | | if (ObjectUtils.isNotEmpty(dto.getUnQualifiedLockedQuantity())) { |
| | | if (dto.getUnQualifiedLockedQuantity().compareTo(dto.getUnQualifiedQuantity()) > 0) { |
| | | throw new RuntimeException("不合格冻结数量不能超过本次导入的不合格库存数量"); |
| | | } |
| | | stockUninventoryDto.setLockedQuantity(dto.getUnQualifiedLockedQuantity()); |
| | | } else { |
| | | stockUninventoryDto.setLockedQuantity(BigDecimal.ZERO); |
| | | } |
| | | |
| | | stockUninventoryDto.setProductModelId(matchedProduct.getProductModelId()); |
| | | stockUninventoryService.addStockUninventory(stockUninventoryDto); |
| | | successCount++; |
| | | } |
| | | } else { |
| | | // 记录未匹配的产品 |
| | | String unmatchedRecord = "产品名称:" + dto.getProductName() + ",型号:" + dto.getModel(); |
| | | unmatchedRecords.add(unmatchedRecord); |
| | | } |
| | | if (!matched) { |
| | | // 记录未匹配的数据 |
| | | String unmatchedInfo = String.format("产品名称:%s,规格型号:%s", |
| | | dto.getProductName(), dto.getModel()); |
| | | unmatchedRecords.add(unmatchedInfo); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 构建返回信息 |
| | | StringBuilder message = new StringBuilder(); |
| | | if (!unmatchedRecords.isEmpty()) { |
| | | message.append("以下产品未找到匹配项:\n"); |
| | | message.append("导入成功 " + successCount + " 条记录,以下产品未找到匹配项:\n"); |
| | | for (String record : unmatchedRecords) { |
| | | message.append(record).append("\n"); |
| | | } |
| | | throw new RuntimeException(message.toString()); |
| | | return R.ok(message.toString()); |
| | | } |
| | | |
| | | return R.ok("导入成功,共处理 " + successCount + " 条记录"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("导入库存失败", e); |
| | | return R.fail("导入失败:" + e.getMessage()); |
| | | } |
| | | return R.ok("导入成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void exportStockInventory(HttpServletResponse response, StockInventoryDto stockInventoryDto) { |
| | |
| | | stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockInventory); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.stock.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | |
| | | import com.ruoyi.stock.execl.StockUnInventoryExportData; |
| | | import com.ruoyi.stock.mapper.StockUninventoryMapper; |
| | | import com.ruoyi.stock.pojo.StockInRecord; |
| | | import com.ruoyi.stock.pojo.StockInventory; |
| | | import com.ruoyi.stock.pojo.StockUninventory; |
| | | import com.ruoyi.stock.service.StockInRecordService; |
| | | import com.ruoyi.stock.service.StockOutRecordService; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private StockInRecordService stockInRecordService; |
| | | @Autowired |
| | | private ApproveProcessServiceImpl approveProcessService; |
| | | @Autowired |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | @Override |
| | | public IPage<StockUninventoryDto> pageStockUninventory(Page page, StockUninventoryDto stockUninventoryDto) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer addStockUninventory(StockUninventoryDto stockUninventoryDto) { |
| | | List<StockUninventory> stockUninventoryList = stockUninventoryMapper.selectList(null); |
| | | //新增入库记录再添加库存 |
| | | StockInRecordDto stockInRecordDto = new StockInRecordDto(); |
| | | stockInRecordDto.setRecordId(stockUninventoryDto.getRecordId()); |
| | |
| | | stockInRecordDto.setRemark(stockUninventoryDto.getRemark()); |
| | | stockInRecordDto.setApproveStatus(0); |
| | | stockInRecordDto.setType("1"); |
| | | if (stockUninventoryDto.getBatchNo() == null || stockUninventoryDto.getBatchNo().isEmpty()) { |
| | | String batchNo; |
| | | // 获取当前月份(两位) |
| | | LocalDate now = LocalDate.now(); |
| | | String monthFlag = now.format(DateTimeFormatter.ofPattern("MM")); |
| | | |
| | | // 获取当前月份的最大流水号 |
| | | int maxSeq = getCurrentMonthMaxSeq(stockUninventoryDto, monthFlag, stockUninventoryList); |
| | | |
| | | // 新流水号 = 最大流水号 + 1 |
| | | int newSeq = maxSeq + 1; |
| | | String seqStr = String.format("%03d", newSeq); |
| | | |
| | | // 组装batchNo |
| | | ProductModel productModel = productModelMapper.selectById(stockUninventoryDto.getProductModelId()); |
| | | batchNo = stockUninventoryDto.getMaterialCode() + productModel.getModel() + "P" + monthFlag + seqStr; |
| | | stockInRecordDto.setBatchNo(batchNo); |
| | | } else { |
| | | stockInRecordDto.setBatchNo(stockUninventoryDto.getBatchNo()); |
| | | } |
| | | Long id = stockInRecordService.add(stockInRecordDto); |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 查询当前月份已存在的最大流水号 |
| | | */ |
| | | private static int getCurrentMonthMaxSeq(StockUninventoryDto dto, String monthFlag, List<StockUninventory> existingList) { |
| | | int maxSeq = 0; |
| | | |
| | | String prefix = dto.getMaterialCode() + dto.getModel() + "P" + monthFlag; |
| | | |
| | | // 正则匹配:前缀 + 3位数字 |
| | | Pattern pattern = Pattern.compile(Pattern.quote(prefix) + "(\\d{3})"); |
| | | |
| | | for (StockUninventory item : existingList) { |
| | | String batchNo = item.getBatchNo(); |
| | | if (batchNo == null) continue; |
| | | |
| | | Matcher matcher = pattern.matcher(batchNo); |
| | | if (matcher.find()) { |
| | | int seq = Integer.parseInt(matcher.group(1)); |
| | | if (seq > maxSeq) { |
| | | maxSeq = seq; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return maxSeq; |
| | | } |
| | | |
| | | public void addApproveByPurchase(LoginUser loginUser, StockInRecordDto stockInRecordDto,Long id) throws Exception { |
| | |
| | | */ |
| | | public void updateOrCreateStockUninventory(StockInRecord stockInRecord) { |
| | | // 先查询库存表中的产品是否存在 |
| | | StockUninventory oldStockUnInventory = stockUninventoryMapper.selectOne( |
| | | new QueryWrapper<StockUninventory>().lambda() |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()) |
| | | ); |
| | | LambdaQueryWrapper<StockUninventory> queryWrapper = new QueryWrapper<StockUninventory>().lambda() |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | |
| | | // 根据 batchNo 是否为空构建不同的查询条件 |
| | | if (stockInRecord.getBatchNo() != null && !stockInRecord.getBatchNo().isEmpty()) { |
| | | queryWrapper.eq(StockUninventory::getBatchNo, stockInRecord.getBatchNo()); |
| | | } else { |
| | | queryWrapper.isNull(StockUninventory::getBatchNo); |
| | | } |
| | | |
| | | StockUninventory oldStockUnInventory = stockUninventoryMapper.selectOne(queryWrapper); |
| | | |
| | | if (ObjectUtils.isEmpty(oldStockUnInventory)) { |
| | | // 不存在则新增 |
| | |
| | | newStockUnInventory.setQualitity(stockInRecord.getStockInNum()); |
| | | newStockUnInventory.setVersion(1); |
| | | newStockUnInventory.setRemark(stockInRecord.getRemark()); |
| | | newStockUnInventory.setLockedQuantity(stockInRecord.getLockedQuantity()); |
| | | newStockUnInventory.setBatchNo(stockInRecord.getBatchNo()); |
| | | stockUninventoryMapper.insert(newStockUnInventory); |
| | | } else { |
| | | // 存在则更新 |
| | | LambdaUpdateWrapper<StockUninventory> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | if (stockInRecord.getStockInNum() != null) { |
| | | updateWrapper.setSql("qualitity = qualitity + " + stockInRecord.getStockInNum()); |
| | | updateWrapper |
| | | .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | |
| | | // 根据 batchNo 是否为空构建不同的更新条件 |
| | | if (stockInRecord.getBatchNo() != null && !stockInRecord.getBatchNo().isEmpty()) { |
| | | updateWrapper.eq(StockUninventory::getBatchNo, stockInRecord.getBatchNo()); |
| | | } else { |
| | | updateWrapper.isNull(StockUninventory::getBatchNo); |
| | | } |
| | | updateWrapper.setSql("version = version + 1"); |
| | | String remark = stockInRecord.getRemark(); |
| | | if (remark != null && !remark.isEmpty()) { |
| | | updateWrapper.set(StockUninventory::getRemark, remark); |
| | | } |
| | | updateWrapper.set(StockUninventory::getUpdateTime, new Date()); |
| | | updateWrapper.eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId()); |
| | | |
| | | updateWrapper |
| | | .setSql(stockInRecord.getStockInNum() != null, |
| | | "qualitity = qualitity + " + stockInRecord.getStockInNum()) |
| | | .setSql(true, "version = version + 1") |
| | | .set(stockInRecord.getRemark() != null && !stockInRecord.getRemark().isEmpty(), |
| | | StockUninventory::getRemark, stockInRecord.getRemark()) |
| | | .setSql(stockInRecord.getLockedQuantity() != null, |
| | | "locked_quantity = locked_quantity + " + stockInRecord.getLockedQuantity()) |
| | | .set(StockUninventory::getUpdateTime, new Date()); |
| | | |
| | | stockUninventoryMapper.update(null, updateWrapper); |
| | | } |
| | | } |
| | |
| | | stockUninventory.setLockedQuantity(stockUninventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockUninventory); |
| | | } |
| | | } |
| | | } |
| | |
| | | AND p.product_name LIKE CONCAT('%', #{ew.productName}, '%') |
| | | </if> |
| | | </select> |
| | | <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData"> |
| | | select si.qualitity, |
| | | |
| | | <select id="pageListCombinedStockInventory" resultType="com.ruoyi.stock.dto.StockInventoryDto"> |
| | | WITH RECURSIVE product_tree AS ( |
| | | SELECT id |
| | | FROM product |
| | | WHERE id = #{ew.topParentProductId} |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT p.id |
| | | FROM product p |
| | | INNER JOIN product_tree pt ON p.parent_id = pt.id |
| | | ) |
| | | select |
| | | MAX(qualifiedId) as qualifiedId, |
| | | MAX(unQualifiedId) as unQualifiedId, |
| | | SUM(qualifiedQuantity) as qualifiedQuantity, |
| | | SUM(unQualifiedQuantity) as unQualifiedQuantity, |
| | | SUM(qualifiedLockedQuantity) as qualifiedLockedQuantity, |
| | | SUM(unQualifiedLockedQuantity) as unQualifiedLockedQuantity, |
| | | SUM(qualifiedQuantity - qualifiedLockedQuantity) as qualifiedUnLockedQuantity, |
| | | SUM(unQualifiedQuantity - unQualifiedLockedQuantity) as unQualifiedUnLockedQuantity, |
| | | product_model_id, |
| | | MAX(create_time) as create_time, |
| | | MAX(update_time) as update_time, |
| | | MAX(warn_num) as warn_num, |
| | | MAX(version) as version, |
| | | model, |
| | | MAX(remark) as remark, |
| | | unit, |
| | | product_name, |
| | | product_id, |
| | | MAX(qualifiedBatchNo) as qualifiedBatchNo, |
| | | MAX(unQualifiedBatchNo) as unQualifiedBatchNo, |
| | | MAX(materialCode) as materialCode, |
| | | 'combined' as stockType |
| | | from ( |
| | | select |
| | | si.id as qualifiedId, |
| | | null as unQualifiedId, |
| | | si.qualitity as qualifiedQuantity, |
| | | 0 as unQualifiedQuantity, |
| | | COALESCE(si.locked_quantity, 0) as locked_quantity, |
| | | COALESCE(si.locked_quantity, 0) as qualifiedLockedQuantity, |
| | | 0 as unQualifiedLockedQuantity, |
| | | si.product_model_id, |
| | | si.create_time, |
| | | si.update_time, |
| | | COALESCE(si.warn_num, 0) as warn_num, |
| | | si.version, |
| | | (si.qualitity - COALESCE(si.locked_quantity, 0)) as un_locked_quantity, |
| | | pm.model, |
| | | pm.unit, |
| | | pm.material_code as materialCode, |
| | | p.product_name, |
| | | coalesce(si.warn_num, 0) as warn_num, |
| | | coalesce(si.locked_quantity, 0) as locked_quantity, |
| | | si.remark, |
| | | si.update_time |
| | | pm.unit, |
| | | p.product_name, |
| | | p.id as product_id, |
| | | si.batch_no as qualifiedBatchNo, |
| | | null as unQualifiedBatchNo, |
| | | pm.material_code as materialCode |
| | | from stock_inventory si |
| | | left join product_model pm on si.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | where 1 = 1 |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | | and p.product_name like concat('%',#{ew.productName},'%') |
| | | </if> |
| | | |
| | | union all |
| | | |
| | | select |
| | | null as qualifiedId, |
| | | su.id as unQualifiedId, |
| | | 0 as qualifiedQuantity, |
| | | su.qualitity as unQualifiedQuantity, |
| | | COALESCE(su.locked_quantity, 0) as locked_quantity, |
| | | 0 as qualifiedLockedQuantity, |
| | | COALESCE(su.locked_quantity, 0) as unQualifiedLockedQuantity, |
| | | su.product_model_id, |
| | | su.create_time, |
| | | su.update_time, |
| | | 0 as warn_num, |
| | | su.version, |
| | | (su.qualitity - COALESCE(su.locked_quantity, 0)) as un_locked_quantity, |
| | | pm.model, |
| | | su.remark, |
| | | pm.unit, |
| | | p.product_name, |
| | | p.id as product_id, |
| | | null as qualifiedBatchNo, |
| | | su.batch_no as unQualifiedBatchNo, |
| | | pm.material_code as materialCode |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | ) as combined |
| | | <where> |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | | and combined.product_name in ( |
| | | select distinct p.product_name |
| | | from product p |
| | | left join product_model pm on p.id = pm.product_id |
| | | where p.product_name like concat('%',#{ew.productName},'%') or pm.model like concat('%',#{ew.productName},'%') |
| | | ) |
| | | </if> |
| | | <if test="ew.topParentProductId != null and ew.topParentProductId > 0"> |
| | | and combined.product_id in (select id from product_tree) |
| | | </if> |
| | | </where> |
| | | group by product_model_id, model, unit, product_name, product_id, qualifiedBatchNo, unQualifiedBatchNo, materialCode, product_id, qualifiedBatchNo, unQualifiedBatchNo |
| | | </select> |
| | | |
| | | <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData"> |
| | | WITH RECURSIVE product_tree AS ( |
| | | SELECT id |
| | | FROM product |
| | | WHERE id = #{ew.topParentProductId} |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT p.id |
| | | FROM product p |
| | | INNER JOIN product_tree pt ON p.parent_id = pt.id |
| | | ) |
| | | select |
| | | SUM(qualifiedQuantity) as qualifiedQuantity, |
| | | SUM(unQualifiedQuantity) as unQualifiedQuantity, |
| | | SUM(qualifiedLockedQuantity) as qualifiedLockedQuantity, |
| | | SUM(unQualifiedLockedQuantity) as unQualifiedLockedQuantity, |
| | | model, |
| | | unit, |
| | | product_name, |
| | | MAX(warn_num) as warn_num, |
| | | MAX(remark) as remark, |
| | | MAX(update_time) as update_time, |
| | | MAX(qualifiedBatchNo) as qualifiedBatchNo, |
| | | MAX(unQualifiedBatchNo) as unQualifiedBatchNo, |
| | | MAX(materialCode) as materialCode |
| | | from ( |
| | | select |
| | | si.qualitity as qualifiedQuantity, |
| | | 0 as unQualifiedQuantity, |
| | | COALESCE(si.locked_quantity, 0) as qualifiedLockedQuantity, |
| | | 0 as unQualifiedLockedQuantity, |
| | | si.product_model_id, |
| | | si.create_time, |
| | | si.update_time, |
| | | COALESCE(si.warn_num, 0) as warn_num, |
| | | si.remark, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name, |
| | | p.id as product_id, |
| | | si.batch_no as qualifiedBatchNo, |
| | | null as unQualifiedBatchNo, |
| | | pm.material_code as materialCode |
| | | from stock_inventory si |
| | | left join product_model pm on si.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | |
| | | union all |
| | | |
| | | select |
| | | 0 as qualifiedQuantity, |
| | | su.qualitity as unQualifiedQuantity, |
| | | 0 as qualifiedLockedQuantity, |
| | | COALESCE(su.locked_quantity, 0) as unQualifiedLockedQuantity, |
| | | su.product_model_id, |
| | | su.create_time, |
| | | su.update_time, |
| | | 0 as warn_num, |
| | | su.remark, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name, |
| | | p.id as product_id, |
| | | null as qualifiedBatchNo, |
| | | su.batch_no as unQualifiedBatchNo, |
| | | pm.material_code as materialCode |
| | | from stock_uninventory su |
| | | left join product_model pm on su.product_model_id = pm.id |
| | | left join product p on pm.product_id = p.id |
| | | ) as combined |
| | | <where> |
| | | <if test="ew.productName != null and ew.productName !=''"> |
| | | and combined.product_name in ( |
| | | select distinct p.product_name |
| | | from product p |
| | | left join product_model pm on p.id = pm.product_id |
| | | where p.product_name like concat('%',#{ew.productName},'%') or pm.model like concat('%',#{ew.productName},'%') |
| | | ) |
| | | </if> |
| | | <if test="ew.topParentProductId != null and ew.topParentProductId > 0"> |
| | | and combined.product_id in (select id from product_tree) |
| | | </if> |
| | | </where> |
| | | group by product_model_id, model, unit, product_name, qualifiedBatchNo, unQualifiedBatchNo, materialCode |
| | | </select> |
| | | <select id="stockInventoryPage" resultType="com.ruoyi.stock.dto.StockInRecordDto"> |
| | | select sir.*,si.qualitity as current_stock, |
| | |
| | | left join product p on pm.product_id = p.id |
| | | </select> |
| | | |
| | | </mapper> |
| | | </mapper> |