package com.yuchen.saas.park.service.service.work.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.dto.work.SaasWorkOrderTypeDto;
import com.yuchen.saas.park.api.dto.work.SaasWorkOrderTypeQueryDto;
import com.yuchen.saas.park.api.entity.work.SaasWorkOrderType;
import com.yuchen.saas.park.api.vo.work.SaasWorkOrderTypeVo;
import com.yuchen.saas.park.service.service.work.ISaasWorkOrderTypeService;
import com.yuchen.saas.park.service.mapper.work.SaasWorkOrderTypeMapper;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.utils.BeanUtil;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 工单类型表 服务实现类
 * </p>
 *
 * @author caiwq
 * @since 2024-04-01
 */
@Service
public class SaasWorkOrderTypeServiceImpl extends BaseServiceImpl<SaasWorkOrderTypeMapper, SaasWorkOrderType> implements ISaasWorkOrderTypeService {

    @Override
    public Boolean add(SaasWorkOrderTypeDto workOrderTypeDto) {
        SaasWorkOrderType workOrderType = BeanUtil.copyProperties(workOrderTypeDto, SaasWorkOrderType.class);
        return save(workOrderType);
    }

    @Override
    public Boolean edit(SaasWorkOrderTypeDto workOrderTypeDto) {
        SaasWorkOrderType workOrderType = BeanUtil.copyProperties(workOrderTypeDto, SaasWorkOrderType.class);
        return updateById(workOrderType);
    }

    @Override
    public Boolean remove(Long id) {
        return removeById(id);
    }

    @Override
    public NestPage<SaasWorkOrderTypeVo> list(SaasWorkOrderTypeQueryDto queryDto) {
        LambdaQueryWrapper<SaasWorkOrderType> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Func.isNotEmpty(queryDto.getType()), SaasWorkOrderType::getType, queryDto.getType());
        queryWrapper.like(Func.isNotEmpty(queryDto.getName()), SaasWorkOrderType::getName, queryDto.getName());
        queryWrapper.like(Func.isNotEmpty(queryDto.getTno()), SaasWorkOrderType::getTno, queryDto.getTno());
        queryWrapper.orderByDesc(SaasWorkOrderType::getCreateTime);
        IPage<SaasWorkOrderType> page = this.page(Condition.getPage(queryDto), queryWrapper);
        IPage<SaasWorkOrderTypeVo> result = new Page<>(queryDto.getCurrent(), queryDto.getSize());
        List<SaasWorkOrderType> recordList = page.getRecords();
        List<SaasWorkOrderTypeVo> list = BeanUtil.copyProperties(recordList, SaasWorkOrderTypeVo.class);
        result.setRecords(list);
        result.setTotal(page.getTotal());
        return NestPage.of(result);
    }

    @Override
    public List<SaasWorkOrderTypeVo> listAll(SaasWorkOrderTypeQueryDto queryDto) {
        LambdaQueryWrapper<SaasWorkOrderType> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Func.isNotEmpty(queryDto.getType()), SaasWorkOrderType::getType, queryDto.getType());
        queryWrapper.like(Func.isNotEmpty(queryDto.getName()), SaasWorkOrderType::getName, queryDto.getName());
        queryWrapper.like(Func.isNotEmpty(queryDto.getTno()), SaasWorkOrderType::getTno, queryDto.getTno());
        queryWrapper.orderByDesc(SaasWorkOrderType::getCreateTime);
        List<SaasWorkOrderType> list = list(queryWrapper);
        return BeanUtil.copyProperties(list, SaasWorkOrderTypeVo.class);
    }



}
