24282 před 2 roky
rodič
revize
35cec3d3f4

+ 1 - 1
hx-common/common-tool/src/main/java/com/fjhx/utils/wrapperUtil/IWrapper.java

@@ -430,7 +430,7 @@ public class IWrapper<T> extends AbstractWrapper<T, String, IWrapper<T>> impleme
 
     @Override
     public IWrapper<T> like(String sqlFieldName, Object value) {
-        return like(ObjectUtil.isNotEmpty(value), sqlFieldName, value);
+        return apply(ObjectUtil.isNotEmpty(value), "instr(" + sqlFieldName + ", {0}) > 0", value);
     }
 
     /**

+ 63 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/stock/PageByCombinationVo.java

@@ -0,0 +1,63 @@
+package com.fjhx.params.stock;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@Getter
+@Setter
+public class PageByCombinationVo {
+
+    /**
+     * 定义 1物料 2产品
+     */
+    private Integer productDefinition;
+
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品编码
+     */
+    private String productCode;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 产品规格
+     */
+    private String productSpecs;
+
+    /**
+     * 产品单位
+     */
+    private String productUnit;
+
+    /**
+     * 库存数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 冻结数量
+     */
+    private BigDecimal frozenQuantity;
+
+    /**
+     * 可组合数量
+     */
+    private BigDecimal groupQuantity;
+
+    /**
+     * 具体产品
+     */
+    private List<PageByCombinationVo> children;
+
+}

+ 52 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/stock/PageByProductVo.java

@@ -0,0 +1,52 @@
+package com.fjhx.params.stock;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class PageByProductVo {
+
+    /**
+     * 定义 1物料 2产品
+     */
+    private Integer productDefinition;
+
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品编码
+     */
+    private String productCode;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 产品规格
+     */
+    private String productSpecs;
+
+    /**
+     * 产品单位
+     */
+    private String productUnit;
+
+    /**
+     * 库存数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 冻结数量
+     */
+    private BigDecimal frozenQuantity;
+
+}

+ 67 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/stock/PageByWarehouseVo.java

@@ -0,0 +1,67 @@
+package com.fjhx.params.stock;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class PageByWarehouseVo {
+
+    /**
+     * 仓库id
+     */
+    private Long warehouseId;
+
+    /**
+     * 仓库名称
+     */
+    private String warehouseName;
+
+    /**
+     * 库存id
+     */
+    private Long stockId;
+
+    /**
+     * 定义 1物料 2产品
+     */
+    private Integer productDefinition;
+
+    /**
+     * 产品id
+     */
+    private Long productId;
+
+    /**
+     * 产品编码
+     */
+    private String productCode;
+
+    /**
+     * 产品名称
+     */
+    private String productName;
+
+    /**
+     * 产品规格
+     */
+    private String productSpecs;
+
+    /**
+     * 产品单位
+     */
+    private String productUnit;
+
+    /**
+     * 库存数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 冻结数量
+     */
+    private BigDecimal frozenQuantity;
+
+}

+ 31 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/stock/StockController.java

@@ -3,6 +3,9 @@ package com.fjhx.controller.stock;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.base.Condition;
 import com.fjhx.entity.stock.Stock;
+import com.fjhx.params.stock.PageByCombinationVo;
+import com.fjhx.params.stock.PageByProductVo;
+import com.fjhx.params.stock.PageByWarehouseVo;
 import com.fjhx.params.stock.StockVo;
 import com.fjhx.service.stock.StockService;
 import org.springblade.core.tool.api.R;
@@ -62,5 +65,33 @@ public class StockController {
         return R.success(result);
     }
 
+    /**
+     * 根据仓库查询库存
+     */
+    @PostMapping("/pageByWarehouse")
+    public R pageByWarehouse(@RequestBody Condition condition) {
+        Page<PageByWarehouseVo> result = stockService.pageByWarehouse(condition);
+        return R.success(result);
+    }
+
+    /**
+     * 根据产品查询库存
+     */
+    @PostMapping("/pageByProduct")
+    public R pageByProduct(@RequestBody Condition condition) {
+        Page<PageByProductVo> result = stockService.pageByProduct(condition);
+        return R.success(result);
+    }
+
+    /**
+     * 根据组合查询库存
+     */
+    @PostMapping("/pageByCombination")
+    public R pageByCombination(@RequestBody Condition condition) {
+        Page<PageByCombinationVo> result = stockService.pageByCombination(condition);
+        return R.success(result);
+    }
+
+
 }
 

+ 10 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/stock/StockMapper.java

