| | |
| | | |
| | | @TableField(exist = false) |
| | | private LocalDateTime createTime; |
| | | @ApiModelProperty(value = "创建用户") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Integer createUser; |
| | | |
| | | @TableField(exist = false) |
| | | private Long parentId; |
| | | |
| | | @TableField(exist = false) |
| | | private String parentName; |
| | | |
| | | @ApiModelProperty("顶部父产品id") |
| | | @TableField(exist = false) |
| | | private Long topProductParentId; |
| | | } |
| | |
| | | return R.ok(stockInventoryDtoIPage); |
| | | } |
| | | |
| | | @GetMapping("/pageListCombinedStockInventory") |
| | | @ApiOperation("分页查询联合库存列表") |
| | | public R pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto) { |
| | | IPage<StockInventoryDto> stockInventoryDtoIPage = stockInventoryService.pageListCombinedStockInventory(page, stockInventoryDto); |
| | | return R.ok(stockInventoryDtoIPage); |
| | | } |
| | | |
| | | @PostMapping("/addstockInventory") |
| | | @ApiOperation("新增库存") |
| | | public R addstockInventory(@RequestBody StockInventoryDto stockInventoryDto) { |
| | |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.stock.pojo.StockInventory; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | |
| | | * 厚度 |
| | | */ |
| | | private BigDecimal thickness; |
| | | |
| | | @ApiModelProperty("顶部父产品id") |
| | | private Long topParentProductId; |
| | | |
| | | @ApiModelProperty("库存类型:qualified(合格)、unqualified(不合格)") |
| | | private String stockType; |
| | | |
| | | @ApiModelProperty("合格库存数量") |
| | | private BigDecimal qualifiedQuantity; |
| | | |
| | | @ApiModelProperty("不合格库存数量") |
| | | private BigDecimal unQualifiedQuantity; |
| | | |
| | | @ApiModelProperty("合格库存冻结数量") |
| | | private BigDecimal qualifiedLockedQuantity; |
| | | |
| | | @ApiModelProperty("不合格库存冻结数量") |
| | | private BigDecimal unQualifiedLockedQuantity; |
| | | |
| | | @ApiModelProperty("合格库存未冻结数量") |
| | | private BigDecimal qualifiedUnLockedQuantity; |
| | | |
| | | @ApiModelProperty("不合格库存未冻结数量") |
| | | private BigDecimal unQualifiedUnLockedQuantity; |
| | | |
| | | @ApiModelProperty("合格库存ID") |
| | | private Long qualifiedId; |
| | | |
| | | @ApiModelProperty("不合格库存ID") |
| | | private Long unQualifiedId; |
| | | } |
| | |
| | | @Excel(name = "单位") |
| | | private String unit; |
| | | |
| | | @Excel(name = "库存数量") |
| | | private BigDecimal qualitity; |
| | | @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; |
| | |
| | | |
| | | IPage<StockInventoryDto> pagestockInventory(Page page, @Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | | IPage<StockInventoryDto> pageListCombinedStockInventory(Page page, @Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | | int updateAddStockInventory(@Param("ew") StockInventoryDto stockInventoryDto); |
| | | |
| | |
| | | |
| | | IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto); |
| | | |
| | | IPage<StockInventoryDto> pageListCombinedStockInventory(Page page, StockInventoryDto stockInventoryDto); |
| | | |
| | | Boolean addstockInventory(StockInventoryDto stockInventoryDto); |
| | | |
| | | Boolean subtractStockInventory(StockInventoryDto stockInventoryDto); |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.R; |
| | |
| | | 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.StockInventory; |
| | | 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 lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockInRecordService stockInRecordService; |
| | | private StockOutRecordService stockOutRecordService; |
| | | private StockUninventoryService stockUninventoryService; |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | |
| | | @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); |
| | | } |
| | | |
| | | //入库调用 |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | 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("冻结数量不能超过本次导入的库存数量"); |
| | | // 验证合格冻结数量 |
| | | if (ObjectUtils.isNotEmpty(dto.getQualifiedLockedQuantity())) { |
| | | if (dto.getQualifiedLockedQuantity().compareTo(dto.getQualifiedQuantity()) > 0) { |
| | | throw new ServiceException("合格冻结数量不能超过本次导入的合格库存数量"); |
| | | } |
| | | 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()); |
| | | |
| | | // 验证不合格冻结数量 |
| | | if (ObjectUtils.isNotEmpty(dto.getUnQualifiedLockedQuantity())) { |
| | | if (dto.getUnQualifiedLockedQuantity().compareTo(dto.getUnQualifiedQuantity()) > 0) { |
| | | throw new ServiceException("不合格冻结数量不能超过本次导入的不合格库存数量"); |
| | | } |
| | | 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("导入成功"); |
| | | } |
| | | |
| | | |
| | |
| | | stockInventory.setLockedQuantity(stockInventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity())); |
| | | return this.updateById(stockInventory); |
| | | } |
| | | } |
| | | } |
| | |
| | | StockUninventory newStockUnInventory = new StockUninventory(); |
| | | newStockUnInventory.setProductModelId(stockUninventoryDto.getProductModelId()); |
| | | newStockUnInventory.setQualitity(stockUninventoryDto.getQualitity()); |
| | | newStockUnInventory.setLockedQuantity(stockUninventoryDto.getLockedQuantity()); |
| | | newStockUnInventory.setVersion(1); |
| | | newStockUnInventory.setRemark(stockUninventoryDto.getRemark()); |
| | | stockUninventoryMapper.insert(newStockUnInventory); |
| | |
| | | <if test="c.parentName != null and c.parentName != ''"> |
| | | AND pt.top_name LIKE CONCAT('%', #{c.parentName}, '%') |
| | | </if> |
| | | <if test="c.topProductParentId != null and c.topProductParentId > 0"> |
| | | and p.id in ( |
| | | WITH RECURSIVE product_tree AS ( |
| | | SELECT id |
| | | FROM product |
| | | WHERE id = #{c.topProductParentId} |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT p.id |
| | | FROM product p |
| | | INNER JOIN product_tree pt ON p.parent_id = pt.id |
| | | ) |
| | | select id from product_tree |
| | | ) |
| | | </if> |
| | | </where> |
| | | ORDER BY pm.id DESC |
| | | </select> |
| | |
| | | </if> |
| | | </select> |
| | | |
| | | <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, |
| | | '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, |
| | | si.remark, |
| | | pm.unit, |
| | | p.product_name, |
| | | p.id as product_id |
| | | 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 |
| | | 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 |
| | | 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 like concat('%',#{ew.productName},'%') |
| | | </if> |
| | | <if test="ew.model != null and ew.model !=''"> |
| | | and combined.model like concat('%',#{ew.model},'%') |
| | | </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 |
| | | </select> |
| | | <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData"> |
| | | select si.qualitity, |
| | | pm.model, |
| | | pm.unit, |
| | | p.product_name, |
| | | coalesce(si.warn_num, 0) as warn_num, |
| | | coalesce(si.locked_quantity, 0) as locked_quantity, |
| | | si.remark, |
| | | si.update_time |
| | | 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> |
| | | 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 |
| | | 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 |
| | | 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 |
| | | 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 like concat('%',#{ew.productName},'%') |
| | | </if> |
| | | <if test="ew.model != null and ew.model !=''"> |
| | | and combined.model like concat('%',#{ew.model},'%') |
| | | </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 |
| | | </select> |
| | | <select id="stockInventoryPage" resultType="com.ruoyi.stock.dto.StockInRecordDto"> |
| | | select sir.*,si.qualitity as current_stock, |
| | |
| | | ORDER BY DATE(sor.create_time) ASC |
| | | </select> |
| | | |
| | | </mapper> |
| | | </mapper> |
| | |
| | | <if test="ew.qualitity != null"> |
| | | qualitity = qualitity + #{ew.qualitity}, |
| | | </if> |
| | | <if test="ew.lockedQuantity != null"> |
| | | locked_quantity = locked_quantity + #{ew.lockedQuantity}, |
| | | </if> |
| | | <if test="ew.version != null"> |
| | | version = version + 1, |
| | | </if> |