package com.ics.admin.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ics.admin.domain.PolicyBanner;
import com.ics.admin.mapper.PolicyBannerMapper;
import com.ics.admin.service.IPolicyBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 政策bannerService业务层处理
 *
 * @author ics
 * @date 2021-03-23
 */
@Service
public class PolicyBannerServiceImpl extends ServiceImpl<PolicyBannerMapper, PolicyBanner> implements IPolicyBannerService {
    @Autowired
    private PolicyBannerMapper policyBannerMapper;

    /**
     * 查询政策banner
     *
     * @param id 政策bannerID
     * @return 政策banner
     */
    @Override
    public PolicyBanner selectPolicyBannerById(Long id) {
        return policyBannerMapper.selectById(id);
    }

    /**
     * 查询政策banner列表
     *
     * @param policyBanner 政策banner
     * @return 政策banner
     */
    @Override
    public List<PolicyBanner> selectPolicyBannerList(PolicyBanner policyBanner) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (policyBanner.getIsMarketable() != null) {
            queryWrapper.eq("is_marketable", policyBanner.getIsMarketable());
        }
        return policyBannerMapper.selectList(queryWrapper);
    }

    /**
     * 新增政策banner
     *
     * @param policyBanner 政策banner
     * @return 结果
     */
    @Override
    public int insertPolicyBanner(PolicyBanner policyBanner) {
        policyBanner.setIsMarketable(false);
        return policyBannerMapper.insert(policyBanner);
    }

    /**
     * 修改政策banner
     *
     * @param policyBanner 政策banner
     * @return 结果
     */
    @Override
    public int updatePolicyBanner(PolicyBanner policyBanner) {
        return policyBannerMapper.updateById(policyBanner);
    }

    /**
     * 删除政策banner对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePolicyBannerByIds(String ids) {
        String[] idsArray = StrUtil.split(ids,",");
        return policyBannerMapper.deleteBatchIds(CollUtil.toList(idsArray));
    }

    /**
     * 删除政策banner信息
     *
     * @param id 政策bannerID
     * @return 结果
     */
    @Override
    public int deletePolicyBannerById(Long id) {
        return policyBannerMapper.deleteById(id);
    }


}