@@ -3,6 +3,10 @@ package com.fjhx.mapper.stock;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.entity.stock.Stock;
+import com.fjhx.params.stock.PageByCombinationVo;
+import com.fjhx.params.stock.PageByProductVo;
+import com.fjhx.params.stock.PageByWarehouseVo;
+import com.fjhx.utils.wrapperUtil.IWrapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.Map;
@@ -18,4 +22,10 @@ import java.util.Map;
 public interface StockMapper extends BaseMapper<Stock> {
     Page<Map<String, Object>> pageByWarehouseId(@Param("page") Page<Object> page, @Param("warehouseId") Long warehouseId);
 
+    Page<PageByWarehouseVo> pageByWarehouse(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
+
+    Page<PageByProductVo> pageByProduct(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
+
+    Page<PageByCombinationVo> pageByCombination(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
+
 }

+ 41 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/stock/StockMapper.xml

@@ -13,4 +13,45 @@
                  left join stock s on s.goods_id = pi.id and s.warehouse_id = #{warehouseId}
     </select>
 
+    <select id="pageByWarehouse" resultType="com.fjhx.params.stock.PageByWarehouseVo">
+        select w.id          warehouseId,
+               w.name        warehouseName,
+               s.id          stockId,
+               pi.definition productDefinition,
+               pi.id         productId,
+               pi.code       productCode,
+               pi.name       productName,
+               pi.specs      productSpecs,
+               pi.unit       productUnit,
+               s.quantity,
+               s.frozen_quantity
+        from warehouse w
+                 inner join stock s on w.id = s.warehouse_id
+                 inner join product_info pi on s.goods_id = pi.id
+            ${ew.customSqlSegment}
+    </select>
+
+    <select id="pageByProduct" resultType="com.fjhx.params.stock.PageByProductVo">
+        <include refid="page"/>
+    </select>
+
+    <select id="pageByCombination" resultType="com.fjhx.params.stock.PageByCombinationVo">
+        <include refid="page"/>
+    </select>
+
+    <sql id="page">
+        select pi.definition          productDefinition,
+               pi.id                  productId,
+               pi.code                productCode,
+               pi.name                productName,
+               pi.specs               productSpecs,
+               pi.unit                productUnit,
+               sum(s.quantity)        quantity,
+               sum(s.frozen_quantity) frozenQuantity
+        from warehouse w
+                 inner join stock s on w.id = s.warehouse_id
+                 inner join product_info pi on s.goods_id = pi.id
+            ${ew.customSqlSegment}
+    </sql>
+
 </mapper>

+ 14 - 6
hx-service/victoriatourist/src/main/java/com/fjhx/service/logistics/impl/LogisticsInfoServiceImpl.java

@@ -16,6 +16,7 @@ import com.fjhx.uitl.kd100.KD100Util;
 import com.fjhx.utils.FileClientUtil;
 import com.fjhx.utils.UserClientUtil;
 import com.fjhx.utils.wrapperUtil.IWrapper;
+import com.fjhx.utils.wrapperUtil.KeywordData;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.utils.Func;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,10 +62,11 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
         wrapper.eq("t1", LogisticsInfo::getStatus, LogisticsConstant.Status.STATUS_1)
                 .lt("t1", LogisticsInfo::getInStockStatus, LogisticsConstant.InStockStatus.STATUS_30)
                 .eq("t1", LogisticsInfo::getBusinessType, 1)
-                .ge("t2", Purchase::getStatus, PurchaseStatusEnum.STATUS_30.getKey())
-                .le("t2", Purchase::getStatus, PurchaseStatusEnum.STATUS_40.getKey())
+                .between("t2", Purchase::getStatus, PurchaseStatusEnum.STATUS_30.getKey(), PurchaseStatusEnum.STATUS_40.getKey())
                 .eq("t1", LogisticsInfo::getInStockStatus)
-                .and(Func.isNotEmpty(condition.get("keyword")), o -> o.apply("instr(t1.`code`, '" + condition.get("keyword") + "') > 0").or().apply("instr(t2.`code`, '" + condition.get("keyword") + "') > 0").or().apply("instr(t3.`name`, '" + condition.get("keyword") + "') > 0"))
+                .keyword(new KeywordData("t1.`code`"),
+                        new KeywordData("t2.`code`"),
+                        new KeywordData("t3.`name`"))
                 .orderByDesc("t1", ApplyPurchase::getId);
 
         Page<LogisticsInfo> page = baseMapper.getPurchaseInStockPage(createPage(condition), wrapper);
@@ -87,9 +89,15 @@ public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, L
             throw new ServiceException("物流信息不能为空");
         }
 
-        //查询快递100的物流信息
-        JSONObject result = KD100Util.queryTrack(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode());
-        Integer state = result.getInteger("state");
+        Integer state = -1;
+        // 查询快递100的物流信息
+        try {
+            JSONObject result = KD100Util.queryTrack(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode());
+            state = result.getInteger("state");
+        } catch (Exception e) {
+            log.error("未找到快递消息", e);
+        }
+
         if (!Objects.equals(state, LogisticsConstant.KD100Status.STATUS_3)) {
             // 如果不是已签收状态,则开启订阅(物流状态跟踪并推送)
             KD100Util.subscribe(logisticsInfoVo.getLogisticsCompanyCode(), logisticsInfoVo.getCode(), new Date());

+ 2 - 2
hx-service/victoriatourist/src/main/java/com/fjhx/service/product/impl/ProductInfoServiceImpl.java

@@ -191,7 +191,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
         }
 
-        FileClientUtil.relieveBindingFile(productInfoVo.getId());
+        FileClientUtil.againBindingFile(productInfoVo.getId(), productInfoVo.getFileInfoList());
 
     }
 
@@ -203,7 +203,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         Assert.eqZero(count, "此产品已有库存,无法删除");
 
         removeById(productInfoVo.getId());
-        FileClientUtil.againBindingFile(productInfoVo.getId(), productInfoVo.getFileInfoList());
+        FileClientUtil.relieveBindingFile(productInfoVo.getId());
     }
 
     @Override

