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

import cn.superdesk.uniorder.common.exception.utils.AssertUtils;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtData;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleExtDataExample;
import cn.superdesk.uniorder.dao.mapper.sys.role.SysRoleExtDataMapper;
import cn.superdesk.uniorder.service.sys.role.SysRoleExtDataService;
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 SysRoleExtDataServiceImpl implements SysRoleExtDataService {

    @Autowired
    private SysRoleExtDataMapper sysRoleExtDataMapper;


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

    @Override
    public int insertSelective(SysRoleExtData entity) {
        return sysRoleExtDataMapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(SysRoleExtData entity) {
        return sysRoleExtDataMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    @Override
    public SysRoleExtData findById(Long id) {
        return sysRoleExtDataMapper.selectByPrimaryKey(id);
    }

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

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

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


    public void addSysRoleExtData(SysRoleExtData entity) {
        sysRoleExtDataMapper.insertSelective(entity);
    }

    public void updateSysRoleExtData(SysRoleExtData entity) {
        SysRoleExtData originEntity = sysRoleExtDataMapper.selectByPrimaryKey(entity.getId());
        AssertUtils.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);
        sysRoleExtDataMapper.updateByPrimaryKey(originEntity);
    }

    public void deleteSysRoleExtData(Long id) {
        sysRoleExtDataMapper.deleteByPrimaryKey(id);
    }

    public SysRoleExtData findSysRoleExtDataById(Long id) {
        SysRoleExtData entity = sysRoleExtDataMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);
        return entity;
    }

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

        // 样例 保留
//		SysRoleExtData sysRoleExtDataConditions = BeanUtils.mapToBean(conditions,SysRoleExtData.class);

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


        Object searchKeyWord = conditions.get("searchKeyWord");
        if (null != searchKeyWord && StringUtils.isNotBlank(String.valueOf(searchKeyWord))) {
            criteria
                    .andNameLike("%" + String.valueOf(searchKeyWord) + "%");
//					.andRemarkLike()

        }

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

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

    }

}