瀏覽代碼

Merge remote-tracking branch 'origin/master'

home 2 年之前
父節點
當前提交
f4650530ca

+ 8 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/material/Material.java

@@ -7,6 +7,8 @@ import com.fjhx.base.BaseEntity;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 物料
@@ -67,4 +69,10 @@ public class Material extends BaseEntity {
      */
     @TableField(exist = false)
     private String deptName;
+
+    /**
+     * 库存数量
+     */
+    @TableField(exist = false)
+    private BigDecimal stockQuantity;
 }

+ 13 - 7
hx-service/victoriatourist/src/main/java/com/fjhx/controller/apply/ApplyPurchaseController.java

@@ -1,16 +1,17 @@
 package com.fjhx.controller.apply;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import org.springblade.core.tool.api.R;
 import com.fjhx.entity.apply.ApplyPurchase;
 import com.fjhx.params.apply.ApplyPurchaseVo;
 import com.fjhx.service.apply.ApplyPurchaseService;
+import org.springblade.core.tool.api.R;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -22,35 +23,40 @@ import java.util.Map;
  * @since 2022-11-28
  */
 @RestController
-@RequestMapping("/applyPurchase")
+@RequestMapping("/apply/purchase")
 public class ApplyPurchaseController {
 
     @Autowired
     private ApplyPurchaseService applyPurchaseService;
 
     @PostMapping("/page")
-    public R page(@RequestBody Map<String, Object> condition){
+    public R page(@RequestBody Map<String, Object> condition) {
         Page<ApplyPurchase> result = applyPurchaseService.getPage(condition);
         return R.success(result);
     }
 
     @PostMapping("/add")
-    public R add(@RequestBody ApplyPurchaseVo applyPurchaseVo){
-        applyPurchaseService.add(applyPurchaseVo);
+    public R add(@RequestBody List<ApplyPurchase> list) {
+        applyPurchaseService.add(list);
         return R.success();
     }
 
     @PostMapping("/edit")
-    public R edit(@RequestBody ApplyPurchaseVo applyPurchaseVo){
+    public R edit(@RequestBody ApplyPurchaseVo applyPurchaseVo) {
         applyPurchaseService.edit(applyPurchaseVo);
         return R.success();
     }
 
     @PostMapping("/delete")
-    public R delete(@RequestBody ApplyPurchaseVo applyPurchaseVo){
+    public R delete(@RequestBody ApplyPurchaseVo applyPurchaseVo) {
         applyPurchaseService.delete(applyPurchaseVo);
         return R.success();
     }
 
+    @PostMapping("/details")
+    public R details(@RequestBody ApplyPurchaseVo applyPurchaseVo) {
+        return R.success(applyPurchaseService.getById(applyPurchaseVo.getId()));
+    }
+
 }
 

+ 2 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/apply/ApplyPurchaseService.java

@@ -5,6 +5,7 @@ import com.fjhx.entity.apply.ApplyPurchase;
 import com.fjhx.params.apply.ApplyPurchaseVo;
 import com.fjhx.base.BaseService;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -19,7 +20,7 @@ public interface ApplyPurchaseService extends BaseService<ApplyPurchase> {
 
     Page<ApplyPurchase> getPage(Map<String, Object> condition);
 
-    void add(ApplyPurchaseVo applyPurchaseVo);
+    void add(List<ApplyPurchase> list);
 
     void edit(ApplyPurchaseVo applyPurchaseVo);
 

+ 40 - 4
hx-service/victoriatourist/src/main/java/com/fjhx/service/apply/impl/ApplyPurchaseServiceImpl.java

@@ -1,14 +1,21 @@
 package com.fjhx.service.apply.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.entity.apply.ApplyPurchase;
-import com.fjhx.params.apply.ApplyPurchaseVo;
 import com.fjhx.mapper.apply.ApplyPurchaseMapper;
+import com.fjhx.params.apply.ApplyPurchaseVo;
 import com.fjhx.service.apply.ApplyPurchaseService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.uitl.code.CodeEnum;
 import com.fjhx.utils.wrapperUtil.IWrapper;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.redis.lock.RedisLockClient;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -22,6 +29,11 @@ import java.util.Map;
 @Service
 public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, ApplyPurchase> implements ApplyPurchaseService {
 
+    @Autowired
+    private RedisLockClient redisLockClient;
+
+    private final String REDIS_LOCK_CACHE_KEY = "seq:lock:" + AuthUtil.getTenantId() + ":material:";
+
     @Override
     public Page<ApplyPurchase> getPage(Map<String, Object> condition) {
 
@@ -31,8 +43,32 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
     }
 
     @Override
-    public void add(ApplyPurchaseVo applyPurchaseVo) {
-        save(applyPurchaseVo);
+    public void add(List<ApplyPurchase> list) {
+        if (
+                !redisLockClient.lockFair(REDIS_LOCK_CACHE_KEY, () -> {
+                    //获取编码
+                    String code = CodeEnum.APPLY_PURCHASE.getCode();
+                    //查询编码是否已存在
+                    if (!checkCodeIsExist(null, code)) {
+                        throw new ServiceException("后台自增编码存在重复,请重试或联系管理员!编码:" + code);
+                    }
+                    list.forEach(item -> {
+                        item.setCode(code);
+                    });
+                    saveBatch(list);
+                    return true;
+                })
+        ) {
+            throw new ServiceException("当前系统繁忙,请稍后重试!");
+        }
+    }
+
+    private Boolean checkCodeIsExist(Long id, String code) {
+        List<ApplyPurchase> list = lambdaQuery().ne(Func.isNotEmpty(id), ApplyPurchase::getId, id).eq(ApplyPurchase::getCode, code).list();
+        if (Func.isNotEmpty(list)) {
+            return false;
+        }
+        return true;
     }
 
     @Override

+ 19 - 1
hx-service/victoriatourist/src/main/java/com/fjhx/service/material/impl/MaterialServiceImpl.java

@@ -24,8 +24,10 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -95,11 +97,27 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
             //查询部门
             Map<Long, Dept> deptMap = iSysClient.getDeptByIdsToMap(deptIds);
 
+            Map<Long, Stock> stockMap = new HashMap<>();
+            //查询库存量
+            if (Func.isNotEmpty(condition.get("warehouseId"))) {
+                //物料ID集合
+                List<Long> ids = page.getRecords().stream().map(Material::getId).distinct().collect(Collectors.toList());
+                List<Stock> stocks = stockService.lambdaQuery().eq(Stock::getWarehouseId, condition.get("warehouseId")).in(Stock::getGoodsId, ids).list();
+                if (Func.isNotEmpty(stocks)) {
+                    stockMap = stocks.stream().collect(Collectors.toMap(Stock::getGoodsId, Function.identity(), (key1, key2) -> key2));
+                }
+            }
+
             for (Material record : page.getRecords()) {
-                if (Func.isNotEmpty(deptMap) && Func.isEmpty(deptMap.get(record.getDeptId()))) {
+                if (Func.isNotEmpty(deptMap) && Func.isNotEmpty(deptMap.get(record.getDeptId()))) {
                     Dept dept = deptMap.get(record.getDeptId());
                     record.setDeptName(dept.getDeptName());
                 }
+
+                if (Func.isNotEmpty(stockMap) && Func.isNotEmpty(stockMap.get(record.getId()))) {
+                    Stock stock = stockMap.get(record.getId());
+                    record.setStockQuantity(stock.getQuantity());
+                }
             }
         }