package com.fjhx.service.qa.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.qa.QaInfo;
import com.fjhx.mapper.qa.QaInfoMapper;
import com.fjhx.params.qa.QaInfoVo;
import com.fjhx.service.qa.QaInfoService;
import com.fjhx.utils.FileClientUtil;
import com.fjhx.utils.WrapperUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * qa 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-11-02
 */
@Service
public class QaInfoServiceImpl extends ServiceImpl<QaInfoMapper, QaInfo> implements QaInfoService {

    @Override
    public Page<QaInfo> getPage(Map<String, String> condition) {

        QueryWrapper<QaInfo> wrapper = Wrappers.query();

        WrapperUtil.init(condition, wrapper)
                .keyword("question")
                .createTimeDesc();

        return page(condition, wrapper);
    }

    @Override
    public void add(QaInfoVo qaInfoVo) {
        save(qaInfoVo);
        FileClientUtil.bindingFile(qaInfoVo.getId(), qaInfoVo.getFileInfoList());
    }

    @Override
    public void edit(QaInfoVo qaInfoVo) {
        updateById(qaInfoVo);
        FileClientUtil.againBindingFile(qaInfoVo.getId(), qaInfoVo.getFileInfoList());
    }

    @Override
    public void delete(QaInfoVo qaInfoVo) {
        removeById(qaInfoVo.getId());
        FileClientUtil.relieveBindingFile(qaInfoVo.getId());
    }

}
