package com.persagy.bdtp.adm.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.persagy.bdtp.adm.common.AdmConst;
import com.persagy.bdtp.adm.dao.AdmObjectMapper;
import com.persagy.bdtp.adm.entity.db.AdmObject;
import com.persagy.bdtp.adm.service.IAdmObjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
public class AdmObjectServiceImpl extends ServiceImpl<AdmObjectMapper, AdmObject> implements IAdmObjectService {

	private final AdmObjectMapper admObjMapper;

	@Override
	public List<AdmObject> insert(List<AdmObject> voList) {
		if(CollUtil.isEmpty(voList))
			return null;

		for(AdmObject obj : voList) {
			admObjMapper.insert(obj);
			// 新增后消息
			//messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_INSERT, null, vo, false);
		}

		return voList;
	}

	@Override
	public List<AdmObject> update(List<AdmObject> voList) {
		if(CollUtil.isEmpty(voList))
			return null;

		for(AdmObject obj : voList) {
			admObjMapper.updateById(obj);
			// 更新后消息
			//messageSender.sendMessage(DigitalMessageConstant.OPERATE_AFTER_INSERT, null, vo, false);
		}

		return voList;
	}

	@Override
	public List<AdmObject> queryBdAndFl(String... projectIds) {
		QueryWrapper<AdmObject> queryWrapper = new QueryWrapper<>();
		queryWrapper.in("project_id", projectIds).in("obj_type", AdmConst.OBJ_TYPE_BUILDING, AdmConst.OBJ_TYPE_FLOOR);
		return admObjMapper.selectList(queryWrapper);
	}

	@Override
	public List<AdmObject> queryM2dByObjType(String projectId, String objType) {
		QueryWrapper<AdmObject> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("project_id", projectId).eq("obj_type", objType).isNull("client_id");
		return admObjMapper.selectList(queryWrapper);
	}

}
