@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));
} );
}
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;
}
}
import java.util.Objects;
import java.util.function.BiConsumer;
public class ForEachUtils {
public static <T> void forEach(int startIndex,Iterable<? extends T> elements, BiConsumer<Integer, ? super T> action) {
Objects.requireNonNull(elements);
Objects.requireNonNull(action);
if(startIndex < 0) {
startIndex = 0;
}
int index = 0;
for (T element : elements) {
index++;
if(index <= startIndex) {
continue;
}
action.accept(index-1, element);
}
}
}