Ver código fonte

新增按商户查询库存

lvjian 2 anos atrás
pai
commit
ff706c11b0

+ 13 - 0
eccs-biz/src/main/java/com/emato/biz/domain/warehouse/OWbInveMng.java

@@ -108,6 +108,11 @@ public class OWbInveMng extends BaseEntity
     @Excel(name = "是否有效,0:有效,1:无效")
     private String isValid;
 
+    /**
+     * 三方商户号
+     */
+    private String thirdMerchSn;
+
     /** 创建人编号 */
     private String createrSn;
 
@@ -120,6 +125,14 @@ public class OWbInveMng extends BaseEntity
     /** 时间戳 */
     private Date tstm;
 
+    public String getThirdMerchSn() {
+        return thirdMerchSn;
+    }
+
+    public void setThirdMerchSn(String thirdMerchSn) {
+        this.thirdMerchSn = thirdMerchSn;
+    }
+
     public void setInveSn(String inveSn)
     {
         this.inveSn = inveSn;

+ 15 - 0
eccs-biz/src/main/java/com/emato/biz/mapper/merchant/MerchUserMapper.java

@@ -13,6 +13,21 @@ import java.util.List;
  */
 public interface MerchUserMapper 
 {
+    /**
+     * 根据用户 Id 查询绑定的商户
+     *
+     * @param userId
+     * @return
+     */
+    MerchUser selectMerchUserByUserId(String userId);
+
+    /**
+     * 根据查询条件统计数量
+     *
+     * @param merchUser
+     * @return
+     */
+    int selectCount(MerchUser merchUser);
 
     /**
      * 查询用户商户 VO

+ 9 - 0
eccs-biz/src/main/java/com/emato/biz/mapper/merchant/ThirdMerchantBizMapper.java

@@ -11,6 +11,15 @@ import com.emato.biz.domain.merchant.ThirdMerchantBiz;
  */
 public interface ThirdMerchantBizMapper
 {
+
+    /**
+     * 根据货主编号查询第三方商户信息
+     *
+     * @param clientMerchSn
+     * @return
+     */
+    ThirdMerchantBiz selectByClientMerchSn(String clientMerchSn);
+
     /**
      * 查询第三方商户信息
      *

+ 49 - 4
eccs-biz/src/main/java/com/emato/biz/service/impl/OWbInveMngServiceImpl.java

@@ -11,14 +11,21 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.emato.biz.config.OmsConfig;
+import com.emato.biz.domain.merchant.MerchUser;
+import com.emato.biz.domain.merchant.ThirdMerchantBiz;
 import com.emato.biz.domain.warehouse.Page;
 import com.emato.biz.domain.warehouse.PullInveQueryVO;
+import com.emato.biz.mapper.merchant.MerchUserMapper;
+import com.emato.biz.mapper.merchant.ThirdMerchantBizMapper;
 import com.emato.biz.mapper.warehouse.WbInveMngMapper;
 import com.emato.biz.util.JsonUtil;
 import com.emato.biz.util.OmsDataUtil;
+import com.emato.biz.util.RoleUtils;
 import com.emato.common.core.domain.AjaxResult;
+import com.emato.common.core.domain.entity.SysUser;
 import com.emato.common.exception.ServiceException;
 import com.emato.common.utils.DateUtils;
+import com.emato.common.utils.SecurityUtils;
 import com.emato.common.utils.oms.JacksonUtils;
 import com.emato.common.utils.oms.request.OmsSign;
 import org.apache.http.HttpStatus;
@@ -55,6 +62,12 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
     @Resource
     private WbInveMngMapper wbInveMngMapper;
 
+    @Resource
+    private MerchUserMapper merchUserMapper;
+
+    @Resource
+    private ThirdMerchantBizMapper thirdMerchantBizMapper;
+
     private static final Logger log = LoggerFactory.getLogger(OWbInveMngServiceImpl.class);
 
     @Autowired
@@ -75,12 +88,18 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
         queryVO.setPage(page);
         queryVO.setLimit(10);
 
+        ThirdMerchantBiz merchantBiz = thirdMerchantBizMapper.selectByClientMerchSn(queryVO.getMerchId());
+        if (Objects.nonNull(merchantBiz)) {
+            queryVO.setThirdMerchId(merchantBiz.getThirdMerchSn());
+        }
+
+
         // 查询 OMS 分页数据
         Optional<Page<OWbInveMng>> firstPageOpt =
                 OmsDataUtil.fetchOmsPageData(queryVO, OmsConfig.getQueryMngInveUrl(), OWbInveMng.class);
 
         // 如果有数据
-        firstPageOpt.ifPresent(firstPage -> {
+        /*firstPageOpt.ifPresent(firstPage -> {
             // 如果有数据,开始批量处理
             firstPage.getList().forEach(obj -> log.debug("拉取的 sku => {}", obj.getSku()));
             // 插入数据库
@@ -103,14 +122,14 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
                     rows.getAndIncrement();
                 });
                 // 查询 OMS 数据
-                /*CompletableFuture<Void> task = CompletableFuture.runAsync(() -> {
+                CompletableFuture<Void> task = CompletableFuture.runAsync(() -> {
                 }, threadPoolExecutor);
                 // 将任务添加到列表中
-                tasks.add(task);*/
+                tasks.add(task);
             }
             CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])).join();
 
