package com.qmth.sop.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.sop.business.bean.dto.DataPermissionDto;
import com.qmth.sop.business.entity.SysDevice;
import com.qmth.sop.business.entity.SysUser;
import com.qmth.sop.business.mapper.DeviceMonitorMapper;
import com.qmth.sop.business.service.DeviceMonitorService;
import com.qmth.sop.business.service.SysUserService;
import com.qmth.sop.common.util.ServletUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


/**
 * @author dhshu
 * @date:
 */
@Service
public class DeviceMonitorServiceImpl extends ServiceImpl<DeviceMonitorMapper, SysDevice> implements DeviceMonitorService {

    @Resource
    private SysUserService sysUserService;
    @Override
    public Map<String, Object> count(Long supplierId, String model) {
        return this.baseMapper.count(supplierId, model);
    }

    @Override
    public List<Map<String, Object>> countByModel(Long supplierId) {
        return this.baseMapper.countByModel(supplierId);
    }

    @Override
    public Map<String, Object> countByServiceUnit() {
        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
        Map<String, Object> map = this.baseMapper.countByServiceUnit(dpr);

        Map<String, Object> count = this.count(null, null);
        count.putAll(map);
        return count;
    }

    @Override
    public List<Map<String, Object>> countByServiceUnitDetail() {
        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
        DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
        return this.baseMapper.countByServiceUnitDetail(dpr);
    }
}
