package com.changhu.module.superManagement.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.exception.MessageException;
import com.changhu.module.superManagement.mapper.AssessmentCriteriaMapper;
import com.changhu.module.superManagement.pojo.params.CkGroupSaveOrUpdateParams;
import com.changhu.module.superManagement.pojo.params.CkItemSaveOrUpdateParams;
import com.changhu.module.superManagement.pojo.params.CkProjectSaveOrUpdateParams;
import com.changhu.module.superManagement.pojo.params.CkStandardSaveOrUpdateParams;
import com.changhu.module.superManagement.pojo.queryParams.CkProjectPagerQueryParams;
import com.changhu.module.superManagement.pojo.vo.CkProjectDetailTableVo;
import com.changhu.module.superManagement.pojo.vo.CkProjectPagerVo;
import com.changhu.module.superManagement.service.AssessmentCriteriaService;
import com.changhu.pojo.entity.CkGroup;
import com.changhu.pojo.entity.CkItem;
import com.changhu.pojo.entity.CkProject;
import com.changhu.pojo.entity.CkStandard;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/11/22 下午2:38
 * @desc AssessmentCriteriaServiceImpl...
 */
@Service("superManagementAssessmentCriteriaService")
public class AssessmentCriteriaServiceImpl implements AssessmentCriteriaService {

    @Autowired
    private AssessmentCriteriaMapper assessmentCriteriaMapper;

    @Override
    public Page<CkProjectPagerVo> ckProjectPagerVoPager(PageParams<CkProjectPagerQueryParams, CkProjectPagerVo> queryParams) {
        return assessmentCriteriaMapper.ckProjectPager(queryParams.getPage(), queryParams.getParams());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveOrUpdateCkProject(CkProjectSaveOrUpdateParams params) {
        boolean b = Db.saveOrUpdate(BeanUtil.copyProperties(params, CkProject.class));
        if (!b) {
            throw new MessageException();
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteCkProjectById(Long ckProjectId) {
        boolean b = Db.removeById(ckProjectId, CkProject.class);
        if (!b) {
            throw new MessageException();
        }
    }

    @Override
    public List<CkProjectDetailTableVo> ckProjectDetail(Long ckProjectId) {
        return assessmentCriteriaMapper.ckProjectDetail(ckProjectId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveOrUpdateCkGroup(CkGroupSaveOrUpdateParams params) {
        boolean b = Db.saveOrUpdate(BeanUtil.copyProperties(params, CkGroup.class));
        if (!b) {
            throw new MessageException();
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveOrUpdateCkItem(CkItemSaveOrUpdateParams params) {
        boolean b = Db.saveOrUpdate(BeanUtil.copyProperties(params, CkItem.class));
        if (!b) {
            throw new MessageException();
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveOrUpdateCkStandard(CkStandardSaveOrUpdateParams params) {
        boolean b = Db.saveOrUpdate(BeanUtil.copyProperties(params, CkStandard.class));
        if (!b) {
            throw new MessageException();
        }
    }

}
