package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.MallPermission;
import com.iformall.mapper.MallPermissionMapper;
import com.iformall.service.MallPermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallPermissionServiceImpl implements MallPermissionService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    MallPermissionMapper mallPermissionMapper;


    @Override
    public PageInfo<MallPermission> listAsPage(MallPermission record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> mallPermissionMapper.findList(record));
    }

    @Override
    public MallPermission getById(Long id) {
        return mallPermissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(MallPermission record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
            record.setId(idWorker.nextId());
            mallPermissionMapper.insertSelective(record);
        } else {
            mallPermissionMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public void deleteById(Long id) {
        mallPermissionMapper.deleteByPrimaryKey(id);
    }
    
    @Override
    public List<MallPermission> findPermissionByRoleId(Long roleId) {
        return mallPermissionMapper.findPermissionByRoleId(roleId);
    }

    @Override
    public List<MallPermission> findPermissionByRoleIds(List<Long> roleIds) {
        return mallPermissionMapper.findPermissionByRoleIds(roleIds);
    }
    
    
    
    
    
    
    
}
