Browse Source

店铺体验分、带货口碑分 初版 kwaixiaodian_shop_score

zhaoxian 7 tháng trước cách đây
mục cha
commit
10a4e00f27

+ 22 - 2
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaixiaodianItemGetController.java

@@ -88,7 +88,7 @@ public class KwaixiaodianItemGetController extends BaseController {
     @ApiOperation(value = "获kwai订单列表月度数据")
     @ApiOperation(value = "获kwai订单列表月度数据")
     public void querykwaiOrderListMonth(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
     public void querykwaiOrderListMonth(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
         String date1 = DateUtils.getDate();
         String date1 = DateUtils.getDate();
-        String date0 = DateUtils.getSubtractTime(new Date(),30);
+        String date0 = DateUtils.getSubtractTime(new Date(), 30);
         List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes(date0, date1);
         List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes(date0, date1);
         for (String date : allDatesOfTwoTimes) {
         for (String date : allDatesOfTwoTimes) {
             orderCursorListService.querykwaiOrderList(shopId.trim(), 1, date, date, "");
             orderCursorListService.querykwaiOrderList(shopId.trim(), 1, date, date, "");
@@ -96,9 +96,29 @@ public class KwaixiaodianItemGetController extends BaseController {
         }
         }
     }
     }
 
 
+    /**
+     * 获取带货口碑分信息(open.score.master.get)
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.score.master.get&version=1
+     */
+    @GetMapping("/queryMasterScore")
+    @ApiOperation(value = "获取带货口碑分信息")
+    public void queryMasterScore(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
+        orderCursorListService.queryMaster(shopId);
+    }
+
+    /**
+     * 获取店铺体验分信息(open.score.shop.get)
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.score.master.get&version=1
+     */
+    @GetMapping("/queryShopScore")
+    @ApiOperation(value = "获取店铺体验分信息")
+    public void queryShopScore(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
+        orderCursorListService.queryShop(shopId);
+    }
+
     public static void main(String[] args) {
     public static void main(String[] args) {
         String date0 = DateUtils.getDate();
         String date0 = DateUtils.getDate();
-        String date1 = DateUtils.getSubtractTime(new Date(),30);
+        String date1 = DateUtils.getSubtractTime(new Date(), 30);
 
 
         System.out.println(date0);
         System.out.println(date0);
         System.out.println(date1);
         System.out.println(date1);

+ 55 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KwaixiaodianShopScore.java

@@ -0,0 +1,55 @@
+package com.ruixuan.isc.entity;
+
+import lombok.Data;
+
+/**
+ * kwaixiaodian店铺体验分、带货口碑分 kwaixiaodian_shop_score
+ */
+@Data
+public class KwaixiaodianShopScore {
+    /**
+     * 店铺id
+     */
+    private String shopId;
+
+    /**
+     * 店铺名称
+     */
+    private String shopName;
+
+    /**
+     * 公司ID
+     */
+    private Long companyId;
+
+    /**
+     * 公司名称
+     */
+    private String companyName;
+
+    /**
+     * 负责人
+     */
+    private String leaderName;
+
+    /**
+     * 带货口碑分
+     */
+    private String masterScore;
+
+    /**
+     * 带货口碑分消息体
+     */
+    private String masterScoreBody;
+
+    /**
+     * 店铺体验分
+     */
+    private String shopScore;
+
+    /**
+     * 店铺体验分消息体
+     */
+    private String shopScoreBody;
+
+}

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/KwaixiaodianOrderCursorListMapper.java

@@ -1,6 +1,7 @@
 package com.ruixuan.isc.mapper;
 package com.ruixuan.isc.mapper;
 
 
 import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
 import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
+import com.ruixuan.isc.entity.KwaixiaodianShopScore;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
@@ -19,4 +20,9 @@ public interface KwaixiaodianOrderCursorListMapper {
 
 
     int updateKWaiShopOrderStatus(@Param("oid") Long oid, @Param("status") Integer status);
     int updateKWaiShopOrderStatus(@Param("oid") Long oid, @Param("status") Integer status);
 
 
+    KwaixiaodianShopScore getScore(@Param("shopId") String shopId);
+
+    void insertKwaixiaodianShopScore(@Param("shopScore") KwaixiaodianShopScore shopScore);
+
+    void updateKwaixiaodianShopScore(KwaixiaodianShopScore shopScore);
 }
 }

+ 3 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IKwaixiaodianOrderCursorListService.java

@@ -19,4 +19,7 @@ public interface IKwaixiaodianOrderCursorListService {
     /*修改 新增kwaixiaodian_order_cursor_list status*/
     /*修改 新增kwaixiaodian_order_cursor_list status*/
     void updateKWaiShopOrderStatus(JSONObject eventJSon);
     void updateKWaiShopOrderStatus(JSONObject eventJSon);
 
 
+    void queryMaster(String shopId);
+
+    void queryShop(String shopId);
 }
 }

+ 99 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/KwaixiaodianOrderCursorListServiceImpl.java

@@ -7,13 +7,18 @@ import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
 import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
 import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
 import com.kuaishou.merchant.open.api.request.order.OpenOrderCursorListRequest;
 import com.kuaishou.merchant.open.api.request.order.OpenOrderCursorListRequest;
 import com.kuaishou.merchant.open.api.request.order.OpenOrderDetailRequest;
 import com.kuaishou.merchant.open.api.request.order.OpenOrderDetailRequest;
+import com.kuaishou.merchant.open.api.request.shop.OpenScoreMasterGetRequest;
+import com.kuaishou.merchant.open.api.request.shop.OpenScoreShopGetRequest;
 import com.kuaishou.merchant.open.api.response.order.OpenOrderCursorListResponse;
 import com.kuaishou.merchant.open.api.response.order.OpenOrderCursorListResponse;
 import com.kuaishou.merchant.open.api.response.order.OpenOrderDetailResponse;
 import com.kuaishou.merchant.open.api.response.order.OpenOrderDetailResponse;
+import com.kuaishou.merchant.open.api.response.shop.OpenScoreMasterGetResponse;
+import com.kuaishou.merchant.open.api.response.shop.OpenScoreShopGetResponse;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.isc.constants.KuaiShouConstants;
 import com.ruixuan.isc.constants.KuaiShouConstants;
 import com.ruixuan.isc.entity.KuaishouAccessToken;
 import com.ruixuan.isc.entity.KuaishouAccessToken;
 import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
 import com.ruixuan.isc.entity.KwaixiaodianOrderCursorList;
+import com.ruixuan.isc.entity.KwaixiaodianShopScore;
 import com.ruixuan.isc.mapper.KwaixiaodianOrderCursorListMapper;
 import com.ruixuan.isc.mapper.KwaixiaodianOrderCursorListMapper;
 import com.ruixuan.isc.service.IAccessTokenService;
 import com.ruixuan.isc.service.IAccessTokenService;
 import com.ruixuan.isc.service.IKwaixiaodianOrderCursorListService;
 import com.ruixuan.isc.service.IKwaixiaodianOrderCursorListService;
@@ -221,4 +226,98 @@ public class KwaixiaodianOrderCursorListServiceImpl implements IKwaixiaodianOrde
         }
         }
     }
     }
 
 
