package com.fjhx.victoriatourist.service.blessing.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.victoriatourist.entity.blessing.dto.BlessingLanguageDto;
import com.fjhx.victoriatourist.entity.blessing.dto.BlessingLanguageSelectDto;
import com.fjhx.victoriatourist.entity.blessing.po.BlessingLanguage;
import com.fjhx.victoriatourist.entity.blessing.vo.BlessingLanguageVo;
import com.fjhx.victoriatourist.mapper.blessing.BlessingLanguageMapper;
import com.fjhx.victoriatourist.service.blessing.BlessingLanguageService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.ruoyi.common.utils.wrapper.SqlField;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 祝福语管理 服务实现类
 * </p>
 *
 * @author LQH
 * @since 2023-12-10
 */
@Service
public class BlessingLanguageServiceImpl extends ServiceImpl<BlessingLanguageMapper, BlessingLanguage> implements BlessingLanguageService {

    @Override
    public List<BlessingLanguageVo> getList(BlessingLanguageSelectDto dto) {
        IWrapper<BlessingLanguage> wrapper = getWrapper();
        wrapper.keyword(dto, new SqlField("bl", BlessingLanguage::getBlessingContent));
        wrapper.orderByDesc("bl", BlessingLanguage::getId);
        List<BlessingLanguageVo> list = this.baseMapper.getList(wrapper);
        return list;
    }

    @Override
    public Page<BlessingLanguageVo> getPage(BlessingLanguageSelectDto dto) {
        IWrapper<BlessingLanguage> wrapper = getWrapper();

        if (StringUtils.isNotEmpty(dto.getBlessingType())){
            wrapper.eq("bl", BlessingLanguage::getBlessingType, dto.getBlessingType());
        }
        wrapper.keyword(dto, new SqlField("bl", BlessingLanguage::getBlessingContent));
        wrapper.orderByDesc("bl", BlessingLanguage::getId);
        Page<BlessingLanguageVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public BlessingLanguageVo detail(Long id) {
        BlessingLanguage BlessingLanguage = this.getById(id);
        BlessingLanguageVo result = BeanUtil.toBean(BlessingLanguage, BlessingLanguageVo.class);
        return result;
    }

    @Override
    public void add(BlessingLanguageDto blessingLanguageDto) {
        this.save(blessingLanguageDto);
    }

    @Override
    public void edit(BlessingLanguageDto blessingLanguageDto) {
        this.updateById(blessingLanguageDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
