package com.yami.shop.api.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.yami.shop.bean.model.CpsDdCategory;
|
import com.yami.shop.bean.model.CpsJdCategory;
|
import com.yami.shop.bean.model.CpsMtActitvity;
|
import com.yami.shop.bean.model.CpsShop;
|
import com.yami.shop.bean.param.JtkShopSearchParam;
|
import com.yami.shop.common.config.BigSellerConfig;
|
import com.yami.shop.common.response.ServerResponseEntity;
|
import com.yami.shop.common.util.PageParam;
|
import com.yami.shop.cps.commom.client.DtkApiClient;
|
import com.yami.shop.cps.commom.request.putstorage.DtkGoodsListRequest;
|
import com.yami.shop.cps.commom.request.search.DtkJdGoodsTypeRequest;
|
import com.yami.shop.cps.commom.response.base.DtkApiResponse;
|
import com.yami.shop.cps.commom.response.base.DtkPageResponse;
|
import com.yami.shop.cps.commom.response.putstorage.DtkGoodsListItemResponse;
|
import com.yami.shop.cps.commom.response.search.DtkJdGoodsTypeResponse;
|
import com.yami.shop.cps.commom.service.CpsDdCategoryService;
|
import com.yami.shop.cps.commom.service.CpsJdCategoryService;
|
import com.yami.shop.cps.commom.service.CpsMtActitvityService;
|
import com.yami.shop.cps.commom.service.CpsShopService;
|
import com.yami.shop.cps.commom.utils.DTKUtils;
|
import com.yami.shop.cps.commom.utils.MTUtils;
|
import com.yami.shop.cps.commom.utils.PddUtils;
|
import com.yami.shop.cps.commom.vo.*;
|
import com.yami.shop.service.CpsConfigService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/cps")
|
@Tag(name = "CPS接口")
|
public class CpsController {
|
|
@Autowired
|
private CpsConfigService cpsConfigService;
|
|
@Autowired
|
private CpsShopService cpsShopService;
|
|
@Autowired
|
private CpsJdCategoryService cpsJdCategoryService;
|
|
@Autowired
|
private CpsMtActitvityService cpsMtActitvityService;
|
|
@Autowired
|
private CpsDdCategoryService cpsDdCategoryService;
|
|
@Value("${image.url:''}")
|
private String url;
|
|
@GetMapping("/getAllShop")
|
@Operation(summary = "拉取所有淘宝商品列表", description = "通过大淘客的接口拉取商品列表(只拉取一次,后续)")
|
|
public ServerResponseEntity<?> getALLTbShop(String pageId) {
|
TaoBaoVo taoBaoVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_TAOBAO_CONFIG, TaoBaoVo.class);
|
DtkApiClient client = DtkApiClient.getInstance(taoBaoVo.getAppKey(), taoBaoVo.getAppSecret());
|
DtkGoodsListRequest request = new DtkGoodsListRequest();
|
request.setVersion("v1.2.4");
|
if (StringUtils.isNotBlank(pageId)) {
|
request.setPageId(pageId);
|
} else {
|
request.setPageId("1");
|
}
|
request.setPageSize(100);
|
DtkApiResponse<DtkPageResponse<DtkGoodsListItemResponse>> execute = client.execute(request);
|
//创建实体类
|
List<DtkGoodsListItemResponse> list = execute.getData().getList();
|
List<CpsShop> cpsShopList = new ArrayList<>();
|
for (DtkGoodsListItemResponse shop : list) {
|
CpsShop cpsShop = new CpsShop();
|
BeanUtils.copyProperties(shop, cpsShop);
|
cpsShop.setShopId(shop.getId());
|
cpsShop.setConnect(shop.getDesc());
|
cpsShopList.add(cpsShop);
|
}
|
int count = cpsShopService.insertCpsShops(cpsShopList);
|
if (count > 0 && count < 100) {
|
return ServerResponseEntity.success("淘宝商品数据拉取成功!");
|
} else if (count == 100) {
|
getALLTbShop(execute.getData().getPageId());
|
} else {
|
return ServerResponseEntity.showFailMsg("淘宝商品数据拉取失败!");
|
}
|
return ServerResponseEntity.success("淘宝商品数据拉取成功!");
|
}
|
|
@GetMapping("/getShopList")
|
@Operation(summary = "淘宝商品列表查询", description = "通过大淘客的接口查询商品列表")
|
public ServerResponseEntity<IPage<CpsShop>> getShopList(PageParam<CpsShop> page, CpsShop cpsShop) {
|
IPage<CpsShop> cpsShopPage = cpsShopService.cpsShopList(cpsShop, page);
|
return ServerResponseEntity.success(cpsShopPage);
|
}
|
|
@GetMapping("/getShopDetail")
|
@Operation(summary = "淘宝商品详情查询", description = "通过大淘客的接口查询单个商品详情")
|
@Parameters({
|
@Parameter(name = "id", description = "商品主键id")
|
})
|
public ServerResponseEntity<?> getShopDetail(@RequestParam(value = "id") Long id) {
|
CpsShop cpsShop = cpsShopService.getById(id);
|
TaoBaoVo taoBaoVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_TAOBAO_CONFIG, TaoBaoVo.class);
|
return ServerResponseEntity.success(DTKUtils.getTBShopDetails(cpsShop.getGoodsId().toString(), taoBaoVo));
|
}
|
|
|
@GetMapping("/getCategoryList")
|
@Operation(summary = "京东商品类目查询", description = "京东商品类目查询")
|
public ServerResponseEntity<List<CpsJdCategory>> getCategoryList() {
|
List<CpsJdCategory> cpsJdCategory = cpsJdCategoryService.getCategoryList();
|
return ServerResponseEntity.success(cpsJdCategory);
|
}
|
|
@GetMapping("/getJdShopList")
|
@Operation(summary = "根据京东类目查询商品列表", description = "根据京东类目查询商品列表")
|
@Parameters({
|
@Parameter(name = "cid1", description = "一级类目"),
|
@Parameter(name = "keyword", description = "关键词"),
|
@Parameter(name = "pageNo", description = "页码"),
|
@Parameter(name = "pageSize", description = "每页数量")
|
})
|
public ServerResponseEntity<?> getJdShopList(@RequestParam(value = "cid1") Long cid1, @RequestParam(value = "keyword") String keyword, @RequestParam(value = "pageNo") String pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
|
JingDongVo jingDongVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JINGDONG_CONFIG, JingDongVo.class);
|
return ServerResponseEntity.success(DTKUtils.getJDShopList(cid1, keyword, jingDongVo, pageNo, pageSize));
|
}
|
|
|
@GetMapping("/getJdShopDetail")
|
@Operation(summary = "京东商品详情查询", description = "京东商品详情查询")
|
@Parameters({
|
@Parameter(name = "skuIds", description = "商品skuId")
|
})
|
public ServerResponseEntity<?> getJdShopDetail(@RequestParam(value = "skuIds") String skuIds) {
|
JingDongVo jingDongVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JINGDONG_CONFIG, JingDongVo.class);
|
return ServerResponseEntity.success(DTKUtils.getJDShopDetails(skuIds, jingDongVo));
|
}
|
|
|
@GetMapping("/getJdShopCategory")
|
@Operation(summary = "拉取京东商品类目查询", description = "获取京东商品类目查询(平台调用一次就行)")
|
public ServerResponseEntity<?> getJdShopCategory() {
|
JingDongVo jingDongVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JINGDONG_CONFIG, JingDongVo.class);
|
DtkApiClient client = DtkApiClient.getInstance(jingDongVo.getAppKey(), jingDongVo.getAppSecret());
|
DtkJdGoodsTypeRequest request = new DtkJdGoodsTypeRequest();
|
request.setVersion("v1.0.0");
|
DtkApiResponse<List<DtkJdGoodsTypeResponse>> execute = client.execute(request);
|
List<DtkJdGoodsTypeResponse> list = execute.getData();
|
int sort = 1;
|
for (DtkJdGoodsTypeResponse category : list) {
|
CpsJdCategory cpsJdCategory = new CpsJdCategory();
|
BeanUtils.copyProperties(category, cpsJdCategory);
|
cpsJdCategory.setIsShow(0);
|
cpsJdCategory.setSort(sort);
|
cpsJdCategoryService.insert(cpsJdCategory);
|
sort++;
|
}
|
return ServerResponseEntity.success();
|
}
|
|
@GetMapping("/getMtActivityList")
|
@Operation(summary = "CPS导航栏查询", description = "CPS导航栏查询")
|
public ServerResponseEntity<List<CpsMtActitvity>> getMtActivityList() {
|
List<CpsMtActitvity> cpsJdCategory = cpsMtActitvityService.getMtActivityList();
|
for (CpsMtActitvity cpsMtActitvity : cpsJdCategory) {
|
cpsMtActitvity.setImage(url + cpsMtActitvity.getImage());
|
}
|
return ServerResponseEntity.success(cpsJdCategory);
|
}
|
|
|
@GetMapping("/getPddShopCategory")
|
@Operation(summary = "拉取拼多多商品类目查询", description = "拉取拼多多商品类目查询(平台调用一次就行)")
|
public ServerResponseEntity<?> getPddShopCategory() throws Exception {
|
PddVo pddVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_PDD_CONFIG, PddVo.class);
|
List<CpsDdCategory> list = PddUtils.getPddGoodsCatsGet(pddVo);
|
for (CpsDdCategory cpsDdCategory:list){
|
cpsDdCategoryService.insert(cpsDdCategory);
|
}
|
return ServerResponseEntity.success();
|
}
|
|
@GetMapping("/getPddCategoryList")
|
@Operation(summary = "拼多多商品类目查询", description = "拼多多商品类目查询")
|
public ServerResponseEntity<List<CpsDdCategory>> getPddCategoryList() {
|
List<CpsDdCategory> cpsJdCategory = cpsDdCategoryService.getPddCategoryList();
|
return ServerResponseEntity.success(cpsJdCategory);
|
}
|
|
@GetMapping("/getUserIsBind")
|
@Operation(summary = "拼多多查询用户是否备案", description = "拼多多查询用户是否备案")
|
@Parameters({
|
@Parameter(name = "userId", description = "用户Id")
|
})
|
public ServerResponseEntity<?> getUserIsBind(@RequestParam(value = "userId") String userId) throws Exception {
|
PddVo pddVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_PDD_CONFIG, PddVo.class);
|
Integer bind = PddUtils.getIsBind(userId,pddVo);
|
return ServerResponseEntity.success(bind);
|
}
|
|
@GetMapping("/getProvinceAll")
|
@Operation(summary = "美团团购API-省份查询接口", description = "美团团购API-省份查询接口")
|
public ServerResponseEntity<?> getProvinceAll() throws Exception {
|
JtkVo jtkVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JTK_CONFIG, JtkVo.class);
|
return ServerResponseEntity.success(MTUtils.getAllProvince(jtkVo));
|
}
|
|
|
@GetMapping("/getCitiesByProvince")
|
@Operation(summary = "获取某个省份中城市信息", description = "获取某个省份中城市信息")
|
@Parameters({
|
@Parameter(name = "platformId", description = "平台 1:点评,2:美团"),
|
@Parameter(name = "provinceId", description = "省份ID")
|
})
|
public ServerResponseEntity<?> getCitiesByProvince(@RequestParam(value = "platformId") Integer platformId,@RequestParam(value = "provinceId") Integer provinceId) throws Exception {
|
JtkVo jtkVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JTK_CONFIG, JtkVo.class);
|
return ServerResponseEntity.success(MTUtils.getCitiesByProvince(provinceId,jtkVo));
|
}
|
|
@GetMapping("/getCategoriesByCity")
|
@Operation(summary = "获取某个城市的一级类目包含的二级类目信息", description = "获取某个城市的一级类目包含的二级类目信息")
|
@Parameters({
|
@Parameter(name = "cityId", description = "城市Id"),
|
@Parameter(name = "cat0Id", description = "一级类目Id")
|
})
|
public ServerResponseEntity<?> getCategoriesByCity(@RequestParam(value = "cityId") Integer cityId,String cat0Id) throws Exception {
|
JtkVo jtkVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JTK_CONFIG, JtkVo.class);
|
return ServerResponseEntity.success(MTUtils.getCategoriesByCity(cityId,cat0Id,jtkVo));
|
}
|
|
|
@GetMapping("/getMtRegions")
|
@Operation(summary = "获取某个城市的商圈信息(美团)", description = "获取某个城市的商圈信息(美团)")
|
@Parameters({
|
@Parameter(name = "cityId", description = "城市Id")
|
})
|
public ServerResponseEntity<?> getMtRegions(@RequestParam(value = "cityId") Integer cityId) throws Exception {
|
JtkVo jtkVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JTK_CONFIG, JtkVo.class);
|
return ServerResponseEntity.success(MTUtils.getMtRegions(cityId,jtkVo));
|
}
|
|
|
@GetMapping("/getRegions")
|
@Operation(summary = "获取某个城市的商圈信息(点评)", description = "获取某个城市的商圈信息(点评)")
|
@Parameters({
|
@Parameter(name = "cityId", description = "城市Id")
|
})
|
public ServerResponseEntity<?> getRegions(@RequestParam(value = "cityId") Integer cityId) throws Exception {
|
MtfxlmVo mtfxlmVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_MTFXLM_CONFIG, MtfxlmVo.class);
|
String result =MTUtils.getRegions(cityId,mtfxlmVo);
|
return ServerResponseEntity.success(result);
|
}
|
|
|
@PostMapping("/getShopSearch")
|
@Operation(summary = "团购搜索接口", description = "团购搜索接口")
|
public ServerResponseEntity<?> getShopSearch(@RequestBody JtkShopSearchParam param) throws Exception {
|
JtkVo jtkVo = cpsConfigService.getCpsConfigObject(BigSellerConfig.CPS_JTK_CONFIG, JtkVo.class);
|
return ServerResponseEntity.success(MTUtils.getShopSearch(param,jtkVo));
|
}
|
}
|