package com.sky.ioc.service.scene.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sky.ioc.entity.domain.scene.Strategy;
import com.sky.ioc.mapper.scene.StrategyMapper;
import com.sky.ioc.service.scene.StrategyService;
import com.sky.ioc.tool.ReturnMsg;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements StrategyService {

    @Autowired
    StrategyMapper strategyMapper;

    @Override
    public ReturnMsg addStrategy(Strategy strategy) {
        strategyMapper.insert(strategy);
        return ReturnMsg.ok();
    }

    @Override
    public ReturnMsg delStrategyById(Integer id) {
        if(id==null){
            return ReturnMsg.fail("参数错误");
        }else{
            strategyMapper.delById(id);
            return ReturnMsg.ok();
        }

    }

    @Override
    public ReturnMsg delBatchById(List<Integer> ids) {
        if(ids.size()==0||ids==null){
            return ReturnMsg.fail("参数错误");
        }else{
            strategyMapper.batchDelByIds(ids);
            return ReturnMsg.ok();
        }

    }

    @Override
    public ReturnMsg editStrategy(Strategy strategy) {
        if(strategy.getId()==null){
            return ReturnMsg.fail("参数错误");
        }else{
            strategyMapper.updateById(strategy);
            return ReturnMsg.ok();
        }

    }

    @Override
    public ReturnMsg getListByNameAndType(Integer type,Integer status,String name) {
        if(name!=null&&!name.isEmpty()){
            name = "%"+name+"%";
        }
        List<Strategy> lists = strategyMapper.getListByNameAndTypeAndStatus(type,status,name);
        return ReturnMsg.ok(lists);
    }
}
