|
|
|
@ -2,23 +2,23 @@ package com.jianshui.invoice.service.impl.api; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.ReUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
|
import cn.hutool.json.JSON; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.jianshui.common.core.domain.AjaxResult; |
|
|
|
|
import com.jianshui.common.core.domain.entity.Companyservice; |
|
|
|
|
import com.jianshui.common.core.domain.entity.CompanyserviceDetail; |
|
|
|
|
import com.jianshui.common.enums.ErrorCode; |
|
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; |
|
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceException; |
|
|
|
|
import com.jianshui.common.utils.BeanToMapUtils; |
|
|
|
|
import com.jianshui.common.utils.StringUtils; |
|
|
|
|
import com.jianshui.common.utils.TimeUtil; |
|
|
|
|
import com.jianshui.common.utils.ValidateUtils; |
|
|
|
|
import com.jianshui.common.utils.*; |
|
|
|
|
import com.jianshui.common.utils.spring.SpringUtils; |
|
|
|
|
import com.jianshui.common.utils.uuid.IdUtils; |
|
|
|
|
import com.jianshui.invoice.constant.aisino.console.AisinoConsoleConstants; |
|
|
|
@ -51,6 +51,8 @@ import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
@ -778,46 +780,21 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
@Override |
|
|
|
|
public HXResponse downloadRedInfo(DownloadRedInfoDTO downloadRedInfoDTO, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
// 查找之前的红票
|
|
|
|
|
Redinfo redinfo = new Redinfo(); |
|
|
|
|
redinfo.setRedInfoNo(downloadRedInfoDTO.getBillInfoNo()); |
|
|
|
|
redinfo.setCompanyId(companyservice.getCompanyid()); |
|
|
|
|
QueryWrapper<Redinfo> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getInvoiceLine())) { |
|
|
|
|
queryWrapper.eq("invoice_type", downloadRedInfoDTO.getInvoiceLine()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getBuyerTaxNo())) { |
|
|
|
|
queryWrapper.eq("buyer_taxnum", downloadRedInfoDTO.getBuyerTaxNo()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getExtensionNumber())) { |
|
|
|
|
queryWrapper.eq("fjh", downloadRedInfoDTO.getExtensionNumber()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getTerminalNumber())) { |
|
|
|
|
queryWrapper.eq("terminal_number", downloadRedInfoDTO.getTerminalNumber()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getBillTimeBegin())) { |
|
|
|
|
queryWrapper.ge("bill_input_time", downloadRedInfoDTO.getBillTimeBegin()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getBillTimeEnd())) { |
|
|
|
|
queryWrapper.le("bill_input_time", downloadRedInfoDTO.getBillTimeEnd()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isNotEmpty(downloadRedInfoDTO.getBillNo())) { |
|
|
|
|
queryWrapper.le("out_trade_orderno", downloadRedInfoDTO.getBillNo()); |
|
|
|
|
} |
|
|
|
|
queryWrapper.orderByDesc("id"); |
|
|
|
|
queryWrapper.last(" limit 1 "); |
|
|
|
|
Redinfo redInfoResult = redinfoMapper.selectOne(queryWrapper); |
|
|
|
|
if (redInfoResult == null) { |
|
|
|
|
HXResponse response = new HXResponse("9999", "未查到指定红字信息"); |
|
|
|
|
return response; |
|
|
|
|
|
|
|
|
|
List<CompanyserviceDetail> companyserviceDetailList = companyservice.getCompanyserviceDetailList(); |
|
|
|
|
if(CollectionUtils.isEmpty(companyserviceDetailList) || StrUtil.isEmpty(companyserviceDetailList.get(0).getGoldenTaxDiskNo())){ |
|
|
|
|
throw new JianshuiServiceException("金税盘编号未配置,请联系管理员!"); |
|
|
|
|
} |
|
|
|
|
String goldenTaxDiskNo = companyserviceDetailList.get(0).getGoldenTaxDiskNo(); |
|
|
|
|
|
|
|
|
|
// 组装报文
|
|
|
|
|
AisinoConsoleInvoiceRedDownloadDTO downloadDTO = BeanUtil.copyProperties(redInfoResult, AisinoConsoleInvoiceRedDownloadDTO.class); |
|
|
|
|
AisinoConsoleInvoiceRedDownloadDTO downloadDTO = BeanUtil.copyProperties(downloadRedInfoDTO, AisinoConsoleInvoiceRedDownloadDTO.class); |
|
|
|
|
downloadDTO.setYQZT("N"); |
|
|
|
|
downloadDTO.setXXBFW("0"); |
|
|
|
|
downloadDTO.setPAGENO("1"); |
|
|
|
|
downloadDTO.setPAGESIZE("1000"); |
|
|
|
|
downloadDTO.setNSRSBH(companyservice.getSellertax()); |
|
|
|
|
downloadDTO.setSBBH(goldenTaxDiskNo); |
|
|
|
|
|
|
|
|
|
String param = JSONUtil.toXmlStr(JSONUtil.parse(downloadDTO)); |
|
|
|
|
param = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" + |
|
|
|
@ -844,9 +821,6 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : ""; |
|
|
|
|
String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : ""; |
|
|
|
|
|
|
|
|
|
// todo-k: 下载的返回报文需要单独处理,更新信息表状态?
|
|
|
|
|
// todo-k: 返回的格式看看怎么处理一把,VO都已经创建
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.equals("0000", retcode)) { |
|
|
|
|
|
|
|
|
|
return new HXResponse(retmsg); |
|
|
|
@ -1016,8 +990,10 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
|
|
|
|
|
// 发起请求
|
|
|
|
|
AjaxResult ajaxResult = null; |
|
|
|
|
|
|
|
|
|
JSON json = JSONUtil.parse(decryptResult); |
|
|
|
|
try { |
|
|
|
|
ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.VEHIC, JSONUtil.parse(decryptResult), companyservice); |
|
|
|
|
ajaxResult = AisinoConsoleUtil.sendRequest(AisinoConsoleConstants.VEHIC, json, companyservice); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("【销项发票】【总部控制台接口】【机动车加密】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(decryptResult).toString(), JSONObject.toJSONString(companyservice)); |
|
|
|
|
e.printStackTrace(); |
|
|
|
@ -1036,71 +1012,40 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
|
|
|
|
|
if("0".equals(retcode)){ |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 读取nginx地址,读取数据。
|
|
|
|
|
String indexPage = HttpUtil.get("http://localhost:8082/"); |
|
|
|
|
|
|
|
|
|
System.out.println(indexPage); |
|
|
|
|
|
|
|
|
|
String startDate = "2023.10.10"; |
|
|
|
|
String endDate = "2023.10.12"; |
|
|
|
|
|
|
|
|
|
// 构建要匹配的日期范围字符串
|
|
|
|
|
String dateRange = startDate + "-" + endDate; |
|
|
|
|
// 使用Jsoup解析HTML
|
|
|
|
|
Document doc = Jsoup.parse(indexPage); |
|
|
|
|
|
|
|
|
|
// 获取带有动态日期范围的<a>标签
|
|
|
|
|
Elements aTags = doc.select("a[href*='%28" + dateRange + "%29.dat']"); |
|
|
|
|
|
|
|
|
|
// 遍历<a>标签,提取href属性内容
|
|
|
|
|
for (Element aTag : aTags) { |
|
|
|
|
String href = aTag.attr("href"); |
|
|
|
|
log.info("读取到的机动车加密文件名为"+href); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 调用重汽的推送接口
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("File", ""); |
|
|
|
|
paramMap.put("qyjc", "KS"); |
|
|
|
|
paramMap.put("zdr", ""); |
|
|
|
|
|
|
|
|
|
String result = HttpUtil.post("",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() : ""; |
|
|
|
|
|
|
|
|
|
if("1".equals(retCode)){ |
|
|
|
|
|
|
|
|
|
} else if ("0".equals(retCode)) { |
|
|
|
|
// TODO: 2023/10/25 机动车加密数据导出推送
|
|
|
|
|
/** |
|
|
|
|
* 推送逻辑: |
|
|
|
|
* 调用加密接口,调用成功后推送,推送中间状态断了停止推送 |
|
|
|
|
* 否则获取到推送结果之后停止推送 |
|
|
|
|
* 需要个手动重推的操作。 |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
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("推送中间件地址未配置!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String downloadUrl = secretIdProp.getValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new HXResponse("0000","导出成功!"); |
|
|
|
|
}else { |
|
|
|
|
return new HXResponse("9999","导出失败、发票不存在!"); |
|
|
|
|
cn.hutool.json.JSONObject queryDto = JSONUtil.parseObj(json); |
|
|
|
|
if(queryDto == null){ |
|
|
|
|
log.info("【销项发票】【总部控制台发票-机动车加密】查询条件未获取到!"); |
|
|
|
|
return new HXResponse("查询条件未获取到!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String indexPage = null; |
|
|
|
|
try { |
|
|
|
|
indexPage = HttpUtil.get(downloadUrl); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("【销项发票】【总部控制台发票-机动车加密】{}",e); |
|
|
|
|
return new HXResponse("中间件读取失败!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 机动车加密文件读取,搭配nginx
|
|
|
|
|
|
|
|
|
|
String indexPage = HttpUtil.get("http://localhost:8082/"); |
|
|
|
|
|
|
|
|
|
System.out.println(indexPage); |
|
|
|
|
|
|
|
|
|
String startDate = "2023.10.10"; |
|
|
|
|
String endDate = "2023.10.12"; |
|
|
|
|
String startDate = queryDto.get("KSRQ") != null ? queryDto.get("KSRQ").toString().replace("-",".") : ""; |
|
|
|
|
String endDate = queryDto.get("JSRQ") != null ? queryDto.get("JSRQ").toString().replace("-",".") : ""; |
|
|
|
|
|
|
|
|
|
// 构建要匹配的日期范围字符串
|
|
|
|
|
String dateRange = startDate + "-" + endDate; |
|
|
|
@ -1110,37 +1055,44 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
// 获取带有动态日期范围的<a>标签
|
|
|
|
|
Elements aTags = doc.select("a[href*='%28" + dateRange + "%29.dat']"); |
|
|
|
|
|
|
|
|
|
String href = ""; |
|
|
|
|
// 遍历<a>标签,提取href属性内容
|
|
|
|
|
for (Element aTag : aTags) { |
|
|
|
|
String href = aTag.attr("href"); |
|
|
|
|
href = aTag.attr("href"); |
|
|
|
|
log.info("读取到的机动车加密文件名为"+href); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 调用重汽的推送接口
|
|
|
|
|
File file = FileUtil.file(downloadUrl + href); |
|
|
|
|
InputStream inputStream = FileUtil.getInputStream(file); |
|
|
|
|
|
|
|
|
|
// TODO: 2023/10/24 调用重汽的推送接口
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
|
paramMap.put("File", ""); |
|
|
|
|
paramMap.put("qyjc", "KS"); |
|
|
|
|
paramMap.put("zdr", ""); |
|
|
|
|
paramMap.put("File", file); |
|
|
|
|
// TODO: 2023/10/25 调整成可配置的简称
|
|
|
|
|
paramMap.put("qyjc", companyservice.getSellertax()); |
|
|
|
|
paramMap.put("zdr", companyservice.getCompanyid()); |
|
|
|
|
|
|
|
|
|
String result = HttpUtil.post("",paramMap); |
|
|
|
|
CompanyserviceProp pushUrl = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "aisino_upload_url"); |
|
|
|
|
if(pushUrl == null || StrUtil.isEmpty(pushUrl.getValue())){ |
|
|
|
|
return new HXResponse("重汽推送机动车地址未设置!"); |
|
|
|
|
} |
|
|
|
|
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() : ""; |
|
|
|
|
|
|
|
|
|
if("1".equals(retCode)){ |
|
|
|
|
|
|
|
|
|
} else if ("0".equals(retCode)) { |
|
|
|
|
|
|
|
|
|
// 重汽返回接口信息
|
|
|
|
|
return new HXResponse(retCode,retMsg); |
|
|
|
|
}else { |
|
|
|
|
return new HXResponse("9999","导出失败、发票不存在!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|