+    @Override
+    public void queryMaster(String shopId) {
+        KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
+        if (Check.isNull(token)) {
+            log.error("----kwaixiaodian获取带货口碑分信息失败,shopId:{} 没有token信息", shopId);
+        }
+
+        AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, token.getAppKey(), token.getSignSecret());
+        OpenScoreMasterGetRequest request = new OpenScoreMasterGetRequest();
+        request.setAccessToken(token.getAccessToken());
+        request.setApiMethodVersion(1L);
+        OpenScoreMasterGetResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSONObject.parseObject(GsonUtils.toJSON(response));
+        String code = jsonObject.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = jsonObject.getJSONObject("data");
+            String scoreStr = null;
+            JSONObject summary = data.getJSONObject("summary");
+            if (Check.isNotNull(summary)) {
+                scoreStr = summary.getString("scoreStr");
+            }
+            KwaixiaodianShopScore shopScore = mapper.getScore(shopId);
+            if (Check.isNull(shopScore)) {
+                shopScore = new KwaixiaodianShopScore();
+                shopScore.setShopId(shopId);
+                shopScore.setShopName(token.getShopName());
+                shopScore.setCompanyId(token.getCompanyId());
+                shopScore.setCompanyName(token.getCompanyName());
+                shopScore.setLeaderName(token.getLeaderName());
+                shopScore.setMasterScore(scoreStr);
+                shopScore.setMasterScoreBody(data.toJSONString());
+                mapper.insertKwaixiaodianShopScore(shopScore);
+            } else {
+                shopScore.setMasterScore(scoreStr);
+                shopScore.setMasterScoreBody(data.toJSONString());
+                mapper.updateKwaixiaodianShopScore(shopScore);
+            }
+        } else {
+            log.error("===kwaixiaodian获取带货口碑分信息异常,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
+        }
+    }
+
+    @Override
+    public void queryShop(String shopId) {
+        KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
+        if (Check.isNull(token)) {
+            log.error("----kwaixiaodian获取店铺体验分信息,shopId:{} 没有token信息", shopId);
+        }
+        AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, token.getAppKey(), token.getSignSecret());
+        OpenScoreShopGetRequest request = new OpenScoreShopGetRequest();
+        request.setAccessToken(token.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        OpenScoreShopGetResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSONObject.parseObject(GsonUtils.toJSON(response));
+        String code = jsonObject.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = jsonObject.getJSONObject("data");
+            String scoreStr = null;
+            JSONObject summary = data.getJSONObject("summary");
+            if (Check.isNotNull(summary)) {
+                scoreStr = summary.getString("scoreStr");
+            }
+            KwaixiaodianShopScore shopScore = mapper.getScore(shopId);
+            if (Check.isNull(shopScore)) {
+                shopScore = new KwaixiaodianShopScore();
+                shopScore.setShopId(shopId);
+                shopScore.setShopName(token.getShopName());
+                shopScore.setCompanyId(token.getCompanyId());
+                shopScore.setCompanyName(token.getCompanyName());
+                shopScore.setLeaderName(token.getLeaderName());
+                shopScore.setShopScore(scoreStr);
+                shopScore.setShopScoreBody(data.toJSONString());
+                mapper.insertKwaixiaodianShopScore(shopScore);
+            } else {
+                shopScore.setShopScore(scoreStr);
+                shopScore.setShopScoreBody(data.toJSONString());
+                mapper.updateKwaixiaodianShopScore(shopScore);
+            }
+        } else {
+            log.error("===kwaixiaodian获取店铺体验分信息异常,shopId:{},信息:{}", shopId, jsonObject.getString("error_msg"));
+        }
+    }
+
 }
 }

