|
@@ -3,12 +3,9 @@ package org.jeecg.modules.adweb.api.controller;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
@@ -31,8 +28,6 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/openapi")
|
|
@@ -42,15 +37,21 @@ public class OpenAPIController {
|
|
|
private static final String BEARER_TOKEN_HEADER = "AdWeb-Authorization";
|
|
|
private static final String STATIC_BEARER_TOKEN = "Bearer uxl9Wpzh65vXNUyDvynJDjBo";
|
|
|
|
|
|
- @Resource private CommonMapper commonMapper;
|
|
|
+ @Resource
|
|
|
+ private CommonMapper commonMapper;
|
|
|
|
|
|
- @Resource private IAdwebSiteService adwebSiteService;
|
|
|
+ @Resource
|
|
|
+ private IAdwebSiteService adwebSiteService;
|
|
|
|
|
|
- @Resource private IAdwebProductService adwebProductService;
|
|
|
+ @Resource
|
|
|
+ private IAdwebProductService adwebProductService;
|
|
|
|
|
|
- @Resource private IAdwebEnquiryService adwebEnquiryService;
|
|
|
+ @Resource
|
|
|
+ private IAdwebEnquiryService adwebEnquiryService;
|
|
|
|
|
|
- /** 外部api请求获取产品列表 */
|
|
|
+ /**
|
|
|
+ * 外部api请求获取产品列表
|
|
|
+ */
|
|
|
@IgnoreAuth
|
|
|
@PostMapping("/product/list")
|
|
|
@ResponseBody
|
|
@@ -68,33 +69,20 @@ public class OpenAPIController {
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(adwebSites)) {
|
|
|
QueryWrapper<AdwebProduct> adwebProductQueryWrapper = new QueryWrapper<>();
|
|
|
- adwebSiteQueryWrapper.eq("domain", adwebSites.get(0).getCode());
|
|
|
+ adwebSiteQueryWrapper.eq("site_code", adwebSites.get(0).getCode());
|
|
|
List<AdwebProduct> adwebProducts =
|
|
|
adwebProductService.getBaseMapper().selectList(adwebProductQueryWrapper);
|
|
|
// 根据AdwebProduct::getProductId去重,以AdwebProduct::getRequestTime排序
|
|
|
- adwebProducts =
|
|
|
- adwebProducts.stream()
|
|
|
- .collect(
|
|
|
- Collectors.toMap(
|
|
|
- AdwebProduct::getProductId,
|
|
|
- Function.identity(),
|
|
|
- (existing, replacement) ->
|
|
|
- existing.getRequestTime()
|
|
|
- .after(
|
|
|
- replacement
|
|
|
- .getRequestTime())
|
|
|
- ? existing
|
|
|
- : replacement))
|
|
|
- .values()
|
|
|
- .stream()
|
|
|
- .toList();
|
|
|
+
|
|
|
return Result.ok(adwebProducts.stream().map(ProductInfoVO::fromAdwebProduct).toList());
|
|
|
} else {
|
|
|
return Result.error("未找到该站点!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /** 外部api请求获取询盘列表 */
|
|
|
+ /**
|
|
|
+ * 外部api请求获取询盘列表
|
|
|
+ */
|
|
|
@IgnoreAuth
|
|
|
@PostMapping("/enquiry/list")
|
|
|
@ResponseBody
|
|
@@ -178,6 +166,43 @@ public class OpenAPIController {
|
|
|
return Result.ok(result);
|
|
|
}
|
|
|
|
|
|
+ @IgnoreAuth
|
|
|
+ @PostMapping("/enquiry/getMaxDate")
|
|
|
+ @ResponseBody
|
|
|
+ public Result<?> getEnquiryMaxDate(
|
|
|
+ @RequestHeader(value = BEARER_TOKEN_HEADER, required = true) String authToken,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ this.validateAuthToken(authToken);
|
|
|
+
|
|
|
+ String domain = request.getParameter("siteHost");
|
|
|
+ if (domain == null) {
|
|
|
+ return Result.error("未传递合法的参数!");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("EnquiryMaxDate request from domain: {}", domain);
|
|
|
+ // 获取站点
|
|
|
+ QueryWrapper<AdwebSite> adwebSiteQueryWrapper = new QueryWrapper<>();
|
|
|
+ adwebSiteQueryWrapper.like("domain", domain);
|
|
|
+ AdwebSite adwebsite = adwebSiteService.getOne(adwebSiteQueryWrapper);
|
|
|
+ if (adwebsite == null) {
|
|
|
+ return Result.error("该站点未绑定adweb3系统!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String filterSiteCode = "site_code='%s'".formatted(adwebsite.getCode());
|
|
|
+
|
|
|
+ Date maxDate = commonMapper.getMaxDate("adweb_enquiry", "record_ctime", filterSiteCode);
|
|
|
+ Long maxTime = null;
|
|
|
+ if (maxDate != null) {
|
|
|
+ maxTime = maxDate.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ result.put("maxTime", maxTime);
|
|
|
+
|
|
|
+ return Result.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
private boolean validateAuthToken(String authToken) {
|
|
|
if (!StringUtils.equals(STATIC_BEARER_TOKEN, authToken)) {
|
|
|
throw new InvalidBearerTokenException("Bearer toke is invalid: " + authToken);
|