package cn.superdesk.uniorder.service.sys.role.impl;

import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.exception.utils.AssertUtils;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtDataSamplePermission;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtDataSamplePermissionExample;
import cn.superdesk.uniorder.dao.mapper.sys.role.SysRoleExtDataSamplePermissionMapper;
import cn.superdesk.uniorder.service.sys.role.SysRoleExtDataSamplePermissionService;
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
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-08-26 14:15:28
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-08-26 14:15:28
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class SysRoleExtDataSamplePermissionServiceImpl implements SysRoleExtDataSamplePermissionService {

	@Autowired
	private SysRoleExtDataSamplePermissionMapper sysRoleExtDataSamplePermissionMapper;


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

	@Override
	public int insertSelective(SysRoleExtDataSamplePermission entity) {
		return sysRoleExtDataSamplePermissionMapper.insertSelective(entity);
	}

	@Override
	public int updateByPrimaryKeySelective(SysRoleExtDataSamplePermission entity) {
		return sysRoleExtDataSamplePermissionMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public void deleteObj(Long id) {
	}

	@Override
	public SysRoleExtDataSamplePermission findById(Long id) {
		return sysRoleExtDataSamplePermissionMapper.selectByPrimaryKey(id);
	}

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

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

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


	public void addSysRoleExtDataSamplePermission(SysRoleExtDataSamplePermission entity) {
		sysRoleExtDataSamplePermissionMapper.insertSelective(entity);
	}

	public void updateSysRoleExtDataSamplePermission(SysRoleExtDataSamplePermission entity) {
		SysRoleExtDataSamplePermission originEntity = sysRoleExtDataSamplePermissionMapper.selectByPrimaryKey(entity.getId());
		AssertUtils.notNull(originEntity);
		AnBeanUtils.copy(entity, originEntity);
		sysRoleExtDataSamplePermissionMapper.updateByPrimaryKey(originEntity);
	}

	public void deleteSysRoleExtDataSamplePermission(Long id) {
		sysRoleExtDataSamplePermissionMapper.deleteByPrimaryKey(id);
	}

	public SysRoleExtDataSamplePermission findSysRoleExtDataSamplePermissionById(Long id) {
		SysRoleExtDataSamplePermission entity = sysRoleExtDataSamplePermissionMapper.selectByPrimaryKey(id);
		AssertUtils.notNull(entity);
		return entity;
	}

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

		// 样例 保留
//		SysRoleExtDataSamplePermission sysRoleExtDataSamplePermissionConditions = BeanUtils.mapToBean(conditions,SysRoleExtDataSamplePermission.class);

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

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

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

	}

}