-        });
+        });*/
 
         log.debug("拉取库存成功,拉取数据条数 => {}", rows.get());
         return AjaxResult.success("拉取库存成功!");
@@ -137,6 +156,32 @@ public class OWbInveMngServiceImpl implements IOWbInveMngService
     @Override
     public List<OWbInveMng> selectOWbInveMngList(OWbInveMng oWbInveMng)
     {
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        boolean allRole = RoleUtils.isAllRole(user);
+
+        if (!allRole) {
+            // 如果没有全部数据权限
+            // 查询该用户属于哪个商户
+            MerchUser merchUser = merchUserMapper.selectMerchUserByUserId(user.getUserId()+"");
+            if (Objects.isNull(merchUser)) {
+                // 如果用户没有绑定商户就返回空数据
+                return Collections.emptyList();
+            }
+
+            // 如果用户绑定了商户
+            // 获取用户绑定的商户号,开始查询该商户的库存数据
+            String merchSn = merchUser.getMerchSn();
+            // 设置商户作为查询条件
+            oWbInveMng.setMerchSn(merchSn);
+
+            // 查询是否有三方商户
+            ThirdMerchantBiz merchantBiz = thirdMerchantBizMapper.selectByClientMerchSn(merchSn);
+            if (Objects.nonNull(merchantBiz)) {
+                // 如果有第三方商户,设置三方商户号作为查询条件
+                oWbInveMng.setThirdMerchSn(merchantBiz.getThirdMerchSn());
+            }
+        }
+
         return wbInveMngMapper.selectWbInveMngList(oWbInveMng);
     }
 

+ 20 - 0
eccs-biz/src/main/resources/mapper/biz/merchant/MerchUserMapper.xml

@@ -42,6 +42,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         t1.mod_time
     </sql>
 
+    <!-- 根据用户 Id 查询绑定的商户 -->
+    <select id="selectMerchUserByUserId" resultMap="MerchUserResult">
+        <include refid="selectMerchUserVo"/>
+        <where>
+            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
+        </where>
+    </select>
+
+    <!-- 根据查询条件统计数量 -->
+    <select id="selectCount" resultType="int">
+        SELECT
+            COUTN(1)
+        FROM
+            merch_user
+        <where>
+            <if test="merchSn != null  and merchSn != ''"> and t1.merch_sn = #{merchSn}</if>
+            <if test="userId != null  and userId != ''"> and t1.user_id = #{userId}</if>
+        </where>
+    </select>
+
     <!-- 查询用户商户 VO 列表-->
     <select id="selectMerchUserVOList" resultMap="MerchUserVOResult">
         SELECT

+ 7 - 1
eccs-biz/src/main/resources/mapper/biz/merchant/ThirdMerchantBizMapper.xml

@@ -22,6 +22,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select third_merch_sn, third_merch_code, third_merch_name, account_merch_sn, client_merch_sn, is_valid, creater_sn, create_time, moder_sn, mod_time, tstm from third_merchant_biz
     </sql>
 
+    <!-- 根据货主编号查询第三方商户信息 -->
+    <select id="selectByClientMerchSn" resultType="com.emato.biz.domain.merchant.ThirdMerchantBiz">
+        <include refid="selectThirdMerchantBizVo"/>
+        where client_merch_sn = #{clientMerchSn}
+         AND is_valid = '0'
+    </select>
+
     <select id="selectThirdMerchantBizList" parameterType="ThirdMerchantBiz" resultMap="ThirdMerchantBizResult">
         <include refid="selectThirdMerchantBizVo"/>
         <where>
@@ -95,5 +102,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{thirdMerchSn}
         </foreach>
     </delete>
-
 </mapper>

+ 2 - 1
eccs-biz/src/main/resources/mapper/biz/warehouse/WbInveMngMapper.xml

@@ -71,7 +71,8 @@
         FROM
             wb_inve_mng t
         <where>
-            <if test="merchSn != null  and merchSn != ''"> and merch_sn = #{merchSn}</if>
+            <if test="merchSn != null  and merchSn != ''"> and t.merch_sn = #{merchSn}</if>
+            <if test="thirdMerchSn != null and thirdMerchSn != ''">or t.third_merch_sn = #{thirdMerchSn}</if>
             <if test="merchName != null  and merchName != ''"> and merch_name like concat('%', #{merchName}, '%')</if>
             <if test="emsClassCode != null  and emsClassCode != ''"> and ems_class_code = #{emsClassCode}</if>
             <if test="sku != null  and sku != ''"> and sku = #{sku}</if>