diff --git a/shapelight-admin/src/main/java/net/shapelight/common/utils/Constant.java b/shapelight-admin/src/main/java/net/shapelight/common/utils/Constant.java index ed5b8d4..352f559 100644 --- a/shapelight-admin/src/main/java/net/shapelight/common/utils/Constant.java +++ b/shapelight-admin/src/main/java/net/shapelight/common/utils/Constant.java @@ -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"; + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/CmdConstant.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/CmdConstant.java index 8b24071..562456d 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/CmdConstant.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/CmdConstant.java @@ -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; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/DeviceApiService.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/DeviceApiService.java index e94c184..556032f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/DeviceApiService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/DeviceApiService.java @@ -13,6 +13,8 @@ public interface DeviceApiService { boolean isOnline(String sn); + void memberUpdate(Channel channel, String content); + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java index c76c3b2..c42431f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/DeviceApiServiceImpl.java @@ -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() // .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() + .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 syncEntitys = tenPersonSyncService.findByPersonId(p.getPersonId(), p.getTenantId()); + for (TenPersonSyncEntity syncEn : syncEntitys) { + syncEn.setLastUpdateTime(p.getLastUpdateTime()); + syncEn.setState(2); + tenPersonSyncService.updateById(syncEn); + //下发通知 + List 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); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/MessageServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/MessageServiceImpl.java index 21096d5..0b929f0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/MessageServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/MessageServiceImpl.java @@ -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; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenDeviceEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenDeviceEntity.java index ffa3049..813434e 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenDeviceEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenDeviceEntity.java @@ -250,4 +250,9 @@ public class TenDeviceEntity extends BaseEntity implements Serializable { // @ApiModelProperty("户室") // private String roomName; + //--------------------------------------3d数据------------------------------- + private String recognizeScore3d; + + private Integer detectionType; + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonEntity.java index 93cd317..6b096b3 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonEntity.java @@ -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; + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRecordEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRecordEntity.java index b46819c..386e894 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRecordEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRecordEntity.java @@ -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; + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java index cd66f5b..500e0a7 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenRecordServiceImpl.java @@ -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实时刷新 diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenUserVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenUserVo.java index 513c509..0468d19 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenUserVo.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenUserVo.java @@ -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; + } diff --git a/shapelight-admin/src/main/resources/application-dev.yml b/shapelight-admin/src/main/resources/application-dev.yml index 20c45be..a5680a1 100644 --- a/shapelight-admin/src/main/resources/application-dev.yml +++ b/shapelight-admin/src/main/resources/application-dev.yml @@ -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 diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenDeviceDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenDeviceDao.xml index efb868b..de3994c 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenDeviceDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenDeviceDao.xml @@ -3,57 +3,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -