فهرست منبع

设备类型查询

wangyangyang 4 سال پیش
والد
کامیت
3729c3df0b

+ 40 - 0
sms_water/src/main/java/com/huaxu/controller/DeviceTypeController.java

@@ -0,0 +1,40 @@
+package com.huaxu.controller;
+
+
+import com.huaxu.dto.TreeDataDto;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.ui.ModelMap;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Date;
+import org.springframework.web.bind.annotation.*;
+import com.huaxu.entity.DeviceTypeEntity;
+import com.huaxu.service.DeviceTypeService;
+
+/**
+ * 设备型号页面控制器
+ * @author WYY
+ * @date 2020-11-18 08:21
+ */
+@RestController
+@RequestMapping("/devicetype/devicetype")
+@Api(tags = "设备类型管理")
+public class DeviceTypeController {
+
+    @Autowired
+    private DeviceTypeService deviceTypeService;
+
+    @ApiOperation(value = "查询设备类型")
+    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
+    @ResponseBody
+    public List<TreeDataDto> getTreeData(String name) {
+        List<TreeDataDto> treeDataDtos = deviceTypeService.getTreeData(name);
+        return treeDataDtos;
+    }
+
+}

+ 33 - 0
sms_water/src/main/java/com/huaxu/dao/DeviceTypeMapper.java

@@ -0,0 +1,33 @@
+package com.huaxu.dao;
+
+import java.io.Serializable;
+import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huaxu.entity.DeviceTypeEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+/**
+ *
+ * sms_device_typeDAO接口
+ * @author: WYY
+ * @date 2020-11-18 08:21
+ */
+@Mapper
+public interface DeviceTypeMapper extends BaseMapper<DeviceTypeEntity> {
+
+	/**
+     * 自定义分页查询
+     * @param  page 
+     * @param  deviceTypeEntity 实体类
+     */
+     Page<DeviceTypeEntity> findPage(IPage<DeviceTypeEntity> page, @Param("deviceType") DeviceTypeEntity deviceTypeEntity);
+
+     DeviceTypeEntity findDeviceTypeById(Serializable id);
+
+
+     List<DeviceTypeEntity> findList(DeviceTypeEntity deviceTypeEntity);
+
+     /**删除相关方法  使用mybatis-plus集成的 **/
+}

+ 23 - 0
sms_water/src/main/java/com/huaxu/dto/TreeDataDto.java

@@ -0,0 +1,23 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+import java.util.Objects;
+
+@Data
+public class TreeDataDto {
+    @ApiModelProperty(value = "id", position = 1)
+    private Long id;
+
+    @ApiModelProperty(value = "标签", position = 3)
+    private String label;
+
+    @ApiModelProperty(value = "值", position = 3)
+    private String value;
+
+    @ApiModelProperty(value = "子类", position = 5)
+    private List<TreeDataDto> children;
+}

+ 65 - 0
sms_water/src/main/java/com/huaxu/entity/DeviceTypeEntity.java

@@ -0,0 +1,65 @@
+package com.huaxu.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * sms_device_type
+ * @author: WYY
+ * @date 2020-11-18 08:21
+ */
+@Data
+@TableName("sms_device_type")
+public class DeviceTypeEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */ 
+	@TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    /** 厂商名称 */
+    @ApiModelProperty(value = "厂商名称")
+    private String manufacturerName;
+
+    /** 厂商ID */
+    @ApiModelProperty(value = "厂商ID")
+    private String manufacturerId;
+
+    /** 设备类型 */
+    @ApiModelProperty(value = "设备类型")
+    private String deviceType;
+
+    /** 设备型号 */
+    @ApiModelProperty(value = "设备型号")
+    private String deviceMode;
+
+    /** 数据删除标记 */
+    @TableLogic
+    @ApiModelProperty(value = "数据删除标记")
+    private Integer status;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "2020-12-12 12:12:12")
+    @ApiModelProperty(value = "创建时间",example = "2020-12-12 12:12:12")
+    private Date dateCreate;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /** 更新者 */
+    @ApiModelProperty(value = "更新者")
+    private String updateBy;
+    /** 更新时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "2020-12-12 12:12:12")
+    @ApiModelProperty(value = "更新时间",example = "2020-12-12 12:12:12")
+    private Date dateUpdate;
+}

+ 129 - 0
sms_water/src/main/java/com/huaxu/service/DeviceTypeService.java

@@ -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;
+    }
+}

+ 66 - 0
sms_water/src/main/resources/mapper/DeviceTypeMapper.xml

@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.huaxu.dao.DeviceTypeMapper">
+
+
+    <resultMap type="DeviceTypeEntity" id="DeviceTypeResult">
+        <result property="id" column="id"/>
+        <result property="manufacturerName" column="manufacturer_name"/>
+        <result property="manufacturerId" column="manufacturer_id"/>
+        <result property="deviceType" column="device_type"/>
+        <result property="deviceMode" column="device_mode"/>
+        <result property="status" column="status"/>
+        <result property="dateCreate" column="date_create"/>
+        <result property="createBy" column="create_by"/>
+        <result property="dateUpdate" column="date_update"/>
+        <result property="updateBy" column="update_by"/>
+    </resultMap>
+
+    <!--  实体栏位  -->
+    <sql id="deviceTypeColumns">
+         a.id as "id" ,
+         a.manufacturer_name as "manufacturerName" ,
+         a.manufacturer_id as "manufacturerId" ,
+         a.device_type as "deviceType" ,
+         a.device_mode as "deviceMode" ,
+         a.status as "status" ,
+         a.date_create as "dateCreate" ,
+         a.create_by as "createBy" ,
+         a.date_update as "dateUpdate" ,
+         a.update_by as "updateBy" 
+     </sql>
+
+    <!--  根据主键获取实体   -->
+    <select id="findDeviceTypeById" resultType="com.huaxu.entity.DeviceTypeEntity">
+        SELECT
+        <include refid="deviceTypeColumns"/>
+        FROM sms_device_type a
+        WHERE a.id = #{id}
+    </select>
+
+    <!--  根据获取实体List   -->
+    <select id="findList" resultType="com.huaxu.entity.DeviceTypeEntity">
+        SELECT
+        <include refid="deviceTypeColumns"/>
+        FROM sms_device_type a
+        <where>
+            <if test="manufacturerName != null  and manufacturerName != ''">
+                and a.manufacturer_name LIKE concat('%',#{manufacturerName},'%')
+            </if>
+        </where>
+    </select>
+
+    <!--  根据获取实体 page   -->
+    <select id="findPage" resultType="com.huaxu.entity.DeviceTypeEntity">
+        SELECT
+        <include refid="deviceTypeColumns"/>
+        FROM sms_device_type a
+        <where>
+            <if test="deviceType.manufacturerName != null  and deviceType.manufacturerName != ''">
+                and a.manufacturer_name LIKE concat('%',#{deviceType.manufacturerName},'%')
+            </if>
+        </where>
+    </select>
+</mapper>