@Scheduled(fixedRate=200000)
public static String login() throws IOException{
String loginParam = buildLogin("********", "administrator", "****", 2052);
String url = "http://192.168.2.18/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc";
ResponseEntity<String> response= HttpUtil.httpPost(url, loginParam);
String login_cookie="";
if(response.getStatusCode()== HttpStatus.OK) {
Set<String> keys=response.getHeaders().keySet();
for(String key:keys){
if (key.equalsIgnoreCase("Set-Cookie")) {
List<String> cookies = response.getHeaders().get(key);
for(String cookie:cookies){
if(cookie.startsWith("kdservice-sessionid")){
login_cookie=cookie;
System.out.println("登录K3成功啦:"+login_cookie);
break;
}
}
}
}
}
return login_cookie;
}
public static String buildLogin(String dbid, String userName, String password, int lang){
Map<String,Object> param = new HashMap<>(4);
param.put("acctID",dbid);
param.put("username",userName);
param.put("password",password);
param.put("lcid",lang);
return JSON.toJSONString(param);
}
public static String buildMaterial(String template,String formid) {
JSONObject basic = JSON.parseObject(template);
JSONObject jsonObject = new JSONObject();
jsonObject.put("formid",formid);
jsonObject.put("data",JSON.toJSONString(basic));
return JSON.toJSONString(jsonObject);
}
public static String ExecuteBillQuery(String cookie) {
String url = "http://192.168.2.18/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc";
String sContent = "{\"FormId\":\"PRD_MO\",\"FieldKeys\":\"FID,FBillNo,FDocumentStatus,FBillType,FDate\",\"FilterString\":\"\",\"OrderString\":\"\",\"TopRowCount\":\"0\",\"StartRow\":\"0\",\"Limit\":\"2\"}";
String material = buildMaterial(sContent,"PRD_MO") ;
Map<String, Object> header = new HashMap<>();
header.put("Cookie",cookie);
String result = HttpUtil.httpPost(url, header, material);
return result;
}
public static void main(String[] args) throws IOException {
String str2="[[\"MO10003000080\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-21T00:00:00\",\"C\",\"1\",115084,\"WR705(规格:JDF)\",0,100080,10095,753.0000000000,\"7\",0,\"1\"],[\"MO10003000012\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",115098,\"WR7168(规格:F2)\",0,100080,10095,125.0000000000,\"7\",0,\"1\"],[\"MO10003000080\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-21T00:00:00\",\"C\",\"1\",115169,\"WR7501PB(规格:7)\",0,100080,10095,6.5000000000,\"7\",0,\"1\"],[\"MO10003000013\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",115203,\"WR7501PB(规格:1Y )\",0,100080,10095,10.0000000000,\"7\",0,\"1\"],[\"MO10003000029\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-16T00:00:00\",\"C\",\"1\",115205,\"WR7399 A(规格:D3)\",0,100080,10095,82.0000000000,\"7\",0,\"1\"],[\"MO10003000153\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-23T00:00:00\",\"C\",\"1\",115205,\"WR7399 A(规格:D3)\",0,100080,10095,193.0000000000,\"7\",0,\"1\"],[\"MO10003000031\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-16T00:00:00\",\"C\",\"1\",115226,\"WR7399B(规格:D5L)\",0,100080,10095,99.0000000000,\"7\",0,\"1\"],[\"MO10003000383\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-30T00:00:00\",\"C\",\"1\",115380,\"WR7501(规格:T7)\",0,100080,10095,20.8800000000,\"7\",223760,\"1\"],[\"MO10001000076\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-26T00:00:00\",\"C\",\"1\",122393,\"WH-3100-J\",0,100078,10095,369.0000000000,\"7\",221598,\"1\"],[\"MO10001000076\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-26T00:00:00\",\"C\",\"1\",122438,\"WH-1100-J-126\",0,100078,10095,420.0000000000,\"7\",221190,\"1\"],[\"MO10001000076\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-26T00:00:00\",\"C\",\"1\",122450,\"WH-3100-JZH\",0,100078,10095,316.0000000000,\"7\",221199,\"1\"],[\"MO10001000092\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-27T00:00:00\",\"C\",\"1\",122511,\"WH-3100-J\",0,100078,10095,100.0000000000,\"7\",221586,\"1\"],[\"MO10002000078\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-10T00:00:00\",\"C\",\"1\",124123,\"7101-09T-10\",0,100079,10095,15.0000000000,\"7\",0,\"1\"],[\"MO10003000010\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",193574,\"903-1000-M\",0,100080,10095,885.0000000000,\"7\",209209,\"1\"],[\"MO10003000011\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",198700,\"WR7306A(规格:YC-RH)\",0,100080,10095,30.0000000000,\"7\",0,\"1\"],[\"MO10003000011\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",198703,\"WR7306B(规格:YC-RH)\",0,100080,10095,30.0000000000,\"7\",209211,\"1\"],[\"MO10002000083\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-11T00:00:00\",\"C\",\"1\",199617,\"R-15T\",0,100079,10095,10.0000000000,\"7\",0,\"1\"],[\"MO10003000007\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",206101,\"WR7306A(规格:9107L)\",0,100080,10095,180.0000000000,\"7\",0,\"1\"],[\"MO10003000007\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-15T00:00:00\",\"C\",\"1\",206105,\"WR7306B(规格:9107L)\",0,100080,10095,370.0000000000,\"7\",209192,\"1\"],[\"MO10003000030\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-16T00:00:00\",\"C\",\"1\",207920,\"WR7399A规格:D3(高速分散基料)\",0,100080,10095,78.0000000000,\"7\",213449,\"1\"],[\"MO10001000076\",\"123f39178eb2424c8449f992e1fff1ee\",\"2020-09-26T00:00:00\",\"C\",\"1\",216829,\"WH-G310-1A\",0,100078,10095,395.0000000000,\"7\",221203,\"1\"]]";
List<String>key=new ArrayList<String>(){
{
this.add("FBillNo");
this.add("FBillType");
this.add("FDate");
this.add("FDocumentStatus");
this.add("FProductType");
this.add("FMaterialId");
this.add("FMaterialName");
this.add("FWorkShopID0");
this.add("FPrdOrgId");
this.add("FUnitId");
this.add("FQty");
this.add("FStatus");
this.add("FLot");
this.add("FPickMtrlStatus");
}
};
String[][] parse1 = JSON.parseObject(str2, String[][].class);
List<List<String>> lists1 = JSON.parseObject(JSON.toJSONString(parse1),new TypeReference<List<List<String>>>() {});
List<Map<String,Object>>listMap=new ArrayList<>();
lists1.forEach(list->{
Map<String,Object>map=new LinkedHashMap<>();
ForEachUtils.forEach(0, list, (index, item) -> {
map.put( key.get(index),list.get(index));
});
listMap.add(map);
});
listMap.forEach(item->{
System.out.println(JsonUtil.toJson(item));
} );
}

