Java tutorial
/** * Copyright (C) qzgf, 2010 * * License :Apache License 2.0 * Project :emsex * Package :com.qzgf.datacollection.timer * File :Yd12580TimerTask.java * Written by :fjfdszj * Created Date :Sep 13, 2010 * Purpose :?? ====================================== * Modifyer by :fjfdszj * Update Date :Sep 13, 2010 * Purpose :?? */ package com.qzgf.datacollection.timer; import java.rmi.RemoteException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.TimerTask; import javax.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import com._59112580.www.Postal; import com._59112580.www.PostalServiceSoapProxy; import com.qzgf.IbatisDaoTools.BaseSqlMapDAO; import com.qzgf.application.net.communicate.domain.CommunicateFacade; import com.qzgf.comm.Constant; import com.qzgf.comm.MD5; /** * Purpose : 201012580? * : webserivce? http://www.59112580.com/PostalService.asmx?WSDL * @author fjfdszj * @see Yd12580TimerTask.java * */ public class Yd12580TimerTask extends TimerTask { /** * Purpose : */ private Log log = LogFactory.getLog(ImmigrationTimerTask.class); private BaseSqlMapDAO baseSqlMapDAO; //mysql?? //webservice? PostalServiceSoapProxy proxy = new PostalServiceSoapProxy();//??webservice? //?(???) String username = Constant.User_Yd12580; String passwd = Constant.Pwd_Yd12580; String parameter = Constant.Parm_Yd12580; //?? private String userid = Constant.NetUser_Yd12580; private CommunicateFacade communicateFacade;//??? //,?? public Yd12580TimerTask(ServletContext servletContext) { // ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); //? baseSqlMapDAO = (BaseSqlMapDAO) context.getBean("baseSqlMapDAO"); //??? communicateFacade = (CommunicateFacade) context.getBean("communicateFacade"); if (log.isDebugEnabled()) log.debug("12580?"); } //???5? @Override public void run() { //get message HashMap param = new HashMap(); // Date currentTime = new Date();//? SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowtime = formatter.format(currentTime); //? SimpleDateFormat formatterex = new SimpleDateFormat("yyyyMMdd"); String time = formatterex.format(currentTime); //? //??? log.debug(nowtime + ":12580??5???"); System.out.println(nowtime + ":12580??5???"); try { //webservice???======================== //? String md5username = username + time; String md5passwd = passwd + time; MD5 md5 = new MD5(); md5username = md5.StrToMd5(md5username); md5passwd = md5.StrToMd5(md5passwd); //===================================================== //webservice Postal[] ps = proxy.getList(md5username, md5passwd, parameter); String reorderArr = ""; int size = ps.length; if (ps != null && size > 0) { System.out.println(nowtime + ":?12580" + size + "??"); for (int i = 0; i < size; i++) { //??? String pidex = baseSqlMapDAO.sequences("t_net_order"); param.clear(); param.put("pidex", pidex); param.put("pname", ps[i].getRecName()); //??? param.put("punit", " "); //?? //?? String paddressex = ps[i].getRecAddress();//??^13 HashMap anlyadd = new HashMap(); //? // anlyadd.put("type", "NAME_PROVINCEID"); // anlyadd.put("value", ps[i].getProvince()); // String addcode=(String)baseSqlMapDAO.queryForObject("Communicate.gerCodeYd12580",paddress); /* // anlyadd.clear(); anlyadd.put("type", "NAME_CITYID"); anlyadd.put("value", ps[i].getRecCity()); String pcity=(String)baseSqlMapDAO.queryForObject("Communicate.gerCodeYd12580",anlyadd); // anlyadd.clear(); anlyadd.put("type", "NAME_COUNTYID"); anlyadd.put("value", ps[i].getRecCounty()); String pcounty=(String)baseSqlMapDAO.queryForObject("Communicate.gerCodeYd12580",anlyadd); */ //ps[i].getRecCity()? ps[i].getRecProvince()?? ps[i].getRecCounty() String paddress = ps[i].getRecProvince().replace("?", "") + ps[i].getRecCity().replace("", "") + ps[i].getCounty(); System.out.println("???:" + paddress); String addcode = (String) baseSqlMapDAO.queryForObject("Communicate.gerCodeImmigration", paddress); String[] addcodearr = addcode.split("\\,");//? //??? param.put("pprovince", "350000"); param.put("pcity", addcodearr[1]); param.put("pcounty", addcodearr[2]); param.put("paddress", paddressex);//???,??? //? anlyadd.clear(); anlyadd.put("type", "NAME_PROVINCEID"); anlyadd.put("value", ps[i].getProvince()); String precprovince = (String) baseSqlMapDAO.queryForObject("Communicate.gerCodeYd12580", anlyadd); // anlyadd.clear(); anlyadd.put("type", "NAME_CITYID"); anlyadd.put("value", ps[i].getCity()); String recpcity = (String) baseSqlMapDAO.queryForObject("Communicate.gerCodeYd12580", anlyadd); // param.put("precprovince", precprovince);//?? param.put("preccity", recpcity); param.put("pareacode", " "); param.put("ptel", ps[i].getRecTel());//??? param.put("pmobile", ps[i].getRecTel()); param.put("ppost", ""); param.put("pmailtype", "0");//0? //================================================================================ /** * ???? */ String spec = ps[i].getSpec(); String price = ps[i].getPrice(); String isfee = ps[i].getIsFee(); String cnt = ""; if (isfee.equals("0")) { cnt = ":" + spec; } else { cnt = ":" + spec + ",?:" + price + ","; } param.put("pclientremark", cnt);// //========================================================================================= param.put("porderingnum", "1"); param.put("porderingweight", "0.00"); param.put("pbookingtime", "");//2010-06-23 param.put("porderingtime", nowtime); param.put("precevingtime", nowtime); //?testadmin,testadmin param.put("pcreate_code", userid); param.put("peditor_code", userid); param.put("paddressid", "0"); //???? param.put("pthirdparty", "12580"); //1.? try { baseSqlMapDAO.insert("Order.insertOrder", param); } catch (Exception e) { System.out.println(e.toString()); } //2.???? param.clear(); param.put("pid", pidex); try { HashMap map = communicateFacade.ProRequest("clientadd", param); param.clear(); if (map != null) { String state = map.get("STATE").toString(); String remark = map.get("REMARK").toString(); //??? if (state.equals("2")) { param.put("orderingstate", "");//(??) } else if (state.equals("1")) { param.put("orderingstate", "?");// } else if (state.equals("0")) { param.put("orderingstate", "");// } } else { param.put("orderingstate", "?");// } //??:??????? param.put("ORDERID", pidex); communicateFacade.modifyBillState(param); } catch (Exception ex) { System.out.println("?"); } //3.??12580??? param.clear(); reorderArr = reorderArr + ps[i].getOrderID() + ","; param.put("pno", ps[i].getOrderID()); param.put("pcontactor", ps[i].getContactor()); param.put("paddress", paddressex); param.put("pphone", ps[i].getPhone()); param.put("pprice", ps[i].getPrice()); param.put("pisfee", isfee); param.put("pspec", ps[i].getSpec()); param.put("pprovince", ps[i].getProvince()); param.put("pcity", ps[i].getCity()); param.put("pcounty", ps[i].getCounty()); param.put("ppostcode", ps[i].getPostCode()); param.put("precprovince", ps[i].getRecProvince()); param.put("preccity", ps[i].getRecCity()); param.put("preccounty", ps[i].getCounty()); param.put("precname", ps[i].getRecName()); param.put("precaddress", ps[i].getRecAddress()); param.put("prectel", ps[i].getRecTel()); //?? param.put("porderid", pidex); baseSqlMapDAO.insert("Communicate.insertYd12580", param); } //for end reorderArr = reorderArr.substring(0, reorderArr.length() - 1); } //if end System.out.println(nowtime + " " + reorderArr); log.debug(nowtime + " " + reorderArr); //????12580 System.out.println("12850??1?" + proxy.postalGetDataBack(reorderArr)); } catch (RemoteException e) { // TODO Auto-generated catch block System.out.println("12580"); } } // public static void main(String[] args) { PostalServiceSoapProxy proxy = new PostalServiceSoapProxy(); // SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); Date currentTime = new Date();//? String nowtime = formatter.format(currentTime); //? //?() try { String username = "12580postal"; String passwd = "12580postal"; String parameter = "";//116,-1,178 System.out.println("say no"); // username = username + nowtime; passwd = passwd + nowtime; MD5 md5 = new MD5(); username = md5.StrToMd5(username); passwd = md5.StrToMd5(passwd); // try { // MessageDigest md; // md = MessageDigest.getInstance("MD5"); // BASE64Encoder base64en = new BASE64Encoder(); //// username=new String(md.digest(username.getBytes("UTF-8")),"UTF-8"); //// passwd=new String(md.digest(passwd.getBytes("UTF-8")),"UTF-8"); // username=new String(base64en.encode(md.digest(username.getBytes()))); // passwd=new String(base64en.encode(md.digest(passwd.getBytes()))); // } catch (NoSuchAlgorithmException e) { // // TODO Auto-generated catch block // e.printStackTrace(); //// }catch (UnsupportedEncodingException e) { //// // TODO Auto-generated catch block //// e.printStackTrace(); // } System.out.println("hello"); //661B4842E1F2F64FABFE96DE5B1CDBEF // username="7D5F89392DDD0DD9A2F76C61C4AD61E2"; // passwd="7D5F89392DDD0DD9A2F76C61C4AD61E2"; Postal[] ps = proxy.getList(username, passwd, parameter);//parameter if (ps != null) { for (int i = 0; i < ps.length; i++) { System.out.println("ps[i].getAddress()" + ps[i].getAddress()); System.out.println("ps[i].getContactor()" + ps[i].getContactor()); System.out.println("ps[i].getIsFee()" + ps[i].getIsFee()); System.out.println("ps[i].getOrderID()" + ps[i].getOrderID()); System.out.println("ps[i].getPhone()" + ps[i].getPhone()); System.out.println("ps[i].getPrice()" + ps[i].getPrice()); System.out.println("ps[i].getSpec()" + ps[i].getSpec()); System.out.println("ps[i].getCity()" + ps[i].getCity()); System.out.println("ps[i].getPostCode()" + ps[i].getPostCode()); System.out.println("ps[i].getCounty()" + ps[i].getCounty()); System.out.println("ps[i].getProvince()" + ps[i].getProvince()); System.out.println("ps[i].getRecAddress()" + ps[i].getRecAddress()); System.out.println("ps[i].getRecCity()" + ps[i].getRecCity()); System.out.println("ps[i].getRecTel()" + ps[i].getRecTel()); System.out.println("ps[i].getRecProvince()" + ps[i].getRecProvince()); System.out.println("ps[i].getRecCounty()" + ps[i].getRecCounty()); System.out.println("ps[i].getRecName()" + ps[i].getRecName()); System.out.println("\r\n\r\n"); } } /// System.out.println("???"+proxy.postalGetDataBack("1000068,1000081,1000087,1000088,1000089,1000090")); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /*? * 1000068,1000081,1000087,1000088,1000089,1000090 ps[i].getAddress()11?1706 ps[i].getContactor() ps[i].getIsFee()0 ps[i].getOrderID()1000033 ps[i].getPhone()13712345678 ps[i].getPrice() ps[i].getSpec()50cm*30cm*10cm ps[i].getCity() ps[i].getPostCode()361006 ps[i].getCounty() ps[i].getProvince()?? ps[i].getRecAddress()?168??6 ps[i].getRecCity()? ps[i].getRecTel()0591-88019098 ps[i].getRecProvince()?? ps[i].getRecCounty() ps[i].getRecName() ps[i].getAddress()???168? ps[i].getContactor()? ps[i].getIsFee()0 ps[i].getOrderID()1000036 ps[i].getPhone()13612345678 ps[i].getPrice() ps[i].getSpec()50cm*60cm*10cm ps[i].getCity()? ps[i].getPostCode()350003 ps[i].getCounty() ps[i].getProvince()?? ps[i].getRecAddress()?168??6 ps[i].getRecCity()? ps[i].getRecTel()0591-88019098 ps[i].getRecProvince()?? ps[i].getRecCounty() ps[i].getRecName() */ }