WebPiccPushController.java
9.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.lhcredit.project.webbusiness.controller;
import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.common.utils.FileSysUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.mail.SendMailUtil;
import com.lhcredit.project.business.bCreditReport.domain.BCreditReport;
import com.lhcredit.project.business.bCreditReport.mapper.BCreditReportMapper;
import com.lhcredit.project.business.bCreditReport.service.IBCreditReportService;
import com.lhcredit.project.business.reportMake.ReportOverseasMakeService;
import com.lhcredit.project.business.worldboxlog.domain.Worldboxlog;
import com.lhcredit.project.worldbox.EasyAPI;
import com.lhcredit.project.worldbox.WorldBoxAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
@Controller
@RequestMapping("/web/piccPush")
public class WebPiccPushController {
@Autowired
private IBCreditReportService bCreditReportService;
@Autowired
BCreditReportMapper bCreditReportMapper;
@Autowired
ReportOverseasMakeService reportOverseasMakeService;
@Autowired
WorldBoxAPI WorldBoxAPI;
@Autowired
EasyAPI easyAPI;
@RequestMapping("/piccGetPush")
public void piccGetPush(){
try {
System.out.println("===========执行获取海外报告任务!");
//查询制作中的海外订单
BCreditReport bCreditReport=new BCreditReport();
bCreditReport.setReportType("-10");
bCreditReport.setReportProgress("3");
List<BCreditReport> listReport=bCreditReportService.selectBCreditReportListXml(bCreditReport);
listReport.parallelStream().forEach(report->{
System.out.println("===========订单编号!"+report.getReferenceNo());
//记录日志
Worldboxlog worldboxlog1 = new Worldboxlog();
worldboxlog1.setName(report.getEnterpriseName());
worldboxlog1.setCreateBy("获取订单数据");
worldboxlog1.setCreateTime(new Date());
//获取订单
String str= WorldBoxAPI.getOrder(report.getReferenceNo(),worldboxlog1);
JSONObject json=JSONObject.parseObject(str);
// System.out.println("===========返回数据!"+str);
if(StringUtils.isNotNull(json)) {
JSONArray array = json.getJSONArray("orderitems");
if (array.size() > 0) {
JSONObject obj = array.getJSONObject(0);
if(obj.getString("statuscode").equals("6")) {
String base64Str = obj.getString("binary");
byte[] decodedBytes = Base64.decode(base64Str);
InputStream inputStream = new ByteArrayInputStream(decodedBytes);
//上传文件
String path = FileSysUtils.upLoadFile(inputStream, report.getEnterpriseName() + ".xml", "3");
JSONObject json1 = JSONObject.parseObject(path);
String url = FileSysUtils.host + "/" + json1.get("data");
System.out.println("===========xmlUrl返回数据!"+url);
//读取数据
String xmlStr = null;
try {
xmlStr = new String(decodedBytes, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
Map<String, Object> xmlMap = bCreditReportService.readXml(xmlStr);
List lt1=new ArrayList();
Map mp1=new HashMap();
mp1.put("fileName",report.getEnterpriseName());
mp1.put("fileExtension","xml");
mp1.put("fileAttachments",url);
lt1.add(mp1);
//发送请求
//发送数据
// long timespan = System.currentTimeMillis()/1000;
// String result = HttpRequest.post("https://qyld.piccltd.com.cn/apiserviceTest/PICCDataInfo/haiWaiCreditReportInfo").header("token", PiccMd5Token.string2MD5(Key + timespan + SecretKey).toUpperCase()).header("timespan",timespan+"").header("Key",Key).contentType("application/json; utf-8").form(json.toJSONString(pushMap)).execute().body();
// System.err.println(result);
//修改订单状态
bCreditReportMapper.updateStatusXmlUrl(report.getId(),"3","获取订单交付",new Date(), json.toJSONString(lt1),xmlMap.get("lrd").toString());
System.out.println("===========修改数据!"+report.getId()+" "+json.toJSONString(lt1));
}else if(obj.getString("statuscode").equals("9")){//取消订单
//修改订单状态
bCreditReportMapper.updateStatusXmlUrl(report.getId(),"7","取消制作",new Date(), "","");
}
}
}
});
}catch (Exception e){
e.printStackTrace();
}
System.out.println("===========获取海外报告任务结束!");
}
@RequestMapping("/piccGetDoc")
public void piccGetDoc(HttpServletResponse response){
System.out.println("===========执行获取海外报告任务!");
//查询制作中的海外订单
BCreditReport bCreditReport=new BCreditReport();
bCreditReport.setReportType("-10");
bCreditReport.setReportProgress("3");
List<BCreditReport> listReport=bCreditReportService.selectBCreditReportList(bCreditReport);
listReport.parallelStream().forEach(report->{
System.out.println("===========订单编号!"+report.getReferenceNo());
String xmlUrl=report.getUrl();
if(StringUtils.isNotEmpty(xmlUrl)) {
JSONArray array =JSONArray.parseArray(xmlUrl);
JSONObject json=JSONObject.parseObject(array.get(0).toString());
String url =json.getString("fileAttachments");
System.out.println("===========生成doc");
String docxUrl ="";
try {
byte[] bytes=FileSysUtils.downloadFile(url,response);
Map<String, Object> xmlMap = bCreditReportService.readXml(new String(bytes, "utf-8"));
xmlMap.put("companyName",report.getEnterpriseName());
docxUrl =reportOverseasMakeService.markOverseasReportPath(xmlMap,report.getEnterpriseName());
List lt2=new ArrayList();
Map mp2=new HashMap();
mp2.put("fileName",report.getEnterpriseName());
mp2.put("fileExtension","docx");
mp2.put("fileAttachments",docxUrl);
lt2.add(mp2);
//修改订单状态
bCreditReportMapper.updateStatusDocUrl(report.getId(),"4","订单待交付",new Date(),json.toJSONString(lt2));
}catch (Exception e){
bCreditReportMapper.updateStatusDocUrl(report.getId(),"8","生成doc异常:"+e.getMessage(),new Date(), "");
e.printStackTrace();
}
}
});
System.out.println("===========生成海外报告结束!");
}
@GetMapping("/easyOrder")
public void easyOrder(String entName,String countryIso){
//查询所有
String queryStr=easyAPI.query(entName,countryIso,"test");
if(StringUtils.isNotEmpty(queryStr)){
JSONObject obj=JSONObject.parseObject(queryStr);
if(obj.getInteger("code")==200){
//
JSONArray array=obj.getJSONArray("data");
for(int i=0;i<array.size();i++){
JSONObject obj1=array.getJSONObject(i);
String eid=obj1.getString("eid");
String nameEnglish=obj1.getString("nameEnglish");
String status=obj1.getString("status");
//entName.trim().equals(nameEnglish.trim())&&
if(status.equals("Active")){
//下单
String order=easyAPI.addOrder(eid,entName,"test");
System.out.println(order);
}
}
}
}
}
@GetMapping("/getOrder")
public void getOrder(String reportId,String entName){
String queryStr=easyAPI.getOrder(reportId,entName,"test");
System.out.println(queryStr);
}
}