lizijie
2021-09-10 6c5658432934f182cfc5a7c5362c53080cbd27cf
gov_monitor_point表相关文件,查询与新增接口
6 files added
1 files modified
420 ■■■■■ changed files
screen-common/src/main/java/com/moral/constant/RedisConstants.java 5 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/controller/GovMonitorPoionController.java 71 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/entity/GovMonitorPoint.java 101 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/mapper/GovMonitorPointMapper.java 16 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/GovMonitorPointService.java 45 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java 160 ●●●●● patch | view | raw | blame | history
screen-manage/src/main/resources/mapper/GovMonitorPointMapper.xml 22 ●●●●● patch | view | raw | blame | history
screen-common/src/main/java/com/moral/constant/RedisConstants.java
@@ -78,5 +78,10 @@
     * */
    public static final String SPECIAL_DEVICE_INFO = "special_device_alarm_info";
    /*
     * redis中政府站点信息key
     * */
    public static final String GOV_MONITOR_POINT = "gov_monitor_point";
}
screen-manage/src/main/java/com/moral/api/controller/GovMonitorPoionController.java
New file
@@ -0,0 +1,71 @@
package com.moral.api.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.entity.GovMonitorPoint;
import com.moral.api.mapper.GovMonitorPointMapper;
import com.moral.api.service.GovMonitorPointService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
 * @program: screen
 * @description: 政府站点
 * @author: lizijie
 * @create: 2021-09-09 11:31
 **/
