com.xia.ssm.tools.ocr.CheckPic.java Source code

Java tutorial

Introduction

Here is the source code for com.xia.ssm.tools.ocr.CheckPic.java

Source

package com.xia.ssm.tools.ocr;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Timestamp;
import java.util.List;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.xia.ssm.constant.ocr.ErrorsLogPrintUtil;
import com.xia.ssm.constant.ocr.ExceptionClaimCode;
import com.xia.ssm.vo.ocr.ClaimPhoneDTO;

public class CheckPic {
    private static Logger log = Logger.getLogger(CheckPic.class);

    /**
     * ?
     * @Title: sendPicToWt
     * @param thPhoneDTO
     * @return  
     * @createDate 20161026;?3:26:55
     * @author xjf
     */
    public static ClaimPhoneDTO sendPicToWt(ClaimPhoneDTO thPhoneDTO) {
        String result = "";
        String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//?
        long beginTime = System.currentTimeMillis();
        try {
            log.info("file======" + file);
            result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK,
                    WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl());
            log.info("result======" + result);
        } catch (Exception e) {
            // TODO: handle exception
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }

        String[] encData = result.split("==@@");
        long times = System.currentTimeMillis() - beginTime;
        log.info("" + times);
        String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", "");
        Document doc;
        String insertString = "";
        try {
            doc = DocumentHelper.parseText(dataString);
            String status = doc.selectSingleNode("/data/message/status").getText();
            String value = doc.selectSingleNode("/data/message/value").getText();
            StringBuffer sql = new StringBuffer();
            if ("?".equals(value)) {
                List list = doc.selectNodes("/data/cardsinfo/card/item");
                StringBuffer json = new StringBuffer();
                for (int j = 1; j < list.size() - 1; j++) {
                    Element term = (Element) list.get(j);
                    String returString = term.getText();
                    insertString += "'" + returString + "'" + ",";
                    String name = term.attribute("desc").getText();

                    if ("???".equals(name)) {
                        thPhoneDTO.setPlateNo(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setVehicleType(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setCustomerName(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setAddress(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setVehicleModels(returString);
                    }
                    if ("?".equals(name)) {
                        thPhoneDTO.setVin(returString);
                    }
                    if ("???".equals(name)) {
                        thPhoneDTO.setEngineNo(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setRegisterDate(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setIssueDate(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setUseType(returString);
                    }
                    thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                    thPhoneDTO.setState(value);
                    thPhoneDTO.setStatus(status);
                }
            } else {
                thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                thPhoneDTO.setState(value);
                thPhoneDTO.setStatus(status);
                thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            }
        } catch (Exception e) {
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }
        return thPhoneDTO;
    }

    public static Connection getCon() {
        try {
            //SQLServer2005
            String urlString = "jdbc:sqlserver://192.168.110.200:1433;DatabaseName=??";
            String nameString = "sa";
            String pasString = "sa1";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection(urlString, nameString, pasString);
            return con;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    public static String getMillisecond() {
        String str = new Timestamp(System.currentTimeMillis()).toString().replaceAll("-", "").replaceAll(" ", "")
                .replaceAll(":", "").replaceAll("\\.", "");
        return str;
    }

    /**
     * 
     * @Title: sendPlateNoPicToWt
     * @param thPhoneDTO
     * @return  
     * @createDate 20161026;?3:31:45
     * @author luy
     */
    public static ClaimPhoneDTO sendPlateNoPicToWt(ClaimPhoneDTO thPhoneDTO) {
        String result = "";
        String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//?
        long beginTime = System.currentTimeMillis();
        try {
            log.info("file======" + file);
            result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK,
                    WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl());
            log.info("result======" + result);
        } catch (Exception e) {
            // TODO: handle exception
            thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }

        String[] encData = result.split("==@@");
        long times = System.currentTimeMillis() - beginTime;
        log.info("" + times);
        String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", "");
        Document doc;
        String insertString = "";
        try {
            doc = DocumentHelper.parseText(dataString);
            String status = doc.selectSingleNode("/data/message/status").getText();
            String value = doc.selectSingleNode("/data/message/value").getText();
            if ("?".equals(value)) {
                List list = doc.selectNodes("/data/cardsinfo/card/item");
                for (int j = 0; j < list.size(); j++) {
                    Element term = (Element) list.get(j);
                    String returString = term.getText();
                    insertString += "'" + returString + "'" + ",";
                    String name = term.attribute("desc").getText();
                    if ("?".equals(name)) {
                        thPhoneDTO.setPlateNo(returString);
                    }
                    thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                    thPhoneDTO.setState(value);
                    thPhoneDTO.setStatus(status);
                }
            } else {
                thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                thPhoneDTO.setState(value);
                thPhoneDTO.setStatus(status);
                thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED);
            }
        } catch (Exception e) {
            thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }
        return thPhoneDTO;
    }

    /**
     * ?
     * @Title: sendIdCardToWt
     * @param thPhoneDTO
     * @return  
     * @createDate 20161026;?3:32:41
     * @author xjf
     */
    public static ClaimPhoneDTO sendIdCardToWt(ClaimPhoneDTO thPhoneDTO) {
        String result = "";
        String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//?
        long beginTime = System.currentTimeMillis();
        try {
            log.info("file======" + file);
            result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK,
                    WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl());
            log.info("result======" + result);
        } catch (Exception e) {
            // TODO: handle exception
            thPhoneDTO.setResponseCode(ExceptionClaimCode.IDCARD_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }

        String[] encData = result.split("==@@");
        long times = System.currentTimeMillis() - beginTime;
        log.info("" + times);
        String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", "");
        Document doc;
        String insertString = "";
        try {
            doc = DocumentHelper.parseText(dataString);
            String status = doc.selectSingleNode("/data/message/status").getText();
            String value = doc.selectSingleNode("/data/message/value").getText();
            if ("?".equals(value)) {
                List list = doc.selectNodes("/data/cardsinfo/card/item");
                for (int j = 1; j < list.size() - 1; j++) {
                    Element term = (Element) list.get(j);
                    String returString = term.getText();
                    insertString += "'" + returString + "'" + ",";
                    String name = term.attribute("desc").getText();

                    if ("??".equals(name)) {
                        thPhoneDTO.setUserName(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setSex(returString);
                    }
                    if ("?".equals(name)) {
                        thPhoneDTO.setNation(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setBirthday(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setAddress(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setIdCardNo(returString);
                    }
                    if ("?".equals(name)) {
                        thPhoneDTO.setIdCardPhoto(returString);
                    }
                    thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                    thPhoneDTO.setState(value);
                    thPhoneDTO.setStatus(status);
                }
            } else {
                thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                thPhoneDTO.setState(value);
                thPhoneDTO.setStatus(status);
                thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            }
        } catch (Exception e) {
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }
        return thPhoneDTO;
    }

    /**
     * ?
     * @Title: sendDriverToWt
     * @param thPhoneDTO
     * @return  
     * @createDate 20161026;?3:33:28
     * @author luy
     */
    public static ClaimPhoneDTO sendDriverToWt(ClaimPhoneDTO thPhoneDTO) {
        String result = "";
        String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//?
        long beginTime = System.currentTimeMillis();
        try {
            log.info("file======" + file);
            result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK,
                    WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl());
            log.info("result======" + result);
        } catch (Exception e) {
            // TODO: handle exception
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVER_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }

        String[] encData = result.split("==@@");
        long times = System.currentTimeMillis() - beginTime;
        log.info("" + times);
        String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", "");
        Document doc;
        String insertString = "";
        try {
            doc = DocumentHelper.parseText(dataString);
            String status = doc.selectSingleNode("/data/message/status").getText();
            String value = doc.selectSingleNode("/data/message/value").getText();
            if ("?".equals(value)) {
                List list = doc.selectNodes("/data/cardsinfo/card/item");
                for (int j = 1; j < list.size() - 1; j++) {
                    Element term = (Element) list.get(j);
                    String returString = term.getText();
                    insertString += "'" + returString + "'" + ",";
                    String name = term.attribute("desc").getText();

                    if ("??".equals(name)) {
                        thPhoneDTO.setCardNo(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setUserName(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setSex(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setAddress(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setBirthday(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setRegisterTime(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setDrivingType(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setStartTime(returString);
                    }
                    if ("?".equals(name)) {
                        thPhoneDTO.setLimitTime(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setEndTime(returString);
                    }
                    thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                    thPhoneDTO.setState(value);
                    thPhoneDTO.setStatus(status);
                }
            } else {
                thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                thPhoneDTO.setState(value);
                thPhoneDTO.setStatus(status);
                thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            }
        } catch (Exception e) {
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }
        return thPhoneDTO;
    }

    /**
     * ?
     * @Title: sendBankToWt
     * @param thPhoneDTO
     * @return  
     * @createDate 20161026;?6:39:23
     * @author luy
     */
    public static ClaimPhoneDTO sendBankToWt(ClaimPhoneDTO thPhoneDTO) {
        String result = "";
        String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//?
        long beginTime = System.currentTimeMillis();
        try {
            log.info("file======" + file);
            result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK,
                    WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl());
            log.info("result======" + result);
        } catch (Exception e) {
            // TODO: handle exception
            thPhoneDTO.setResponseCode(ExceptionClaimCode.BANK_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }

        String[] encData = result.split("==@@");
        long times = System.currentTimeMillis() - beginTime;
        log.info("" + times);
        String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", "");
        Document doc;
        String insertString = "";
        try {
            doc = DocumentHelper.parseText(dataString);
            String status = doc.selectSingleNode("/data/message/status").getText();
            String value = doc.selectSingleNode("/data/message/value").getText();
            if ("?".equals(value)) {
                List list = doc.selectNodes("/data/cardsinfo/card/item");
                for (int j = 1; j < list.size() - 1; j++) {
                    Element term = (Element) list.get(j);
                    String returString = term.getText();
                    insertString += "'" + returString + "'" + ",";
                    String name = term.attribute("desc").getText();

                    if ("???".equals(name)) {
                        thPhoneDTO.setPlateNo(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setVehicleType(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setCustomerName(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setAddress(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setVehicleModels(returString);
                    }
                    if ("?".equals(name)) {
                        thPhoneDTO.setVin(returString);
                    }
                    if ("???".equals(name)) {
                        thPhoneDTO.setEngineNo(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setRegisterDate(returString);
                    }
                    if ("??".equals(name)) {
                        thPhoneDTO.setIssueDate(returString);
                    }
                    if ("".equals(name)) {
                        thPhoneDTO.setUseType(returString);
                    }
                    thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                    thPhoneDTO.setState(value);
                    thPhoneDTO.setStatus(status);
                }
            } else {
                thPhoneDTO.setConsumeTime("" + String.valueOf(times) + "");
                thPhoneDTO.setState(value);
                thPhoneDTO.setStatus(status);
                thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            }
        } catch (Exception e) {
            thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED);
            ErrorsLogPrintUtil.printToLog4j(log, e);
        }
        return thPhoneDTO;
    }
}