|
@@ -0,0 +1,129 @@
|
|
|
|
+package com.huaxu.service;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.huaxu.dao.DeviceTypeMapper;
|
|
|
|
+import com.huaxu.dto.TreeDataDto;
|
|
|
|
+import com.huaxu.entity.DeviceTypeEntity;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import static com.google.common.collect.Lists.newArrayList;
|
|
|
|
+/**
|
|
|
|
+ * 设备型号Service接口
|
|
|
|
+ *
|
|
|
|
+ * @author: WYY
|
|
|
|
+ * @date 2020-11-18 08:21
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class DeviceTypeService extends ServiceImpl<DeviceTypeMapper, DeviceTypeEntity> {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DeviceTypeMapper deviceTypeMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查列表
|
|
|
|
+ */
|
|
|
|
+ public List<DeviceTypeEntity> findList(DeviceTypeEntity deviceTypeEntity) {
|
|
|
|
+ return deviceTypeMapper.findList(deviceTypeEntity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量删除
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean delDeviceTypeByIds(Long[] ids) {
|
|
|
|
+ return this.removeByIds(Arrays.asList(ids));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 单个删除
|
|
|
|
+ */
|
|
|
|
+ public boolean delDeviceTypeById(Long id) {
|
|
|
|
+ return this.removeById(id);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存
|
|
|
|
+ */
|
|
|
|
+ public boolean addDeviceType(DeviceTypeEntity deviceType) {
|
|
|
|
+ if (this.save(deviceType)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改根居ID
|
|
|
|
+ */
|
|
|
|
+ public boolean updateDeviceTypeById(DeviceTypeEntity deviceType) {
|
|
|
|
+ if (this.updateById(deviceType)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根居ID获取对象
|
|
|
|
+ */
|
|
|
|
+ public DeviceTypeEntity findDeviceTypeById(Long id) {
|
|
|
|
+ return deviceTypeMapper.findDeviceTypeById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<TreeDataDto> getTreeData(String name)
|
|
|
|
+ {
|
|
|
|
+ DeviceTypeEntity deviceTypeEntity = new DeviceTypeEntity();
|
|
|
|
+ deviceTypeEntity.setManufacturerName(name);
|
|
|
|
+ List<DeviceTypeEntity> list = deviceTypeMapper.findList(deviceTypeEntity);
|
|
|
|
+
|
|
|
|
+ List<TreeDataDto> datalist = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ Map<String, List<DeviceTypeEntity>> manufacturerNameGroupBy = list.stream().collect(Collectors.groupingBy(DeviceTypeEntity::getManufacturerName));
|
|
|
|
+ for (String manufacturerNameKey:manufacturerNameGroupBy.keySet()){
|
|
|
|
+ List<DeviceTypeEntity> manufacturerNameList = manufacturerNameGroupBy.get(manufacturerNameKey);
|
|
|
|
+ TreeDataDto manufacturerNameTreeDataDto = new TreeDataDto();
|
|
|
|
+ manufacturerNameTreeDataDto.setLabel(manufacturerNameKey);
|
|
|
|
+ manufacturerNameTreeDataDto.setValue(manufacturerNameKey);
|
|
|
|
+ datalist.add(manufacturerNameTreeDataDto);
|
|
|
|
+
|
|
|
|
+ Map<String, List<DeviceTypeEntity>> equipmentTypeGroupBy = manufacturerNameList.stream().collect(Collectors.groupingBy(DeviceTypeEntity::getDeviceType));
|
|
|
|
+ for (String equipmentTypeKey:equipmentTypeGroupBy.keySet()){
|
|
|
|
+ TreeDataDto equipmentTypeTreeDataDto = new TreeDataDto();
|
|
|
|
+ equipmentTypeTreeDataDto.setLabel(equipmentTypeKey);
|
|
|
|
+ equipmentTypeTreeDataDto.setValue(equipmentTypeKey);
|
|
|
|
+ if (manufacturerNameTreeDataDto.getChildren() != null) {
|
|
|
|
+ manufacturerNameTreeDataDto.getChildren().add(equipmentTypeTreeDataDto);
|
|
|
|
+ }else {
|
|
|
|
+ manufacturerNameTreeDataDto.setChildren(newArrayList(equipmentTypeTreeDataDto));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<DeviceTypeEntity> equipmentTypeKeyList = equipmentTypeGroupBy.get(equipmentTypeKey);
|
|
|
|
+ for (DeviceTypeEntity deviceTypeDto : equipmentTypeKeyList) {
|
|
|
|
+ TreeDataDto modelTreeDataDto = new TreeDataDto();
|
|
|
|
+ modelTreeDataDto.setId(deviceTypeDto.getId());
|
|
|
|
+ modelTreeDataDto.setLabel(deviceTypeDto.getDeviceMode());
|
|
|
|
+ modelTreeDataDto.setValue(deviceTypeDto.getDeviceMode());
|
|
|
|
+
|
|
|
|
+ if (equipmentTypeTreeDataDto.getChildren() != null) {
|
|
|
|
+ equipmentTypeTreeDataDto.getChildren().add(modelTreeDataDto);
|
|
|
|
+ }else {
|
|
|
|
+ equipmentTypeTreeDataDto.setChildren(newArrayList(modelTreeDataDto));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return datalist;
|
|
|
|
+ }
|
|
|
|
+}
|