随手拍

来源:互联网 发布:上海联通网络 编辑:程序博客网 时间:2024/04/28 16:04
import java.util.*;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.justep.system.context.ContextHelper;
import com.justep.system.data.*;
import java.text.SimpleDateFormat;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import javax.imageio.ImageIO;


import com.justep.design.model.ksql.Utils;
import com.justep.doc.DocUtils;
import com.justep.doc.Docs;
import com.justep.doc.Doc;


import com.justep.system.data.*;


public class ConstructionDis {




public static String getProjectID2(){
//
String projectInfo = "";
String currName = ContextHelper.getPerson().getName();
String strKsql = "select m.fProjectID as fProjectID,m.fProjectCode as fProjectCode,m.fProjectName as fProjectName,"
+"case when t.fProgress is null then 0 else fProgress end as fProgress from TE_MyProjectInfo m optional join TE_ProjectInfo t on t = m.fProjectID where m.fIsDefault='是' and m.fPersonName='"+currName+"'";
System.out.println(strKsql);
Table t = KSQL.select(strKsql, null, "/TeamTreasure/projectManage/data", null);
Iterator<Row> rows = t.iterator();
if (rows.hasNext()) {
Row row = rows.next();
String fProjectID = row.getString("fProjectID");
String fProjectCode = row.getString("fProjectCode");
String fProjectName = row.getString("fProjectName");


String fProgress = row.getDecimal("fProgress").toString();
projectInfo = fProjectID +","+ fProjectCode +","+fProjectName+","+fProgress;
}
return projectInfo;


}


public static void PictureWatermark(String ID,String docId,String docPath){
// 查询sql
String  doc2 = "";
String  docValue = "";
String  URL = "";
String strKsql = "select m.fPictureName as fPictureName from TE_PhotoDirectoryStructureinfor m where m = '"+ID+"'";
System.out.println(strKsql);
Table t = KSQL.select(strKsql, null, "/TeamTreasure/ConstructionDis/data", null);
//
Iterator<Row> rows = t.iterator();
while (rows.hasNext()){
Row row = rows.next();
String v = row.getString("fPictureName");
JSONArray ja=JSONArray.parseArray(v); 
for(int i=0;i<ja.size();i++){
JSONObject jsonObject=ja.getJSONObject(i); 
String docPaths =jsonObject.getString("docPath");
String fileID = jsonObject.getString("fileID");
String docID = jsonObject.getString("docID");
Docs docs = new Docs();
Doc doc = docs.query(null,docPaths, null, null, null).get(docID);
File outPutFile =new File("c:/"+doc.getsDocName());


try {
doc.download(new FileOutputStream(outPutFile));
} catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("已经下载完成,请查看");
//图片加水印
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:MM:ss");//设置日期格式
String date = df.format(new Date());
System.out.println(date);// new Date()为获取当前系统时间
ConstructionDis.waterMarkByText(date+"班组宝", "c:/"+doc.getsDocName(), "c:/"+doc.getsDocName(), 0, 200, 20, (float) 1);
//上传
String docID1 =docId;
String  path1 = docPath; 
Docs docs1 = new Docs().query(docID1,path1,null,null,null);
Doc doc1 = docs1.get(docID1);
//lock
DocUtils.lock(docID1);
try {
doc1.upload(new File( "c:/"+doc.getsDocName()));
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("已经上传");
//拼接字符串
String fileID3 = doc1.getsFileID();
String docID3 = doc1.getsID();
String docName3 = doc1.getsDocName();
String docPath3 = doc1.getsDocPath();
String size3 = doc1.getsSize().toString();
docValue = "{\"docID\":\"" + docID3 + "\",\"docName\":\"" + docName3 + "\",\"size\":\"" + size3 + "\",\"fileID\":\"" + fileID3+ "\",\"docPath\":\"" + docPath3 + "\",\"time\":\"" + new java.sql.Timestamp((new java.util.Date()).getTime()) + "\"}";
URL+=URL+docValue+",";
//
String upKsql ="update te_photodirectorystructureinfor s  set s.fPictureName ="+URL+"-"+','+" where s ="+ID+"";
System.out.println(upKsql);
KSQL.executeUpdate(upKsql, null,"/TeamTreasure/ConstructionDis/data", null);
}
}
}






public static void waterMarkByText(String logoText, String srcImgPath,
String targerPath, Integer degree, Integer width, Integer height,
Float clarity) {
// 主图片的路径
InputStream is = null;
OutputStream os = null;
try {
Image srcImg = ImageIO.read(new File(srcImgPath));


BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),
srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);


// 得到画笔对象
// Graphics g= buffImg.getGraphics();
Graphics2D g = buffImg.createGraphics();


// 设置对线段的锯齿状边缘处理
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);


g.drawImage(
srcImg.getScaledInstance(srcImg.getWidth(null),
srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0,
null);


if (null != degree) {
// 设置水印旋转
g.rotate(Math.toRadians(degree),
(double) buffImg.getWidth() / 2,
(double) buffImg.getHeight() / 2);
}


// 设置颜色
g.setColor(Color.red);


// 设置 Font
g.setFont(new Font("宋体", Font.BOLD, 18));


float alpha = clarity;
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
alpha));


// 第一参数->设置的内容,后面两个参数->文字在图片上的坐标位置(x,y) .
g.drawString(logoText, width, height);


g.dispose();


os = new FileOutputStream(targerPath);


// 生成图片
ImageIO.write(buffImg, "JPG", os);


System.out.println("添加水印文字完成!");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != is)
is.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
if (null != os)
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}


public static String getProjectIDNameThing(){
//获取默认项目
String projectInfo = "";
String currName = ContextHelper.getPerson().getName();
String strKsql = "select m.fProjectID as fProjectID,m.fProjectCode as fProjectCode,m.fProjectName as fProjectName,"+"case when t.fProgress is null then 0 else fProgress end as fProgress from TE_MyProjectInfo m optional join TE_ProjectInfo t on t = m.fProjectID where m.fIsDefault='是' and m.fPersonName='"+currName+"'";
System.out.println(strKsql);
Table t = KSQL.select(strKsql, null, "/TeamTreasure/projectManage/data", null);
Iterator<Row> rows = t.iterator();
if (rows.hasNext()) {
Row row = rows.next();
String fProjectID = row.getString("fProjectID");
String fProjectCode = row.getString("fProjectCode");
String fProjectName = row.getString("fProjectName");


String fProgress = row.getDecimal("fProgress").toString();
projectInfo = fProjectID +","+ fProjectCode +","+fProjectName+","+fProgress;
}
return projectInfo;
}
}
原创粉丝点击