tao.mo

监听系统,并且发送邮件&修复API进来数据规格型号model字段不是 品名:| 格式

mt
2023年4月18日18:26:20
......@@ -30,6 +30,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
......@@ -43,6 +44,23 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- starter-mail 依赖包升级-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
......
......@@ -47,4 +47,12 @@ public interface HsCodeRepository extends JpaSpecificationExecutor<HsCode>, JpaR
*/
@Query(nativeQuery = true,value = "select * from T_CC_HS_CODE where OUT_RATE <> 0 or MONITOR_CONDITION collate Chinese_PRC_CS_AI_WS LIKE ?1")
List<HsCode> findMonitorCondition(String chinsesName);
/**
* 根据hscode查询数据
* @param code
* @return
*/
@Query(nativeQuery = true,value = "select top 1 * from T_CC_HS_CODE where VALIDATE=1 AND SKU_CODE =?1 order by id desc ")
public HsCode findHsCodeByCode(String code);
}
\ No newline at end of file
......
......@@ -15,13 +15,20 @@ import com.erry.iclear.dateInterface.repository.ReceiptMessageRepository;
import com.erry.iclear.dateInterface.util.DateUtils;
import com.erry.iclear.dateInterface.util.HttpUtils;
import com.erry.iclear.dateInterface.util.JsonToJava;
import com.erry.iclear.dateInterface.util.SSLClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
/**
......@@ -312,6 +319,24 @@ public class ApiService {
}
/**
* 连接iclear应用指定节点,并且判断是否正常访问
* @param url
* @return
*/
public boolean connectIclearNode(String url){
boolean result = false;
try {
Integer statusCode = HttpUtils.doProxyGet(url,this.proxyUrl,this.proxyPort);
if(statusCode == 200){
result = true;
}
} catch (Exception ex) {
log.error(ex.getMessage(),ex);
}
return result;
}
/**
* 获取headerMap
* @param token
* @return
......
......@@ -5,6 +5,7 @@ import com.erry.iclear.dateInterface.api.request.MawbDetail;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.*;
import com.erry.iclear.dateInterface.repository.ChmConsignmentDetailRepository;
import com.erry.iclear.dateInterface.repository.HsCodeRepository;
import com.erry.iclear.dateInterface.util.NumberUtils;
import com.erry.iclear.dateInterface.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -24,17 +25,17 @@ import java.util.Objects;
@Slf4j
public class ChmConsignmentDetailService {
@Autowired
private ChmConsignmentDetailRepository chmConsignmentDetailRepository;
@Autowired
private HsCodeRepository hsCodeRepository;
/**
* 转换运单明细
* @param mawbDetail
* @return
*/
public ChmConsignmentDetail convertToChmConsignmentDetail(MawbDetail mawbDetail,ChmConsignment chmConsignment){
public ChmConsignmentDetail convertToChmConsignmentDetail(MawbDetail mawbDetail,ChmConsignment chmConsignment,boolean isCheck){
ChmConsignmentDetail result = new ChmConsignmentDetail();
try{
result.setChmConsignment(chmConsignment);
......@@ -70,8 +71,15 @@ public class ChmConsignmentDetailService {
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//如果为数据校验,则不进行数据转换
if(isCheck){
result.setModel(mawbDetail.getGmodel());
}else{
//商品规格、型号
String model = this.modelConvert(mawbDetail.getCodeTS(),mawbDetail.getGname(),mawbDetail.getGmodel());
result.setModel(model);
}
//商品名称
result.setSkuName(mawbDetail.getGname());
//商品序号
......@@ -137,7 +145,7 @@ public class ChmConsignmentDetailService {
* @param mawbDetail
* @return
*/
public ChmConsignmentDetail convertToChmConsignmentDetailFedex(FedexMawbDetail mawbDetail, ChmConsignment chmConsignment){
public ChmConsignmentDetail convertToChmConsignmentDetailFedex(FedexMawbDetail mawbDetail, ChmConsignment chmConsignment,boolean isCheck){
ChmConsignmentDetail result = new ChmConsignmentDetail();
try{
result.setChmConsignment(chmConsignment);
......@@ -160,8 +168,16 @@ public class ChmConsignmentDetailService {
result.setKnockdownUnitDic(knockdownUnitEntries);
result.setKnockdownUnit(knockdownUnitEntries.getChineseName());
}
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
//如果为校验,则不进行转换
if(isCheck){
//商品规格、型号
result.setModel(mawbDetail.getGmodel());
}else{
//商品规格、型号
String model = this.modelConvert(mawbDetail.getCodeTS(),mawbDetail.getGname(),mawbDetail.getGmodel());
result.setModel(model);
}
//商品名称
result.setSkuName(mawbDetail.getGname());
//成交数量
......@@ -308,29 +324,50 @@ public class ChmConsignmentDetailService {
return bdForMat;
}
public List<ChmConsignmentDetail> findChmConsignmentDetailListByConsignmentCode(Long consignmentId){
List<ChmConsignmentDetail> result = new ArrayList<>();
/**
* 将API传的model格式转换为iclear格式类型
* 0|0|表面活性剂|否是|低聚-D-吡喃葡萄糖-C10-16-烷基苷 10-20%,乙氧基化-C16-18、C18-不饱和醇 10-20%,甘油 30-40%,水 10-20%|无品牌|无型号||||
* 转换成
* 品名:鸦片|品牌类型:0|出口享惠情况:0|制作或保存方法[液汁、浸膏、粉末]:嗷嗷|GTIN:|CAS:|其他[非必报要素,请根据实际情况填报]:|
* @param skuCode
* @param skuName
* @param model
* @return
*/
private String modelConvert(String skuCode,String skuName,String model){
String resultModel = model;
try{
result= chmConsignmentDetailRepository.findChmConsignmentDetailByConsignmentCode(consignmentId);
}catch (Exception e){
log.error("findChmConsignmentDetailListByConsignmentCode() error:"+e.getMessage());
HsCode hsCode = hsCodeRepository.findHsCodeByCode(skuCode);
if (hsCode != null) {
String[] modelSplit = model.split("\\|");
String[] modelSplits = new String[20];
Class<? extends HsCode> hsCodeClass = hsCode.getClass();
for (int j = 0; j < 20; j++) {
int element = j + 1;
String invoke = (String) hsCodeClass.getMethod("getElement" + element).invoke(hsCode);
if (j == 0) {
modelSplits[j] = invoke + ":" + skuName;
continue;
}
if (!StringUtil.isEmptyWithTrim(invoke)) {
if (modelSplit.length <= j - 1) {
modelSplits[j] = invoke + ":";
} else {
modelSplits[j] = invoke + ":" + modelSplit[j - 1];
}
}
}
StringBuffer modelSb = new StringBuffer();
for (String split : modelSplits) {
modelSb.append(split).append("|");
}
if(modelSb.length() > 0){
resultModel = modelSb.toString();
}
}
}catch(Exception ex){
log.error("modelConvert() error:"+ex.getMessage());
}
return result;
}
public void saveDetailList(List<ChmConsignmentDetail> chmConsignmentDetailList){
chmConsignmentDetailRepository.saveAll(chmConsignmentDetailList);
}
public void saveChmConsignmentDetail(ChmConsignmentDetail consignmentDetail){
chmConsignmentDetailRepository.save(consignmentDetail);
}
public void deleteChmConsignmentDetail(Long id){
chmConsignmentDetailRepository.deleteById(id);
}
public void deleteChmConsignmentDetailBatch(List<Long> idList){
chmConsignmentDetailRepository.deleteChmConsignmentDetailByChnConIdList(idList);
return resultModel;
}
}
......
......@@ -505,7 +505,7 @@ public class ChmConsignmentService {
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail, chmConsignment));
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail, chmConsignment,Boolean.FALSE));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
......@@ -592,7 +592,7 @@ public class ChmConsignmentService {
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
fedexMawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetailFedex(detail, chmConsignment));
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetailFedex(detail, chmConsignment,Boolean.FALSE));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
......
package com.erry.iclear.dateInterface.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.mail.internet.*;
import java.util.*;
/**
* Created on 2017-9-22.
*/
@Service("emailSenderService")
public class EmailSenderService {
@Value("${smtp_server}")
String smtpServer;
@Value("${smtp_account}")
String smtpAccount;
@Value("${smtp_account_name}")
String smtpAccountName;
@Value("${smtp_port}")
Integer smtpPort;
@Value("${send_email_msg}")
String sendEmailMsg;
@Value("${send_email_cc}")
String sendEmailCc;
/**
* 邮件发送
*
* @param bcc 暗送地址
* @param subject 邮件主题
* @param body 邮件正文
* @throws Exception
*/
public void sendMail(String bcc, String subject, String body) throws Exception {
if (this.sendEmailMsg == null || this.sendEmailMsg.length() == 0) {
return;
}
try {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
senderImpl.setHost(this.smtpServer);
senderImpl.setUsername(null);
senderImpl.setPassword(null);
// senderImpl.setUsername(smtpAccount);
// senderImpl.setPassword(smtpPwd);
senderImpl.setPort(this.smtpPort);
Properties prop = new Properties();
// prop.put("mail.smtp.auth", smtpAuthType);
prop.put("mail.smtp.timeout", "60000");
senderImpl.setJavaMailProperties(prop);
MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
InternetAddress[] internetAddressTo = InternetAddress.parse(this.sendEmailMsg);
messageHelper.setTo(internetAddressTo);
if (this.sendEmailCc != null && this.sendEmailCc.length() > 0) {
InternetAddress[] internetAddressCc = InternetAddress.parse(this.sendEmailCc);
messageHelper.setCc(internetAddressCc);
}
if (bcc != null && bcc.length() > 0) {
InternetAddress[] internetAddressBcc = InternetAddress.parse(bcc);
messageHelper.setBcc(internetAddressBcc);
}
messageHelper.setFrom(this.smtpAccount, this.smtpAccountName);
messageHelper.setSubject(subject);
messageHelper.setText(body, true);
senderImpl.send(mailMessage);
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -127,7 +127,7 @@ public class FedexService {
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
fedexMawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(consignmentDetailService.convertToChmConsignmentDetailFedex(detail,chmConsignment));
chmConsignmentDetailList.add(consignmentDetailService.convertToChmConsignmentDetailFedex(detail,chmConsignment,Boolean.TRUE));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
......
......@@ -189,7 +189,7 @@ public class MawbService {
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(consignmentDetailService.convertToChmConsignmentDetail(detail,chmConsignment));
chmConsignmentDetailList.add(consignmentDetailService.convertToChmConsignmentDetail(detail,chmConsignment,Boolean.TRUE));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
//调用IClear接口进行运单数据校验
......
......@@ -3,8 +3,10 @@ package com.erry.iclear.dateInterface.task;
import com.erry.iclear.dateInterface.enums.ErrorCodeEnum;
import com.erry.iclear.dateInterface.api.response.TokenResult;
import com.erry.iclear.dateInterface.service.ApiService;
import com.erry.iclear.dateInterface.service.EmailSenderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
......@@ -16,7 +18,13 @@ import org.springframework.stereotype.Component;
public class IClearApiTask {
@Autowired
ApiService apiService;
@Autowired
EmailSenderService emailSenderService;
String token;
@Value("${iclear.address.url42}")
String iclearAddressUrl42;
@Value("${iclear.address.url43}")
String iclearAddressUrl43;
/**
* TODO 定时任务:每分钟推送: 报关数据、回执
......@@ -51,6 +59,28 @@ public class IClearApiTask {
log.error("pushMawbTask() error:" +e.getMessage());
}
}
/**
* TODO 定时任务:每5分钟监听: iclear应用节点是否正常
*/
@Scheduled(cron = "${task.monitorIclearNodes}")
public void monitorIclearNodesTask(){
try{
log.info("monitorIclearNodesTask start>>>>>>>>>>>>");
boolean requestResult42 = apiService.connectIclearNode(this.iclearAddressUrl42);
if(requestResult42){
emailSenderService.sendMail(null,"系统访问异常提示","42机器无法正常访问");
}
boolean requestResult43 = apiService.connectIclearNode(this.iclearAddressUrl43);
if(requestResult43){
emailSenderService.sendMail(null,"系统访问异常提示","43机器无法正常访问");
}
log.info("monitorIclearNodesTask end>>>>>>>>>>>>");
}catch (Exception e){
log.error("monitorIclearNodesTask() error:" +e.getMessage());
}
}
/**
* 每次请求获取最新token
* @throws Exception
......
......@@ -12,6 +12,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.StringEntity;
......@@ -110,6 +111,31 @@ public class HttpUtils {
}
return result;
}
/**
* 代理模式get请求,返回请求状态
* @param url
* @param proxyUrl
* @param port
* @return
* @throws Exception
*/
public static Integer doProxyGet(String url,String proxyUrl,Integer port) throws Exception {
HttpGet httpGet = null;
Integer statusCode = 0;
HttpClient httpClient = SSLClient.getProxyHttpsClient(proxyUrl,port);
try{
httpGet = new HttpGet(url);
HttpResponse response = httpClient.execute(httpGet);
if(response != null){
statusCode = response.getStatusLine().getStatusCode();
}
} finally {
httpClient.getConnectionManager().shutdown(); //关闭连接
}
return statusCode;
}
/**
* post请求
* @param url
......
......@@ -15,8 +15,10 @@ task.pushMawbTask=0 0/1 * * * ?
task.pushErrorReturnDate=0 0/3 * * * ?
#推送失败的申报数据
task.pushErrorDeclareDate=0 0/3 * * * ?
#推送失败的回执数据
task.monitorIclearNodes=0 0/1 * * * ?
api.base-address=https://declarationuat.fedex.com.cn/Exp
api.base-address=http://localhost:8080/Exp
#获取token账号
api.token-info.username=iclear_external_ctm
#获取token密码
......@@ -35,6 +37,9 @@ api.address.refresh-token-url=https://apiuat.iclrccd-fedex.com/user/token/refres
api.address.customs-url=https://apiuat.iclrccd-fedex.com/export/outbound/customs
#推送完整报文地址
api.address.complete-msg-url=https://apiuat.iclrccd-fedex.com/export/outbound/mawb
#iclear应用节点是否能够正常访问
iclear.address.url42=https://www.fedex.com/
iclear.address.url43=https://www.baidu.com/
#代理地址(刷新token、传输海关回执地址、推送完整报文地址)
api.address.proxy-url=cn2-proxy.apac.fedex.com
api.address.proxy-port=3128
\ No newline at end of file
......
......@@ -8,6 +8,8 @@ task.pushMawbTask=0 0/1 * * * ?
task.pushErrorReturnDate=0 0/30 * * * ?
#推送失败的申报数据
task.pushErrorDeclareDate=0 0/30 * * * ?
#推送失败的回执数据
task.monitorIclearNodes=0 0/5 * * * ?
api.base-address=https://declaration.fedex.com.cn/Exp
#获取token账号
......@@ -28,6 +30,9 @@ api.address.refresh-token-url=https://apictm.iclrccd-fedex.com/admin/user/token/
api.address.customs-url=https://apictm.iclrccd-fedex.com/export/outbound/customs
#推送完整报文地址
api.address.complete-msg-url=https://apictm.iclrccd-fedex.com/export/outbound/mawb
#iclear应用节点是否能够正常访问
iclear.address.url42=https://pjec0003.cndczmd.apac.fedex.com:9002/Exp/
iclear.address.url43=https://pjec0004.cndczmd.apac.fedex.com:9002/Exp/
#代理地址(刷新token、传输海关回执地址、推送完整报文地址)
api.address.proxy-url=cn2-proxy.apac.fedex.com
api.address.proxy-port=3128
\ No newline at end of file
api.address.proxy-port=3128
......
......@@ -8,6 +8,8 @@ task.pushMawbTask=0 0/1 * * * ?
task.pushErrorReturnDate=0 0/3 * * * ?
#推送失败的申报数据
task.pushErrorDeclareDate=0 0/3 * * * ?
#推送失败的回执数据
task.monitorIclearNodes=0 0/5 * * * ?
api.base-address=https://declarationuat.fedex.com.cn/Exp
#获取token账号
......@@ -28,6 +30,9 @@ api.address.refresh-token-url=https://apiuat.iclrccd-fedex.com/user/token/refres
api.address.customs-url=https://apiuat.iclrccd-fedex.com/export/outbound/customs
#推送完整报文地址
api.address.complete-msg-url=https://apiuat.iclrccd-fedex.com/export/outbound/mawb
#iclear应用节点是否能够正常访问
iclear.address.url42=https://pjec0003.cndczmd.apac.fedex.com:9002/Exp/
iclear.address.url43=https://pjec0004.cndczmd.apac.fedex.com:9002/Exp/
#代理地址(刷新token、传输海关回执地址、推送完整报文地址)
api.address.proxy-url=cn2-proxy.apac.fedex.com
api.address.proxy-port=3128
\ No newline at end of file
......
......@@ -11,4 +11,24 @@ spring.jpa.database=sql_server
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.event.merge.entity_copy_observer=allow
\ No newline at end of file
spring.jpa.properties.event.merge.entity_copy_observer=allow
####email properties
#SMTP Server IP or Domain name
smtp_server=mapper.gslb.fedex.com
smtp_port=25
#Account to send email
smtp_account=donotreply@fedex.com
#Password
smtp_pwd=
#Account Name to send emailis_customer
smtp_account_name=й
#bcc
email_bcc=donotreply@fedex.com
#email link
#email_link=http://localhost:8080/Exp
#user email
send_email=hyssmt@vip.qq.com,li.chang@erry.com
#return_message job email
send_email_msg=hyssmt@vip.qq.com,li.chang@erry.com,yi.zhou@erry.com
send_email_cc=ICE-IClear-Support@erry.com
......