UasEisApplicationTests.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package com.uas.eis;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.uas.eis.config.DonlimConfig;
  5. import com.uas.eis.dao.*;
  6. import com.uas.eis.service.ERPService;
  7. import com.uas.eis.task.ElecInvoiceTask;
  8. import com.uas.eis.task.InvoiceOrderTask;
  9. import nuonuo.open.sdk.NNOpenSDK;
  10. import org.junit.Test;
  11. import org.junit.runner.RunWith;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.boot.test.context.SpringBootTest;
  14. import org.springframework.test.context.junit4.SpringRunner;
  15. import java.io.*;
  16. import java.net.URL;
  17. import java.net.URLConnection;
  18. import java.text.SimpleDateFormat;
  19. import java.util.*;
  20. @RunWith(SpringRunner.class)
  21. @SpringBootTest(classes = {UasEisApplication.class})
  22. public class UasEisApplicationTests {
  23. @Autowired
  24. private BaseDao baseDao;
  25. @Autowired
  26. private ERPService erpService;
  27. @Autowired
  28. private DonlimConfig donlimConfig;
  29. @Autowired
  30. private ElecInvoiceTask elecInvoiceTask;
  31. @Autowired
  32. InvoiceOrderTask invoiceOrderTask;
  33. /**
  34. * 开票订单对接
  35. */
  36. @Test
  37. public void Test() {
  38. System.out.println("test");
  39. System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
  40. Object ob=baseDao.getFieldDataByCondition("enterprise","EN_WHICHSYSTEM","1=1");
  41. System.out.println(ob.toString());
  42. erpService.pushInvoiceOrder("N_HUASL_SZ",47);
  43. }
  44. /**
  45. * 获取token
  46. */
  47. @Test
  48. public void Test1() {
  49. /*//测试
  50. String appKey = "SD47646161";
  51. String appSecret = "SD681C05C3EA4408";*/
  52. //正式
  53. String appKey = "47646161";
  54. String appSecret = "B6681C05C3EA4408";
  55. // 接口调用
  56. NNOpenSDK sdk = NNOpenSDK.getIntance();
  57. String json = sdk.getMerchantToken(appKey, appSecret);
  58. // 响应报文解析
  59. System.out.println("\n\n\n【商户获取Token】");
  60. System.out.println(json);
  61. }
  62. @Test
  63. public void Test2(){
  64. NNOpenSDK sdk = NNOpenSDK.getIntance();
  65. String taxnum ="339901999999199";////测试
  66. String appKey = "78607195";
  67. String appSecret = "26A860C451744A21";
  68. String method = "nuonuo.OpeMplatform.queryInvoiceList"; // API方法名
  69. String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址
  70. String token = "77f21f617f87135fcd97ef1ueud3dxdi";
  71. String content = "{ \"requestType\": \"1\", \"pageNo\": \"2\", \"pageSize\": \"20\", \"taxnum\": \"339901999999199\", " +
  72. " \"startTime\": \"2023-07-20 00:00:00\", " +
  73. "\"endTime\": \"2023-07-21 00:00:00\" }";
  74. content=sdk.convertToUtf8(content);
  75. String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
  76. String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
  77. System.out.println("result:");
  78. System.out.println(result);
  79. }
  80. /**
  81. * 请求开具发票
  82. */
  83. @Test
  84. public void Test3() {
  85. erpService.invoiceOrderSubmitKp("N_HUASL_SZ",5);
  86. }
  87. /**
  88. * 删除平台开票订单
  89. */
  90. @Test
  91. public void Test_del() {
  92. erpService.cancelInvoiceOrder("N_HUASL_SZ",7);
  93. }
  94. /**
  95. * nuonuo.OpeMplatform.findOrderState(诺税通Saas订单状态查询接口)
  96. */
  97. @Test
  98. public void TestfindOrderState() {
  99. String OrderCode = "SZ23070031";
  100. SqlRowList io = baseDao.queryForRowSet("SELECT io_id FROM N_HUASL_SZ.invoiceOrder where IO_STATUS ='已审核' and IO_DOCKSTATUS = '对接成功' " +
  101. // "and nvl(IO_INVOICESTATUS,0) in(0,1,6) " +
  102. "and io_code = '"+OrderCode+"'" +
  103. "order by io_id ");
  104. //订单状态(0:待处理 1:处理中 2:已处理 4:提交失败 6:部分待处理 7:无需开票)
  105. //0:待处理 表示订单没有转了开票申请,此状态需要定时获取
  106. //1:处理中 表示订单可能转了开票申请,此状态需要定时获取
  107. //2:已处理 表示订单全部都转了开票申请,没有发票号的情况下要继续获取订单状态。
  108. //4:提交失败 表示订单自动转失败了,此状态需要定时获取
  109. //6:部分待处理 表示订单部分转了开票申请,此状态需要定时获取
  110. //7:无需开票,此状态可以不用管,此状态需要定时获取
  111. while (io.next()){
  112. Map<String, Object> mm = erpService.findOrderState("N_HUASL_SZ", io.getGeneralInt("io_id"));
  113. }
  114. }
  115. @Test
  116. public void TestInvoiceOrderStateUpdate(){
  117. invoiceOrderTask.InvoiceOrderStateUpdate();
  118. }
  119. /**
  120. * 查询订单关联发票接口 nuonuo.OpeMplatform.findOrderRelationInvoice
  121. */
  122. @Test
  123. public void Test5() {
  124. NNOpenSDK sdk = NNOpenSDK.getIntance();
  125. String taxnum ="339901999999199";////测试
  126. String appKey = "78607195";
  127. String appSecret = "26A860C451744A21";
  128. String method = "nuonuo.OpeMplatform.findOrderRelationInvoice"; // API方法名
  129. String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址
  130. String token = "77f21f617f87135fcd97ef1ueud3dxdi";
  131. Map<String,Object> reqParam=new HashMap<>();
  132. reqParam.put("needInvoiceSourceDetail","0");// 是否需要发票所来源的订单明细,1-是, 0-否(不填默认 0) 当为0时,将不回传orderDetailCallBackVOS
  133. //SZ23070026
  134. //betaRTC-202105-003180-209
  135. reqParam.put("originalOrderNo","SZ23070042");//部分待处理-没开票 {"status":"8958","message":"该订单对应的开票单不存在","data":null}
  136. reqParam.put("saleTaxNum","339901999999199");
  137. // invoiceState = 1 开票状态,合并冲销时为空 1:开票成功 2:开票失败
  138. //exceptionMessage 开票异常信息,开票失败状态时返回
  139. String content=JSONArray.toJSONString(reqParam);
  140. // content=sdk.convertToUtf8(content);
  141. // System.out.println(content);
  142. String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
  143. String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
  144. System.out.println(result);
  145. }
  146. @Test
  147. public void TestDownLoadElecInvoice(){
  148. // 20230731182154174492 SZ23070033
  149. Map<String, Object> m = erpService.getElecInvoicesById("N_HUASL_SZ", 7);
  150. System.out.println(JSONObject.toJSONString(m));
  151. // elecInvoiceTask.elecInvoiceDownLoad();
  152. }
  153. //文件转存
  154. //https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf
  155. @Test
  156. public void TestPdfDowLoad(){
  157. //下载地址
  158. String fileUrl = "https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf";
  159. // 定义要保存的文件的路径
  160. String filePath = "C:\\invoice\\988038486766_00007404.pdf";//开票代码_发票号码
  161. try {
  162. // 创建URL对象
  163. URL url = new URL(fileUrl);
  164. // 打开连接
  165. URLConnection conn = url.openConnection();
  166. // 获取输入流
  167. InputStream in = conn.getInputStream();
  168. // 创建输出流
  169. OutputStream out = new FileOutputStream(filePath);
  170. // 创建缓冲区
  171. byte[] buffer = new byte[1024];
  172. // 读取并写入数据
  173. int len;
  174. while ((len = in.read(buffer)) != -1) {
  175. out.write(buffer, 0, len);
  176. }
  177. // 关闭流
  178. in.close();
  179. out.close();
  180. //存文件 filepath
  181. System.out.println("下载成功");
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. }
  185. }
  186. @Test
  187. public void TestElecInvoiceAttachSave(){
  188. elecInvoiceTask.elecInvoiceAttachSave();
  189. }
  190. //冲红
  191. @Test
  192. public void testRushRed(){
  193. erpService.rushRed("N_HUASL_SZ",7);
  194. }
  195. @Test
  196. public void queryInvoiceRedConfirm(){
  197. String url=donlimConfig.getRoute();
  198. String appKey = donlimConfig.getAppKey();
  199. String appSecret = donlimConfig.getAppSecret();
  200. String token = donlimConfig.getToken();
  201. String taxnum= donlimConfig.getTaxnum();
  202. // erpService.queryInvoiceRedConfirmByCode( taxnum, appKey, appSecret, token, url,"1135624457459470336");
  203. }
  204. @Test
  205. public void testRed(){
  206. NNOpenSDK sdk = NNOpenSDK.getIntance();
  207. String taxnum ="339901999999199";////测试
  208. String appKey = "78607195";
  209. String appSecret = "26A860C451744A21";
  210. String token = "77f21f617f87135fcd97ef1ueud3dxdi";
  211. String url = "https://sdk.nuonuo.com/open/v1/services";//SDK请求地址
  212. String method = "nuonuo.OpeMplatform.queryInvoiceResult"; // API方法名
  213. String content = "{" +
  214. // "\"serialNos\": \"23073118215402725192\""+//流水号 -- EI_SID -- invoiceSerialNum
  215. ",\"orderNos\": \"20230731182154174492\""+ //开票单号 --- EI_ORDERNO -- ORDERNO
  216. ",\"isOfferInvoiceDetail\": \"0\""+
  217. // ",\"extensionNumber\": \"-\","+
  218. // "\"deptId\": \"-\","+
  219. // "\"clerkId\": \"-\","+
  220. // "\"startTime\": \"2022-05-19\","+
  221. // "\"endTime\": \"2022-06-19\""+
  222. "}";
  223. String senid = UUID.randomUUID().toString().replace("-", ""); // 唯一标识,32位随机码,无需修改,保持默认即可
  224. String result = sdk.sendPostSyncRequest(url, senid, appKey, appSecret, token, taxnum, method, content);
  225. System.out.println(result);
  226. }
  227. @Test
  228. public void TestelecInvoiceRedConfirmStateUpdate(){
  229. elecInvoiceTask.elecInvoiceRedConfirmStateUpdate();
  230. }
  231. @Test
  232. public void TestElecInvoiceRedAttachSave(){
  233. elecInvoiceTask.elecInvoiceRedAttachSave();
  234. }
  235. }