|
|
|
@ -4,10 +4,10 @@ import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.core.util.XmlUtil; |
|
|
|
|
import cn.hutool.core.net.URLDecoder; |
|
|
|
|
import cn.hutool.core.util.*; |
|
|
|
|
import cn.hutool.http.Header; |
|
|
|
|
import cn.hutool.http.HttpRequest; |
|
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
|
import cn.hutool.json.JSON; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
@ -40,7 +40,17 @@ import com.jianshui.invoice.utils.BillInfoUtils; |
|
|
|
|
import com.jianshui.invoice.utils.aisino.console.AisinoConsoleUtil; |
|
|
|
|
import com.jianshui.system.domain.CompanyserviceProp; |
|
|
|
|
import com.jianshui.system.service.ICompanyservicePropService; |
|
|
|
|
import io.lettuce.core.StrAlgoArgs; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.httpclient.HttpClient; |
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; |
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
|
import org.apache.http.ssl.SSLContexts; |
|
|
|
|
import org.jsoup.Jsoup; |
|
|
|
|
import org.jsoup.nodes.Document; |
|
|
|
|
import org.jsoup.nodes.Element; |
|
|
|
@ -53,10 +63,14 @@ import org.w3c.dom.Node; |
|
|
|
|
import org.w3c.dom.NodeList; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection; |
|
|
|
|
import javax.net.ssl.SSLContext; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.*; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -82,6 +96,10 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
@Autowired |
|
|
|
|
private InvoiceBackMapper invoiceBackMapper; |
|
|
|
|
|
|
|
|
|
static final String PREFIX = "stream2file";//前缀字符串定义文件名;必须至少三个字符
|
|
|
|
|
static final String SUFFIX = ".tmp";//后缀字符串定义文件的扩展名;如果为null,则将使用后缀".tmp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 1.发票开具 SID = 1 |
|
|
|
@ -910,7 +928,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
// 返回结果处理
|
|
|
|
|
if (!StringUtils.equals("0", retcode)) { |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/28 返回结果待解析。
|
|
|
|
|
// TODO: 2023/10/28 返回结果待解析。
|
|
|
|
|
/*if(sss.indexOf("<DATA>") != -1 && sss.indexOf("</DATA>") != -1){ |
|
|
|
|
System.out.println("存在"); |
|
|
|
|
String data = sss.substring(sss.indexOf("<DATA>") + 6,sss.indexOf("</DATA>")); |
|
|
|
@ -928,12 +946,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
cn.hutool.json.JSONArray jsonArray = JSONUtil.parseArray(RedInvReqBill); |
|
|
|
|
List<DownloadJdcVO> downloadJdcVOList = BeanUtil.copyToList(jsonArray,DownloadJdcVO.class); |
|
|
|
|
System.out.println(jsonArray); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(map); |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
@ -1095,32 +1108,31 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
@Override |
|
|
|
|
public HXResponse exportVehicleInvoice(JSONObject decryptResult, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/10 机动车
|
|
|
|
|
/** |
|
|
|
|
* { |
|
|
|
|
* "SavePath":"C://", |
|
|
|
|
* "FPZL":"", |
|
|
|
|
* "KSRQ":"", |
|
|
|
|
* "StrGuid":"" |
|
|
|
|
* } |
|
|
|
|
*/ |
|
|
|
|
ExportVehicleDTO exportVehicleDTO = BeanUtil.copyProperties(decryptResult,ExportVehicleDTO.class); |
|
|
|
|
|
|
|
|
|
if(BeanUtil.isEmpty(exportVehicleDTO)){ |
|
|
|
|
return new HXResponse("9999","请求参数为空!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/28 机动车处理
|
|
|
|
|
exportVehicleDTO.setSavePath("C:\\test\\fileDownload\\"); |
|
|
|
|
|
|
|
|
|
// 发起请求
|
|
|
|
|
AjaxResult ajaxResult = null; |
|
|
|
|
|
|
|
|
|
JSON json = JSONUtil.parse(decryptResult); |
|
|
|
|
JSON json = JSONUtil.parse(exportVehicleDTO); |
|
|
|
|
try { |
|
|
|
|
ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.VEHIC, json, companyservice); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("【销项发票】【总部控制台接口】【机动车加密】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(decryptResult).toString(), JSONObject.toJSONString(companyservice)); |
|
|
|
|
log.error("【销项发票】【总部控制台接口】【机动车加密】机动车加密文件导出请求异常,请求报文{},销方信息{}", JSONUtil.parse(decryptResult).toString(), JSONObject.toJSONString(companyservice)); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
throw new JianshuiServiceException("系统异常!"); |
|
|
|
|
return new HXResponse("9999","系统异常!"); |
|
|
|
|
} |
|
|
|
|
log.info("【销项发票】【总部控制台发票】发票开具请求拉取结果{}", ajaxResult.toString()); |
|
|
|
|
log.info("【销项发票】【总部控制台发票】机动车加密文件导出结果{}", ajaxResult.toString()); |
|
|
|
|
|
|
|
|
|
//返回报文解析
|
|
|
|
|
if (ajaxResult.isError()) { |
|
|
|
|
throw new JianshuiServiceException(ajaxResult.getMsg()); |
|
|
|
|
return new HXResponse("9999",ajaxResult.getMsg()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cn.hutool.json.JSONObject resultJSON = JSONUtil.parseObj(ajaxResult.get("data")); |
|
|
|
@ -1129,20 +1141,12 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
|
|
|
|
|
if ("0".equals(retcode)) { |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/25 机动车加密数据导出推送
|
|
|
|
|
/** |
|
|
|
|
* 推送逻辑: |
|
|
|
|
* 调用加密接口,调用成功后推送,推送中间状态断了停止推送 |
|
|
|
|
* 否则获取到推送结果之后停止推送 |
|
|
|
|
* 需要个手动重推的操作。 |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); |
|
|
|
|
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_nginx_url"); |
|
|
|
|
|
|
|
|
|
if (secretIdProp == null || StrUtil.isEmpty(secretIdProp.getValue())) { |
|
|
|
|
log.info("【销项发票】【总部控制台发票-机动车加密】推送nginx地址未配置!aisino_nginx_url"); |
|
|
|
|
return new HXResponse("推送中间件地址未配置!"); |
|
|
|
|
return new HXResponse("9999","推送中间件地址未配置!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String downloadUrl = secretIdProp.getValue(); |
|
|
|
@ -1150,7 +1154,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
cn.hutool.json.JSONObject queryDto = JSONUtil.parseObj(json); |
|
|
|
|
if (queryDto == null) { |
|
|
|
|
log.info("【销项发票】【总部控制台发票-机动车加密】查询条件未获取到!"); |
|
|
|
|
return new HXResponse("查询条件未获取到!"); |
|
|
|
|
return new HXResponse("9999","查询条件未获取到!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String indexPage = null; |
|
|
|
@ -1158,7 +1162,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
indexPage = HttpUtil.get(downloadUrl); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("【销项发票】【总部控制台发票-机动车加密】{}", e); |
|
|
|
|
return new HXResponse("中间件读取失败!"); |
|
|
|
|
return new HXResponse("9999","中间件读取失败!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String startDate = queryDto.get("KSRQ") != null ? queryDto.get("KSRQ").toString().replace("-", ".") : ""; |
|
|
|
@ -1180,27 +1184,50 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
File file = FileUtil.file(downloadUrl + href); |
|
|
|
|
InputStream inputStream = FileUtil.getInputStream(file); |
|
|
|
|
// String fileStream = null;
|
|
|
|
|
InputStream inputStream = null; |
|
|
|
|
File file = null; |
|
|
|
|
try { |
|
|
|
|
// fileStream = HttpUtil.get(downloadUrl + href);
|
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
|
HttpGet httpGet = new HttpGet(downloadUrl + href); |
|
|
|
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
|
|
|
|
inputStream = response.getEntity().getContent(); |
|
|
|
|
file = stream2file(inputStream); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("读取到的机动车加密文件名为{},下载文件nginx接口失败", href); |
|
|
|
|
return new HXResponse("9999", "导出失败,未获取到下载文件!"); |
|
|
|
|
} |
|
|
|
|
// InputStream is = new ByteArrayInputStream(fileStream.getBytes());
|
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 调用重汽的推送接口
|
|
|
|
|
// 调用重汽的推送接口
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("File", file); |
|
|
|
|
paramMap.put("file", file); |
|
|
|
|
// TODO: 2023/10/25 调整成可配置的简称
|
|
|
|
|
paramMap.put("qyjc", companyservice.getSellertax()); |
|
|
|
|
paramMap.put("zdr", companyservice.getCompanyid()); |
|
|
|
|
|
|
|
|
|
CompanyserviceProp pushUrl = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_upload_url"); |
|
|
|
|
if (pushUrl == null || StrUtil.isEmpty(pushUrl.getValue())) { |
|
|
|
|
return new HXResponse("重汽推送机动车地址未设置!"); |
|
|
|
|
return new HXResponse("9999","重汽推送机动车地址未设置!"); |
|
|
|
|
} |
|
|
|
|
String retCode = null; |
|
|
|
|
String retMsg = null; |
|
|
|
|
try { |
|
|
|
|
log.info("【机动车加密接口推送】请求内容:{}",paramMap); |
|
|
|
|
// String result = HttpUtil.post(pushUrl.getValue(), paramMap);
|
|
|
|
|
String result = HttpRequest.post(pushUrl.getValue()) |
|
|
|
|
.form(paramMap)//表单内容
|
|
|
|
|
.timeout(20000)//超时,毫秒
|
|
|
|
|
.execute().body(); |
|
|
|
|
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(result); |
|
|
|
|
|
|
|
|
|
retCode = jsonObject.get("retCode") != null ? jsonObject.get("retCode").toString() : ""; |
|
|
|
|
retMsg = jsonObject.get("retMsg") != null ? jsonObject.get("retMsg").toString() : ""; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("【机动车加密接口推送】超时,{}",e); |
|
|
|
|
return new HXResponse("9999", "推送接口超时!"); |
|
|
|
|
} |
|
|
|
|
String result = HttpUtil.post(pushUrl.getValue(), paramMap); |
|
|
|
|
|
|
|
|
|
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(result); |
|
|
|
|
|
|
|
|
|
String retCode = jsonObject.get("retCode") != null ? jsonObject.get("retCode").toString() : ""; |
|
|
|
|
String retMsg = jsonObject.get("retMsg") != null ? jsonObject.get("retMsg").toString() : ""; |
|
|
|
|
|
|
|
|
|
// 重汽返回接口信息
|
|
|
|
|
return new HXResponse(retCode, retMsg); |
|
|
|
|
} else { |
|
|
|
@ -1209,6 +1236,22 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author kk |
|
|
|
|
* @date 17:42 |
|
|
|
|
* @param: [in] |
|
|
|
|
* @return: |
|
|
|
|
* 机动车加密导出-文件转化本地 |
|
|
|
|
*/ |
|
|
|
|
public static File stream2file (InputStream in) throws IOException { |
|
|
|
|
final File tempFile = File.createTempFile(PREFIX, SUFFIX); |
|
|
|
|
tempFile.deleteOnExit(); |
|
|
|
|
try (FileOutputStream out = new FileOutputStream(tempFile)) { |
|
|
|
|
IOUtils.copy(in, out); |
|
|
|
|
} |
|
|
|
|
return tempFile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public AjaxResult syncStockInfo(Companyservice companyservice) { |
|
|
|
|