Browse Source

同步ldm轮播图

Aslee 2 years ago
parent
commit
f0d1b018e4

+ 7 - 0
src/main/java/com/caimei/controller/auth/AuthApi.java

@@ -205,4 +205,11 @@ public class AuthApi {
         }
         return authService.exportDataByExcel(authUserId, response);
     }
+
+    @ApiOperation("ldm门店图/备注导入")
+    @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id")
+    @GetMapping("/ldm/image/import")
+    public ResponseJson importLdmImage(Integer authUserId){
+        return authService.importLdmImage(authUserId);
+    }
 }

+ 4 - 0
src/main/java/com/caimei/mapper/cmMapper/AuthMapper.java

@@ -70,4 +70,8 @@ public interface AuthMapper {
     List<TownPo> getTownList(String townName);
 
     Integer getProvinceIdByCityId(Integer cityId);
+
+    List<AuthVo> getAuthByNameAndAddress(@Param("authParty") String authParty, @Param("address") String address);
+
+    void updateRemarks(@Param("authId") Integer authId, @Param("remarks") String remarks);
 }

+ 1 - 1
src/main/java/com/caimei/mapper/ldmMapper/LdmMapper.java

@@ -15,5 +15,5 @@ import java.util.List;
 public interface LdmMapper {
 
 
-    List<LdmDataPo> getLdmClubData(Integer ldmLatestClubId);
+    List<LdmDataPo> getLdmClubData(Integer ldmLatestClubId, Integer delFlag);
 }

+ 5 - 0
src/main/java/com/caimei/model/po/LdmDataPo.java

@@ -116,4 +116,9 @@ public class LdmDataPo {
      */
     private Integer maxParamNum;
 
+    /**
+     * 店铺备注
+     */
+    private String remarks;
+
 }

+ 7 - 0
src/main/java/com/caimei/service/auth/AuthService.java

@@ -106,4 +106,11 @@ public interface AuthService {
      * 机构下拉框列表
      */
     ResponseJson<List<AuthVo>> getAuthSelectList(Integer authUserId);
+
+    /**
+     * ldm门店图/备注导入
+     * @param authUserId
+     * @return
+     */
+    ResponseJson importLdmImage(Integer authUserId);
 }

+ 48 - 0
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -3,6 +3,7 @@ package com.caimei.service.auth.impl;
 import com.caimei.config.FastDfsClient;
 import com.caimei.mapper.cmMapper.AuthMapper;
 import com.caimei.mapper.cmMapper.AuthProductMapper;
+import com.caimei.mapper.ldmMapper.LdmMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.ProductSaveDto;
 import com.caimei.model.po.AuthImportPo;
