v4.0 支持3d设备,数据库有变

This commit is contained in:
gaoben 2022-03-22 17:47:50 +08:00
parent e921fd57ab
commit ce9efa70ab
15 changed files with 358 additions and 53 deletions

View File

@ -90,6 +90,9 @@ public class Constant {
public static final int PERSON_SYNC_MODIFY = 2;
public static final int PERSON_SYNC_DELETE = 3;
public static final String DEVICE_FLAG_2D = "0";
public static final String DEVICE_FLAG_3D = "1";

View File

@ -16,6 +16,8 @@ public class CmdConstant {
public static final byte CMD_UPRECORD = 0x05;
public static final byte CMD_EXTRACT = 0x06;
public static final byte CMD_UPDATE_MEMBER = 0x14;
public static final byte CMD_CONFIG = 0x50;
public static final byte CMD_CHANGE = 0x51;
public static final byte CMD_OPENDOOR = 0x52;

View File

@ -13,6 +13,8 @@ public interface DeviceApiService {
boolean isOnline(String sn);
void memberUpdate(Channel channel, String content);

View File

@ -4,10 +4,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.netty.channel.Channel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import net.shapelight.common.config.GlobalValue;
import net.shapelight.common.config.MinioConfig;
import net.shapelight.common.utils.*;
import net.shapelight.modules.nettyapi.config.ClientMap;
import net.shapelight.modules.nettyapi.config.CmdConstant;
@ -16,19 +19,24 @@ import net.shapelight.modules.nettyapi.service.DeviceApiService;
import net.shapelight.modules.nettyapi.service.ServerApiService;
import net.shapelight.modules.nettyapi.utils.Result;
import net.shapelight.modules.sys.entity.SysDeviceEntity;
import net.shapelight.modules.sys.entity.SysDeviceTypeEntity;
import net.shapelight.modules.sys.service.SysDeviceAppService;
import net.shapelight.modules.sys.service.SysDeviceService;
import net.shapelight.modules.sys.service.SysDeviceTypeService;
import net.shapelight.modules.ten.entity.*;
import net.shapelight.modules.ten.service.*;
import net.shapelight.modules.vo.TenPersonIdUpdateAllVo;
import net.shapelight.modules.vo.TenPersonIdUpdateVo;
import net.shapelight.modules.vo.TenPersonOperationVo;
import net.shapelight.modules.vo.TenUserVo;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
@ -61,6 +69,12 @@ public class DeviceApiServiceImpl implements DeviceApiService {
private TenDoorCardService tenDoorCardService;
@Autowired
private RedisUtils redisUtils;
@Autowired
private SysDeviceTypeService sysDeviceTypeService;
@Autowired
private MinioConfig minioConfig;
@Autowired
private MinioClient minioClient;
/*
@ -191,6 +205,16 @@ public class DeviceApiServiceImpl implements DeviceApiService {
configMap.put("support_stranger",false);
}
//-----------------------------------------3d数据--------------------------------------
// 以下是3d配置
SysDeviceTypeEntity deviceTypeEntity = sysDeviceTypeService.getById(sysDeviceEntity.getDeviceTypeId());
// if (deviceTypeEntity.getOther().equals(Constant.DEVICE_FLAG_3D)) {
// configMap.put("recognize_score_3d", deviceEntity.getRecognizeScore3d());
// configMap.put("detection_type", deviceEntity.getDetectionType());
// }
dataMap.put("config",configMap);
res.put("data",dataMap);
String resContent = JSONObject.toJSONString(res);
@ -328,6 +352,33 @@ public class DeviceApiServiceImpl implements DeviceApiService {
+ p.getOrgImage());
puser.setFace_pic_base64("");
//-----------------------------------------3d数据--------------------------------------
/*
"rgb":"url"
"depth":"url"
"faceModel": ""
"souceFile": "url"
"cameraParam": "65464313212"
*/
// 以下是3d配置
SysDeviceTypeEntity deviceTypeEntity = sysDeviceTypeService.getById(sysDeviceEntity.getDeviceTypeId());
if (deviceTypeEntity.getOther().equals(Constant.DEVICE_FLAG_3D)) {
if(p.getSourceFile()!=null){
puser.setSourceFile(globalValue.getMinioEndpoint()+"/"
+ globalValue.getMinioBucketName()+"/"
+ p.getSourceFile());
}
if(p.getCameraParam()!=null){
puser.setCameraParam(p.getCameraParam());
}
if(p.getFaceModel()!=null){
puser.setFaceModel(p.getFaceModel());
}
}
// TenPersonSyncEntity syncEntity = tenPersonSyncService.getOne(new QueryWrapper<TenPersonSyncEntity>()
// .eq("device_id",deviceEntity.getDeviceId())
// .eq("person_id",p.getPersonId()));
@ -489,6 +540,33 @@ public class DeviceApiServiceImpl implements DeviceApiService {
record.setRecordFaceStr(captureFacePic);
record.setTenantId(deviceEntity.getTenantId());
//------------------------------------3d------------------------------------
/*
private String depth;
private String sourceFile;
private Integer duration;
private String threshold;
private Float distance;
private Float temperature;
private String cameraParam;
*/
String score3d = jsonContent.getString("score");
String sourceFileStr = jsonContent.getString("sourceFile");
Integer duration = jsonContent.getInteger("duration");
String threshold = jsonContent.getString("threshold");
Float distance = jsonContent.getFloat("distance");
Float temperature = jsonContent.getFloat("temperature");
String cameraParam = jsonContent.getString("cameraParam");
record.setScore3d(score3d);
record.setSourceFileStr(sourceFileStr);
record.setDuration(duration);
record.setThreshold(threshold);
record.setDistance(distance);
record.setTemperature(temperature);
record.setCameraParam(cameraParam);
// log.info("保存记录:----------------------"+record.getRecordTime()+"-"+record.getMemberId().intValue());
tenRecordService.saveForFace(record);
@ -555,6 +633,90 @@ public class DeviceApiServiceImpl implements DeviceApiService {
channel.writeAndFlush(message);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void memberUpdate(Channel channel, String content) {
JSONObject jsonContent = JSONObject.parseObject(content);
String devId = jsonContent.getString("dev_id");
Long uid = jsonContent.getLongValue("uid");
// String rgbBase64 = jsonContent.getString("rgb");
// String depthBase64 = jsonContent.getString("depth");
// String faceModelBase64 = jsonContent.getString("faceModel");
String sourceFileBase64 = jsonContent.getString("sourceFile");
String cameraParam = jsonContent.getString("cameraParam");
TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId);
if(deviceEntity == null){
return;
}
SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper<SysDeviceEntity>()
.eq("sn",devId));
if(sysDeviceEntity.getState() == 0){
Result res = Result.error(202, "Device Is Stop");
String resContent = JSONObject.toJSONString(res);
MyMessage message = new MyMessage(CmdConstant.CMD_GETONE,resContent.length(),resContent.getBytes());
channel.writeAndFlush(message);
return;
}
TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId());
TenPersonEntity p = tenPersonService.getById(uid,cellEntity.getCellId());
if(p!=null){
p.setLastUpdateTime(new Date());
p.setCameraParam(cameraParam);
//保存sourcefile
if (sourceFileBase64 != null && !sourceFileBase64.isEmpty()) {
try {
byte[] b = Base64.getDecoder().decode(sourceFileBase64.replace("\n", ""));
InputStream inputStream = new ByteArrayInputStream(b);
String fileName = globalValue.getImagesDir() + "/" +
p.getCellId().toString() + "/" +
p.getPersonId().toString() + "/so_" + UUIDUtil.uuid() + ".zip";
PutObjectOptions putObjectOptions = new PutObjectOptions(b.length, -1);
putObjectOptions.setContentType("application/zip");
minioClient.putObject(
minioConfig.getBucketName(), fileName, inputStream, putObjectOptions);
inputStream.close();
p.setSourceFile(fileName);
//保存人员信息
tenPersonService.updateNonal(p);
Result res = new Result();
String resContent = JSONObject.toJSONString(res);
MyMessage message = new MyMessage(CmdConstant.CMD_UPDATE_MEMBER, resContent.getBytes().length, resContent.getBytes());
channel.writeAndFlush(message);
//配置同步数据
List<TenPersonSyncEntity> syncEntitys = tenPersonSyncService.findByPersonId(p.getPersonId(), p.getTenantId());
for (TenPersonSyncEntity syncEn : syncEntitys) {
syncEn.setLastUpdateTime(p.getLastUpdateTime());
syncEn.setState(2);
tenPersonSyncService.updateById(syncEn);
//下发通知
List<TenPersonOperationVo> list = new ArrayList<>();
TenPersonOperationVo vo = new TenPersonOperationVo();
vo.setUid(p.getPersonId());
vo.setOperation(2);
vo.setLast_update_stamp(p.getLastUpdateTime());
list.add(vo);
serverApiService.personOperation(syncEn.getDeviceSn(), list);
}
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
}
}
@Override
public boolean isOnline(String sn) {
return clientMap.isLogin(sn);

View File

@ -108,6 +108,19 @@ public class MessageServiceImpl implements MessageService {
break;
}
case CmdConstant.CMD_UPDATE_MEMBER: {
log.debug("人员修改:" + msg.cmd);
if(!clientMap.hasUser(channel)){
Result res = Result.error(403,"No permission");
String resContent = JSONObject.toJSONString(res);
MyMessage message = new MyMessage(CmdConstant.CMD_UPDATE_MEMBER,resContent.length(),resContent.getBytes());
channel.writeAndFlush(message);
return;
}
deviceApiService.memberUpdate(channel,content);
break;
}
case CmdConstant.CMD_CONFIG: {
break;

View File

@ -250,4 +250,9 @@ public class TenDeviceEntity extends BaseEntity implements Serializable {
// @ApiModelProperty("户室")
// private String roomName;
//--------------------------------------3d数据-------------------------------
private String recognizeScore3d;
private Integer detectionType;
}

View File

@ -334,4 +334,16 @@ public class TenPersonEntity extends BaseEntity implements Serializable {
private Integer xaSyncImage;
// "rgb":"url"
// "depth":"url"
// "faceModel": ""
// "souceFile": "url"
// "cameraParam": "65464313212"
private String depth;
private String faceModel;
private String sourceFile;
private String cameraParam;
}

View File

@ -159,4 +159,28 @@ public class TenRecordEntity implements Serializable {
@ApiModelProperty("")
private Integer xaSyncImage;
/*
depth string 人脸depth base64字符串
sourceFile string 人脸ir base64字符串
duration int 耗时
threshold string 阈值,多个用,隔开
distance float 距离
score string 分数,多个用,隔开
temperature String 体温
cameraParam string 相机参数
*/
private String score3d;
private String depth;
private String sourceFile;
private Integer duration;
private String threshold;
private Float distance;
private Float temperature;
private String cameraParam;
@TableField(exist = false)
private String sourceFileStr;
}

View File

@ -204,6 +204,27 @@ public class TenRecordServiceImpl implements TenRecordService {
}
}
String source = entity.getSourceFileStr();
if(source!=null && !source.isEmpty()){
try {
byte[] b = Base64.getDecoder().decode(source.replace("\n", ""));
InputStream inputStream = new ByteArrayInputStream(b);
String userFileUrl = globalValue.getImagesDir() + "/" +
entity.getCellId().toString() + "/" +
entity.getPersonId().toString() + "/";
String fileName = userFileUrl + UUIDUtil.uuid() + ".zip";
// String fileName = "t_"+UUIDUtil.uuid()+ "." +extension;
PutObjectOptions putObjectOptions = new PutObjectOptions(b.length, -1);
putObjectOptions.setContentType("application/zip");
minioClient.putObject(
minioConfig.getBucketName(), fileName, inputStream, putObjectOptions);
inputStream.close();
entity.setSourceFile(fileName);
} catch (Exception e) {
e.printStackTrace();
}
}
int flag = tenRecordDao.insert(entity);
if (flag == 1) {
//推送到web实时刷新

View File

@ -26,5 +26,10 @@ public class TenUserVo {
private Integer active_end_time;
private String card_id="";
private String depth;
private String faceModel;
private String sourceFile;
private String cameraParam;
}

View File

@ -3,7 +3,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.50.20:3306/cell_db_0621?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&rewriteBatchedStatements=true
url: jdbc:mysql://192.168.50.20:3306/cell_db_v4.0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&rewriteBatchedStatements=true
username: user
password: user@server001
initial-size: 10

View File

@ -3,57 +3,6 @@
<mapper namespace="net.shapelight.modules.ten.dao.TenDeviceDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="net.shapelight.modules.ten.entity.TenDeviceEntity" id="tenDeviceMap">
<result property="deviceId" column="device_id"/>
<result property="name" column="name"/>
<result property="sn" column="sn"/>
<result property="mac" column="mac"/>
<result property="type" column="type"/>
<result property="gateFlag" column="gate_flag"/>
<result property="cellId" column="cell_id"/>
<result property="buildNumber" column="build_number"/>
<result property="buildId" column="build_id"/>
<result property="roomId" column="room_id"/>
<result property="tenantId" column="tenant_id"/>
<result property="apkVersion" column="apk_version"/>
<result property="faceCount" column="face_count"/>
<result property="algVersion" column="alg_version"/>
<result property="cpuTemplate" column="cpu_template"/>
<result property="cameraStatus" column="camera_status"/>
<result property="osType" column="os_type"/>
<result property="firmwareVersion" column="firmware_version"/>
<result property="licenseSerial" column="license_serial"/>
<result property="livenessFlag" column="liveness_flag"/>
<result property="rgbLiveThd" column="rgb_live_thd"/>
<result property="nirLiveThd" column="nir_live_thd"/>
<result property="recThd" column="rec_thd"/>
<result property="minFaceWidth" column="min_face_width"/>
<result property="heartbeatCycle" column="heartbeat_cycle"/>
<result property="lightScore" column="light_score"/>
<result property="songFlag" column="song_flag"/>
<result property="songDoor" column="song_door"/>
<result property="uploadImageFlag" column="upload_image_flag"/>
<result property="cutFaceFlag" column="cut_face_flag"/>
<result property="avCallFlag" column="av_call_flag"/>
<result property="recSpace" column="rec_space"/>
<result property="strangerFlag" column="stranger_flag"/>
<result property="createTime" column="create_time"/>
<result property="createBy" column="create_by"/>
<result property="lastUpdateTime" column="last_update_time"/>
<result property="lastUpdateBy" column="last_update_by"/>
<result property="deleteFlag" column="delete_flag"/>
<result property="doorOpenLevel" column="door_open_level"/>
<result property="lockOpenLevel" column="lock_open_level"/>
<result property="temperatureUp" column="temperature_up"/>
<result property="temperatureAlert" column="temperature_alert"/>
<result property="healthCodeFlag" column="health_code_flag"/>
<result column="xa_sync" property="xaSync"/>
</resultMap>
<select id="findAllSn" resultType="String">
select sn from ten_device where delete_flag = 0

View File

@ -47,6 +47,12 @@
<result column="xa_sync" jdbcType="TINYINT" property="xaSync" />
<result column="xa_sync_card" jdbcType="TINYINT" property="xaSyncCard" />
<result column="xa_sync_image" jdbcType="TINYINT" property="xaSyncImage" />
<result column="depth" jdbcType="VARCHAR" property="depth" />
<result column="face_model" jdbcType="VARCHAR" property="faceModel" />
<result column="source_file" jdbcType="VARCHAR" property="sourceFile" />
<result column="camera_param" jdbcType="VARCHAR" property="cameraParam" />
<association property="cellName" javaType="String"
select="net.shapelight.modules.ten.dao.TenCellDao.getCellName"
column="cellId=cell_id">
@ -491,6 +497,12 @@
<if test="xaSyncImage != null">
xa_sync_image = #{xaSyncImage,jdbcType=TINYINT},
</if>
<if test="cameraParam != null">
camera_param = #{cameraParam,jdbcType=VARCHAR},
</if>
<if test="sourceFile != null">
source_file = #{sourceFile,jdbcType=VARCHAR},
</if>
</set>
where person_id = #{personId,jdbcType=BIGINT}
</update>

View File

@ -3,7 +3,13 @@
<mapper namespace="net.shapelight.modules.ten.dao.TenRecordDao">
<!-- -->
<!--private String depth;
private String sourceFile;
private Integer duration;
private String threshold;
private Float distance;
private Float temperature;
private String cameraParam; -->
<resultMap type="net.shapelight.modules.ten.entity.TenRecordEntity" id="tenRecordMap">
<result property="recordId" column="record_id"/>
<result property="cellId" column="cell_id"/>
@ -19,6 +25,15 @@
<result property="tenantId" column="tenant_id"/>
<result column="xa_sync" jdbcType="TINYINT" property="xaSync"/>
<result column="xa_sync_image" jdbcType="TINYINT" property="xaSyncImage"/>
<result property="score3d" column="score3d"/>
<result property="depth" column="depth"/>
<result property="sourceFile" column="source_file"/>
<result property="duration" column="duration"/>
<result property="threshold" column="threshold"/>
<result property="distance" column="distance"/>
<result property="temperature" column="temperature"/>
<result property="cameraParam" column="camera_param"/>
</resultMap>
@ -67,6 +82,31 @@
<if test="xaSyncImage != null">
xa_sync_image,
</if>
<if test="score3d != null">
score3d,
</if>
<if test="depth != null">
depth,
</if>
<if test="sourceFile != null">
source_file,
</if>
<if test="duration != null">
duration,
</if>
<if test="threshold != null">
threshold,
</if>
<if test="distance != null">
distance,
</if>
<if test="temperature != null">
temperature,
</if>
<if test="cameraParam != null">
camera_param,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="recordId != null">
@ -111,6 +151,33 @@
<if test="xaSyncImage != null">
#{xaSyncImage},
</if>
<if test="score3d != null">
#{score3d},
</if>
<if test="depth != null">
#{depth},
</if>
<if test="sourceFile != null">
#{sourceFile},
</if>
<if test="duration != null">
#{duration},
</if>
<if test="threshold != null">
#{threshold},
</if>
<if test="distance != null">
#{distance},
</if>
<if test="temperature != null">
#{temperature},
</if>
<if test="cameraParam != null">
#{cameraParam},
</if>
</trim>
</insert>

28
version4.txt Normal file
View File

@ -0,0 +1,28 @@
v4.0
1.sys_device_type表 启用other字段0表示2d,1表示3dv4.0加入空表示2d
2.ten_device表增加两个字段识别阈值recognize_score_3d,检测方式detection_type
3.ten_person表增加5个字段depth,face_model,source_file,camera_param
4.ten_record表增加8个字段depth,source_file,duration,threshold,distance,score3d,temperature,camera_param
v4.0 数据库修改内容
alter table ten_device_copy1
ADD COLUMN recognize_score3d varchar(30) DEFAULT '62,65' COMMENT '3d识别阈值',
ADD COLUMN detection_type tinyint(1) DEFAULT 0 COMMENT '0默认2d检测 13d检测';
alter table ten_person_copy1
ADD COLUMN depth varchar(200) COMMENT '深度图片',
ADD COLUMN face_model varchar(200) COMMENT '脸模',
ADD COLUMN source_file varchar(200) COMMENT '源文件',
ADD COLUMN camera_param varchar(200) COMMENT '相机参数';
alter table ten_record_9999999999999
ADD COLUMN depth varchar(200) COMMENT '深度图片',
ADD COLUMN source_file varchar(200) COMMENT '源文件',
ADD COLUMN camera_param varchar(200) COMMENT '相机参数',
ADD COLUMN duration int(11) COMMENT '耗时',
ADD COLUMN threshold varchar(50) COMMENT '阈值',
ADD COLUMN distance float COMMENT '距离',
ADD COLUMN score3d varchar(50) COMMENT '分数',
ADD COLUMN temperature float COMMENT '体温';