Commit b3b85d6b by YANGYANG

在线离线设备批量入库 查询 提交

parent 6f67e001
package com.founder.commonutils.ZdryAndZdryApiVo;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author yangyang
* @since 2021-06-02
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="UsersAndOnlineVo对象", description="UsersAndOnlineVo对象")
public class UsersAndOnlineVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "姓名")
private String xm;
@ApiModelProperty(value = "性别 1男 2女 0未知")
private Integer xb;
@ApiModelProperty(value = "家庭住址")
private String jtZz;
@ApiModelProperty(value = "是否有前科 1是 0否")
private Integer sfyQk;
@ApiModelProperty(value = "现住址")
private String xzz;
@ApiModelProperty(value = "病史")
private String bs;
@ApiModelProperty(value = "病情等级 1低 2中 3高 4极高")
private Integer bqDj;
@ApiModelProperty(value = "监护人1姓名")
private String jhr1Xm;
@ApiModelProperty(value = "监护人1关系")
private String jhr1Gx;
@ApiModelProperty(value = "监护人1联系电话")
private String jhr1Lxdh;
@ApiModelProperty(value = "监护人1紧急电话")
private String jhr1Jjdh;
@ApiModelProperty(value = "监护人2姓名")
private String jhr2Xm;
@ApiModelProperty(value = "监护人2关系")
private String jhr2Gx;
@ApiModelProperty(value = "监护人2联系电话")
private String jhr2Lxdh;
@ApiModelProperty(value = "监护人2紧急电话")
private String jhr2Jjdh;
@ApiModelProperty(value = "设备IMEI")
private String sbImei;
@ApiModelProperty(value = "设备型号")
private String sbXh;
@ApiModelProperty(value = "身份证号码")
private String sfzhm;
@ApiModelProperty(value = "是否在线 1在线 0离线")
private String online;
@ApiModelProperty(value = "是否佩戴 1佩戴 0位佩戴")
private String WearFlag;
@ApiModelProperty(value = "最新发生时间")
private String locationUpdatedAt;
@ApiModelProperty(value = "最新位置经度")
private String lastLocationX;
@ApiModelProperty(value = "最新位置纬度")
private String lastLocationY;
@ApiModelProperty(value = "最新位置地址")
private String lastAddress;
}
package com.founder.commonutils.ZdryApiEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
......@@ -12,35 +18,45 @@ import java.io.Serializable;
* </p>
*
* @author yangyang
* @since 2021-06-01
* @since 2021-06-02
*/
@Data
@ApiModel(value="OnlineAndWear对象", description="OnlineAndWear对象")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="gk_online对象", description="gk_online对象")
@TableName("gk_online")
public class OnlineAndWear implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "设备Imei")
private String id;
@TableField(value = "sb_imei")
private String sbImei;
@ApiModelProperty(value = "是否在线 1在线 0离线")
@TableField(value = "online")
private String online;
@ApiModelProperty(value = "是否佩戴 1佩戴 0位佩戴")
@TableField(value = "wear_flag")
private String WearFlag;
@ApiModelProperty(value = "最新发生时间")
@TableField(value = "location_updated_at")
private String locationUpdatedAt;
@ApiModelProperty(value = "最新位置经度")
@TableField(value = "last_location_x")
private String lastLocationX;
@ApiModelProperty(value = "最新位置纬度")
@TableField(value = "last_location_y")
private String lastLocationY;
@ApiModelProperty(value = "最新位置地址")
@TableField(value = "last_address")
private String lastAddress;
@ApiModelProperty(value = "姓名")
@TableField(value = "xm")
private String xm;
}
......@@ -3,6 +3,7 @@ package com.founder.zdry.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.founder.commonutils.ZdryAndZdryApiVo.UsersAndOnlineVo;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.publicEntity.ResultCode;
import com.founder.commonutils.zdryEntity.Users;
......@@ -16,7 +17,9 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -204,6 +207,36 @@ public class UsersController {
}
}
@ApiOperation(value = "分页用户是否在线列表")
@GetMapping("userPageOnlineList/{page}/{limit}")
public MapRestResult userPageOnlineList(
@ApiParam(name = "page", value = "当前页码", required = true)
@PathVariable Integer page,
@ApiParam(name = "limit", value = "每页记录数", required = true)
@PathVariable Integer limit,
@ApiParam(name = "xm", value = "姓名")
@RequestParam(required = false) String xm,
@ApiParam(name = "sbimei", value = "设备IMEI")
@RequestParam(required = false) String sbimei,
@ApiParam(name = "online", value = "1在线 0离线")
@RequestParam(required = false) String online,
@ApiParam(name = "wearFlag", value = "1佩戴 0未佩戴")
@RequestParam(required = false) String wearFlag){
Map map = new HashMap();
map.put("page",page);
map.put("limit",limit);
map.put("xm",xm);
map.put("sbimei",sbimei);
map.put("online",online);
map.put("wearFlag",wearFlag);
List<UsersAndOnlineVo> list = usersService.userPageOnlineList(map);
Integer total = usersService.userPageOnlineListCount(xm,sbimei,online,wearFlag);
return MapRestResult.build(ResultCode.SUCCESS,"成功获取用户列表信息",total,list);
}
}
package com.founder.zdry.mapper;
import com.founder.commonutils.ZdryAndZdryApiVo.UsersAndOnlineVo;
import com.founder.commonutils.zdryEntity.Users;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -13,6 +20,11 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2021-05-30
*/
@Mapper
@Component
public interface UsersMapper extends BaseMapper<Users> {
List<UsersAndOnlineVo> userPageOnlineList(Map map);
Integer userPageOnlineListCount(@Param("xm") String xm, @Param("sbimei")String sbimei, @Param("online") String online, @Param("wearFlag") String wearFlag);
}
<?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.founder.zdry.mapper.UsersMapper">
<sql id="queryTlWhere">
<if test="xm!= null and xm!=''">
AND users.xm LIKE '%' || #{xm , jdbcType=VARCHAR } || '%'
</if>
<if test="sbimei!= null and sbimei != ''">
AND users.sb_imei= #{ sbimei , jdbcType=INTEGER }
</if>
<if test="online!= null and online != ''">
AND online.online= #{ online , jdbcType=INTEGER }
</if>
<if test="wearFlag!= null and wearFlag != ''">
AND online.wear_flag= #{ wearFlag , jdbcType=INTEGER }
</if>
</sql>
<select id="userPageOnlineList" parameterType="java.util.Map" resultType="com.founder.commonutils.ZdryAndZdryApiVo.UsersAndOnlineVo">
select
users.xm as xm,
users.xb as xb,
users. jt_zz as jtZz,
users.sfy_qk as sfyQk,
users.xzz as xzz,
users.bs as bs,
users.bq_dj as bqDj,
users.jhr1_xm as jhr1Xm,
users.jhr1_gx as jhr1Gx,
users.jhr1_lxdh as jhr1Lxdh,
users.jhr1_jjdh as jhr1Jjdh,
users.jhr2_xm as jhr2Xm,
users. jhr2_gx as jhr2Gx,
users.jhr2_lxdh as jhr2Lxdh,
users. jhr2_jjdh as jhr2Jjdh,
users. sb_imei as sbImei,
users. sb_xh as sbXh,
users.sfzhm as sfzhm,
online.online as online,
online.Wear_flag as WearFlag,
online.location_updated_at as locationUpdatedAt,
online.last_location_x as lastLocationX,
online.last_location_y as lastLocationY,
online.last_address as lastAddress
from gk_users users,gk_online online
where users.sb_imei = online.sb_imei
<include refid="queryTlWhere"/>
limit #{ page },#{ limit}
</select>
<select id="userPageOnlineListCount" parameterType="java.lang.String" resultType="java.lang.Integer">
select
count(*)
from gk_users users,gk_online online
where users.sb_imei = online.sb_imei
<include refid="queryTlWhere"/>
</select>
</mapper>
package com.founder.zdry.service;
import com.founder.commonutils.ZdryAndZdryApiVo.UsersAndOnlineVo;
import com.founder.commonutils.zdryEntity.Users;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务类
......@@ -12,5 +16,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2021-05-30
*/
public interface UsersService extends IService<Users> {
List<UsersAndOnlineVo> userPageOnlineList(Map map);
Integer userPageOnlineListCount(String xm, String sbimei, String online, String wearFlag);
}
package com.founder.zdry.service.impl;
import com.founder.commonutils.ZdryAndZdryApiVo.UsersAndOnlineVo;
import com.founder.commonutils.zdryEntity.Users;
import com.founder.zdry.mapper.UsersMapper;
import com.founder.zdry.service.UsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务实现类
......@@ -16,5 +21,16 @@ import org.springframework.stereotype.Service;
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {
@Autowired
private UsersMapper usersMapper;
@Override
public List<UsersAndOnlineVo> userPageOnlineList(Map map) {
return usersMapper.userPageOnlineList(map);
}
@Override
public Integer userPageOnlineListCount(String xm, String sbimei, String online, String wearFlag) {
return usersMapper.userPageOnlineListCount(xm,sbimei,online,wearFlag);
}
}
......@@ -68,21 +68,8 @@ public class ZdryApiController {
@ApiOperation(value = "批量获取设备离线在线状态数据")
@PostMapping(value = "/onlineAndWeardata")
public List<OnlineAndWear> onlineAndWeardata(@ApiParam(name = "online", value = "是否在线 1在线 0离线")
@RequestParam(required = false) String online,
@ApiParam(name = "wearFlag", value = "是否佩戴 1佩戴 0未佩戴")
@RequestParam(required = false) String wearFlag,
@ApiParam(name = "sbImei", value = "设备IMEI")
@RequestParam(required = false) String sbImei,
@ApiParam(name = "xm", value = "姓名")
@RequestParam(required = false) String xm,
@ApiParam(name = "current", value = "当前页", required = true)
@RequestParam int current,
@ApiParam(name = "pageNum", value = "每页多少条", required = true)
@RequestParam int pageNum
) {
return zdryApiService.onlineAndWeardata(online,wearFlag,sbImei,xm,current,pageNum);
public MapRestResult onlineAndWeardata() {
return zdryApiService.onlineAndWeardata();
}
}
package com.founder.zdryapi.mapper;
import com.founder.commonutils.ZdryApiEntity.OnlineAndWear;
import com.founder.commonutils.zdryEntity.Users;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
/**
* <p>
* Mapper 接口
* </p>
*
* @author yangyang
* @since 2021-06-02
*/
@Mapper
@Component
public interface ZdryApiMapper extends BaseMapper<OnlineAndWear> {
}
<?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.founder.zdryapi.mapper.ZdryApiMapper">
</mapper>
......@@ -26,5 +26,5 @@ public interface ZdryApiService {
MapRestResult locationdata(String deviceId,String time_begin);
List<OnlineAndWear> onlineAndWeardata(String online, String wearFlag, String sbImei, String xm,int current,int pageNum);
MapRestResult onlineAndWeardata();
}
......@@ -2,11 +2,13 @@ package com.founder.zdryapi.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.commonutils.ZdryApiEntity.LocationData;
import com.founder.commonutils.ZdryApiEntity.OnlineAndWear;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.zdryapi.mapper.ZdryApiMapper;
import com.founder.zdryapi.service.ZdryApiService;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -64,6 +66,9 @@ public class ZdryApiServiceImpl implements ZdryApiService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private ZdryApiMapper zdryApiMapper;
public Device getDevice(String deviceId){
Device device = new Device();
try {
......@@ -254,8 +259,8 @@ public class ZdryApiServiceImpl implements ZdryApiService {
}
@Override
public List<OnlineAndWear> onlineAndWeardata(String online, String wearFlag, String sbImei, String xm,int current,int pageNum) {
List<OnlineAndWear> OnlineAndWearResults=new ArrayList<>();
public MapRestResult onlineAndWeardata() {
List<OnlineAndWear> OnlineAndWearList=new ArrayList<>();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 循环请求
......@@ -275,14 +280,13 @@ public class ZdryApiServiceImpl implements ZdryApiService {
if(getToken().equals("success")){
resultString = restTemplate.getForEntity(url,String.class).getBody();
}else{
return OnlineAndWearResults;
return MapRestResult.build(201,"登陆失败",1);
};
}
JSONObject resultLast = JSONObject.parseObject(StringEscapeUtils.unescapeJava(resultString));
if (resultLast.getString("success").equals("true")) {
JSONArray jsonArray = resultLast.getJSONArray("objs");//当前页返回的结果总数
if(null!=jsonArray&&jsonArray.size()>0) {
List<OnlineAndWear> OnlineAndWearList=new ArrayList<>();
currentPageTotal = jsonArray.size();
for (Object obj : jsonArray) {
OnlineAndWear onlineAndWear = new OnlineAndWear();
......@@ -298,7 +302,7 @@ public class ZdryApiServiceImpl implements ZdryApiService {
JSONArray jsonArrayPoint = point.getJSONArray("coordinates");
String x = jsonArrayPoint.get(0).toString();
String y = jsonArrayPoint.get(1).toString();
onlineAndWear.setId(id);
onlineAndWear.setSbImei(id);
onlineAndWear.setLocationUpdatedAt(sf.format(new Date(Long.parseLong(locationUpdatedAt))));
onlineAndWear.setWearFlag(wearFlags);
if(onlines.equals("true")){
......@@ -312,6 +316,23 @@ public class ZdryApiServiceImpl implements ZdryApiService {
onlineAndWear.setXm(name);
OnlineAndWearList.add(onlineAndWear);
}
if(OnlineAndWearList.size()>0){
OnlineAndWearList.stream().forEach(p->{
// 先查看是否存在 不存在插入 存在更新
QueryWrapper<OnlineAndWear> wrapper = new QueryWrapper<>();
wrapper.eq("sb_imei",p.getSbImei());
// 查询
OnlineAndWear onlineAndWear = zdryApiMapper.selectOne(wrapper);
if(null != onlineAndWear){
// 执行更新
zdryApiMapper.updateById(p);
}else{
// 插入数据
zdryApiMapper.insert(p);
}
});
}
}
}
}
......@@ -325,7 +346,7 @@ public class ZdryApiServiceImpl implements ZdryApiService {
}catch (Exception e){
e.printStackTrace();
}
return OnlineAndWearResults;
return MapRestResult.build(200,"批量获取设备离线在线状态数据",OnlineAndWearList.size());
}
public String getToken() {
......
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