- 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
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
import java.util.Map;
import java.util.Set;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
public class HttpUtil {
private HttpUtil(){
}
private static final int CONN_TIMEOUT = 30000;
private static final int READ_TIMEOUT = 30000;
private static RestTemplate restTemplate = null;
static{
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(CONN_TIMEOUT);
requestFactory.setReadTimeout(READ_TIMEOUT);
restTemplate = new RestTemplate(requestFactory);
}
private static HttpHeaders initHeader(){
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Accpet-Encoding", "gzip");
headers.add("Content-Encoding", "UTF-8");
headers.add("Content-Type", "application/json; charset=UTF-8");
return headers;
}
private static void setHeaderParam(HttpHeaders httpHeaders,Map<String,Object> headers){
if(!CollectionUtils.isEmpty(headers)){
Set<String> keys = headers.keySet();
for(String key:keys){
httpHeaders.add(key,headers.get(key).toString());
}
}
}
public static ResponseEntity<String> httpPost(String url,String json){
HttpHeaders httpHeaders = initHeader();
return toPost(url,httpHeaders,json);
}
public static String httpPost(String url,Map<String,Object> header,String json){
HttpHeaders httpHeaders = initHeader();
setHeaderParam(httpHeaders,header);
return toPost(url,httpHeaders,json).getBody();
}
private static ResponseEntity<String> toPost(String url,HttpHeaders httpHeaders,String json){
HttpEntity<String> httpEntity = new HttpEntity<>(json,httpHeaders);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST,httpEntity,String.class);
return responseEntity;
}
}

- 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
-