今天心情不错,800万的数据终于按照老大们的要求导成Txt文件了,爽.
Python做文件处理还真是爽,今天用Python写了一个循环建目录,省了我不少点击鼠标的动作.
又弄个一个把所有文件的"/n"换成"/r/n",几句话就搞定了,速度还非常快,这方面就是比Java爽.
晚上回家闲的没事,看了一个设计模式的书,再结合要做的东东,写了一个小实践,只主是用Template模式,不知道用的对不对.
这里是源码:
1.一个Bean,这个只要是一个存入手机号的Bean,我弄成Hibernate的POJO了....
public class SmsCustom {
String cid;//短信用户Id
String mobile;//手机号
/**
* @return Returns the cid.
*/
public String getCid() {
return cid;
}
/**
* @param cid The cid to set.
*/
public void setCid(String cid) {
this.cid = cid;
}
/**
* @return Returns the mobile.
*/
public String getMobile() {
return mobile;
}
/**
* @param mobile The mobile to set.
*/
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
2.第二个Bean,这个是短信下成功后写MT下行日志的Bean
public class MTLog {
private String content;//短信内容
private SmsCustom send_cid;//短信用户Bean
private String rec_mobile;//接收手机号
private int feeCode;//收费金额
private Date send_time;//发送时间
public Date getSend_time() {
return send_time;
}
/**
* @return Returns the content.
*/
public String getContent() {
return content;
}
/**
* @return Returns the feeCode.
*/
public int getFeeCode() {
return feeCode;
}
/**
* @return Returns the rec_mobile.
*/
public String getRec_mobile() {
return rec_mobile;
}
/**
* @return Returns the send_cid.
*/
public SmsCustom getSend_cid() {
return send_cid;
}
/**
* @return Returns the send_time.
*/
/**
* @param content The content to set.
*/
public void setContent(String content) {
this.content = content;
}
/**
* @param feeCode The feeCode to set.
*/
public void setFeeCode(int feeCode) {
this.feeCode = feeCode;
}
/**
* @param rec_mobile The rec_mobile to set.
*/
public void setRec_mobile(String rec_mobile) {
this.rec_mobile = rec_mobile;
}
/**
* @param send_cid The send_cid to set.
*/
public void setSend_cid(SmsCustom send_cid) {
this.send_cid = send_cid;
}
/**
* @param send_time The send_time to set.
*/
public void setSend_time(Date send_time) {
this.send_time = send_time;
}
}
3.Template抽象类 ,呵,不用解释,看看吧
public abstract class SendSms {
public void run(){
SmsCustom sc=checkMobileAndAddSmsCustomIfNotExist(getMobile());//检查是否为短信用户
System.out.println("调入无线CGI接口发送短信");//发送短信
// TODO 调用无线CGI接口发送短信,并接收发送报告,如果成功才添加MT日志
MTLog mtLog=new MTLog();//建立MT下行Bean
mtLog.setContent(getContent());
mtLog.setSend_cid(sc);
mtLog.setRec_mobile(getRec_mobile());
mtLog.setFeeCode(getFeeCode());
mtLog.setSend_time(getSend_time());
System.out.println("向MTLOG表插入一条");//写数据库
System.out.println(mtLog.getSend_cid().getMobile()+"在"+mtLog.getSend_time()+"给"+mtLog.getRec_mobile()+"发送短信,内容为"+mtLog.getContent()+"花费了"+mtLog.getFeeCode());
// mtldao.addMtLong(mtLog);
}
/**
* 检查传进来的手机(param)是否为短信用户,如果不是就自动加为短信用户,并返加短信用户Bean,如果是就直接获得相应的短信用户Bean
* @param mobile
* @return
*/
protected abstract SmsCustom checkMobileAndAddSmsCustomIfNotExist(String mobile);
protected abstract String getMobile();
protected abstract String getContent();
protected abstract String getRec_mobile();
protected abstract int getFeeCode();
protected abstract Date getSend_time();
}
4.Template实现类
public class SendSmsTemplateMethod extends SendSms {
private String send_mobile;
private String content;
private SmsCustom send_cid;
private String rec_mobile;
private int feeCode;
private Date send_time;
public static void main(String[] args) throws Exception{
SendSmsTemplateMethod t=new SendSmsTemplateMethod();
t.send_mobile="12345678901";
t.content="发短信呀,发短信";
// t.send_cid="10000";
t.rec_mobile="11111111111";
t.feeCode=0;
t.send_time=new Date();
t.run();
}
/* (non-Javadoc)
* @see AddMTLog#getContent()
*/
protected String getContent() {
return this.content;
}
/* (non-Javadoc)
* @see AddMTLog#getRec_mobile()
*/
protected String getRec_mobile() {
return this.rec_mobile;
}
/* (non-Javadoc)
* @see AddMTLog#getFeeCode()
*/
protected int getFeeCode() {
return this.feeCode;
}
/* (non-Javadoc)
* @see AddMTLog#getSend_time()
*/
protected Date getSend_time() {
return this.send_time;
}
/* (non-Javadoc)
* @see AddMTLog#addSmsCustom()
*/
protected SmsCustom addSmsCustom(String mobile) {
SmsCustom sc=new SmsCustom();
sc.setCid("2");
sc.setMobile(mobile);
System.out.println("增加一个短信用户");
return sc;
}
/* (non-Javadoc)
* @see AddMTLog#checkMobileAndAddSmsCustomIfNotExist(java.lang.String)
*/
protected SmsCustom checkMobileAndAddSmsCustomIfNotExist(String mobile) {
SmsCustom sc=null;
// SmsCustom sc=new SmsCustom();
// sc.setCid("1");
// sc.setMobile("12345678901");
if(sc==null){
sc=addSmsCustom(mobile);
}
return sc;
}
/* (non-Javadoc)
* @see AddMTLog#getMobile()
*/
protected String getMobile() {
return this.send_mobile;
}
}
2004-23-17分