diff --git a/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java b/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java index 8ac612da..21ee2bf4 100644 --- a/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java +++ b/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java @@ -140,7 +140,7 @@ public enum SNFplxEnum { return null; } - public String getFplxDm(String snFplxDm) { + public static String getFplxDm(String snFplxDm) { for (SNFplxEnum fplx : SNFplxEnum.values()) { if (fplx.getSnFplxDm() == snFplxDm) { return fplx.fplxDm; diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java index b9b6d7de..00103e84 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java @@ -1134,7 +1134,7 @@ public class InterfaceController extends AbstractController { } @RequestMapping(path = "/po",method={RequestMethod.POST,RequestMethod.GET}) public String po(@RequestBody String param,HttpServletRequest request){ - log.info("po接口调用开始,传参{}",JsonUtils.getInstance().toJsonString(request)); + log.info("po接口调用开始,传参{}",param); String token = request.getHeader("token"); if(org.apache.commons.lang3.StringUtils.isBlank(token) && !ConfigureConstant.POTOKEN.equals(token)){ return "非法请求,请停止访问!"; @@ -1142,9 +1142,10 @@ public class InterfaceController extends AbstractController { String resultString = ""; ErpInvoiceData requestParam = JsonUtils.getInstance().parseObject(param, ErpInvoiceData.class); //同步 凭证号 判断自动认证接口开发 - if("FI005".equals(requestParam.getIS_INPUT().getIFYWID())){ + if("FI847".equals(requestParam.getIS_INPUT().getIFYWID())){ resultString = receiveErpInvoiceMessage(requestParam); - }else if("FI110".equals(requestParam.getIS_INPUT().getIFYWID())){ + //进项税转出 + }else if("FI849".equals(requestParam.getIS_INPUT().getIFYWID())){ resultString = transferOut(requestParam); } return resultString; @@ -1184,8 +1185,19 @@ public class InterfaceController extends AbstractController { baseInvoiceEditVO.setOutStatus("1"); baseInvoiceEditVO.setOutTaxPeriod(outTaxPeriod); UserInfo userInfo = new UserInfo(); - String transfer = iReceiptOutService.transfer(erpInvoiceData,baseInvoiceEditVO, userInfo); - return transfer; + try{ + String transfer = iReceiptOutService.transfer(erpInvoiceData,baseInvoiceEditVO, userInfo); + return transfer; + }catch (Exception e){ + log.info(e.getMessage()); + EsOutPutResp es = new EsOutPutResp(); + es.setSAPKEY(erpInvoiceData.getIS_INPUT().getSAPKEY()); + es.setBSKEY(erpInvoiceData.getIS_INPUT().getBSKEY()); + es.setZTYPE("E"); + es.setZMESSAGE("系统内部错误"); + return JsonUtils.getInstance().toJsonString(es); + } + } } diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java index 770a7048..fe2bbc39 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java @@ -1,13 +1,16 @@ package com.dxhy.erp.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.dxhy.common.aspect.SysLog; import com.dxhy.common.constant.CommonConstants; import com.dxhy.common.controller.AbstractController; import com.dxhy.common.enums.FplxEnum; import com.dxhy.common.enums.SNFplxEnum; +import com.dxhy.common.jwt.IJWTInfo; import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.util.UserInfoUtil; +import com.dxhy.common.utils.BaseContextHandler; import com.dxhy.common.utils.R; import com.dxhy.erp.entity.sdny.*; import com.dxhy.erp.service.InvoiceQueryService; @@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.security.auth.message.config.AuthConfig; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; @@ -50,22 +54,6 @@ public class SDNYMainProcessController extends AbstractController { @ResponseBody @SysLog("发票查验") public ResponseEntity singleInvoiceCheck(@RequestBody Map pramsMap) { - // 入参统一在入口处理 - String userid = getLoginName(); - pramsMap.put("userid", userid); - String dbName = getUserInfo().getDbName(); - pramsMap.put("dbName", dbName); - pramsMap.put("saveHistory","Y"); - - pramsMap.put("company", getUserInfo().getCompany()); - - List gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg()); - if (gfshAll.size() > 0) { - pramsMap.put("taxNo", gfshAll.get(0)); - - } - pramsMap.put("purchaserTaxNo", pramsMap.get("purchaserTaxNo")); - InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); String fplxdm = iu.getFplxdm(); @@ -74,8 +62,6 @@ public class SDNYMainProcessController extends AbstractController { return ResponseEntity.ok(R.error("发票代码不能为空!")); } - pramsMap.put("invoiceType", iu.getFplxdm()); - if (pramsMap.get("invoiceNumber").isEmpty()) { return ResponseEntity.ok(R.error("发票号码不能为空!")); @@ -84,7 +70,7 @@ public class SDNYMainProcessController extends AbstractController { if (!pramsMap.get("billingDate").isEmpty()) { iu.setKprq(pramsMap.get("billingDate")); - pramsMap.put("invoiceDate", pramsMap.get("invoiceNumber")); + pramsMap.put("invoiceDate", pramsMap.get("billingDate")); if (!iu.kprqValid(null)) { pramsMap.put("invoiceDate", "开票日期格式错误!"); } @@ -92,12 +78,16 @@ public class SDNYMainProcessController extends AbstractController { return ResponseEntity.ok(R.error("开票日期不能为空!")); } - if (FplxEnum.ZP.getFplxDm().equals(pramsMap.get("invoiceType")) - || FplxEnum.JDC.getFplxDm().equals(pramsMap.get("invoiceType")) - || FplxEnum.DZZP.getFplxDm().equals(pramsMap.get("invoiceType")) - || FplxEnum.ESC.getFplxDm().equals(pramsMap.get("invoiceType")) - || FplxEnum.QDZZP.getFplxDm().equals(pramsMap.get("invoiceType")) - || FplxEnum.QDPP.getFplxDm().equals(pramsMap.get("invoiceType"))) { + if (pramsMap.get("invoiceType").isEmpty()) { + return ResponseEntity.ok(R.error("开票日期不能为空!")); + } + + if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) { if (pramsMap.get("totalAmount").isEmpty()) { return ResponseEntity.ok(R.error("金额不能为空!")); } @@ -107,8 +97,8 @@ public class SDNYMainProcessController extends AbstractController { } } - String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode"))+ pramsMap.get("invoiceNo"); - String notes = invoiceQueryService.checkingInvoiceInfo(dbName, uuid, getUserInfo()); + String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); + String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo()); if (notes != null) { return ResponseEntity.ok(R.error(notes)); } @@ -124,13 +114,23 @@ public class SDNYMainProcessController extends AbstractController { || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType")) ) { + //查验发票数据 - checkInvoiceResult = snPushCheckRecordService.checkInvoice(pramsMap, getUserInfo()); - }else{ - //价税分离 + try { + checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap); + } catch (Exception e) { + e.printStackTrace(); + } + + if (!checkInvoiceResult.containsKey("code")) { + return ResponseEntity.ok(R.ok().put("data", checkInvoiceResult)); + } + } else { + //价税分离 +// snPushCheckRecordService.valoremTaxCount(); } - return ResponseEntity.ok(R.ok().put("data", checkInvoiceResult)); + return ResponseEntity.ok(R.error().put("data", checkInvoiceResult)); } /** @@ -147,36 +147,44 @@ public class SDNYMainProcessController extends AbstractController { List gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg()); - - //String notes = invoiceQueryService.checkingInvoiceInfo(dbName, uuid, getUserInfo()); + String gfsh = ""; + if (gfshAll.size() > 0) { + gfsh = gfshAll.get(0); + } //入票池 + try { + snPushCheckRecordService.pushInvoiceToRecordInvoice(snRequestObject, gfsh, company); - //推送到SAP - List invoiceInfoList = snRequestObject.getInvoiceInfoList(); + //推送到SAP + List invoiceInfoList = snRequestObject.getInvoiceInfoList(); - String imageId = snRequestObject.getImageId(); + String imageId = snRequestObject.getImageId(); - for(SNInvoice invoice : invoiceInfoList) { - SNSAPObject object = convertToSapOnject(invoice,imageId); - JSONObject sapObj = (JSONObject) JSONObject.toJSON(object); + for (SNInvoice invoice : invoiceInfoList) { + SNSAPObject object = convertToSapOnject(invoice, imageId); + JSONObject sapObj = (JSONObject) JSONObject.toJSON(object); - String result = ""; - try { - //将信息推送到影像系统 - result = snPushCheckRecordService.pushCheckResultToSAP(sapObj); + String result = ""; + try { + //将信息推送到影像系统 + result = snPushCheckRecordService.pushCheckResultToSAP(sapObj); - return ResponseEntity.ok(R.ok().put("data", result)); - } catch (Exception e) { - e.printStackTrace(); - log.error("", e); - return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); + return ResponseEntity.ok(R.ok().put("data", result)); + } catch (Exception e) { + e.printStackTrace(); + log.error("", e); + return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); + } } + return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); + } catch (Exception e) { + e.printStackTrace(); } return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); } - private SNSAPObject convertToSapOnject(SNInvoice snInvoice,String imageId) { + private SNSAPObject convertToSapOnject(SNInvoice snInvoice, String imageId) { Date date = new Date(); @@ -230,7 +238,7 @@ public class SDNYMainProcessController extends AbstractController { info.setZBZ(snInvoice.getRemarks()); List invoiceLineList = snInvoice.getInvoiceLineList(); List sapInvoiceDetailList = new ArrayList<>(); - if(invoiceLineList != null && invoiceLineList.size() > 0){ + if (invoiceLineList != null && invoiceLineList.size() > 0) { SNInvoiceDetail snInvoiceDetail = invoiceLineList.get(0); String taxRate = snInvoiceDetail.getTaxRate(); info.setZSM(taxRate); diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/dao/BaseTDxTaxCurrentDao.java b/dxhy-erp/src/main/java/com/dxhy/erp/dao/BaseTDxTaxCurrentDao.java new file mode 100644 index 00000000..872b2e72 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/dao/BaseTDxTaxCurrentDao.java @@ -0,0 +1,20 @@ +package com.dxhy.erp.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.dxhy.erp.entity.BaseTDxTaxCurrent; +import org.apache.ibatis.annotations.Mapper; + +/** + * + * + * 企业税务信息表dao + * + * + * @author peipei.li + * @date 2019-04-23 + */ +@SuppressWarnings("AlibabaClassNamingShouldBeCamel") +@Mapper +public interface BaseTDxTaxCurrentDao extends BaseMapper { + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/dao/OrgUserInfoDao.java b/dxhy-erp/src/main/java/com/dxhy/erp/dao/OrgUserInfoDao.java index f843e55b..f55a6006 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/dao/OrgUserInfoDao.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/dao/OrgUserInfoDao.java @@ -4,6 +4,7 @@ import com.dxhy.erp.entity.sdny.BxwxEnterpriseUserEntity; import com.dxhy.erp.entity.sdny.OrgUserInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxRecordInvoice.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxRecordInvoice.java index 1046b110..e285d039 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxRecordInvoice.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxRecordInvoice.java @@ -464,5 +464,4 @@ public class BaseTDxRecordInvoice implements Serializable { */ private String inAccountStatus; - private String invoiceSource; } diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxTaxCurrent.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxTaxCurrent.java new file mode 100644 index 00000000..2de155d4 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseTDxTaxCurrent.java @@ -0,0 +1,106 @@ +package com.dxhy.erp.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * + * + * 企业税务信息表 + * + * @author peipei.li + * @date 2019-04-23 + */ +@SuppressWarnings("AlibabaClassNamingShouldBeCamel") +@Data +@TableName("t_dx_tax_current") +public class BaseTDxTaxCurrent implements Serializable { + + private static final long serialVersionUID = -6721685467254429845L; + + /** + * id + */ + private Long id; + + /** + * 税号 + */ + private String taxno; + + /** + * 企业名称 + */ + private String taxname; + + /** + * 当前税款所属期 + */ + private String currentTaxPeriod; + + /** + * 当前税款所属期可勾选发票的起始开票日期 + */ + private String selectStartDate; + + /** + * 当前税款所属期可勾选发票的截止开票日期 + */ + private String selectEndDate; + + /** + * 当前税款所属期可勾选发票操作截止日期 + */ + private String operationEndDate; + + /** + * 企业旧税号 + */ + private String oldTaxNo; + + /** + * 申报周期,值为3-季度/1-月 + */ + private String declarePeriod; + + /** + * 信用等级,值为a/b/c/d或者空 + */ + private String creditRating; + + /** + * update_time + */ + private Date updateTime; + + /** + * create_time + */ + private Date createTime; + + /** + * 锁定状态:0否;1是 + */ + private String latchStatus; + + /** + * 抵扣限额 + */ + private BigDecimal limitDkse; + + private String bussiPwd; + + private String newBussiPwd; + + private String companyType; + private String oilType; + private String taxpayerType; + private String syncTime; + private String indexInfo; + private String periodIndexInfo; + private String monthIndexInfo; +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiCheckInvoiceSingleRequest.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiCheckInvoiceSingleRequest.java new file mode 100644 index 00000000..7d02806a --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiCheckInvoiceSingleRequest.java @@ -0,0 +1,18 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class ApiCheckInvoiceSingleRequest { + + private String fpdm; + private String fphm; + private String fpje; + private String jym; + private String kprq; + private String fpzl; + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiRequest.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiRequest.java new file mode 100644 index 00000000..018ad86c --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiRequest.java @@ -0,0 +1,24 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +import java.util.UUID; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class ApiRequest { + + private String zipCode; + private String encryptCode; + private String dataExchangeId; + private String entCode; + private String content; + + public ApiRequest() { + zipCode = "0"; + encryptCode = "0"; + dataExchangeId = UUID.randomUUID().toString().replace("-", ""); + } +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiResponse.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiResponse.java new file mode 100644 index 00000000..319f7957 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiResponse.java @@ -0,0 +1,22 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class ApiResponse { + + private String zipCode; + private String encryptCode; + private String dataExchangeId; + private String entCode; + private String content; + private ApiReturnStateInfo returnStateInfo; + private String status; + private String error; + private String message; + private String timestamp; + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiReturnStateInfo.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiReturnStateInfo.java new file mode 100644 index 00000000..1e7c36f0 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/ApiReturnStateInfo.java @@ -0,0 +1,14 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class ApiReturnStateInfo { + + private String returnCode; + private String returnMessage; + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenRequest.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenRequest.java new file mode 100644 index 00000000..7f25b477 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenRequest.java @@ -0,0 +1,14 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class TokenRequest { + + private String appKey; + private String appSecret; + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenResponse.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenResponse.java new file mode 100644 index 00000000..b92588e4 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/kfpt/TokenResponse.java @@ -0,0 +1,18 @@ +package com.dxhy.erp.entity.kfpt; + +import lombok.Data; + +/** + * Created by rei on 2021/8/26. + */ +@Data +public class TokenResponse { + + private String access_token; + private String token_type; + private String expires_in; + private String scope; + private String error; + private String error_description; + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java index cdc87b90..d477eb45 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java @@ -3,17 +3,31 @@ package com.dxhy.erp.service; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dxhy.common.constant.DbConstant; import com.dxhy.common.datasource.config.DynamicContextHolder; -import com.dxhy.common.util.UserInfoUtil; +import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.vo.UserInfo; import com.dxhy.erp.dao.AreaDao; +import com.dxhy.erp.dao.BaseTDxRecordInvoiceDao; +import com.dxhy.erp.dao.BaseTDxTaxCurrentDao; import com.dxhy.erp.dao.OrgUserInfoDao; +import com.dxhy.erp.entity.BaseTDxRecordInvoice; +import com.dxhy.erp.entity.BaseTDxTaxCurrent; +import com.dxhy.erp.entity.kfpt.ApiCheckInvoiceSingleRequest; +import com.dxhy.erp.entity.kfpt.ApiRequest; +import com.dxhy.erp.entity.kfpt.ApiResponse; +import com.dxhy.erp.entity.kfpt.TokenResponse; import com.dxhy.erp.entity.sdny.InvoiceDetail; import com.dxhy.erp.entity.sdny.InvoiceInfo; +import com.dxhy.erp.entity.sdny.SNInvoice; +import com.dxhy.erp.entity.sdny.SNRequestObject; import com.dxhy.erp.entity.sdny.area.Area; import com.dxhy.erp.utils.*; +import com.dxhy.erp.utils.Base64; +import com.google.gson.JsonArray; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -23,9 +37,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.text.SimpleDateFormat; +import java.util.*; /** * 与山东能源交互数据主类 @@ -36,22 +49,45 @@ import java.util.Map; @SuppressWarnings("AlibabaUndefineMagicConstant") @Service @Slf4j -public class SNPushCheckRecordService extends AbstractServiceAdapter { +public class SNPushCheckRecordService extends AbstractServiceAdapter { @Value("${sdny.snYxUrl}") private String snYxUrl; + @Value("${params.api.invoiceCheckSingleUrl}") + private String invoiceCheckSingleUrl; + + @Value("${params.api.appKey}") + private String appKey; + + @Value("${params.api.appSecret}") + private String appSecret; + + @Value("${params.api.entCode}") + private String entCode; + + @Resource private InvoiceQueryUtil invoiceQueryUtil; @Resource - private AreaDao areaDao; + private ApiUtils apiUtils; @Resource + private IcpUtils icpUtils; + + @Autowired + private AreaDao areaDao; + + @Autowired private OrgUserInfoDao orgUserInfoDao; + @Resource + private BaseTDxTaxCurrentDao baseTDxTaxCurrentDao; + + @Resource + private BaseTDxRecordInvoiceDao baseTDxRecordInvoiceDao; + public String pushCheckResultToSAP(JSONObject result) throws Exception { - result.put("systemSign", ""); - result.put("roleIds", ""); log.info("获取角色请求参数:{} , 请求地址:{}", result, snYxUrl); String post = HttpUtil.post(snYxUrl, result, 30000); log.info("获取角色返回信息:{}", post); @@ -61,38 +97,235 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { return post; } + public String pushInvoiceToRecordInvoice(SNRequestObject snRequestObject,String taxNo,String company) throws Exception { + QueryWrapper currentWrapper = new QueryWrapper<>(); + currentWrapper.eq("taxno", taxNo); + DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ); + BaseTDxTaxCurrent current = baseTDxTaxCurrentDao.selectOne(currentWrapper); + + List invoiceInfoList = snRequestObject.getInvoiceInfoList(); + + if(invoiceInfoList != null && invoiceInfoList.size() > 0) { + + for(SNInvoice snInvoice : invoiceInfoList) { + + String fpdm = snInvoice.getInvoiceCode(); + String fphm = snInvoice.getInvoiceNumber(); + + QueryWrapper recordWrapper = new QueryWrapper<>(); + currentWrapper.eq("uuid", fpdm + fphm); + + BaseTDxRecordInvoice baseTDxRecordInvoice = baseTDxRecordInvoiceDao.selectOne(recordWrapper); + + + String kprq = snInvoice.getBillingDate(); + String je = snInvoice.getTotalAmount(); + String xfsh = snInvoice.getSalesTaxNo(); + String se = snInvoice.getAmountTax(); + String gfsbh = snInvoice.getPurchaserTaxNo(); + String gfmc = snInvoice.getPurchaserName(); + String invoiceType = snInvoice.getInvoiceType(); + + BaseTDxRecordInvoice recordInvoice = new BaseTDxRecordInvoice(); + recordInvoice.setUuid(fpdm + fphm); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + try { + recordInvoice.setInvoiceDate(sdf.parse(kprq)); + } catch (ParseException e) { + e.printStackTrace(); + } + recordInvoice.setInvoiceCode(fpdm); + recordInvoice.setInvoiceNo(fphm); + recordInvoice.setInvoiceAmount(new BigDecimal(je)); + recordInvoice.setTaxAmount(new BigDecimal(se)); + recordInvoice.setXfTaxNo(xfsh); + recordInvoice.setGfTaxNo(gfsbh); + recordInvoice.setGfName(gfmc); + recordInvoice.setRzlx("5"); + recordInvoice.setYqsqStatus("1"); + recordInvoice.setYqCurrentPeriod(current.getCurrentTaxPeriod()); + recordInvoice.setCreateDate(new Date()); + recordInvoice.setYqsqDate(new Date()); + recordInvoice.setSourceSystem("2"); + recordInvoice.setInvoiceStatus("0"); + recordInvoice.setInvoiceType(invoiceType); + recordInvoice.setCompany(company); + + if(baseTDxRecordInvoice != null) { + baseTDxRecordInvoiceDao.update(recordInvoice,recordWrapper); + }else{ + baseTDxRecordInvoiceDao.insert(recordInvoice); + } + } + } + + return ""; + } + public JSONObject checkInvoice(Map pramsMap, UserInfo userInfo) { // uuid = 发票代码+发票号码 - String uuid = (org.apache.commons.lang.StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); + String uuid = (org.apache.commons.lang.StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); - DynamicContextHolder.push(userInfo.getDbName() + DbConstant.BUSINESS_READ); + DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ); - List gfshAll = UserInfoUtil.getGfshAll(userInfo.getOrg()); +// List gfshAll = UserInfoUtil.getGfshAll(userInfo.getOrg()); String gfsh = ""; - if (gfshAll.size() > 0) { - gfsh = gfshAll.get(0); - } +// if (gfshAll.size() > 0) { +// gfsh = gfshAll.get(0); +// } + + gfsh = "91370000166120002R"; + + JSONObject queryInvoiceResult = invoiceQueryUtil.queryInvoice(pramsMap.get("invoiceCode"), - pramsMap.get("invoiceNo"), pramsMap.get("invoiceDate"), pramsMap.get("invoiceAmount"), pramsMap.get("checkCode"), - gfsh,"31"); + pramsMap.get("invoiceNumber"), pramsMap.get("billingDate"), pramsMap.get("totalAmount"), pramsMap.get("checkCode"), + gfsh, pramsMap.get("invoiceType")); String resultCode = queryInvoiceResult.getString("resultCode"); - DynamicContextHolder.push(userInfo.getDbName() + DbConstant.BUSINESS_WRITE); + DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE); // 调用查验接口失败,将签收状态更新到扫描表中或者insert数据到扫描表,然后return; - if (queryInvoiceResult.containsKey("returnCode")) { - log.error("发票号码:" + pramsMap.get("invoiceNo") + "签收失败,失败原因:" + queryInvoiceResult.getString("returnMessage")); - return queryInvoiceResult; - } - if (!"0001".equals(resultCode)) { - // 接口通过但,调用返回失败 - log.error("发票号码:" + pramsMap.get("invoiceNo") + "签收失败,失败原因:" + queryInvoiceResult.getString("resultTip")); + if (queryInvoiceResult.containsKey("returnCode") && !"0001".equals(resultCode)) { + log.error("发票号码:" + pramsMap.get("invoiceNo") + "查验失败,失败原因:" + queryInvoiceResult.getString("returnMessage")); return queryInvoiceResult; } + + return queryInvoiceResult; } + public JSONObject singleCheckInvoice(Map pramsMap) throws Exception{ + + //1.封装查验参数 + ApiRequest apiRequest = new ApiRequest(); + apiRequest.setEntCode(entCode); + + InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); + String fplxdm = iu.getFplxdm(); + + String snIinvoiceType = pramsMap.get("invoiceType"); + + ApiCheckInvoiceSingleRequest request = new ApiCheckInvoiceSingleRequest(); + request.setFphm(pramsMap.get("invoiceNumber")); + request.setFpdm(pramsMap.get("invoiceCode")); + request.setFpje(pramsMap.get("totalAmount")); + request.setKprq(pramsMap.get("billingDate")); + request.setJym(pramsMap.get("checkCode")); + request.setFpzl(fplxdm); + + String check = JSONObject.toJSONString(request); + + + //2.获取token + TokenResponse token = apiUtils.getToken(appKey, appSecret); + String access_token = token.getAccess_token(); + + //3.调用开放平台查验接口 + ApiResponse apiResponse = apiUtils.callApi(invoiceCheckSingleUrl, entCode, request, access_token, apiRequest.getDataExchangeId()); + + //4.封装返回参数 + JSONObject jsonObject = new JSONObject(); + if (StringUtils.isNoneBlank(apiResponse.getContent())) + jsonObject = convertToSnObject(apiResponse.getContent(), jsonObject, snIinvoiceType); + + + return jsonObject; + } + + private JSONObject convertToSnObject(String content, JSONObject jsonObject, String invoiceType) { + + String con = new String(Base64.decode(content)); + HashMap contentMap = JSONObject.parseObject(con, HashMap.class); + + if ("0000".equals(contentMap.get("code"))) { + + HashMap invoiceData = JSONObject.parseObject(contentMap.get("data").toString(), HashMap.class); + if("0001".equals(invoiceData.get("cyjg"))) { + jsonObject.put("invoiceType", invoiceType); + jsonObject.put("administrativeDivisionNo", ""); + jsonObject.put("administrativeDivisionName", ""); + + jsonObject.put("invoiceCode", invoiceData.get("fpdm")); + jsonObject.put("invoiceNumber", invoiceData.get("fphm")); + jsonObject.put("billingDate", invoiceData.get("kprq")); + jsonObject.put("purchaserName", invoiceData.get("gmfmc")); + jsonObject.put("purchaserTaxNo", invoiceData.get("gmfsbh")); + jsonObject.put("purchaserBank", invoiceData.get("gmfyhzh")); + jsonObject.put("purchaserAddressPhone", invoiceData.get("gmfdzdh")); + jsonObject.put("salesName", invoiceData.get("xhfmc")); + jsonObject.put("salesTaxNo", invoiceData.get("xhfsbh")); + jsonObject.put("salesAddressPhone", invoiceData.get("xhfdzdh")); + jsonObject.put("salesBank", invoiceData.get("xhfyhzh")); + jsonObject.put("totalAmount", invoiceData.get("totalAmount")); + jsonObject.put("totalTax", invoiceData.get("fpse")); + jsonObject.put("amountTax", invoiceData.get("jshj")); + jsonObject.put("amountTaxCN", ""); + jsonObject.put("checkCode", invoiceData.get("jym")); + jsonObject.put("state", invoiceData.get("zfbz")); + jsonObject.put("carrierName", invoiceData.get("cyrmc")); + jsonObject.put("carrierTaxNo", invoiceData.get("cyrsbh")); + jsonObject.put("draweeName", invoiceData.get("spfmc")); + jsonObject.put("draweeTaxNo", invoiceData.get("spfsbh")); + jsonObject.put("cargoInformation", invoiceData.get("ysgwxx")); + jsonObject.put("transportRoute", invoiceData.get("qydjyddd")); + jsonObject.put("machineCode", invoiceData.get("skph")); + jsonObject.put("tonnage", invoiceData.get("ccdw")); + jsonObject.put("taxAuthorityNo", invoiceData.get("zgswjgdm")); + jsonObject.put("taxAuthorityName", invoiceData.get("zgswjgmc")); + jsonObject.put("remarks", invoiceData.get("bz")); + jsonObject.put("vehicleType", invoiceData.get("cllx")); + jsonObject.put("brandModel", invoiceData.get("cpxh")); + jsonObject.put("originPlace", invoiceData.get("cd")); + jsonObject.put("certificateNo", invoiceData.get("hgzs")); + jsonObject.put("inspectionListNo", invoiceData.get("sjdh")); + jsonObject.put("engineNo", invoiceData.get("fdjhm")); + jsonObject.put("vehicleNo", invoiceData.get("clsbh")); + jsonObject.put("importCertificateNo", invoiceData.get("jszmsh")); + jsonObject.put("paymentVoucherNo", invoiceData.get("wspzhm")); + jsonObject.put("passengersLimited", invoiceData.get("xcrs")); + jsonObject.put("tollSign", invoiceData.get("txfbz")); + jsonObject.put("zeroTaxRateSign", invoiceData.get("lslbs")); + jsonObject.put("source", ""); + jsonObject.put("idcardNo", invoiceData.get("sfzh")); + + List> returnDetailList = new ArrayList<>(); + JSONArray detailList = (JSONArray) invoiceData.get("detailList"); + for (int i = 0; i < detailList.size(); i++) { + JSONObject detail = (JSONObject) detailList.get(i); + Map snDetailMap = new HashMap(); + snDetailMap.put("rowNo", ++i + ""); + snDetailMap.put("commodityCode", detail.getString("mxbh")); + snDetailMap.put("commodityName", detail.getString("hwmc")); + snDetailMap.put("specificationModel", detail.getString("ggxh")); + snDetailMap.put("unit", detail.getString("jldw")); + snDetailMap.put("quantity", detail.getString("spsl")); + snDetailMap.put("unitPrice", detail.getString("hsdj")); + snDetailMap.put("amount", detail.getString("je")); + snDetailMap.put("taxRate", detail.getString("sl")); + snDetailMap.put("tax", detail.getString("se")); + snDetailMap.put("currentDateEnd", detail.getString("txrqz")); + snDetailMap.put("currentDateStart", detail.getString("txrqq")); + snDetailMap.put("licensePlateNum", detail.getString("cph")); + snDetailMap.put("type", detail.getString("lx")); + + returnDetailList.add(snDetailMap); + } + + jsonObject.put("invoiceLineList", returnDetailList); + }else{ + jsonObject.put("cyjg",invoiceData.get("cyjg")); + jsonObject.put("cyjgxx",invoiceData.get("cyjgxx")); + } + + } else { + jsonObject.put("code", contentMap.get("code")); + jsonObject.put("message", contentMap.get("message")); + } + + return jsonObject; + } + /** * 客票价税计算 @@ -213,7 +446,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { */ private ServiceResult checkIsDeduction(InvoiceInfo invoiceInfo, String enterpriseId) throws ParseException { try { - String result = verifyInfo( invoiceInfo); + String result = verifyInfo(invoiceInfo); if (!CommonEnum.RESPONSE_INTERFACE_STATUS_CODE_SUCCESS.equals(result)) { return fail(result); } @@ -331,7 +564,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { result = "出发或到达城市不符合标准"; } } - return result; + return result; } /** diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/CheckIpBlocAppidServiceImpl.java b/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/CheckIpBlocAppidServiceImpl.java index 5d4bd1f3..fd122fa8 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/CheckIpBlocAppidServiceImpl.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/CheckIpBlocAppidServiceImpl.java @@ -14,7 +14,6 @@ import com.dxhy.erp.dao.SysDeptDao; import com.dxhy.erp.model.ReturnStateInfo; import com.dxhy.erp.model.auth.InterfaceCode; import com.dxhy.erp.service.CheckIpBlocAppidService; -import com.dxhy.erp.utils.IpUtil; import lombok.extern.slf4j.Slf4j; @@ -42,7 +41,7 @@ public class CheckIpBlocAppidServiceImpl implements CheckIpBlocAppidService { public String getIp(HttpServletRequest request) { String remoteAddr; String remoteAddr1 = request.getHeader("X-Real-IP"); - if (remoteAddr1 != null && !"".equals(remoteAddr1) && IpUtil.isboolIp(remoteAddr1)) { + if (remoteAddr1 != null && !"".equals(remoteAddr1)) { remoteAddr = remoteAddr1; } else { remoteAddr = request.getRemoteAddr(); diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/ReceiptOutServiceImpl.java b/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/ReceiptOutServiceImpl.java index bb833462..e556be35 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/ReceiptOutServiceImpl.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/service/impl/ReceiptOutServiceImpl.java @@ -17,13 +17,16 @@ import com.dxhy.erp.model.ErpInvoiceData; import com.dxhy.erp.model.EsOutPutResp; import com.dxhy.erp.service.BaseIReceiptInvoiceService; import com.dxhy.erp.service.IReceiptOutService; +import com.dxhy.erp.utils.JsonUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -42,6 +45,9 @@ public class ReceiptOutServiceImpl extends MpBaseServiceImpl invoices = baseIReceiptInvoiceService.selectByUuids(ids); + if(CollectionUtils.isEmpty(invoices)){ + es.setZTYPE("E"); + es.setZMESSAGE("底账数据不存在"); + return JsonUtils.getInstance().toJsonString(es); + } // second:根据uuids查询出转出明细并转为map,key=uuid ,value=转出明细 List outs = listByUuids(ids); Map outMap = @@ -73,7 +84,7 @@ public class ReceiptOutServiceImpl extends MpBaseServiceImpl调用开放平台获取token异常:", e); + } finally { + log.info("<线程{}>interface={}|param={}|result={}|responseTime={}", + Thread.currentThread().getId(), url, body, result, new Duration(start, DateTime.now()).getMillis()); + } + return JSONObject.parseObject(result, TokenResponse.class); + } + + + public ApiResponse callApi(String url, String entCode, Object content, String accessToken, String requestId) { + final DateTime start = DateTime.now(); + ApiRequest apiRequest = new ApiRequest(); + apiRequest.setContent(Base64.encode(JSONObject.toJSONBytes(content))); + apiRequest.setEntCode(entCode); + apiRequest.setDataExchangeId(requestId); + String body = JSONObject.toJSONString(apiRequest); + url = url + accessToken; + String result = null; + try { + result = HttpClientUtils.post(url, body, contentType, charset, connTimeout, readTimeout); + } catch (Exception e) { + log.error("<线程" + Thread.currentThread().getId() + ">调用开放平台业务接口异常:", e); + } finally { + log.info("<线程{}>interface={}|param={}|result={}|responseTime={}", + Thread.currentThread().getId(), url, body, result, new Duration(start, DateTime.now()).getMillis()); + } + ApiResponse apiResponse = JSONObject.parseObject(result, ApiResponse.class); + return apiResponse; + + } + + + public TokenResponse getToken(String appKey, String appSecret) { + TokenRequest tokenRequest = new TokenRequest(); + tokenRequest.setAppKey(appKey); + tokenRequest.setAppSecret(appSecret); + TokenResponse tokenResponse = callToken(tokenUrl, tokenRequest); + if (tokenResponse != null && StringUtils.isEmpty(tokenResponse.getError())) { + return tokenResponse; + } else { + return null; + } + } + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/utils/Base64.java b/dxhy-erp/src/main/java/com/dxhy/erp/utils/Base64.java new file mode 100644 index 00000000..836740b2 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/utils/Base64.java @@ -0,0 +1,271 @@ +package com.dxhy.erp.utils; + +public final class Base64 { + + static private final int BASELENGTH = 128; + static private final int LOOKUPLENGTH = 64; + static private final int TWENTYFOURBITGROUP = 24; + static private final int EIGHTBIT = 8; + static private final int SIXTEENBIT = 16; + static private final int SIXBIT = 6; + static private final int FOURBYTE = 4; + static private final int SIGN = -128; + static private final char PAD = '='; + static private final boolean fDebug = false; + static final private byte [] base64Alphabet = new byte[BASELENGTH]; + static final private char [] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; + + static { + + for (int i = 0; i < BASELENGTH; ++i) { + base64Alphabet[i] = -1; + } + for (int i = 'Z'; i >= 'A'; i--) { + base64Alphabet[i] = (byte) (i-'A'); + } + for (int i = 'z'; i>= 'a'; i--) { + base64Alphabet[i] = (byte) ( i-'a' + 26); + } + + for (int i = '9'; i >= '0'; i--) { + base64Alphabet[i] = (byte) (i-'0' + 52); + } + + base64Alphabet['+'] = 62; + base64Alphabet['/'] = 63; + + for (int i = 0; i<=25; i++) + lookUpBase64Alphabet[i] = (char)('A'+i); + + for (int i = 26, j = 0; i<=51; i++, j++) + lookUpBase64Alphabet[i] = (char)('a'+ j); + + for (int i = 52, j = 0; i<=61; i++, j++) + lookUpBase64Alphabet[i] = (char)('0' + j); + lookUpBase64Alphabet[62] = (char)'+'; + lookUpBase64Alphabet[63] = (char)'/'; + + } + + protected static boolean isWhiteSpace(char octect) { + return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); + } + + protected static boolean isPad(char octect) { + return (octect == PAD); + } + + protected static boolean isData(char octect) { + return (octect < BASELENGTH && base64Alphabet[octect] != -1); + } + + protected static boolean isBase64(char octect) { + return (isWhiteSpace(octect) || isPad(octect) || isData(octect)); + } + + /** + * Encodes hex octects into Base64 + * + * @param binaryData Array containing binaryData + * @return Encoded Base64 array + */ + public static String encode(byte[] binaryData) { + + if (binaryData == null) + return null; + + int lengthDataBits = binaryData.length*EIGHTBIT; + if (lengthDataBits == 0) { + return ""; + } + + int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP; + int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP; + int numberQuartet = fewerThan24bits != 0 ? numberTriplets+1 : numberTriplets; + char encodedData[] = null; + + encodedData = new char[numberQuartet*4]; + + byte k=0, l=0, b1=0,b2=0,b3=0; + + int encodedIndex = 0; + int dataIndex = 0; + if (fDebug) { + System.out.println("number of triplets = " + numberTriplets ); + } + + for (int i=0; i>4 ) ; + decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); + decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); + } + + if (!isData( (d1 = base64Data[dataIndex++]) ) || + !isData( (d2 = base64Data[dataIndex++]) )) { + return null;//if found "no data" just return null + } + + b1 = base64Alphabet[d1]; + b2 = base64Alphabet[d2]; + + d3 = base64Data[dataIndex++]; + d4 = base64Data[dataIndex++]; + if (!isData( (d3 ) ) || + !isData( (d4 ) )) {//Check if they are PAD characters + if (isPad( d3 ) && isPad( d4)) { //Two PAD e.g. 3c[Pad][Pad] + if ((b2 & 0xf) != 0)//last 4 bits should be zero + return null; + byte[] tmp = new byte[ i*3 + 1 ]; + System.arraycopy( decodedData, 0, tmp, 0, i*3 ); + tmp[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ; + return tmp; + } else if (!isPad( d3) && isPad(d4)) { //One PAD e.g. 3cQ[Pad] + b3 = base64Alphabet[ d3 ]; + if ((b3 & 0x3 ) != 0)//last 2 bits should be zero + return null; + byte[] tmp = new byte[ i*3 + 2 ]; + System.arraycopy( decodedData, 0, tmp, 0, i*3 ); + tmp[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ); + tmp[encodedIndex] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); + return tmp; + } else { + return null;//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data + } + } else { //No PAD e.g 3cQl + b3 = base64Alphabet[ d3 ]; + b4 = base64Alphabet[ d4 ]; + decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ; + decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); + decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); + + } + + return decodedData; + } + + /** + * remove WhiteSpace from MIME containing encoded Base64 data. + * + * @param data the byte array of base64 data (with WS) + * @return the new length + */ + protected static int removeWhiteSpace(char[] data) { + if (data == null) + return 0; + + // count characters that's not whitespace + int newSize = 0; + int len = data.length; + for (int i = 0; i < len; i++) { + if (!isWhiteSpace(data[i])) + data[newSize++] = data[i]; + } + return newSize; + } +} + diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/utils/HttpClientUtils.java b/dxhy-erp/src/main/java/com/dxhy/erp/utils/HttpClientUtils.java new file mode 100644 index 00000000..1090a627 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/utils/HttpClientUtils.java @@ -0,0 +1,228 @@ +package com.dxhy.erp.utils; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.config.RequestConfig.Builder; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.conn.ssl.X509HostnameVerifier; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLException; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocket; +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.security.GeneralSecurityException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +public class HttpClientUtils { + + public static final int connTimeout = 10000; + public static final int readTimeout = 10000; + public static final String charset = "UTF-8"; + private static HttpClient client = null; + + static { + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + cm.setMaxTotal(1000); + cm.setDefaultMaxPerRoute(500); + client = HttpClients.custom().setConnectionManager(cm).build(); + } + + public static String postParameters(String url, String parameterStr) throws ConnectTimeoutException, SocketTimeoutException, Exception { + return post(url, parameterStr, "application/json", charset, connTimeout, readTimeout); + } + + public static String get(String url) throws Exception { + return get(url, charset, null, null); + } + + public static String get(String url, String charset) throws Exception { + return get(url, charset, connTimeout, readTimeout); + } + + /** + * 发送一个 Post 请求, 使用指定的字符集编码. + * + * @param url + * @param body RequestBody + * @param mimeType 例如 application/xml "application/x-www-form-urlencoded" a=1&b=2&c=3 + * @param charset 编码 + * @param connTimeout 建立链接超时时间,毫秒. + * @param readTimeout 响应超时时间,毫秒. + * @return ResponseBody, 使用指定的字符集编码. + * @throws ConnectTimeoutException 建立链接超时异常 + * @throws SocketTimeoutException 响应超时 + * @throws Exception + */ + public static String post(String url, String body, String mimeType, String charset, Integer connTimeout, Integer readTimeout) + throws ConnectTimeoutException, SocketTimeoutException, Exception { + HttpClient client = null; + HttpPost post = new HttpPost(url); + String result = ""; + try { + if (StringUtils.isNotBlank(body)) { + HttpEntity entity = new StringEntity(body, ContentType.create(mimeType, charset)); + post.setEntity(entity); + } + // 设置参数 + Builder customReqConf = RequestConfig.custom(); + if (connTimeout != null) { + customReqConf.setConnectTimeout(connTimeout); + } + if (readTimeout != null) { + customReqConf.setSocketTimeout(readTimeout); + } + post.setConfig(customReqConf.build()); + + HttpResponse res; + if (url.startsWith("https")) { + // 执行 Https 请求. + client = createSSLInsecureClient(); + res = client.execute(post); + } else { + // 执行 Http 请求. + client = HttpClientUtils.client; + res = client.execute(post); + } + result = IOUtils.toString(res.getEntity().getContent(), charset); + } finally { + post.releaseConnection(); + if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) { + ((CloseableHttpClient) client).close(); + } + } + return result; + } + + /** + * 发送一个 GET 请求 + * + * @param url + * @param charset + * @param connTimeout 建立链接超时时间,毫秒. + * @param readTimeout 响应超时时间,毫秒. + * @return + * @throws ConnectTimeoutException 建立链接超时 + * @throws SocketTimeoutException 响应超时 + * @throws Exception + */ + public static String get(String url, String charset, Integer connTimeout, Integer readTimeout) + throws ConnectTimeoutException, SocketTimeoutException, Exception { + + HttpClient client = null; + HttpGet get = new HttpGet(url); + get.setHeader("Authorization", "pq8fTpZWeWv8"); + String result = ""; + try { + // 设置参数 + Builder customReqConf = RequestConfig.custom(); + if (connTimeout != null) { + customReqConf.setConnectTimeout(connTimeout); + } + if (readTimeout != null) { + customReqConf.setSocketTimeout(readTimeout); + } + get.setConfig(customReqConf.build()); + + HttpResponse res = null; + + if (url.startsWith("https")) { + // 执行 Https 请求. + client = createSSLInsecureClient(); + res = client.execute(get); + } else { + // 执行 Http 请求. + client = HttpClientUtils.client; + res = client.execute(get); + } + + result = IOUtils.toString(res.getEntity().getContent(), charset); + } finally { + get.releaseConnection(); + if (url.startsWith("https") && client != null && client instanceof CloseableHttpClient) { + ((CloseableHttpClient) client).close(); + } + } + return result; + } + + /** + * 从 response 里获取 charset + * + * @param ressponse + * @return + */ + @SuppressWarnings("unused") + private static String getCharsetFromResponse(HttpResponse ressponse) { + // Content-Type:text/html; charset=GBK + if (ressponse.getEntity() != null && ressponse.getEntity().getContentType() != null && ressponse.getEntity().getContentType().getValue() != null) { + String contentType = ressponse.getEntity().getContentType().getValue(); + if (contentType.contains("charset=")) { + return contentType.substring(contentType.indexOf("charset=") + 8); + } + } + return null; + } + + /** + * 创建 SSL连接 + * + * @return + * @throws GeneralSecurityException + */ + private static CloseableHttpClient createSSLInsecureClient() throws GeneralSecurityException { + try { + SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { + public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { + return true; + } + }).build(); + + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new X509HostnameVerifier() { + + @Override + public boolean verify(String arg0, SSLSession arg1) { + return true; + } + + @Override + public void verify(String host, SSLSocket ssl) + throws IOException { + } + + @Override + public void verify(String host, X509Certificate cert) + throws SSLException { + } + + @Override + public void verify(String host, String[] cns, + String[] subjectAlts) throws SSLException { + } + + }); + + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + + } catch (GeneralSecurityException e) { + throw e; + } + } + +} \ No newline at end of file diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/utils/IcpUtils.java b/dxhy-erp/src/main/java/com/dxhy/erp/utils/IcpUtils.java new file mode 100644 index 00000000..cf7243e4 --- /dev/null +++ b/dxhy-erp/src/main/java/com/dxhy/erp/utils/IcpUtils.java @@ -0,0 +1,33 @@ +package com.dxhy.erp.utils; + +import com.dxhy.erp.entity.kfpt.ApiCheckInvoiceSingleRequest; +import com.dxhy.erp.entity.kfpt.ApiResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class IcpUtils { + + @Value("${params.api.invoiceCheckSingleUrl}") + private String invoiceCheckSingleUrl; + + @Autowired + private ApiUtils apiUtils; + + /** + * 调用开放平台单张发票查验 + * + * @param requestId + * @param singleInvoiceRequest + * @param taxpayerId + * @return InvoiceCheckResponse + */ + public ApiResponse callSingleCheck(String requestId, ApiCheckInvoiceSingleRequest singleInvoiceRequest, String taxpayerId, String access_token) { + ApiResponse apiResponse = apiUtils.callApi(invoiceCheckSingleUrl, taxpayerId, singleInvoiceRequest, access_token, requestId); + return apiResponse; + } + +} diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/utils/IpUtil.java b/dxhy-erp/src/main/java/com/dxhy/erp/utils/IpUtil.java deleted file mode 100644 index 83236a83..00000000 --- a/dxhy-erp/src/main/java/com/dxhy/erp/utils/IpUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.dxhy.erp.utils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author dxhy - */ -public class IpUtil { - - /** * 判断是否为合法IP * @return the ip */ - public static boolean isboolIp(String ipAddress) { - String ip = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}"; - Pattern pattern = Pattern.compile(ip); - Matcher matcher = pattern.matcher(ipAddress); - return matcher.matches(); - } -}