JSON架包以及JobStatus任務狀態資料庫狀態修改
(1)轉載:”https://blog.csdn.net/qice675563721/article/details/74000124
用這個api有時候會報錯,基本上是因為包沒引入完,
引入這幾個包後基本上沒什麼問題,
但是對於JSONObject.fromObject 和 SONObject.toBean的使用為:
String strTmp = "{\"errmsg\":\"ok\",\"ErrorCode\":0,\"messageId\":\"f5d4566c4c833152b3feb42a8092ee6c\",\"invaliduser\":\"\",\"forbiddenUserId\":\"\",\"resJson\":{\"errmsg\":\"ok\",\"ErrorCode\":0,\"messageId\":\"f5d4566c4c833152b3feb42a8092ee6c\",\"invaliduser\":\"\",\"forbiddenUserId\":\"\"}}"; JSONObject jb = JSONObject.fromObject(strTmp); Map<String, Object> resmap = (Map<String, Object>)jb; System.out.println("-----resmap:---"+resmap.toString()); String json = "{id:'1001',name:'張三',age:'22'}"; student stu = new student(); JSONObject obj = JSONObject.fromObject(json); stu = (student)JSONObject.toBean(obj, student.class); System.out.println(stu);
package bao; public class student { private int id ; private String name; private int age; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String toString(){ return this.id + ",==== " + this.name + ", " + this.age; } }
結果為:
-----resmap:---{"errmsg":"ok","ErrorCode":0,"messageId":"f5d4566c4c833152b3feb42a8092ee6c","invaliduser":"","forbiddenUserId":"","resJson":{"errmsg":"ok","ErrorCode":0,"messageId":"f5d4566c4c833152b3feb42a8092ee6c","invaliduser":"","forbiddenUserId":""}}
1001,==== 張三, 22
(2)修改狀態JobStatus
這次的程式碼主要是拋磚物料到OA,實現的步驟差不多,主要是34.6版本用的是指令碼執行。
首先是找到拋磚的按鈕
(1)
然後由於
JSONObject json = JSONObject.fromObject(map);沒有拋異常嗎,很是奇怪,
於是主管在dynaTeam下面new了一個新的class測試檔案,然後
package dyna;
import java.util.HashMap;
import net.sf.json.JSONObject;
public class JSONTest
{
/**
* @param args
*/
public static void main(String[] args)
{
HashMap<String,String> map=new HashMap<String,String>();
map.put("A", "B");
JSONObject json = JSONObject.fromObject(map);
System.out.println(json.toString());
}
}
發現是缺少架包。
用這個api的時候會報錯,基本上市因為沒有引入完架包。
commons-beanutils-1.9.2.jar;
commons-collections-3.2.2.jar;
commons-lang-2.6.jar;
commons-logging-1.2.jar;
ezmorph-1.0.6.jar;
json-lib-2.4-jdk15.jar(2)發現客戶端執行成功,生成拋磚佇列之後,伺服器不執行,僅當伺服器重啟才可以。
於是
update SA_JOB_QUEUE sjq set sjq.jobstatus=0 where sjq.jobstatus=4
select sjq.jobstatus from SA_JOB_QUEUE sjq where sjq.jobstatus=1
JobStatus.java這是一個job的狀態列表。0是等待執行,1是正在執行,2是取消執行,3是執行成功,4是執行失敗。
然後先弄一條是等待的,然後開啟伺服器,這樣就不用每次去客戶端建一條正在等待的佇列。
var jss=provider.getServiceInstance(JSS,sid);
var boas=provider.getServiceInstance(BOAS,sid);
var ERPStub = new JSERPStub(jss);
var objectGuid=inputObject.getObjectGuid();
var classObject = ClassStub.getClassObjectByName("JG_SHEETMETAL");
var flag = true;
var foundation = boas.getObject(objectGuid);
var role = boas.getUserSignature().getLoginRoleId();//獲取當前使用者角色
var USERNAME = boas.getUserSignature().getUserName();//獲取當前使用者
var OWNERNAME = foundation.get("OWNERUSER$NAME");//獲取資料的所有者名稱
//if (!OWNERNAME.equals("admin"))
//{
//if (!OWNERNAME.equals(USERNAME))
//{
if(!role.equals("OAGLY"))
{
return ServiceRequestException("不是傳OA角色,沒有操作許可權!", "A");
}
//}
//}
if(null!=foundation.get("SFYC_ITEM"))
{
if(foundation.get("SFYC_ITEM").equals("Y"))
{
return ServiceRequestException("該物料的BOM結構已拋轉至ERP,不能重複拋轉!", "A");
}
}
if(foundation!=null)
{
foundation.put("alterid$",foundation.get("SAPBH"));
boas.saveObject(foundation, false, false,false, null, false, false, false);
}
var list = classObject.getChildList();
for(var i = 0;i<list.size();i++){
var co = list.get(i);
if(co.getInfo().getGuid().equals(objectGuid.getClassGuid())){
JSERPStub.createJSERPJob(objectGuid,"ITEMBJ",jss);
flag= false;
break;
}
}
if(flag){
JSERPStub.createJSERPJob(objectGuid,"ITEM",jss);
}