parent
3288b0d7c1
commit
63857fd37a
@ -0,0 +1,37 @@ |
||||
package com.jianshui.common.utils; |
||||
|
||||
import org.springframework.beans.BeanWrapper; |
||||
import org.springframework.beans.BeanWrapperImpl; |
||||
|
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
|
||||
/** |
||||
* hutool工具类处理 |
||||
* kk |
||||
*/ |
||||
public class HutoolUtilsPro { |
||||
|
||||
|
||||
/** |
||||
* 修改BeanUtils.copy null属性覆盖的问题,判断null属性加入忽略列表 |
||||
* @param source |
||||
* @return |
||||
*/ |
||||
public static String[] getNullPropertyNames (Object source) { |
||||
final BeanWrapper src = new BeanWrapperImpl(source); |
||||
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); |
||||
|
||||
Set<String> emptyNames = new HashSet<String>(); |
||||
for(java.beans.PropertyDescriptor pd : pds) { |
||||
Object srcValue = src.getPropertyValue(pd.getName()); |
||||
if (srcValue == null) emptyNames.add(pd.getName()); |
||||
} |
||||
String[] result = new String[emptyNames.size()]; |
||||
return emptyNames.toArray(result); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -1,228 +0,0 @@ |
||||
package com.jianshui.invoice.service.impl.adapter.request; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.jianshui.common.core.domain.entity.Companyservice; |
||||
import com.jianshui.common.enums.ErrorCode; |
||||
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; |
||||
import com.jianshui.common.utils.IdcardUtils; |
||||
import com.jianshui.common.utils.StringUtils; |
||||
import com.jianshui.common.utils.encrypt.AisinoInvoiceDecryptUtil; |
||||
import com.jianshui.invoice.domain.BillDetail; |
||||
import com.jianshui.invoice.domain.BillInfo; |
||||
import com.jianshui.invoice.domain.Redinfo; |
||||
import com.jianshui.invoice.domain.Redinfodetail; |
||||
import com.jianshui.invoice.domain.dto.DownloadRedInfoDTO; |
||||
import com.jianshui.invoice.domain.dto.adapter.request.aisino_jn.HxBillDetailDTO; |
||||
import com.jianshui.invoice.domain.dto.adapter.request.aisino_jn.HxBillInfoDTO; |
||||
import com.jianshui.invoice.domain.dto.adapter.request.aisino_jn.HxRedInfoDTO; |
||||
import com.jianshui.invoice.domain.dto.adapter.request.aisino_jn.HxRedInfoDetailsDTO; |
||||
import com.jianshui.invoice.service.IInvoiceRequestService; |
||||
import com.jianshui.system.service.ICompanyserviceService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @Description 航信入口报文适配器 |
||||
* @Author 巩权林 |
||||
* @Date 2022/3/19 21:28 |
||||
**/ |
||||
@Slf4j |
||||
@Component("jn_jcsk_invoice_request_adapter") |
||||
public class JcskInvoiceRequestAdapterImpl implements IInvoiceRequestService { |
||||
|
||||
@Autowired |
||||
private ICompanyserviceService companyserviceService; |
||||
|
||||
/** |
||||
* 解密函数 |
||||
* |
||||
* @param request |
||||
* @param companyservice |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public JSONObject decrypt(HttpServletRequest request, Companyservice companyservice, String serviceKey) { |
||||
// 根据servletRequest获取原始请求报文
|
||||
// String rawInput = HttpHelper.getBodyString(request);
|
||||
// if (StringUtils.isEmpty(rawInput)) {
|
||||
// throw new JianshuiParamErrorException(ErrorCode.EMPTY_PARAMS,"invoice);
|
||||
// }
|
||||
// JSONObject rawJson = JSONObject.parseObject(rawInput);
|
||||
// 因为航信的报文都是Form,所以这里要按form的来
|
||||
//方式一:getParameterMap(),获得请求参数map
|
||||
Map<String, String[]> map = request.getParameterMap(); |
||||
//参数名称
|
||||
Set<String> key = map.keySet(); |
||||
//参数迭代器
|
||||
Iterator<String> iterator = key.iterator(); |
||||
// JSONObject rawJson = JSONObject.parseObject(JSONObject.toJSONString(params));
|
||||
JSONObject rawJson = new JSONObject(); |
||||
while (iterator.hasNext()) { |
||||
String k = iterator.next(); |
||||
rawJson.put(k, map.get(k)[0]); |
||||
} |
||||
|
||||
|
||||
if (StringUtils.isEmpty(rawJson)) { |
||||
throw new JianshuiParamErrorException(ErrorCode.ERROR_PARAMS, companyservice, "invoice"); |
||||
} |
||||
|
||||
String order = rawJson.getString("order"); |
||||
String identity = rawJson.getString("identity"); |
||||
|
||||
log.info("【航信转invoice请求适配器】客户请求报文原始数据:{},销方id:{},serviceKey:{}", rawJson, companyservice.getCompanyid(), serviceKey); |
||||
|
||||
// 开始解析报文
|
||||
if (order == null || "".equals(order.trim())) { |
||||
throw new JianshuiParamErrorException(ErrorCode.ERROR_PARAMS, companyservice, "invoice"); |
||||
} |
||||
|
||||
String JKey = companyservice.getSecret(); // 解密用的secret
|
||||
if (StringUtils.isEmpty(JKey)) { |
||||
throw new JianshuiParamErrorException(ErrorCode.IDENTITY_NOT_SET, companyservice, "jcsk"); |
||||
} |
||||
|
||||
// 平台解密
|
||||
try { |
||||
order = AisinoInvoiceDecryptUtil.decrypt(order, JKey); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
throw new JianshuiParamErrorException(ErrorCode.DECRYPT_ERROR, companyservice, "jcsk"); |
||||
} |
||||
|
||||
|
||||
log.info("销项报文:identity=" + identity + ",order=" + order); |
||||
|
||||
// 报文内容体
|
||||
JSONObject json = new JSONObject(); |
||||
try { |
||||
// 根据用户封装参数进行区别处理
|
||||
JSONObject orderJson = JSONObject.parseObject(order); |
||||
String myIdentity = orderJson.getString("identity"); |
||||
if (myIdentity != null) { |
||||
// order里面有identity的情况,取出来order
|
||||
JSONObject tempJson = new JSONObject(); |
||||
tempJson = orderJson.getJSONObject("order"); |
||||
if (tempJson != null) { |
||||
orderJson = tempJson; |
||||
} |
||||
} |
||||
|
||||
json = orderJson; |
||||
|
||||
// 如果是开票或者查询
|
||||
if (StringUtils.equals(serviceKey, "add") || StringUtils.equals(serviceKey, "query")) { |
||||
// 开始把航信报文转成billInfo
|
||||
HxBillInfoDTO hxBillInfo = json.toJavaObject(HxBillInfoDTO.class); |
||||
BillInfo billInfo = new BillInfo(); |
||||
BeanUtils.copyProperties(hxBillInfo, billInfo); |
||||
if(StringUtils.isNotEmpty(hxBillInfo.getEmail())){ |
||||
billInfo.setBuyerEmail(hxBillInfo.getEmail()); |
||||
} |
||||
if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { |
||||
String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); |
||||
if (StringUtils.isNotEmpty(bankNo)) { |
||||
String raw = billInfo.getBuyerAccount(); |
||||
billInfo.setBuyerAccount(bankNo); |
||||
billInfo.setBuyerBank(raw.replace(bankNo, "")); |
||||
} |
||||
} |
||||
// 处理detail
|
||||
List<HxBillDetailDTO> hxBillDetailList = hxBillInfo.getDetail(); |
||||
List<BillDetail> detailList = new ArrayList<>(); |
||||
if (hxBillDetailList != null && hxBillDetailList.size() > 0) { |
||||
for (HxBillDetailDTO detial : hxBillDetailList) { |
||||
BillDetail temp = new BillDetail(); |
||||
BeanUtils.copyProperties(detial, temp); |
||||
detailList.add(temp); |
||||
} |
||||
billInfo.setBillDetailList(detailList); |
||||
} |
||||
|
||||
if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { |
||||
String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); |
||||
if (StringUtils.isNotEmpty(bankNo)) { |
||||
String raw = billInfo.getBuyerAccount(); |
||||
billInfo.setBuyerAccount(bankNo); |
||||
billInfo.setBuyerBank(raw.replace(bankNo, "")); |
||||
} |
||||
} |
||||
// 处理销方信息
|
||||
if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) { |
||||
String bankNo = IdcardUtils.getBankNo(billInfo.getSellerAccount()); |
||||
if (StringUtils.isNotEmpty(bankNo)) { |
||||
String raw = billInfo.getSellerAccount(); |
||||
billInfo.setSellerAccount(bankNo); |
||||
billInfo.setSellerBank(raw.replace(bankNo, "")); |
||||
} |
||||
} |
||||
|
||||
json = (JSONObject) JSONObject.toJSON(billInfo); |
||||
} |
||||
|
||||
// 如果是redinfo
|
||||
if (StringUtils.equals(serviceKey, "add_redinfo")) { |
||||
// 开始把航信报文转成billInfo
|
||||
HxRedInfoDTO hxBillInfo = json.toJavaObject(HxRedInfoDTO.class); |
||||
Redinfo billInfo = new Redinfo(); |
||||
BeanUtils.copyProperties(hxBillInfo, billInfo); |
||||
|
||||
|
||||
// 处理detail
|
||||
List<HxRedInfoDetailsDTO> hxBillDetailList = hxBillInfo.getRedinfodetailList(); |
||||
List<Redinfodetail> detailList = new ArrayList<>(); |
||||
for (int i = 0; i < hxBillDetailList.size(); i++) { |
||||
HxRedInfoDetailsDTO detial = hxBillDetailList.get(i); |
||||
Redinfodetail temp = new Redinfodetail(); |
||||
BeanUtils.copyProperties(detial, temp); |
||||
temp.setIndex(i); |
||||
detailList.add(temp); |
||||
} |
||||
billInfo.setRedinfodetailList(detailList); |
||||
json = (JSONObject) JSONObject.toJSON(billInfo); |
||||
} |
||||
|
||||
// 如果是发票作废
|
||||
if (StringUtils.equals(serviceKey, "deprecate")) { |
||||
return json; |
||||
} |
||||
|
||||
// 如果是红字信息表下载
|
||||
if (StringUtils.equals(serviceKey, "download_redinfo")) { |
||||
DownloadRedInfoDTO downloadRedInfoDTO = json.toJavaObject(DownloadRedInfoDTO.class); |
||||
json = (JSONObject) JSONObject.toJSON(downloadRedInfoDTO); |
||||
return json; |
||||
} |
||||
|
||||
// 如果是发票打印
|
||||
if (StringUtils.equals(serviceKey, "batch_print")) { |
||||
// JSONArray detail = json.getJSONArray("dyfpxx");
|
||||
// for (int i = 0; i < detail.size(); i++) {
|
||||
// JSONObject temp = (JSONObject) detail.get(i);
|
||||
// String fplxdm = ElephantUtils.transElephantType(temp.getString("fpzldm"), 1);
|
||||
// temp.put("fpzldm", fplxdm);
|
||||
// detail.set(i, temp);
|
||||
// }
|
||||
return json; |
||||
} |
||||
|
||||
} catch (JianshuiParamErrorException e) { |
||||
throw e; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
throw new JianshuiParamErrorException(ErrorCode.DECRYPT_ERROR, companyservice, "invoice"); |
||||
} |
||||
|
||||
return json; |
||||
} |
||||
|
||||
@Override |
||||
public String covertMethodName(String method) { |
||||
return null; |
||||
} |
||||
} |
@ -1,246 +0,0 @@ |
||||
package com.jianshui.invoice.service.impl.adapter.response; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.jianshui.common.core.domain.AjaxResult; |
||||
import com.jianshui.common.core.domain.entity.Companyservice; |
||||
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; |
||||
import com.jianshui.common.utils.DictUtils; |
||||
import com.jianshui.common.utils.StringUtils; |
||||
import com.jianshui.common.utils.bean.BeanUtils; |
||||
import com.jianshui.invoice.domain.BillInfo; |
||||
import com.jianshui.invoice.domain.Invoice; |
||||
import com.jianshui.invoice.domain.InvoiceDetail; |
||||
import com.jianshui.invoice.domain.Redinfo; |
||||
import com.jianshui.invoice.domain.dto.HXResponse; |
||||
import com.jianshui.invoice.domain.dto.adapter.response.aisino_jn.AisinoJnInvoiceDetailResponse; |
||||
import com.jianshui.invoice.domain.dto.adapter.response.aisino_jn.AisinoJnInvoiceResponse; |
||||
import com.jianshui.invoice.service.IInvoiceResponseService; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Description 航信出口报文适配器 |
||||
* @Author 巩权林 |
||||
* @Date 2022/3/19 21:28 |
||||
**/ |
||||
@Component("jn_jcsk_invoice_response_adapter") |
||||
public class JcskInvoiceResponseAdapterImpl implements IInvoiceResponseService { |
||||
|
||||
@Override |
||||
public JSONObject response(HXResponse result, Companyservice companyservice, String query) { |
||||
|
||||
// 如果是开具
|
||||
if (StringUtils.equals("add", query)) { |
||||
return result; |
||||
} |
||||
|
||||
// 如果是发票查询
|
||||
if (StringUtils.equals("query", query)) { |
||||
// 判断有无data
|
||||
Object datas = result.getData(); |
||||
|
||||
// 如果datas不为Null
|
||||
if (datas != null) { |
||||
// 如果返回将诶过为invioce
|
||||
List<AisinoJnInvoiceResponse> responses = new ArrayList<>(); |
||||
if (datas instanceof List) { |
||||
for (int ij = 0; ij < ((List<?>) datas).size(); ij++) { |
||||
Object data = ((List<?>) datas).get(ij); |
||||
// 转为HxInvoice
|
||||
Invoice invoice = (Invoice) data; |
||||
if (invoice == null) { |
||||
continue; |
||||
} |
||||
AisinoJnInvoiceResponse invoiceResponse = new AisinoJnInvoiceResponse(); |
||||
BeanUtils.copyProperties(invoice, invoiceResponse); |
||||
String invoiceType = DictUtils.getDictLabel("invoice_type", invoice.getInvoiceType()); |
||||
if (invoiceType != null) { |
||||
invoiceResponse.setInvoiceType(invoiceType); |
||||
} |
||||
|
||||
// 处理发票状态
|
||||
|
||||
// 处理Detail
|
||||
List<InvoiceDetail> detailList = invoice.getInvoiceDetailList(); |
||||
if (detailList != null) { |
||||
List<AisinoJnInvoiceDetailResponse> invoiceDetailResponses = new ArrayList<>(); |
||||
for (int i = 0; i < detailList.size(); i++) { |
||||
AisinoJnInvoiceDetailResponse response = new AisinoJnInvoiceDetailResponse(); |
||||
InvoiceDetail tempDetail = detailList.get(i); |
||||
BeanUtils.copyProperties(tempDetail, response); |
||||
Integer hsbz = tempDetail.getHsbz(); |
||||
if (hsbz == 0) { |
||||
response.setHsbz("false"); |
||||
response.setTaxamt(null); |
||||
// 如果不含税
|
||||
} else { |
||||
// 如果含税
|
||||
response.setHsbz("true"); |
||||
response.setTaxfreeamt(response.getTaxamt()); |
||||
} |
||||
invoiceDetailResponses.add(response); |
||||
} |
||||
invoiceResponse.setInvoiceDetailList(invoiceDetailResponses); |
||||
} |
||||
responses.add(invoiceResponse); |
||||
} |
||||
|
||||
JSONObject queryResult = new JSONObject(); |
||||
queryResult.put("result", result.getMessage()); |
||||
queryResult.put("list", responses); |
||||
return queryResult; |
||||
} |
||||
|
||||
} |
||||
JSONObject queryResult = new JSONObject(); |
||||
queryResult.put("result", result.getMessage()); |
||||
queryResult.put("list", new ArrayList<>()); |
||||
} |
||||
|
||||
// 如果是开具红票
|
||||
if (StringUtils.equals("add_redinfo", query)) { |
||||
return result; |
||||
} |
||||
|
||||
// 如果是下载红票
|
||||
if (StringUtils.equals("download_redinfo", query)) { |
||||
|
||||
Object datas = result.getData(); |
||||
|
||||
// 如果datas不为Null
|
||||
if (datas != null) { |
||||
// 如果返回将诶过为invioce
|
||||
// List<AisinoJnInvoiceResponse> responses = new ArrayList<>();
|
||||
// if (datas instanceof List) {
|
||||
// }
|
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
// 如果是打印
|
||||
if (StringUtils.equals("printer", query)) { |
||||
|
||||
Object datas = result.getData(); |
||||
|
||||
// 如果datas不为Null
|
||||
if (datas != null) { |
||||
// 如果返回将诶过为invioce
|
||||
// List<AisinoJnInvoiceResponse> responses = new ArrayList<>();
|
||||
// if (datas instanceof List) {
|
||||
// }
|
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
// 作废查询
|
||||
if (StringUtils.equals("deprecate_query", query)) { |
||||
Object datas = result.getData(); |
||||
if (datas != null) { |
||||
JSONObject dataJson = (JSONObject) datas; |
||||
// String status = dataJson.getString("status");
|
||||
JSONObject result2 = new JSONObject(); |
||||
result2.put("message", "操作完成"); |
||||
result2.put("status", "0000"); |
||||
result2.put("data", dataJson); |
||||
// if (StringUtils.equals(status, "3")) {
|
||||
// result2.put("code", "0000");
|
||||
// result2.put("msg", "作废成功");
|
||||
// } else if (StringUtils.equals(status, "1")) {
|
||||
// result2.put("code", "9998");
|
||||
// result2.put("msg", "作废中");
|
||||
// } else {
|
||||
// result2.put("code", "9998");
|
||||
// result2.put("msg", "作废失败");
|
||||
// }
|
||||
return result2; |
||||
} |
||||
} |
||||
|
||||
if (StringUtils.equals("sign_e_seal", query)) { |
||||
AjaxResult resp = AjaxResult.success(); |
||||
Object data = result.getData(); |
||||
if (!StringUtils.equals("0000", result.getStatus())) { |
||||
resp = AjaxResult.error(result.getMessage()); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
JSONObject dataJson = (JSONObject) data; |
||||
if (StringUtils.equals("0000", dataJson.getString("CODE"))) { |
||||
// result.put("code", "200");
|
||||
// result.put("data", dataJson.getJSONObject("data"));
|
||||
resp.put("data", dataJson.getJSONObject("DATA")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
}else{ |
||||
// result.put("code", dataJson.getString("CODE"));
|
||||
// result.put("message", dataJson.getJSONObject("MESSAGE"));
|
||||
resp.put("code", dataJson.getString("CODE")); |
||||
resp.put("message", dataJson.getString("MESSAGE")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
} |
||||
if (StringUtils.equals("register_e_seal", query)) { |
||||
AjaxResult resp = AjaxResult.success(); |
||||
Object data = result.getData(); |
||||
if (!StringUtils.equals("0000", result.getStatus())) { |
||||
resp = AjaxResult.error(result.getMessage()); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
JSONObject dataJson = (JSONObject) data; |
||||
if (StringUtils.equals("0000", dataJson.getString("CODE"))) { |
||||
// result.put("code", "200");
|
||||
// result.put("data", dataJson.getJSONObject("data"));
|
||||
resp.put("data", dataJson.getJSONObject("DATA")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
}else{ |
||||
// result.put("code", dataJson.getString("CODE"));
|
||||
// result.put("message", dataJson.getJSONObject("MESSAGE"));
|
||||
resp.put("code", dataJson.getString("CODE")); |
||||
resp.put("message", dataJson.getString("MESSAGE")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
} |
||||
if (StringUtils.equals("create_e_seal", query)) { |
||||
AjaxResult resp = AjaxResult.success(); |
||||
Object data = result.getData(); |
||||
if (!StringUtils.equals("0000", result.getStatus())) { |
||||
resp = AjaxResult.error(result.getMessage()); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
JSONObject dataJson = (JSONObject) data; |
||||
if (StringUtils.equals("0000", dataJson.getString("CODE"))) { |
||||
// result.put("code", "200");
|
||||
// result.put("data", dataJson.getJSONObject("data"));
|
||||
resp.put("data", dataJson.getJSONObject("DATA")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
}else{ |
||||
// result.put("code", dataJson.getString("CODE"));
|
||||
// result.put("message", dataJson.getJSONObject("MESSAGE"));
|
||||
resp.put("code", dataJson.getString("CODE")); |
||||
resp.put("message", dataJson.getString("MESSAGE")); |
||||
return JSONObject.parseObject(JSONObject.toJSONString(resp)); |
||||
} |
||||
} |
||||
|
||||
|
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Object response(JianshuiParamErrorException result, Companyservice companyservice) { |
||||
// JSONObject myResult = new JSONObject();
|
||||
// myResult.put("status", result.getErrorCode());
|
||||
// myResult.put("message", result.getMsg());
|
||||
// return myResult;
|
||||
AjaxResult resp = AjaxResult.error(result.getErrorCode(), null); |
||||
resp.put("msg", result.getMsg()); |
||||
return resp; |
||||
} |
||||
|
||||
@Override |
||||
public AjaxResult callback(BillInfo billInfo, Invoice invoice, Redinfo redinfo, Companyservice companyservice, String src) { |
||||
return null; |
||||
} |
||||
} |
Loading…
Reference in new issue