+ 46 - 0
ruixuan-live/src/main/resources/mapper/isc/KwaixiaodianOrderCursorListMapper.xml

@@ -421,4 +421,50 @@
         WHERE oid = #{oid}
         WHERE oid = #{oid}
     </update>
     </update>
 
 
+    <select id="getScore" resultType="com.ruixuan.isc.entity.KwaixiaodianShopScore" parameterType="java.lang.String">
+        select *
+        from ruixuan.kwaixiaodian_shop_score
+        where shop_id = #{shopId} limit 1
+    </select>
+
+
+    <insert id="insertKwaixiaodianShopScore">
+        insert
+        into `ruixuan`.kwaixiaodian_shop_score
+        (shop_id,
+         shop_name,
+         company_id,
+         company_name,
+         leader_name,
+         master_score,
+         master_score_body,
+         shop_score,
+         shop_score_body) value
+            ( #{shopScore.shopId},
+            #{shopScore.shopName},
+            #{shopScore.companyId},
+            #{shopScore.companyName},
+            #{shopScore.leaderName},
+            #{shopScore.masterScore},
+            #{shopScore.masterScoreBody},
+            #{shopScore.shopScore},
+            #{shopScore.shopScoreBody}
+            )
+    </insert>
+
+    <update id="updateKwaixiaodianShopScore" parameterType="com.ruixuan.isc.entity.KwaixiaodianShopScore">
+        update `ruixuan`.kwaixiaodian_shop_score
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="shopName != null">shop_name = #{shopName},</if>
+            <if test="companyId != null">company_id = #{companyId},</if>
+            <if test="companyName != null">company_name = #{companyName},</if>
+            <if test="leaderName != null">leader_name = #{leaderName},</if>
+            <if test="masterScore != null">master_score = #{masterScore},</if>
+            <if test="masterScoreBody != null">master_score_body = #{masterScoreBody},</if>
+            <if test="shopScore != null">shop_score = #{shopScore},</if>
+            <if test="shopScoreBody != null">shop_score_body = #{shopScoreBody},</if>
+        </trim>
+        where shop_id = #{shopId}
+    </update>
+
 </mapper>
 </mapper>