【仅供内部供应商使用,不提供对外解答和培训】
【仅供内部供应商使用,不提供对外解答和培训】
1.实现一个Entity
import com.fr.schedule.base.entity.output.BaseOutputActionEntity;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
/**
* Created by Zed on 2018/01/09.
*/
@Entity
@Table(name = "fine_output_wx") //注入数据库的表名
@TableAssociation(associated = true)
public class WXEntity extends BaseOutputActionEntity {
@Column(name = "pushContent")
private String pushContent = null;
@Column(name = "pushTitle")
private String pushTitle = null;
//...
//转bean对象
@Override
public WXBean createBean() {
WXBean wxBean = new WXBean();
wxBean.setId(this.getId());
wxBean.setActionName(this.getActionName());
wxBean.setExecuteByUser(this.isExecuteByUser());
wxBean.setRunType(this.getRunType());
wxBean.setPushContent(this.getPushContent());
wxBean.setPushTitle(this.getPushTitle());
return wxBean;
}
public String getPushContent() {
return pushContent;
}
public void setPushContent(String pushContent) {
this.pushContent = pushContent;
}
public String getPushTitle() {
return pushTitle;
}
public void setPushTitle(String pushTitle) {
this.pushTitle = pushTitle;
}
}
2.实现一个bean
import com.fr.base.FRContext;
import com.fr.json.JSONObject;
import com.fr.schedule.base.bean.output.BaseOutputAction;
import com.fr.schedule.base.constant.RunType;
import com.fr.schedule.base.constant.ScheduleConstants;
import java.util.Map;
/**
* Created by Zed on 2018/01/09.
*/
public class WXBean extends BaseOutputAction {
private String pushContent = null;
private String pushTitle = null;
//...
public OutputSMS() {
super();
}
@Override
public boolean willExecuteByUser() {
return true;
}
@Override
public RunType runType() {
return RunType.SEND_WX;
}
//转entity,将bean对象持久化到数据库
@Override
public WXEntity createEntity() {
WXEntity entity = new WXEntity();
//4个父类属性
entity.setId(this.getId());
entity.setActionName(this.getActionName());
entity.setExecuteByUser(this.isExecuteByUser());
entity.setRunType(this.getRunType());
//
entity.setPushContent(this.getPushContent());
entity.setPushTitle(this.getPushTitle());
return entity;
}
public String getPushContent() {
return pushContent;
}
public void setPushContent(String pushContent) {
this.pushContent = pushContent;
}
public String getPushTitle() {
return pushTitle;
}
public void setPushTitle(String pushTitle) {
this.pushTitle = pushTitle;
}
}
3.实现一个handler
import com.fr.schedule.base.bean.output.BaseOutputAction;
import com.fr.schedule.base.constant.OutputActionHandler;
import java.util.Map;
/**
* Created by Zed on 2018/01/09.
*/
public class WXHandler extends OutputActionHandler<WXBean> {
@Override
public void doAction(WXBean action, Map<String, Object> map) throws Exception {
//map里面有taskName(String), outputFile(File[]), currentUsername(String)...
//调用微信接口
//WXManager.getInstance().sendMessage(wxBean.getPushTitle(), wxBean.getPushContent()) //这句瞎写的,不清楚推送微信消息的具体业务代码
}
}
4.注册entity和handler
DBContext.getInstance().addEntityClass(WXEntity.class)
ScheduleTableRelation.getInstance().addClass(WXEntity.class);
OutputActionHandler.registerHandler(new WXHandler(), WXBean.class.getName());
4 Comments
Anonymous
最新的10.0这个BaseOutputActionEntity是final的
ezreal-陈军
10.03之后的版本使用这个 新定时调度扩展outputAction(10.0.3)
Anonymous
最后的注册代码写在哪啊?
ezreal-陈军
2、插件生命周期 这个文档里面有一个生命周期的接口,你在这个afterRun方法里面注册下
public class DemoPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor { @Override public void afterRun(PluginContext pluginContext) { OutputActionHandler.registerHandler(new DemoOutActionHandler(), DemoOutBean.class.getName()); ScheduleOutputActionEntityRegister.getInstance().addClass(DemoOutputEntity.class); } @Override public void beforeStop(PluginContext pluginContext) { } }