yili-apps/com.awspaas.user.apps.yili.integration/src/com/awspaas/user/apps/integration/event/CreateDataKnow.java

505 lines
24 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.awspaas.user.apps.integration.event;
import com.actionsoft.apps.coe.pal.pal.output.constant.OutputConst;
import com.actionsoft.apps.coe.pal.pal.output.dao.OutputTask;
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppManager;
import com.actionsoft.apps.coe.pal.pal.output.extend.OutputAppProfile;
import com.actionsoft.apps.coe.pal.pal.output.model.OutputTaskModel;
import com.actionsoft.apps.coe.pal.pal.repository.upfile.model.UpfileModel;
import com.actionsoft.apps.coe.pal.pal.repository.upfile.web.UpfileWeb;
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.server.SSOUtil;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.fs.DCContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.AWSException;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import javax.swing.tree.RowMapper;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 创建已发布的知识
*/
public class CreateDataKnow implements IJob {
private static String APPID = "com.awspaas.user.apps.yili.integration";
private static String USERID = "admin";
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
SSOUtil ssoUtil = new SSOUtil();
String portalUrl = SDK.getPortalAPI().getPortalUrl();
String sid = ssoUtil.registerClientSessionNoPassword(USERID, "cn", portalUrl, "pc");
UserContext userContext = UserContext.fromSessionId(sid);
System.out.println("创建知识准备开始===============");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("开始时间是>>>>>>>>>>"+sdf.format(new Date()));
String sql = "select * from APP_ACT_COE_PAL_REPOSITORY " +
"where PLCATEGORY = 'process'and PLMETHODID !='process.framework' " +
"and ISPUBLISH = '1' and PLNAME not in ('流程架构图','测试用','GMY-截图用','sx批量测试'" +
",'8.2培训使用','用户练习使用','YX测试分部','yx测试人员','yx测试部','流程架构测试')" +
" and PLPARENTID not in ('63ff93c6-2f27-4851-a396-6830c428db2e'," +
"'c84f497a-4de3-4404-86e8-cd5af71c3b47','94dabf55-b032-4316-a4c3-00b83763da09'," +
"'36ac7cdd-a361-4bd3-9511-c03c1b3627a4','84e534b4-e51a-4874-9ff1-8a0206d9e0c5'," +
"'98bd5917-7563-4b29-b775-815e91d9864c','f07da63c-3423-4c1e-ae75-b323c6a69093'," +
"'79cb4c35-d2f7-4c43-a7db-44038b557eac','7ad79a73-a497-417a-a5ec-d4c9fd45061c'," +
"'42c09260-c1d3-44b7-ac3d-f8280e04c294')";
List<RowMap> rowMapList = DBSql.getMaps(sql);
for (RowMap rowmap:rowMapList
) {
String card_sql = "SELECT * FROM APP_ACT_KMS_CARD WHERE CARDNAME like '"+rowmap.getString("PLNAME")+"%'";
RowMap map = DBSql.getMap(card_sql);
if (map!=null){
String sql_pal = "SELECT * FROM APP_ACT_COE_PAL_REPOSITORY WHERE EXT4 = '"+map.getString("ID")+"'";
RowMap rowMap = DBSql.getMap(sql_pal);
if (rowMap!=null){
System.out.println("该知识已经存在于PAL资产库中的EXT4中并且已经在知识中");
}else{
String level = "";
if (rowMap!=null){
if (rowmap.getString("PLVER").contains(".00")){
String[] plvers = rowmap.getString("PLVER").split("\\.");
plvers[1] = plvers[1].replaceAll("0","");
level = plvers[0]+"."+plvers[1];
}else {
level = rowmap.getString("PLVER")+".0";
}
}
CreateKnow(rowmap.getString("PLMETHODID"),rowmap.getString("PLNAME")+"V"+level,rowmap.getString("PLNAME"),rowmap.getString("PLVER"),true,true,"2099-12-31","1",USERID,"",sid);
/*Map names = new LinkedHashMap<>();
String plname = rowmap.getString("PLNAME");
for (int i=0;i<4;i++) {
String sql_de = sql+" and PLNAME = '"+plname+"'";
RowMap map1 = DBSql.getMap(sql_de);
if (map1!=null){
names.put(i,map1.getString("PLNAME"));
plname = map1.getString("PLNAME");
}else {
break;
}
}
for (int i=names.size() - 1; i >= 0; i--) {
String sql_de = sql+" and PLNAME = '"+names.get(i)+"'";
RowMap map1 = DBSql.getMap(sql_de);
String sql_decre = "select * from APP_ACT_KMS_DIMENSION where DIMENSIONNAME = '"+names.get(i)+"'";
RowMap map2 = DBSql.getMap(sql_decre);
if (map2==null){
createDimension(map1.getString("ID"),false,true,"1","","",names.get(i).toString(),sid);
}
}*/
}
}else {
String level = "";
if (rowmap!=null){
if (rowmap.getString("PLVER").contains(".00")){
System.out.println("PLver>>>>>>>>>>"+rowmap.getString("PLVER"));
String levels = rowmap.getString("PLVER");
String[] plvers = levels.split("\\.");
System.out.println("pleces>>>>>>>>>>>>>>>>>"+plvers[0]);
plvers[1] = plvers[1].replaceAll("0","");
level = plvers[0]+"."+plvers[1];
}else {
level = rowmap.getString("PLVER")+".0";
}
}
CreateKnow(rowmap.getString("PLMETHODID"),rowmap.getString("PLNAME")+"V"+level,rowmap.getString("PLNAME"),rowmap.getString("PLVER"),true,true,"2099-12-31","1",USERID,"",sid);
/*Map names = new LinkedHashMap<>();
String plname = rowmap.getString("PLNAME");
String plparentid = rowmap.getString("PLPARENTID");
for (int i=0;i<4;i++) {
String slq = "select * from APP_ACT_COE_PAL_REPOSITORY where id = '"+plparentid+"'";
RowMap map3 = DBSql.getMap(slq);
if (map3!=null){
names.put(i,map3.getString("PLNAME"));
plname = map3.getString("PLNAME");
plparentid = map3.getString("PLPARENTID");
}else if (plparentid.equals("process")){
names.put(i,"流程制度");
}else {
break;
}
}
for (int i=names.size() - 1; i >= 0; i--) {
if (names.get(i).equals("流程制度")){
String sql_decre = "select * from APP_ACT_KMS_DIMENSION where DIMENSIONNAME = '"+names.get(i)+"'";
RowMap map2 = DBSql.getMap(sql_decre);
if (map2==null){
createDimension("",false,true,"1","","",names.get(i).toString(),sid);
}
}else {
String sql_de = "select * from APP_ACT_COE_PAL_REPOSITORY " +
"where PLCATEGORY = 'process'and PLMETHODID ='process.framework' " +
"and PLNAME not in ('流程架构图','测试用','GMY-截图用','sx批量测试'" +
",'8.2培训使用','用户练习使用','YX测试分部','yx测试人员','yx测试部','流程架构测试')" +
" and PLPARENTID not in ('63ff93c6-2f27-4851-a396-6830c428db2e'," +
"'c84f497a-4de3-4404-86e8-cd5af71c3b47','94dabf55-b032-4316-a4c3-00b83763da09'," +
"'36ac7cdd-a361-4bd3-9511-c03c1b3627a4','84e534b4-e51a-4874-9ff1-8a0206d9e0c5'," +
"'98bd5917-7563-4b29-b775-815e91d9864c','f07da63c-3423-4c1e-ae75-b323c6a69093'," +
"'79cb4c35-d2f7-4c43-a7db-44038b557eac','7ad79a73-a497-417a-a5ec-d4c9fd45061c'," +
"'42c09260-c1d3-44b7-ac3d-f8280e04c294')"+" and PLNAME = '"+names.get(i)+"'";
RowMap map1 = DBSql.getMap(sql_de);
String sql_decre = "select * from APP_ACT_KMS_DIMENSION where DIMENSIONNAME = '"+names.get(i)+"'";
RowMap map2 = DBSql.getMap(sql_decre);
if (map2==null){
createDimension(map1.getString("ID"),false,true,"1","","",names.get(i).toString(),sid);
}
}
}
*/
}
}
System.out.println("知识库同步完成");
}
/**
* 创建知识
* @param securityLevel
* @param knwlName
* @param plname
* @param PLVER
* @param isComment
* @param isRate
* @param validDate
* @param onlineLevel
* @param createUser
* @param cardContext
* @param sid
*/
public void CreateKnow(String securityLevel,String knwlName,String plname,String PLVER, boolean isComment,boolean isRate,String validDate,String onlineLevel,String createUser,String cardContext,String sid) {
// 调用App
UserContext userContext = UserContext.fromSessionId(sid);
String sourceAppId = APPID;
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.kms/CreateKnwl";
// 参数定义列表
Map params = new HashMap<String, Object>();
//保密级别, 0: 普通 1秘密 2机密,必填
params.put("securityLevel", 0);
//知识名称,必填
params.put("knwlName", knwlName);
//是否可以评论,必填
params.put("isComment", isComment);
//是否可以评分,必填
params.put("isRate", isRate);
//有效期:yyyy-MM-dd,非必填
params.put("validDate", validDate);
//只读控制1在线阅读和下载 0在线阅读,必填
params.put("onlineLevel", 1);
//知识创建人某些特殊场景下sid和createUser代表的用户并不一样如果此参数为null则使用sid代表的用户,非必填
params.put("createUser", createUser);
//知识内容,非必填
params.put("cardContext", cardContext);
//sid,必填
params.put("sid", sid);
AppAPI appAPI = SDK.getAppAPI();
//创建知识
ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params);
if (ro.isOk()){
String cardId = ((LinkedHashMap) ro.getData()).get("cardId").toString();
String update_sql = "UPDATE APP_ACT_COE_PAL_REPOSITORY SET EXT4 = '"+cardId+"' WHERE " +
" PLCATEGORY = 'process'and PLMETHODID !='process.framework' " +
" and PLNAME not in ('流程架构图','测试用','GMY-截图用','sx批量测试'" +
" ,'8.2培训使用','用户练习使用','YX测试分部','yx测试人员','yx测试部','流程架构测试')" +
" and ISPUBLISH = '1' and PLPARENTID not in ('63ff93c6-2f27-4851-a396-6830c428db2e'," +
" 'c84f497a-4de3-4404-86e8-cd5af71c3b47','94dabf55-b032-4316-a4c3-00b83763da09'," +
" '36ac7cdd-a361-4bd3-9511-c03c1b3627a4','84e534b4-e51a-4874-9ff1-8a0206d9e0c5'," +
" '98bd5917-7563-4b29-b775-815e91d9864c','f07da63c-3423-4c1e-ae75-b323c6a69093'," +
" '79cb4c35-d2f7-4c43-a7db-44038b557eac','7ad79a73-a497-417a-a5ec-d4c9fd45061c'," +
" '42c09260-c1d3-44b7-ac3d-f8280e04c294') and PLMETHODID = '"+securityLevel+"' and PLNAME = '"+plname+"' AND PLVER = '"+PLVER+"'";
int update = DBSql.update(update_sql);
System.out.println("更新名称为:"+plname+"版本为:"+PLVER +"的知识对应的资产库的EXT4的影响行数为"+update);
creadteFile(userContext,cardId);
}
}
/**
* 创建附件以及手册dc
* @param userContext
* @param cardId
*/
public void creadteFile(UserContext userContext, String cardId){
/**
* 这个主要是负责对流程手册进行相关的文件的生成
*/
String sourceAppId = APPID;
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.kms/CreateFile";
if (StringUtils.isNotEmpty(cardId)){
String sql_ext4 = "select * from APP_ACT_COE_PAL_REPOSITORY where EXT4 = '"+cardId+"'";
RowMap map = DBSql.getMap(sql_ext4);
RowMap rowMap = DBSql.getMap("select * from (select * from BO_ACT_COE_PUBLISH_N where PUBLISHFILEID = '"+map.getString("ID")+"' order by CREATEDATE desc) where rownum = 1");
if (rowMap!=null){
if (StringUtils.isNotEmpty(rowMap.getString("TASKID"))) {
OutputTaskModel model = new OutputTask().getTaskReportById(rowMap.getString("TASKID"));
if (model != null) {
System.out.println("pdel============" + model);
System.out.println("123313123123123==========" + model.getProfileId());
OutputAppProfile appProfile = OutputAppManager.getProfile(model.getProfileId());
System.out.println("dajadfas======" + appProfile);
if (appProfile == null) {
throw new AWSException("Not Find OutputAppProfile! profileId=" + model.getProfileId());
}
DCPluginProfile dcProfile = SDK.getDCAPI().getDCProfile(appProfile.getAppContext().getId(), OutputConst.EXT_APP_DC_OUTPUT);
if (dcProfile == null)
throw new AWSException("Not Find DCProfile! repositoryName=" + OutputConst.EXT_APP_DC_OUTPUT);
String sql_lever = "SELECT PLVER FROM APP_ACT_COE_PAL_REPOSITORY WHERE ID = '" + rowMap.getString("PUBLISHFILEID") + "'";
System.out.println("手册的版本号>>>>>>>>>>>>"+sql_lever);
String lever = DBSql.getString( sql_lever);
//lever = lever.substring(0,3);
if(lever.length()==5&&lever.substring(4).equals("0")){
lever.substring(0,3);
}else if (lever.length()==1){
lever=lever+".0";
}
System.out.println("手册截取之后的版本号>>>>>>>>>>"+lever);
DCContext dcContext = new DCContext(userContext, dcProfile, appProfile.getAppContext().getId(), model.getWsId(), rowMap.getString("TASKID"), rowMap.getString("PUBLISHFILENAME") + "_" + lever + ".doc");
//UtilFile file = new UtilFile(dcContext.getPath());
Map params = new HashMap<String, Object>();
//知识ID,必填
params.put("cardId", cardId);
//sid,必填
params.put("sid", userContext.getSessionId());
params.put("dc", dcContext);
AppAPI appAPI = SDK.getAppAPI();
//创建文件
ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params);
System.out.println("流程手册的存入=================" + ro);
}
}
}
String sql_A = "SELECT PLNAME FROM APP_ACT_COE_PAL_REPOSITORY where ID = '"+map.getString("ID")+"' AND PLMETHODID != 'process.framework' AND PLMETHODID IN (select distinct PLMETHODID from APP_ACT_COE_PAL_REPOSITORY)";
List<RowMap> rows = DBSql.getMaps(sql_A);
for (RowMap bo:rows
) {
/**
* 这个是模型中的附件获取的并插入的数据信息,需要做修改
*/
// 调用App
// 参数定义列表
Map paramss = new HashMap<String, Object>();
//知识ID,必填
paramss.put("cardId", cardId);
//sid,必填
paramss.put("sid", userContext.getSessionId());
UpfileWeb upfileWeb = new UpfileWeb(userContext);
String sql_upfile = "select * from APP_ACT_COE_PAL_UPFILE where palrepositoryid in (select ID from APP_ACT_COE_PAL_REPOSITORY where PLMETHODID != 'process.framework' AND ID= '"+map.getString("ID")+"'" +
")";
List<RowMap> maps = DBSql.getMaps(sql_upfile);
for (RowMap row : maps) {
System.out.println("附件的名称>>>>>>>>>>"+row.getString("FILENAME"));
if (!row.getString("FILENAME").contains(".xml")){
try {
UpfileModel upfileModel = new UpfileModel();
upfileModel.setType(row.getString("FILETYPE"));
upfileModel.setFileName(row.getString("FILENAME"));
upfileModel.setPl_uuid(row.getString("PALREPOSITORYID"));
upfileModel.setShape_uuid(row.getString("SHAPEID"));
DCContext dcContexts = upfileWeb.getDCContext(upfileModel);
paramss.put("dc", dcContexts);
AppAPI appAPIs = SDK.getAppAPI();
ResponseObject ros = appAPIs.callASLP(appAPIs.getAppContext(sourceAppId), aslp, paramss);
System.out.println("流程模型附件的生成============="+ros);
}catch (Exception e){
System.out.println("附件无法上传>>>>>>>>"+row.getString("FILENAME"));
}
}
}
//DCContext对象,必填
//创建文件
}
PublishKnow(userContext,cardId);
}
}
/**
* 发布知识
* @param userContext
* @param id
*/
public void PublishKnow(UserContext userContext,String id){
String sql = "select EXT4 from APP_ACT_COE_PAL_REPOSITORY where id in (select PLPARENTID from APP_ACT_COE_PAL_REPOSITORY where EXT4 = '"+id +"')";
List<RowMap> maps = DBSql.getMaps(sql);
String ids = "";
for (RowMap rowmap:maps
) {
ids+=rowmap.getString("EXT4")+",";
}
String[] deptSplit_id = ids.split(",");
JSONArray jsonArray = new JSONArray();
for (String id_names:deptSplit_id
) {
jsonArray.add(id_names);
}
//jsonObject.put(deptSplit_id);
id+=",";
String[] deptSplit_das = id.split(",");
JSONArray jsonArray_das = new JSONArray();
for (String das:deptSplit_das
) {
jsonArray_das.add(das);
}
//jsonObject.put(deptSplit_id);
// 调用App
String sourceAppId = APPID;
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.kms/PublishKnwl";
// 参数定义列表
Map params = new HashMap<String, Object>();
//要发布到的维度ID的JSON数组字符串,必填
params.put("dimensionIDArray", jsonArray.toString());
//要发布的知识ID的JSON数组字符串,必填
params.put("knwlIDArray", jsonArray_das.toString());
//标签的JSON数组字符串,非必填
//sid,必填
params.put("sid", userContext.getSessionId());
AppAPI appAPI = SDK.getAppAPI();
//发布知识
ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params);
System.out.println("知识发布============"+ro);
String sql_ext4 = "select PERMTYPE,ORGPERM from BO_ACT_PUBLISH_PERM_SCOPE where PALVERSIONID = (select PLVERSIONID from ( select PLVERSIONID from APP_ACT_COE_PAL_REPOSITORY a where ISPUBLISH = '1' AND EXT4 = '"+id.substring(0,id.length()-1)+"' order by a.createdate desc ) where rownum=1)";//id.substring(0,id.length()-1)
RowMap rowMap = DBSql.getMap(sql_ext4);
System.out.println("rowMap>>>>>>>>"+rowMap);
System.out.println("sqls>>>>>>>>"+sql_ext4);
JSONArray jsonArray1 = new JSONArray(new LinkedList<>());
if (rowMap==null){
List<RowMap> select_id_from_orgdepartment = DBSql.getMaps("select ID from ORGDEPARTMENT");
for (RowMap depaid:
select_id_from_orgdepartment) {
String id_depart = depaid.getString("ID");
JSONObject jsonObjecta = new JSONObject();
jsonObjecta.put("assignmentType","department");
jsonObjecta.put("assignmentId",id_depart);
jsonArray1.add(jsonObjecta);
}
}else {
String permtype = rowMap.getString("PERMTYPE");
if (permtype.equals("1")) {
List<RowMap> select_id_from_orgdepartment = DBSql.getMaps("select ID from ORGDEPARTMENT");
for (RowMap depaid :
select_id_from_orgdepartment) {
String depaid_id = depaid.getString("ID");
JSONObject jsonObjecta = new JSONObject();
jsonObjecta.put("assignmentType", "department");
jsonObjecta.put("assignmentId", depaid_id);
jsonArray1.add(jsonObjecta);
}
} else {
String org_depart = rowMap.getString("ORGPERM");
String deoa = "";
if (org_depart.contains(",")) {
String[] ds = org_depart.split(",");
for (String depaid :
ds) {
JSONObject jsonObjecta = new JSONObject();
jsonObjecta.put("assignmentType", "department");
jsonObjecta.put("assignmentId", depaid);
jsonArray1.add(jsonObjecta);
}
} else {
deoa = org_depart;
JSONObject jsonObjecta = new JSONObject();
jsonObjecta.put("assignmentType", "department");
jsonObjecta.put("assignmentId", deoa);
jsonArray1.add(jsonObjecta);
}
}
}
AddKnwlAC(jsonArray1,userContext.getSessionId(),id.substring(0,id.length()-1));
}
/**
* 授权知识
* @param jsonArray
* @param sid
* @param knwlId
* @return
*/
public boolean AddKnwlAC(JSONArray jsonArray, String sid, String knwlId) {
// 调用App
String sourceAppId = APPID;
// aslp服务地址
String aslp = "aslp://com.actionsoft.apps.kms/AddKnwlAC";
// 参数定义列表
Map params = new HashMap<String, Object>();
//[{"assignmentType":"department","assignmentId":"62196ff9-a26d-4be5-9480-3ef680886f63"},{"assignmentType":"user","assignmentId":"user1"}],必填
params.put("acList", jsonArray);
//sid如果为空则需要传createUser参数,非必填
params.put("sid", sid);
//知识ID,必填
params.put("knwlId", knwlId);
AppAPI appAPI = SDK.getAppAPI();
//给知识授权
ResponseObject ro = appAPI.callASLP(appAPI.getAppContext(sourceAppId), aslp, params);
System.out.println("授权>>>>>>>>>>>>"+ro);
return ro.isOk();
}
}