需求描述:
1 新增一個單元:應用管理
欄位參考:語雀文檔
主要包含:应用名称,endpoint url,显示位置,图标等,是否系统级别(系统级别就是租户创建就一定产生)
2 同步应用给CE
在租户参数加一个按钮【同步应用的按钮】
呼叫api 参考:語雀文檔
詳細分析:
1.先列出單元的各種參數、欄位(語雀),再進行建單元,可參考ce中的aiff單元。
其中有一些單元欄位的設置,如:設置字典、表單類型的設置(
1.先列出單元的各種參數、欄位(語雀文檔),再進行建單元,可參考ce中的aiff單元()。
其中有一些單元欄位的設置,如:設置字典、表單類型的設置(
,在表單類型下,預設中設置)以及點選APP,彈出APP欄設置(在應用載具下添加對應的js代碼,代碼如下:
var AiffForm = {
doLoad: function () {
form.getControl("FSupportDevice").onchange = AiffForm.checkSupportDevice;
AiffForm.checkSupportDevice();
},
checkSupportDevice: function () {
var supportDevice = form.getFieldValue("FSupportDevice");
supportDevice = new String(supportDevice);
if (supportDevice.includes("Client")) {
document.getElementsByClassName("JuiTabStripTabZone")[0].children[1].hidden = false;
form.setFieldVisible("FPictureId", true);
form.setFieldVisible("FEmbedLocation", true);
form.setFieldVisible("FDisplayLocation", true);
form.setFieldVisible("FUserType", true);
form.setFieldVisible("FCloseInAiff", true);
form.setFieldVisible("FIncomingAiff", true);
} else {
form.setFieldVisible("FPictureId", false);
form.setFieldVisible("FEmbedLocation", false);
form.setFieldVisible("FDisplayLocation", false);
form.setFieldVisible("FUserType", false);
form.setFieldVisible("FCloseInAiff", false);
form.setFieldVisible("FIncomingAiff", false);
document.getElementsByClassName("JuiTabStripTabZone")[0].children[1].hidden = true;
}
if (supportDevice.includes("APP")) {
document.getElementsByClassName("JuiTabStripTabZone")[0].children[2].hidden = false;
form.setFieldVisible("FIncomingAiff_APP", true);
form.setFieldVisible("FPictureId_APP", true);
form.setFieldVisible("FEmbedLocation_APP", true);
form.setFieldVisible("FDisplayLocation_APP", true);
form.setFieldVisible("FUserType_APP", true);
form.setFieldVisible("FCloseInAiff_APP", true);
} else {
form.setFieldVisible("FPictureId_APP", false);
form.setFieldVisible("FEmbedLocation_APP", false);
form.setFieldVisible("FDisplayLocation_APP", false);
form.setFieldVisible("FUserType_APP", false);
form.setFieldVisible("FCloseInAiff_APP", false);
form.setFieldVisible("FIncomingAiff_APP", false);
document.getElementsByClassName("JuiTabStripTabZone")[0].children[2].hidden = true;
}
},
}
最後就是在新建的租戶下添加應用同步按鈕,并添加點擊事件。
2.後端代碼部分:
①首先,在tenant包下action層是常規的拿參,調service的方法,返回dataresult對象:
@Override
public DataResult doAppSync(ActionContext ac) {
JSONObject args = ac.getArguments();
try {
TenantHome.getService().sync(ac.getServiceContext(), args);
}catch(Exception e) {
e.printStackTrace();
}
DataResult result = new DataResult();
return result;
}
②接著是在tenant的service層寫處理邏輯,拼裝調用遠程API所需要的參數(request數據,tenantCode及secret):
@Override
public void sync(ServiceContext sc, JSONObject args) {
String tenantCode = JsonUtil.getString(args, "FTenantCode");
String secret = AileDepartmentUtil.getSecret(sc, tenantCode);
List<JSONObject> aiffList = AiffHome.getService().getAiffList(sc, tenantCode);
JSONObject request = new JSONObject();
request.put("aiffs", aiffList);
RemoteApi.AiffSetup(request, tenantCode, secret);
}
③當然,調用遠程API首先要在環境上做設置,新建遠端API的方法:
public static JSONObject AiffSetup(JSONObject request, String tenantCode, String secret) {
JSONObject result = AileUtil.invoke("CEServer.AiffSetup", null, tenantCode, request, secret);
return result;
}
④在aiff包下service實現數據格式的拼裝(環環包裝啊!!!):
请求示例:
{
aiffs:[
{
aiffKey: "1234567890",
name: "測試訂位API11",
title: "什麼名字好呢",
endpointURL: "https://asasga",
supportDevice: ["Client", "APP"],
status: "New",
clientInfo: {
embedLocation: "MainFrame",
displayLocation: ["ServiceRoom", "PrivateRoom"],
pictureUrl:"https://gateway-test.aile.cloud:16622/gateway/openapi/gateway/file/download/183c0752-8190-0ae6-767f-0625d4c68070"
},
APPInfo: {
embedLocation: "MainFrame",
displayLocation: ["ServiceRoom", "PrivateRoom"],
pictureUrl:"https://gateway-test.aile.cloud:16622/gateway/openapi/gateway/file/download/183c0752-3650-0ae6-767f-0625d4c68070"
}
},
{
aiffKey: "1234567891",
status: "Enable",
}
]}
代码:
@Override
public List<JSONObject> getAiffList(ServiceContext sc, String tenantCode) {
List<AiffModel> ds = AiffHome.getDao().getAiffList(sc.getDaoContext());
List<JSONObject> aiffs = new ArrayList<>();
ds.forEach(model -> {
JSONObject request = new JSONObject();
String aiffKey = model.getFId();
String name = model.getName();
String title = model.getFTitle();
String url = model.getFUrl();
String qsSystemUrl = ParameterHome.getDao().getSystemParameter(sc.getDaoContext(), "QsSystemUrl");
StringBuffer buffer = new StringBuffer(url);
buffer.insert(0, qsSystemUrl);
String endpointURL = new String(buffer);
String[] supportDevice = model.getFSupportDevice().split(",");
String status = model.getFStatus();
JSONObject clientInfo = new JSONObject();
JSONObject APPInfo = new JSONObject();
for (String device : supportDevice) {
if (device.equals("Client")) {
String embedLocation = model.getFEmbedLocation();
String fPictureId = model.getFPictureId();
String pictureUrl = getPictureUrl(sc,fPictureId);
String closeInAiff = model.getFCloseInAiff();
String userType = model.getFUserType();
String[] displayLocation = model.getFDisplayLocation().split(",");
clientInfo.put("embedLocation", embedLocation);
clientInfo.put("pictureUrl", pictureUrl);
clientInfo.put("closeInAiff", closeInAiff);
clientInfo.put("userType", userType);
clientInfo.put("displayLocation", displayLocation);
} else if (device.equals("APP")) {
String embedLocation = model.getFEmbedLocation_APP();
String fPictureId = model.getFPictureId_APP();
String pictureUrl = getPictureUrl(sc,fPictureId);
String closeInAiff = model.getFCloseInAiff_APP();
String userType = model.getFUserType_APP();
String[] displayLocation = model.getFDisplayLocation_APP().split(",");
APPInfo.put("userType", userType);
APPInfo.put("embedLocation", embedLocation);
APPInfo.put("pictureUrl", pictureUrl);
APPInfo.put("closeInAiff", closeInAiff);
APPInfo.put("displayLocation", displayLocation);
}
}
request.put("aiffKey", aiffKey);
request.put("name", name);
request.put("title", title);
request.put("endpointURL", endpointURL);
request.put("supportDevice", supportDevice);
request.put("status", status);
request.put("clientInfo", clientInfo);
request.put("APPInfo", APPInfo);
aiffs.add(request);
});
return aiffs;
}
private String getPictureUrl(ServiceContext sc, String p) {
UUID pictureId = UUID.fromString(p);
String imageUrl = QsParameter.getSystemUrl() + "/openapi/base/file/download/"
+ AileNoticeHome.getService().getQSSystemPictureUrl(sc, pictureId);
return imageUrl.replaceAll("\\\\", "/");
}
需要注意的是傳出的PictureId,應該處理成url形式傳出。
⑤最後是在aiff包的dao層寫sql查詢語句了:
@Override
public List<AiffModel> getAiffList(DaoContext daoContext) {
String sql = "select FId,FName,FTitle, FUrl,FSupportDevice,FStatus, " +
"FEmbedLocation,FCloseInAiff,FPictureId,FUserType,FDisplayLocation," +
" FEmbedLocation_APP,FCloseInAiff_APP,FPictureId_APP,FUserType_APP,FDisplayLocation_APP from TcAiff";
return getExecutor().getObjectList(AiffModel.class, sql);
}
至此,業務完成!!!
難點是在數據的包裝吧,層層加包,有的時候有點暈。