package cn.superdesk.uniorder.service.invoice.common.impl;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceTaxRate;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceTaxRateExample;
import cn.superdesk.uniorder.dao.mapper.invoice.common.InvoiceTaxRateMapper;
import cn.superdesk.uniorder.dao.mapper.invoice.common.InvoiceTaxRateMapperEx;
import cn.superdesk.uniorder.service.invoice.common.InvoiceTaxRateService;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


/**
 * @Description: 重构
 * @Author: linjinyu
 * @CreateDate: 2021/7/23 下午4:03
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/7/23 下午4:03
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class InvoiceTaxRateServiceImpl implements InvoiceTaxRateService {


	@Autowired
	private InvoiceTaxRateMapper   invoiceTaxRateMapper;
	@Autowired
	private InvoiceTaxRateMapperEx invoiceTaxRateMapperEx;

	/****************************************** extends BaseService 部分 start ******************************************/
	@Override
	public void addObj(InvoiceTaxRate entity) {
		invoiceTaxRateMapper.insert(entity);
	}

	@Override
	public void updateObj(InvoiceTaxRate entity) {
		invoiceTaxRateMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public void deleteObj(Long id) {
		invoiceTaxRateMapper.deleteByPrimaryKey(id);
	}

	@Override
	public InvoiceTaxRate findById(Long id) {
		return invoiceTaxRateMapper.selectByPrimaryKey(id);
	}

	@Override
	public PageInfo<InvoiceTaxRate> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
		return null;
	}

	@Override
	public List<InvoiceTaxRate> findAll(Map<String, Object> queryMap) {
		return invoiceTaxRateMapperEx.findAll(queryMap);
	}

	/****************************************** extends BaseService 部分   end ******************************************/


	public void addInvoiceTaxRate(InvoiceTaxRate entity) {
		invoiceTaxRateMapper.insertSelective(entity);
	}

	public void updateInvoiceTaxRate(InvoiceTaxRate entity) {
		InvoiceTaxRate originEntity = invoiceTaxRateMapper.selectByPrimaryKey(entity.getId());
//		AssertUtil.notNull(originEntity);
		AnBeanUtils.copy(entity, originEntity);
		invoiceTaxRateMapper.updateByPrimaryKey(originEntity);
	}

	public void deleteInvoiceTaxRate(Long id) {
		invoiceTaxRateMapper.deleteByPrimaryKey(id);
	}

	public InvoiceTaxRate findInvoiceTaxRateById(Long id) {
		InvoiceTaxRate entity = invoiceTaxRateMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);
		return entity;
	}

	public R<List<InvoiceTaxRate>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

		// 样例 保留
//		InvoiceTaxRate invoiceTaxRateConditions = BeanUtils.mapToBean(conditions,InvoiceTaxRate.class);

		InvoiceTaxRateExample          example  = new InvoiceTaxRateExample();
		InvoiceTaxRateExample.Criteria criteria = example.createCriteria();

		PageHelper.startPage(pageNun, pageSize);
		List<InvoiceTaxRate>     resultList = invoiceTaxRateMapper.selectByExample(example);
		PageInfo<InvoiceTaxRate> page       = new PageInfo<InvoiceTaxRate>(resultList);
		PageHelper.clearPage();

		return new R<List<InvoiceTaxRate>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);

	}

}
