package cn.hmsoft.weixin.request;

import cn.hmsoft.application.SpringHelper;
import cn.hmsoft.weixin.data.model.WxTag;
import cn.hmsoft.weixin.entity.request.TagUpdateRequestJson;
import cn.hmsoft.weixin.entity.response.WxResponseJson;

/*******************************
 * @note 更新一个标签
 * @author revisit@126.com
 * @Company: www.hmsoft.cn
 * @create 2017-05-09 00:52:18
 * @version 4.0.0
 */
public class TagUpdateRequest extends AbstractRequest<WxResponseJson, WxResponseJson, TagUpdateRequestJson> {

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

	public TagUpdateRequest(WxTag tag) {
		this.requestEntity = new TagUpdateRequestJson();
		TagUpdateRequestJson.Tag tg = requestEntity.new Tag();
		tg.setName(tag.getTag_name());
		tg.setId(tag.getTag_id());
		requestEntity.setTag(tg);

	}

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

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