kaiyu
2021-07-01 49875151be4b427935fcb3d60696e99ba9d2e1ad
screen-manage
添加根据组织id和地区码获取设备接口
10 files added
9 files modified
557 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/AlarmController.java 2 ●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/MonitorPointController.java 53 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/entity/MonitorPoint.java 108 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/exception/GlobalExceptionHandler.java 10 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/interceptor/WebInterceptor.java 17 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/kafka/consumer/SecondDataConsumer.java 4 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/MonitorPointMapper.java 16 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/form/device/MonitorPointQueryForm.java 30 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/vo/alarm/AlarmLevelVO.java 2 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/vo/device/DeviceVO.java 37 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/vo/monitorPoint/MonitorPointVO.java 41 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/vo/monitorPoint/MonitorPointsVO.java 52 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/DeviceService.java 4 ●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/MonitorPointService.java 28 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/OrganizationService.java 10 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java 16 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java 67 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java 38 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/MonitorPointMapper.xml 22 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/AlarmController.java
@@ -33,7 +33,7 @@
    OrganizationUnitAlarmService organizationUnitAlarmService;
    @GetMapping("queryAlarmByMac")
    public ResultMessage queryByMac(String mac){
    public ResultMessage queryAlarmByMac(String mac){
        List<Sensor> sensors = organizationUnitAlarmService.queryAlarmLevel(mac);
        AlarmLevelVO vo = AlarmLevelVO.convert(sensors);
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), vo);
screen-api/src/main/java/com/moral/api/controller/MonitorPointController.java
New file
@@ -0,0 +1,53 @@
package com.moral.api.controller;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.pojo.vo.monitorPoint.MonitorPointsVO;
import com.moral.api.service.MonitorPointService;
import com.moral.api.service.OrganizationService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @ClassName DeviceController
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 9:24
 * @Version TODO
 **/
@Slf4j
@Api(tags = {"设备数据"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/monitorPoint")
public class MonitorPointController {
    @Autowired
    MonitorPointService monitorPointService;
    @GetMapping("queryMonitorPoints")
    public ResultMessage queryMonitorPointsAndDevices(MonitorPointQueryForm form){
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        //处理查询业务
        List<MonitorPoint> monitorPoints = monitorPointService.query(form);
        //转换前端参数
        MonitorPointsVO vo = MonitorPointsVO.convert(monitorPoints);
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), vo);
    }
}
screen-api/src/main/java/com/moral/api/entity/MonitorPoint.java
New file
@@ -0,0 +1,108 @@
package com.moral.api.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * <p>
 *
 * </p>
 *
 * @author moral
 * @since 2021-07-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class MonitorPoint extends Model<MonitorPoint> {
    private static final long serialVersionUID = 1L;
    /**
     * 序号
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 站点名
     */
    private String name;
    /**
     * 经度
     */
    private Double longitude;
    /**
     * 纬度
     */
    private Double latitude;
    /**
     * 省编码
     */
    private Integer provinceCode;
    /**
     * 地级市编码
     */
    private Integer cityCode;
    /**
     * 县/区/县级市
     */
    private Integer areaCode;
    /**
     * 具体地址
     */
    private String address;
    /**
     * 组织id
     */
    private Integer organizationId;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 是否已删除
     */
    private String isDelete;
    /**
     * 描述
     */
    @TableField(value = "`desc`")
    private String desc;
    /*
    * 站点设备
    * */
    @TableField(exist = false)
    private List<Device> devices;
    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
screen-api/src/main/java/com/moral/api/exception/GlobalExceptionHandler.java
@@ -3,6 +3,7 @@
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.exception.TokenException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -35,4 +36,13 @@
        return ResultMessage.fail(ResponseCodeEnum.FAIL.getCode(), "请求用户数据失败");
    }
    /**
     * 处理TokenException异常
     */
    @ExceptionHandler({TokenException.class})
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public ResultMessage handleTokenException(TokenException ex) {
        return ResultMessage.fail(ex.getCode(),ex.getMsg());
    }
}
screen-api/src/main/java/com/moral/api/interceptor/WebInterceptor.java
@@ -14,21 +14,12 @@
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!(handler instanceof HandlerMethod)) {
        /*if (!(handler instanceof HandlerMethod)) {
            return true;
        }
        }*/
        String token = request.getHeader("token");
        if (token == null) {
            return false;
        }
        try {
            //校验token
            TokenUtils.checkToken(token);
            //延长token
            TokenUtils.extendTokenTime(token);
        } catch (Exception e) {
            return false;
        }
        TokenUtils.checkToken(token);
        //TokenUtils.extendTokenTime(token);
        return true;
    }
}
screen-api/src/main/java/com/moral/api/kafka/consumer/SecondDataConsumer.java
@@ -26,13 +26,13 @@
    public void listen(ConsumerRecord<String, String> record , Consumer consumer) throws Exception {
        String messageStr = record.value();
        Map<String,String> message = (Map<String,String>)JSON.parse(messageStr);
        System.out.println(message);
        //System.out.println(message);
        CopyOnWriteArraySet<SingleDeviceServer> sockets = SingleDeviceServer.sockets;
        for (SingleDeviceServer socket : sockets) {
            //判断消息书否数据该socket
            socket.sendMessage(message.toString());
        }
        System.out.println(message);
       // System.out.println(message);
    }
    @Override
