package com.mortals.xhx.module.room.service.impl;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.room.dao.RoomDao;
import com.mortals.xhx.module.room.model.RoomEntity;
import com.mortals.xhx.module.room.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;

/**
* RoomService
* 房间管理 service实现
*
* @author zxfei
* @date 2023-05-22
*/
@Service("roomService")
@Slf4j
public class RoomServiceImpl extends AbstractCRUDServiceImpl<RoomDao, RoomEntity, Long> implements RoomService {

    @Autowired
    private DeviceService deviceService;

    @Override
    protected void validData(RoomEntity entity, Context context) throws AppException {
        super.validData(entity, context);

        if(!ObjectUtils.isEmpty(entity.getDeviceId())){
            DeviceEntity deviceEntity = deviceService.get(entity.getDeviceId(), context);
            if(!ObjectUtils.isEmpty(deviceEntity)){
                entity.setDeviceCode(deviceEntity.getDeviceCode());
                entity.setDeviceName(deviceEntity.getDeviceName());
            }
        }
    }
}