|
|
@@ -0,0 +1,251 @@
|
|
|
+package shop.alien.storeplatform.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import shop.alien.entity.result.R;
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.StoreInfo;
|
|
|
+import shop.alien.entity.store.WebAudit;
|
|
|
+import shop.alien.entity.store.dto.StoreInfoDto;
|
|
|
+import shop.alien.entity.storePlatform.StoreLicenseHistory;
|
|
|
+import shop.alien.mapper.*;
|
|
|
+import shop.alien.mapper.storePlantform.StoreLicenseHistoryMapper;
|
|
|
+import shop.alien.storeplatform.service.StoreBusinessService;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Lhaibo
|
|
|
+ * @date 2025/11/28
|
|
|
+ * @desc: xxl-job
|
|
|
+ * AI调用审核任务
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class LicenseImgValidate {
|
|
|
+
|
|
|
+ // 添加RestTemplate用于HTTP调用
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
+
|
|
|
+ // 第三方接口地址 登录接口URL
|
|
|
+ @Value("${third-party-login.base-url}")
|
|
|
+ private String loginUrl;
|
|
|
+
|
|
|
+ //用户名
|
|
|
+ @Value("${third-party-user-name.base-url}")
|
|
|
+ private String userName;
|
|
|
+
|
|
|
+ //密码
|
|
|
+ @Value("${third-party-pass-word.base-url}")
|
|
|
+ private String passWord;
|
|
|
+
|
|
|
+ // 第三方接口地址 登录接口URL
|
|
|
+ @Value("${third-party-license-expiry.base-url}")
|
|
|
+ private String licenseImgUrl;
|
|
|
+
|
|
|
+
|
|
|
+ private final StoreBusinessService storeBusinessService;
|
|
|
+
|
|
|
+ private final WebAuditMapper webAuditMapper;
|
|
|
+
|
|
|
+ /** 商户证照历史记录数据访问对象 */
|
|
|
+ private final StoreLicenseHistoryMapper licenseHistoryMapper;
|
|
|
+
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * AI自动审核任务处理器
|
|
|
+ * <p>
|
|
|
+ * 定时任务方法,用于批量处理用户违规举报记录,通过AI接口进行自动审核。
|
|
|
+ * 主要流程:
|
|
|
+ * 1. 查询所有待处理的用户违规记录
|
|
|
+ * 2. 遍历每条记录,组装审核请求数据
|
|
|
+ * 3. 调用AI审核接口进行自动审核(当前代码中已准备请求体,待实现接口调用)
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Lhaibo
|
|
|
+ * @date 2025/11/28
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+ public void aiCheckLicenseImg(String imgUrl, Integer storeId, int status, Integer id) {
|
|
|
+ log.info("开始执行AI自动审核任务");
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("登录Ai服务获取token..." + loginUrl);
|
|
|
+ //构建请求参数
|
|
|
+ MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
|
|
+ formData.add("username", userName); // 表单字段 1:用户名
|
|
|
+ formData.add("password", passWord); // 表单字段 2:密码
|
|
|
+
|
|
|
+ //设置请求头
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
|
|
|
+ ResponseEntity<String> postForEntity = null;
|
|
|
+ try {
|
|
|
+ postForEntity = restTemplate.postForEntity(loginUrl, requestEntity, String.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("类:PostMethod 方法:post", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (postForEntity != null) {
|
|
|
+ if (postForEntity.getStatusCodeValue() == 200) {
|
|
|
+ log.info("请求Ai服务登录成功 postForEntity.getBody()\t" + postForEntity.getBody());
|
|
|
+ String responseBody = postForEntity.getBody();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
|
|
+ JSONObject dataJson = jsonObject.getJSONObject("data");
|
|
|
+ String accessToken = dataJson.getString("access_token");
|
|
|
+
|
|
|
+ // 初始化请求体Map
|
|
|
+ Map<String, Object> requestBody = new HashMap<>();
|
|
|
+
|
|
|
+ // 设置投诉记录ID
|
|
|
+ requestBody.put("image_url", imgUrl);
|
|
|
+
|
|
|
+ HttpHeaders aiHeaders = new HttpHeaders();
|
|
|
+ aiHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ aiHeaders.set("Authorization", "Bearer " + accessToken);
|
|
|
+
|
|
|
+ System.out.println(requestBody);
|
|
|
+ HttpEntity<Map<String, Object>> request = new HttpEntity<>(requestBody, aiHeaders);
|
|
|
+ ResponseEntity<String> response = null;
|
|
|
+ try {
|
|
|
+ response = restTemplate.postForEntity(licenseImgUrl, request, String.class);
|
|
|
+ log.info("AI自动审核结果:{}", response.getBody());
|
|
|
+ String licenseResponseBody = response.getBody();
|
|
|
+ JSONObject licenseJsonObject = JSONObject.parseObject(licenseResponseBody);
|
|
|
+ JSONObject licenseDataJson = licenseJsonObject.getJSONObject("data");
|
|
|
+ boolean isValid = licenseDataJson.getBoolean("is_valid");
|
|
|
+ String reason = licenseDataJson.getString("reason");
|
|
|
+
|
|
|
+ if (status == 3 || status == 2) {
|
|
|
+ StoreInfoDto storeInfoDto = new StoreInfoDto();
|
|
|
+ storeInfoDto.setFoodLicenceReason(reason);
|
|
|
+ storeInfoDto.setFoodLicenceStatus(isValid ? 1 : 3);
|
|
|
+ storeInfoDto.setId(storeId);
|
|
|
+ updatefoodLicenceImageStatus(storeInfoDto, status, id);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("AI自动审核请求异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("AI自动审核任务执行异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("AI自动审核任务执行完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public R<String> updatefoodLicenceImageStatus(StoreInfoDto storeInfoDto, int status, Integer id) {
|
|
|
+ log.info("StoreInfoController.updatefoodLicenceImageStatus?storeInfoDto={}", storeInfoDto);
|
|
|
+ StoreInfo storeInfo = storeBusinessService.getOne(new LambdaQueryWrapper<StoreInfo>().eq(StoreInfo::getId, storeInfoDto.getId()));
|
|
|
+ if (storeInfo != null) {
|
|
|
+ if (storeInfoDto.getFoodLicenceStatus() == 3) {
|
|
|
+ storeInfo.setFoodLicenceReason(storeInfoDto.getFoodLicenceReason());
|
|
|
+ storeInfo.setFoodLicenceStatus(storeInfoDto.getFoodLicenceStatus());
|
|
|
+ boolean flag = storeBusinessService.updateById(storeInfo);
|
|
|
+ if (flag) {
|
|
|
+ // 审核拒绝时修改提交记录
|
|
|
+ LambdaUpdateWrapper<StoreLicenseHistory> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(StoreLicenseHistory::getStoreId, storeInfo.getId());
|
|
|
+ wrapper.eq(StoreLicenseHistory::getId, id);
|
|
|
+ wrapper.eq(StoreLicenseHistory::getLicenseStatus, status);
|
|
|
+ wrapper.set(StoreLicenseHistory::getLicenseExecuteStatus, 3);
|
|
|
+ wrapper.set(StoreLicenseHistory::getDeleteFlag, 1);
|
|
|
+ wrapper.set(StoreLicenseHistory::getReasonRefusal, storeInfoDto.getFoodLicenceReason());
|
|
|
+ licenseHistoryMapper.update(null, wrapper);
|
|
|
+
|
|
|
+ //待审核状态变为已审核
|
|
|
+ WebAudit webAudit = webAuditMapper.selectOne(new LambdaQueryWrapper<WebAudit>().eq(WebAudit::getStoreInfoId, storeInfo.getId()).eq(WebAudit::getDeleteFlag, 0).eq(WebAudit::getType, "7"));
|
|
|
+ if (webAudit != null) {
|
|
|
+ webAudit.setStatus("1");
|
|
|
+ webAuditMapper.updateById(webAudit);
|
|
|
+ }
|
|
|
+ return R.success("拒绝审核成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("拒绝审核失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (status == 2) {
|
|
|
+ storeInfo.setFoodLicenceReason(storeInfoDto.getFoodLicenceReason());
|
|
|
+ storeInfo.setFoodLicenceStatus(storeInfoDto.getFoodLicenceStatus());
|
|
|
+ } else {
|
|
|
+ storeInfo.setEntertainmentLicenceStatus(storeInfoDto.getFoodLicenceStatus());
|
|
|
+ storeInfo.setEntertainmentLicenceReason(storeInfoDto.getFoodLicenceReason());
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = storeBusinessService.updateById(storeInfo);
|
|
|
+ if (flag) {
|
|
|
+ int num = foodLicenceType(storeInfoDto.getId(), status);
|
|
|
+ if (num > 0) {
|
|
|
+ //待审核状态变为已审核
|
|
|
+ WebAudit webAudit = webAuditMapper.selectOne(new LambdaQueryWrapper<WebAudit>().eq(WebAudit::getStoreInfoId, storeInfo.getId()).eq(WebAudit::getDeleteFlag, 0).eq(WebAudit::getType, "7"));
|
|
|
+ if (webAudit != null) {
|
|
|
+ webAudit.setStatus("1");
|
|
|
+ webAuditMapper.updateById(webAudit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("审核通过成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("审核失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("审核失败 店铺不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ public int foodLicenceType(int id, int status) {
|
|
|
+ //删除原合同照片
|
|
|
+ LambdaUpdateWrapper<StoreImg> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.eq(StoreImg::getStoreId, id);
|
|
|
+ if (status == 2) {
|
|
|
+ lambdaUpdateWrapper.eq(StoreImg::getImgType, 25);
|
|
|
+ } else {
|
|
|
+ lambdaUpdateWrapper.eq(StoreImg::getImgType, 31);
|
|
|
+ }
|
|
|
+ lambdaUpdateWrapper.set(StoreImg::getDeleteFlag,1);
|
|
|
+ storeImgMapper.update(null,lambdaUpdateWrapper);
|
|
|
+ //修改续签合同类型为合同类型
|
|
|
+ List<StoreImg> storeImgList = storeImgMapper.selectList(new LambdaQueryWrapper<StoreImg>().eq(StoreImg::getStoreId, id).eq(StoreImg::getImgType, 24));
|
|
|
+ List<Integer> imgList = storeImgList.stream().map(StoreImg::getId).collect(Collectors.toList());
|
|
|
+ LambdaUpdateWrapper<StoreImg> imgLambdaUpdateWrapper = new LambdaUpdateWrapper();
|
|
|
+ imgLambdaUpdateWrapper.in(StoreImg::getId, imgList).set(StoreImg::getImgType, 25).set(StoreImg::getImgDescription,"经营许可证审核通过图片");
|
|
|
+ int num = storeImgMapper.update(null, imgLambdaUpdateWrapper);
|
|
|
+
|
|
|
+ // 将原来的食品经营许可证历史表数据删除
|
|
|
+ licenseHistoryMapper.delete(new LambdaQueryWrapper<StoreLicenseHistory>()
|
|
|
+ .eq(StoreLicenseHistory::getStoreId,id)
|
|
|
+ .eq(StoreLicenseHistory::getLicenseStatus,status)
|
|
|
+ .eq(StoreLicenseHistory::getLicenseExecuteStatus,1)
|
|
|
+ .eq(StoreLicenseHistory::getDeleteFlag,0));
|
|
|
+
|
|
|
+ // 将新的食品经营许可证历史表数据变为审核通过
|
|
|
+ LambdaUpdateWrapper<StoreLicenseHistory> wrapper1 = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper1.eq(StoreLicenseHistory::getStoreId, id);
|
|
|
+ wrapper1.eq(StoreLicenseHistory::getLicenseStatus, status);
|
|
|
+ wrapper1.eq(StoreLicenseHistory::getLicenseExecuteStatus, 2);
|
|
|
+ wrapper1.eq(StoreLicenseHistory::getDeleteFlag, 0);
|
|
|
+ wrapper1.set(StoreLicenseHistory::getLicenseExecuteStatus, 1);
|
|
|
+ licenseHistoryMapper.update(null, wrapper1);
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+}
|