package com.sptg.permissions.biz.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.permissions.api.dto.DictDto;
import com.sptg.permissions.api.entity.Dict;
import com.sptg.permissions.biz.mapper.DictMapper;
import com.sptg.permissions.biz.service.DictServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * title: DictServiceImpl
 * package: com.sptg.permissions.biz.security.impl
 * description: 全国省市区街道-服务层实现类
 *
 *
 *
 */
@Service
@CacheConfig(cacheNames = DictServiceInterface.SUB_DICT_CACHE_NAME)
@RequiredArgsConstructor
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictServiceInterface {


    @Override
    public List<Dict> getSubList(Serializable pid) {
        return null;
    }

    @Override
    public Dict selectByCode(Serializable code) {
        return null;
    }

    @Override
    public List<Dict> selectAll() {
        return null;
    }

    @Override
    public List<Dict> selectList(Wrapper<Dict> wrapper) {
        wrapper.notIn("i_status", OperationConstant.MINUS_ONE);
//        wrapper.eq("l_pid", OperationConstant.ZERO);
        return super.selectList(wrapper);
    }

    @Override
    public ResultBean<Boolean> insertDict(DictDto dictDto) {
        return new ResultBean<>(ResultEnum.SUCCESS, this.insert(dictDto));
    }

    @Override
    public ResultBean<Boolean> updateDict(DictDto dictDto) {
        return new ResultBean<>(ResultEnum.SUCCESS, this.updateById(dictDto));
    }

    @Override
    public ResultBean<Dict> getByCode(String code) {
        Wrapper<Dict> wrapper = new EntityWrapper<>();
        wrapper.eq("s_code",code);
        wrapper.notIn("i_status", OperationConstant.MINUS_ONE);
        wrapper.notIn("l_pid", OperationConstant.ZERO);
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectList(wrapper));
    }

}
