9 changed files with 408 additions and 7 deletions
@ -0,0 +1,71 @@ |
|||||
|
package yq.web.controller.behaviorDetection; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import yq.common.core.controller.BaseController; |
||||
|
import yq.common.core.domain.AjaxResult; |
||||
|
import yq.common.core.page.TableDataInfo; |
||||
|
import yq.framework.config.ServerConfig; |
||||
|
import yq.system.domain.BehaviorDetection; |
||||
|
|
||||
|
import yq.system.service.IBehaviorDetectionService; |
||||
|
import yq.system.service.IMineFaceService; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
import static yq.common.utils.PageUtils.startPage; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/14 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/system/behaviorDetection") |
||||
|
public class BehaviorDetectionController extends BaseController { |
||||
|
|
||||
|
@Autowired |
||||
|
private IMineFaceService mineFaceService; |
||||
|
|
||||
|
@Autowired |
||||
|
private IBehaviorDetectionService behaviorDetectionService; |
||||
|
/** |
||||
|
* 查询【请填写功能名称】列表 |
||||
|
*/ |
||||
|
@GetMapping("/list") |
||||
|
public TableDataInfo list(BehaviorDetection behaviorDetection) |
||||
|
{ |
||||
|
startPage(); |
||||
|
List<BehaviorDetection> list = behaviorDetectionService.list(behaviorDetection); |
||||
|
return getDataTable(list); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查询【请填写功能名称】列表 |
||||
|
*/ |
||||
|
@GetMapping("/getFaceLatest") |
||||
|
public AjaxResult getFaceLatest(String behaviorType) |
||||
|
{ |
||||
|
BehaviorDetection behaviorDetection = behaviorDetectionService.getFaceLatest(behaviorType); |
||||
|
return AjaxResult.success(behaviorDetection); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查询【请填写功能名称】列表 |
||||
|
*/ |
||||
|
@GetMapping("/saveBehavior") |
||||
|
public void saveBehavior(BehaviorDetection behaviorDetection) |
||||
|
{ |
||||
|
behaviorDetectionService.saveBehavior(behaviorDetection); |
||||
|
|
||||
|
} |
||||
|
@GetMapping("/updateBehavior") |
||||
|
public void updateBehavior(BehaviorDetection behaviorDetection) |
||||
|
{ |
||||
|
behaviorDetectionService.updateBehavior(behaviorDetection); |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
package yq.system.domain; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
import yq.common.annotation.Excel; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/14 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BehaviorDetection { |
||||
|
|
||||
|
private Long id; |
||||
|
//人脸库id
|
||||
|
private Long faceId; |
||||
|
|
||||
|
//人名
|
||||
|
private String faceName; |
||||
|
private String age; |
||||
|
|
||||
|
//饮水量
|
||||
|
private Integer waterIntake; |
||||
|
|
||||
|
//行为类型 1:饮水 2:睡眠 3:行走 4:坐姿
|
||||
|
private int behaviorType; |
||||
|
|
||||
|
|
||||
|
@Excel(name = "创建时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
private Date createTime; |
||||
|
@Excel(name = "开始时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
private Date startTime; |
||||
|
|
||||
|
@Excel(name = "结束时间", width = 20, dateFormat = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
private Date endTime; |
||||
|
|
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
package yq.system.domain.vo; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/15 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BehaviorDetectionVo { |
||||
|
private String faceName; |
||||
|
|
||||
|
private Long age; |
||||
|
|
||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
private Date latestTime; |
||||
|
private Long totalWaterIntake; |
||||
|
private Long totalWaterCount; |
||||
|
|
||||
|
private Boolean isAboveThreshold; |
||||
|
|
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package yq.system.mapper; |
||||
|
|
||||
|
import yq.system.domain.BehaviorDetection; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/14 |
||||
|
*/ |
||||
|
public interface BehaviorDetectionMapper { |
||||
|
List<BehaviorDetection> list(BehaviorDetection behaviorDetection); |
||||
|
|
||||
|
BehaviorDetection getFaceLatest(String behaviorType); |
||||
|
|
||||
|
void saveBehavior(BehaviorDetection behaviorDetection); |
||||
|
|
||||
|
void updateBehavior(BehaviorDetection behaviorDetection); |
||||
|
|
||||
|
List<Map<String,Object>> behaviorTypeCount(); |
||||
|
|
||||
|
List<Map<String,Object>> behaviorCount(); |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
package yq.system.service; |
||||
|
|
||||
|
import yq.system.domain.BehaviorDetection; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/14 |
||||
|
*/ |
||||
|
public interface IBehaviorDetectionService { |
||||
|
|
||||
|
List<BehaviorDetection> list(BehaviorDetection behaviorDetection); |
||||
|
BehaviorDetection getFaceLatest(String behaviorType); |
||||
|
|
||||
|
void saveBehavior(BehaviorDetection behaviorDetection); |
||||
|
|
||||
|
void updateBehavior(BehaviorDetection behaviorDetection); |
||||
|
|
||||
|
List<Map<String,Object>>behaviorTypeCount(); |
||||
|
|
||||
|
List<Map<String,Object>>behaviorCount(); |
||||
|
|
||||
|
} |
@ -0,0 +1,54 @@ |
|||||
|
package yq.system.service.impl; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import yq.system.domain.BehaviorDetection; |
||||
|
import yq.system.mapper.BehaviorDetectionMapper; |
||||
|
|
||||
|
import yq.system.service.IBehaviorDetectionService; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @auther yq |
||||
|
* @data 2025/3/14 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class BehaviorDetectionServiceImpl implements IBehaviorDetectionService { |
||||
|
|
||||
|
@Autowired |
||||
|
private BehaviorDetectionMapper behaviorDetectionMapper; |
||||
|
@Override |
||||
|
public List<BehaviorDetection> list(BehaviorDetection behaviorDetection) { |
||||
|
List<BehaviorDetection> detectionList = behaviorDetectionMapper.list(behaviorDetection); |
||||
|
|
||||
|
|
||||
|
return detectionList; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BehaviorDetection getFaceLatest(String behaviorType) { |
||||
|
return behaviorDetectionMapper.getFaceLatest(behaviorType); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void saveBehavior(BehaviorDetection behaviorDetection) { |
||||
|
behaviorDetectionMapper.saveBehavior(behaviorDetection); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateBehavior(BehaviorDetection behaviorDetection) { |
||||
|
behaviorDetectionMapper.updateBehavior(behaviorDetection); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Map<String,Object>> behaviorTypeCount() { |
||||
|
return behaviorDetectionMapper.behaviorTypeCount(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Map<String,Object>> behaviorCount() { |
||||
|
return behaviorDetectionMapper.behaviorCount(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,96 @@ |
|||||
|
<?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="yq.system.mapper.BehaviorDetectionMapper"> |
||||
|
<resultMap type="BehaviorDetection" id="BehaviorDetectionResult"> |
||||
|
<result property="id" column="id" /> |
||||
|
<result property="faceId" column="face_id" /> |
||||
|
<result property="faceName" column="face_name" /> |
||||
|
<result property="age" column="age" /> |
||||
|
<result property="createTime" column="create_time" /> |
||||
|
<result property="waterIntake" column="water_intake" /> |
||||
|
<result property="behaviorType" column="behavior_type" /> |
||||
|
<result property="startTime" column="start_time" /> |
||||
|
<result property="endTime" column="end_time" /> |
||||
|
|
||||
|
</resultMap> |
||||
|
<resultMap type="BehaviorDetection" id="BehaviorResult"> |
||||
|
<result property="faceName" column="face_name" /> |
||||
|
<result property="age" column="age" /> |
||||
|
<result property="createTime" column="create_time" /> |
||||
|
<result property="waterIntake" column="water_intake" /> |
||||
|
<result property="behaviorType" column="behavior_type" /> |
||||
|
<result property="startTime" column="start_time" /> |
||||
|
<result property="endTime" column="end_time" /> |
||||
|
|
||||
|
</resultMap> |
||||
|
<insert id="saveBehavior"> |
||||
|
insert into behavior_detection (face_id,face_name,behavior_type, water_intake, create_time,start_time,end_time) |
||||
|
values (#{faceId},#{faceName},#{behaviorType}, #{waterIntake}, now(),#{startTime},#{endTime}) |
||||
|
</insert> |
||||
|
<update id="updateBehavior"> |
||||
|
update behavior_detection |
||||
|
set |
||||
|
water_intake = #{waterIntake} , |
||||
|
start_time = #{startTime}, |
||||
|
end_time = #{endTime} |
||||
|
where id = #{id} |
||||
|
</update> |
||||
|
|
||||
|
<select id="list" resultType="behaviorDetectionVo"> |
||||
|
SELECT |
||||
|
mf.face_name as faceName, |
||||
|
CASE |
||||
|
WHEN LENGTH(mf.birth_date) = 15 THEN |
||||
|
-- 15位身份证号,提取出生年份、月份、日期并计算年龄 |
||||
|
FLOOR(DATEDIFF(CURDATE(), STR_TO_DATE(CONCAT('19', SUBSTRING(mf.birth_date, 7, 6)), '%Y%m%d')) / 365.25) |
||||
|
WHEN LENGTH(mf.birth_date) = 18 THEN |
||||
|
-- 18位身份证号,提取出生年份、月份、日期并计算年龄 |
||||
|
FLOOR(DATEDIFF(CURDATE(), STR_TO_DATE(SUBSTRING(mf.birth_date, 7, 8), '%Y%m%d')) / 365.25) |
||||
|
ELSE |
||||
|
NULL |
||||
|
END AS age, |
||||
|
MAX(bd.create_time) AS latestTime, -- 显示最新记录时间 |
||||
|
SUM(bd.water_intake) AS totalWaterIntake, -- 当天饮水总量 |
||||
|
COUNT(bd.id) AS totalWaterCount, -- 当天饮水次数 |
||||
|
CASE |
||||
|
WHEN SUM(bd.water_intake) > 1000 THEN 'true' -- 超过阈值显示 'true' |
||||
|
ELSE 'false' -- 不超过阈值显示 'false' |
||||
|
END AS isAboveThreshold |
||||
|
FROM |
||||
|
behavior_detection bd |
||||
|
INNER JOIN |
||||
|
mine_face mf ON bd.face_id = mf.id |
||||
|
WHERE |
||||
|
DATE(bd.create_time) = CURDATE() and bd.behavior_type=1 -- 仅查询当天的数据 |
||||
|
GROUP BY |
||||
|
mf.id, mf.face_name |
||||
|
</select> |
||||
|
<select id="getFaceLatest" resultMap="BehaviorDetectionResult"> |
||||
|
select * from behavior_detection where behavior_type = #{behaviorType} and water_intake is null order by create_time desc limit 1 |
||||
|
</select> |
||||
|
<select id="behaviorTypeCount" resultType="java.util.Map"> |
||||
|
select behavior_type as behaviorType, |
||||
|
CASE |
||||
|
WHEN behavior_type = 1 THEN '饮水' |
||||
|
WHEN behavior_type = 2 THEN '睡眠' |
||||
|
WHEN behavior_type = 3 THEN '行走' |
||||
|
WHEN behavior_type = 4 THEN '坐姿' |
||||
|
ELSE '未知' |
||||
|
END AS behaviorTypeName, COUNT(id) as behaviorCount from behavior_detection GROUP BY behavior_type |
||||
|
</select> |
||||
|
<select id="behaviorCount" resultType="java.util.Map"> |
||||
|
select face_name as faceName,COUNT(id) as behaviorCount , |
||||
|
CASE |
||||
|
WHEN behavior_type = 1 THEN '饮水' |
||||
|
WHEN behavior_type = 2 THEN '睡眠' |
||||
|
WHEN behavior_type = 3 THEN '行走' |
||||
|
WHEN behavior_type = 4 THEN '坐姿' |
||||
|
ELSE '未知' |
||||
|
END AS behaviorTypeName |
||||
|
from behavior_detection |
||||
|
where date_format(create_time,'%y%m%d') >= date_format(now(),'%y%m%d') |
||||
|
GROUP BY face_name ,behavior_type |
||||
|
</select> |
||||
|
</mapper> |
Loading…
Reference in new issue