Commit ccb6cf8f by 吴迪

【新增】GLN、GTIN接口修改

parent 1d157555
......@@ -43,24 +43,41 @@ public class GLNController {
@Login
@PostMapping("/api/gln")
public R uploadFile(@RequestBody GLNRequestBo glnRequestBo, HttpServletRequest request) {
boolean captcha = sysCaptchaService.validate(glnRequestBo.getUuid(), glnRequestBo.getCaptcha());
/* boolean captcha = sysCaptchaService.validate(glnRequestBo.getUuid(), glnRequestBo.getCaptcha());
if(!captcha){
return R.error("验证码不正确");
}
}*/
SearchgtinlogEntity searchgtinlogEntity = new SearchgtinlogEntity();
searchgtinlogEntity.setCreatedate(new Date());
searchgtinlogEntity.setIp(IPUtils.getIpAddr(request));
if(glnRequestBo.getType().equals("GLN")) {
if(glnRequestBo.getCode().length()!=13) {
return R.error("请输入13位GLN!");
}
// glnRequestBo.setCode("0"+glnRequestBo.getCode());
searchgtinlogEntity.setKeyword(glnRequestBo.getCode());
searchgtinlogEntity.setClassStr("GLN查询");
} else if(glnRequestBo.getType().equals("GTIN")){
if(glnRequestBo.getCode().length()<12) {
return R.error("GTIN不能少于12位!");
}
if(glnRequestBo.getCode().length()==12) {
glnRequestBo.setCode("00"+glnRequestBo.getCode());
}
if(glnRequestBo.getCode().length()==13) {
glnRequestBo.setCode("0"+glnRequestBo.getCode());
}
searchgtinlogEntity.setClassStr("境外条码查询:厂商信息查询");
}
searchgtinlogEntity.setKeyword(glnRequestBo.getCode());
searchgtinlogEntity.setSearchsource(0);
//新增查询日志
searchgtinlogService.save(searchgtinlogEntity);
return R.ok().put("data",GLNSearchUtils.getGLNResult("9","GLN",glnRequestBo.getCode(),glnRequestBo.getRequestedLanguage()));
if(glnRequestBo.getType().equals("GLN")) {
return R.ok().put("data",GLNSearchUtils.getGLNResult("9",glnRequestBo.getType(),glnRequestBo.getCode(),glnRequestBo.getRequestedLanguage()));
}else {
return R.ok().put("data",GLNSearchUtils.getGTINResult("9",glnRequestBo.getType(),glnRequestBo.getCode(),glnRequestBo.getRequestedLanguage()));
}
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONException;
import io.office.modules.app.annotation.Login;
import io.office.modules.ueditor.com.baidu.ueditor.ActionEnter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -25,6 +26,7 @@ public class UeditorController {
@Value("${ueditorSavePath}")
private String ueditorSavePath;
@CrossOrigin
@Login
@RequestMapping("/ueditorConfig")
public void getUEditorConfig(HttpServletResponse response, HttpServletRequest request){
......
......@@ -37,7 +37,50 @@ public class GLNSearchUtils {
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
System.out.println(responseEntity.getBody());
// 下面的是通过解析xml字符串的
String returnObjs = responseEntity.getBody().substring(responseEntity.getBody().indexOf("<partyDataLine>"), responseEntity.getBody().indexOf("</gepirParty>")).replaceAll("<partyName />","");//注意 获取根节点的时候要查看返回的xml参数的形式是否为一个根节点
System.out.println(returnObjs);
PartyDataLine xmlObject = null;
Reader reader = null;
//利用JAXBContext将类转为一个实例
try {
JAXBContext context = JAXBContext.newInstance(PartyDataLine.class);
//XMl 转为对象的接口
Unmarshaller unmarshaller = context.createUnmarshaller();
reader = new StringReader(returnObjs);
xmlObject = (PartyDataLine) unmarshaller.unmarshal(reader);
if (reader != null) {
reader.close();
}
} catch (JAXBException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return xmlObject;
}
return null;
}
public static PartyDataLine getGTINResult(String cascade,String requestedKeyCode,String requestedKeyValue,String requestedLanguage) {
String smsTemplateXml = WebServiceXmlTemplate.SEND_MESSAGE_GTIN_TEMPLATE.replaceAll("\\$\\{cascade\\}", cascade).replaceAll("\\$\\{requestedKeyCode\\}", requestedKeyCode)
.replaceAll("\\$\\{requestedKeyValue\\}", requestedKeyValue).replaceAll("\\$\\{requestedLanguage\\}", requestedLanguage);
String url = "http://webservice.anccnet.com:8080/gepir4/gepirv4.asmx";
RestTemplate restTemplate = new RestTemplate();
//创建请求头
//创建请求头
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "text/xml; charset=utf-8");
HttpEntity<String> entity = new HttpEntity<>(smsTemplateXml, headers);
System.out.println(smsTemplateXml);
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, entity, String.class);
if (responseEntity.getStatusCode().value() == 200) {
System.out.println(responseEntity.getBody());
// 下面的是通过解析xml字符串的
String returnObjs = responseEntity.getBody().substring(responseEntity.getBody().indexOf("<partyDataLine>"), responseEntity.getBody().indexOf("</gepirParty>")).replaceAll("<partyName />","");//注意 获取根节点的时候要查看返回的xml参数的形式是否为一个根节点
System.out.println(returnObjs);
......@@ -64,4 +107,5 @@ public class GLNSearchUtils {
}
}
......@@ -20,15 +20,41 @@ public class WebServiceXmlTemplate {
" </requestHeader>\n" +
" </soap:Header>\n" +
" <soap:Body>\n" +
" <getKeyLicensee xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <getKeyLicensee xmlns=\"\">\n" +
" <getKeyLicensee>\n" +
" <requestedKeyCode>${requestedKeyCode}</requestedKeyCode>\n" +
" <requestedKeyValue>${requestedKeyValue}</requestedKeyValue>\n" +
" <requestedLanguage>${requestedLanguage}</requestedLanguage>\n" +
" </getKeyLicensee>\n" +
" </getKeyLicensee>\n" +
" </getKeyLicensee>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
public static String SEND_MESSAGE_GTIN_TEMPLATE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soap:Header>\n" +
" <requestHeader xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <requesterGLN xmlns=\"\">6900000000007</requesterGLN>\n" +
" <onBehalfOfGLN xmlns=\"\">6900000000007</onBehalfOfGLN>\n" +
" <isAuthenticated xmlns=\"\">true</isAuthenticated>\n" +
" <cascade xmlns=\"\">${cascade}</cascade>\n" +
" </requestHeader>\n" +
" </soap:Header>\n" +
" <soap:Body>\n" +
" <getPrefixLicensee xmlns=\"http://gepir4.ws.gs1.org/\">\n" +
" <getPrefixLicensee xmlns=\"\">\n" +
" <getPrefixLicensee>\n" +
"<getPrefixLicensee> \n" +
" <requestedKeyCode>${requestedKeyCode}</requestedKeyCode>\n" +
" <requestedKeyValue>${requestedKeyValue}</requestedKeyValue>\n" +
" <requestedLanguage>${requestedLanguage}</requestedLanguage>\n" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </getPrefixLicensee>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
}
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