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

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

1.实现一个Entity

Code Block
languagejava
themeMidnight
titleWXEntity
linenumberstrue
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

Code Block
languagejava
themeMidnight
titleWXBean
linenumberstrue
 
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

Code Block
languagejava
themeMidnight
titleWXHandler
linenumberstrue
 
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());