package cn.iocoder.yudao.module.property.service.impl;

import cn.iocoder.yudao.module.property.entity.Property;
import cn.iocoder.yudao.module.property.entity.PropertyKeep;
import cn.iocoder.yudao.module.property.mapper.PropertyKeepMapper;
import cn.iocoder.yudao.module.property.service.PropertyKeepService;
import cn.iocoder.yudao.module.property.service.PropertyService;
import cn.iocoder.yudao.module.property.vo.PropertyKeepReqVO;
import cn.iocoder.yudao.module.property.vo.PropertyKeepRespVO;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 资产维修/保养记录 接口实现类
 * @author 小李
 * @date 11:23 2024/8/16
**/
@Service
@Validated
public class PropertyKeepServiceImpl extends ServiceImpl<PropertyKeepMapper, PropertyKeep> implements PropertyKeepService {

    @Resource
    private PropertyService propertyService;

    /**
     * 创建资产维修/保养记录
     * @author 小李
     * @date 11:26 2024/8/16
     * @param keepRespVO 资产维修/保养记录对象
     **/
    @Override
    @DSTransactional
    public void createPropertyKeep(PropertyKeepRespVO keepRespVO){
        // 更新资产的保养时间和下次保养时间
        Property property = keepRespVO.getProperty();
        property.setLastKeepDate(keepRespVO.getKeepDate());
        propertyService.updateById(property);

        // 接入资产维修\保养记录
        keepRespVO.setPropertyId(keepRespVO.getProperty().getId());
        baseMapper.insert(keepRespVO);
    }

    /**
     * 资产维修/保养记录 分页
     * @author 小李
     * @date 15:42 2024/8/16
     * @param pageReqVO 查询对象
     **/
    @Override
    public IPage<PropertyKeep> getPropertyKeepPage(PropertyKeepReqVO pageReqVO, Page<PropertyKeep> page){
        return baseMapper.getPropertyKeepPage(pageReqVO, page);
    }
}