package com.goafanti.patent.service.impl;

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

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

import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.dao.PatentRegistrationMapper;
import com.goafanti.common.model.PatentRegistration;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.patent.bo.PatentRecieveSendBo;
import com.goafanti.patent.service.PatentRegistrationService;

@Service
public class PatentRegistrationServiceImpl extends BaseMybatisDao<PatentRegistrationMapper>
		implements PatentRegistrationService {
	@Autowired
	private PatentRegistrationMapper patentRegistrationMapper;

	@Override
	public PatentRegistration insert(PatentRegistration patentRegistration) {
		patentRegistrationMapper.insert(patentRegistration);
		return patentRegistration;
	}

	@Override
	public int updateByPrimaryKeySelective(PatentRegistration patentRegistration) {
		return patentRegistrationMapper.updateByPrimaryKeySelective(patentRegistration);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination<PatentRecieveSendBo> getRecieveSendList(Integer pageNo, Integer pageSize) {
		Map<String, Object> params = new HashMap<>();
		
		if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
			params.put("principal", TokenManager.getAdminId());
		}
		

		if (pageNo == null || pageNo < 0) {
			pageNo = 1;
		}

		if (pageSize == null || pageSize < 0) {
			pageSize = 15;
		}
		return (Pagination<PatentRecieveSendBo>) findPage("findRecieveSendList", "findRecieveSendCount", params, pageNo,
				pageSize);
	}

	@Override
	public int updateByPrimaryKey(PatentRegistration patentRegistration) {
		return patentRegistrationMapper.updateByPrimaryKeySelective(patentRegistration);
	}

	@Override
	public PatentRegistration selectByPrimaryKey(String id) {
		return patentRegistrationMapper.selectByPrimaryKey(id);
	}

}
