package com.mosty.base.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.manager.mapper.TbJcglXfclSbMapper;
import com.mosty.base.manager.service.TbJcglXfclSbService;
import com.mosty.base.model.entity.jcgl.TbJcglXfclSb;
import com.mosty.base.model.query.jcgl.TbJcglXfclSbQuery;
import com.mosty.base.utils.UUIDGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbJcglXfclSbServiceImpl extends ServiceImpl<TbJcglXfclSbMapper, TbJcglXfclSb>
        implements TbJcglXfclSbService {
    @Override
    public int addEntity(TbJcglXfclSb dto) {
        dto.setId(UUIDGenerator.getUUID());
        return this.baseMapper.insert(dto);
    }

    @Override
    public int editEntity(TbJcglXfclSb dto) {
        return this.baseMapper.updateById(dto);
    }

    @Override
    public Integer delEntity(List<String> ids) {
        return this.baseMapper.deleteBatchIds(ids);
    }

    @Override
    public TbJcglXfclSb getInfo(String id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public Integer deleteById(String id) {
        return this.baseMapper.deleteById(id);
    }

    @Override
    public IPage<TbJcglXfclSb> getXfclSbPage(TbJcglXfclSbQuery dto) {
        IPage<TbJcglXfclSb> page = new Page<>(dto.getPageCurrent(), dto.getPageSize());
        return this.baseMapper.selectPage(page, new LambdaQueryWrapper<TbJcglXfclSb>()
                .like(StringUtils.isNoneBlank(dto.getSbbh()), TbJcglXfclSb::getSbbh, dto.getSbbh())
                .like(StringUtils.isNoneBlank(dto.getSbmc()), TbJcglXfclSb::getSbmc, dto.getSbmc())
                .eq(StringUtils.isNoneBlank(dto.getSbFl()), TbJcglXfclSb::getSbFl, dto.getSbFl())
                .eq(StringUtils.isNoneBlank(dto.getSbPp()), TbJcglXfclSb::getSbPp, dto.getSbPp())
                .eq(StringUtils.isNoneBlank(dto.getAzwz()), TbJcglXfclSb::getAzwz, dto.getAzwz())
                .like(StringUtils.isNoneBlank(dto.getSbIpv4()), TbJcglXfclSb::getSbIpv4, dto.getSbIpv4())
                .like(StringUtils.isNoneBlank(dto.getSbIpv6()), TbJcglXfclSb::getSbIpv6, dto.getSbIpv6())
                .eq(StringUtils.isNoneBlank(dto.getSfsp()), TbJcglXfclSb::getSfsp, dto.getSfsp())
                .eq(StringUtils.isNoneBlank(dto.getCId()), TbJcglXfclSb::getCId, dto.getCId())
        );
    }

    @Override
    public List<TbJcglXfclSb> getXfclSbList(TbJcglXfclSbQuery dto) {
        return this.baseMapper.selectList(new LambdaQueryWrapper<TbJcglXfclSb>()
                .like(StringUtils.isNoneBlank(dto.getSbbh()), TbJcglXfclSb::getSbbh, dto.getSbbh())
                .like(StringUtils.isNoneBlank(dto.getSbmc()), TbJcglXfclSb::getSbmc, dto.getSbmc())
                .eq(StringUtils.isNoneBlank(dto.getSbFl()), TbJcglXfclSb::getSbFl, dto.getSbFl())
                .eq(StringUtils.isNoneBlank(dto.getSbPp()), TbJcglXfclSb::getSbPp, dto.getSbPp())
                .eq(StringUtils.isNoneBlank(dto.getAzwz()), TbJcglXfclSb::getAzwz, dto.getAzwz())
                .like(StringUtils.isNoneBlank(dto.getSbIpv4()), TbJcglXfclSb::getSbIpv4, dto.getSbIpv4())
                .like(StringUtils.isNoneBlank(dto.getSbIpv6()), TbJcglXfclSb::getSbIpv6, dto.getSbIpv6())
                .eq(StringUtils.isNoneBlank(dto.getSfsp()), TbJcglXfclSb::getSfsp, dto.getSfsp())
                .eq(StringUtils.isNoneBlank(dto.getCId()), TbJcglXfclSb::getCId, dto.getCId())
        );
    }

}
