Commit 1dc64b43 authored by Luochenglong's avatar Luochenglong

Merge remote-tracking branch 'origin/remote_dev' into remote_dev

parents b135f26a 56a37a0d
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.hand.kinggrid;
import java.util.Formatter;
/**
* <p>
* 字节 16进制字串转换工具类
* </p>
*
* @author hubin
* @Date 2016-01-20
*/
public class Byte2Hex {
/**
*
* 字节转换为 16 进制字符串
*
* @param b
* 字节
* @return
*/
public static String byte2Hex( byte b ) {
String hex = Integer.toHexString(b);
if ( hex.length() > 2 ) {
hex = hex.substring(hex.length() - 2);
}
while ( hex.length() < 2 ) {
hex = "0" + hex;
}
return hex;
}
/**
*
* 字节数组转换为 16 进制字符串
*
* @param bytes
* 字节数组
* @return
*/
public static String byte2Hex( byte[] bytes ) {
Formatter formatter = new Formatter();
for ( byte b : bytes ) {
formatter.format("%02x", b);
}
String hash = formatter.toString();
formatter.close();
return hash;
}
}
package com.hand.kinggrid;
import com.alibaba.fastjson.JSONObject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
public class ContractSignaturesNew
{
public static String hl_contract_signatures(String file_path, String sign_path, Object[] param,String server_url,String app_id,String app_security)
throws IOException, NoSuchAlgorithmException
{
String contractid = UUID.randomUUID().toString().replaceAll("-", "");
HttpRequest request = MainRequest.createHttpRequest("/api/cnt/sign",server_url,app_id,app_security);
InputStream is = null;
String status;
String signer_info;
try
{
File file = new File(file_path);
request.addFile("pdf_file", file);
request.addParam("contract_name", "合同名称");
request.addParam("contract_id", contractid);
request.addParam("biz_id",
UUID.randomUUID().toString().replaceAll("-", ""));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
request.addParam("biz_time", sdf.format(new Date()));
for(int i=0;i<param.length;i++){
signer_info = param[i].toString();
request.addParam("signer_info", signer_info);
}
/*
* if (qf_flag.equalsIgnoreCase("Y")) { request.addParam( "signer_info",
* "[{code:\"hlrzzl\",seal_code:\"9295f56b09124d508079b85f4a1e7e19\",seal_width:151,fontname:\"����\",fontsize:\"50\",fontcolor:\"#FF00FF\",pageno:\"0\",text:\"��ͬӡ��λ��\",qfzstart:\"1\",qfzdistance:\"200\"}]"
* ); } else { request.addParam( "signer_info",
* "[{code:\"hlrzzl\",seal_code:\"9295f56b09124d508079b85f4a1e7e19\",seal_width:151,fontname:\"����\",fontsize:\"50\",fontcolor:\"#FF00FF\",pageno:\"0\",text:\"��ͬӡ��λ��\"}]"
* ); }
*
* if (org_flag.equalsIgnoreCase("Y")) { request.addParam( "signer_info",
* "[{code:\"hlrzzl\",seal_code:\"fdd2f48507cb460fb372be3af2551a71\",seal_width:151,fontname:\"����\",fontsize:\"50\",fontcolor:\"#FF00FF\",pageno:\"0\",text:\"����ӡ��λ��\"}]"
* ); }
*/
request.send();
JSONObject json = JSONObject.parseObject(request.resultToString());
if (json.getInteger("code").intValue() == 1)
{
ContractWithTemplate.downFiles(
json.getJSONArray("record_saved_urls"),
file_path,
server_url,
app_id,
app_security);
status = "SUCCESS";
} else {
status = "FAILURE";
}
}
finally
{
if (is != null) {
is.close();
}
}
return status;
}
}
\ No newline at end of file
package com.hand.kinggrid;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* 合同相关测试(使用模板)接口
* @author Administrator
*
*/
public class ContractWithTemplate {
//public static final String SERVER_URL = "http://10.203.0.11:8989/tosignserver";
/**
* 信签服务器对接应用ID
*/
//public static final String APP_ID = "ac4a3bd1bf6f44fa86477ac251933259";
/**
* 信签服务器对接应用密钥
*/
// public static final String APP_SECURITY = "7lQ7GC1HSviWAFG6";
public static void main(String[] args) throws IOException {
//String contractid = "testte222211";
String contractid = UUID.randomUUID().toString().replaceAll("-", "");//合同编号,随机生成
JSONObject json = generateContract(contractid , null);
//System.out.println(json);
if(json.getInteger("code") == 1){//创建成功
downFiles(json.getJSONArray("doc_last_urls"), "d:/"+contractid,null,null,null);
json = signContract(contractid,null);
json = signContract2(contractid,null);
if(json.getInteger("code") == 1){//签署成功
downFiles(json.getJSONArray("record_saved_urls"), "d:/"+contractid,null,null,null);
System.out.println("record_saved_urls:"+json.getJSONArray("record_saved_urls"));
}else{
System.out.println(json);
}
}
}
/**
* 下载多个文件保存在文件夹
* @param urls
* @param savePath
* @throws IOException
*/
public static final void downFiles(JSONArray urls , String savePath,String server_url,String app_id,String app_security) throws IOException{
for (Object url : urls) {
downFile((String)url, savePath,server_url,app_id,app_security);
}
}
/**
* 下载文件保存
* @param url
* @param savePath
* @throws IOException
*/
public static final void downFile(String url , String savePath,String server_url,String app_id,String app_security) throws IOException{
HttpRequest request = MainRequest.createHttpRequest(url,server_url,app_id,app_security);
//HttpRequest request = new HttpRequest(url);
request.send();
int code = request.getResponseCode();
if(code==200){
FileOutputStream fos = null;
try{
String fileName = savePath;
if(!(savePath.endsWith("/")|| savePath.endsWith("\\"))){
fileName +="/";
}
fileName+=request.getDownFileName();
File file = new File(fileName);
//file.getParentFile().mkdirs();
fos = new FileOutputStream(file);
//System.out.println("保存文件至:"+fileName);
request.result(fos);
}finally{
if(fos!=null){
fos.close();
}
}
}else{
System.out.println("错误信息:"+request.resultToString());
}
}
/**
* 使用模板创建合同
* @throws IOException
*/
public static JSONObject generateContract(String contractid , String contract_tpl_code) throws IOException{
HttpRequest request = MainRequest.createHttpRequest("/api/contract/start",null,null,null);
//{"姓名":"李东长","cardname_ID":"360111198708080899","year":"2018","month":"01","day":"01"}
JSONObject docx_metadata = new JSONObject(true);
docx_metadata.put("INSURANCE_COMPANY", "信签售后");
docx_metadata.put("INSURANCE_MAN", "龚琪");
docx_metadata.put("PLATE_NUM", "京A88888");
docx_metadata.put("INSURANCE_YEAR", "2018");
docx_metadata.put("INSURANCE_MONTH", "05");
docx_metadata.put("INSURANCE_DAY", "21");
docx_metadata.put("INSURANCE_MONEY", "50000");
docx_metadata.put("SIGN_YEAR", "2018");
docx_metadata.put("SIGN_MONTH", "05");
docx_metadata.put("SIGN_DAY", "21");
//quest.addFile("attach_file", new File("d:/t1.pdf"));
//request.addFile("attach_file", new File("d:/t2.gif"));
//request.addFile("attach_file_2", new File("d:/test.docx"));
//request.addParam("contract_tlp_code",contract_tpl_code);
request.addParam("contract_tlp_code","nxs001");
request.addParam("doc_metadata",docx_metadata.toJSONString());
//设置合同ID
request.addParam("contract_id", contractid);
//设置合同名称参数
request.addParam("contract_name", "测试");
//设置业务编码参数
request.addParam("biz_id", UUID.randomUUID().toString().replaceAll("-", ""));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置业务时间参数
request.addParam("biz_time", sdf.format(new Date()));
request.send();
return JSONObject.parseObject(request.resultToString());
}
/**
* 签署合同
* @throws IOException
*/
public static JSONObject signContract(String contractid , String signer_code ) throws IOException{
HttpRequest request = MainRequest.createHttpRequest("/api/contract/sign",null,null,null);
request.addParam("contract_id", contractid);
request.addParam("biz_id", UUID.randomUUID().toString().replaceAll("-", ""));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置业务时间参数
request.addParam("biz_time", sdf.format(new Date()));
//设置签署人的编码
request.addParam("signer_code", signer_code);
//设置签署位置信息
//request.addParam("signatures", "[{ y:680,x:200,pageno:\"1\"}]");
request.send();
return JSONObject.parseObject(request.resultToString());
}
public static JSONObject signContract2(String contractid , String signer_code ) throws IOException{
HttpRequest request = MainRequest.createHttpRequest("/api/contract/sign",null,null,null);
request.addParam("contract_id", contractid);
request.addParam("biz_id", UUID.randomUUID().toString().replaceAll("-", ""));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//设置业务时间参数
request.addParam("biz_time", sdf.format(new Date()));
//设置签署人的编码
request.addParam("signer_code", "xurong");
//设置签署位置信息
//request.addParam("signatures", "[{ y:680,x:200,pageno:\"1\"}]");
request.send();
return JSONObject.parseObject(request.resultToString());
}
}
package com.hand.kinggrid;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public
class FileHolder {
private String filename;
private File file;
private InputStream is ;
public FileHolder(File file) {
this.filename = file.getName();
this.file = file;
}
public FileHolder(String filename , InputStream is) {
this.filename = filename;
this.is = is;
}
public InputStream getInputStream() throws FileNotFoundException{
if(is == null){
return new FileInputStream(file);
}
return is;
}
public String getFilename() {
return filename;
}
}
package com.hand.kinggrid;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/**
* HTTP 简单封装
* @author Administrator
*
*/
public class HttpRequest {
/**
* https 域名校验
*/
private class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
/**
* https 证书管理
*/
private class TrustAnyTrustManager implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
}
private static String CHARSET = "UTF-8";
private static final SSLSocketFactory sslSocketFactory = initSSLSocketFactory();
private static final TrustAnyHostnameVerifier trustAnyHostnameVerifier = new HttpRequest(null).new TrustAnyHostnameVerifier();
private static SSLSocketFactory initSSLSocketFactory() {
try {
TrustManager[] tm = {new HttpRequest(null).new TrustAnyTrustManager() };
SSLContext sslContext = SSLContext.getInstance("TLS"); // ("TLS", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
return sslContext.getSocketFactory();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String end = "\r\n";
private static String PREFIX = "--";
public String url;
private String requestMethod = "POST";
private int readTimeout =30000;
protected Map<String,String> headers = new LinkedHashMap<String, String>();
protected Map<String , List<FileHolder>> fileMap = new LinkedHashMap<String, List<FileHolder>>();
protected Map<String,List<String>> params = new LinkedHashMap<String, List<String>>();
HttpURLConnection conn;
private int responseCode;
private String charset = CHARSET;
public HttpRequest(String url){
this.url = url;
}
/**
* 添加header信息
* @param key
* @param value
*/
public HttpRequest addHeader(String key , String value){
this.headers.put(key, value);
return this;
}
public HttpRequest addHeaders(Map<String,String> maps){
this.headers.putAll(maps);
return this;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
/**
* 添加参数
* @param key
* @param value
*/
public HttpRequest addParam(String key , String value){
if(value==null || "".equals(value)){
return this;
}
List<String> files = params.get(key);
if(files == null){
files = new ArrayList<String>();
}
files.add(value);
this.params.put(key, files);
return this;
}
public HttpRequest addInputStream(String key , String filename , InputStream is){
List<FileHolder> files = fileMap.get(key);
if(files == null){
files = new ArrayList<FileHolder>();
}
files.add(new FileHolder(filename ,is ));
this.fileMap.put(key, files);
return this;
}
public HttpRequest addFile(String key , File file){
List<FileHolder> files = fileMap.get(key);
if(files == null){
files = new ArrayList<FileHolder>();
}
files.add(new FileHolder(file));
this.fileMap.put(key, files);
return this;
}
private void writeFile(OutputStream out, InputStream fis , String name , String filename) throws IOException{
out.write((PREFIX + boundary + end).getBytes(charset));
String contentDisposition = "Content-Disposition: form-data; name=\"" + name
+ "\"; filename=\"" + filename + "\""+end;
out.write(contentDisposition.getBytes(charset));
out.write(("Content-Type: application/octet-stream"+end).getBytes(charset));
out.write(end.getBytes(charset));
byte[] buffer = new byte[1024];
for (int n = -1; (n = fis.read(buffer)) != -1;) {
out.write(buffer, 0, n);
}
out.write(end.getBytes(charset));
}
private void writeFiles(OutputStream out) throws IOException{
Set<String> keySet = fileMap.keySet();
for (Iterator<String> it = keySet.iterator(); it.hasNext();) {
String name = it.next();
List<FileHolder> value = fileMap.get(name);
for (FileHolder fileHolder : value) {
InputStream fis = null;
try{
fis = fileHolder.getInputStream();
writeFile(out, fis, name, fileHolder.getFilename());
}finally{
if(fis!=null){
try{
fis.close();
}catch(Exception e){
}
}
}
}
}
out.write((PREFIX + boundary + PREFIX + end).getBytes(charset));
}
private void writeParams(OutputStream out) throws IOException{
Set<String> keySet = params.keySet();
StringBuffer sb = new StringBuffer();
int i = 0;
for (Iterator<String> it = keySet.iterator(); it.hasNext();) {
String name = it.next();
List<String> values = params.get(name);
for (String string : values) {
if(i>0){
sb.append("&");
}
sb.append(name).append("=").append(URLEncoder.encode(string , charset));
i++;
}
}
out.write(sb.toString().getBytes(charset));
}
private void writeParamsWithFile(OutputStream out) throws IOException{
Set<String> keySet = params.keySet();
StringBuffer sb = new StringBuffer();
for (Iterator<String> it = keySet.iterator(); it.hasNext();) {
String name = it.next();
List<String> values = params.get(name);
for (String string : values) {
sb.append(PREFIX).append(boundary).append(end);//分界符
sb.append("Content-Disposition: form-data; name=\"" + name + "\"" + end);
//sb.append("Content-Type: text/plain; charset=" + charset + end);
sb.append(end);
sb.append(string);
sb.append(end);
}
}
out.write(sb.toString().getBytes(charset));
}
private String boundary = "----TosignFormBoundary5TGBNHY67UJM";
public HttpRequest open() throws IOException{
URL _url = new URL(url);
conn = (HttpURLConnection)_url.openConnection();
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
((HttpsURLConnection)conn).setHostnameVerifier(trustAnyHostnameVerifier);
}
conn.setRequestMethod(this.requestMethod);
conn.setDoInput(true); //允许输入流
conn.setDoOutput(true); //允许输出流
conn.setUseCaches(false); //不允许使用缓存
conn.setConnectTimeout(10000);
conn.setReadTimeout(readTimeout);
boolean hasUploadFile = !fileMap.isEmpty();
if(hasUploadFile){
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
}else{
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=" + charset);
}
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
if (headers != null && !headers.isEmpty())
for (Entry<String, String> entry : headers.entrySet())
conn.setRequestProperty(entry.getKey(), entry.getValue());
return this;
}
public int getReadTimeout() {
return readTimeout;
}
public void setReadTimeout(int readTimeout) {
this.readTimeout = readTimeout;
}
public HttpRequest write(byte[] data) throws IOException{
OutputStream out = conn.getOutputStream();
out.write(data);
return this;
}
public HttpRequest request() throws IOException{
boolean hasUploadFile = !fileMap.isEmpty();
OutputStream out = conn.getOutputStream();
if(hasUploadFile){
writeParamsWithFile(out);
writeFiles(out);
}else{
writeParams(out);
}
out.flush();
out.close();
responseCode = conn.getResponseCode();
return this;
}
/**
* 发送请求
* @return 返回状态码 requestCode
* @throws IOException
*/
public HttpRequest send() throws IOException{
open();
request();
return this;
}
public int getResponseCode() {
return responseCode;
}
/**
* 将响应结果以string返回
* @return
* @throws IOException
*/
public String resultToString() throws IOException{
String _charset = charset;
String contentType = conn.getContentType();
if(StrKit.notBlank(contentType)){
Pattern pattern = Pattern.compile("charset=\\S*");
Matcher matcher = pattern.matcher(conn.getContentType());
if (matcher.find()) {
_charset = matcher.group().replace("charset=", "");
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
result(baos);
return new String(baos.toByteArray() , _charset);
}
public String getDownFileName() throws IOException{
String contentDisposition = new String(conn.getHeaderField("content-disposition").getBytes("ISO8859-1") ,this.charset);
// 匹配文件名
Pattern pattern = Pattern.compile(".*filename=(.*)");
Matcher matcher = pattern.matcher(contentDisposition);
System.out.println(matcher.groupCount()+"1");
System.out.println(matcher.matches()+"2");
System.out.println(matcher.group(1)+"3");
String filename = matcher.group(1);
String s=filename.substring(1,filename.length()-1);
// System.out.println(s);
return filename.substring(1,filename.length()-1).replace("_1_saved.",".");
// return filename;
}
/**
* 将响应结果写入输出流,主要用于接收服务返回的文件
* @param os
* @throws IOException
*/
public void result(OutputStream os ) throws IOException{
InputStream inputStream = null;
try {
if(getResponseCode() >=400 && getResponseCode()!=404){
inputStream = conn.getErrorStream();
}else{
inputStream = conn.getInputStream();
}
byte[] buffer = new byte[2048];
for (int n = -1; (n = inputStream.read(buffer)) != -1;) {
os.write(buffer, 0, n);
os.flush();
}
}
finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
conn.disconnect();
}
}
public HttpURLConnection getConn() {
return conn;
}
public String getRequestMethod() {
return requestMethod;
}
public void setRequestMethod(String requestMethod) {
this.requestMethod = requestMethod;
}
}
package com.hand.kinggrid;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Logger;
public class MD5 {
private static final Logger logger = Logger.getLogger("MD5");
/**
* @Description 字符串加密为MD5 中文加密一致通用,必须转码处理: plainText.getBytes("UTF-8")
* @param plainText
* 需要加密的字符串
* @return
*/
public static String toMD5(String plainText) {
StringBuffer rlt = new StringBuffer();
try {
rlt.append(md5String(plainText.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
logger.severe(" CipherHelper toMD5 exception.");
e.printStackTrace();
}
return rlt.toString();
}
/**
* MD5 参数签名生成算法
*
* @param HashMap<String,String>
* params 请求参数集,所有参数必须已转换为字符串类型
* @param String
* secret 签名密钥
* @return 签名
* @throws IOException
*/
public static String getSignature(HashMap<String, String> params, String secret) {
Map<String, String> sortedParams = new TreeMap<String, String>(params);
Set<Entry<String, String>> entrys = sortedParams.entrySet();
StringBuilder basestring = new StringBuilder();
for (Entry<String, String> param : entrys) {
basestring.append(param.getKey()).append("=").append(param.getValue());
}
return getSignature(basestring.toString(), secret);
}
/**
* MD5 参数签名生成算法
*
* @param String
* sigstr 签名字符串
* @param String
* secret 签名密钥
* @return 签名
* @throws IOException
*/
public static String getSignature(String sigstr, String secret) {
StringBuilder basestring = new StringBuilder(sigstr);
basestring.append("#");
basestring.append(toMD5(secret));
return toMD5(basestring.toString());
}
public static byte[] md5Raw(byte[] data) {
byte[] md5buf = null;
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5buf = md5.digest(data);
} catch (Exception e) {
md5buf = null;
logger.severe("md5Raw error.");
e.printStackTrace();
}
return md5buf;
}
public static String md5String(byte[] data) {
String md5Str = "";
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] buf = md5.digest(data);
for (int i = 0; i < buf.length; i++) {
md5Str += Byte2Hex.byte2Hex(buf[i]);
}
} catch (Exception e) {
md5Str = null;
logger.severe("md5String error.");
e.printStackTrace();
}
return md5Str;
}
}
\ No newline at end of file
package com.hand.kinggrid;
public class MainRequest {
/**
* 信签服务器地址
*/
//public static final String SERVER_URL = "http://171.34.78.70:8081:8081/tosignserver";
//public static final String SERVER_URL = "http://10.203.0.11:8989/tosignserver";
// public static final String SERVER_URL = "http://171.34.78.70:8081/tosignpub";
/**
* 信签服务器对接应用ID
*/
//public static final String APP_ID = "king";
// public static final String APP_ID = "ac4a3bd1bf6f44fa86477ac251933259";
//public static final String APP_ID = "f12a2c19e72348998b159df903b9b379";
/**
* 信签服务器对接应用密钥
*/
//public static final String APP_SECURITY = "e3f55030d473095d";
// public static final String APP_SECURITY = "7lQ7GC1HSviWAFG6";
//public static final String APP_SECURITY = "SK60MXsN7dzv1iIM";
//public static final String APP_ID = "f12a2c19e72348998b159df903b9b379";
/**
* 测试签署用户编码
*/
//public static final String SIGNER_CODE= "hlzlUser";
//public static final String SIGNER_CODE= "lidongzhang";
/**
* 模板创建合同使用的模板编码
*/
//public static final String CONTRACT_TPL_CODE= "testTemplate";
public static void main(String[] args) {
}
/**
* 生成信签请求操作对象
* @param url
* @return
*/
public static HttpRequest createHttpRequest(String url,String server_url,String app_id,String app_security){
String requestUrl = url;
if(!url.toUpperCase().startsWith("HTTP")){
if(server_url.endsWith("/")){
requestUrl = server_url.substring(0, server_url.length()-1)+url;
}else{
requestUrl = server_url+url;
}
}
HttpRequest httpRequest = new HttpRequest(requestUrl);
/**
* 如果是云服务,需要添加应用id到header
* 如果是私有云,可以不用设置
*/
httpRequest.addHeader("app_id", app_id);
String time = System.currentTimeMillis()+"";
httpRequest.addHeader("time", time);
httpRequest.addHeader("sign", MD5.toMD5(app_id+"."+time+'.'+app_security));
return httpRequest;
}
}
package com.hand.kinggrid;
public class StrKit {
public static boolean notBlank(String str) {
return !isBlank(str);
}
public static boolean isBlank(String str) {
if (str == null) {
return true;
}
int len = str.length();
if (len == 0) {
return true;
}
for (int i = 0; i < len; i++) {
switch (str.charAt(i)) {
case ' ':
case '\t':
case '\n':
case '\r':
// case '\b':
// case '\f':
break;
default:
return false;
}
}
return true;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: gzj
$Date: 2022年12月8日 17:13:08
$Revision: 1.0
$Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
<bm:operations>
<bm:operation name="query">
<bm:query-sql><![CDATA[
select t.file_name,
to_char(t.print_date,'yyyy-mm-dd hh24:mi:ss') print_date,
t.print_id
from cux_contract_print t
where (((SELECT e.role_code
FROM sys_role_vl e
WHERE e.role_id = ${/session/@role_id}) in ('0018', '0019') and
t.file_type = 'EXCEL')
or (SELECT e.role_code
FROM sys_role_vl e
WHERE e.role_id = ${/session/@role_id}) not in
('0018', '0019'))
and t.contract_id = ${@contract_id}
order by t.print_date
]]></bm:query-sql>
</bm:operation>
</bm:operations>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:ns2="leaf.database.local.oracle" xmlns:bm="http://www.leaf-framework.org/schema/bm">
<bm:operations>
<bm:operation name="update">
<bm:update-sql><![CDATA[
BEGIN
hl_contract_pkg.insert_into_attachment_bmp(
p_file_path =>${@p_file_path},
p_file_name =>${@p_file_name},
p_file_size =>${@p_file_size},
p_user_id =>${@p_user_id},
p_contract_id =>${@p_contract_id},
p_file_type =>${@p_file_type}
);
END;
]]></bm:update-sql>
</bm:operation>
</bm:operations>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: gaoyang
$Date: 2014-11-26 下午04:24:11
$Revision: 1.0
$Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
<bm:operations>
<bm:operation name="query">
<bm:query-sql><![CDATA[
SELECT
faa.file_name,
faa.file_path,
faa.attachment_id
FROM
fnd_atm_attachment_multi fam,
fnd_atm_attachment faa
WHERE fam.table_name = 'CON_CONTRACT_CONTENT' AND
fam.attachment_id = faa.attachment_id AND
fam.table_pk_value = ${@content_id}
]]></bm:query-sql>
</bm:operation>
</bm:operations>
<bm:fields>
<bm:field name="file_name" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_NAME"/>
<!-- <bm:field name="file_name2" databaseType="VARCHAR2" datatype="java.lang.String"/>-->
<bm:field name="file_path" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FILE_PATH"/>
<bm:field name="attachment_id" databaseType="NUMBER" datatype="java.lang.Long" physicalName="ATTACHMENT_ID"/>
<!-- <bm:field name="templet_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="TEMPLET_CODE"/>-->
</bm:fields>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: Yenick
$Date: 2018-06-06 下午04:24:11
$Revision: 1.0
$Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
<bm:operations>
<bm:operation name="update">
<bm:update-sql><![CDATA[
begin
HL_CONTRACT_PKG.save_pdf_atm(p_content_id =>${@content_id});
end;
]]></bm:update-sql>
</bm:operation>
</bm:operations>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: wxm
$Date: 2020-6-08 下午04:24:11
$Revision: 1.0
$Purpose:
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
<bm:operations>
<bm:operation name="query">
<bm:query-sql><![CDATA[
select s.signature_code,
s.code,
s.seal_code,
s.seal_width,
s.fontname,
s.fontsize,
s.fontcolor,
s.pageno,
s.word_code,
s.qfzstart,
s.qfzdistance
from CON_CONTRACT_SIGNATURE_CM s
]]></bm:query-sql>
</bm:operation>
</bm:operations>
<bm:fields>
<bm:field name="signature_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SIGNATURE_CODE"/>
<bm:field name="code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="CODE"/>
<bm:field name="seal_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="SEAL_CODE"/>
<bm:field name="seal_width" databaseType="NUMBER" datatype="java.lang.Long" physicalName="SEAL_WIDTH"/>
<bm:field name="fontname" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FONTNAME"/>
<bm:field name="fontsize" databaseType="NUMBER" datatype="java.lang.Long" physicalName="FONTSIZE"/>
<bm:field name="fontcolor" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="FONTCOLOR"/>
<bm:field name="pageno" databaseType="NUMBER" datatype="java.lang.Long" physicalName="PAGENO"/>
<bm:field name="word_code" databaseType="VARCHAR2" datatype="java.lang.String" physicalName="WORD_CODE"/>
<bm:field name="qfzstart" databaseType="NUMBER" datatype="java.lang.Long" physicalName="QFZSTART"/>
<bm:field name="qfzdistance" databaseType="NUMBER" datatype="java.lang.Long" physicalName="QFZDISTANCE"/>
</bm:fields>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?>
<!--<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">-->
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<s:server-script ><![CDATA[
importPackage(Packages.java.util);
importPackage(Packages.java.lang);
importPackage(Packages.com.hand.hl);
importPackage(Packages.java.io);
importPackage(java.io);
try{
var sys_url_bm=$bm('cont.CON4000.get_sys_url');
var parameter_code='HLS_SYSTEM_URL';
var SysurlQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var sys_url = SysurlQuery.getChildren()[0].parameter_value;
var down_url =sys_url+'con/contract/conExportExcel?contractId=' +$ctx.parameter.contract_id;
println(down_url);
var now = new Date();
y = now.getFullYear();
m = now.getMonth() + 1;
m = m < 10 ? "0" + m : m;
d = now.getDate();
d = d < 10 ? "0" + d : d;
h = now.getHours();
h = h < 10 ? "0" + h : h;
mi = now.getMinutes();
mi = mi < 10 ? "0" + mi : mi;
var f_fileDir = $ctx.parameter.file_path;
var filePath = (f_fileDir + y + "//" + m + "//").toString();
var tranfer_dir= new File(String(filePath));
if(!tranfer_dir.exists()){//如果文件夹不存在,创建文件夹
tranfer_dir.mkdirs();//创建文件夹
}
var contract_number = $ctx.parameter.contract_number;
var file_name = $ctx.parameter.file_name + y + m + d + h + mi + ".xlsx";
var f_fileName = file_name.toString();
var result_flag=DoloadFileByUrl.downloadFile(down_url, filePath, f_fileName);
file_size=get_file_length(filePath+f_fileName);
if(result_flag=true){
var business_daily_email=$bm('cont.CON301N.insert_into_attachment_bmp').update({
p_file_path :(filePath+f_fileName).toString(),
p_file_name :f_fileName,
p_file_size :file_size,
p_user_id :$ctx.session.user_id,
p_contract_id :$ctx.parameter.contract_id,
p_file_type :'EXCEL'
});
}
}catch(e){
raise_app_error(e.message);
}
function get_file_length(path){
var file=new File(String(path));
if(file.exists() && file.isFile()){
length=file.length();
return length;
}else{
return 0 ;
}
}
]]></s:server-script>
</a:init-procedure>
<a:service-output output="/parameter"/>
</a:service>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">-->
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<s:server-script ><![CDATA[
importPackage(Packages.java.util);
importPackage(Packages.java.lang);
importPackage(Packages.com.hand.hl);
importPackage(Packages.leaf.plugin.word2pdf);
importPackage(Packages.java.io);
importPackage(java.io);
try{
var sys_url_bm=$bm('cont.CON4000.get_sys_url');
var parameter_code='HLS_SYSTEM_URL';
var SysurlQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var sys_url = SysurlQuery.getChildren()[0].parameter_value;
var down_url =sys_url+'con/contract/conExportExcel?contractId=' +$ctx.parameter.contract_id;
var now = new Date();
y = now.getFullYear();
m = now.getMonth() + 1;
m = m < 10 ? "0" + m : m;
d = now.getDate();
d = d < 10 ? "0" + d : d;
h = now.getHours();
h = h < 10 ? "0" + h : h;
mi = now.getMinutes();
mi = mi < 10 ? "0" + mi : mi;
var f_fileDir = $ctx.parameter.file_path;
var filePath = (f_fileDir + y + "\/" + m + "\/").toString();
//var filePath = (f_fileDir + y + "//" + m + "//").toString();
var tranfer_dir= new File(String(filePath));
if(!tranfer_dir.exists()){//如果文件夹不存在,创建文件夹
tranfer_dir.mkdirs();//创建文件夹
}
var contract_number = $ctx.parameter.contract_number;
var file_name = $ctx.parameter.file_name + y + m + d + h + mi + ".xlsx";
var f_fileName = file_name.toString();
var result_flag=DoloadFileByUrl.downloadFile(down_url, filePath, f_fileName);
//excel 转pdf
var to_file_path = filePath + file_name;
var pdf_file_path= filePath + $ctx.parameter.file_name + y + m + d + h + mi + ".pdf";
println('to_file_path = ' + to_file_path);
println('pdf_file_path = ' + pdf_file_path);
var outputfilepath = wordToPdf(to_file_path,pdf_file_path);
file_size=get_file_length(outputfilepath);
pdf_path =(pdf_file_path).toString()
println('p_file_name = '+ $ctx.parameter.file_name + y + m + d + h + mi + ".pdf");
if(result_flag=true){
var business_daily_email=$bm('cont.CON301N.insert_into_attachment_bmp').update({
p_file_path :(pdf_file_path).toString(),
p_file_name :($ctx.parameter.file_name + y + m + d + h + mi + ".pdf").toString(),
p_file_size :file_size,
p_user_id :$ctx.session.user_id,
p_contract_id :$ctx.parameter.contract_id,
p_file_type :'PDF'
});
}
}catch(e){
raise_app_error(e.message);
}
function get_file_length(path){
var file=new File(String(path));
if(file.exists() && file.isFile()){
length=file.length();
return length;
}else{
return 0 ;
}
}
function wordToPdf(word_file_path,pdf_file_path) {
// excel转pdf
//var pdf_file_path_new = pdf_file_path + '.pdf';
var pdf_file_path_new = pdf_file_path;
var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
wordToPdf.exceltopdf(word_file_path, pdf_file_path_new);
//删除word文件
//deleteFile(word_file_path);
return pdf_file_path_new;
}
]]></s:server-script>
</a:init-procedure>
<a:service-output output="/parameter"/>
</a:service>
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: ZLF
$Date: 2014-11-20 下午8:50:38
$Revision: 1.0
$Purpose:
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true"
trace="true">
<a:init-procedure>
<s:server-script import="con_print_path.js"><![CDATA[
set_parameter_file_path();
]]></s:server-script>
<a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
</a:init-procedure>
<a:view>
<a:link id="con_contract_content_asset_detail_link_id"
url="${/request/@context_path}/modules/cont/CON505/con_contract_content_asset_detail.lview"/>
<a:link id="con_doc_batch_create_link_id"
url="${/request/@context_path}/modules/cont/CON500/con_doc_batch_create.lsc"/>
<a:link id="con301n_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
<a:link id="con301n_print_excel_link"
url="${/request/@context_path}/modules/cont/CON301N/con_contract_print_atm.lsc"/>
<a:link id="con301n_print_pdf_link"
url="${/request/@context_path}/modules/cont/CON301N/con_contract_print_pdf.lsc"/>
<script type="text/javascript"><![CDATA[
function lock_current_window() {
Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
}
function unlock_current_window() {
Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
}
function con_print_excel_create() {
Leaf.Masker.mask(Ext.getBody(), '请稍等......');
// var file_name = '对账单(' +'${/parameter/@tenant_name}'+'+'+'${/parameter/@contract_number}'+').doc';
// var file_dir = '$ctx.parameter.file_path';
// var contract_id = '${/parameter/@contract_id}';
// var url;
// url ='${/request/@context_path}/con/contract/conExportExcel?contractId=' + contract_id;
// window.open(href = url);
var contract_id = '${/parameter/@contract_id}';
var contract_number = '${/parameter/@contract_number}';
var tenant_name = '${/parameter/@tenant_name}';
var file_path = '${/parameter/@file_path}';
//var file_name = '对账单('+ tenant_name + '_'+contract_number+').xlsx';
var file_name = '对账单('+ tenant_name + '_'+contract_number+')';
Leaf.request({
url: $('con301n_print_excel_link').getUrl(),
para: {
contract_id : contract_id,
contract_number : contract_number,
file_path : file_path,
file_name : file_name
},
success: function(res) {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
},
failure: function() {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
},
error: function() {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
}
});
}
function con_print_signatures_create() {
Leaf.Masker.mask(Ext.getBody(), '请稍等......');
var contract_id = '${/parameter/@contract_id}';
var contract_number = '${/parameter/@contract_number}';
var tenant_name = '${/parameter/@tenant_name}';
var file_path = '${/parameter/@file_path}';
//var file_name = '对账单('+ tenant_name + '_'+contract_number+').xlsx';
var file_name = '对账单('+ tenant_name + '_'+contract_number+')';
Leaf.request({
url: $('con301n_print_pdf_link').getUrl(),
para: {
contract_id : contract_id,
contract_number : contract_number,
file_path : file_path,
file_name : file_name
},
success: function(res) {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
},
failure: function() {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
},
error: function() {
Leaf.Masker.unmask(Ext.getBody());
$('con_contract_print_detail_line_ds').query();
}
});
}
function update_attachment_renderer(value, record, name) {
var content_id = record.get('content_id');
return '<a href="javascript:open_uploadfile_win(' + content_id + ')">附件</a>';
}
function attachment_download(val,rec,name) {
return '<a href=javascript:detail_download_window('+rec.get('print_id')+')>下载</a>';}
function detail_download_window(record_id) {
var url = $('con301n_downloadFile_id').getUrl() + '?table_name=CUX_CONTRACT_PRINT&header_id=' + record_id;
var win = new Leaf.Window({
url: url,
title: '${l:HLS.SUPPORTING_DOCUMENT}',
id: 'con301n_records_uploadFile_id',
width: 850,
height: 400
});
win.on('close', function() {
});
}
]]></script>
<a:dataSets>
<a:dataSet id="con_contract_update_print_detail_header_ds" autoCreate="true">
<a:fields>
<a:field name="contract_number" defaultValue="${/parameter/@contract_number}" readOnly="true"/>
<a:field name="contract_name" defaultValue="${/parameter/@contract_name}" readOnly="true"/>
</a:fields>
</a:dataSet>
<a:dataSet id="con_contract_print_detail_line_ds" autoQuery="true" fetchAll="true" pageSize="100"
queryUrl="${/request/@context_path}/autocrud/cont.CON301N.con_statement_of_account_print/query?contract_id=${/parameter/@contract_id}">
<a:fields>
<a:field name="contract_id"/>
<a:field name="content_number" readOnly="true"/>
</a:fields>
</a:dataSet>
</a:dataSets>
<a:screenBody>
<div id="screenTopToolbardiv">
<a:screenTopToolbar style="width:700px">
<a:gridButton id="con_print_id" click="con_print_excel_create" text="生成对账单excel"/>
<a:gridButton id="con_print_signatures_id" click="con_print_signatures_create" text="生成对账单PDF"/>
</a:screenTopToolbar>
<a:form column="2" width="700">
<a:textField name="contract_number" bindTarget="con_contract_update_print_detail_header_ds"
prompt="HLS.CONTRACT_NUMBER"/>
<a:textField name="contract_name" bindTarget="con_contract_update_print_detail_header_ds"
prompt="HLS.CONTRACT_NAME" width="330"/>
</a:form>
</div>
<a:grid id="con_contract_update_print_detail_grid_id" bindTarget="con_contract_print_detail_line_ds"
height="350" navBar="true" width="700">
<a:toolBar>
<a:button prompt="PROMPT.EXPORT_EXCEL" type="excel"/>
</a:toolBar>
<a:columns>
<a:column name="file_name" prompt="文本名称" width="260"/>
<a:column name="print_date" prompt="生成日期" width="180"/>
<a:column name="download" align="center" prompt="下载" renderer="attachment_download" width="50"/>
</a:columns>
</a:grid>
</a:screenBody>
<script type="text/javascript"><![CDATA[
Leaf.onReady(function() {
if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {
document.getElementById("con_print_signatures_id").style.display = "";
} else {
document.getElementById("con_print_signatures_id").style.display = "none";
}
});
]]></script>
</a:view>
</a:screen>
......@@ -35,9 +35,9 @@
url="${/request/@context_path}/modules/cont/CON3200/con_re_incept_modify.lview"/>
<a:link id="${/parameter/@layout_code}_contract_seal_link_id" url="${/request/@context_path}/modules/cont/CON301N/con_contract_finish_seal_info.lview"/>
<a:link id="con_contract_finish_print_link_id" url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req_history_pdf_print.lsc"/>
<script src="${/request/@context_path}/javascripts/hap/dynamicStopAutoQuery.js" type="text/javascript"/>
<a:link id="rl_notice_print_link"
url="${/request/@context_path}/modules/cont/CON301N/rl_notice_print.lsc"/>
<!-- <script src="${/request/@context_path}/javascripts/hap/dynamicStopAutoQuery.js" type="text/javascript"/>-->
<a:link id="${/parameter/@layout_code}_contract_print_signatures_link_id"
url="${/request/@context_path}/modules/cont/CON301N/con_contract_print_signatures.lview"/>
<script type="text/javascript"><![CDATA[
// stopDymanicAutoQuery('${/parameter/@layout_code}', 'G_CONTRACT_RESULT', 'con_contract');
......@@ -90,14 +90,8 @@
}
}
var role_code = '${/model/role_info/record/@role_code}';
if(role_code!="0008"&&role_code!="0017"&&role_code!="HAND") {
document.getElementById("CONTRACT_QUERY_ENTRANCE_user_button9").style.display = "none";
} else {
document.getElementById("CONTRACT_QUERY_ENTRANCE_user_button9").style.display = "";
}
});
});
function open_contract_win(ds_id, record_id) {
var record = $(ds_id).findById(record_id);
var param = record.data;
......@@ -277,6 +271,7 @@
url ='${/request/@context_path}/con/contract/conExportExcel?contractId=' + record.get('contract_id');
window.open(href = url);
//window.location.href='${/request/@context_path}/con/contract/conExportExcel?contractId='+record.get('contract_id');
};
//返还金通知打印
......@@ -308,6 +303,41 @@
}
//对账单打印加盖公章
window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
debugger;
// var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
// var record = $(ds_id).getSelected()[0];
// var url;
// url ='${/request/@context_path}/con/contract/conExportExcel?contractId=' + record.get('contract_id');
// window.open(href = url);
var ds = $('CONTRACT_QUERY_ENTRANCE_G_CONTRACT_RESULT_con_contract_ds');
var records = ds.getSelected();
if (records.length != 1) {
Leaf.showMessage('提示', '请选择一条数据!');
return;
}
var contract_id = records[0].get('contract_id');
var contract_number = records[0].get('contract_number');
var contract_name = records[0].get('contract_name');
var tenant_name = records[0].get('bp_id_tenant_n');
var win = new Leaf.Window({
id: 'contract_print_signatures',
url: $('${/parameter/@layout_code}_contract_print_signatures_link_id').getUrl(),
params: {
contract_id: contract_id,
contract_number: contract_number,
contract_name: contract_name,
tenant_name: tenant_name,
winid : 'contract_print_signatures_winid'
},
title: '对账单打印',
height: 500,
width: 800
});
};
]]></script>
<a:screen-include
screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON501"/>
......
......@@ -38,7 +38,8 @@
url="${/request/@context_path}/modules/cont/CON620/create_content_lease_return.lsc"/>
<a:link id="${/parameter/@layout_code}_con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
<a:link id="con_collection_message_create_link_id" model="cont.CON620.con_collection_message_create" modelaction="update"/>
<a:link id="con_lease_org_print_signatures_link"
url="${/request/@context_path}/modules/cont/CON620/create_content_for_collection_signatures.lsc"/>
<script type="text/javascript"><![CDATA[
Ext.ux.Lightbox.register('a[ref=img]', true);
......@@ -186,7 +187,6 @@
//add by lihh 20210318 发送函件类型为只读
//加载时调用(grid,table,gridBox)
window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
debugger;
var col_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
var records = $(col_ds).getAll();
if(ds.id == col_ds && col_ds){
......@@ -209,13 +209,25 @@
if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {
document.getElementById("CON_DUE_DETAIL_user_button4").style.display = "";
document.getElementById("CON_DUE_DETAIL_user_button3").style.display = "";
document.getElementById("CON_DUE_DETAIL_user_button5").style.display = "";
} else {
document.getElementById("CON_DUE_DETAIL_user_button4").style.display = "none";
document.getElementById("CON_DUE_DETAIL_user_button3").style.display = "none";
document.getElementById("CON_DUE_DETAIL_user_button5").style.display = "none";
}
}
});
//新增催款函pdf打印(盖章)
window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
var contract_id = '${/parameter/@document_id}';
var templet_code = 'CON_LEASE_ORG';
var url=$('con_lease_org_print_signatures_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
window.open(url, '_self');
create_message(contract_id,templet_code);
};
]]></script>
<a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
</a:view>
......
......@@ -7,10 +7,10 @@
importPackage(Packages.org.apache.commons.io);
function RandomString(length) {   
var str = '';   
for (;str.length < length;str += Math.random().toString(36).substr(2));   
return str.substr(0, length); 
function RandomString(length) {
var str = '';
for (;str.length < length;str += Math.random().toString(36).substr(2));
return str.substr(0, length);
}
//删除文件
......@@ -122,7 +122,6 @@
}
}
$ctx.parameter.return_status = 'S';
$ctx.parameter.return_message = '执行成功';
} catch (e) {
......
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<s:server-script import="contract_print_path.js"><![CDATA[
importPackage(java.io);
importPackage(Packages.com.hand.hl);
importPackage(Packages.com.hand.kinggrid);
importPackage(Packages.hls.plugin.docx4j);
importPackage(Packages.leaf.plugin.word2pdf);
importPackage(Packages.org.apache.commons.io);
importPackage(Packages.hls.plugin.jacob.engine);
importPackage(Packages.uncertain.proc);
importPackage(Packages.com.itextpdf.text);
importPackage(Packages.com.itextpdf.text.pdf);
function word_to_pdf_sign(content_id) {
importPackage(Packages.com.hl.signatures);
importPackage(Packages.java.io);
importPackage(Packages.java.util);
var attachment_batch_dl = $bm('cont.CON620.con_collection_file_download');
var attachment_update = $bm('cont.CON620.con_contract_save_pdf_atm');
var org_flag = '';
var qf_flag = '';
var param = new ArrayList();
var paramdetail;
var result = attachment_batch_dl.queryAsMap({
content_id: content_id
});
var arr = result.getChildren();
for (var i = 0;i < arr.length;i++) {
var f = arr[i];
var file_name = f.file_name;
var file_path = f.file_path;
if (file_name.substring(file_name.length - 4) == '.doc') {
file_name = file_name.substring(0, file_name.length - 4);
} else if (file_name.substring(file_name.length - 5) == '.docx') {
file_name = file_name.substring(0, file_name.length - 5);
}
var outputfilepath = file_path + '.pdf'; // 由于wordToPdf转换后pdf文件已经带有.pdf
var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
//wordToPdf.WordToPdf(file_path, outputfilepath);
wordToPdf.word2pdf(file_path, outputfilepath);
// 获取pdf页数,如果是只有1页,不需要骑缝章
var pageNum = getPdfPageNum(outputfilepath);
println(pageNum);
println(1);
var con_signature_info = $bm('cont.CON620.get_con_signature_info').queryAsMap();
var con_signature_data = con_signature_info.getChildren();
println(2);
var con_signature_record;
for (var i = 0;i < con_signature_data.length;i++) {
con_signature_record = con_signature_data[i];
if (pageNum > 1) {
if (con_signature_record.signature_code == 'gz_flag' || con_signature_record.signature_code == 'qf_gz_flag' ){
paramdetail = '[{ "code":"' + con_signature_record.code +
'", "seal_code":"' + con_signature_record.seal_code +
'", "seal_width":' + con_signature_record.seal_width +
', "fontname":"' + con_signature_record.fontname +
'", "fontsize":"' + con_signature_record.fontsize +
'", "fontcolor":"' + con_signature_record.fontcolor +
'", "pageno":"' + con_signature_record.pageno +
'", "text":"' + con_signature_record.word_code +
'", "qfzstart":"' + con_signature_record.qfzstart +
'", "qfzdistance":"' + con_signature_record.qfzdistance + '"}]';
}
param.add(paramdetail);
} else {
if (con_signature_record.signature_code == 'gz_flag'){
paramdetail = '[{ "code":"' + con_signature_record.code +
'", "seal_code":"' + con_signature_record.seal_code +
'", "seal_width":' + con_signature_record.seal_width +
', "fontname":"' + con_signature_record.fontname +
'", "fontsize":"' + con_signature_record.fontsize +
'", "fontcolor":"' + con_signature_record.fontcolor +
'", "pageno":"' + con_signature_record.pageno +
'", "text":"' + con_signature_record.word_code + '"}]';
}
param.add(paramdetail);
}
}
println(param);
var sys_url_bm=$bm('cont.CON4000.get_sys_url');
var parameter_code='JG_SERVER_URL';
var SysurlQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var server_url = SysurlQuery.getChildren()[0].parameter_value;
var parameter_code='JG_APP_ID';
var SysIdQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var app_id = SysIdQuery.getChildren()[0].parameter_value;
var parameter_code='JG_APP_ID';
var SysSecurityQuery = sys_url_bm.queryAsMap({
parameter_code: parameter_code
});
var app_security = SysSecurityQuery.getChildren()[0].parameter_value;
var status = new ContractSignaturesNew.hl_contract_signatures(outputfilepath, 1,param.toArray(),server_url,app_id,app_security);
attachment_update.update({
content_id: content_id,
table_name: 'HLS_DOC_FILE_CONTENT'
});
}
}
function getPdfPageNum(files) {
var document = null;
var pageNum = null;
var reader = new PdfReader(files);
pageNum = reader.getNumberOfPages();
return pageNum;
}
function RandomString(length) {
var str = '';
for (;str.length < length;str += Math.random().toString(36).substr(2));
return str.substr(0, length);
}
//删除文件
function deleteFile(filePath) {
var file = new File(filePath);
if (file.exists()) {
file.delete();
}
}
//生成pdf
function wordToPdf(word_file_path,pdf_file_path) {
// word转pdf
var pdf_file_path_new = pdf_file_path + '.pdf';
var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
wordToPdf.word2pdf(word_file_path, pdf_file_path_new);
//删除word文件
// deleteFile(word_file_path);
return pdf_file_path_new;
}
function copyFile(fOld, fNew) {
var fis = new java.io.FileInputStream(fOld);
var fos = new java.io.FileOutputStream(fNew);
var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 4);
var len = -1;
while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len);
}
fis.close();
fos.close();
}
//按日期创建目录
function getDatePath() {
set_parameter_file_path();
var file_path = $ctx.parameter.file_path; //file_path = c:/hls_test_files/content_files/
var now = new Date()
y = now.getFullYear()
m = now.getMonth() + 1
m = m < 10 ? "0" + m : m
var datePath = file_path + y + "/" + m + "/";
return datePath; //datePath = d:/hls_test_files/fileupload/2018/04/
}
function write_os_to_file(file, os) {
var fis = new FileInputStream(file);
var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 64);
var len = -1;
while ((len = fis.read(b)) != -1) {
os.write(b, 0, len);
}
fis.close();
}
function download_file(file_path, file_name) {
$ctx["__request_type__"] = 'file';
var resp = $ctx['_instance.javax.servlet.http.HttpServletResponse'];
resp.setHeader("Pragma", "No-cache");
resp.setHeader("Cache-Control", "no-cache, must-revalidate");
resp.setHeader("Content-disposition", "attachment; filename=" + encodeURI(file_name, 'utf-8'));
resp.setDateHeader("Expires", 0);
resp.setContentType("application/x-msdownload");
try {
var os = resp.getOutputStream();
write_os_to_file(file_path, os);
os.flush();
} catch (e) {
$logger("server-script").severe(e.message);
}
}
function collection_create_content() {
try {
//第一步生成合同文本
$bm('cont.CON620.create_content_for_collection').update({
contract_id: $ctx.parameter.contract_id,
templet_code: $ctx.parameter.templet_code
});
//获取日期目录
var datePath = getDatePath();
$ctx.parameter.batch_flag='Y';
FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录
var from_file_data_map = $bm('cont.CON500.con_doc_file_templet_get_atm_new').queryAsMap({
contract_id: $ctx.parameter.contract_id,
batch_flag:$ctx.parameter.batch_flag,
templet_code: $ctx.parameter.templet_code
});
var from_file_data = from_file_data_map.getChildren();
for (var i = 0;i < from_file_data.length;i++) {
var to_file_path = $ctx.parameter.file_path;
var record_data = from_file_data[i];
if (record_data.file_exists_flag != 'Y') {
var to_file_name = record_data.to_file_name + '.' + record_data.file_type_code || 'doc';
var from_file_path = record_data.file_path;
var guid_file_name_path = $bm('cont.CON500.con_contract_get_guid_file_name').queryAsMap();
var guid_file_name_tables = guid_file_name_path.getChildren();
to_file_path = datePath + guid_file_name_tables[0].guid_file_name + 'con' + record_data.content_id;
copyFile(from_file_path, to_file_path);
try {
var brwt = new BookmarksReplaceWithText($instance('leaf.database.service.IDatabaseServiceFactory'), $instance('uncertain.ocm.IObjectRegistry'), $ctx.getData());
brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id);
} catch (e) {
raise_app_error(e);
}
var to_file_name_n = record_data.to_file_name + '.' + 'pdf';
file_size=get_file_length(to_file_path+to_file_name_n);
$bm('cont.CON500.con_file_content_copy_update').update({
table_name: 'CON_CONTRACT_CONTENT',
content_id: record_data.content_id,
file_name: to_file_name.toString(),
file_path: to_file_path.toString()
});
//word转pdf并加盖公章
word_to_pdf_sign(record_data.content_id);
to_file_name = record_data.to_file_name + '.pdf';
to_file_path = to_file_path + '.pdf';
download_file(to_file_path.toString(),to_file_name.toString());
}
}
$ctx.parameter.return_status = 'S';
$ctx.parameter.return_message = '执行成功';
} catch (e) {
$ctx.success = "true";
$ctx.parameter.return_status = 'E';
$ctx.parameter.return_message = $ctx.get('/error/@message') || String(e);
raise_app_error(e);
}
var result = {
result: $ctx.parameter.return_status,
message: $ctx.parameter.return_message
};
$ctx.parameter.json = JSON.stringify(result);
}
if ($ctx.parameter.return_status != 'E' && $ctx.parameter.return_status != 'TIMEOUT') {
collection_create_content();
}
function get_file_length(path){
var file=new File(String(path));
if(file.exists() && file.isFile()){
//println(f.length());
length=file.length();
return length;}
else{
return 0 ;}
}
]]></s:server-script>
</a:init-procedure>
<a:service-output/>
</a:service>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment