This commit is contained in:
ScorpioMiku
2019-09-06 21:22:11 +08:00
13 changed files with 753 additions and 394 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
package com.oldpeoplehome.dao;
import com.oldpeoplehome.dto.LocationFilter;
import com.oldpeoplehome.entity.Location;
import java.util.List;
/**
* Created By Jiangyuwei on 2019/9/6 11:30
* Description:
*/
public interface LocationDao {
List<Location> findByParent(LocationFilter locationFilter);
List<Location> findByTime(LocationFilter locationFilter);
List<Location> findByParentAndTime(LocationFilter locationFilter);
void insert(Location location);
}

View File

@@ -0,0 +1,64 @@
package com.oldpeoplehome.dto;
import java.sql.Date;
import java.sql.Timestamp;
/**
* Created By Jiangyuwei on 2019/9/6 11:27
* Description:
*/
public class LocationFilter {
private Timestamp startTime;
private Timestamp endTime;
private long parentId;
public LocationFilter() {
}
public LocationFilter(long parentId) {
this.parentId = parentId;
}
public LocationFilter(String startTime, long parentId) {
this.startTime = Timestamp.valueOf(startTime);
this.parentId = parentId;
}
public LocationFilter(String startTime, String endTime, long parentId) {
this.startTime = Timestamp.valueOf(startTime);
this.endTime = Timestamp.valueOf(endTime);
this.parentId = parentId;
}
public Timestamp getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = Timestamp.valueOf(startTime);
}
public void setStartTime(Timestamp startTime) {
this.startTime = startTime;
}
public Timestamp getEndTime() {
return endTime;
}
public void setEndTime(Timestamp endTime) {
this.endTime = endTime;
}
public void setEndTime(String endTime) {
this.endTime = Timestamp.valueOf(endTime);
}
public long getParentId() {
return parentId;
}
public void setParentId(long parentId) {
this.parentId = parentId;
}
}

View File

