package com.gitee.sop.admin.service.help;

import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.LambdaQuery;
import com.gitee.sop.admin.common.dto.StatusUpdateDTO;
import com.gitee.sop.admin.common.support.ServiceSupport;
import com.gitee.sop.admin.common.util.CopyUtil;
import com.gitee.sop.admin.dao.entity.HelpDoc;
import com.gitee.sop.admin.dao.mapper.HelpDocMapper;
import com.gitee.sop.admin.service.help.dto.HelpDocDTO;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author thc
 */
@Service
public class HelpDocService implements ServiceSupport<HelpDoc, HelpDocMapper> {

    public List<HelpDocDTO> listTree() {
        return this.query()
                .select(HelpDoc::getId, HelpDoc::getLabel, HelpDoc::getParentId,
                        HelpDoc::getAddTime,
                        HelpDoc::getUpdateTime)
                .orderByAsc(HelpDoc::getSort)
                .list(data -> CopyUtil.copyBean(data, HelpDocDTO::new));
    }

    public PageInfo<HelpDoc> doPage(LambdaQuery<HelpDoc> query) {
        query.orderByDesc(HelpDoc::getId);
        PageInfo<HelpDoc> page = this.page(query);

        // 格式转换
        return page.convert(isvInfo -> {

            return isvInfo;
        });
    }


    /**
     * 修改状态
     *
     * @param statusUpdateDTO 修改值
     * @return 返回影响行数
     */
    public int updateStatus(StatusUpdateDTO statusUpdateDTO) {
        return this.query()
                .eq(HelpDoc::getId, statusUpdateDTO.getId())
                .set(HelpDoc::getStatus, statusUpdateDTO.getStatus())
                .update();
    }
}
