【仅供内部供应商使用,不提供对外解答和培训】

Page tree

【仅供内部供应商使用,不提供对外解答和培训】

Skip to end of metadata
Go to start of metadata

1.实现一个Entity

WXEntity
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

WXBean
 
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

WXHandler
 
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());
 
  • No labels

4 Comments

  1. Anonymous

    最新的10.0这个BaseOutputActionEntity是final的

  2. Anonymous

    最后的注册代码写在哪啊?

    1. 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) {
      
          }
      }