|
@@ -6,6 +6,8 @@ import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.common.redis.service.RedisIdGenerator;
|
|
import com.ruoyi.common.redis.service.RedisIdGenerator;
|
|
|
import com.ruoyi.logistics.config.InvoiceConfig;
|
|
import com.ruoyi.logistics.config.InvoiceConfig;
|
|
|
import com.ruoyi.logistics.domain.InvoiceRequest;
|
|
import com.ruoyi.logistics.domain.InvoiceRequest;
|
|
|
|
|
+import com.ruoyi.logistics.domain.RptFinancialMonthSummary;
|
|
|
|
|
+import com.ruoyi.logistics.service.IRptFinancialMonthSummaryService;
|
|
|
import com.ruoyi.logistics.service.InvoiceService;
|
|
import com.ruoyi.logistics.service.InvoiceService;
|
|
|
import com.ruoyi.logistics.util.Base64Util;
|
|
import com.ruoyi.logistics.util.Base64Util;
|
|
|
import com.ruoyi.logistics.util.HttpUtil;
|
|
import com.ruoyi.logistics.util.HttpUtil;
|
|
@@ -14,10 +16,12 @@ import com.ruoyi.logistics.util.TaxAmountCalculator;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -35,8 +39,11 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
private RedisIdGenerator redisIdGenerator;
|
|
private RedisIdGenerator redisIdGenerator;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private InvoiceConfig invoiceConfig;
|
|
private InvoiceConfig invoiceConfig;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IRptFinancialMonthSummaryService rptFinancialMonthSummaryService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 电子发票专票开据
|
|
* 电子发票专票开据
|
|
@@ -50,7 +57,8 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
// 1. 组装正票申请的业务报文(content)
|
|
// 1. 组装正票申请的业务报文(content)
|
|
|
JSONObject content = new JSONObject();
|
|
JSONObject content = new JSONObject();
|
|
|
// 必选参数
|
|
// 必选参数
|
|
|
- content.put("djbh", redisIdGenerator.generateUniqueId("BWKP")); // 全局唯一单据编号
|
|
|
|
|
|
|
+ String djbh=redisIdGenerator.generateUniqueId("BWKP");
|
|
|
|
|
+ content.put("djbh", djbh); // 全局唯一单据编号
|
|
|
content.put("kpzddm", invoiceConfig.getKpZddm()); // 开票终端代码
|
|
content.put("kpzddm", invoiceConfig.getKpZddm()); // 开票终端代码
|
|
|
content.put("fplxdm", "01"); // 发票类型:01=专票,02=普票
|
|
content.put("fplxdm", "01"); // 发票类型:01=专票,02=普票
|
|
|
content.put("kplx", "0"); // 开票类型:0=蓝字发票
|
|
content.put("kplx", "0"); // 开票类型:0=蓝字发票
|
|
@@ -100,13 +108,19 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
requestParam.put("signType", invoiceConfig.getSignType());
|
|
requestParam.put("signType", invoiceConfig.getSignType());
|
|
|
String responseJson = HttpUtil.doPostJson(invoiceConfig.getBaseUrl(), requestParam.toJSONString());
|
|
String responseJson = HttpUtil.doPostJson(invoiceConfig.getBaseUrl(), requestParam.toJSONString());
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- // JsonNode jsonNode = objectMapper.readTree(responseJson);
|
|
|
|
|
Map<String, Object> invoiceMap = objectMapper.readValue(
|
|
Map<String, Object> invoiceMap = objectMapper.readValue(
|
|
|
responseJson,
|
|
responseJson,
|
|
|
new TypeReference<Map<String, Object>>() {}
|
|
new TypeReference<Map<String, Object>>() {}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- //这里成功后也要将单据编号进行回传月度报表
|
|
|
|
|
|
|
+ if("0".equals(invoiceMap.get("code").toString())){
|
|
|
|
|
+ //这里成功后也要将单据编号进行回传月度报表
|
|
|
|
|
+ RptFinancialMonthSummary rptFinancialMonthSummary= new RptFinancialMonthSummary();
|
|
|
|
|
+ rptFinancialMonthSummary.setStatus("3");
|
|
|
|
|
+ rptFinancialMonthSummary.setBwDjbh(djbh);
|
|
|
|
|
+ rptFinancialMonthSummary.setSummaryId(invoiceRequest.getSummaryId());
|
|
|
|
|
+ rptFinancialMonthSummaryService.updateRptFinancialMonthSummary(rptFinancialMonthSummary);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return invoiceMap;
|
|
return invoiceMap;
|
|
|
}
|
|
}
|
|
@@ -120,42 +134,53 @@ public class InvoiceServiceImpl implements InvoiceService {
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Map selectInvoice(Map param) throws JsonProcessingException {
|
|
|
|
|
- // 1.组装查询的报文
|
|
|
|
|
- JSONObject content = new JSONObject();
|
|
|
|
|
- content.put("djbh",param.get("djbh").toString());
|
|
|
|
|
- String contentBase64 = Base64Util.encode(content.toJSONString());
|
|
|
|
|
- // 3. 构建签名参数,生成签名值
|
|
|
|
|
- Map<String, String> signParams = new HashMap<>();
|
|
|
|
|
- signParams.put("appid", invoiceConfig.getAppId());
|
|
|
|
|
- signParams.put("serviceid", invoiceConfig.getServiceSelect());
|
|
|
|
|
- signParams.put("content", contentBase64);
|
|
|
|
|
- String signature = SignUtil.sign("3", invoiceConfig.getAppSecret(), signParams);
|
|
|
|
|
-
|
|
|
|
|
- JSONObject requestParam = new JSONObject();
|
|
|
|
|
- requestParam.put("appid", invoiceConfig.getAppId());
|
|
|
|
|
- requestParam.put("serviceid", invoiceConfig.getServiceSelect());
|
|
|
|
|
- requestParam.put("content", contentBase64);
|
|
|
|
|
- requestParam.put("signature", signature);
|
|
|
|
|
- requestParam.put("signType","3");
|
|
|
|
|
- String responseJson = HttpUtil.doPostJson(invoiceConfig.getBaseUrl(), requestParam.toJSONString());
|
|
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
- Map<String, Object> invoiceMap = objectMapper.readValue(
|
|
|
|
|
- responseJson,
|
|
|
|
|
- new TypeReference<Map<String, Object>>() {}
|
|
|
|
|
- );
|
|
|
|
|
- if(StringUtils.isNotBlank(invoiceMap.get("data").toString())){
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> dataMap = objectMapper.readValue(
|
|
|
|
|
- Base64Util.decode(invoiceMap.get("data").toString()),
|
|
|
|
|
|
|
+ public void updateInvoice() throws JsonProcessingException {
|
|
|
|
|
+
|
|
|
|
|
+ //查询所有未开票的
|
|
|
|
|
+ List<Map<String,Object>> invoiceList= jdbcTemplate.queryForList("SELECT bw_djbh FROM `rpt_financial_month_summary` where bw_djbh is not null and bw_dzfp_pdf_url is null");
|
|
|
|
|
+ for(int i=0;i<invoiceList.size();i++){
|
|
|
|
|
+ // 1.组装查询的报文
|
|
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
|
|
+ String djbh=invoiceList.get(i).get("bw_djbh").toString();
|
|
|
|
|
+ content.put("djbh",djbh);
|
|
|
|
|
+ String contentBase64 = Base64Util.encode(content.toJSONString());
|
|
|
|
|
+ // 3. 构建签名参数,生成签名值
|
|
|
|
|
+ Map<String, String> signParams = new HashMap<>();
|
|
|
|
|
+ signParams.put("appid", invoiceConfig.getAppId());
|
|
|
|
|
+ signParams.put("serviceid", invoiceConfig.getServiceSelect());
|
|
|
|
|
+ signParams.put("content", contentBase64);
|
|
|
|
|
+ String signature = SignUtil.sign("3", invoiceConfig.getAppSecret(), signParams);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject requestParam = new JSONObject();
|
|
|
|
|
+ requestParam.put("appid", invoiceConfig.getAppId());
|
|
|
|
|
+ requestParam.put("serviceid", invoiceConfig.getServiceSelect());
|
|
|
|
|
+ requestParam.put("content", contentBase64);
|
|
|
|
|
+ requestParam.put("signature", signature);
|
|
|
|
|
+ requestParam.put("signType","3");
|
|
|
|
|
+ String responseJson = HttpUtil.doPostJson(invoiceConfig.getBaseUrl(), requestParam.toJSONString());
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+ Map<String, Object> invoiceMap = objectMapper.readValue(
|
|
|
|
|
+ responseJson,
|
|
|
new TypeReference<Map<String, Object>>() {}
|
|
new TypeReference<Map<String, Object>>() {}
|
|
|
);
|
|
);
|
|
|
- invoiceMap.put("data",dataMap);
|
|
|
|
|
|
|
+ Map<String, Object> dataMap= new HashMap<>();
|
|
|
|
|
+ if(StringUtils.isNotBlank(invoiceMap.get("data").toString())){
|
|
|
|
|
+ dataMap = objectMapper.readValue(
|
|
|
|
|
+ Base64Util.decode(invoiceMap.get("data").toString()),
|
|
|
|
|
+ new TypeReference<Map<String, Object>>() {}
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ //这里 需要将查询到的信息进行回写月度报表里面
|
|
|
|
|
+ if("0".equals(invoiceMap.get("code").toString())){
|
|
|
|
|
+ RptFinancialMonthSummary rptFinancialMonthSummary= new RptFinancialMonthSummary();
|
|
|
|
|
+ rptFinancialMonthSummary.setBwDjbh(djbh);
|
|
|
|
|
+ rptFinancialMonthSummary.setBwDzfpPdfUrl(dataMap.get("ofd").toString());
|
|
|
|
|
+ rptFinancialMonthSummary.setBwDzfpOfdUrl(dataMap.get("pdf").toString());
|
|
|
|
|
+ rptFinancialMonthSummary.setBwDzfpXmlUrl(dataMap.get("xml").toString());
|
|
|
|
|
+ rptFinancialMonthSummaryService.updateRptFinancialMonthSummaryByInvoice(rptFinancialMonthSummary);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- //这里 需要将查询到的信息进行回写月度报表里面
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- return invoiceMap;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|