package cn.iocoder.yudao.module.system.service.sys;

import cn.iocoder.yudao.module.system.controller.admin.sys.vo.ServiceItemLevelPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.sys.vo.ServiceItemLevelSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ServiceItemLevelDO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import cn.iocoder.yudao.module.system.dal.mysql.biz.SysServiceItemLevelMapper;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;


import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.SERVICE_ITEM_LEVEL_NOT_EXISTS;

/**
 * @Author: jinyd
 * @CreateTime: 2025/4/1  13:54
 * @Description:
 * @Version: 4.0
 */

@Service
@Validated
public class ServiceItemLevelServiceImpl implements ServiceItemLevelService{

    @Resource
    private SysServiceItemLevelMapper serviceItemLevelMapper;

    @Override
    public Long createServiceItemLevel(ServiceItemLevelSaveReqVO createReqVO) {
        // 插入
        ServiceItemLevelDO serviceItemLevel = BeanUtils.toBean(createReqVO, ServiceItemLevelDO.class);
        serviceItemLevelMapper.insert(serviceItemLevel);
        // 返回
        return serviceItemLevel.getId();
    }

    @Override
    public void updateServiceItemLevel(ServiceItemLevelSaveReqVO updateReqVO) {
        // 校验存在
        validateServiceItemLevelExists(updateReqVO.getId());
        // 更新
        ServiceItemLevelDO updateObj = BeanUtils.toBean(updateReqVO, ServiceItemLevelDO.class);
        serviceItemLevelMapper.updateById(updateObj);
    }

    @Override
    public void deleteServiceItemLevel(Long id) {
        // 校验存在
        validateServiceItemLevelExists(id);
        // 删除
        serviceItemLevelMapper.deleteById(id);
    }

    private void validateServiceItemLevelExists(Long id) {
        if (serviceItemLevelMapper.selectById(id) == null) {
            throw exception(SERVICE_ITEM_LEVEL_NOT_EXISTS);
        }
    }

    @Override
    public ServiceItemLevelDO getServiceItemLevel(Long id) {
        return serviceItemLevelMapper.selectById(id);
    }

    @Override
    public PageResult<ServiceItemLevelDO> getServiceItemLevelPage(ServiceItemLevelPageReqVO pageReqVO) {
        List<ServiceItemLevelDO> page = serviceItemLevelMapper.findPage(null, pageReqVO);
        PageResult<ServiceItemLevelDO> pageResult = new PageResult<>(page, null);
        return pageResult;
    }


}