screen-api/src/main/java/com/moral/api/mapper/MonitorPointMapper.java
New file
@@ -0,0 +1,16 @@
package com.moral.api.mapper;
import com.moral.api.entity.MonitorPoint;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author moral
 * @since 2021-07-01
 */
public interface MonitorPointMapper extends BaseMapper<MonitorPoint> {
}
screen-api/src/main/java/com/moral/api/pojo/form/device/MonitorPointQueryForm.java
New file
@@ -0,0 +1,30 @@
package com.moral.api.pojo.form.device;
import lombok.Data;
import org.springframework.util.ObjectUtils;
/**
 * @ClassName QueryMonitorPointsAndDevicesForm
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 11:55
 * @Version TODO
 **/
@Data
public class MonitorPointQueryForm {
    /*
    * 组织id
    * */
    Integer organizationId;
    /*
    * 地区code
    * */
    Integer regionCode;
    public boolean valid(){
        if(ObjectUtils.isEmpty(organizationId)||ObjectUtils.isEmpty(regionCode))
            return false;
        return true;
    }
}
screen-api/src/main/java/com/moral/api/pojo/vo/alarm/AlarmLevelVO.java
@@ -1,5 +1,6 @@
package com.moral.api.pojo.vo.alarm;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moral.api.entity.Sensor;
import lombok.Data;
@@ -15,6 +16,7 @@
 * @Version TODO
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AlarmLevelVO {
    private Map<String,String> alarmLevel;
screen-api/src/main/java/com/moral/api/pojo/vo/device/DeviceVO.java
New file
@@ -0,0 +1,37 @@
package com.moral.api.pojo.vo.device;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
/**
 * @ClassName DeviceVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 14:18
 * @Version TODO
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class DeviceVO {
    private Integer id;
    private Integer monitorPointId;
    private Integer organizationId;
    private Integer versionId;
    private String name;
    private String mac;
    private String address;
    private Double longitude;
    private Double latitude;
    private String state;
}
screen-api/src/main/java/com/moral/api/pojo/vo/monitorPoint/MonitorPointVO.java
New file
@@ -0,0 +1,41 @@
package com.moral.api.pojo.vo.monitorPoint;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moral.api.pojo.vo.device.DeviceVO;
import lombok.Data;
import java.util.List;
/**
 * @ClassName MonitorPointVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 14:28
 * @Version TODO
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MonitorPointVO {
    private Integer id;
    private Integer organizationId;
    private String name;
    private Double longitude;
    private Double latitude;
    private String state;
    private Integer provinceCode;
    private Integer cityCode;
    private Integer areaCode;
    private String address;
    private List<DeviceVO> devices;
}
screen-api/src/main/java/com/moral/api/pojo/vo/monitorPoint/MonitorPointsVO.java
New file
@@ -0,0 +1,52 @@
package com.moral.api.pojo.vo.monitorPoint;
import com.moral.api.entity.Device;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.pojo.vo.device.DeviceVO;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
 * @ClassName MonitorPointsVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 14:33
 * @Version TODO
 **/
@Data
public class MonitorPointsVO {
    private List<MonitorPointVO> monitorPoints;
    public static MonitorPointsVO convert(List<MonitorPoint> monitorPoints){
        MonitorPointsVO monitorPointsVO = new MonitorPointsVO();
        List<MonitorPointVO> monitorPointVOS = new ArrayList<>();
        for (MonitorPoint monitorPoint : monitorPoints) {
            MonitorPointVO monitorPointVO = new MonitorPointVO();
            List<Device> devices = monitorPoint.getDevices();
            List<DeviceVO> deviceVOS = new ArrayList<>();
            for (Device device : devices) {
                DeviceVO deviceVO = deviceConvert(device);
                deviceVOS.add(deviceVO);
            }
            monitorPointVO.setName(monitorPoint.getName());
            monitorPointVO.setLatitude(monitorPoint.getLatitude());
            monitorPointVO.setLongitude(monitorPoint.getLongitude());
            monitorPointVO.setDevices(deviceVOS);
            monitorPointVOS.add(monitorPointVO);
        }
        monitorPointsVO.setMonitorPoints(monitorPointVOS);
        return monitorPointsVO;
    }
    private static DeviceVO deviceConvert(Device device){
        DeviceVO vo = new DeviceVO();
        vo.setName(device.getName());
        vo.setMac(device.getMac());
        vo.setLatitude(device.getLatitude());
        vo.setLongitude(device.getLongitude());
        return vo;
    }
}
screen-api/src/main/java/com/moral/api/service/DeviceService.java
@@ -3,6 +3,8 @@
import com.moral.api.entity.Device;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
 * <p>
 * 设备表 服务类
@@ -12,5 +14,5 @@
 * @since 2021-06-28
 */
public interface DeviceService extends IService<Device> {
    List<Device> getDevicesByMonitorPointId(Integer monitorPointId);
}
screen-api/src/main/java/com/moral/api/service/MonitorPointService.java
New file
@@ -0,0 +1,28 @@
package com.moral.api.service;
import com.moral.api.entity.MonitorPoint;
import com.baomidou.mybatisplus.extension.service.IService;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import java.util.List;
/**
 * <p>
 * 服务类
 * </p>
 *
 * @author moral
 * @since 2021-07-01
 */
public interface MonitorPointService extends IService<MonitorPoint> {
    /**
    * @Description: 根据组织id和地区码查询站点和设备
            * @Param: [form]
            * @return: java.util.List<com.moral.api.entity.MonitorPoint>
            * @Author: 陈凯裕
            * @Date: 2021/7/1
            */
    List<MonitorPoint> query(MonitorPointQueryForm form);
}
screen-api/src/main/java/com/moral/api/service/OrganizationService.java
@@ -3,6 +3,8 @@
import com.moral.api.entity.Organization;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
 * <p>
 * 组织表 服务类
@@ -13,4 +15,12 @@
 */
public interface OrganizationService extends IService<Organization> {
    /**
    * @Description: 查询组织拥有的子组织
            * @Param: [id]
            * @return: java.util.List<com.moral.api.entity.Organization>
            * @Author: 陈凯裕
            * @Date: 2021/7/1
            */
    List<Organization> getChildrenOrganizationsById(Integer id);
}
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -1,10 +1,15 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.service.DeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * <p>
@@ -17,4 +22,15 @@
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
    @Autowired
    DeviceMapper deviceMapper;
    @Override
    public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) {
        QueryWrapper<Device> wrapper = new QueryWrapper();
        wrapper.eq("is_delete", Constants.NOT_DELETE);
        wrapper.eq("monitor_point_id",monitorPointId);
        List<Device> devices = deviceMapper.selectList(wrapper);
        return devices;
    }
}
screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
New file
@@ -0,0 +1,67 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.MonitorPointMapper;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.service.DeviceService;
import com.moral.api.service.MonitorPointService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.OrganizationService;
import com.moral.constant.Constants;
import com.moral.util.RegionCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-07-01
 */
@Service
public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, MonitorPoint> implements MonitorPointService {
    @Autowired
    MonitorPointMapper monitorPointMapper;
    @Autowired
    OrganizationService organizationService;
    @Autowired
    DeviceService deviceService;
    @Override
    public List<MonitorPoint> query(MonitorPointQueryForm form) {
        //取参
        Integer organizationId = form.getOrganizationId();
        Integer regionCode = form.getRegionCode();
        String region = RegionCodeUtils.regionCodeConvertToName(regionCode);
        //查询子组织
        List<Organization> childrenOrganization = organizationService.getChildrenOrganizationsById(organizationId);
        List<Integer> organizationIds = new ArrayList<>();
        for (Organization organization : childrenOrganization) {
            organizationIds.add(organization.getId());
        }
        organizationIds.add(organizationId);
        //查询站点
        QueryWrapper<MonitorPoint> queryMonitorPointsWrapper = new QueryWrapper<>();
        queryMonitorPointsWrapper.eq(region,regionCode);
        queryMonitorPointsWrapper.in("organization_id",organizationIds);
        queryMonitorPointsWrapper.eq("is_delete", Constants.NOT_DELETE);
        List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(queryMonitorPointsWrapper);
        //查询站点对应的设备
        for (MonitorPoint monitorPoint : monitorPoints) {
            List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId());
            monitorPoint.setDevices(devices);
        }
        return monitorPoints;
    }
}
screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -1,10 +1,17 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.service.OrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
/**
 * <p>
@@ -17,4 +24,35 @@
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
    @Autowired
    OrganizationMapper organizationMapper;
    @Override
    public List<Organization> getChildrenOrganizationsById(Integer id) {
        List<Organization> childrenOrganization = new ArrayList<>();
        recursionQueryChildren(id,childrenOrganization);
        return childrenOrganization;
    }
    /**
    * @Description: 通过父组织查询下面所有的子组织放到children中
            * @Param: [parentId, children]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/7/1
            */
    private void recursionQueryChildren(Integer parentId, List<Organization> children) {
        QueryWrapper<Organization> queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete", Constants.NOT_DELETE);
        queryWrapper.eq("parent_id", parentId);
        List<Organization> organizations = organizationMapper.selectList(queryWrapper);
        if (!ObjectUtils.isEmpty(organizations)) {
            children.addAll(organizations);
            for (Organization organization : organizations) {
                recursionQueryChildren(organization.getId(), children);
            }
        } else {
            return;
        }
    }
}
screen-api/src/main/resources/mapper/MonitorPointMapper.xml
New file
@@ -0,0 +1,22 @@
<?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.moral.api.mapper.MonitorPointMapper">
        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.moral.api.entity.MonitorPoint">
                    <id column="id" property="id" />
                    <result column="name" property="name" />
                    <result column="longitude" property="longitude" />
                    <result column="latitude" property="latitude" />
                    <result column="province_code" property="provinceCode" />
                    <result column="city_code" property="cityCode" />
                    <result column="area_code" property="areaCode" />
                    <result column="address" property="address" />
                    <result column="organization_id" property="organizationId" />
                    <result column="create_time" property="createTime" />
                    <result column="update_time" property="updateTime" />
                    <result column="is_delete" property="isDelete" />
                    <result column="desc" property="desc" />
        </resultMap>
</mapper>