Commit 7c20b118 by 刘宇峰

同步基础数据接口

1 parent 7054735b
Showing 18 changed files with 223 additions and 9 deletions
......@@ -3,6 +3,7 @@ package cn.com.glsx.admin.api;
import cn.com.glsx.admin.modules.model.cloudcrane.response.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
......@@ -103,4 +104,16 @@ public interface ShopmallBaseDataApiService {
@GetMapping(value = "/queryExpressList")
public List<QueryExpressListResponse> queryExpressList();
@PostMapping(value = "/syncAddressData")
public Integer syncAddressData();
@PostMapping(value = "/syncCategoryData")
public Integer syncCategoryData();
@PostMapping(value = "/syncBrandData")
public Integer syncBrandData();
@PostMapping(value = "/syncExpressData")
public Integer syncExpressData();
}
......@@ -104,4 +104,28 @@ public class BaseDataApiController implements ShopmallBaseDataApiService {
return baseExpressService.queryExpressList();
}
@Operation(summary = "同步地址数据接口")
@Override
public Integer syncAddressData() {
return baseDistrictService.syncAddressData();
}
@Operation(summary = "同步分类数据接口")
@Override
public Integer syncCategoryData() {
return baseCategoryService.syncCategoryData();
}
@Operation(summary = "同步品牌数据接口")
@Override
public Integer syncBrandData() {
return baseBrandService.syncBrandData();
}
@Operation(summary = "同步快递公司数据接口")
@Override
public Integer syncExpressData() {
return baseExpressService.syncExpressData();
}
}
......@@ -12,4 +12,6 @@ public interface BaseBrandConverter {
QueryBrandListResponse toBrandListResponse(BaseBrand entity);
BaseBrand responseToBaseBrand(QueryBrandListResponse entity);
}
package cn.com.glsx.admin.modules.converter;
import cn.com.glsx.admin.modules.entity.BaseCategory;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryCategoryListResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryOneCategoryListResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QuerySecondCategoryListResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryThreeCategoryListResponse;
......@@ -18,4 +19,6 @@ public interface BaseCategoryConverter {
QueryThreeCategoryListResponse toThreeCategoryListResponse(BaseCategory entity);
BaseCategory responseToBaseCategory(QueryCategoryListResponse entity);
}
......@@ -2,10 +2,7 @@ package cn.com.glsx.admin.modules.converter;
import cn.com.glsx.admin.modules.entity.BaseDistrict;
import cn.com.glsx.admin.modules.model.BaseDistrictDTO;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryAddressAreaResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryAddressCityResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryAddressProvinceResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryAddressStreetResponse;
import cn.com.glsx.admin.modules.model.cloudcrane.response.*;
import cn.com.glsx.admin.modules.model.dto.BaseDistrictBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
......@@ -29,4 +26,6 @@ public interface BaseDistrictConverter {
QueryAddressStreetResponse toAddressStreetResponse(BaseDistrict entity);
BaseDistrict responseToBaseDistrict(QueryAddressListResponse entity);
}
......@@ -10,6 +10,8 @@ public interface BaseExpressConverter {
BaseExpressConverter INSTANCE = Mappers.getMapper(BaseExpressConverter.class);
QueryExpressListResponse toExpressListResponse(BaseExpress baseExpress);
QueryExpressListResponse toExpressListResponse(BaseExpress entity);
BaseExpress responseToBaseExpress(QueryExpressListResponse entity);
}
......@@ -3,7 +3,9 @@ package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.BaseBrand;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@Mapper
......@@ -11,4 +13,12 @@ public interface BaseBrandMapper extends CommonBaseMapper<BaseBrand> {
List<BaseBrand> selectList();
/**
* 批量插入数据
*
* @param list
* @return
*/
Integer batchInsertOrUpdate(@Param("list") Collection<BaseBrand> list);
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@Mapper
......@@ -16,4 +17,12 @@ public interface BaseCategoryMapper extends CommonBaseMapper<BaseCategory> {
List<BaseCategory> selectByParentCategoryCode(@Param("parentCategoryCode") String parentCategoryCode);
/**
* 批量插入数据
*
* @param list
* @return
*/
Integer batchInsertOrUpdate(@Param("list") Collection<BaseCategory> list);
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@Mapper
......@@ -16,4 +17,12 @@ public interface BaseDistrictMapper extends CommonBaseMapper<BaseDistrict> {
List<BaseDistrict> selectByParentAddressCode(@Param("parentAddressCode") String parentAddressCode);
/**
* 批量插入数据
*
* @param list
* @return
*/
Integer batchInsertOrUpdate(@Param("list") Collection<BaseDistrict> list);
}
\ No newline at end of file
......@@ -3,11 +3,22 @@ package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.BaseExpress;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@Mapper
public interface BaseExpressMapper extends CommonBaseMapper<BaseExpress> {
List<BaseExpress> selectList();
/**
* 批量插入数据
*
* @param list
* @return
*/
Integer batchInsertOrUpdate(@Param("list") Collection<BaseExpress> list);
}
\ No newline at end of file
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.converter.BaseBrandConverter;
import cn.com.glsx.admin.modules.entity.BaseBrand;
import cn.com.glsx.admin.modules.mapper.BaseBrandMapper;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryBrandListResponse;
import com.glsx.plat.constant.CacheNameTimeConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
......@@ -22,9 +26,25 @@ public class BaseBrandService {
@Cacheable(cacheNames = {CacheNameTimeConstant.CACHE_24HOURS}, value = "brandList")
public List<QueryBrandListResponse> queryBrandList() {
List<BaseBrand> list = baseBrandMapper.selectList();
// TODO: 2023/4/10 待转换
List<BaseBrand> brandList = baseBrandMapper.selectList();
List<QueryBrandListResponse> list = brandList.parallelStream()
.map(BaseBrandConverter.INSTANCE::toBrandListResponse).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
return list;
}
return cloudCraneService.queryBrandList();
}
@Transactional
public Integer syncBrandData() {
log.info("开始同步品牌数据");
List<QueryBrandListResponse> brandList = cloudCraneService.queryBrandList();
if (CollectionUtils.isEmpty(brandList)) {
return 0;
}
List<BaseBrand> list = brandList.parallelStream().map(BaseBrandConverter.INSTANCE::responseToBaseBrand).collect(Collectors.toList());
return baseBrandMapper.batchInsertOrUpdate(list);
}
}
......@@ -67,4 +67,14 @@ public class BaseCategoryService {
return cloudCraneService.queryCategoryList();
}
public Integer syncCategoryData() {
log.info("开始同步分类数据");
List<QueryCategoryListResponse> categoryList = cloudCraneService.queryCategoryList();
if (CollectionUtils.isEmpty(categoryList)) {
return 0;
}
List<BaseCategory> list = categoryList.parallelStream().map(BaseCategoryConverter.INSTANCE::responseToBaseCategory).collect(Collectors.toList());
return baseCategoryMapper.batchInsertOrUpdate(list);
}
}
......@@ -35,7 +35,7 @@ public class BaseDistrictService {
baseDistrictMapper.insert(district);
}
public void batchAdd(List<BaseDistrictBO> districtBOList) {
public void batchAddOrUpdate(List<BaseDistrictBO> districtBOList) {
AssertUtils.isNull(districtBOList, "districtBOList不能为空");
List<BaseDistrict> list = Lists.newArrayList();
......@@ -103,4 +103,14 @@ public class BaseDistrictService {
return cloudCraneService.queryAddressList();
}
public Integer syncAddressData() {
log.info("开始同步地址数据");
List<QueryAddressListResponse> addressList = cloudCraneService.queryAddressList();
if (CollectionUtils.isEmpty(addressList)) {
return 0;
}
List<BaseDistrict> list = addressList.parallelStream().map(BaseDistrictConverter.INSTANCE::responseToBaseDistrict).collect(Collectors.toList());
return baseDistrictMapper.batchInsertOrUpdate(list);
}
}
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.converter.BaseExpressConverter;
import cn.com.glsx.admin.modules.entity.BaseExpress;
import cn.com.glsx.admin.modules.mapper.BaseExpressMapper;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryExpressListResponse;
import com.glsx.plat.constant.CacheNameTimeConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
......@@ -22,8 +25,24 @@ public class BaseExpressService {
@Cacheable(cacheNames = {CacheNameTimeConstant.CACHE_24HOURS}, value = "expressList")
public List<QueryExpressListResponse> queryExpressList() {
List<BaseExpress> list = baseExpressMapper.selectList();
List<BaseExpress> expressList = baseExpressMapper.selectList();
List<QueryExpressListResponse> list = expressList.parallelStream()
.map(BaseExpressConverter.INSTANCE::toExpressListResponse).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
return list;
}
return cloudCraneService.queryExpressList();
}
public Integer syncExpressData() {
log.info("开始同步快递公司数据");
List<QueryExpressListResponse> expressList = cloudCraneService.queryExpressList();
if (CollectionUtils.isEmpty(expressList)) {
return 0;
}
List<BaseExpress> list = expressList.parallelStream().map(BaseExpressConverter.INSTANCE::responseToBaseExpress).collect(Collectors.toList());
return baseExpressMapper.batchInsertOrUpdate(list);
}
}
......@@ -31,4 +31,24 @@
from shopmall_base_brand
where del_flag = 0
</select>
<insert id="batchInsertOrUpdate">
INSERT INTO shopmall_base_brand
(brand_code, brand_name, en_brand_name, brand_logo, brand_synopsis, brand_initials, del_flag, created_date)
values
<foreach collection="list" item="item" separator=",">
(
#{item.brandCode},
#{item.brandName},
#{item.enBrandName},
#{item.brandLogo},
#{item.brandSynopsis},
#{item.brandInitials},
0,
sysdate()
)
</foreach>
ON DUPLICATE KEY UPDATE
updated_time=sysdate()
</insert>
</mapper>
\ No newline at end of file
......@@ -46,4 +46,23 @@
where del_flag = 0
and parent_category_code = #{parentCategoryCode}
</select>
<insert id="batchInsertOrUpdate">
INSERT INTO shopmall_base_category
(category_code, category_name, parent_category_code, category_level, category_img_url, del_flag, created_date)
values
<foreach collection="list" item="item" separator=",">
(
#{item.categoryCode},
#{item.categoryName},
#{item.parentCategoryCode},
#{item.categoryLevel},
#{item.categoryImgUrl},
0,
sysdate()
)
</foreach>
ON DUPLICATE KEY UPDATE
updated_time=sysdate()
</insert>
</mapper>
\ No newline at end of file
......@@ -45,4 +45,22 @@
where del_flag = 0
and parent_address_code = #{parentAddressCode}
</select>
<insert id="batchInsertOrUpdate">
INSERT INTO shopmall_base_district
(address_code, address_name, parent_address_code, address_level, del_flag, created_date)
values
<foreach collection="list" item="item" separator=",">
(
#{item.addressCode},
#{item.addressName},
#{item.parentAddressCode},
#{item.addressLevel},
0,
sysdate()
)
</foreach>
ON DUPLICATE KEY UPDATE
updated_time=sysdate()
</insert>
</mapper>
\ No newline at end of file
......@@ -27,4 +27,20 @@
from shopmall_base_express
where del_flag = 0
</select>
<insert id="batchInsertOrUpdate">
INSERT INTO shopmall_base_express
(express_code, express_name, del_flag, created_date)
values
<foreach collection="list" item="item" separator=",">
(
#{item.expressCode},
#{item.expressName},
0,
sysdate()
)
</foreach>
ON DUPLICATE KEY UPDATE
updated_time=sysdate()
</insert>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!