Commit 921c9e6c authored by huangcb's avatar huangcb

获取设备类型时,增加返回字段:设备实例数量

parent 32e61303
...@@ -6,6 +6,9 @@ import com.esv.datacenter.iot.module.devicemodel.entity.DeviceInstanceEntity; ...@@ -6,6 +6,9 @@ import com.esv.datacenter.iot.module.devicemodel.entity.DeviceInstanceEntity;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/** /**
* 设备实例表 * 设备实例表
* *
...@@ -25,5 +28,14 @@ public interface DeviceInstanceDao extends BaseMapper<DeviceInstanceEntity> { ...@@ -25,5 +28,14 @@ public interface DeviceInstanceDao extends BaseMapper<DeviceInstanceEntity> {
* @createTime 2020/08/07 13:37 * @createTime 2020/08/07 13:37
**/ **/
IPage select4Page(IPage page, DeviceInstanceForm queryObj); IPage select4Page(IPage page, DeviceInstanceForm queryObj);
/**
* @description 查询设备类型的实例数量
* @param queryObj:
* @return java.util.List<java.util.Map<java.lang.String,java.lang.Long>>
* @author huangChaobin@esvtek.com
* @createTime 2020/08/10 17:28
**/
List<Map<String, Long>> selectInstanceCountByType(Map<String, Object> queryObj);
} }
...@@ -7,6 +7,7 @@ import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm; ...@@ -7,6 +7,7 @@ import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 设备实例Service * 设备实例Service
...@@ -89,5 +90,14 @@ public interface DeviceInstanceService extends IService<DeviceInstanceEntity> { ...@@ -89,5 +90,14 @@ public interface DeviceInstanceService extends IService<DeviceInstanceEntity> {
**/ **/
List<DeviceInstanceVO> getInstanceListByTypeId(Long deviceTypeId); List<DeviceInstanceVO> getInstanceListByTypeId(Long deviceTypeId);
/**
* @description 查询设备类型的实例数量
* @param deviceTypeId:
* @return java.util.Map<java.lang.String,java.lang.Long>
* @author huangChaobin@esvtek.com
* @createTime 2020/08/10 17:30
**/
Map<String, Long> getInstanceCountByType(Long deviceTypeId);
} }
...@@ -13,14 +13,11 @@ import com.esv.datacenter.iot.module.devicemodel.entity.DeviceInstanceEntity; ...@@ -13,14 +13,11 @@ import com.esv.datacenter.iot.module.devicemodel.entity.DeviceInstanceEntity;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Objects;
@Service("deviceInstanceService") @Service("deviceInstanceService")
...@@ -118,4 +115,20 @@ public class DeviceInstanceServiceImpl extends ServiceImpl<DeviceInstanceDao, De ...@@ -118,4 +115,20 @@ public class DeviceInstanceServiceImpl extends ServiceImpl<DeviceInstanceDao, De
return voList; return voList;
} }
@Override
public Map<String, Long> getInstanceCountByType(Long deviceTypeId) {
Map<String, Object> queryObj = new HashMap<>(1);
if (Objects.nonNull(deviceTypeId)) {
queryObj.put("deviceTypeId", deviceTypeId);
}
List<Map<String, Long>> instanceCountMapList = this.getBaseMapper().selectInstanceCountByType(queryObj);
Map<String, Long> instanceCountMap = new HashMap<>(instanceCountMapList.size());
for (Map<String, Long> map : instanceCountMapList) {
instanceCountMap.put(String.valueOf(map.get("device_type_id")), map.get("count"));
}
return instanceCountMap;
}
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ import com.esv.datacenter.iot.module.devicemodel.dao.DeviceTypeDao; ...@@ -16,6 +16,7 @@ import com.esv.datacenter.iot.module.devicemodel.dao.DeviceTypeDao;
import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity; import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataMapService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataMapService;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceTypeService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceTypeService;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeBriefVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeBriefVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO;
...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -36,6 +38,8 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType ...@@ -36,6 +38,8 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType
private DeviceDataMapService deviceDataMapService; private DeviceDataMapService deviceDataMapService;
@Autowired @Autowired
private DataModelPropertyService dataModelPropertyService; private DataModelPropertyService dataModelPropertyService;
@Autowired
private DeviceInstanceService deviceInstanceService;
@Override @Override
public Long insertDeviceType(DeviceTypeForm form) { public Long insertDeviceType(DeviceTypeForm form) {
...@@ -84,14 +88,24 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType ...@@ -84,14 +88,24 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType
@Override @Override
public PageResultVO getType4Page(DeviceTypeForm form) { public PageResultVO getType4Page(DeviceTypeForm form) {
// 分页查询设备类型
IPage<DeviceTypeEntity> page = new Page<>(form.getPageNum(), form.getPageSize()); IPage<DeviceTypeEntity> page = new Page<>(form.getPageNum(), form.getPageSize());
this.baseMapper.select4Page(page, form); this.baseMapper.select4Page(page, form);
// 查询设备类型对应的实例数量
Map<String, Long> instanceCountMap = deviceInstanceService.getInstanceCountByType(null);
List<DeviceTypeEntity> entityList = page.getRecords(); List<DeviceTypeEntity> entityList = page.getRecords();
List<DeviceTypeVO> voList = new ArrayList<>(); List<DeviceTypeVO> voList = new ArrayList<>();
Long instanceCount;
for (DeviceTypeEntity entity : entityList) { for (DeviceTypeEntity entity : entityList) {
DeviceTypeVO vo = new DeviceTypeVO(); DeviceTypeVO vo = new DeviceTypeVO();
BeanUtils.copyProperties(entity, vo); BeanUtils.copyProperties(entity, vo);
instanceCount = instanceCountMap.get(String.valueOf(entity.getId()));
if (Objects.isNull(instanceCount)) {
instanceCount = 0L;
}
vo.setInstanceCount(instanceCount);
vo.setCreateTime(entity.getCreateTime().getTime()); vo.setCreateTime(entity.getCreateTime().getTime());
vo.setUpdateTime(entity.getUpdateTime().getTime()); vo.setUpdateTime(entity.getUpdateTime().getTime());
voList.add(vo); voList.add(vo);
......
...@@ -25,6 +25,10 @@ public class DeviceTypeVO { ...@@ -25,6 +25,10 @@ public class DeviceTypeVO {
* 描述 * 描述
*/ */
private String description; private String description;
/**
* 设备实例数量
*/
private Long instanceCount;
/** /**
* 创建者 * 创建者
*/ */
......
...@@ -41,4 +41,14 @@ ...@@ -41,4 +41,14 @@
ORDER BY a.name ASC ORDER BY a.name ASC
</select> </select>
<select id="selectInstanceCountByType" parameterType="java.util.Map" resultType="java.util.Map">
select device_type_id, count(id) as count
from device_instance
where deleted = false
<if test="deviceTypeId != null">
and device_type_id = #{deviceTypeId}
</if>
group by device_type_id
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment