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.SysRoleExtDataSample;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtDataSampleExample;
import cn.superdesk.uniorder.dao.mapper.sys.role.SysRoleExtDataSampleMapper;
import cn.superdesk.uniorder.service.sys.role.SysRoleExtDataSampleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
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 SysRoleExtDataSampleServiceImpl implements SysRoleExtDataSampleService {

	@Autowired
	private SysRoleExtDataSampleMapper sysRoleExtDataSampleMapper;


	/****************************************** extends BaseService 部分 start ******************************************/
	@Override
	public int insertSelective(SysRoleExtDataSample entity) {
		return sysRoleExtDataSampleMapper.insertSelective(entity);
	}

	@Override
	public int updateByPrimaryKeySelective(SysRoleExtDataSample entity) {
		return sysRoleExtDataSampleMapper.updateByPrimaryKeySelective(entity);
	}

	@Override
	public void deleteObj(Long id) {
	}

	@Override
	public SysRoleExtDataSample findById(Long id) {
		return sysRoleExtDataSampleMapper.selectByPrimaryKey(id);
	}

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

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

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


	public void addSysRoleExtDataSample(SysRoleExtDataSample entity) {
		sysRoleExtDataSampleMapper.insertSelective(entity);
	}

	public void updateSysRoleExtDataSample(SysRoleExtDataSample entity) {
		SysRoleExtDataSample originEntity = sysRoleExtDataSampleMapper.selectByPrimaryKey(entity.getId());
		AssertUtils.notNull(originEntity);
		AnBeanUtils.copy(entity, originEntity);
		sysRoleExtDataSampleMapper.updateByPrimaryKey(originEntity);
	}

	public void deleteSysRoleExtDataSample(Long id) {
		sysRoleExtDataSampleMapper.deleteByPrimaryKey(id);
	}

	public SysRoleExtDataSample findSysRoleExtDataSampleById(Long id) {
		SysRoleExtDataSample entity = sysRoleExtDataSampleMapper.selectByPrimaryKey(id);
		AssertUtils.notNull(entity);
		return entity;
	}

	@Override
	public List<SysRoleExtDataSample> findSysRoleExtDataSampleBySysRoleExtDataId(List<Long> ids) {

		SysRoleExtDataSampleExample example = new SysRoleExtDataSampleExample();
		example.createCriteria()
				.andIdIn(ids);

		List<SysRoleExtDataSample> result = sysRoleExtDataSampleMapper.selectByExample(example);

		return result;

	}

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

		// 样例 保留
//		SysRoleExtDataSample sysRoleExtDataSampleConditions = BeanUtils.mapToBean(conditions,SysRoleExtDataSample.class);

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


		// outOrgId
		// outOrgName

		Object outOrgId   = conditions.get("outOrgId");
		Object outOrgName = conditions.get("outOrgName");

		if(null != outOrgId && StringUtils.isNotBlank(String.valueOf(outOrgId))){
			criteria.andOutOrgIdEqualTo(Long.valueOf(String.valueOf(outOrgId)));
		}

		if(null != outOrgName){
//			criteria.andOutOrgNameEqualTo(String.valueOf(outOrgName));
		}





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


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

	}

}