package com.persagy.dmp.rwd.simple.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.persagy.dmp.basic.dto.RequestData;
import com.persagy.dmp.digital.entity.ObjectDigital;
import com.persagy.dmp.rwd.basic.utils.DigitalCommonUtils;
import com.persagy.dmp.rwd.digital.dao.ObjectDigitalMapper;
import com.persagy.dmp.rwd.simple.dao.SystemCustomMapper;
import com.persagy.dmp.rwd.simple.service.ISystemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author lvxy
 * @date 2021/10/9
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class SystemServiceImpl extends ServiceImpl<ObjectDigitalMapper, ObjectDigital> implements ISystemService {

    @Resource
    private SystemCustomMapper mapper;
    @Override
    public Page<Map<String,Object>> queryNotSureSystem(RequestData requestData) {
        // 2.不确定建筑 buildingId is null
        // 3.确定建筑不确定楼层 buildingId is not null
        if(StrUtil.isEmpty(requestData.getBuildingId())){
            return mapper.querySystemNotSureBuilding(DigitalCommonUtils
                    .computePageObject(requestData),requestData);
        }else{
            return mapper.querySystemNotSureFloor(DigitalCommonUtils
                    .computePageObject(requestData),requestData);
        }
    }

    @Override
    public List<ObjectDigital> queryByCondition(Wrapper<ObjectDigital> queryWrapper) {
        return mapper.selectList(queryWrapper);
    }

    @Override
    public Integer queryCount(Wrapper<ObjectDigital> queryWrapper) {
        return mapper.selectCount(queryWrapper);
    }

    @Override
    public Page queryByCondition(Page page, Wrapper<ObjectDigital> queryWrapper) {
        return mapper.selectPage(page, queryWrapper);
    }
}
