package com.usky.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.BaseBuild;
import com.usky.iot.domain.BaseBuildFacilityRelate;
import com.usky.iot.domain.BaseBuildPlane;
import com.usky.iot.mapper.BaseBuildPlaneMapper;
import com.usky.iot.service.BaseBuildPlaneService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.List;

/**
 * <p>
 * 建筑楼层平面图 服务实现类
 * </p>
 *
 * @author han
 * @since 2023-08-17
 */
@Service
public class BaseBuildPlaneServiceImpl extends AbstractCrudService<BaseBuildPlaneMapper, BaseBuildPlane> implements BaseBuildPlaneService {

    @Override
    public void add(BaseBuildPlane baseBuildPlane){
        baseBuildPlane.setCreateBy(SecurityUtils.getUsername());
        baseBuildPlane.setCreateTime(LocalDateTime.now());
        this.save(baseBuildPlane);

    }

    @Override
    public void update(BaseBuildPlane baseBuildPlane){
        UpdateWrapper<BaseBuildPlane> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("plane_view_url",baseBuildPlane.getPlaneViewUrl());
        updateWrapper.set("create_by",SecurityUtils.getUsername());
        updateWrapper.set("create_time",LocalDateTime.now());
        updateWrapper.eq("build_id",baseBuildPlane.getBuildId());
        updateWrapper.eq("floor",baseBuildPlane.getFloor());
        this.update(updateWrapper);

    }

    @Override
    public List<BaseBuildPlane> dataList(Integer buildId,String floor){
        LambdaQueryWrapper<BaseBuildPlane> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper
                .eq(!ObjectUtils.isEmpty(buildId),BaseBuildPlane::getBuildId,buildId)
                .eq(StringUtils.isNotBlank(floor),BaseBuildPlane::getFloor,floor);
        List<BaseBuildPlane> list = this.list(queryWrapper);
        return list;
    }
}
