You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
4.6 KiB
Java

package com.weaver.seconddev.workflow.action;
/**
* author:liuhao
* use:PDF https://www.kdocs.cn/l/ciMvDAGQsXaH
*/
import com.alibaba.fastjson.JSONObject;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.eteams.file.client.file.FileCapabilityParam;
import com.weaver.eteams.file.client.file.FileCapabilityResult;
import com.weaver.eteams.file.client.param.FileCovertParam;
import com.weaver.eteams.file.client.remote.OfficialFileConvertService;
import com.weaver.framework.rpc.annotation.RpcReference;
import com.weaver.seconddev.tjzs.cronjob.job.util.ETUtil;
import com.weaver.seconddev.tjzs.cronjob.job.util.ZsConfig;
import com.weaver.seconddev.tjzs.tb.config.EbDbDataSourceConfig;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service("esb_releaseNoticeTransPdf")
public class ReleaseNoticeTransPdf implements EsbServerlessRpcRemoteInterface {
@RpcReference
private OfficialFileConvertService officialFileConvertService;
@Autowired
private JdbcTemplate jdbcTemplate = new JdbcTemplate(EbDbDataSourceConfig.dbDataSource());
@Override
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
Map<String, Object> rs = new HashMap<>();
String zhengwendocid = (String)params.get("docid");//这里正文拿到的是docid
String id = (String)params.get("id");//表单数据id
String userId = (String)params.get("userId");//当前登录用户id
String resultdetails = getWdContent(userId,zhengwendocid);
if(resultdetails.length()>0) {
JSONObject jsonObject = JSONObject.parseObject(resultdetails);
JSONObject data = jsonObject.getJSONObject("data");
if(data.containsKey("content")&&data.getString("content").length()>0) {
String zwfieldid = data.getString("content");
Long feild = Long.parseLong(zwfieldid);
FileCapabilityParam fileCapabilityParam = new FileCapabilityParam();
fileCapabilityParam.setOption("CONVERT");
fileCapabilityParam.setFileId(feild);
fileCapabilityParam.setUserId(userId);
fileCapabilityParam.setModule("workflow");
FileCovertParam fileCovertParam = new FileCovertParam();
fileCovertParam.setTargetType("pdf");
fileCapabilityParam.setFileCovertParam(fileCovertParam);
WeaResult<FileCapabilityResult> result = officialFileConvertService.capabilityFile(fileCapabilityParam);
log.error("格式转换msg:{},code:{}",result.getMsg(),result.getCode());
if(result.getCode() == 200) {
FileCapabilityResult fileCapabilityResult = result.getData();
String targetFileId = fileCapabilityResult.getTargetFileId();
//更新附件PDF字段
String sql = "update ft_942048192473825282 set zwpdf = '"+targetFileId+"' where id = "+id;
log.error("howecsql:"+sql);
jdbcTemplate.update(sql);
}
rs.put("msg",result.getMsg());
rs.put("code",result.getCode());
return WeaResult.success(rs);
}else {
rs.put("msg","该正文没有文件生成无需转换pdf");
rs.put("code",500);
}
}else {
rs.put("msg","调用根据docid获取文件内容接口失败联系管理员");
rs.put("code",500);
}
return WeaResult.success(rs);
}
/**
* use:
*/
public static String getWdContent(String userid,String docid) {
String token = ETUtil.getToken();
String url = ZsConfig.zshost;
String rs = "";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url+"/api/doc/document/v2/info?access_token="+token+"&userid="+userid+"&id="+docid)
.get()
.addHeader("cache-control", "no-cache")
.build();
try {
Response response = client.newCall(request).execute();
rs = response.body().string();
}catch (Exception e){
}
return rs;
}
}