标签:
package com.aig.ecompass.ecard.handler;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.font.TextAttribute;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import com.aiait.framework.dataaccess.database.DataSet;
import com.aiait.framework.util.Utilities;
import com.aig.batchjob.BatchJobThreadTask;
import com.aig.batchjob.model.BatchJobTask;
import com.aig.batchjob.model.ItemTask;
import com.aig.dynamic.util.TypeChecker;
import com.aig.ecompass.dao.CommonDAO;
import com.aig.ecompass.ecard.eCardXMLConfigManager;
import com.aig.ecompass.ecard.model.eCardForm;
import com.aig.ecompass.ecard.model.eCardModel;
import com.aig.ecompass.utility.Utility;
import com.aig.ecompassios.dao.AppleECardDAO;
import com.aig.ecompassios.ecard.model.AppleECardImageInformationWebServiceResult;
import com.aig.ecompassios.ecard.model.AppleECardImageModel;
import com.aig.ecompassios.ecard.model.AppleECardImagesInforModel;
public class ECardHandler {
private eCardModel eCardModel;
public static int count=0;
private String suffix = new CommonDAO().getParmValByTHSDPARM("eCARD.IMAGE.SUFFIX","png");
public AppleECardImageInformationWebServiceResult generate(HashMap parmMap) {
count++;
AppleECardImageInformationWebServiceResult result = new AppleECardImageInformationWebServiceResult();
//get ecard data according to clntcode and certno,
String clntCode = (String)parmMap.get("CLNTCODE");
String certNo = (String)parmMap.get("CERTNO");
List appleECardImageModelList = new ArrayList();
AppleECardDAO eCardDAO = new AppleECardDAO();
String returnCode = "0";
DataSet eCardDS = eCardDAO.getECardInformation(clntCode, certNo);
long dataTime = System.currentTimeMillis();
Thread.currentThread().setName("Thread"+count);
System.out.println(Thread.currentThread().getName()+"getData时间=========="+(dataTime-(Long)parmMap.get("time"))+"毫秒");
if (!TypeChecker.isEmpty(eCardDS.getReturnValues())) {
returnCode = Utility.convertNullToEmpty((String)eCardDS.getReturnValues().get(0));
}
String eCardType = "eCardInformation";
this.eCardModel = eCardXMLConfigManager.geteCardXMLConfigManager().getXMLeCardModelById(eCardType);
String currentDate = Utilities.getCurrentDate().substring(0,8);
//generate eCard image
while (eCardDS.next()) {
AppleECardImageModel appleECardImageModel = new AppleECardImageModel();
List appleECardImagesInforModelList = new ArrayList();
AppleECardImagesInforModel appleECardImagesInforModel = new AppleECardImagesInforModel();
eCardForm eCardForm = (com.aig.ecompass.ecard.model.eCardForm) eCardModel.getFrontFormList().get(0);
/*eCardForm.setFontSize(32);
eCardForm.setFontType("Standard Gothic");*/
BufferedImage image;
BufferedImage frontImage;
BufferedImage backImage;
String memberId = eCardDS.getString("MEMBERID").trim();
String depCode = eCardDS.getString("DEPCODE").trim();
String polNo = eCardDS.getString("POLNO").trim();
appleECardImageModel.setMemberId(memberId);
appleECardImageModel.setDepCode(depCode);
appleECardImageModel.setPolNo(polNo);
String frontFileName = eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/temp/"+memberId+"_F_"+currentDate+"."+suffix ;
String backFileName = eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/temp/"+memberId+"_B_"+currentDate+"."+suffix;
String imageFileName = eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/temp/"+memberId+"_"+currentDate+"."+suffix;
deleteDirFilesLikeName(eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/temp/",memberId);
try{
String eCardColor = eCardDS.getString("CARDCOLOR");
frontImage = ImageIO.read(new File(eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/com/aig/ecompass/common/images/ecard/"+eCardColor+"Front."+suffix));
Graphics2D frontG = frontImage.createGraphics();
for(Iterator frontIte = this.eCardModel.getFrontFormList().iterator() ;frontIte.hasNext();){
eCardForm eform = (eCardForm)frontIte.next();
setFormInformation(eform, frontG, eCardDS);
}
appleECardImagesInforModel.setFrontimage(frontFileName);
frontG.dispose();
frontImage.flush();
backImage = ImageIO.read(new File(eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/com/aig/ecompass/common/images/ecard/"+eCardColor+"Back."+suffix));
Graphics2D backG = backImage.createGraphics();
for(Iterator backIte = this.eCardModel.getBackFormList().iterator() ;backIte.hasNext();){
eCardForm eform = (eCardForm)backIte.next();
setFormInformation(eform, backG, eCardDS);
}
appleECardImagesInforModel.setBackimage(backFileName);
appleECardImagesInforModelList.add(appleECardImagesInforModel);
appleECardImageModel.setImageList(appleECardImagesInforModelList);
backG.dispose();
backImage.flush();
appleECardImageModelList.add(appleECardImageModel);
try{
ImageIO.write(frontImage, suffix, new File(frontFileName));
ImageIO.write(backImage, suffix, new File(backFileName));
System.out.println(Thread.currentThread().getName()+"===CreateImage时间=========="+System.currentTimeMillis()+"毫秒");
System.out.println(Thread.currentThread().getName()+"===getData到createimage时间===="+(System.currentTimeMillis()-dataTime)+"毫秒");
} catch (Exception e) {
throw new RuntimeException(e);
}
} catch (IOException e) {
e.printStackTrace();
}
}
result.setResult(returnCode, "");
result.seteCardImageList(appleECardImageModelList);
return result;
}
private void setFormInformation(eCardForm eForm, Graphics2D g, DataSet ds)throws IOException{
Font plainFont = new Font(eForm.getFontType(), Font.LAYOUT_LEFT_TO_RIGHT, eForm.getFontSize());
String drawString = null ;
if(TypeChecker.isTrue(eForm.isConstant())){
drawString = eForm.getValue().trim();
}
else{
try{
drawString = ds.getString(eForm.getValue()).trim();
}
catch(Exception e){
return ;
}
}
//check value
if(TypeChecker.isEmpty(drawString)){
return ;
}
if(TypeChecker.isTrue(eForm.getImage()) ) {
if(TypeChecker.isTrue(drawString)){
String eCardColor = ds.getString("CARDCOLOR");
String MedpassLogo = eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/com/aig/ecompass/common/images/ecard/MedpassLogo."+suffix ;
if(!TypeChecker.isEmpty(eCardColor) && eCardColor.equalsIgnoreCase("eCARDCOLOR.Red")){
MedpassLogo = eCardXMLConfigManager.geteCardXMLConfigManager().getRealPath()+ "/com/aig/ecompass/common/images/ecard/eCARDCOLOR.RedMedpassLogo."+suffix ;
}
Image imagewritted = ImageIO.read(new File(MedpassLogo));
g.drawImage(imagewritted,eForm.getxPosition(), eForm.getyPosition(), eForm.getWidth(), eForm.getHeight(), null, null);
}
return ;
}
//color
g.setColor(Color.BLACK);
if(TypeChecker.isEmpty(eForm.getColor())){
if(eForm.getColor().equals("red")){
g.setColor(Color.BLACK);
}
else if(eForm.getColor().equals("blue")){
g.setColor(Color.BLUE);
}
else if(eForm.getColor().equals("gray")){
g.setColor(Color.GRAY);
}
else if(eForm.getColor().equals("yellow")){
g.setColor(Color.YELLOW);
}
else if(eForm.getColor().equals("dark_gray")){
g.setColor(Color.DARK_GRAY);
}
else if(eForm.getColor().equals("pink")){
g.setColor(Color.PINK);
}
}
AttributedString as = new AttributedString(drawString);
as.addAttribute(TextAttribute.FONT, plainFont);
if(TypeChecker.isTrue(eForm.isBold())){
g.setFont(plainFont);
Font boldFont = new Font(eForm.getFontType(), Font.BOLD, eForm.getFontSize());
as.addAttribute(TextAttribute.FONT, boldFont);
as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_LIGHT);
//as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
}
if(TypeChecker.isTrue(eForm.isAlignRight())){
as.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL);
}
else{
as.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_LTR);
}
if(TypeChecker.isTrue(eForm.isUnderLine())){
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
}
//as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 25);
int xPos = eForm.getxPosition();
if(TypeChecker.isTrue(eForm.isAlignRight())){
g.setFont(plainFont);
FontMetrics fm = g.getFontMetrics();
Rectangle2D rc = fm.getStringBounds(drawString.trim(), g);
xPos = eForm.getxPosition() - (int)(rc.getWidth());
if(xPos < 0 ){
xPos = 0;
}
}
if(TypeChecker.isTrue(eForm.isAlignCenter())){
g.setFont(plainFont);
FontMetrics fm = g.getFontMetrics();
Rectangle2D rc = fm.getStringBounds(drawString.trim(), g);
xPos = Math.round((1130-(int)(rc.getWidth()))/2);
if(xPos < 0 ){
xPos = 0;
}
}
int yxPos = eForm.getyPosition();
g.drawString(as.getIterator(), xPos, yxPos);
}
private void deleteDirFilesLikeName(String dir, String likeName){
File file = new File(dir);
if(file.exists()){
deleteFilesLikeName(file, likeName);
}
}
private void deleteFilesLikeName(File file, String likeName){
if(file.isFile()){
String temp = file.getName().substring(0,file.getName().lastIndexOf("."));
if(temp.indexOf(likeName) != -1){
file.delete();
}
}
else{
File[] files = file.listFiles();
for(int i = 0; i < files.length; i++){
deleteFilesLikeName(files[i], likeName);
}
}
}
public static void main(String[] args) throws InterruptedException {
ECardHandler test = new ECardHandler();
HashMap parmMap = new HashMap();
parmMap.put("clntCode", "0001");
parmMap.put("certNo", "0001");
test.generate(parmMap);
}
}
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[16-5-13 16:28:56:254 CST] 00000031 SystemOut O at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O Common Logon Log -- [Fri May 13 16:28:56 CST 2016][Thread1]:[info]Common Die
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O /eCOMPASS
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,269 INFO FrameworkLog :Application Framework finds a your configuring ActionForm <FormBeanParameter Name=‘AppleCommonWebServiceActionForm‘ type=‘‘ inputaction=‘ECardModule.eCardImageInformation‘ scope=‘request‘ intercept=‘com.aig.ecompass.utility.ActionFormGeneralIntercept‘ />
[16-5-13 16:28:56:269 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,269 INFO FrameworkLog :Application Framework finds a ActionForm instance with<FormBeanParameter Name=‘AppleCommonWebServiceActionForm‘ type=‘com.aig.ecompassios.system.AppleCommonWebServiceActionForm‘ inputaction=‘‘ scope=‘‘ intercept=‘‘ />
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog :CommandMapping command=‘AppleWebService‘ commandProcessor=‘class com.aiait.web.container.AppleWebServiceCommandProcessor‘
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog :Module Name:ECardModule Processor:com.aig.ecompassios.ecard.AppleECardModuleBusinessHandler Result:com.aig.ecompassios.ecard.model.AppleECardImageInformationWebServiceResult
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO DefaultLogge :Your Apple Web Service Result class com.aig.ecompassios.ecard.model.AppleECardImageInformationWebServiceResult
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog :Database SQL Execute in [class com.aiait.web.container.session.dao.HttpSessionDAO]
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog : exec dbo.EC_APPLE_SESSIONCONTAINER_CHECKSESSIONSTATUS N‘eBenefits1463127813133AAB6F7CH8AB0UIJV8XCIZN04I8R47SLSKOV0XOZAKOWYAB0P711N71OO10DP0Q9U1O8ZQUTSH‘,N‘1463128125952‘,‘2016-05-13 16:28:56.285‘
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog :Application Framework Closes a database connection
[16-5-13 16:28:56:285 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,285 INFO FrameworkLog :The method (doECardImageInformation) has been invoked in class com.aig.ecompassios.ecard.AppleECardModuleBusinessHandler.
[16-5-13 16:28:56:300 CST] 00000031 SystemOut O Thread1getDate前================1463128136300
[16-5-13 16:28:56:300 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,300 INFO FrameworkLog :Database SQL Execute in [class com.aig.ecompassios.dao.AppleECardDAO]
[16-5-13 16:28:56:300 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,300 INFO FrameworkLog : exec EC_GET_ECARD_INFORMATION N‘15604‘,N‘0000071233‘,null
[16-5-13 16:28:56:488 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,488 INFO FrameworkLog :Application Framework Closes a database connection
[16-5-13 16:28:56:488 CST] 00000031 SystemOut O Thread2getData时间==========188毫秒
[16-5-13 16:28:56:488 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:28:56,488 INFO DefaultLogge :Get XML eCard By Id = eCardInformation
[16-5-13 16:29:02:266 CST] 00000031 SystemOut O Thread2===CreateImage时间==========1463128142266毫秒
[16-5-13 16:29:02:266 CST] 00000031 SystemOut O Thread2===getData到createimage时间====5778毫秒
[16-5-13 16:29:02:812 CST] 00000031 SystemOut O Thread2===CreateImage时间==========1463128142812毫秒
[16-5-13 16:29:02:812 CST] 00000031 SystemOut O Thread2===getData到createimage时间====6324毫秒
[16-5-13 16:29:05:885 CST] 00000031 SystemOut O Thread2===CreateImage时间==========1463128145885毫秒
[16-5-13 16:29:05:885 CST] 00000031 SystemOut O Thread2===getData到createimage时间====9397毫秒
[16-5-13 16:29:09:192 CST] 00000031 SystemOut O Thread2===CreateImage时间==========1463128149192毫秒
[16-5-13 16:29:09:192 CST] 00000031 SystemOut O Thread2===getData到createimage时间====12704毫秒
[16-5-13 16:29:12:156 CST] 00000031 SystemOut O Thread2===CreateImage时间==========1463128152156毫秒
[16-5-13 16:29:12:156 CST] 00000031 SystemOut O Thread2===getData到createimage时间====15668毫秒
[16-5-13 16:29:12:156 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:29:12,156 INFO FrameworkLog :The page view is JSON_Common_View
[16-5-13 16:29:12:156 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:29:12,156 INFO FrameworkLog :Database SQL Execute in [class com.aiait.web.container.session.dao.HttpSessionDAO]
[16-5-13 16:29:12:156 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:29:12,156 INFO FrameworkLog : exec dbo.EC_APPLE_SESSIONCONTAINER_SAVE_HTTPSESSION N‘eBenefits1463127813133AAB6F7CH8AB0UIJV8XCIZN04I8R47SLSKOV0XOZAKOWYAB0P711N71OO10DP0Q9U1O8ZQUTSH‘,‘2016-05-13 16:59:12.156‘,N‘1463128125952‘
[16-5-13 16:29:12:172 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:29:12,172 INFO FrameworkLog :Application Framework Closes a database connection
[16-5-13 16:29:12:172 CST] 00000031 SystemOut O eBenefit 2016-05-13 16:29:12,172 INFO FrameworkLog :
标签:
原文地址:http://www.cnblogs.com/jingRegina/p/5489922.html