Commit f56e95cf authored by hanfeng's avatar hanfeng

开票

parent 2840ae43
...@@ -113,9 +113,15 @@ public class Invoice { ...@@ -113,9 +113,15 @@ public class Invoice {
*/ */
private String salerTaxCode; private String salerTaxCode;
/** /**
* 销售方地址电话 * 销售方地址
*/ */
private String salerAddressPhone; private String salerAddress;
/**
* 销售方电话
*/
private String salerPhone;
/** /**
* 销售方银行及账户 * 销售方银行及账户
*/ */
......
package com.xxfc.platform.universal.entity;
import lombok.Data;
import javax.persistence.Table;
import java.util.Date;
/**
* 发票最终查询结果,错误记录表
* @author Administrator
*/
@Data
@Table(name = "invoice_query_error")
public class InvoiceQueryError {
private Integer id;
private Integer invoiceId;
private String invoiceSerialNum;
private Integer status;
private Date creTime;
}
...@@ -20,7 +20,7 @@ public class OrderData { ...@@ -20,7 +20,7 @@ public class OrderData {
*/ */
private Integer num; private Integer num;
/** /**
* 是否含税价格 * 是否含税价格 0:不含税,1:含税
*/ */
private Integer withTaxFlag=1; private Integer withTaxFlag=1;
/** /**
...@@ -30,7 +30,7 @@ public class OrderData { ...@@ -30,7 +30,7 @@ public class OrderData {
/** /**
* 税率 * 税率
*/ */
private Double taxRate; private BigDecimal taxRate;
/** /**
* 单位 * 单位
......
package com.xxfc.platform.universal.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.universal.entity.InvoiceQueryError;
import com.xxfc.platform.universal.mapper.InvoiceQueryErrorMapper;
/**
* @Auther: Administrator
* @Date: 2020/1/8 10:48
* @Description:
*/
public class InvoiceQueryErrorBiz extends BaseBiz<InvoiceQueryErrorMapper, InvoiceQueryError> {
}
...@@ -51,7 +51,7 @@ public class InvoiceController extends BaseController<InvoiceBiz, Invoice> { ...@@ -51,7 +51,7 @@ public class InvoiceController extends BaseController<InvoiceBiz, Invoice> {
@GetMapping("/result") @GetMapping("/result")
public ObjectRestResponse invoiceResult(@RequestParam("invoiceSerialNum")String invoiceSerialNum){ public ObjectRestResponse invoiceResult(@RequestParam("invoiceSerialNum")String invoiceSerialNum){
String result= baseBiz.invoiceResult(invoiceSerialNum); List<Map<String,Object>> result= baseBiz.invoiceResult(invoiceSerialNum);
return ObjectRestResponse.succ(result); return ObjectRestResponse.succ(result);
} }
} }
package com.xxfc.platform.universal.mapper;
import com.xxfc.platform.universal.entity.InvoiceQueryError;
import tk.mybatis.mapper.common.Mapper;
/**
* @author Administrator
* @Date: 2020/1/8 10:49
* @Description:
*/
public interface InvoiceQueryErrorMapper extends Mapper<InvoiceQueryError> {
}
...@@ -18,5 +18,5 @@ public interface InvoiceDao { ...@@ -18,5 +18,5 @@ public interface InvoiceDao {
String Invoicing(Invoice invoice, List<OrderData> orders); String Invoicing(Invoice invoice, List<OrderData> orders);
String invoiceResult(String invoiceSerialNum); List<Map<String,Object>> invoiceResult(String invoiceSerialNum);
} }
...@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import nuonuo.open.sdk.NNOpenSDK; import nuonuo.open.sdk.NNOpenSDK;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -35,26 +36,31 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -35,26 +36,31 @@ public class InvoiceDaoImpl implements InvoiceDao {
/** /**
* 诺诺-极速开票 * 诺诺-极速开票
*/ */
private static final String taxnum = "91441900MA53C6713X"; @Value("${invoice.nuonuo.js.taxnum}")
private static final String appKey = "80653463"; private String taxnum;
private static final String appSecret = "EA55B47A6D0A4560"; @Value("${invoice.nuonuo.js.appKey}")
private String appKey;
@Value("${invoice.nuonuo.js.appSecret}")
private String appSecret;
/** /**
* 诺诺-诺诺发票 * 诺诺-诺诺发票
*/ */
private static final String taxnum2 = "91441900MA53C6713X"; @Value("${invoice.nuonuo.nn.taxnum}")
//沙箱 private String taxnum2;
private static final String appKey2 = "SD26345711"; @Value("${invoice.nuonuo.nn.appKey}")
private static final String appSecret2 = "SD1B543442BF41A1"; private String appKey2;
@Value("${invoice.nuonuo.nn.appSecret}")
private String appSecret2;
// //正式 // //正式
// private static final String appKey2 = "26345711"; // private static final String appKey2 = "26345711";
// private static final String appSecret2 = "901B543442BF41A1"; // private static final String appSecret2 = "901B543442BF41A1";
/** /**
* 给定的部分名获取税号 * 给定的部分名获取税号
*
* @param name * @param name
* @return * @return
*/ */
...@@ -82,6 +88,7 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -82,6 +88,7 @@ public class InvoiceDaoImpl implements InvoiceDao {
/** /**
* 根据开票代码,调用第三方接口获取税号 * 根据开票代码,调用第三方接口获取税号
*
* @param code * @param code
* @return * @return
*/ */
...@@ -105,7 +112,6 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -105,7 +112,6 @@ public class InvoiceDaoImpl implements InvoiceDao {
} }
@Override @Override
public String Invoicing(Invoice invoice, List<OrderData> orders) { public String Invoicing(Invoice invoice, List<OrderData> orders) {
...@@ -123,7 +129,7 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -123,7 +129,7 @@ public class InvoiceDaoImpl implements InvoiceDao {
HashMap<String, Map<String, Object>> orderMap = new HashMap<>(); HashMap<String, Map<String, Object>> orderMap = new HashMap<>();
orderMap.put("order", map); orderMap.put("order", map);
//购方信息 //购方信息
map.put("buyerName",invoice.getPurchaserName()); map.put("buyerName", invoice.getPurchaserName());
map.put("buyerTaxNum", invoice.getPurchaserTaxCode()); map.put("buyerTaxNum", invoice.getPurchaserTaxCode());
// map.put("buyerTel", invoice.getPurchaserPhone()); // map.put("buyerTel", invoice.getPurchaserPhone());
map.put("buyerAddress", invoice.getPurchaserAddressPhone()); map.put("buyerAddress", invoice.getPurchaserAddressPhone());
...@@ -134,18 +140,19 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -134,18 +140,19 @@ public class InvoiceDaoImpl implements InvoiceDao {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//销方信息 //销方信息
map.put("orderNo", invoice.getOrderNo()); map.put("orderNo", invoice.getOrderNo());
map.put("invoiceDate",dateFormat.format(invoice.getInvoiceDate())); map.put("invoiceDate", dateFormat.format(invoice.getInvoiceDate()));
map.put("salerName", invoice.getSalerName()); map.put("salerName", invoice.getSalerName());
map.put("salerTaxNum", invoice.getSalerTaxCode()); map.put("salerTaxNum", invoice.getSalerTaxCode());
map.put("salerAddress", invoice.getSalerAddressPhone()); map.put("salerTel", invoice.getSalerPhone());
map.put("salerAccount",invoice.getSalerAccountBank()); map.put("salerAddress", invoice.getSalerAddress());
map.put("salerAccount", invoice.getSalerAccountBank());
map.put("clerk", invoice.getIssuer()); map.put("clerk", invoice.getIssuer());
map.put("payee", invoice.getPayee()); map.put("payee", invoice.getPayee());
map.put("checker", invoice.getReviewer()); map.put("checker", invoice.getReviewer());
//其他设置 //其他设置
map.put("pushMode", String.valueOf(invoice.getPushMode())); map.put("pushMode", String.valueOf(invoice.getPushMode()));
map.put("invoiceType",String.valueOf(invoice.getInvoiceType())); map.put("invoiceType", String.valueOf(invoice.getInvoiceType()));
//订单信息 //订单信息
...@@ -154,40 +161,41 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -154,40 +161,41 @@ public class InvoiceDaoImpl implements InvoiceDao {
for (OrderData order : orders) { for (OrderData order : orders) {
HashMap<String, String> mx = new HashMap<>(); HashMap<String, String> mx = new HashMap<>();
mx.put("goodsName", invoice.getContent()); mx.put("goodsName", invoice.getContent());
mx.put("num",String.valueOf(order.getNum()) ); mx.put("num", String.valueOf(order.getNum()));
//单价含税标志,0:不含税,1:含税 //单价含税标志,0:不含税,1:含税
mx.put("withTaxFlag", String.valueOf(order.getWithTaxFlag())); mx.put("withTaxFlag", String.valueOf(order.getWithTaxFlag()));
mx.put("price", String.valueOf(order.getPrice())); mx.put("price", String.valueOf(order.getPrice()));
mx.put("taxRate", String.valueOf(order.getTaxRate())); mx.put("taxRate", String.valueOf(order.getTaxRate()));
mx.put("unit", order.getUnit()); mx.put("unit", order.getUnit());
mx.put("specType",order.getOrderName()); mx.put("specType", order.getOrderName());
arrayList.add(mx); arrayList.add(mx);
} }
String token = getTokenFP(); String token = getTokenFP();
String jsonString = JSON.toJSONString(orderMap); String jsonString = JSON.toJSONString(orderMap);
//调用第三方接口 //调用第三方接口
String result = sdk.sendPostSyncRequest(url, senid, appKey2, appSecret2,token , taxnum2, method, jsonString); String result = sdk.sendPostSyncRequest(url, senid, appKey2, appSecret2, token, taxnum2, method, jsonString);
log.info("result={}",result); log.info("result={}", result);
//把字符串json数据转换为map //把字符串json数据转换为map
JSONObject jsonObject = JSON.parseObject(result); JSONObject jsonObject = JSON.parseObject(result);
Map<String,String> data = (Map<String, String>) jsonObject.get("result"); Map<String, String> data = (Map<String, String>) jsonObject.get("result");
String invoiceSerialNum = data.get("invoiceSerialNum"); String invoiceSerialNum = data.get("invoiceSerialNum");
if (StringUtils.isBlank(invoiceSerialNum)){ if (StringUtils.isBlank(invoiceSerialNum)) {
log.error("失败原因={}",result); log.error("失败原因={}", result);
throw new BaseException("开票失败"); throw new BaseException("开票失败");
} }
return invoiceSerialNum; return invoiceSerialNum;
} }
@Override @Override
public String invoiceResult(String invoiceSerialNum) { public List<Map<String, Object>> invoiceResult(String invoiceSerialNum) {
NNOpenSDK sdk = NNOpenSDK.getIntance(); NNOpenSDK sdk = NNOpenSDK.getIntance();
// API方法名 // API方法名
String method = "nuonuo.electronInvoice.CheckEInvoice"; String method = "nuonuo.electronInvoice.CheckEInvoice";
HashMap<String, List<String>> map = new HashMap<>(); HashMap<String, List<String>> map = new HashMap<>();
ArrayList<String> arrayList = Lists.newArrayList(); ArrayList<String> arrayList = Lists.newArrayList();
arrayList.add(invoiceSerialNum); arrayList.add(invoiceSerialNum);
map.put("invoiceSerialNum",arrayList); map.put("invoiceSerialNum", arrayList);
String content = JSON.toJSONString(map); String content = JSON.toJSONString(map);
// SDK请求地址 // SDK请求地址
//沙箱 //沙箱
...@@ -197,16 +205,30 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -197,16 +205,30 @@ public class InvoiceDaoImpl implements InvoiceDao {
// 唯一标识,由企业自己生成32位随机码 // 唯一标识,由企业自己生成32位随机码
String senid = UUID.randomUUID().toString().replace("-", ""); String senid = UUID.randomUUID().toString().replace("-", "");
String result = sdk.sendPostSyncRequest(url, senid, appKey2, appSecret2, getTokenFP(), taxnum2, method, content);
System.out.println(result); String data = null;
return result; try {
data = sdk.sendPostSyncRequest(url, senid, appKey2, appSecret2, getTokenFP(), taxnum2, method, content);
} catch (Exception e) {
e.printStackTrace();
}
if (data!=null){
try {
JSONObject jsonObject = JSON.parseObject(data);
List<Map<String, Object>> mapList = (List<Map<String, Object>>) jsonObject.get("result");
return mapList;
} catch (Exception e) {
throw new BaseException("发票请求流水号错误");
}
}
return null;
} }
/** /**
* 获取极速开票token * 获取极速开票token
*/ */
private String getTokenJS() { private String getTokenJS() {
return getToken(appKey, appSecret); return getToken(appKey, appSecret);
} }
...@@ -220,7 +242,6 @@ public class InvoiceDaoImpl implements InvoiceDao { ...@@ -220,7 +242,6 @@ public class InvoiceDaoImpl implements InvoiceDao {
} }
private String getToken(String appKey, String appSecret) { private String getToken(String appKey, String appSecret) {
String token = (String) redisTemplate.opsForValue().get(appKey); String token = (String) redisTemplate.opsForValue().get(appKey);
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
......
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