@@ -55,6 +56,9 @@ public class AuthServiceImpl implements AuthService {
     @Resource
     private AuthMapper authMapper;
 
+    @Resource
+    private LdmMapper ldmMapper;
+
     @Resource
     private AuthProductMapper authProductMapper;
 
@@ -161,6 +165,50 @@ public class AuthServiceImpl implements AuthService {
         return ResponseJson.success(authList);
     }
 
+    @Override
+    public ResponseJson importLdmImage(Integer authUserId) {
+        List<LdmDataPo> ldmClubData = ldmMapper.getLdmClubData(null, 0);
+        ldmClubData.forEach(ldmClub->{
+            String pic2 = ldmClub.getPic2();
+            String pic3 = ldmClub.getPic3();
+            String pic4 = ldmClub.getPic4();
+            List<AuthVo> authList = authMapper.getAuthByNameAndAddress(ldmClub.getAuthParty(), ldmClub.getAddress());
+            if (null != authList && authList.size() > 0 ) {
+                if (authList.size() > 1) {
+                    log.info(">>>>>>>>>>>>>>>>>>>>>导入ldm门店图错误:对应门店过多,门店名称:" + ldmClub.getAuthParty());
+                } else {
+                    AuthVo auth = authList.get(0);
+                    Integer authId = auth.getAuthId();
+                    if (StringUtils.isNotEmpty(pic2) || StringUtils.isNotEmpty(pic3) || StringUtils.isNotEmpty(pic4)) {
+                        authMapper.deleteBanner(authId);
+                        insertBanner(pic2, authId);
+                        insertBanner(pic3, authId);
+                        insertBanner(pic4, authId);
+                    }
+                    if (StringUtils.isNotEmpty(ldmClub.getRemarks())) {
+                        authMapper.updateRemarks(authId, ldmClub.getRemarks());
+                    }
+                }
+            } else {
+                log.info(">>>>>>>>>>>>>>>>>>>>>导入ldm门店图错误:找不到对应门店,门店名称:" + ldmClub.getAuthParty());
+            }
+        });
+        return ResponseJson.success();
+    }
+
+    private void insertBanner(String pic, Integer authId) {
+        if (StringUtils.isNotEmpty(pic)) {
+            String imagePath = "https://wangdian.skinovachina.com" + pic;
+            String fileName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
+            try {
+                String banner = uploadService.saveFileByUrl(imagePath, fileName);
+                authMapper.insertBanner(authId, banner);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     @Override
     public ResponseJson saveAuth(CmBrandAuthPo auth, List<String> bannerList, boolean importFlag) {
         Integer authId = auth.getId();

+ 1 - 1
src/main/java/com/caimei/task/LdmTask.java

@@ -49,7 +49,7 @@ public class LdmTask {
     public void readLdmData() {
         AtomicReference<Integer> ldmLatestClubId = new AtomicReference<>(authMapper.getLdmLatestClubId());
         log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>开始同步,ldmLatestClubId:" + ldmLatestClubId.get());
-        List<LdmDataPo> ldmDataList = ldmMapper.getLdmClubData(ldmLatestClubId.get());
+        List<LdmDataPo> ldmDataList = ldmMapper.getLdmClubData(ldmLatestClubId.get(), null);
         ldmDataList.forEach(ldmData->{
             ldmLatestClubId.set(ldmData.getId());
             String lngAndLat = ldmData.getLngAndLat();

+ 11 - 0
src/main/resources/mapper/AuthMapper.xml

@@ -48,6 +48,12 @@
     <update id="updateLdmLatestClubId">
         update ldm_latest_club_id set ldmClubId = #{ldmLatestClubId} where id = 1;
     </update>
+    <update id="updateRemarks">
+        update cm_brand_auth
+        set customFlag = 1,
+            remarks = #{remarks}
+        where id = #{authId}
+    </update>
     <delete id="deleteBanner">
         delete from cm_brand_auth_banner where authId = #{authId}
     </delete>
@@ -184,4 +190,9 @@
     <select id="getProvinceIdByCityId" resultType="java.lang.Integer">
         select provinceID from city where cityID = #{cityId}
     </select>
+    <select id="getAuthByNameAndAddress" resultType="com.caimei.model.vo.AuthVo">
+        select id as authId from cm_brand_auth
+        where authParty like concat('%',#{authParty},'%') and address like concat('%',#{address},'%')
+        and delFlag = 0
+    </select>
 </mapper>

+ 10 - 2
src/main/resources/mapper/LdmMapper.xml

@@ -5,7 +5,15 @@
     <select id="getLdmClubData" resultType="com.caimei.model.po.LdmDataPo">
         select id,name as authParty,if(status = 1,1,0) as status,if(status = 1,1,0) as auditStatus,
                tel as mobile,addr as address,pic1,pic2,pic3,pic4,pic5,du as lngAndLat,
-               if(deleted_at is null,0,1) as delFlag,regId1,regId2,regId3
-        from nissan_ht_alcohol where id > #{ldmLatestClubId};
+               if(deleted_at is null,0,1) as delFlag,regId1,regId2,regId3,labe as remarks
+        from nissan_ht_alcohol
+        <where>
+            <if test="ldmLatestClubId != null">
+                and id > #{ldmLatestClubId}
+            </if>
+            <if test="delFlag != null">
+                and deleted_at is null
+            </if>
+        </where>
     </select>
 </mapper>