|
|
@ -1,23 +1,34 @@ |
|
|
package com.zdxt.enforcementcode.controller.app.enforcement; |
|
|
package com.zdxt.enforcementcode.controller.app.enforcement; |
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore; |
|
|
import cn.dev33.satoken.annotation.SaIgnore; |
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
|
import com.zdxt.enforcementcode.common.util.CrawlerUtil; |
|
|
import com.zdxt.enforcementcode.domain.EnterpriseInformation; |
|
|
import com.zdxt.enforcementcode.domain.EnterpriseInformation; |
|
|
import com.zdxt.enforcementcode.domain.bo.EnterpriseInformationBo; |
|
|
import com.zdxt.enforcementcode.domain.bo.EnterpriseInformationBo; |
|
|
import com.zdxt.enforcementcode.domain.vo.EnterpriseInformationVo; |
|
|
import com.zdxt.enforcementcode.domain.vo.EnterpriseInformationVo; |
|
|
import com.zdxt.enforcementcode.domain.vo.QrCodeGenerateHistoryVo; |
|
|
import com.zdxt.enforcementcode.domain.vo.QrCodeGenerateHistoryVo; |
|
|
import com.zdxt.enforcementcode.service.IEnterpriseInformationService; |
|
|
import com.zdxt.enforcementcode.service.IEnterpriseInformationService; |
|
|
import com.zdxt.enforcementcode.service.IQrCodeGenerateHistoryService; |
|
|
import com.zdxt.enforcementcode.service.IQrCodeGenerateHistoryService; |
|
|
|
|
|
import com.zdxt.enforcementcode.service.ISsztJbxx110497NewService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.dromara.common.core.domain.R; |
|
|
import org.dromara.common.core.domain.R; |
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
import org.dromara.common.mybatis.core.page.PageQuery; |
|
|
import org.dromara.common.mybatis.core.page.PageQuery; |
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.net.URL; |
|
|
|
|
|
import java.net.URLConnection; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@ -32,6 +43,7 @@ public class AppEnfEnterpriseInformationController { |
|
|
|
|
|
|
|
|
private final IEnterpriseInformationService enterpriseInformationService; |
|
|
private final IEnterpriseInformationService enterpriseInformationService; |
|
|
private final IQrCodeGenerateHistoryService qrCodeGenerateHistoryService; |
|
|
private final IQrCodeGenerateHistoryService qrCodeGenerateHistoryService; |
|
|
|
|
|
private final ISsztJbxx110497NewService iSsztJbxx110497NewService; |
|
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -51,6 +63,56 @@ public class AppEnfEnterpriseInformationController { |
|
|
public R<EnterpriseInformationVo> getEntInfoByQRCode(@RequestParam("qrContent") String qrContent) { |
|
|
public R<EnterpriseInformationVo> getEntInfoByQRCode(@RequestParam("qrContent") String qrContent) { |
|
|
log.info("执法端扫码获取企业信息,二维码内容: {}", qrContent); |
|
|
log.info("执法端扫码获取企业信息,二维码内容: {}", qrContent); |
|
|
|
|
|
|
|
|
|
|
|
// 按二维码原文分流:http/https 开头为市监公示 URL,否则为本系统 JSON
|
|
|
|
|
|
if (StrUtil.startWith(qrContent, "http://") || StrUtil.startWith(qrContent, "https://")) { |
|
|
|
|
|
//解析路由获取企业统一信用代码
|
|
|
|
|
|
String cid = null; |
|
|
|
|
|
try { |
|
|
|
|
|
cid = getUrlParams(qrContent, "cid"); |
|
|
|
|
|
if(StringUtils.isNotEmpty(cid)) { |
|
|
|
|
|
//初始化对象
|
|
|
|
|
|
EnterpriseInformationVo enterpriseVo = null; |
|
|
|
|
|
//查询企业表中是否存在企业信息
|
|
|
|
|
|
enterpriseVo = enterpriseInformationService.queryByEnterpriseNumber(cid); |
|
|
|
|
|
log.warn("企业信息表中查询企业信息,企业:{}", JSONObject.toJSONString(enterpriseVo)); |
|
|
|
|
|
|
|
|
|
|
|
//判断企业信息为空
|
|
|
|
|
|
if(BeanUtil.isEmpty(enterpriseVo)){ |
|
|
|
|
|
enterpriseVo = iSsztJbxx110497NewService.queryByTyshxydmOne(cid); |
|
|
|
|
|
if(BeanUtil.isNotEmpty(enterpriseVo) && |
|
|
|
|
|
StringUtils.isNotEmpty(enterpriseVo.getEnterpriseNumber())){ |
|
|
|
|
|
//默认ID
|
|
|
|
|
|
enterpriseVo.setId(IdUtil.simpleUUID()); |
|
|
|
|
|
//企业表中新增
|
|
|
|
|
|
EnterpriseInformation enterprise = new EnterpriseInformation(); |
|
|
|
|
|
BeanUtils.copyProperties(enterpriseVo, enterprise); |
|
|
|
|
|
int i = enterpriseInformationService.insertEnterpriseInformation(enterprise); |
|
|
|
|
|
if(i > 0){ |
|
|
|
|
|
log.info("企业信息表中新增成功,新增企业:{}", JSONObject.toJSONString(enterpriseVo)); |
|
|
|
|
|
}else{ |
|
|
|
|
|
log.info("企业信息表中新增失败,失败企业:{}", JSONObject.toJSONString(enterpriseVo)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return R.ok(enterpriseVo); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("企业营业执照二维码中不存在企业统一信用代码,访问地址:{}",qrContent); |
|
|
|
|
|
//爬取页面统一信用代码
|
|
|
|
|
|
String s = CrawlerUtil.getCreditCode(qrContent); |
|
|
|
|
|
if (StringUtils.isNotEmpty(s)) { |
|
|
|
|
|
EnterpriseInformationVo enterpriseVo = iSsztJbxx110497NewService.queryByTyshxydmOne(s); |
|
|
|
|
|
return R.ok(enterpriseVo); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("营业执照解析错误: {}", cid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("企业信息表中查询企业信息,统一信用代码:{}", cid); |
|
|
|
|
|
log.info("识别为市监公示系统二维码,后续解析待补充,原始内容: {}", qrContent); |
|
|
|
|
|
return R.fail("无法通过该二维码识别企业信息"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 1. 判断 qrContent 是否为 JSON,是则转为 Map,否则打印日志
|
|
|
// 1. 判断 qrContent 是否为 JSON,是则转为 Map,否则打印日志
|
|
|
Map<String, String> qrMap = null; |
|
|
Map<String, String> qrMap = null; |
|
|
try { |
|
|
try { |
|
|
@ -211,4 +273,39 @@ public class AppEnfEnterpriseInformationController { |
|
|
log.info("执法端查询企业信息详情成功,企业: {}", enterprise.getEnterpriseName()); |
|
|
log.info("执法端查询企业信息详情成功,企业: {}", enterprise.getEnterpriseName()); |
|
|
return R.ok(enterprise); |
|
|
return R.ok(enterprise); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getUrlParams(String urlStr,String paramKey) throws IOException { |
|
|
|
|
|
URL url = new URL(urlStr); |
|
|
|
|
|
URLConnection connection = url.openConnection(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取查询字符串,即URL中"?"后面的部分
|
|
|
|
|
|
String query = url.getQuery(); |
|
|
|
|
|
|
|
|
|
|
|
// 将查询字符串拆分为键值对
|
|
|
|
|
|
Map<String, String> queryParams = new HashMap<>(); |
|
|
|
|
|
if (query != null) { |
|
|
|
|
|
String split_flag = "&"; |
|
|
|
|
|
if (query.indexOf("&") < 0) { |
|
|
|
|
|
if (query.indexOf("&") < 0) { |
|
|
|
|
|
split_flag = "%26"; |
|
|
|
|
|
} else { |
|
|
|
|
|
split_flag = "&"; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
split_flag = "&"; |
|
|
|
|
|
} |
|
|
|
|
|
// String split_flag = query.indexOf("&") < 0 ?"%26":"&"; // 有些链接的 & 会被转义成 %26
|
|
|
|
|
|
String[] pairs = query.split(split_flag); |
|
|
|
|
|
for (String pair : pairs) { |
|
|
|
|
|
int idx = pair.indexOf("="); |
|
|
|
|
|
String key = pair.substring(0, idx); |
|
|
|
|
|
String value = pair.substring(idx + 1); |
|
|
|
|
|
queryParams.put(key, value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// 输出参数
|
|
|
|
|
|
queryParams.forEach((k, v) -> System.out.println(k + " = " + v)); |
|
|
|
|
|
return queryParams.get(paramKey); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|