diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/CmdProcess.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/CmdProcess.java index 9188df1..d3b71ff 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/CmdProcess.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/CmdProcess.java @@ -15,6 +15,7 @@ import net.shapelight.modules.ten.service.TenDeviceService; import net.shapelight.modules.vo.TenDeviceParamVo; import net.shapelight.modules.vo.TenPersonVo; import net.shapelight.modules.vo.TenRecordVo; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -78,6 +79,10 @@ public class CmdProcess { case addPerson: log.info("addPerson", cmdEnum.getCmd()); break; + case getParam: + subGetParam(deviceSn,content); + log.info("getParam", cmdEnum.getCmd()); + break; } } @@ -311,6 +316,54 @@ public class CmdProcess { } + + + /** + * + * @param deviceSn + * @param content + * { + * "cmd": "getParam" + * "data": { + + * } + * } + */ + private static void subGetParam(String deviceSn,String content){ + JSONObject resJson = JSONObject.parseObject(content); + JSONObject data = resJson.getJSONObject("data"); + TenDeviceParamVo paramVo = data.toJavaObject(TenDeviceParamVo.class); + paramVo.setSn(deviceSn); + log.debug("收到mqtt设备参数:"+content); + TenDeviceEntity dev = cmdProcess.tenDeviceService.findBySn(deviceSn); + BeanUtils.copyProperties(paramVo,dev); + cmdProcess.tenDeviceService.evictupdateById(dev); + } + + + + /** + * + * @param deviceSn + * + * { + * "cmd":" getParam", + * "data":{ + * } + * } + */ + public static void publishGetParam(String deviceSn){ + String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); + //要发送消息的内容 + JSONObject sendContent = new JSONObject(); + Map data = new HashMap<>(); + sendContent.put("cmd", "getParam"); + sendContent.put("data", data); + //发布消息 + MqttClientUtil.publish_common(topic, sendContent.toString()); + } + + /** * * @param deviceSn diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/TopicCmdEnum.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/TopicCmdEnum.java index 8b57df8..4630cbc 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/TopicCmdEnum.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/TopicCmdEnum.java @@ -7,7 +7,8 @@ public enum TopicCmdEnum { faceCount("faceCount"), alert("alert"), upRecord("upRecord"), - addPerson("addPerson"); + addPerson("addPerson"), + getParam("getParam"); private String cmd; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/excel/listener/PersonExcelListener.java b/shapelight-admin/src/main/java/net/shapelight/modules/excel/listener/PersonExcelListener.java index b00cafc..d13dd0b 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/excel/listener/PersonExcelListener.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/excel/listener/PersonExcelListener.java @@ -156,6 +156,7 @@ public class PersonExcelListener extends AnalysisEventListener { personModel.setOrgImage(image); } //检测图片人脸 + //--------------------------------------------------------------------- String tempPath = ""; if (Pattern.matches("Linux.*", System.getProperty("os.name"))) { tempPath = image.substring(0,image.lastIndexOf("/")+1); @@ -171,6 +172,7 @@ public class PersonExcelListener extends AnalysisEventListener { list.add(personModel); return; } + //--------------------------------------------------------------------- personModel.setStatus(1); list.add(personModel); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenDeviceController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenDeviceController.java index d934238..c6934f1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenDeviceController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenDeviceController.java @@ -24,6 +24,7 @@ import net.shapelight.modules.ten.service.TenCellService; import net.shapelight.modules.ten.service.TenUserScopeService; import net.shapelight.modules.vo.TenDeviceParamVo; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.web.bind.annotation.*; @@ -157,12 +158,45 @@ public class TenDeviceController extends AbstractController { } + + /** + * 获取设备参数 + */ + @GetMapping("/getParam/{sn}") + @ApiOperation(value = "获取设备参数") + public R getParam(@PathVariable("sn") String sn){ + boolean onlineFlag = emqHttpApi.getClient(sn); + if(onlineFlag){ + + }else{ + return R.error("设备离线,无法更新"); + } + CmdProcess.publishGetParam(sn); + try { + Thread.sleep(3000); + TenDeviceEntity dev = tenDeviceService.findBySn(sn); + TenDeviceParamVo paramVo = new TenDeviceParamVo(); + BeanUtils.copyProperties(dev,paramVo); + return R.ok().put("data",paramVo); + }catch (Exception e){ + return R.error("获取失败,请重试"); + } + } + + /** * 设置设备参数 */ @PostMapping("/setParam") @ApiOperation(value = "设置设备参数") public R setParam(@RequestBody TenDeviceParamVo paramVo){ + String sn = paramVo.getSn(); + boolean onlineFlag = emqHttpApi.getClient(sn); + if(onlineFlag){ + + }else{ + return R.error("设备离线,无法更新"); + } CmdProcess.publishSetParam(paramVo.getSn(),paramVo); return R.ok(); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java index 68a5487..cc74406 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.minio.MinioClient; import io.minio.PutObjectOptions; import lombok.extern.slf4j.Slf4j; +import net.coobird.thumbnailator.Thumbnails; import net.shapelight.common.config.GlobalValue; import net.shapelight.common.config.MinioConfig; import net.shapelight.common.utils.*; @@ -34,6 +35,7 @@ import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; +import java.awt.image.BufferedImage; import java.io.*; import java.util.*; import java.util.regex.Pattern; @@ -45,6 +47,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import net.shapelight.modules.ten.dao.TenPersonDao; import org.springframework.transaction.annotation.Transactional; +import javax.imageio.ImageIO; + @Service("tenPersonService") @Slf4j @@ -1736,8 +1740,12 @@ public class TenPersonServiceImpl implements TenPersonService { tenPerson.setOrgImage(orgImageFileName); // log.info("原图"+tenPerson.getOrgImage()+"-"+personModel.getOrgImage()); + + //2. 截取人脸图片 //检测图片人脸 + +//-------------------------------------------------------------------- String tempPath = ""; if (Pattern.matches("Linux.*", System.getProperty("os.name"))) { tempPath = personModel.getOrgImage().substring(0, personModel.getOrgImage().lastIndexOf("/") + 1); @@ -1758,8 +1766,35 @@ public class TenPersonServiceImpl implements TenPersonService { minioConfig.getBucketName(), faceImageFileName, inputStreamFace, putObjectOptionsFace); inputStreamFace.close(); tenPerson.setFaceImage(faceImageFileName); -// log.info("人脸图"+tenPerson.getFaceImage()); } +// tenPerson.setFaceImage(orgImageFileName); + +//-------------------------------------------------------------------- + + + +//--------------------------------处理图片大小------------------------------------------------------ + if (tenPerson.getOrgImage() != null && !tenPerson.getOrgImage().isEmpty()) { + String orgFileStr = "/root/minio/data/cell/"+ tenPerson.getOrgImage(); +// String orgFileStr = "/home/server001/minio/data/cell/"+ tenPerson.getOrgImage(); + try { + File picture = new File(orgFileStr); + BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture)); + int w = sourceImg.getWidth(); + int h = sourceImg.getHeight(); + if (w > 1080 || h > 1080) { + Thumbnails.of(orgFileStr) + .size(1080, 1080) + .toFile(orgFileStr); + } + }catch (Exception e){ + log.error(e.getMessage()); + } + } +//--------------------------------处理图片大小------------------------------------------------------ + + + } catch (Exception e) { e.printStackTrace(); tenPerson.setStatus(0); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceParamVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceParamVo.java index 89d99ab..030d65e 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceParamVo.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceParamVo.java @@ -14,44 +14,46 @@ import java.io.Serializable; public class TenDeviceParamVo implements Serializable { private static final long serialVersionUID = 1L; @JsonSerialize(using = ToStringSerializer.class) - @ApiModelProperty("设备ID") - private Long deviceId; +// @ApiModelProperty("设备ID") +// private Long deviceId; @ApiModelProperty("设备序列号") private String sn; @ApiModelProperty("活体开关") private Integer livenessFlag; @ApiModelProperty("rgb活体阈值") private Float rgbLiveThd; - @ApiModelProperty("nir活体阈值") - private Float nirLiveThd; +// @ApiModelProperty("nir活体阈值") +// private Float nirLiveThd; @ApiModelProperty("识别阈值") private Float recThd; - @ApiModelProperty("最小人脸框尺寸") - private Integer minFaceWidth; - @ApiModelProperty("心跳周期") - private Integer heartbeatCycle; - @ApiModelProperty("补光灯亮度") - private Integer lightScore; - @ApiModelProperty("声音开关") - private Integer songFlag; - @ApiModelProperty("开门声音") - private String songDoor; - @ApiModelProperty("是否上传头像1上传0不上传") - private Integer uploadImageFlag; - @ApiModelProperty("1截取人脸0原图") - private Integer cutFaceFlag; +// @ApiModelProperty("最小人脸框尺寸") +// private Integer minFaceWidth; +// @ApiModelProperty("心跳周期") +// private Integer heartbeatCycle; +// @ApiModelProperty("补光灯亮度") +// private Integer lightScore; +// @ApiModelProperty("声音开关") +// private Integer songFlag; +// @ApiModelProperty("开门声音") +// private String songDoor; +// @ApiModelProperty("是否上传头像1上传0不上传") +// private Integer uploadImageFlag; +// @ApiModelProperty("1截取人脸0原图") +// private Integer cutFaceFlag; @ApiModelProperty("识别间隔秒") private Integer recSpace; - @ApiModelProperty("是否抓拍陌生人0否1是") - private Integer strangerFlag; - @ApiModelProperty("门常开电平0低1高") - private Integer doorOpenLevel; +// @ApiModelProperty("是否抓拍陌生人0否1是") +// private Integer strangerFlag; +// @ApiModelProperty("门常开电平0低1高") +// private Integer doorOpenLevel; @ApiModelProperty("锁常开电平0低1高") private Integer lockOpenLevel; - @ApiModelProperty("测温补偿") - private Float temperatureUp; - @ApiModelProperty("告警温度") - private Float temperatureAlert; - @ApiModelProperty("健康码1支持0不支持") - private Integer healthCodeFlag; + @ApiModelProperty("开锁时间") + private Integer lockOpenTime; +// @ApiModelProperty("测温补偿") +// private Float temperatureUp; +// @ApiModelProperty("告警温度") +// private Float temperatureAlert; +// @ApiModelProperty("健康码1支持0不支持") +// private Integer healthCodeFlag; } diff --git a/shapelight-admin/src/main/resources/application-dev.yml b/shapelight-admin/src/main/resources/application-dev.yml index fd3ca31..2c6d583 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.1.111:3306/cell_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.50.232:3306/cell_db?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: user password: user@server001 initial-size: 10 diff --git a/shapelight-admin/src/main/resources/application.yml b/shapelight-admin/src/main/resources/application.yml index 2f671f6..0a70829 100644 --- a/shapelight-admin/src/main/resources/application.yml +++ b/shapelight-admin/src/main/resources/application.yml @@ -26,12 +26,12 @@ spring: time-zone: GMT+8 servlet: multipart: - max-file-size: 100MB - max-request-size: 100MB + max-file-size: 1000MB + max-request-size: 1000MB enabled: true redis: database: 0 - host: 192.168.1.111 + host: 192.168.50.232 port: 6379 password: 123456 # 密码(默认为空) timeout: 6000ms # 连接超时时长(毫秒) @@ -49,13 +49,13 @@ spring: mqtt: username: admin password: public - url: tcp://192.168.1.111:1883 + url: tcp://192.168.50.232:1883 keepAliveInterval: 10 client: id: web-server default: topic: topic - api: http://192.168.1.111:8081 + api: http://192.168.50.232:8081 mvc: @@ -83,7 +83,7 @@ global: db_host: localhost db_port: 3306 minio: - endpoint: http://192.168.1.111:9000 + endpoint: http://192.168.50.232:9000 port: 9000 accessKey: admin secretKey: admin@C501