Commit 247011f5 by 吴迪

【新增】修改查询接口

parent 008d6def
package io.office.modules.manage.controller;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.office.common.utils.IPUtils;
import io.office.common.utils.R;
import io.office.modules.app.annotation.Login;
......@@ -11,16 +13,24 @@ import io.office.modules.manage.utils.*;
import io.office.modules.manage.vo.request.DomesticCodeDetailRequest;
import io.office.modules.manage.vo.request.DomesticCodeVo;
import io.office.modules.manage.vo.request.GLNRequestBo;
import io.office.modules.manage.vo.response.DomesticCodeResponse;
import io.office.modules.manage.webservice.newWebservice.JaxbUtil;
import io.office.modules.manage.webservice.newWebservice.ProductInformationLink;
import io.office.modules.sys.service.SysCaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jdom.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
*
......@@ -124,12 +134,61 @@ public class GLNController {
searchgtinlogService.save(searchgtinlogEntity);
if(domesticCodeVo.getType().equals("1")) {
return R.ok().put("data", ESSearchUtils.getInfoByCode(searchgtinlogEntity.getKeyword()));
DomesticCodeResponse infoByCode = ESSearchUtils.getInfoByCode(searchgtinlogEntity.getKeyword());
if(infoByCode!=null) {
if(infoByCode.getHits()!=null) {
if(CollectionUtils.isNotEmpty(infoByCode.getHits().getHits())) {
List<DomesticCodeResponse.HitsBeanX.HitsBean> hits = infoByCode.getHits().getHits();
for (DomesticCodeResponse.HitsBeanX.HitsBean hit : hits) {
if(StringUtils.isNotBlank(hit.get_source().getFirm_name())) {
if(StringUtils.isNotBlank(IdCardUtils.getIdCard(hit.get_source().getFirm_name()))) {
hit.get_source().setFirm_name(hit.get_source().getFirm_name().replaceAll(IdCardUtils.getIdCard(hit.get_source().getFirm_name()),""));
}
}
}
}
}
}
return R.ok().put("data", infoByCode);
} else if(domesticCodeVo.getType().equals("2")){
return R.ok().put("data", ESSearchUtils.getInfoByName(searchgtinlogEntity.getKeyword()));
DomesticCodeResponse infoByCode = ESSearchUtils.getInfoByName(searchgtinlogEntity.getKeyword());
if(infoByCode!=null) {
if(infoByCode.getHits()!=null) {
if(CollectionUtils.isNotEmpty(infoByCode.getHits().getHits())) {
List<DomesticCodeResponse.HitsBeanX.HitsBean> hits = infoByCode.getHits().getHits();
for (DomesticCodeResponse.HitsBeanX.HitsBean hit : hits) {
if(StringUtils.isNotBlank(hit.get_source().getFirm_name())) {
if(StringUtils.isNotBlank(IdCardUtils.getIdCard(hit.get_source().getFirm_name()))) {
hit.get_source().setFirm_name(hit.get_source().getFirm_name().replaceAll(IdCardUtils.getIdCard(hit.get_source().getFirm_name()),""));
}
}
}
}
}
}
return R.ok().put("data", infoByCode);
} else if(domesticCodeVo.getType().equals("3")){
return R.ok().put("data", ESSearchUtils.getInfoByAddress(searchgtinlogEntity.getKeyword()));
DomesticCodeResponse infoByCode = ESSearchUtils.getInfoByAddress(searchgtinlogEntity.getKeyword());
if(infoByCode!=null) {
if(infoByCode.getHits()!=null) {
if(CollectionUtils.isNotEmpty(infoByCode.getHits().getHits())) {
List<DomesticCodeResponse.HitsBeanX.HitsBean> hits = infoByCode.getHits().getHits();
for (DomesticCodeResponse.HitsBeanX.HitsBean hit : hits) {
if(StringUtils.isNotBlank(hit.get_source().getFirm_name())) {
if(StringUtils.isNotBlank(IdCardUtils.getIdCard(hit.get_source().getFirm_name()))) {
hit.get_source().setFirm_name(hit.get_source().getFirm_name().replaceAll(IdCardUtils.getIdCard(hit.get_source().getFirm_name()),""));
}
}
}
}
}
}
return R.ok().put("data", infoByCode);
}
return R.error("参数不合法");
}
......@@ -162,5 +221,57 @@ public class GLNController {
}
/**
* 境内码查询接口
*/
@Login
@RequestMapping("/api/domesticCodeProductionNews")
public R domesticCodeProductionNews(@RequestBody DomesticCodeVo domesticCodeVo, HttpServletRequest request) {
SearchgtinlogEntity searchgtinlogEntity = new SearchgtinlogEntity();
searchgtinlogEntity.setCreatedate(new Date());
searchgtinlogEntity.setIp(IPUtils.getIpAddr(request));
searchgtinlogEntity.setClassStr("境内商品条码信息查询");
searchgtinlogEntity.setKeyword(domesticCodeVo.getCode());
searchgtinlogEntity.setSearchsource(0);
//新增查询日志
searchgtinlogService.save(searchgtinlogEntity);
String urlMac = "/AAQI/v1/ProductData/gtin/${code}?targetMarket=156&dataVersion=1.1&clientGln=6901234503814";
String macStr = MacUtils.getMac(urlMac.replaceAll("\\$\\{code\\}",domesticCodeVo.getCode()));
String url = "http://api.chinatrace.org/AAQI/v1/ProductData/gtin/${code}?targetMarket=156&dataVersion=1.1&clientGln=6901234503814&mac=";
url = url.replaceAll("\\$\\{code\\}",domesticCodeVo.getCode())+macStr;
System.out.println(url);
RestTemplate restTemplate = new RestTemplate();
//创建请求头
//创建请求头
ResponseEntity<String> responseEntity = null;
try {
responseEntity = restTemplate.getForEntity(url, String.class);
} catch (RestClientException e) {
e.printStackTrace();
if(e.getLocalizedMessage().equals("400 Bad Request")) {
return R.error("无效的境内商品条码!");
}
else if(e.getLocalizedMessage().equals("403 Bad Request")) {
return R.error("安全异常!");
}
}
if (responseEntity.getStatusCode().value() == 200) {
// 下面的是通过解析xml字符串的
String returnObjs = responseEntity.getBody().substring(responseEntity.getBody().indexOf("<productInformationLink>"),responseEntity.getBody().lastIndexOf("</productInformationLink>")+"</productInformationLink>".length());//注意 获取根节点的时候要查看返回的xml参数的形式是否为一个根节点
ProductInformationLink productInformationLink = JaxbUtil.converyToJavaBean(returnObjs, ProductInformationLink.class);
if(productInformationLink!=null)
{
if(StringUtils.isNotBlank(productInformationLink.getUrl())) {
return R.ok().put("data",productInformationLink.getUrl());
}
}
}
return R.error("查询失败!");
}
}
......@@ -23,7 +23,7 @@ public interface EanUpcDao extends BaseMapper<EanUpcEntity> {
List<EanUpcEntityVo> getEanUpcByCondition (@Param("eanUpcEntity")EanUpcEntity eanUpcEntity, Page page);
List<EanUpcEntityVo> getEanUpcTop();
List<EanUpcEntityVo> getEanUpcTop(@Param("eanUpcEntity")EanUpcEntity eanUpcEntity);
EanUpcEntityDetailVo getDetailById(@Param("eanUpcEntity")EanUpcEntity eanUpcEntity);
......
......@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.office.modules.manage.entity.PartnersEntity;
import io.office.modules.manage.vo.request.EanUpcEntityVo;
import io.office.modules.manage.vo.response.EanUpcEntityDetailVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
......@@ -41,7 +43,19 @@ public class EanUpcServiceImpl extends ServiceImpl<EanUpcDao, EanUpcEntity> impl
@Override
public List<EanUpcEntityVo> getEanUpcTop() {
return this.baseMapper.getEanUpcTop();
List<EanUpcEntityVo> eanUpcTopList = new ArrayList<>();
EanUpcEntity eanUpcEntity = new EanUpcEntity();
eanUpcEntity.setLogoutFlag("0");
List<EanUpcEntityVo> eanUpcTop = this.baseMapper.getEanUpcTop(eanUpcEntity);
if(CollectionUtils.isNotEmpty(eanUpcTop)) {
eanUpcTopList.addAll(eanUpcTop);
}
eanUpcEntity.setLogoutFlag("1");
List<EanUpcEntityVo> eanUpcTop1 = this.baseMapper.getEanUpcTop(eanUpcEntity);
if(CollectionUtils.isNotEmpty(eanUpcTop1)) {
eanUpcTopList.addAll(eanUpcTop1);
}
return eanUpcTopList;
}
@Override
......
......@@ -284,6 +284,7 @@ public class TransferController {
for (PartnersEntity partnersEntity : pageData.getRecords()) {
//如果不为空
if (StringUtils.isNotBlank(partnersEntity.getPic())) {
if (partnersEntity.getPic().startsWith("http://www.gs1cn.org")) {//官网的链接
partnersEntity.setPic(partnersEntity.getPic().replaceAll("http://www.gs1cn.org", domainListProperties.getDomain()));
}
......@@ -293,6 +294,7 @@ public class TransferController {
if (partnersEntity.getPic().startsWith("http://81.68.189.225:8080")) {//官网的链接
partnersEntity.setPic(partnersEntity.getPic().replaceAll("http://81.68.189.225:8080", fileRequestPrefix));
}
partnersEntity.setPic(fileRequestPrefix +"Service/Partners/img/"+partnersEntity.getPic());
//修改
UpdateWrapper<PartnersEntity> updateWrapper = new UpdateWrapper();
updateWrapper.eq("id", partnersEntity.getId());
......
......@@ -52,7 +52,7 @@ public class ESSearchUtils {
"\t\t}\n" +
"\t},\n" +
"\t\"from\": 0,\n" +
"\t\"size\": 10,\n" +
"\t\"size\": 100,\n" +
"\t\"sort\": [],\n" +
"\t\"aggs\": {}\n" +
"}";
......@@ -63,10 +63,8 @@ public class ESSearchUtils {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(ES_URL, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
System.out.println(responseEntity.getBody());
return JSONUtil.toBean(responseEntity.getBody(), DomesticCodeResponse.class);
}
return null;
......@@ -104,7 +102,7 @@ public class ESSearchUtils {
"\t\t}\n" +
"\t},\n" +
"\t\"from\": 0,\n" +
"\t\"size\": 10,\n" +
"\t\"size\": 100,\n" +
"\t\"sort\": [],\n" +
"\t\"aggs\": {}\n" +
"}";
......@@ -115,10 +113,10 @@ public class ESSearchUtils {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(ES_URL, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
System.out.println(responseEntity.getBody());
return JSONUtil.toBean(responseEntity.getBody(), DomesticCodeResponse.class);
}
return null;
......@@ -157,7 +155,7 @@ public class ESSearchUtils {
"\t\t}\n" +
"\t},\n" +
"\t\"from\": 0,\n" +
"\t\"size\": 10,\n" +
"\t\"size\": 100,\n" +
"\t\"sort\": [],\n" +
"\t\"aggs\": {}\n" +
"}";
......@@ -168,10 +166,8 @@ public class ESSearchUtils {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(ES_URL, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
System.out.println(responseEntity.getBody());
return JSONUtil.toBean(responseEntity.getBody(), DomesticCodeResponse.class);
}
return null;
......
package io.office.modules.manage.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* 
 @description:
......@@ -9,16 +12,35 @@ package io.office.modules.manage.utils;
*/
public class IdCardUtils {
public static boolean isIDNumber(String IDNumber) {
if (IDNumber == null || "".equals(IDNumber)) {
return false;
}
// 定义判别用户身份证号的正则表达式(15位或者18位,最后一位可以为字母)
String regularExpression = "^\\d{17}(\\d|x|X)$";
boolean matches = IDNumber.matches(regularExpression);
return matches;
/**
* 提取文字中的身份证信息
* @param content
* @return
*/
public static String getIdCard(String content) {
String regex ="([1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3})";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
if(m.find()){
return m.group();
}
return null;
}
public static void main(String[] args) {
String content = "汕头市潮南区峡山街道董塘金光路289、291号首层92440514MA51EBUH3K(林钦遂440524195503195499)";
String regex ="([1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx])|([1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3})";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
if(m.find()){
System.out.println("m "+m.group());
}
}
}
package io.office.modules.manage.utils;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
*
* 
 @description:
*
* @author wudi
* @date 17:34 2022/1/5
*/
public class MacUtils {
public static String getMac( String data){
Mac m;
byte[] secretByte;
SecretKey macKey ;
String resultMac = "";
byte[] digest;
try {
m = Mac.getInstance("HmacSHA256");
secretByte = DatatypeConverter.parseBase64Binary("FyFjqPowXyD57yHBny/RsacE7Ldw4uxWu4MyxwIj2rc=");
byte[] dataBytes = data.getBytes("ASCII");
macKey = new SecretKeySpec(secretByte, "HMACSHA256");
m.init(macKey);
digest = m.doFinal(dataBytes);
resultMac = toHex(digest);
resultMac = resultMac.toUpperCase();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
e.printStackTrace();
}
return resultMac;
}
/*
* change byte to 16
*/
public static String toHex(byte[] buffer) {
StringBuffer sb = new StringBuffer(buffer.length * 2);
StringBuffer s = new StringBuffer(buffer.length);
for (int i = 0; i < buffer.length; i++) {
sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16));
sb.append(Character.forDigit(buffer[i] & 15, 16));
s.append(buffer[i]);
}
return sb.toString();
}
public static void main(String[] args) {
System.out.println(getMac("/AAQI/v1/ProductData/gtin/6920582200169?targetMarket=156&dataVersion=1.1&clientGln=6901234503814"));
}
}
......@@ -315,12 +315,6 @@ public class DomesticCodeResponse implements Serializable {
public String getFirm_name() {
if(firm_name.length()>19) {
String firmNameNew = firm_name.substring(19);
if(IdCardUtils.isIDNumber(firmNameNew)) {
return firm_name.substring(0,firm_name.length()-19);
}
}
return firm_name;
}
......
package io.office.modules.manage.webservice.newWebservice;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
import java.io.StringWriter;
/**
*
* 
 @description:
*
* @author wudi
* @date 13:02 2022/1/6
*/
public class JaxbUtil {
/**
* JavaBean转换成xml
* 默认编码UTF-8
* @param obj
* @param
* @return
*/
public static String convertToXml(Object obj) {
return convertToXml(obj, "UTF-8");
}
/**
* JavaBean转换成xml
* @param obj
* @param encoding
* @return
*/
public static String convertToXml(Object obj, String encoding) {
String result = null;
try {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
StringWriter writer = new StringWriter();
marshaller.marshal(obj, writer);
result = writer.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* xml转换成JavaBean
* @param xml
* @param c
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T converyToJavaBean(String xml, Class<T> c) {
T t = null;
try {
JAXBContext context = JAXBContext.newInstance(c);
Unmarshaller unmarshaller = context.createUnmarshaller();
t = (T) unmarshaller.unmarshal(new StringReader(xml));
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
}
package io.office.modules.manage.webservice.newWebservice;
import lombok.Data;
import javax.xml.bind.annotation.*;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:50 2022/1/6
*/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@XmlType(name = "book", propOrder = { "url"})
public class ProductInformationLink {
@XmlElement
private String url;
}
package io.office.modules.manage.webservice.newWebservice;
/**
*
* 
 @description:
*
* @author wudi
* @date 11:56 2022/1/6
*/
public class TSDBasicProductInformationModuleType {
}
package io.office.modules.manage.webservice.newWebservice;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*
* 
 @description:
*
* @author wudi
* @date 13:00 2022/1/6
*/@Data
@XmlAccessorType(XmlAccessType.FIELD)
public class Url {
private String url;
}
......@@ -44,7 +44,7 @@
</select>
<select id="getEanUpcTop" resultType="io.office.modules.manage.vo.request.EanUpcEntityVo">
SELECT top 4
SELECT top 2
b.logout_flag AS logout_flag,
a.firm_name,
b.f_id,
......@@ -60,6 +60,7 @@
OR b.code = '69507917'
)
AND b.code &lt;&gt; '69305132'
AND logout_flag = #{eanUpcEntity.logoutFlag}
AND type_name IN (
'系统成员注册',
'厂商识别代码注销'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment