package com.mosty.qwzx.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.model.entity.qwzx.TbQwJjr;
import com.mosty.base.model.query.qwzx.TbQwJjrQuery;
import com.mosty.base.utils.UUIDGenerator;
import com.mosty.qwzx.mapper.TbQwJjrMapper;
import com.mosty.qwzx.service.TbQwJjrService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class TbQwJjrServiceImpl extends ServiceImpl<TbQwJjrMapper, TbQwJjr>
        implements TbQwJjrService {

    @Override
    public void add(TbQwJjr jjr) {
        jjr.setId(UUIDGenerator.getUUID());
        jjr.setXtSjly("1");
        this.baseMapper.insert(jjr);
    }

    @Override
    public void update(TbQwJjr jjr) {
        this.baseMapper.updateById(jjr);
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (ids.size() > 0) {
            this.baseMapper.deleteBatch(ids);
        }
    }

    @Override
    public void deleteByIds(String id) {
        List<String> list = new ArrayList<String>() {{
            this.add(id);
        }};
        this.baseMapper.deleteBatch(list);
    }

    @Override
    public IPage<TbQwJjr> getPageList(TbQwJjrQuery dto) {
        return this.baseMapper.selectPage(
                new Page<>(dto.getPageCurrent(), dto.getPageSize()),
                new LambdaQueryWrapper<TbQwJjr>()
                        .eq(StringUtils.isNotBlank(dto.getRqlx()), TbQwJjr::getRqlx, dto.getRqlx())
                        .like(StringUtils.isNotBlank(dto.getJjrmc()), TbQwJjr::getJjrmc, dto.getJjrmc())
                        .eq(dto.getJjrq() != null, TbQwJjr::getJjrq, dto.getJjrq())
                        .orderByDesc(TbQwJjr::getJjrq)
        );
    }
}
