package com.changhu.module.securityManagement.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.common.utils.UserUtil;
import com.changhu.module.securityManagement.mapper.Service_ProjectMapper;
import com.changhu.module.securityManagement.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.securityManagement.pojo.queryParams.ServiceProjectPagerQueryParams;
import com.changhu.module.securityManagement.pojo.vo.ServiceProjectPagerVo;
import com.changhu.module.securityManagement.service.Service_ProjectService;
import com.changhu.pojo.entity.ServiceProject;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 20252
 * @createTime 2024/11/22 上午10:22
 * @desc Service_ProjectServiceImpl...
 */
@Service
public class Service_ProjectServiceImpl implements Service_ProjectService {

    @Autowired
    private Service_ProjectMapper service_projectMapper;

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

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