parent
c1aaa48771
commit
7b39bfadb5
|
@ -47,9 +47,6 @@ public class AttachmentFileServiceImpl extends BaseService<AttachmentFileEntity,
|
||||||
}
|
}
|
||||||
@Autowired
|
@Autowired
|
||||||
private IOerAnnexService oerAnnexService;
|
private IOerAnnexService oerAnnexService;
|
||||||
@Autowired
|
|
||||||
private IAttachmentFileService attachmentFileService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存附件
|
* 保存附件
|
||||||
* @param entity
|
* @param entity
|
||||||
|
@ -149,7 +146,7 @@ public class AttachmentFileServiceImpl extends BaseService<AttachmentFileEntity,
|
||||||
String fileName = URLDecoder.decode(fileInfo.getFile_name(), "UTF-8");
|
String fileName = URLDecoder.decode(fileInfo.getFile_name(), "UTF-8");
|
||||||
fileEntity.setaTFileName(fileName);
|
fileEntity.setaTFileName(fileName);
|
||||||
fileEntity.setaTFile(fileInfo.getData());
|
fileEntity.setaTFile(fileInfo.getData());
|
||||||
attachmentFileService.saveAttachment(fileEntity);
|
this.saveAttachment(fileEntity);
|
||||||
//保存附件关系
|
//保存附件关系
|
||||||
OerAnnexEntity annexEntity = new OerAnnexEntity();
|
OerAnnexEntity annexEntity = new OerAnnexEntity();
|
||||||
annexEntity.setMlid(mlid);
|
annexEntity.setMlid(mlid);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.hzya.frame.grpU8.nxproof.oerdjml.service;
|
||||||
|
|
||||||
|
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 报销单扩展类,api接口配置的扩展方法调这个类
|
||||||
|
* @Author xiangerlin
|
||||||
|
* @Date 2024/8/16 13:49
|
||||||
|
**/
|
||||||
|
public interface IOerDjmlExtService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存方法前,先调这个方法 组装参数
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysExtensionApiEntity saveExpensePre(SysExtensionApiEntity entity);
|
||||||
|
}
|
|
@ -0,0 +1,355 @@
|
||||||
|
package com.hzya.frame.grpU8.nxproof.oerdjml.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oerdjjsfs.entity.OerDjjsfsEntity;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oerdjml.dto.FileInfoDTO;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oerdjml.entity.OerDjmlEntity;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oerdjml.service.IOerDjmlExtService;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oerdjnr.entity.OerDjnrEntity;
|
||||||
|
import com.hzya.frame.grpU8.nxproof.oeryszb.entity.OerYszbEntity;
|
||||||
|
import com.hzya.frame.seeyon.entity.CollAttachmentResDTO;
|
||||||
|
import com.hzya.frame.seeyon.enums.ColEventTypeEnum;
|
||||||
|
import com.hzya.frame.seeyon.util.RestUtil;
|
||||||
|
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 扩展类,api接口上配置的扩展方法
|
||||||
|
* @Author xiangerlin
|
||||||
|
* @Date 2024/8/16 13:45
|
||||||
|
**/
|
||||||
|
@Service(value = "oerDjmlExtServiceImpl")
|
||||||
|
public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
||||||
|
|
||||||
|
Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
@Autowired
|
||||||
|
private RestUtil restUtil;
|
||||||
|
@Value("${savefile.path}")
|
||||||
|
public String DSK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存方法前,先调这个方法 组装参数
|
||||||
|
*
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SysExtensionApiEntity saveExpensePre(SysExtensionApiEntity entity) {
|
||||||
|
try {
|
||||||
|
String bodys = entity.getBodys();
|
||||||
|
Map<String, String> headers = entity.getHeaders();
|
||||||
|
String eventType = headers.get("eventType");
|
||||||
|
String formmainTableName = headers.get("formmainTableName");
|
||||||
|
String forsonTableName = headers.get("forsonTableName");
|
||||||
|
String djlxid = headers.get("djlxid");
|
||||||
|
String flowcode = headers.get("flowcode");
|
||||||
|
String fileApiCode = headers.get("file_api_code");
|
||||||
|
JSONObject bodyObj = JSONObject.parseObject(bodys);
|
||||||
|
JSONObject seeyonData = bodyObj.getJSONObject("businessDataStr");
|
||||||
|
if (null != seeyonData){
|
||||||
|
/**
|
||||||
|
* 流程发起 保存/更新单据 要全部数据
|
||||||
|
* 流程撤销 只更新状态,传单号和状态就好了
|
||||||
|
* 流程终止 只更新状态,传单号和状态就好了
|
||||||
|
* 流程结束 更新状态 并上传附件
|
||||||
|
*/
|
||||||
|
JSONObject formmainData = seeyonData.getJSONObject(formmainTableName);
|
||||||
|
JSONArray forsonData = seeyonData.getJSONArray(forsonTableName);
|
||||||
|
JSONObject forjsonData0 = forsonData.getJSONObject(0);
|
||||||
|
OerDjmlEntity djml = new OerDjmlEntity();
|
||||||
|
djml.setDjbh(formmainData.getString("field0001"));
|
||||||
|
djml.setLclb(eventType);
|
||||||
|
//流程发起
|
||||||
|
if (ColEventTypeEnum.ONSTART.getType().equals(eventType)){
|
||||||
|
djml.setGsdm(forjsonData0.getString("field0084"));
|
||||||
|
djml.setKjnd(forjsonData0.getString("field0082"));
|
||||||
|
djml.setDjlxId(djlxid);
|
||||||
|
djml.setZt("2");
|
||||||
|
djml.setCrerdm(formmainData.getString("field0107"));
|
||||||
|
djml.setCrermc("");
|
||||||
|
djml.setCrerdate(timestampConvert(formmainData.getString("start_date")));
|
||||||
|
djml.setDjdate((timestampConvert(formmainData.getString("field0002"))));
|
||||||
|
djml.setJe(formmainData.getString("field0080"));
|
||||||
|
djml.setJedx( Convert.numberToChinese(Double.valueOf(formmainData.getString("field0080")),true));
|
||||||
|
djml.setYjje("0.00");
|
||||||
|
djml.setThje("0.00");
|
||||||
|
djml.setBlje(formmainData.getString("field0080"));
|
||||||
|
djml.setFjs( formmainData.getString("field0004"));
|
||||||
|
djml.setZy( formmainData.getString("field0009"));
|
||||||
|
//部门代码
|
||||||
|
djml.setBmdm( formmainData.getString("field0006"));
|
||||||
|
djml.setBmmc( formmainData.getString("field0006"));
|
||||||
|
//项目代码
|
||||||
|
djml.setXmdm(forjsonData0.getString("field0074"));
|
||||||
|
djml.setXmmc(forjsonData0.getString("field0075"));
|
||||||
|
//个人代码
|
||||||
|
djml.setGrdm(formmainData.getString("field0108"));
|
||||||
|
djml.setGrmc("");
|
||||||
|
//经济代码
|
||||||
|
djml.setJjdm("");
|
||||||
|
djml.setJjmc("");
|
||||||
|
//银行帐号 开户银行
|
||||||
|
djml.setYhzh(forjsonData0.getString("field0079"));
|
||||||
|
djml.setKhyh(forjsonData0.getString("field0078"));
|
||||||
|
//当前审核节点、下个审核节点 ,不在grp审批,是不是不用填了
|
||||||
|
djml.setCurshjd("-9");
|
||||||
|
djml.setNextshjd("999");
|
||||||
|
djml.setFlowcode(flowcode);
|
||||||
|
djml.setJsfs(spliceStr(forjsonData0.getString("field0095"),forjsonData0.getString("field0094")));
|
||||||
|
//电话,oa上没有
|
||||||
|
djml.setTel(formmainData.getString("field0110"));
|
||||||
|
djml.setClf_ccr(formmainData.getString("field0010"));
|
||||||
|
//送审日期
|
||||||
|
djml.setSsrq( DateUtil.format(formmainData.getDate("startDate"),"yyyyMMddHHmmssSSS"));
|
||||||
|
djml.setSsrid("");
|
||||||
|
djml.setSsr("");
|
||||||
|
|
||||||
|
//报销明细
|
||||||
|
List<OerDjnrEntity> djnrList = new ArrayList<>();
|
||||||
|
//结算方式
|
||||||
|
List<OerDjjsfsEntity> jsfsList = new ArrayList<>();
|
||||||
|
//预算指标
|
||||||
|
List<OerYszbEntity> yszbList = new ArrayList<>();
|
||||||
|
//指标记录
|
||||||
|
int xh = 1;
|
||||||
|
for (int i=0; i<forsonData.size();i++) {
|
||||||
|
JSONObject forson = forsonData.getJSONObject(i);
|
||||||
|
String gsdm = forson.getString("field0084");
|
||||||
|
String kjnd = forson.getString("field0082");
|
||||||
|
String je = forson.getString("field0032");
|
||||||
|
//单据内容
|
||||||
|
OerDjnrEntity djnr = new OerDjnrEntity();
|
||||||
|
djnr.setXh(String.valueOf(xh));
|
||||||
|
djnr.setGsdm(gsdm);
|
||||||
|
djnr.setKjnd(kjnd);
|
||||||
|
djnr.setDjlxId(djlxid);
|
||||||
|
djnr.setBnxId(headers.get("bxmx_bnxid"));
|
||||||
|
djnr.setJe(je);
|
||||||
|
djnr.setBmdm(forson.getString("field0088"));
|
||||||
|
djnr.setBmmc(forson.getString("field0087"));
|
||||||
|
djnr.setXmdm(forson.getString("field0074"));
|
||||||
|
djnr.setXmmc(forson.getString("field0075"));
|
||||||
|
djnr.setJjdm("");
|
||||||
|
djnr.setJjmc("");
|
||||||
|
//grp库里有,不知道是什么 1001基本支出 2001项目支出(网银)
|
||||||
|
djnr.setFzx8dm("");
|
||||||
|
djnr.setFzx8mc("");
|
||||||
|
//指标id
|
||||||
|
djnr.setZbId(forson.getString("field0085"));
|
||||||
|
djnr.setJflxdm("");
|
||||||
|
djnr.setJflxmc("");
|
||||||
|
djnr.setZy(forson.getString("field0030"));
|
||||||
|
djnr.setClf_startdate(forson.getString("field0016"));
|
||||||
|
djnr.setClf_enddate(forson.getString("field0017"));
|
||||||
|
djnr.setClf_ccdd(forson.getString("field0019"));
|
||||||
|
djnr.setClf_ccksd(forson.getString("field0018"));
|
||||||
|
djnr.setClf_djzs(djml.getFjs());
|
||||||
|
djnr.setClf_ccts(forson.getString("field0023"));
|
||||||
|
djnr.setClf_ccrs(forson.getString("field0021"));
|
||||||
|
djnr.setClf_zw(forson.getString("field0092"));
|
||||||
|
djnr.setClf_jtgj(forson.getString("field0020"));
|
||||||
|
djnr.setClf_jtf(forson.getString("field0024"));
|
||||||
|
djnr.setClf_zsbz(forson.getString("field0077"));
|
||||||
|
djnr.setClf_zsf(forson.getString("field0025"));
|
||||||
|
//伙食补助是 标准金额
|
||||||
|
djnr.setCLF_HSBZ(forson.getString("field0026"));
|
||||||
|
//伙食费是 实际报销的金额
|
||||||
|
djnr.setClf_hsf(forson.getString("field0026"));
|
||||||
|
djnr.setClf_jtbz(forson.getString("field0024"));
|
||||||
|
djnr.setClf_qtf(forson.getString("field0028"));
|
||||||
|
djnr.setFjs(djml.getFjs());
|
||||||
|
djnrList.add(djnr);
|
||||||
|
//结算方式
|
||||||
|
OerDjjsfsEntity jsfs = new OerDjjsfsEntity();
|
||||||
|
jsfs.setGsdm(gsdm);
|
||||||
|
jsfs.setKjnd(kjnd);
|
||||||
|
jsfs.setDjlxId(djlxid);
|
||||||
|
jsfs.setBnxid(headers.get("jsfs_bnxid"));
|
||||||
|
jsfs.setXh(String.valueOf(xh));
|
||||||
|
jsfs.setJsfsdm(forson.getString("field0095"));
|
||||||
|
jsfs.setJsfsmc(forson.getString("field0094"));
|
||||||
|
jsfs.setKmdm(forson.getString("field0089"));
|
||||||
|
jsfs.setKmmc(forson.getString("field0066"));
|
||||||
|
jsfs.setSkr(forson.getString("field0096"));
|
||||||
|
jsfs.setKhyh(forson.getString("field0078"));
|
||||||
|
jsfs.setYhzh(forson.getString("field0079"));
|
||||||
|
jsfs.setJe(je);
|
||||||
|
jsfs.setYh("");
|
||||||
|
jsfs.setYhhh("");
|
||||||
|
jsfs.setProvince("");
|
||||||
|
jsfs.setCity("");
|
||||||
|
//支付方式为个人、公务卡时 可以选择 经办人、负责人、其他
|
||||||
|
jsfs.setRytype("");
|
||||||
|
//oa没有
|
||||||
|
jsfs.setYt(forson.getString("field0030"));
|
||||||
|
jsfsList.add(jsfs);
|
||||||
|
//预算指标
|
||||||
|
OerYszbEntity yszb = new OerYszbEntity();
|
||||||
|
BeanUtil.copyProperties(djnr,yszb);
|
||||||
|
yszb.setBnxId(headers.get("yszb_bnxid"));
|
||||||
|
yszb.setZbdm(forson.getString("field0085"));
|
||||||
|
yszb.setZy(forson.getString("field0111"));
|
||||||
|
yszb.setKmdm(forson.getString("field0089"));
|
||||||
|
yszb.setKmmc(forson.getString("field0066"));
|
||||||
|
yszb.setXh(String.valueOf(xh));
|
||||||
|
yszbList.add(yszb);
|
||||||
|
xh++;
|
||||||
|
}
|
||||||
|
logger.info("报销单主表:{}",JSONObject.toJSONString(djml));
|
||||||
|
logger.info("报销单明细表:{}",JSONObject.toJSONString(djnrList));
|
||||||
|
logger.info("报销单结算方式:{}",JSONObject.toJSONString(jsfsList));
|
||||||
|
logger.info("报销单预算指标:{}",JSONObject.toJSONString(yszbList));
|
||||||
|
djml.setOerDjnrEntityList(djnrList);
|
||||||
|
djml.setOerDjjsfsEntityList(jsfsList);
|
||||||
|
djml.setOerYszbEntityList(yszbList);
|
||||||
|
}else if (ColEventTypeEnum.ONSTOP.getType().equals(eventType)){
|
||||||
|
//流程终止 修改状态,释放指标
|
||||||
|
djml.setZt("0");
|
||||||
|
}else if (ColEventTypeEnum.ONCANCEL.getType().equals(eventType)){
|
||||||
|
//流程撤销 修改状态,释放指标
|
||||||
|
djml.setZt("1");
|
||||||
|
}else if (ColEventTypeEnum.ONPROCESSFINISHED.getType().equals(eventType)){
|
||||||
|
//流程处理事件
|
||||||
|
djml.setZt("3");
|
||||||
|
djml.setCurshjd("999");
|
||||||
|
djml.setNextshjd("-1");
|
||||||
|
//查询协同附件
|
||||||
|
List<FileInfoDTO> fileInfoList = fileDownload(seeyonData.getString("summaryId"),fileApiCode);
|
||||||
|
}
|
||||||
|
String djmlStr = JSONObject.toJSONString(djml);
|
||||||
|
logger.info("差旅报销单报文:{}",djmlStr);
|
||||||
|
}
|
||||||
|
}catch (Exception ex ){
|
||||||
|
logger.error("保存报销单之前组装参数出错",ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳转成 yyyyMMdd
|
||||||
|
* @param timestamp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String timestampConvert(String timestamp){
|
||||||
|
if (StrUtil.isNotEmpty(timestamp)){
|
||||||
|
try {
|
||||||
|
DateTime date = DateUtil.date(Long.valueOf(timestamp));
|
||||||
|
String formattedDate = DateUtil.format(date, "yyyyMMdd");
|
||||||
|
return formattedDate;
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("日期转换出错:{}",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件下载并压缩成zip
|
||||||
|
* @param summaryId
|
||||||
|
* @param apiCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<FileInfoDTO> fileDownload(String summaryId,String apiCode){
|
||||||
|
try {
|
||||||
|
List<CollAttachmentResDTO> colAttachmentList = restUtil.getColAttachments(summaryId, "0", apiCode, "hzya");
|
||||||
|
//下载协同附件
|
||||||
|
if (CollectionUtils.isNotEmpty(colAttachmentList)){
|
||||||
|
List<FileInfoDTO> fileList = new ArrayList<>();
|
||||||
|
for (CollAttachmentResDTO att : colAttachmentList) {
|
||||||
|
FileInfoDTO fileInfoDTO = new FileInfoDTO();
|
||||||
|
|
||||||
|
String fileName = URLDecoder.decode(att.getFilename(), "UTF-8");
|
||||||
|
byte[] bytes = restUtil.downloadFileBytes("hzya", apiCode, att.getFileUrl(), fileName);
|
||||||
|
String filePath = DSK+ File.separator+DateUtil.today()+File.separator+att.getFileUrl()+"."+att.getExtension();
|
||||||
|
File file = new File(filePath);
|
||||||
|
// 使用 FileOutputStream 写入字节数组到文件
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||||
|
fos.write(bytes);
|
||||||
|
}
|
||||||
|
if (null != file){
|
||||||
|
String zipPath = DSK+File.separator+DateUtil.today()+File.separator+att.getSubReference()+".zip";
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath), Charset.forName("GBK"));
|
||||||
|
writeZipFile(file, zos, fileName);
|
||||||
|
zos.close();
|
||||||
|
// 获取压缩文件的字节数组
|
||||||
|
File zipFile = new File(zipPath);
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) zipFile.length());
|
||||||
|
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile));
|
||||||
|
int buf_size = 1024;
|
||||||
|
byte[] buffer = new byte[buf_size];
|
||||||
|
int len = 0;
|
||||||
|
while (-1 != (len = bufferedInputStream.read(buffer, 0, buf_size))) {
|
||||||
|
byteArrayOutputStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
byte[] fileByte = byteArrayOutputStream.toByteArray();
|
||||||
|
fileInfoDTO.setData(fileByte);
|
||||||
|
fileInfoDTO.setFile_size(att.getSize());
|
||||||
|
fileInfoDTO.setFile_name(fileName);
|
||||||
|
fileList.add(fileInfoDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error("下载附件出错:{}",e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 把文件压缩成zip
|
||||||
|
* @param file 要压缩的文件
|
||||||
|
* @param zos 文件压缩流
|
||||||
|
* @param fileName 文件名
|
||||||
|
*/
|
||||||
|
private void writeZipFile(File file, ZipOutputStream zos, String fileName) {
|
||||||
|
if (null != file && null != zos) {
|
||||||
|
try {
|
||||||
|
logger.info("=====压缩文件=====");
|
||||||
|
zos.putNextEntry(new ZipEntry(fileName));
|
||||||
|
FileInputStream fos = new FileInputStream(file);
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(fos);
|
||||||
|
int len;
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
while ((len = bis.read(buf, 0, 1024)) != -1) {
|
||||||
|
zos.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
bis.close();
|
||||||
|
fos.close();
|
||||||
|
logger.info("=====压缩完成=====");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error("=====压缩文件出错=====");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* code和name拼接[]
|
||||||
|
* @param code
|
||||||
|
* @param name
|
||||||
|
* @return 格式:03[公务卡]
|
||||||
|
*/
|
||||||
|
private String spliceStr(String code,String name){
|
||||||
|
String template = "{}[{}]";
|
||||||
|
return StrUtil.format(template,code,name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,8 @@ public class SeeYonInterFaceEntity extends BaseEntity {
|
||||||
private String eventType;
|
private String eventType;
|
||||||
//表单名称
|
//表单名称
|
||||||
private String name;
|
private String name;
|
||||||
|
//流程id
|
||||||
|
private String summaryId;
|
||||||
public String getTabName() {
|
public String getTabName() {
|
||||||
return tabName;
|
return tabName;
|
||||||
}
|
}
|
||||||
|
@ -99,4 +101,12 @@ public class SeeYonInterFaceEntity extends BaseEntity {
|
||||||
public void setEventType(String eventType) {
|
public void setEventType(String eventType) {
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSummaryId() {
|
||||||
|
return summaryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSummaryId(String summaryId) {
|
||||||
|
this.summaryId = summaryId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,11 @@ package com.hzya.frame.seeyon.util;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.hzya.frame.seeyon.entity.CtpFileEntity;
|
import com.hzya.frame.seeyon.entity.CollAttachmentResDTO;
|
||||||
import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity;
|
import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity;
|
||||||
import com.hzya.frame.sysnew.application.api.service.ISysApplicationApiService;
|
import com.hzya.frame.sysnew.application.api.service.ISysApplicationApiService;
|
||||||
import com.hzya.frame.web.exception.BaseSystemException;
|
import com.hzya.frame.web.exception.BaseSystemException;
|
||||||
|
@ -17,6 +18,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description 致远rest接口工具类
|
* @Description 致远rest接口工具类
|
||||||
|
@ -25,7 +27,6 @@ import java.util.HashMap;
|
||||||
**/
|
**/
|
||||||
@Component
|
@Component
|
||||||
public class RestUtil {
|
public class RestUtil {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysApplicationApiService sysApplicationApiService;
|
private ISysApplicationApiService sysApplicationApiService;
|
||||||
static Logger logger = LoggerFactory.getLogger(RestUtil.class);
|
static Logger logger = LoggerFactory.getLogger(RestUtil.class);
|
||||||
|
@ -69,6 +70,51 @@ public class RestUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 查询协同附件列表
|
||||||
|
* @param summaryId col_summary表id
|
||||||
|
* @param attType 0代表附件,2代表关联文档,“0,2”代表附件和关联文档
|
||||||
|
* @param apiCode 接口编码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<CollAttachmentResDTO> getColAttachments(String summaryId,String attType,String apiCode,String loginName){
|
||||||
|
if (StrUtil.isNotEmpty(summaryId) && StrUtil.isNotEmpty(apiCode)){
|
||||||
|
SysApplicationApiEntity sysApp = getByCode(apiCode);
|
||||||
|
String token = getToken(loginName,sysApp);
|
||||||
|
String appUrl = sysApp.getAppUrl();
|
||||||
|
if (StrUtil.isEmpty(attType)){
|
||||||
|
attType = "0";
|
||||||
|
}
|
||||||
|
String url = "/seeyon/rest/coll/attachments/@SummaryID@/@attType@";
|
||||||
|
url = url.replaceAll("@SummaryID@",summaryId).replaceAll("@attType@",attType);
|
||||||
|
String body = HttpRequest.get(appUrl + url).header("token", token).execute().body();
|
||||||
|
if (StrUtil.isNotEmpty(body) && JSONUtil.isTypeJSON(body)){
|
||||||
|
List<CollAttachmentResDTO> list = JSON.parseArray(body,CollAttachmentResDTO.class);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 附件下载
|
||||||
|
* @param loginName oa登录名
|
||||||
|
* @param apiCode 接口编码
|
||||||
|
* @param fileId 附件id
|
||||||
|
* @param fileName 附件名
|
||||||
|
* @return 附件字节数组
|
||||||
|
*/
|
||||||
|
public byte[] downloadFileBytes(String loginName,String apiCode,String fileId,String fileName){
|
||||||
|
if (StrUtil.isNotEmpty(apiCode)){
|
||||||
|
SysApplicationApiEntity sysApp = getByCode(apiCode);
|
||||||
|
String token = getToken(loginName,sysApp);
|
||||||
|
String appUrl = sysApp.getAppUrl();
|
||||||
|
String url = "/seeyon/rest/attachment/file/@ctp_file_ID@?fileName=@文件名@&token=@token@";
|
||||||
|
url = url.replaceAll("@ctp_file_ID@",fileId).replaceAll("@文件名@",fileName).replaceAll("@token@",token);
|
||||||
|
byte[] bytes = HttpUtil.downloadBytes(appUrl + url);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取token
|
* 获取token
|
||||||
* @param login_name
|
* @param login_name
|
||||||
|
@ -78,36 +124,45 @@ public class RestUtil {
|
||||||
public String getToken(String login_name,String api_code){
|
public String getToken(String login_name,String api_code){
|
||||||
if (StrUtil.isNotEmpty(api_code)){
|
if (StrUtil.isNotEmpty(api_code)){
|
||||||
SysApplicationApiEntity sysApp = getByCode(api_code);
|
SysApplicationApiEntity sysApp = getByCode(api_code);
|
||||||
if (null != sysApp){
|
return getToken(login_name,sysApp);
|
||||||
HashMap<String, String> hashMap = new HashMap<>();
|
|
||||||
String app_url = sysApp.getAppUrl();
|
|
||||||
String url = app_url+"/seeyon/rest/token";
|
|
||||||
String headerIn = sysApp.getHeaderIn();
|
|
||||||
JSONArray headers = JSON.parseArray(headerIn);
|
|
||||||
for (int i = 0; i < headers.size(); i++) {
|
|
||||||
JSONObject object1 = headers.getJSONObject(i);
|
|
||||||
String parameterName = object1.getString("parameterName");
|
|
||||||
if ("userName".equals(parameterName) || "password".equals(parameterName) || "loginName".equals(parameterName)){
|
|
||||||
String example = object1.getString("example");
|
|
||||||
hashMap.put(parameterName,example);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotEmpty(login_name)){
|
|
||||||
hashMap.put("loginName",login_name);
|
|
||||||
}
|
|
||||||
String result = HttpRequest.post(url).body(JSON.toJSONString(hashMap)).execute().body();
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
||||||
if (null != jsonObject) {
|
|
||||||
logger.info("======token:{}======" ,jsonObject.getString("id"));
|
|
||||||
return jsonObject.getString("id");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
throw new BaseSystemException("api_code不能为空");
|
throw new BaseSystemException("api_code不能为空");
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token
|
||||||
|
* @param login_name oa登录名
|
||||||
|
* @param sysApp 应用信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getToken(String login_name,SysApplicationApiEntity sysApp){
|
||||||
|
if (null != sysApp){
|
||||||
|
HashMap<String, String> hashMap = new HashMap<>();
|
||||||
|
String app_url = sysApp.getAppUrl();
|
||||||
|
String url = app_url+"/seeyon/rest/token";
|
||||||
|
String headerIn = sysApp.getHeaderIn();
|
||||||
|
JSONArray headers = JSON.parseArray(headerIn);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
JSONObject object1 = headers.getJSONObject(i);
|
||||||
|
String parameterName = object1.getString("parameterName");
|
||||||
|
if ("userName".equals(parameterName) || "password".equals(parameterName) || "loginName".equals(parameterName)){
|
||||||
|
String example = object1.getString("example");
|
||||||
|
hashMap.put(parameterName,example);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(login_name)){
|
||||||
|
hashMap.put("loginName",login_name);
|
||||||
|
}
|
||||||
|
String result = HttpRequest.post(url).body(JSON.toJSONString(hashMap)).execute().body();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
if (null != jsonObject) {
|
||||||
|
logger.info("======token:{}======" ,jsonObject.getString("id"));
|
||||||
|
return jsonObject.getString("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private SysApplicationApiEntity getByCode(String api_code){
|
private SysApplicationApiEntity getByCode(String api_code){
|
||||||
if (StrUtil.isNotEmpty(api_code)){
|
if (StrUtil.isNotEmpty(api_code)){
|
||||||
SysApplicationApiEntity sysApp = new SysApplicationApiEntity();
|
SysApplicationApiEntity sysApp = new SysApplicationApiEntity();
|
||||||
|
|
Loading…
Reference in New Issue