package com.goafanti.cognizance.service.impl;

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

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goafanti.cognizance.service.OrgTechProductService;
import com.goafanti.common.dao.OrgTechProductMapper;
import com.goafanti.common.model.OrgTechProduct;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
@Service
public class OrgTechProductServiceImpl extends BaseMybatisDao<OrgTechProductMapper> implements OrgTechProductService {
	@Autowired
	OrgTechProductMapper orgTechProductMapper;

	@SuppressWarnings("unchecked")
	@Override
	public Pagination<OrgTechProduct> listTechProduct(Integer pageNo, Integer pageSize, String uid) {
		Map<String, Object> params = new HashMap<>();
		
		params.put("year", Calendar.getInstance().get(Calendar.YEAR)-1); //上一年
		
		if (!StringUtils.isBlank(uid)){
			params.put("uid", uid);
		}

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

		if (pageSize == null || pageSize < 0) {
			pageSize = 10;
		}
		return (Pagination<OrgTechProduct>) findPage("findOrgTechProductListByPage",
				"findOrgTechProductCount", params, pageNo, pageSize);
	}

	@Override
	public OrgTechProduct insert(OrgTechProduct orgTechProduct) {
		orgTechProductMapper.insert(orgTechProduct);
		return orgTechProduct;
	}

	@Override
	public int updateByPrimaryKeySelective(OrgTechProduct orgTechProduct) {
		return orgTechProductMapper.updateByPrimaryKeySelective(orgTechProduct);
	}

	@Override
	public int deleteByPrimaryKey(List<String> id) {
		return orgTechProductMapper.batchDeleteByPrimaryKey(id);
	}

	@Override
	public OrgTechProduct selectByPrimaryKey(String id) {
		return orgTechProductMapper.selectByPrimaryKey(id);
	}

	@Override
	public OrgTechProduct findBySerialNumberAndUid(String serialNumber, String uid) {
		return orgTechProductMapper.findBySerialNumberAndUid(serialNumber, uid);
	}
}
