webservice接口实现类

package service.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import db.ConnectionPool;
import domain.ProductCase;
import net.sf.json.JSONObject;
import service.SayHiService;
import util.Config;
import util.DbConnect;
import util.ParseProperties;
/**
  * 作为测试的WebService实现类
  * @author 
  */
@WebService(endpointInterface = "service.SayHiService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class SayHiServiceImp implements SayHiService {
	protected static Object objwait = new Object();
	@Override
	public String sayHi(String name) {
		synchronized (objwait) {
			JSONObject json = JSONObject.fromObject(name);
			ProductCase	product = (ProductCase) JSONObject.toBean(json, ProductCase.class);
			Config.getLog().writeLog(2, product.toString());
			if(product.getId()==null||"".equals(product.getId().trim())){
				return"Code:201";
			}else if(product.getWallbillNo()==null||"".equals(product.getWallbillNo().trim())){
				return"Code:301";
			}else if(product.getDes()==null||"".equals(product.getDes().trim())){
				return"Code:401";
			}else if(product.getTransitZno()==null||"".equals(product.getTransitZno().trim())){
				return"Code:501";
			}else if(product.getSource()==null||"".equals(product.getSource().trim())){
				return"Code:601";
			}else if(product.getUpdateTm()==null){
				return"Code:701";
			}else if(!dataSelect(product)){
				return "Code:801";
			}else{
				return "Code:101";
			}
		}
	}

public boolean dataSelect(ProductCase product){
	boolean lean=false;
	Connection con = ConnectionPool.getInstance().getConnection();
	if(con!=null){
		PreparedStatement pMhk = null;
		ResultSet rs = null;
   try{
	   pMhk = con.prepareStatement(ParseProperties.getValue("select_sql"));
				pMhk.setString(1, product.getWallbillNo());
				rs = pMhk.executeQuery();
				if(rs.next()){
					lean=dateUpdata(product);
				}else{
					lean=dataInsert(product);
				}
			} catch (SQLException e) {
				Config.getLog().writeLog(2, "查询tt_waybill_des_mid表数据失败:" + e);
			} finally {
				DbConnect.closeOthers(pMhk, null);
				ConnectionPool.getInstance().putConnection(con);
			}
		}
		return lean;
	}

public boolean dataInsert(ProductCase product){
	boolean lean=false;
	Connection con = ConnectionPool.getInstance().getConnection();
	PreparedStatement pMhk = null;
	if(con!=null){
   try{
	   con.setAutoCommit(false);
	   pMhk = con.prepareStatement(ParseProperties.getValue("insert_sql"));
	   pMhk.setString(1, product.getWallbillNo());
	   pMhk.setString(2, product.getDes());
	   pMhk.setTimestamp(3, new java.sql.Timestamp(product.getUpdateTm()));
	   pMhk.addBatch();
	   pMhk.executeBatch();
	   con.commit();
	   lean = true;
} catch (SQLException e) {
	try {
		con.rollback();
	} catch (SQLException e1) {
		Config.getLog().writeLog(2, "tt_waybill_des_mid表回滚数据失败:"+ e1);
	}
Config.getLog().writeLog(2, "插入tt_waybill_des_mid表数据失败:"+ e);
}finally{
	DbConnect.closeOthers(pMhk, null);
	ConnectionPool.getInstance().putConnection(con);					
	}
}
	return lean;
}

private boolean dateUpdata(ProductCase product){
	boolean lean=false;
	Connection con = ConnectionPool.getInstance().getConnection();
	PreparedStatement pMhk = null;
		if(con!=null){
	   try{
		   con.setAutoCommit(false);
		   pMhk = con.prepareStatement(ParseProperties.getValue("update_sql"));
		   pMhk.setString(1, product.getDes());
		   pMhk.setTimestamp(2, new java.sql.Timestamp(product.getUpdateTm()));
		   pMhk.setString(3, product.getWallbillNo());
		   pMhk.executeUpdate();
		   con.commit();
		   lean=true;
	} catch (SQLException e) {
		try {
			con.rollback();
		} catch (SQLException e1) {
			Config.getLog().writeLog(2, "tt_waybill_des_mid表回滚数据失败:"+ e1);
		}
   Config.getLog().writeLog(2, "更新tt_waybill_des_mid表数据失败:"+ e);
	}finally{
		DbConnect.closeOthers(pMhk, null);
		ConnectionPool.getInstance().putConnection(con);					
		}
	}
		return lean;
}
	
/**	@Override
	public int CheckTime(Date clientTime) {
		// 精确到秒
		         String dateServer = new java.sql.Date(System.currentTimeMillis())
		                 .toString()
		                 + " "
		                 + new java.sql.Time(System.currentTimeMillis());
		         String dateClient = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
		                 .format(clientTime);
		         return dateServer.equals(dateClient) ? 1 : 0;
	}*/
}

  

posted @ 2017-12-15 14:34  杯子茶壶  阅读(195)  评论(0)    收藏  举报