package com.changhu.module.management.service.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.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.module.management.mapper.ServiceProjectMapper;
import com.changhu.module.management.pojo.entity.ServiceProject;
import com.changhu.module.management.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ServiceProjectPagerQueryParams;
import com.changhu.module.management.pojo.vo.ServiceProjectPagerVo;
import com.changhu.module.management.service.ServiceProjectService;
import com.changhu.pojo.dto.ServiceProjectDTO;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * service_project (服务项目)  服务实现类
 * author: luozhun
 * desc 由groovy脚本自动生成
 */
@Service
public class ServiceProjectServiceImpl extends ServiceImpl<ServiceProjectMapper, ServiceProject> implements ServiceProjectService {

    @Override
    public Page<ServiceProjectPagerVo> pager(PageParams<ServiceProjectPagerQueryParams, ServiceProjectPagerVo> queryParams) {
        return baseMapper.pager(queryParams.getPage(), queryParams.getParams());
    }

    @Override
    public void saveOrUpdate(ServiceProjectSaveOrUpdateParams params) {
        ServiceProject serviceProject = BeanUtil.copyProperties(params, ServiceProject.class);
        serviceProject.setSecurityUnitId(UserUtil.getUnitId());
        boolean b = this.saveOrUpdate(serviceProject);
        if (!b) {
            throw new MessageException();
        }
    }

    @Override
    public List<ServiceProjectDTO> getServiceProjectByEnterprisesUnitId(Long enterprisesUnitId) {
        return baseMapper.getServiceProjectByEnterprisesUnitId(enterprisesUnitId);
    }
}