+ 7 - 2
hx-service/victoriatourist/src/main/java/com/fjhx/service/stock/StockService.java

@@ -4,8 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.base.BaseService;
 import com.fjhx.base.Condition;
 import com.fjhx.entity.stock.Stock;
-import com.fjhx.params.stock.StockChangeVo;
-import com.fjhx.params.stock.StockVo;
+import com.fjhx.params.stock.*;
 
 import java.util.Map;
 
@@ -31,4 +30,10 @@ public interface StockService extends BaseService<Stock> {
 
     Page<Map<String, Object>> pageByWarehouseId(Condition condition);
 
+    Page<PageByWarehouseVo> pageByWarehouse(Condition condition);
+
+    Page<PageByProductVo> pageByProduct(Condition condition);
+
+    Page<PageByCombinationVo> pageByCombination(Condition condition);
+
 }

+ 78 - 2
hx-service/victoriatourist/src/main/java/com/fjhx/service/stock/impl/StockServiceImpl.java

@@ -6,20 +6,27 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.base.Condition;
+import com.fjhx.constants.StatusConstant;
+import com.fjhx.entity.product.ProductCombination;
+import com.fjhx.entity.product.ProductInfo;
 import com.fjhx.entity.stock.Stock;
+import com.fjhx.entity.warehouse.Warehouse;
 import com.fjhx.enums.stock.InTypeEnum;
 import com.fjhx.mapper.stock.StockMapper;
-import com.fjhx.params.stock.StockChangeVo;
-import com.fjhx.params.stock.StockVo;
+import com.fjhx.params.stock.*;
+import com.fjhx.service.product.ProductCombinationService;
 import com.fjhx.service.stock.StockService;
 import com.fjhx.utils.Assert;
 import com.fjhx.utils.WrapperUtil;
+import com.fjhx.utils.wrapperUtil.IWrapper;
+import com.fjhx.utils.wrapperUtil.KeywordData;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -35,6 +42,9 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
     @Autowired
     private StockJournalServiceImpl stockJournalService;
 
+    @Autowired
+    private ProductCombinationService productCombinationService;
+
     @Override
     public Page<Stock> getPage(Map<String, Object> condition) {
 
@@ -80,6 +90,72 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
         return baseMapper.pageByWarehouseId(condition.getPage(), warehouseId);
     }
 
+    @Override
+    public Page<PageByWarehouseVo> pageByWarehouse(Condition condition) {
+
+        IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
+
+        wrapper.keyword(new KeywordData("w", Warehouse::getName),
+                new KeywordData("p", ProductInfo::getCode),
+                new KeywordData("p", ProductInfo::getName)
+        );
+
+        return baseMapper.pageByWarehouse(condition.getPage(), wrapper);
+    }
+
+    @Override
+    public Page<PageByProductVo> pageByProduct(Condition condition) {
+
+        IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
+
+        wrapper.keyword(
+                        new KeywordData("p", ProductInfo::getCode),
+                        new KeywordData("p", ProductInfo::getName))
+                .groupBy("pi.id");
+
+        return baseMapper.pageByProduct(condition.getPage(), wrapper);
+    }
+
+    @Override
+    public Page<PageByCombinationVo> pageByCombination(Condition condition) {
+
+        // TODO 临时接到通知,优先级低,后面补
+
+        // 获取产品组合
+        IWrapper<Object> wrapper = IWrapper.getWrapper(condition)
+                .keyword(
+                        new KeywordData("p", ProductInfo::getCode),
+                        new KeywordData("p", ProductInfo::getName))
+                .eq("pi", ProductInfo::getCombination, StatusConstant.YES)
+                .groupBy("pi.id");
+        Page<PageByCombinationVo> page = baseMapper.pageByCombination(condition.getPage(), wrapper);
+
+        List<PageByCombinationVo> records = page.getRecords();
+        if (records.size() == 0) {
+            return page;
+        }
+
+        List<Long> productIdList = records.stream().map(PageByCombinationVo::getProductId).collect(Collectors.toList());
+        // 组合产品关联表
+        List<ProductCombination> combinationList = productCombinationService.list(
+                q -> q.select(
+                                ProductCombination::getProductId,
+                                ProductCombination::getLinkProductId,
+                                ProductCombination::getLinkQuantity
+                        )
+                        .in(ProductCombination::getProductId, productIdList));
+
+        // 获取组合关联的产品idList
+        List<Long> linkProductIdList = combinationList.stream().map(ProductCombination::getLinkProductId).collect(Collectors.toList());
+
+        // 查询关联产品信息
+
+        wrapper.clear();
+
+
+        return page;
+    }
+
     /**
      * 合并变更数量(如果同一种物品在出入库一个仓库,则合并数量)
      */