package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.fire.domain.BaseModel;
import com.usky.fire.mapper.BaseModelMapper;
import com.usky.fire.service.BaseModelService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 三维模型设备信息 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-09-05
 */
@Service
public class BaseModelServiceImpl extends AbstractCrudService<BaseModelMapper, BaseModel> implements BaseModelService {


    @Override
    public List<Object> modelDataList(Integer buildId, Integer floorId) {
        List<Object> list = new ArrayList<>();
        LambdaQueryWrapper<BaseModel> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(BaseModel::getId, BaseModel::getDeviceCode, BaseModel::getModelName, BaseModel::getModelType,
                BaseModel::getModelUrl, BaseModel::getModelPosition, BaseModel::getModelAngle, BaseModel::getModelScale,
                BaseModel::getModelDragBool)
                .eq(BaseModel::getEnable, 1)
                .eq(BaseModel::getBuildId, buildId)
                .eq(BaseModel::getFloor, floorId);
        List<BaseModel> list1 = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(list1)) {
            for (int i = 0; i < list1.size(); i++) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", list1.get(i).getId());
                map.put("modelName", list1.get(i).getModelName());
                map.put("modelType", list1.get(i).getModelType());
                map.put("modelUrl", list1.get(i).getModelUrl());
                map.put("modelPosition", list1.get(i).getModelPosition().split(","));
                map.put("modelAngle", list1.get(i).getModelAngle().split(","));
                map.put("modelScale", list1.get(i).getModelScale().split(","));
                map.put("modelDragBool", list1.get(i).getModelDragBool());
                map.put("deviceCode", list1.get(i).getDeviceCode());
                list.add(map);
            }
        }
        return list;
    }
}
