|
@@ -3,9 +3,6 @@ package com.fjhx.wms.service.stock.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.fastjson2.JSONArray;
|
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.alibaba.fastjson2.JSONWriter;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -134,209 +131,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 维多利亚 按仓库库存查询
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Page<StockVo> pageByWarehouse(StockSelectDto dto) {
|
|
|
- Page<StockVo> page = getPage(dto);
|
|
|
- List<StockVo> stockVos = page.getRecords();
|
|
|
-
|
|
|
-
|
|
|
- List<Long> productIds = stockVos.stream().map(Stock::getProductId).collect(Collectors.toList());
|
|
|
- if (ObjectUtil.isNotEmpty(productIds)) {
|
|
|
-
|
|
|
- productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
-
|
|
|
- String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- json.put("code", productInfo.getCode());
|
|
|
- json.put("spec", productInfo.getSpec());
|
|
|
- json.put("unit", productInfo.getUnit());
|
|
|
- json.put("customCode", productInfo.getCustomCode());
|
|
|
-
|
|
|
- BigDecimal frozenQuantity = json.getBigDecimal("frozenQuantity");
|
|
|
- frozenQuantity = ObjectUtil.isEmpty(frozenQuantity) ? BigDecimal.ZERO : frozenQuantity;
|
|
|
- json.put("frozenQuantity", frozenQuantity);
|
|
|
- BigDecimal defectiveQuantity = json.getBigDecimal("defectiveQuantity");
|
|
|
- defectiveQuantity = ObjectUtil.isEmpty(defectiveQuantity) ? BigDecimal.ZERO : defectiveQuantity;
|
|
|
- json.put("defectiveQuantity", defectiveQuantity);
|
|
|
- item.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- List<Long> warehouseIds = new ArrayList<>();
|
|
|
- for (StockVo stockVo : stockVos) {
|
|
|
- String victoriatouristJson = stockVo.getVictoriatouristJson();
|
|
|
- if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
-
|
|
|
- warehouseIds.add(json.getLong("warehouseId"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ObjectUtil.isEmpty(warehouseIds)) {
|
|
|
- return page;
|
|
|
- }
|
|
|
- List<Warehouse> warehouses = warehouseService.listByIds(warehouseIds);
|
|
|
- Map<Long, String> warehouseMap = warehouses.stream().collect(Collectors.toMap(Warehouse::getId, Warehouse::getName));
|
|
|
- for (StockVo stockVo : stockVos) {
|
|
|
- String victoriatouristJson = stockVo.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- String warehouseName = warehouseMap.get(json.getLong("warehouseId"));
|
|
|
- json.put("warehouseName", warehouseName);
|
|
|
- stockVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- }
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<StockVo> pageByProduct(StockSelectDto dto) {
|
|
|
- IWrapper<Stock> wrapper = getWrapper();
|
|
|
- wrapper.orderByDesc("s", Stock::getId);
|
|
|
- wrapper.eq(Stock::getWarehouseId, dto.getId());
|
|
|
-
|
|
|
- String keyword = dto.getKeyword();
|
|
|
- if (ObjectUtil.isNotEmpty(keyword)) {
|
|
|
-
|
|
|
- List<Long> productIds = productInfoService.listObject(ProductInfo::getId,
|
|
|
- q -> q.like(ProductInfo::getCustomCode, keyword).or().like(ProductInfo::getName, keyword));
|
|
|
- wrapper.and(q -> q.like(Stock::getQuantity, keyword).or().in(Stock::getProductId, productIds));
|
|
|
- }
|
|
|
- wrapper.eq("pi.definition", dto.getDefinition());
|
|
|
- wrapper.groupBy("s.product_id");
|
|
|
- Page<StockVo> page = this.baseMapper.pageByProduct(dto.getPage(), wrapper);
|
|
|
- List<StockVo> stockVos = page.getRecords();
|
|
|
-
|
|
|
-
|
|
|
- for (StockVo stockVo : stockVos) {
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- BigDecimal frozenQuantity = stockVo.getFrozenQuantity();
|
|
|
- frozenQuantity = frozenQuantity == null ? BigDecimal.ZERO : frozenQuantity;
|
|
|
- json.put("frozenQuantity", frozenQuantity);
|
|
|
- BigDecimal defectiveQuantity = stockVo.getDefectiveQuantity();
|
|
|
- defectiveQuantity = defectiveQuantity == null ? BigDecimal.ZERO : defectiveQuantity;
|
|
|
- json.put("defectiveQuantity", defectiveQuantity);
|
|
|
- stockVo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- productInfoService.attributeAssign(stockVos, StockVo::getProductId, (item, productInfo) -> {
|
|
|
- item.setType(productInfo.getType());
|
|
|
- item.setProductName(productInfo.getName());
|
|
|
- item.setProductCode(productInfo.getCode());
|
|
|
- item.setProductUnit(productInfo.getUnit());
|
|
|
- item.setProductType(productInfo.getType());
|
|
|
- item.setProductSpec(productInfo.getSpec());
|
|
|
- item.setProductClassifyId(productInfo.getProductClassifyId());
|
|
|
- item.setProductDefinition(productInfo.getDefinition());
|
|
|
- item.setProductCustomCode(productInfo.getCustomCode());
|
|
|
-
|
|
|
-
|
|
|
- String victoriatouristJson = item.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- json.put("code", productInfo.getCode());
|
|
|
- json.put("spec", productInfo.getSpec());
|
|
|
- json.put("unit", productInfo.getUnit());
|
|
|
-
|
|
|
- BigDecimal frozenQuantity = json.getBigDecimal("frozenQuantity");
|
|
|
- frozenQuantity = ObjectUtil.isEmpty(frozenQuantity) ? BigDecimal.ZERO : frozenQuantity;
|
|
|
- json.put("frozenQuantity", frozenQuantity);
|
|
|
- BigDecimal defectiveQuantity = json.getBigDecimal("defectiveQuantity");
|
|
|
- defectiveQuantity = ObjectUtil.isEmpty(defectiveQuantity) ? BigDecimal.ZERO : defectiveQuantity;
|
|
|
- json.put("defectiveQuantity", defectiveQuantity);
|
|
|
- item.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- productClassifyService.attributeAssign(stockVos, StockVo::getProductClassifyId, (item, productClassify) -> {
|
|
|
- item.setProductClassifyName(productClassify.getName());
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- warehouseService.attributeAssign(stockVos, StockVo::getWarehouseId, (item, warehouse) -> {
|
|
|
- item.setWarehouseName(warehouse.getName());
|
|
|
- });
|
|
|
-
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<StockVo> pageByProductSpu(StockSelectDto dto) {
|
|
|
- IWrapper<Stock> wrapper = getWrapper();
|
|
|
- wrapper.eq(Stock::getWarehouseId, dto.getId());
|
|
|
- wrapper.like(Stock::getQuantity, dto.getKeyword());
|
|
|
- wrapper.eq("pi.definition", dto.getDefinition());
|
|
|
- wrapper.isNotNull("ps.id");
|
|
|
- wrapper.groupBy("ps.id");
|
|
|
- wrapper.orderByDesc("s", Stock::getId);
|
|
|
- Page<StockVo> page = this.baseMapper.pageByProductSpu(dto.getPage(), wrapper);
|
|
|
-
|
|
|
- List<StockVo> records = page.getRecords();
|
|
|
- List<Long> spuids = records.stream().map(StockVo::getProductSpuId).collect(Collectors.toList());
|
|
|
- if (ObjectUtil.isEmpty(spuids)) {
|
|
|
- return page;
|
|
|
- }
|
|
|
- List<ProductInfo> productInfoList = productInfoService.list(q -> q.in(ProductInfo::getProductSpuId, spuids));
|
|
|
- Map<Long, List<ProductInfo>> productInfoMap = productInfoList.stream().collect(Collectors.groupingBy(ProductInfo::getProductSpuId));
|
|
|
- for (StockVo record : records) {
|
|
|
- List<ProductInfo> productInfoList1 = productInfoMap.get(record.getProductSpuId());
|
|
|
- record.setLinkProductQuantity(BigDecimal.valueOf(productInfoList1.size()));
|
|
|
- record.setCombinationQuantity(0l);
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> linkProductIds = new ArrayList<>();
|
|
|
- for (StockVo record : records) {
|
|
|
- String victoriatouristJson = record.getVictoriatouristJson();
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- if (json.getInteger("combination") != 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONArray productCombinationList = json.getJSONArray("productCombinationList");
|
|
|
- for (int i = 0; i < productCombinationList.size(); i++) {
|
|
|
- JSONObject item = productCombinationList.getJSONObject(i);
|
|
|
- Long linkProductId = item.getLong("linkProductId");
|
|
|
- linkProductIds.add(linkProductId);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtil.isEmpty(linkProductIds)) {
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- List<Stock> list = list(q -> q.in(Stock::getProductId, linkProductIds));
|
|
|
- Map<Long, BigDecimal> stockMap = list.stream().collect(Collectors.toMap(Stock::getProductId, Stock::getQuantity));
|
|
|
- for (StockVo record : records) {
|
|
|
- String victoriatouristJson = record.getVictoriatouristJson();
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- if (json.getInteger("combination") != 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONArray productCombinationList = json.getJSONArray("productCombinationList");
|
|
|
-
|
|
|
- Long min = -1l;
|
|
|
- for (int i = 0; i < productCombinationList.size(); i++) {
|
|
|
- JSONObject item = productCombinationList.getJSONObject(i);
|
|
|
- Long linkProductId = item.getLong("linkProductId");
|
|
|
- BigDecimal linkQuantity = item.getBigDecimal("linkQuantity");
|
|
|
-
|
|
|
- BigDecimal stockQuantity = stockMap.getOrDefault(linkProductId, BigDecimal.ZERO);
|
|
|
-
|
|
|
- BigDecimal divide = stockQuantity.divide(linkQuantity, 0, BigDecimal.ROUND_DOWN);
|
|
|
-
|
|
|
-
|
|
|
- if (min == -1) {
|
|
|
- min = divide.longValue();
|
|
|
- } else if (divide.intValue() < min) {
|
|
|
- min = divide.longValue();
|
|
|
- }
|
|
|
- }
|
|
|
- record.setCombinationQuantity(min);
|
|
|
- }
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Stock detail(StockDto dto) {
|
|
|
return getOne(q -> q.eq(Stock::getWarehouseId, dto.getWarehouseId()).eq(Stock::getProductId, dto.getProductId()));
|
|
@@ -391,122 +185,6 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * 次品转良品
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void defectiveToQualified(Stock stock) {
|
|
|
- if (ObjectUtil.isEmpty(stock.getId())) {
|
|
|
- throw new ServiceException("库存id不能为空");
|
|
|
- }
|
|
|
- if (ObjectUtil.isEmpty(stock.getQuantity())) {
|
|
|
- throw new ServiceException("要转换的数量不能为空");
|
|
|
- }
|
|
|
- Stock stock1 = getById(stock.getId());
|
|
|
- String victoriatouristJson = stock1.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- BigDecimal quantity = stock1.getQuantity();
|
|
|
- BigDecimal defectiveQuantity = ObjectUtil.isNotEmpty(json.getBigDecimal("defectiveQuantity")) ? json.getBigDecimal("defectiveQuantity") : BigDecimal.ZERO;
|
|
|
- if (defectiveQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- throw new ServiceException("库存不足,无法转换");
|
|
|
- }
|
|
|
- stock1.setQuantity(quantity.add(stock.getQuantity()));
|
|
|
- json.put("defectiveQuantity", defectiveQuantity.subtract(stock.getQuantity()));
|
|
|
- stock1.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- updateById(stock1);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void inOut(List<? extends InOutBo> list, Long warehouseId, JournalType journalType, Long businessId) {
|
|
|
-
|
|
|
-
|
|
|
- changeStock(list, warehouseId, journalType);
|
|
|
-
|
|
|
-
|
|
|
- Long journalId = addJournal(warehouseId, journalType, businessId);
|
|
|
-
|
|
|
-
|
|
|
- addJournalDetails(list, journalId);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 良品转次品
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void qualifiedToDefective(Stock stock) {
|
|
|
- if (ObjectUtil.isEmpty(stock.getId())) {
|
|
|
- throw new ServiceException("库存id不能为空");
|
|
|
- }
|
|
|
- if (ObjectUtil.isEmpty(stock.getQuantity())) {
|
|
|
- throw new ServiceException("要转换的数量不能为空");
|
|
|
- }
|
|
|
- Stock stock1 = getById(stock.getId());
|
|
|
- String victoriatouristJson = stock1.getVictoriatouristJson();
|
|
|
- JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
- BigDecimal quantity = stock1.getQuantity();
|
|
|
- BigDecimal defectiveQuantity = ObjectUtil.isNotEmpty(json.getBigDecimal("defectiveQuantity")) ? json.getBigDecimal("defectiveQuantity") : BigDecimal.ZERO;
|
|
|
- if (quantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- throw new ServiceException("库存不足,无法转换");
|
|
|
- }
|
|
|
- stock1.setQuantity(quantity.subtract(stock.getQuantity()));
|
|
|
- json.put("defectiveQuantity", defectiveQuantity.add(stock.getQuantity()));
|
|
|
- stock1.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
|
|
|
- updateById(stock1);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* 改变库存数量
|
|
|
*/
|
|
@@ -567,49 +245,4 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 添加出入库记录
|
|
|
- */
|
|
|
- private Long addJournal(Long warehouseId, JournalType journalType, Long businessId) {
|
|
|
- StockJournal stockJournal = new StockJournal();
|
|
|
- stockJournal.setType(journalType.getDetailType());
|
|
|
- switch (journalType.getDetailType()) {
|
|
|
- case 1:
|
|
|
- stockJournal.setOpType(1);
|
|
|
- stockJournal.setCode(CodeEnum.SIN_CODE.getCode());
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- stockJournal.setOpType(2);
|
|
|
- stockJournal.setCode(CodeEnum.SOUT_CODE.getCode());
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- stockJournal.setOpType(1);
|
|
|
-
|
|
|
- break;
|
|
|
- case 11:
|
|
|
- stockJournal.setOpType(2);
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
- stockJournal.setBusinessId(businessId);
|
|
|
- stockJournal.setWarehouseId(warehouseId);
|
|
|
- stockJournalService.save(stockJournal);
|
|
|
- return stockJournal.getId();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 添加出入库明细
|
|
|
- */
|
|
|
- private void addJournalDetails(List<? extends InOutBo> list, Long journalId) {
|
|
|
- List<StockJournalDetails> journalDetailsList = list.stream().map(item -> {
|
|
|
- StockJournalDetails stockJournalDetails = new StockJournalDetails();
|
|
|
- stockJournalDetails.setStockJournalId(journalId);
|
|
|
- stockJournalDetails.setProductId(item.getProductId());
|
|
|
- stockJournalDetails.setQuantity(item.getQuantity());
|
|
|
- return stockJournalDetails;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- stockJournalDetailsService.saveBatch(journalDetailsList);
|
|
|
- }
|
|
|
-
|
|
|
}
|