package com.goafanti.member.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.goafanti.common.dao.MemberGradeMapper;
import com.goafanti.common.model.MemberOrder;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.member.bo.MemberGrade;

@Service
public class MemberGradeService {
	@Autowired
	private MemberGradeMapper memberGradeMapper;

	public List<MemberGrade> selectMemberGrade() {
		return memberGradeMapper.selectMemberGrade();
	}

	public int delGrade(int id) {
		return memberGradeMapper.delGrade(id);
	}

	public int selectRank(MemberGrade me) {
		return memberGradeMapper.selectRank(me);
	}

	public int addGradeName(MemberGrade me) {
		return memberGradeMapper.addGradeName(me);
	}

	public int addBusinessAndCost(MemberGrade me) {
		return memberGradeMapper.addBusinessAndCost(me);
	}

	public List<MemberOrder> selectMemberOrder(Map<String, Object> map) {
		return memberGradeMapper.selectMemberOrder(map);
	}

	public List<MemberOrder> selectMemberOrderBa(Map<String, Object> map) {
		return memberGradeMapper.selectMemberOrderBa(map);
	}

	public int countMemberOrder(String userId) {
		return memberGradeMapper.countMemberOrder(userId);
	}

	public int addBasicsMemberOrder(MemberOrder mo) {
		return memberGradeMapper.addBasicsMemberOrder(mo);
	}

	public int countMemberOrderWhere(Map<String, Object> map) {
		return memberGradeMapper.countMemberOrderWhere(map);
	}

	public int delMemberOrder(Long id) {
		Map<String, Object> map = new HashMap<>();
		map.put("id", id);
		if (TokenManager.getAdminToken() == null) {
			map.put("uid", TokenManager.getUserId());
		}
		return memberGradeMapper.delMemberOrder(map);
	}

	public JSONObject selectMemberBusiness(int memberRank) {
		String b = memberGradeMapper.selectMemberBusiness(memberRank);
		return b == null ? null : JSON.parseObject(b);
	}

}
