package com.storlead.framework.mybatis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.storlead.framework.common.constant.CommonConstant;
import com.storlead.framework.mybatis.entity.SysBaseField;
import com.storlead.framework.mybatis.mapper.MyBaseMapper;
import com.storlead.framework.mybatis.service.MyBaseService;
import org.springframework.util.CollectionUtils;

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


/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-04-02 15:31
 */
public class MyBaseServiceImpl<M extends MyBaseMapper<T>, T extends SysBaseField> extends ServiceImpl<M, T> implements MyBaseService<T> {
    @Override
    public Boolean lgDelete(Long id) {
        if (Objects.isNull(id)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        updateWrapper.set("is_delete", CommonConstant.DEL_FLAG_1);
        return this.update(updateWrapper);
    }

    @Override
    public Boolean lgDelete(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id",ids);
        updateWrapper.set("is_delete", CommonConstant.DEL_FLAG_1);
        return this.update(updateWrapper);
    }

    @Override
    public List<T> listByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return null;
        }
        QueryWrapper query = new QueryWrapper<>();
        query.in("id",ids);
        return this.list(query);
    }

    @Override
    public Boolean enable(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id",ids);
        updateWrapper.set("enable", CommonConstant.DEL_FLAG_1);
        return this.update(updateWrapper);
    }

    @Override
    public Boolean enable(Long id) {
        if (Objects.isNull(id)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        updateWrapper.set("enable", CommonConstant.DEL_FLAG_1);
        return this.update(updateWrapper);
    }

    @Override
    public Boolean disable(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",ids);
        updateWrapper.set("enable", CommonConstant.DEL_FLAG_0);
        return this.update(updateWrapper);
    }

    @Override
    public Boolean disable(Long id) {
        if (Objects.isNull(id)) {
            return false;
        }
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        updateWrapper.set("enable", CommonConstant.DEL_FLAG_0);
        return this.update(updateWrapper);
    }
}
