|  | @@ -1,14 +1,23 @@
 | 
	
		
			
				|  |  |  package com.usky.fire.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
	
		
			
				|  |  |  import com.usky.common.mybatis.core.AbstractCrudService;
 | 
	
		
			
				|  |  |  import com.usky.fire.domain.BaseDevice;
 | 
	
		
			
				|  |  | +import com.usky.fire.domain.BaseDeviceStatus;
 | 
	
		
			
				|  |  |  import com.usky.fire.mapper.BaseDeviceMapper;
 | 
	
		
			
				|  |  | +import com.usky.fire.mapper.BaseDeviceStatusMapper;
 | 
	
		
			
				|  |  |  import com.usky.fire.service.BaseDeviceService;
 | 
	
		
			
				|  |  | +import com.usky.fire.service.BaseDeviceStatusService;
 | 
	
		
			
				|  |  | +import com.usky.fire.service.vo.BaseDeviceTypeVO;
 | 
	
		
			
				|  |  | +import com.usky.fire.service.vo.BaseDeviceVO;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * <p>
 | 
	
	
		
			
				|  | @@ -20,6 +29,8 @@ import java.util.List;
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class BaseDeviceServiceImpl extends AbstractCrudService<BaseDeviceMapper, BaseDevice> implements BaseDeviceService {
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private BaseDeviceStatusMapper baseDeviceStatusMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<BaseDevice> deviceData(String deviceCode) {
 | 
	
	
		
			
				|  | @@ -42,4 +53,50 @@ public class BaseDeviceServiceImpl extends AbstractCrudService<BaseDeviceMapper,
 | 
	
		
			
				|  |  |          return count;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public BaseDeviceVO deviceTypeList(){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BaseDeviceVO baseDeviceVO = new BaseDeviceVO();
 | 
	
		
			
				|  |  | +        LambdaQueryWrapper<BaseDevice> queryWrapper = Wrappers.lambdaQuery();
 | 
	
		
			
				|  |  | +        Integer totalCount = this.count(queryWrapper);
 | 
	
		
			
				|  |  | +        baseDeviceVO.setDeviceCount(totalCount);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        QueryWrapper<BaseDevice> queryWrapper1 = Wrappers.query();
 | 
	
		
			
				|  |  | +        queryWrapper1.select("device_type as deviceTypeCode","device_name as deviceTypeName","count(*) as deviceCount")
 | 
	
		
			
				|  |  | +                .groupBy("device_type");
 | 
	
		
			
				|  |  | +        List<Map<String,Object>> map = this.listMaps(queryWrapper1);
 | 
	
		
			
				|  |  | +        if(map.size() > 0){
 | 
	
		
			
				|  |  | +            List<BaseDeviceTypeVO> list1 = new ArrayList<>();
 | 
	
		
			
				|  |  | +            QueryWrapper<BaseDeviceStatus> queryWrapper2 = Wrappers.query();
 | 
	
		
			
				|  |  | +            queryWrapper2.select("company_id as deviceTypeCode","count(*) as lineCount")
 | 
	
		
			
				|  |  | +                    .ne("device_status",0)
 | 
	
		
			
				|  |  | +                    .groupBy("company_id");
 | 
	
		
			
				|  |  | +            List<Map<String,Object>> map1 = baseDeviceStatusMapper.selectMaps(queryWrapper2);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            for (int i = 0; i < map.size(); i++) {
 | 
	
		
			
				|  |  | +                BaseDeviceTypeVO baseDeviceTypeVO = new BaseDeviceTypeVO();
 | 
	
		
			
				|  |  | +                baseDeviceTypeVO.setDeviceTypeCode(Integer.parseInt(map.get(i).get("deviceTypeCode").toString()));
 | 
	
		
			
				|  |  | +                baseDeviceTypeVO.setDeviceTypeName(map.get(i).get("deviceTypeName").toString());
 | 
	
		
			
				|  |  | +                baseDeviceTypeVO.setDeviceCount(Integer.parseInt(map.get(i).get("deviceCount").toString()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                for (int j = 0; j < map1.size(); j++) {
 | 
	
		
			
				|  |  | +                    int typeCode = Integer.parseInt(map.get(i).get("deviceTypeCode").toString());
 | 
	
		
			
				|  |  | +                    int typeCode1 = Integer.parseInt(map1.get(j).get("deviceTypeCode").toString());
 | 
	
		
			
				|  |  | +                    if(typeCode1 == typeCode){
 | 
	
		
			
				|  |  | +                        int lineCount = Integer.parseInt(map1.get(j).get("lineCount").toString());
 | 
	
		
			
				|  |  | +                        int deviceCount = Integer.parseInt(map.get(i).get("deviceCount").toString());
 | 
	
		
			
				|  |  | +                        baseDeviceTypeVO.setLineCount(lineCount);
 | 
	
		
			
				|  |  | +                        double rate = (double)lineCount/deviceCount*100;
 | 
	
		
			
				|  |  | +                        baseDeviceTypeVO.setLineRate(rate);
 | 
	
		
			
				|  |  | +                        list1.add(baseDeviceTypeVO);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            baseDeviceVO.setTypeList(list1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return baseDeviceVO;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |