基于mall4j产品的二开项目后端
lee
2024-12-18 921461a3f906d74403aeb6a27051deb77eca10fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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));
    }
}