From 7df7d9dcff81c9615df310864106eb9a2e65dfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=98=8E=E6=85=A7?= <1191093413@qq.com> Date: Fri, 26 Apr 2024 11:11:21 +0800 Subject: [PATCH] =?UTF-8?q?release:=E5=89=8D=E7=AB=AF=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=AE=80=E7=A8=8E=E5=AF=B9=E6=8E=A5=E5=A4=A7=E8=B1=A1=E7=99=BB?= =?UTF-8?q?=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invoice/v1/InvoiceFrontController.java | 201 ++++++++++++++++++ .../jianshui/common/constant/PersonList.java | 37 ++++ .../service/ElephantInvoiceService.java | 20 ++ .../impl/ElephantInvoiceServiceImpl.java | 149 +++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceFrontController.java create mode 100644 jianshui-common/src/main/java/com/jianshui/common/constant/PersonList.java create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/service/ElephantInvoiceService.java create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java diff --git a/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceFrontController.java b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceFrontController.java new file mode 100644 index 0000000..e6e1afd --- /dev/null +++ b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceFrontController.java @@ -0,0 +1,201 @@ +package com.jianshui.api.controller.http.invoice.v1; + +import com.alibaba.fastjson.JSONObject; +import com.jianshui.common.core.domain.AjaxResult; +import com.jianshui.common.core.domain.entity.Companyservice; +import com.jianshui.common.enums.ErrorCode; +import com.jianshui.common.utils.StringUtils; +import com.jianshui.invoice.service.ElephantInvoiceService; +import com.jianshui.system.service.ICompanyserviceService; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@Slf4j +@RestController +@RequestMapping("/api/invoice/front/v1") +public class InvoiceFrontController { + + @Autowired + private ICompanyserviceService iCompanyserviceService; + + @Autowired + private ElephantInvoiceService elephantInvoiceService; + + + /** + * 数电登录接口(前端使用) + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true), + @ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true), + @ApiImplicitParam(name = "params", value = "请求体", dataType = "java.lang.String", required = true) + }) + @PostMapping("/rpaLogin/{identity}/{secret}") + public Object rpaLogin(@RequestBody Map params,@PathVariable("identity") String identity, @PathVariable("secret") String secret) { + + JSONObject paramJson = new JSONObject(params); + + log.debug("rpaLogin param{} identity:{} secret:{}", paramJson.toJSONString(), identity, secret); + + //参数校验 + if (StringUtils.isBlank(identity)){ + return AjaxResult.error("公司ID不能为空"); + } + + if (StringUtils.isBlank(secret)){ + return AjaxResult.error("公司Key不能为空"); + } + + + if (StringUtils.isBlank(paramJson.getString("yhm"))){ + return AjaxResult.error("电子税局登录名不能为空"); + } + + if (StringUtils.isBlank(paramJson.getString("mm"))){ + return AjaxResult.error("电子税局密码不能为空"); + } + //方法名处理 + if (StringUtils.isBlank(paramJson.getString("ffm"))){ + return AjaxResult.error("方法名不能为空"); + } + + if ("0".equals(paramJson.getString("ffm"))){ + paramJson.put("ffm","login"); + } + if ("1".equals(paramJson.getString("ffm"))){ + paramJson.put("ffm","send_sms"); + } + if ("2".equals(paramJson.getString("ffm"))){ + if (StringUtils.isBlank(paramJson.getString("zrrlx"))){ + return AjaxResult.error("责任人类型不能为空"); + } + paramJson.put("ffm","select_zrrlx"); + } + if ("3".equals(paramJson.getString("ffm"))){ + if (StringUtils.isBlank(paramJson.getString("dxyzm"))){ + return AjaxResult.error("短信验证码不能为空"); + } + paramJson.put("ffm","sms_login"); + } + + Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); + if (companyservice == null || !secret.equals(companyservice.getSecret())) { + return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND); + } + + return elephantInvoiceService.rpaLogin(paramJson,companyservice); + + } + + + /** + * 数电账号查询接口(前端使用) + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true), + @ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true) + }) + @PostMapping("/queryRpaTaxAccount/{identity}/{secret}") + public Object queryRpaTaxAccount(@PathVariable("identity") String identity, @PathVariable("secret") String secret ){ + + log.debug("queryRpaTaxAccount param identity:{} secret:{}",identity,secret); + //参数校验 + if (StringUtils.isBlank(identity)){ + return AjaxResult.error("公司ID不能为空"); + } + + if (StringUtils.isBlank(secret)){ + return AjaxResult.error("公司Key不能为空"); + } + + Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); + if (companyservice == null || !secret.equals(companyservice.getSecret())) { + return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND); + } + + return elephantInvoiceService.queryRpaTaxAccount(companyservice.getSellertax(),companyservice); + + } + + /** + * 数电获取二维码接口(前端使用) + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true), + @ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true), + @ApiImplicitParam(name = "yhm", value = "电子税局登陆账号", dataType = "java.lang.String", required = true) + }) + @PostMapping("/getRpaQrCode/{identity}/{secret}") + public Object getRpaQrCode(@RequestBody Map params,@PathVariable("identity") String identity, @PathVariable("secret") String secret ) { + + JSONObject paramJson = new JSONObject(params); + log.debug("getRpaQrCode param params:{} identity:{} secret:{}", paramJson,identity,secret); + + //参数校验 + if (StringUtils.isBlank(identity)){ + return AjaxResult.error("公司ID不能为空"); + } + + if (StringUtils.isBlank(secret)){ + return AjaxResult.error("公司Key不能为空"); + } + + if (StringUtils.isBlank(paramJson.getString("yhm"))){ + return AjaxResult.error("电子税局登录名不能为空"); + } + + Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); + + if (companyservice == null || !secret.equals(companyservice.getSecret())) { + return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND); + } + + return elephantInvoiceService.getRpaQrCode(paramJson,companyservice); + + } + + + /** + * 数电登录接口(前端使用) + */ + @ApiImplicitParams({ + @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true), + @ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true), + @ApiImplicitParam(name = "params", value = "请求体", dataType = "java.lang.String", required = true) + }) + @PostMapping("/getRpaAuthStatus/{identity}/{secret}") + public Object getRpaAuthStatus(@RequestBody Map params, @PathVariable("identity") String identity, @PathVariable("secret") String secret ) { + + JSONObject paramJson = new JSONObject(params); + + log.debug("getRpaAuthStatus param{} identity:{} secret:{}", paramJson.toJSONString(), identity, secret); + + //参数校验 + if (StringUtils.isBlank(identity)){ + return AjaxResult.error("公司ID不能为空"); + } + + if (StringUtils.isBlank(secret)){ + return AjaxResult.error("公司Key不能为空"); + } + + if (StringUtils.isBlank(paramJson.getString("rzid"))){ + return AjaxResult.error("认证ID不能为空"); + } + + Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); + if (companyservice == null || !secret.equals(companyservice.getSecret())) { + return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND); + } + + return elephantInvoiceService.getRpaAuthStatus(paramJson,companyservice); + + } + + +} diff --git a/jianshui-common/src/main/java/com/jianshui/common/constant/PersonList.java b/jianshui-common/src/main/java/com/jianshui/common/constant/PersonList.java new file mode 100644 index 0000000..4a76788 --- /dev/null +++ b/jianshui-common/src/main/java/com/jianshui/common/constant/PersonList.java @@ -0,0 +1,37 @@ +package com.jianshui.common.constant; + +public enum PersonList { + + PERSON_TYPE_01("01", "法定代表人"), + PERSON_TYPE_02("02", "财务负责人"), + PERSON_TYPE_03("03", "办税员"), + PERSON_TYPE_05("05", "管理员"), + PERSON_TYPE_08("08", "社保经办人"), + PERSON_TYPE_09("09", "开票员"), + PERSON_TYPE_10("10", "销售人员"); + + private String type; + private String name; + + PersonList(String type, String name){ + this.type = type; + this.name = name; + } + + public String getType(){ + return type; + } + + public String getName(){ + return name; + } + + public static String getName(String type){ + for(PersonList personList : PersonList.values()){ + if(personList.getType().equals(type)){ + return personList.getName(); + } + } + return "未知类型"; + } +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/ElephantInvoiceService.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/ElephantInvoiceService.java new file mode 100644 index 0000000..bcfcfdd --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/ElephantInvoiceService.java @@ -0,0 +1,20 @@ +package com.jianshui.invoice.service; + +import com.alibaba.fastjson.JSONObject; +import com.jianshui.common.core.domain.AjaxResult; +import com.jianshui.common.core.domain.entity.Companyservice; + +public interface ElephantInvoiceService { + + //查询电子税局账户 + AjaxResult queryRpaTaxAccount(String sellertax, Companyservice companyservice); + + //数电账户登陆 + AjaxResult rpaLogin(JSONObject paramJson, Companyservice companyservice); + + //获取二维码 + AjaxResult getRpaQrCode(JSONObject paramJson, Companyservice companyservice); + + //获取状态 + AjaxResult getRpaAuthStatus(JSONObject paramJson, Companyservice companyservice); +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java new file mode 100644 index 0000000..83ac2a6 --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java @@ -0,0 +1,149 @@ +package com.jianshui.invoice.service.impl; + +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; +import com.jianshui.common.constant.PersonList; +import com.jianshui.common.core.domain.AjaxResult; +import com.jianshui.common.core.domain.entity.Companyservice; +import com.jianshui.common.utils.JsonKeyCase; +import com.jianshui.invoice.constant.elephant.ElephantConstantsV6; +import com.jianshui.invoice.domain.dto.HXResponse; +import com.jianshui.invoice.service.ElephantInvoiceService; +import com.jianshui.invoice.utils.elephant.ElephantUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { + + //调用大象获取电子税局账号 + @Override + public AjaxResult queryRpaTaxAccount(String sellertax, Companyservice companyservice) { + + Map param = new HashMap<>(); + param.put("NSRSBH",sellertax); + + DxhyInterfaceResponse dxhyInterfaceResponse = null; + try { + log.info("front queryRpaTaxAccount param{}",JSONObject.toJSONString(param)); + dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_LOCALHOST, ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_METHOD, JSONUtil.parse(param), companyservice); + log.info("front queryRpaTaxAccount response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + log.error("获取电子税局账号失败{}",e); + return AjaxResult.error("009999", "系统异常!"); + } + + if (!"000000".equals(dxhyInterfaceResponse.getCode())){ + return AjaxResult.error(dxhyInterfaceResponse.getMessage()); + } + + JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); + responJson = JsonKeyCase.JsonKeyCase(responJson,1); + if (!"000000".equals(responJson.getString("ztdm"))){ + return AjaxResult.error(responJson.getString("ztxx")); + } + return AjaxResult.success(responJson.getJSONArray("data")); + } + + //调用大象进行登录 + @Override + public AjaxResult rpaLogin(JSONObject paramJson, Companyservice companyservice) { + + paramJson.put("NSRSBH",companyservice.getSellertax()); + DxhyInterfaceResponse dxhyInterfaceResponse = null; + try { + paramJson = JsonKeyCase.JsonKeyCase(paramJson); + log.info("front rpaLogin param{}",paramJson); + dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RPA_LOGIN_LOCALHOST, ElephantConstantsV6.RPA_LOGIN_METHOD, JSONUtil.parse(paramJson), companyservice); + log.info("front rpaLogin response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + log.error("电子税局登陆失败{}",e); + return AjaxResult.error("009999", "系统异常!"); + } + if (!"000000".equals(dxhyInterfaceResponse.getCode())){ + return AjaxResult.error(dxhyInterfaceResponse.getMessage()); + } + //获取返回数据 + JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); + //key转成小写 + responJson = JsonKeyCase.JsonKeyCase(responJson,1); + + if (!"000000".equals(responJson.getString("ztdm"))){ + return AjaxResult.error(responJson.getString("ztxx")); + } + //判断后续方法是否为3 + JSONObject dataJson = responJson.getJSONObject("data"); + if ("2".equals(dataJson.getString("hxff"))){ + JSONObject sj = dataJson.getJSONObject("sj"); + List personList = sj.getJSONArray("personList").toJavaList(String.class); + Map personTypes = new HashMap<>(); + personList.forEach(e->personTypes.put(e, PersonList.getName(e))); + dataJson.put("personList",personTypes); + } + + return AjaxResult.success(dataJson); + } + + //获取二维码 + @Override + public AjaxResult getRpaQrCode(JSONObject paramJson, Companyservice companyservice) { + + paramJson.put("NSRSBH",companyservice.getSellertax()); + DxhyInterfaceResponse dxhyInterfaceResponse = null; + try { + paramJson = JsonKeyCase.JsonKeyCase(paramJson); + log.info("front getRpaQrCode param{}",JSONObject.toJSONString(paramJson)); + dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_QY_CODE_LOCALHOST, ElephantConstantsV6.GET_RPA_QY_CODE_METHOD, JSONUtil.parse(paramJson), companyservice); + log.info("front getRpaQrCode response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + log.error("电子税局登陆失败{}",e); + return AjaxResult.error("009999", "系统异常!"); + } + if (!"000000".equals(dxhyInterfaceResponse.getCode())){ + return AjaxResult.error(dxhyInterfaceResponse.getMessage()); + } + JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); + responJson = JsonKeyCase.JsonKeyCase(responJson,1); + + if (!"000000".equals(responJson.getString("ztdm"))){ + return AjaxResult.error(responJson.getString("ztxx")); + } + return AjaxResult.success(responJson.getJSONObject("data")); + } + + //数电实名认证状态 + @Override + public AjaxResult getRpaAuthStatus(JSONObject paramJson, Companyservice companyservice) { + paramJson.put("NSRSBH",companyservice.getSellertax()); + DxhyInterfaceResponse dxhyInterfaceResponse = null; + try { + paramJson = JsonKeyCase.JsonKeyCase(paramJson); + log.info("front getRpaAuthStatus param{}",paramJson); + dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_AUTH_STATUS_LOCALHOST, ElephantConstantsV6.GET_RPA_AUTH_STATUS_METHOD, JSONUtil.parse(paramJson), companyservice); + log.info("front getRpaAuthStatus response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + log.error("电子税局登陆失败{}",e); + return AjaxResult.error("009999", "系统异常!"); + } + if (!"000000".equals(dxhyInterfaceResponse.getCode())){ + return AjaxResult.error(dxhyInterfaceResponse.getMessage()); + } + JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); + responJson = JsonKeyCase.JsonKeyCase(responJson,1); + + if (!"000000".equals(responJson.getString("ztdm"))){ + return AjaxResult.error(responJson.getString("ztxx")); + } + return AjaxResult.success(responJson.getJSONObject("data")); + } +}