package cn.hmsoft.hmplatform.wxtoken.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hmsoft.frame.util.FrameAssertUtil;
import cn.hmsoft.hmplatform.wxtoken.data.dao.PWxDefineDao;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxDefine;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxDeploy;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxDeployLog;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxTokenNotice;
import cn.hmsoft.hmplatform.wxtoken.data.model.PWxTokenRequest;

@Service
public class PlatformTokenDefineService {
	@Autowired
	private PWxDefineDao daoDefine;

	public void checkValues(PWxDefine define) {
		FrameAssertUtil.isNotEmpty(define.getApp_id(), "app_id不允许为空");
		FrameAssertUtil.isNotEmpty(define.getApp_status(), "公众号状态不允许为空");

	}

	public void addDefine(PWxDefine define) {
		this.checkValues(define);
		this.daoDefine.insert(define);
	}

	public void editDefine(PWxDefine define) {
		this.checkValues(define);
		PWxDefine tr2 = this.daoDefine.find("app_id", define.getApp_id());
		FrameAssertUtil.isNotNull(tr2, "该app_id" + tr2.getApp_id() + "已经存在，请检查");
		this.daoDefine.update(define);
	}

	public void deleteDefine(int token_id) {
		this.daoDefine.delete(PWxDefine.class, token_id);
		this.daoDefine.delete(PWxDeploy.class, "token_id", token_id);
		this.daoDefine.delete(PWxDeployLog.class, "token_id", token_id);
		this.daoDefine.delete(PWxTokenRequest.class, "token_id", token_id);
		this.daoDefine.delete(PWxTokenNotice.class, "token_id", token_id);
	}

}
