Java获取金蝶数据
/*** 单据查询
* 此方法可以用来拉取ERP数据或者同步ERP数据
* @Param cookie
*/
public static String ExecuteBillQuery(String cookie) {
/**
* 拉取数据的url
* 此处的IP地址填写需要请求的真实地址
* 改动IP 后面请求地址不变
*
*/
String url = "http://192.168.2.18/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc";
/**
* 提交过去的数据
*FormId:业务对象表单Id 就是每个模块对应的ID
*FieldKeys:需查询的字段key集合 就是字段名
*FilterString:过滤条件,字符串类型(非必录)
*OrderString:排序字段,字符串类型(非必录)
*TopRowCount:返回总行数,整型(非必录)
*StartRow:开始行索引,整型(非必录)
*Limit:最大行数,整型,不能超过2000(非必录)
*
*{
* "FormId": "PRD_MO",
* "FieldKeys":"FBillNo,FBillType,FDate,FDocumentStatus,FProductType,FMaterialId,FMaterialName,FWorkShopID0,FPrdOrgId,FUnitId,FQty,FStatus,FLot,FPickMtrlStatus",
* "FilterString": "FDocumentStatus='C' AND FPickMtrlStatus=1 and datediff(month, FCreateDate,'2020-09-1')=0", --getdate()获取当月数据过滤条件是 已经审核,未领料,本(指定)月数据
* "OrderString": " FDate DESC ", -- 倒序
* "TopRowCount": 0,
* "StartRow": 0,
* "Limit":0
* }
*
*/
String sContent = "{\"FormId\":\"PRD_MO\",\"FieldKeys\":\"FID,FBillNo,FDocumentStatus,FBillType,FDate\",\"FilterString\":\"\",\"OrderString\":\"\",\"TopRowCount\":\"0\",\"StartRow\":\"0\",\"Limit\":\"2\"}";
//调用转换JSON的方法
String material = buildMaterial(sContent,"PRD_MO") ;
Map<String, Object> header = new HashMap<>();
header.put("Cookie",cookie);
String result = HttpUtil.httpPost(url, header, material);
System.out.println("结果:"+ result);
returnresult;
}
public static void main(String[] args) throws IOException {
//String cookie = login();
//ExecuteBillQuery(cookie);
//生产订单 PRD_MO
//用料清单 PRD_PPBOM
//直接调拨单 STK_TransferDirect
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[][]形式的字符串 经过转换之后变成集合
* [
* 规格:JDF), 0, 100080, 10095, 753.0000000000, 7, 0, 1],
* (规格:F2), 0, 100080, 10095, 125.0000000000, 7, 0, 1],
* 规格:7), 0, 100080, 10095, 6.5000000000, 7, 0, 1],
* 规格:1Y ), 0, 100080, 10095, 10.0000000000, 7, 0, 1],
* 规格:D3), 0, 100080, 10095, 82.0000000000, 7, 0, 1],
* 规格:D3), 0, 100080, 10095, 193.0000000000, 7, 0, 1],
* 规格:D5L), 0, 100080, 10095, 99.0000000000, 7, 0, 1],
* 规格:T7), 0, 100080, 10095, 20.8800000000, 7, 223760, 1],
*
* ]
*
*
*/
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<>();
/**
* 此处遍历数据进行处理以下面形式展现
*
* [
* {
*
* "FBillNo": "MO10003000080",
* "FBillType": "123f39178eb2424c8449f992e1fff1ee",
* "FDate": "2020-09-21T00:00:00",
* "FDocumentStatus": "C",
* "FLot": "0",
* "FMaterialId": "115084",
* "FMaterialName": "WR705(规格:JDF)",
* "FPickMtrlStatus": "1",
* "FPrdOrgId": "100080",
* "FProductType": "1",
* "FQty": "753.0000000000",
* "FStatus": "7",
* "FUnitId": "10095",
* "FWorkShopID0": "0"
* },
* {
* "FBillNo": "MO10001000076",
* "FBillType": "123f39178eb2424c8449f992e1fff1ee",
* "FDate": "2020-09-26T00:00:00",
* "FDocumentStatus": "C",
* "FLot": "221203",
* "FMaterialId": "216829",
* "FMaterialName": "WH-G310-1A",
* "FPickMtrlStatus": "1",
* "FPrdOrgId": "100078",
* "FProductType": "1",
* "FQty": "395.0000000000",
* "FStatus": "7",
* "FUnitId": "10095",
* "FWorkShopID0": "0"
* },........
* ]
*
*
*/
lists1.forEach(list->{
//为了和请求时候传递过去的字段的顺序一样 所以这里需要用有序的Map
Map<String,Object>map=new LinkedHashMap<>();
ForEachUtils.forEach(0, list, (index, item) -> {
map.put( key.get(index),list.get(index));
});
listMap.add(map);
});
// for (List<String>list :lists1){
// Map<String,Object>map=new LinkedHashMap<>();
// for (int i = 0; i <list.size() ; i++) {
// map.put( key.get(i),list.get(i));
// }
// listMap.add(map);
// }
/**
*转换过后的数据以Json输出
*/
listMap.forEach(item->{
System.out.println(JsonUtil.toJson(item));
} );
}
/**
* 转换成的JSON数据格式
* @param template需要提交的数据
* @param formid 业务表单的ID
* @return
*/
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);
}@Scheduled(fixedRate=200000)
public static String login() throws IOException{
// id号用户名 和 密码
String loginParam = buildLogin("606bf71d35839c", "administrator", "123456", 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;
}
//生成登录的json串
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);
}
感谢分享,很厉害的样子{:1_921:} 有什么用呢? 这个应该去csdn吧 {:1_907:}{:1_907:}{:1_907:}表示从金蝶出来的没看懂啥东西 不知道这个得到的数据做什么用。 这个要有对应的账号密码替换掉才能用吧 不明白有什么用
页:
[1]