package cn.superdesk.uniorder.service.operation.impl;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.operation.ExcelImportLog;
import cn.superdesk.uniorder.dao.entity.operation.ExcelImportLogExample;
import cn.superdesk.uniorder.dao.mapper.operation.ExcelImportLogMapper;
import cn.superdesk.uniorder.dto.param.operation.ExcelImportLogQueryCriteria;
import cn.superdesk.uniorder.service.operation.ExcelImportLogService;
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: Excel导入日志
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-08-23 10:38:52
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-08-23 10:38:52
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class ExcelImportLogServiceImpl implements ExcelImportLogService {

	@Autowired
	private ExcelImportLogMapper excelImportLogMapper;


	/****************************************** extends BaseService 部分 start ******************************************/

	@Override
	public int insertSelective(ExcelImportLog entity) {
		return excelImportLogMapper.insertSelective(entity);
	}

	@Override
	public int updateByPrimaryKeySelective(ExcelImportLog entity) {
		return excelImportLogMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public void deleteObj(Long id) {
	}

	@Override
	public ExcelImportLog findById(Long id) {
		return excelImportLogMapper.selectByPrimaryKey(id);
	}

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

	@Override
	public List<ExcelImportLog> findAll(Map<String, Object> queryMap) {
		return null;
	}

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


	public void addExcelImportLog(ExcelImportLog entity) {
		excelImportLogMapper.insertSelective(entity);
	}

	public void updateExcelImportLog(ExcelImportLog entity) {
		ExcelImportLog originEntity = excelImportLogMapper.selectByPrimaryKey(entity.getId());
//		AssertUtil.notNull(originEntity);
		AnBeanUtils.copy(entity, originEntity);
		excelImportLogMapper.updateByPrimaryKey(originEntity);
	}

	public void deleteExcelImportLog(Long id) {
		excelImportLogMapper.deleteByPrimaryKey(id);
	}

	public ExcelImportLog findExcelImportLogById(Long id) {
		ExcelImportLog entity = excelImportLogMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);
		return entity;
	}

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

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

		// TODO 喜欢用Map 还是 Bean 自己喜欢... 后期添加 转 ExcelImportLogExample.Criteria
		// ExcelImportLog excelImportLogConditions = AnBeanUtils.mapToBean(conditions,ExcelImportLog.class);

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

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

	}

	public R<List<ExcelImportLog>> pageQueryGenericParam(ExcelImportLogQueryCriteria queryCriteria) {

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

		// TODO 添加条件... 后期添加 queryCriteria 转 ExcelImportLogExample.Criteria

		PageHelper.startPage(queryCriteria.getPageNumber(), queryCriteria.getPageSize());
		List<ExcelImportLog>     resultList = excelImportLogMapper.selectByExample(example);
		PageInfo<ExcelImportLog> page       = new PageInfo<ExcelImportLog>(resultList);
		PageHelper.clearPage();

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

	}

}