@@ -0,0 +1,80 @@
package com.oldpeoplehome.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.sql.Timestamp;
/**
* Created By Jiangyuwei on 2019/9/6 11:15
* Description:
*/
public class Location {
private Long parentId;
private Float longitude;
private Float latitude;
private Timestamp time;
public Location() {
}
public Location(Long parentId, Float longitude, Float latitude, Timestamp time) {
this.parentId = parentId;
this.longitude = longitude;
this.latitude = latitude;
this.time = time;
}
public Location(Long parentId, Float longitude, Float latitude, String time) {
this.parentId = parentId;
this.longitude = longitude;
this.latitude = latitude;
this.time = Timestamp.valueOf(time);
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public Float getLongitude() {
return longitude;
}
public void setLongitude(Float longitude) {
this.longitude = longitude;
}
public Float getLatitude() {
return latitude;
}
public void setLatitude(Float latitude) {
this.latitude = latitude;
}
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
public Timestamp getTime() {
return time;
}
public void setTime(Timestamp time) {
this.time = time;
}
public void setTime(String time) {
this.time = Timestamp.valueOf(time);
}
@Override
public String toString() {
return "Location{" +
"parentId=" + parentId +
", longitude=" + longitude +
", latitude=" + latitude +
", time=" + time +
'}';
}
}

View File

@@ -0,0 +1,20 @@
package com.oldpeoplehome.service;
import com.oldpeoplehome.dto.LocationFilter;
import com.oldpeoplehome.entity.Location;
import java.util.List;
/**
* Created By Jiangyuwei on 2019/9/6 11:35
* Description:
*/
public interface LocationService {
List<Location> findByParent(LocationFilter locationFilter);
List<Location> findByTime(LocationFilter locationFilter);
List<Location> findByParentAndTime(LocationFilter locationFilter);
void insert(Location location);
}

View File

@@ -0,0 +1,41 @@
package com.oldpeoplehome.service.impl;
import com.oldpeoplehome.dao.LocationDao;
import com.oldpeoplehome.dto.LocationFilter;
import com.oldpeoplehome.entity.Location;
import com.oldpeoplehome.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created By Jiangyuwei on 2019/9/6 11:36
* Description:
*/
@Service
public class LocationServiceImpl implements LocationService {
@Autowired
private LocationDao locationDao;
@Override
public List<Location> findByParent(LocationFilter locationFilter) {
return locationDao.findByParent(locationFilter);
}
@Override
public List<Location> findByTime(LocationFilter locationFilter) {
return locationDao.findByTime(locationFilter);
}
@Override
public List<Location> findByParentAndTime(LocationFilter locationFilter) {
return locationDao.findByParentAndTime(locationFilter);
}
@Override
public void insert(Location location) {
locationDao.insert(location);
}
}

View File

@@ -0,0 +1,61 @@
package com.oldpeoplehome.web;
import com.oldpeoplehome.dto.LocationFilter;
import com.oldpeoplehome.entity.Location;
import com.oldpeoplehome.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
/**
* Created By Jiangyuwei on 2019/9/6 13:51
* Description:
*/
@RestController
@RequestMapping("/location")
public class LocationController {
@Autowired
private LocationService locationService;
@RequestMapping("/get/{id}")
@ResponseBody
public List findByParentId(HttpServletRequest request, @PathVariable("id") String id) {
List<Location> list;
String startDate = request.getParameter("start");
String endDate = request.getParameter("end");
if (endDate == null){
if (startDate == null) {
LocationFilter locationFilter = new LocationFilter(Long.valueOf(id));
list = locationService.findByParent(locationFilter);
}
else {
LocationFilter locationFilter = new LocationFilter(startDate, Long.valueOf(id));
list = locationService.findByParentAndTime(locationFilter);
}
}
else{
LocationFilter locationFilter = new LocationFilter(startDate, endDate, Long.valueOf(id));
list = locationService.findByTime(locationFilter);
}
return list;
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public Location add(@RequestParam Map<String, Object> params){
long parentId = Long.valueOf(String.valueOf(params.get("parent")));
float longitude = Float.valueOf(String.valueOf(params.get("longitude")));
float latitude = Float.valueOf(String.valueOf(params.get("latitude")));
String time = String.valueOf(params.get("time"));
Location location = new Location(parentId,longitude,latitude,time);
locationService.insert(location);
return location;
}
}

View File

@@ -1,4 +1,4 @@
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmtest?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=
jdbc.password=root

View File

@@ -0,0 +1,29 @@
<?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.oldpeoplehome.dao.LocationDao">
<resultMap id="BaseResultMap" type="com.oldpeoplehome.entity.Location">
<id column="pid" property="parentId" jdbcType="BIGINT"/>
<result column="longitude" property="longitude" jdbcType="BIGINT"/>
<result column="latitude" property="latitude" jdbcType="BIGINT"/>
<result column="time" property="time" jdbcType="TIMESTAMP"/>
</resultMap>
<select id="findByParent" resultMap="BaseResultMap" parameterType="com.oldpeoplehome.dto.LocationFilter">
select *
from location where pid = #{parentId}
</select>
<select id="findByTime" resultMap="BaseResultMap" parameterType="com.oldpeoplehome.dto.LocationFilter">
select *
from location where pid = #{parentId} and DATE_FORMAT(time,'%Y-%m-%d %T') between #{startTime} and #{endTime}
</select>
<select id="findByParentAndTime" resultMap="BaseResultMap" parameterType="com.oldpeoplehome.dto.LocationFilter">
select l.*, p.* from location l left join parent p on l.pid = p.id where l.pid = #{parentId} and l.date = #{startTime}
</select>
<insert id="insert" parameterType="Location">
insert into location(pid, longitude,latitude, time)
values (#{parentId}, #{longitude},#{latitude}, #{time})
</insert>
</mapper>

View File

@@ -106,4 +106,12 @@ CREATE TABLE `admin` (
PRIMARY KEY (`account`),
UNIQUE INDEX `index_acc`(`account`) USING BTREE
);
CREATE TABLE `location` (
`pid` bigint(0) NOT NULL,
`longitude` float NULL COMMENT '经度',
`latitude` float NULL COMMENT '纬度',
`time` datetime(0) NULL,
INDEX `date`(`time`) USING BTREE,
CONSTRAINT `pid_2` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);

View File

@@ -17,7 +17,7 @@ public class HeartRateServiceTest extends BaseTest {
@Test
public void test(){
HeartRate heartRate = new HeartRate(1, "2019-8-22 10:00:00", 20.3, 21,21);
HeartRate heartRate = new HeartRate(1, "2019-8-22 10:00:00", 1,20.3, 21,21);
heartRateService.insert(heartRate);
// HeartRateFilter heartRateFilter = new HeartRateFilter(1);
// System.out.println(heartRateService.findByParent(heartRateFilter));

View File

@@ -0,0 +1,26 @@
package com.oldpeoplehome.service;
import com.oldpeoplehome.BaseTest;
import com.oldpeoplehome.dto.LocationFilter;
import com.oldpeoplehome.entity.Location;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Created By Jiangyuwei on 2019/9/6 11:38
* Description:
*/
public class LocationServiceTest extends BaseTest {
@Autowired
private LocationService locationService;
@Test
public void test(){
// Location location = new Location(new Long(1),13.2323f,123.45f,"2019-4-5 19:2:2");
// locationService.insert(location);
LocationFilter locationFilter = new LocationFilter("2019-4-5 19:2:7","2019-4-6 19:2:2",1);
System.out.println(locationService.findByTime(locationFilter));
}
}

View File

@@ -77,7 +77,7 @@
| Parent | /parent/add | POST | 添加老人 | parentSex老人性别parentPassword老人密码parentAccount账号parentName姓名parentBirth生日parentLongId身份证 |
| Parent | /parent/update/1 | POST | 更新id=1的老人信息 | **要更新的字段严格按照命名格式传参**比如name就传入parentName |
| Parent | /parent/delete/1 | DELETE | 删除id=1的老人 | |
| Parent | /parent/login | POST | 老人登陆 | 登陆成功返回老人的所有信息登陆失败返回null不返回 account:bao,password:123 |
| Parent | /parent/login | POST | 老人登陆 | 登陆成功返回老人的所有信息登陆失败返回null不返回 account:bao,password:123 |
| Child | /child/get/1 | GET | 查询id=1的子女 | |
| Child | /child/get_longid/111 | GET | 查询身份证=111的child的详细信息 | |
| Child | /child/get_name/小蒋 | GET | 查询姓名=小蒋的child的详细信息 | |
@@ -85,7 +85,7 @@
| Child | /child/add | POST | | childSexchildPasswordchildAccountchildNamechildLongIdchildPhone |
| Child | /child/update/1 | POST | 更新id=1的子女信息 | **要更新的字段严格按照命名格式传参**比如name就传入parentName |
| Child | /child/delete/1 | DELETE | 删除id=1的子女信息 | |
| Child | /child/login | POST | 登陆子女 | 登陆成功返回子女信息,失败返回空(不返回) account:bao,password:123 |
| Child | /child/login | POST | 登陆子女 | 登陆成功返回子女信息,失败返回空(不返回) account:bao,password:123 |
| ChildAndParent | /child_parent/child/1 | GET | 查看子女id=1对应的老人 | |
| ChildAndParent | /child_parent/parent/1 | GET | 查看老人id=1对应的子女 | |
| ChildAndParent | /child_parent/add | POST | 添加老人子女对应关系 | 子女idchild老人idparent关系relation |
@@ -97,3 +97,5 @@
| Sleep | /sleep/add | POST | 添加老人睡眠信息 | parentdatedeeplightawake |
| HeartRate | /heartrate/get/1 | GET | 查找id=1的心率信息 | 参数格式yyyy-mm-dd hh-mm-ss 加上start参数可以查看某一时刻。加上start和end参数可以查看某一时间段。 |
| HeartRate | /heartrate/add | POST | 添加老人睡眠信息 | parentIdtimerate1(收缩压)rate2(舒张压)oxy(血氧) |
| Location | /location/get/1 | GET | 查找id=1的老人位置信息 | 参数格式yyyy-mm-dd hh-mm-ss 加上start参数可以查看某一时刻。加上start和end参数可以查看某一时间段。 |
| Location | /location/add | POST | 添加老人位置信息 | parentlongitudelatitudetime。添加成功返回Location对象 |