/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.homecare.alarmlist.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.homecare.alarmlist.entity.Alarm;
import org.springblade.homecare.alarmlist.vo.AlarmVO;
import org.springblade.homecare.alarmlist.mapper.AlarmMapper;
import org.springblade.homecare.alarmlist.service.IAlarmService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.system.orgposition.entity.OrgPosition;
import org.springblade.system.orgposition.service.IOrgPositionService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.ArrayList;
import java.util.List;

/**
 * 设备告警 服务实现类
 *
 * @author BladeX
 * @since 2020-11-17
 */
@AllArgsConstructor
@Service
public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements IAlarmService {

	private IOrgPositionService orgPositionService;

	@Override
	public IPage<AlarmVO> selectAlarmPage(IPage<AlarmVO> page, AlarmVO alarm) {
		BladeUser bladeUser = SecureUtil.getUser();
		String deptId = bladeUser.getDeptId();
		String[] deptIds = deptId.split(",");
		List<String> list = new ArrayList<>();

		for (int i = 0; i < deptIds.length; i++) {
			OrgPosition orgPosition = orgPositionService.getOne(new QueryWrapper<>(new OrgPosition()).lambda().eq(OrgPosition::getOrgId,deptIds[i]));
			list.add(orgPosition.getOrgPosition());
		}
		return page.setRecords(baseMapper.selectAlarmPage(page, alarm, list));
	}

}
