110 lines
4.5 KiB
Java
110 lines
4.5 KiB
Java
|
|
package com.seeyon.apps.daohuaxiangSys.jkts.service;
|
||
|
|
|
||
|
|
import com.alibaba.fastjson.JSON;
|
||
|
|
import com.alibaba.fastjson.JSONObject;
|
||
|
|
import com.seeyon.apps.daohuaxiangSys.jkts.util.FanWeiNewUtil;
|
||
|
|
import com.seeyon.apps.daohuaxiangSys.jkts.util.FanWeiUtil;
|
||
|
|
import com.seeyon.apps.daohuaxiangSys.jkts.util.InterfaceListUtil;
|
||
|
|
import com.seeyon.apps.daohuaxiangSys.jkts.util.PropKit;
|
||
|
|
import com.seeyon.apps.ext.workflow.vo.FormDataVo;
|
||
|
|
import com.seeyon.apps.ext.workflow.vo.SuperNodeContext;
|
||
|
|
import com.seeyon.ctp.common.AppContext;
|
||
|
|
import com.seeyon.ctp.common.SystemEnvironment;
|
||
|
|
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
|
||
|
|
import com.seeyon.ctp.common.po.filemanager.Attachment;
|
||
|
|
import org.songjian.utils.json.JSONArray;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
public class TongYongService {
|
||
|
|
|
||
|
|
|
||
|
|
private AttachmentManager attachmentManager;
|
||
|
|
|
||
|
|
public void setAttachmentManager(AttachmentManager attachmentManager) {
|
||
|
|
this.attachmentManager = attachmentManager;
|
||
|
|
}
|
||
|
|
|
||
|
|
public AttachmentManager getAttachmentManagery() {
|
||
|
|
if (attachmentManager == null) {
|
||
|
|
attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||
|
|
}
|
||
|
|
return attachmentManager;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Map<String, Object> sendInter(FormDataVo formDataVo) throws Exception {
|
||
|
|
String pathId = formDataVo.getFieldData("上传附件").getStringValue();
|
||
|
|
//附件
|
||
|
|
JSONArray faths = null;
|
||
|
|
if (pathId == null || "".equals(pathId)) {
|
||
|
|
faths = new JSONArray();
|
||
|
|
} else {
|
||
|
|
faths = getPathUrl(pathId);
|
||
|
|
}
|
||
|
|
//封装参数
|
||
|
|
Map parm = FanWeiUtil.createWF(formDataVo, faths);
|
||
|
|
//调用新建接口
|
||
|
|
String userid = formDataVo.getFieldData("客户id").getStringValue();
|
||
|
|
String s = FanWeiUtil.PostRestful(parm, userid);
|
||
|
|
JSONObject returnMsg = JSON.parseObject(s);
|
||
|
|
Object code = returnMsg.get("code");
|
||
|
|
System.out.println("新建code:" + code);
|
||
|
|
Map<String, Object> map = new HashMap<>();
|
||
|
|
if ("SUCCESS".equals(code.toString())) {
|
||
|
|
//调用提交接口
|
||
|
|
// Map data = (Map) returnMsg.get("data");
|
||
|
|
// Object requestid = data.get("requestid");
|
||
|
|
// String msg = FanWeiUtil.PostRestfulbyForm(requestid.toString(), userid);
|
||
|
|
// JSONObject tiJiaoReturnMsg = JSON.parseObject(msg);
|
||
|
|
// Object code2 = tiJiaoReturnMsg.get("code");
|
||
|
|
// System.out.println("提交code:" + code2);
|
||
|
|
map.put("code", "200");
|
||
|
|
map.put("msg", "推送成功");
|
||
|
|
map.put("request", parm.toString());
|
||
|
|
map.put("response", s);
|
||
|
|
} else {
|
||
|
|
// Map data = (Map) returnMsg.get("errMsg");
|
||
|
|
map.put("code", "300");
|
||
|
|
map.put("msg", "新建流程失败!");
|
||
|
|
map.put("request", parm.toString());
|
||
|
|
map.put("response", s);
|
||
|
|
}
|
||
|
|
return map;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取附件路径
|
||
|
|
* @param pathId
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public JSONArray getPathUrl(String pathId) throws IOException {
|
||
|
|
InterfaceListUtil interfaceListUtil = new InterfaceListUtil();
|
||
|
|
String oatoken = interfaceListUtil.getToken(PropKit.getProp(PropKit.LOGINNAME));
|
||
|
|
long aLong = Long.parseLong(pathId);
|
||
|
|
final List<Long> attachmentIds = attachmentManager.getBySubReference(aLong);
|
||
|
|
JSONArray jsonArray = new JSONArray();
|
||
|
|
for (int i = 0 ; i < attachmentIds.size();i++) {
|
||
|
|
Attachment attachment = attachmentManager.getAttachmentByFileURL(attachmentIds.get(i));
|
||
|
|
Long fileUrl = attachment.getFileUrl();
|
||
|
|
String filename = attachment.getFilename();
|
||
|
|
String fileType = filename.substring(filename.lastIndexOf(".")+1);
|
||
|
|
String oaFileName = filename.substring(0,filename.lastIndexOf("."));
|
||
|
|
//调用接口下载文件,文件存放在指定的路径下
|
||
|
|
String dowUrl = PropKit.getProp(PropKit.DOWURL)+"/"+fileUrl+"?fileName="+fileType+"&token="+oatoken;
|
||
|
|
String str = SystemEnvironment.getApplicationFolder();
|
||
|
|
String dowPath = str+"/dhxfile/"+filename;
|
||
|
|
String download = interfaceListUtil.download(dowUrl, dowPath);
|
||
|
|
JSONObject jsonObject = new JSONObject();
|
||
|
|
jsonObject.put("name", filename);
|
||
|
|
jsonObject.put("type", fileType);
|
||
|
|
jsonObject.put("url", PropKit.getProp(PropKit.JYNCFILE)+"/"+filename);
|
||
|
|
jsonArray.add(jsonObject);
|
||
|
|
}
|
||
|
|
return jsonArray;
|
||
|
|
}
|
||
|
|
}
|