|
|
@@ -14,12 +14,12 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.geo.Point;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
import shop.alien.entity.store.*;
|
|
|
@@ -40,10 +40,12 @@ import shop.alien.store.service.*;
|
|
|
import shop.alien.store.util.CommonConstant;
|
|
|
import shop.alien.store.util.FileUploadUtil;
|
|
|
import shop.alien.store.util.GroupConstant;
|
|
|
+import shop.alien.store.util.ai.AiAuthTokenUtil;
|
|
|
import shop.alien.util.ali.AliOSSUtil;
|
|
|
import shop.alien.util.common.DistanceUtil;
|
|
|
import shop.alien.util.common.constant.CouponStatusEnum;
|
|
|
import shop.alien.util.common.constant.CouponTypeEnum;
|
|
|
+import shop.alien.util.common.constant.OcrTypeEnum;
|
|
|
import shop.alien.util.common.constant.OrderStatusEnum;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
@@ -137,6 +139,12 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
|
|
|
private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
|
|
|
+ private final OcrImageUploadMapper ocrImageUploadMapper;
|
|
|
+
|
|
|
+ private final AiAuthTokenUtil aiAuthTokenUtil;
|
|
|
+
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
+
|
|
|
/** 商户证照历史记录数据访问对象 */
|
|
|
private final StoreLicenseHistoryMapper licenseHistoryMapper;
|
|
|
|
|
|
@@ -150,6 +158,12 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
@Value("${spring.web.resources.excel-generate-path}")
|
|
|
private String excelGeneratePath;
|
|
|
|
|
|
+ @Value("${third-party-identification.base-url}")
|
|
|
+ private String identificationPath;
|
|
|
+
|
|
|
+ @Value("${third-party-applications.base-url}")
|
|
|
+ private String applicationsPath;
|
|
|
+
|
|
|
/**
|
|
|
* 懒得查, 留着导出Excel
|
|
|
*/
|
|
|
@@ -2389,5 +2403,101 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void aiApproveStoreInfo(AiApproveStoreInfo aiApproveStoreInfo) {
|
|
|
+ HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
+ aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ aiHeaders.set("Authorization", "Bearer " + aiAuthTokenUtil.getAccessToken());
|
|
|
+
|
|
|
+ HttpEntity<AiApproveStoreInfo> request = new HttpEntity<>(aiApproveStoreInfo, aiHeaders);
|
|
|
+ ResponseEntity<String> response = null;
|
|
|
+ try {
|
|
|
+ response = restTemplate.postForEntity(applicationsPath, request, String.class);
|
|
|
+ if (response.getStatusCodeValue() != 200) {
|
|
|
+ throw new RuntimeException("AI门店审核接口调用失败 http状态:" + response.getStatusCode());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(response.getBody())) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response.getBody());
|
|
|
+ if (jsonObject.getInteger("code") == 200) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ List<StoreInfo> storeInfos = storeInfoMapper.selectList(new LambdaQueryWrapper<StoreInfo>()
|
|
|
+ .eq(StoreInfo::getCreatedUserId, aiApproveStoreInfo.getUserId()).eq(StoreInfo::getStoreApplicationStatus, 0).eq(StoreInfo::getDeleteFlag, 0));
|
|
|
+ for (StoreInfo storeInfo : storeInfos) {
|
|
|
+ if ("approved".equals(data.getString("status"))) {
|
|
|
+ storeInfo.setStoreApplicationStatus(1);
|
|
|
+ } else if ("rejected".equals(data.getString("status"))) {
|
|
|
+ storeInfo.setStoreApplicationStatus(2);
|
|
|
+ } else {
|
|
|
+ System.out.println("未知状态");
|
|
|
+ }
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("AI门店审核接口调用失败 code:" + jsonObject.getInteger("code"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e){
|
|
|
+ throw new RuntimeException("调用门店审核接口异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getStoreOcrData(String storeUserId, String imageUrl) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ LambdaQueryWrapper<OcrImageUpload> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(OcrImageUpload::getStoreUserId, storeUserId)
|
|
|
+ .eq(OcrImageUpload::getOcrType, OcrTypeEnum.BUSINESS_LICENSE.getCode());
|
|
|
+ OcrImageUpload ocrImageUploads = ocrImageUploadMapper.selectOne(queryWrapper);
|
|
|
+ if(ocrImageUploads== null){
|
|
|
+ throw new RuntimeException("未找到OCI识别数据!");
|
|
|
+ }
|
|
|
+ String accessToken = aiAuthTokenUtil.getAccessToken();
|
|
|
+
|
|
|
+ HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
+ aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ aiHeaders.set("Authorization", "Bearer " + accessToken);
|
|
|
+ Map<String, Object> jsonBody = new HashMap<>();
|
|
|
+ List<String> imageUrls = new ArrayList<>();
|
|
|
+ imageUrls.add(imageUrl);
|
|
|
+ jsonBody.put("image_urls", imageUrls);
|
|
|
+ String ocrResult = ocrImageUploads.getOcrResult();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(ocrResult);
|
|
|
+ jsonBody.put("merchant_name", jsonObject.get("companyName"));
|
|
|
+
|
|
|
+ HttpEntity<Map<String, Object>> request = new HttpEntity<>(jsonBody, aiHeaders);
|
|
|
+ ResponseEntity<String> response = null;
|
|
|
+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
|
|
|
+ factory.setConnectTimeout(5000);
|
|
|
+ factory.setReadTimeout(60000);
|
|
|
+ restTemplate.setRequestFactory(factory);
|
|
|
+ try {
|
|
|
+ response = restTemplate.postForEntity(identificationPath, request, String.class);
|
|
|
+ if (response.getStatusCodeValue() != 200) {
|
|
|
+ throw new RuntimeException("AI内容审核接口调用失败 http状态:" + response.getStatusCode());
|
|
|
+ }
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("AI接口调用失败");
|
|
|
+ }
|
|
|
+ com.alibaba.fastjson2.JSONObject responseNode = com.alibaba.fastjson2.JSONObject.parseObject(response.getBody());
|
|
|
+ if (responseNode == null) {
|
|
|
+ throw new RuntimeException("AI接口调用失败,响应内容为空");
|
|
|
+ } else {
|
|
|
+ Integer code = responseNode.getInteger("code");
|
|
|
+ if (code == 200) {
|
|
|
+ Map<String, Object> dataMap = (Map<String, Object>) responseNode.get("data");
|
|
|
+ if (Objects.nonNull(dataMap)) {
|
|
|
+ // 获取match_results(JSON中是数组,反序列化为List<Map>)
|
|
|
+ List<Map<String, Object>> matchResults = (List<Map<String, Object>>) dataMap.get("match_results");
|
|
|
+ map.put("overall_match", dataMap.get("overall_match"));
|
|
|
+ if (Objects.nonNull(matchResults) && !matchResults.isEmpty()) {
|
|
|
+ map.put("match_reason", matchResults.get(0).get("match_reason"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("AI接口调用失败,错误码: " + code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|