package cn.hmsoft.weixin.request;

import java.time.LocalDateTime;

import cn.hmsoft.application.SpringHelper;
import cn.hmsoft.weixin.data.model.WxTag;
import cn.hmsoft.weixin.entity.request.TagCreateRequestJson;
import cn.hmsoft.weixin.entity.response.TagCreateResponseJson;

/***********************************
 * 
 * @note 创建一个标签 
 * @author revisit@126.com
 * @Company: www.hmsoft.cn
 * @create 2017-05-09 00:49:48
 * @version 4.0.0
 */
public class TagCreateRequest extends AbstractRequest<TagCreateResponseJson, WxTag, TagCreateRequestJson> {

	private final static String url = "https://api.weixin.qq.com/cgi-bin/tags/create?";

	public TagCreateRequest(WxTag tag) {
		this.requestEntity = new TagCreateRequestJson();
		TagCreateRequestJson.Tag tg = requestEntity.new Tag();
		tg.setName(tag.getTag_name());
		requestEntity.setTag(tg);

	}

	@Override
	protected String makeUrl() {
		this.method = "POST";
		return url + "access_token=" + this.wxDefine.getApp_accesstoken();
	}

	@Override
	public void processBusiness() {
		this.returnEntity = new WxTag();
		this.returnEntity.setCreate_time(LocalDateTime.now());
		this.returnEntity.setTag_id(this.jsonEntity.getTag().getId());
		this.returnEntity.setWx_id(this.wxDefine.getWx_id());
		this.returnEntity.setTag_name(this.jsonEntity.getTag().getName());
		if (this.jsonEntity.getErrcode() == 0)
			SpringHelper.AppGobalDao.insert(this.returnEntity);
	}

}
