package com.yuchen.saas.park.service.service.property;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuchen.saas.park.api.entity.property.PropertyBuildingUnit;
import com.yuchen.saas.park.service.mapper.property.PropertyBuildingUnitMapper;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PropertyBuildingUnitService extends ServiceImpl<PropertyBuildingUnitMapper, PropertyBuildingUnit> {
    public List<PropertyBuildingUnit> getAll() {

        LambdaQueryWrapper<PropertyBuildingUnit> qw = new LambdaQueryWrapper<>();
        List<PropertyBuildingUnit> propertyBuildingUnitList = baseMapper.selectList(qw);

        return propertyBuildingUnitList;
    }

    public boolean savePropertyBuildingUnit(PropertyBuildingUnit propertyBuildingUnit) {
        //this.verifySaveFeeMode(communityInfo);
        this.assembleSaveDto(propertyBuildingUnit);
        return this.saveOrUpdate(propertyBuildingUnit);

    }

    private void assembleSaveDto(PropertyBuildingUnit propertyBuildingUnit) {
        if (Func.isEmpty(propertyBuildingUnit.getId())) {
            propertyBuildingUnit.setCreateTime(new Date());
        }
    }
    public List<PropertyBuildingUnit> getUnitsByBuildingId(Long buildingId) {

        LambdaQueryWrapper<PropertyBuildingUnit> qw = new LambdaQueryWrapper<>();
        qw.eq(PropertyBuildingUnit::getBuildingId, buildingId);
        List<PropertyBuildingUnit> propertyBuildingUnitList = baseMapper.selectList(qw);

        return propertyBuildingUnitList;
    }


}
