package com.unis.base.server.service.impl;


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

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.unis.base.server.dao.TyShougouqiyebeianDao;
import com.unis.base.server.entity.TyShougouqiyebeian;
import com.unis.base.server.entity.TyShougouqiyebeianEVo;
import com.unis.base.server.example.TyShougouqiyebeianExample;
import com.unis.base.server.example.TyShougouqiyebeianExample.Criteria;
import com.unis.base.server.service.TyShougouqiyebeianService;


@Service
public class TyShougouqiyebeianServiceServiceImpl implements TyShougouqiyebeianService {
	
	@Resource
	private TyShougouqiyebeianDao shougouqiyebeianDao;
	


	@Override
	public List<TyShougouqiyebeian> queryByExample(Integer pageNum, Integer pageSize,
			TyShougouqiyebeian shougouqiyebeian) {
		// TODO Auto-generated method stub
		
		TyShougouqiyebeianExample shougouqiyebeianExample = new TyShougouqiyebeianExample();
		Criteria createCriteria = shougouqiyebeianExample.createCriteria();
		if(shougouqiyebeian.getQymc()!= null && shougouqiyebeian.getQymc() != ""){
			createCriteria.andQymcLike("%"+shougouqiyebeian.getQymc()+"%");
		}
		if(shougouqiyebeian.getBarq() != null ){
			createCriteria.andBarqEqualTo(shougouqiyebeian.getBarq());
		}
		if(shougouqiyebeian.getSzxzqy() != null && shougouqiyebeian.getSzxzqy() != ""){
			createCriteria.andSzxzqyEqualTo(shougouqiyebeian.getSzxzqy());
		}
		if(shougouqiyebeian.getCjdw() != null && shougouqiyebeian.getCjdw() != ""){
			createCriteria.andCjdwLike("%"+shougouqiyebeian.getCjdw()+"%");
		}
		if(shougouqiyebeian.getSjzt() != null){
			createCriteria.andSjztEqualTo(shougouqiyebeian.getSjzt());
		}
		shougouqiyebeianExample.setOrderByClause("cjsj desc");
		PageHelper.startPage(pageNum, pageSize);
        List<TyShougouqiyebeian> list = shougouqiyebeianDao.selectByExample(shougouqiyebeianExample);
		return list;
	}



	@Override
	public int save(TyShougouqiyebeian tyShougouqiyebeian) {
		// TODO Auto-generated method stub
		return shougouqiyebeianDao.insertSelective(tyShougouqiyebeian);
	}



	@Override
	public int remove(String id) {
		// TODO Auto-generated method stub
		TyShougouqiyebeianExample shougouqiyebeianExample = new TyShougouqiyebeianExample();
		Criteria createCriteria = shougouqiyebeianExample.createCriteria();
		createCriteria.andIdEqualTo(id);
		return shougouqiyebeianDao.deleteByExample(shougouqiyebeianExample);
	}



	@Override
	public TyShougouqiyebeian getById(String id) {
		// TODO Auto-generated method stub
		TyShougouqiyebeian shougouqiyebeian = new TyShougouqiyebeian();
		if(id != null && id != ""){
			TyShougouqiyebeianExample shougouqiyebeianExample = new TyShougouqiyebeianExample();
			Criteria createCriteria = shougouqiyebeianExample.createCriteria();
			createCriteria.andIdEqualTo(id);
	        List<TyShougouqiyebeian> list = shougouqiyebeianDao.selectByExample(shougouqiyebeianExample);
	        if(list.size()>0){
	        	return list.get(0);
	        }else{
	        	return shougouqiyebeian;
	        }
		}else{
			return shougouqiyebeian;
		}
	}



	@Override
	public int update(TyShougouqiyebeian tyShougouqiyebeian) {
		// TODO Auto-generated method stub
		return shougouqiyebeianDao.updateByPrimaryKeySelective(tyShougouqiyebeian);
	}



	@Override
	//public List<TyShougouqiyebeianEVo> exportByEntityResult(TyShougouqiyebeian shougouqiyebeian) {
	public List<Map<String, Object>> exportByEntityResult(TyShougouqiyebeian shougouqiyebeian) {
		// TODO Auto-generated method stub
		
		TyShougouqiyebeianExample shougouqiyebeianExample = new TyShougouqiyebeianExample();
		Criteria createCriteria = shougouqiyebeianExample.createCriteria();
		if(shougouqiyebeian.getQymc()!= null && shougouqiyebeian.getQymc() != ""){
			createCriteria.andQymcLike("%"+shougouqiyebeian.getQymc()+"%");
		}
		if(shougouqiyebeian.getBarq() != null ){
			createCriteria.andBarqEqualTo(shougouqiyebeian.getBarq());
		}
		if(shougouqiyebeian.getSzxzqy() != null && shougouqiyebeian.getSzxzqy() != ""){
			createCriteria.andSzxzqyEqualTo(shougouqiyebeian.getSzxzqy());
		}
		if(shougouqiyebeian.getCjdw() != null && shougouqiyebeian.getCjdw() != ""){
			createCriteria.andCjdwLike("%"+shougouqiyebeian.getCjdw()+"%");
		}
		if(shougouqiyebeian.getSjzt() != null){
			createCriteria.andSjztEqualTo(shougouqiyebeian.getSjzt());
		}
		return shougouqiyebeianDao.selectByExampleIsList(shougouqiyebeianExample);
	}
	
	
}