@Slf4j
@Api(tags = {"政府站点"})
@RestController
@RequestMapping("/govMonitorPoint")
public class GovMonitorPoionController {
    @Resource
    private GovMonitorPointService govMonitorPointService;
    @Resource
    private GovMonitorPointMapper govMonitorPointMapper;
    @RequestMapping(value = "getGovMonitorPointByCondition", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getSpecialDeviceByCondition(HttpServletRequest request) {
        Map<String,Object> parameters = WebUtils.getParametersStartingWith(request,null);
        Map<String,Object> resultMap = govMonitorPointService.getDataByCondition(parameters);
        if (!resultMap.containsKey("code")){
            return ResultMessage.ok(resultMap);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
    }
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage insert(@RequestBody GovMonitorPoint govMonitorPoint){
        String guid = govMonitorPoint.getGuid();
        String name = govMonitorPoint.getName();
        double longitude = govMonitorPoint.getLongitude();
        double latitude = govMonitorPoint.getLatitude();
        String station_level = govMonitorPoint.getStationLevel();
        if (ObjectUtils.isEmpty(guid) && ObjectUtils.isEmpty(name) && ObjectUtils.isEmpty(longitude) && ObjectUtils.isEmpty(latitude) && ObjectUtils.isEmpty(station_level)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>();
        wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE);
        wrapper_govMonitorPoint.eq("guid",guid).or().eq("name",name);
        List<GovMonitorPoint> govMonitorPoints = govMonitorPointMapper.selectList(wrapper_govMonitorPoint);
        if (govMonitorPoints.size()>0){
            return ResultMessage.fail(ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode(),ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg());
        }
        govMonitorPointService.insert(govMonitorPoint);
        return ResultMessage.ok();
    }
}
screen-manage/src/main/java/com/moral/api/entity/GovMonitorPoint.java
New file
@@ -0,0 +1,101 @@
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 lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * <p>
 *
 * </p>
 *
 * @author moral
 * @since 2021-09-09
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class GovMonitorPoint extends Model<GovMonitorPoint> {
    private static final long serialVersionUID = 1L;
    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 政府站点code
     */
    private String guid;
    /**
     * 名称
     */
    private String name;
    /**
     * 经度
     */
    private Double longitude;
    /**
     * 纬度
     */
    private Double latitude;
    /**
     * 省编码
     */
    private Integer provinceCode;
    /**
     * 市编码
     */
    private Integer cityCode;
    /**
     * 县/区编码
     */
    private Integer areaCode;
    /**
     * 政府站点类型:国控、省控、县控
     */
    private String stationLevel;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 是否删除
     */
    private String isDelete;
    /**
     * 备注
     */
    @TableField("'desc'")
    private String desc;
    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
screen-manage/src/main/java/com/moral/api/mapper/GovMonitorPointMapper.java
New file
@@ -0,0 +1,16 @@
package com.moral.api.mapper;
import com.moral.api.entity.GovMonitorPoint;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author moral
 * @since 2021-09-09
 */
public interface GovMonitorPointMapper extends BaseMapper<GovMonitorPoint> {
}
screen-manage/src/main/java/com/moral/api/service/GovMonitorPointService.java
New file
@@ -0,0 +1,45 @@
package com.moral.api.service;
import com.moral.api.entity.GovMonitorPoint;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Map;
/**
 * <p>
 *  服务类
 * </p>
 *
 * @author moral
 * @since 2021-09-09
 */
public interface GovMonitorPointService extends IService<GovMonitorPoint> {
    /**
      *@Description: 根据条件查询政府站点信息
      *@Param: [map]
      *@return: java.util.Map<java.lang.String,java.lang.Object>
      *@Author: lizijie
      *@Date: 2021/9/9 11:28
     **/
    Map<String,Object> getDataByCondition(Map map);
    /**
      *@Description: 新增政府站点
      *@Param: [govMonitorPoint]
      *@return: void
      *@Author: lizijie
      *@Date: 2021/9/9 15:09
     **/
    void insert(GovMonitorPoint govMonitorPoint);
    /**
      *@Description: 通过id获取政府站点信息
      *@Param: [id]
      *@return: com.moral.api.entity.GovMonitorPoint
      *@Author: lizijie
      *@Date: 2021/9/9 16:35
     **/
    GovMonitorPoint selectGovMonitorPointInfoById(int id);
}
screen-manage/src/main/java/com/moral/api/service/impl/GovMonitorPointServiceImpl.java
New file
@@ -0,0 +1,160 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.GovMonitorPoint;
import com.moral.api.entity.SysArea;
import com.moral.api.mapper.GovMonitorPointMapper;
import com.moral.api.mapper.SysAreaMapper;
import com.moral.api.service.GovMonitorPointService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.util.LogUtils;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.constant.ResponseCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-09-09
 */
@Service
public class GovMonitorPointServiceImpl extends ServiceImpl<GovMonitorPointMapper, GovMonitorPoint> implements GovMonitorPointService {
    @Autowired(required = false)
    private GovMonitorPointMapper govMonitorPointMapper;
    @Autowired(required = false)
    private SysAreaMapper sysAreaMapper;
    @Autowired(required = false)
    private RedisTemplate redisTemplate;
    @Autowired
    private LogUtils logUtils;
    /*
     * 从redis获取设备信息
     * */
    private Map<String, Object> getGovMonitorPointInfoFromRedis(String id) {
        return (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.GOV_MONITOR_POINT, id);
    }
    /*
     * 设备信息存入redis
     */
    private void setGovMonitorPointInfoToRedis(String id, GovMonitorPoint govMonitorPointInfo) {
        redisTemplate.opsForHash().put(RedisConstants.GOV_MONITOR_POINT, id, govMonitorPointInfo);
    }
    /*
     * 从redis删除设备信息
     */
    private void delGovMonitorPointInfoFromRedis(String id) {
        redisTemplate.opsForHash().delete(RedisConstants.GOV_MONITOR_POINT, id);
    }
    @Override
    public Map<String, Object> getDataByCondition(Map map) {
        Map<String,Object> resultMap = new HashMap<>();
        if (!map.containsKey("current")||!map.containsKey("size")){
            resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode());
            resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            return resultMap;
        }
        int current = Integer.parseInt(map.get("current").toString());
        int size = Integer.parseInt(map.get("size").toString());
        Page<GovMonitorPoint> page = new Page<>(current,size);
        QueryWrapper<GovMonitorPoint> wrapper_Condition = new QueryWrapper<>();
        wrapper_Condition.eq("is_delete",Constants.NOT_DELETE);
        if (!ObjectUtils.isEmpty(map.get("name"))){
            wrapper_Condition.like("name",map.get("name").toString());
        }
        if (!ObjectUtils.isEmpty(map.get("stationLevel"))){
            wrapper_Condition.like("station_level",map.get("stationLevel").toString());
        }
        wrapper_Condition.orderByDesc("create_time");
        Page resultPage = govMonitorPointMapper.selectPage(page,wrapper_Condition);
        int totalNumber = govMonitorPointMapper.selectCount(wrapper_Condition);
        List<GovMonitorPoint> govMonitorPoints = resultPage.getRecords();
        SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<Map<String,Object>> govMonitorPointList = new ArrayList<>();
        for (GovMonitorPoint govMonitorPoint:govMonitorPoints) {
            Map govMonitorPointMap = JSON.parseObject(JSON.toJSONString(govMonitorPoint),Map.class);
            String createTime = SDF.format(govMonitorPoint.getCreateTime());
            String updateTime = SDF.format(govMonitorPoint.getUpdateTime());
            govMonitorPointMap.put("createTime",createTime);
            govMonitorPointMap.put("updateTime",updateTime);
            String position = "";
            if (!ObjectUtils.isEmpty(govMonitorPoint.getProvinceCode())){
                QueryWrapper<SysArea> wrapper_province = new QueryWrapper<>();
                wrapper_province.eq("area_code",govMonitorPoint.getProvinceCode());
                SysArea sysArea_provice = sysAreaMapper.selectOne(wrapper_province);
                if (!ObjectUtils.isEmpty(sysArea_provice)){
                    position = position+sysArea_provice.getAreaName();
                    if (!ObjectUtils.isEmpty(govMonitorPoint.getCityCode())){
                        QueryWrapper<SysArea> wrapper_city = new QueryWrapper<>();
                        wrapper_city.eq("area_code",govMonitorPoint.getCityCode());
                        SysArea sysArea_city = sysAreaMapper.selectOne(wrapper_city);
                        if (!ObjectUtils.isEmpty(sysArea_city)){
                            position = position+"/"+sysArea_city.getAreaName();
                            if (!ObjectUtils.isEmpty(govMonitorPoint.getAreaCode())){
                                QueryWrapper<SysArea> wrapper_area = new QueryWrapper<>();
                                wrapper_area.eq("area_code",govMonitorPoint.getAreaCode());
                                SysArea sysArea_area = sysAreaMapper.selectOne(wrapper_area);
                                if (!ObjectUtils.isEmpty(sysArea_area)){
                                    position = position+"/"+sysArea_area.getAreaName();
                                }
                            }
                        }
                    }
                }
            }
            govMonitorPointMap.put("position",position);
            govMonitorPointList.add(govMonitorPointMap);
        }
        resultMap.put("govMonitorPointList",govMonitorPointList);
        resultMap.put("totalNumber",totalNumber);
        resultMap.put("current",current);
        int totalPageNumber = totalNumber/size;
        if(totalNumber%size != 0){
            totalPageNumber += 1;
        }
        resultMap.put("totalPageNumber",totalPageNumber);
        return resultMap;
    }
    @Override
    public void insert(GovMonitorPoint govMonitorPoint) {
        int count = govMonitorPointMapper.insert(govMonitorPoint);
        //数据插入redis
        setGovMonitorPointInfoToRedis(govMonitorPoint.getId().toString(),selectGovMonitorPointInfoById(govMonitorPoint.getId()));
        if (count > 0){
            //操作日志记录
            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
            StringBuilder content = new StringBuilder();
            content.append("添加了政府站点:").append("id:").append(govMonitorPoint.getId()+";").append(govMonitorPoint.getName()+";").append(":").append("guid:").append(govMonitorPoint.getGuid()+";");
            logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
        }
    }
    @Override
    public GovMonitorPoint selectGovMonitorPointInfoById(int id) {
        GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectById(id);
        return govMonitorPoint;
    }
}
screen-manage/src/main/resources/mapper/GovMonitorPointMapper.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.GovMonitorPointMapper">
        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.moral.api.entity.GovMonitorPoint">
                    <id column="id" property="id" />
                    <result column="gov_code" property="govCode" />
                    <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="gov_type" property="govType" />
                    <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>