/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.workflow.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codvision.commoncore.utils.Preconditions;
import com.codvision.webcore.bean.QueryPage;
import com.codvision.webcore.util.QueryPageUtil;
import com.codvision.workflow.entity.Questionnaire;
import com.codvision.workflow.mapper.QuestionnaireMapper;
import com.codvision.workflow.service.QuestionnaireService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author codvision
 */
@Service
public class QuestionnaireServiceImpl extends ServiceImpl<QuestionnaireMapper, Questionnaire> implements QuestionnaireService {

    @Override
    public IPage<Questionnaire> getPageResult(QueryPage<Map<String, Object>> queryPage) {
        return getBaseMapper().getPageResult(queryPage.getPage(), QueryPageUtil.queryMap(queryPage));
    }

    @Override
    public void delById(Integer id) {
        Questionnaire questionnaire = this.getById(id);
        if (questionnaire != null) {
            Preconditions.checkArgument(questionnaire.getStatus() != 1,"已发布，不允许删除！");
            this.removeById(id);
        }
    }
}
