From 0becc9f841d9a4150c70cbd2cbf97b2fa6c7c1f4 Mon Sep 17 00:00:00 2001 From: gaoben Date: Mon, 15 Mar 2021 16:45:58 +0800 Subject: [PATCH] =?UTF-8?q?netty=E7=89=88=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/shapelight/AdminApplication.java | 32 +- .../net/shapelight/common/utils/Constant.java | 10 +- .../app/controller/AppApiController.java | 39 +- .../app/controller/AppInfoApiController.java | 2 + .../net/shapelight/modules/dev/AppSecret.java | 68 +- .../dev/controller/DeviceController.java | 1252 ++++++++--------- .../modules/dev/mqtt/CmdProcess.java | 816 +++++------ .../modules/dev/mqtt/EmqHttpApi.java | 320 ++--- .../modules/dev/mqtt/HandlerThread.java | 100 +- .../modules/dev/mqtt/MqttClientUtil.java | 466 +++--- .../dev/mqtt/MqttSubscribeClientCallback.java | 74 +- .../modules/dev/mqtt/PublishThread.java | 122 +- .../shapelight/modules/dev/mqtt/RunMqtt.java | 42 +- .../modules/dev/mqtt/TopicCmdEnum.java | 46 +- .../excel/listener/PersonExcelListener.java | 41 +- .../modules/excel/model/PersonModel.java | 3 + .../modules/job/task/PersonProcessTask.java | 60 + .../nettyapi/config/MyMessageDecoder.java | 12 +- .../modules/nettyapi/config/MyServer.java | 2 +- .../nettyapi/service/DeviceApiService.java | 3 + .../nettyapi/service/ServerApiService.java | 14 +- .../service/impl/DeviceApiServiceImpl.java | 175 ++- .../service/impl/MessageServiceImpl.java | 6 +- .../service/impl/ServerApiServiceImpl.java | 104 +- .../controller/SysDeviceAppController.java | 5 +- .../sys/controller/SysDeviceController.java | 29 +- .../sys/entity/SysDeviceAppEntity.java | 5 + .../modules/sys/entity/SysDeviceEntity.java | 3 + .../service/impl/SysDeviceServiceImpl.java | 12 +- .../sys/service/impl/SysUserServiceImpl.java | 1 + .../ten/controller/TenDeviceController.java | 269 +++- .../ten/controller/TenPersonController.java | 85 +- .../TenPersonExtractController.java | 11 +- .../controller/TenPersonSyncController.java | 83 ++ .../ten/controller/TenRecordController.java | 6 +- .../modules/ten/dao/TenCellDao.java | 14 +- .../modules/ten/dao/TenPersonDao.java | 5 + .../modules/ten/dao/TenPersonSyncDao.java | 40 + .../modules/ten/dao/TenRecordDao.java | 6 +- .../modules/ten/entity/TenCarEntity.java | 2 +- .../modules/ten/entity/TenDeviceEntity.java | 2 + .../ten/entity/TenPackRecordEntity.java | 2 +- .../modules/ten/entity/TenPersonEntity.java | 12 +- .../ten/entity/TenPersonExtractEntity.java | 5 + .../ten/entity/TenPersonSyncEntity.java | 58 + .../modules/ten/entity/TenRecordEntity.java | 2 +- .../modules/ten/entity/TenRoomEntity.java | 4 +- .../modules/ten/service/TenDeviceService.java | 4 +- .../modules/ten/service/TenPersonService.java | 6 +- .../ten/service/TenPersonSyncService.java | 42 + .../modules/ten/service/TenRecordService.java | 4 +- .../ten/service/impl/TenCellServiceImpl.java | 15 +- .../service/impl/TenDeviceServiceImpl.java | 63 +- .../impl/TenPersonExtractServiceImpl.java | 2 +- .../service/impl/TenPersonServiceImpl.java | 481 ++++--- .../impl/TenPersonSyncServiceImpl.java | 80 ++ .../service/impl/TenRecordServiceImpl.java | 36 +- .../ten/service/impl/TenUserServiceImpl.java | 2 + .../modules/vo/TenDeviceConfig.java | 24 +- .../modules/vo/TenPersonOperationVo.java | 26 + .../main/resources/mapper/ten/TenBuildDao.xml | 80 +- .../main/resources/mapper/ten/TenCarDao.xml | 38 +- .../main/resources/mapper/ten/TenCellDao.xml | 20 +- .../resources/mapper/ten/TenPackRecordDao.xml | 32 +- .../resources/mapper/ten/TenPersonDao.xml | 343 +++-- .../resources/mapper/ten/TenPersonSyncDao.xml | 167 +++ .../resources/mapper/ten/TenRecordDao.xml | 196 ++- .../main/resources/mapper/ten/TenRoomDao.xml | 87 +- shapelight-admin/src/test/java/gb/Cities.java | 7 + .../src/test/java/gb/ImageTest.java | 42 + .../src/test/java/gb/RandomValue.java | 186 +++ .../src/test/java/net/MyTest.java | 167 +++ .../src/test/java/net/ProcessImages.java | 34 + .../test/java/net/shapelight/BasicTest.java | 68 + .../test/java/net/shapelight/RedisTest.java | 30 + .../test/java/net/shapelight/SwaggerTo.java | 123 ++ 76 files changed, 4598 insertions(+), 2277 deletions(-) create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonProcessTask.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonSyncController.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonSyncEntity.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java create mode 100644 shapelight-admin/src/main/java/net/shapelight/modules/vo/TenPersonOperationVo.java create mode 100644 shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml create mode 100644 shapelight-admin/src/test/java/gb/Cities.java create mode 100644 shapelight-admin/src/test/java/gb/ImageTest.java create mode 100644 shapelight-admin/src/test/java/gb/RandomValue.java create mode 100644 shapelight-admin/src/test/java/net/MyTest.java create mode 100644 shapelight-admin/src/test/java/net/ProcessImages.java create mode 100644 shapelight-admin/src/test/java/net/shapelight/BasicTest.java create mode 100644 shapelight-admin/src/test/java/net/shapelight/RedisTest.java create mode 100644 shapelight-admin/src/test/java/net/shapelight/SwaggerTo.java diff --git a/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java b/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java index 772cf4b..60e851f 100644 --- a/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java +++ b/shapelight-admin/src/main/java/net/shapelight/AdminApplication.java @@ -2,7 +2,7 @@ package net.shapelight; -import net.shapelight.modules.dev.mqtt.MqttClientUtil; +//import net.shapelight.modules.dev.mqtt.MqttClientUtil; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -22,21 +22,21 @@ public class AdminApplication { public static void main(String[] args) { SpringApplication.run(AdminApplication.class, args); - //mqtt服务启动 - MqttClientUtil.createClient(); - - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - try { - //释放工作 - //... - - } catch (Throwable e) { - e.printStackTrace(); - } - } - }); +// //mqtt服务启动 +// MqttClientUtil.createClient(); +// +// Runtime.getRuntime().addShutdownHook(new Thread() { +// @Override +// public void run() { +// try { +// //释放工作 +// //... +// +// } catch (Throwable e) { +// e.printStackTrace(); +// } +// } +// }); } } 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 03725a2..ed5b8d4 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 @@ -61,8 +61,7 @@ public class Constant { public static final int PESON_SUATUS_WAITREVIEW = 2; //待审核 public static final int PESON_SUATUS_REJECT = 3; //审核不通过 public static final int PESON_SUATUS_FACE_FAILURE = 4; //照片质量不合格 -// public static final int PESON_SUATUS_DATE_NOT_START = 5; //访客时间未到 -// public static final int PESON_SUATUS_DATE_OUT = 6; //访客已过时 + public static final int PESON_SUATUS_GUEST_DATE_OUT = 5; //访客已过时 public static final String IMAGE_DIR_CAR = "car"; public static final String IMAGE_DIR_REPAIR= "repair"; @@ -84,6 +83,13 @@ public class Constant { public static final int COMPANY_TYPE_CHUZU = 46; + //0未同步4已同步1新增2修改3删除 + public static final int PERSON_SYNC_NO = 0; + public static final int PERSON_SYNC_OK = 4; + public static final int PERSON_SYNC_ADD = 1; + public static final int PERSON_SYNC_MODIFY = 2; + public static final int PERSON_SYNC_DELETE = 3; + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppApiController.java b/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppApiController.java index 6aa5e34..7922056 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppApiController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppApiController.java @@ -15,7 +15,8 @@ import net.shapelight.modules.app.entity.AppUserEntity; import net.shapelight.modules.app.entity.AppUserScopeEntity; import net.shapelight.modules.app.service.AppUserScopeService; import net.shapelight.modules.app.service.AppUserService; -import net.shapelight.modules.dev.mqtt.CmdProcess; +//import net.shapelight.modules.dev.mqtt.CmdProcess; +import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.entity.*; import net.shapelight.modules.sys.service.*; import io.swagger.annotations.Api; @@ -71,6 +72,8 @@ public class AppApiController { private SysUserService sysUserService; @Autowired private SysDeviceAppService sysDeviceAppService; + @Autowired + private ServerApiService serverApiService; @Login @@ -134,8 +137,6 @@ public class AppApiController { return R.error("姓名在此房间已存在"); } - - int res = tenPersonService.save(tenPerson); if (res==2) { return R.error("照片未检测到人脸"); @@ -155,7 +156,9 @@ public class AppApiController { tenPerson.setAppUserId(user.getUserId()); tenPerson.setPersonType(Constant.PERSON_TYPE_OWNER); tenPerson.setTenantId(cell.getTenantId()); - tenPerson.setCreateTime(new Date()); + Date now = new Date(); + tenPerson.setCreateTime(now); + tenPerson.setLastUpdateTime(now); tenPerson.setRegisterType(Constant.RESGISTER_TYPE_APP); tenPerson.setAppFlag(Constant.APP_LOGIN_YES); tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR); @@ -238,8 +241,6 @@ public class AppApiController { // public static final int PERSON_TYPE_GUEST = 5005; //访客 tenPerson.setPersonType(Constant.PERSON_TYPE_GUEST); tenPerson.setAppFlag(Constant.APP_LOGIN_NO); - - // TenPersonEntity tenPersonEntity = tenPersonService.findByName(tenPerson.getName(), // tenPerson.getRoomId(),tenPerson.getCellId()); // if(tenPersonEntity!=null){ @@ -365,17 +366,22 @@ public class AppApiController { public R remoteOpenDoor(@LoginUser AppUserEntity user, @RequestBody Map params) { AppUserScopeEntity scope = appUserScopeService.getById(user.getCurrentScopeId()); TenPersonEntity loginPerson = tenPersonService.getById(scope.getPersonId(),scope.getCellId()); - String personId = loginPerson.getPersonId().toString(); + Long personId = loginPerson.getPersonId(); //.toString(); String deviceSn = (String) params.get("deviceSn"); String cellId = loginPerson.getCellId().toString(); - TenPersonEntity person = tenPersonService.getById(Long.parseLong(personId),Long.parseLong(cellId)); + TenPersonEntity person = tenPersonService.getById(personId,Long.parseLong(cellId)); Integer memberId = person.getMemberId(); - boolean flag = tenDeviceService.remoteOpenDoor(deviceSn,personId,memberId); - if (flag) { - return R.ok(); - }else{ - return R.error("开门失败"); +// boolean flag = tenDeviceService.remoteOpenDoor(deviceSn,personId,memberId); +// if (flag) { +// return R.ok(); +// }else{ +// return R.error("开门失败"); +// } + int r = serverApiService.openDoor(deviceSn,personId); + if(r == -1){ + return R.error("设备离线"); } + return R.ok(); } @@ -423,8 +429,6 @@ public class AppApiController { return R.error("手机号已经注册"); } } - - TenPersonEntity tenPersonEntity = tenPersonService.findByName(tenPerson.getName(), tenPerson.getRoomId(),tenPerson.getCellId()); if(tenPersonEntity!=null){ @@ -438,6 +442,7 @@ public class AppApiController { tenPerson.setCreateBy(user.getUsername()); tenPerson.setCreateTime(new Date()); tenPerson.setRegisterType(Constant.RESGISTER_TYPE_APP); + tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR); int res = tenPersonService.save(tenPerson); if (res==2) { return R.error("照片未检测到人脸"); @@ -462,6 +467,10 @@ public class AppApiController { TenPersonEntity loginPerson = tenPersonService.getById(scope.getPersonId(),scope.getCellId()); TenCellEntity cell = tenCellService.getById(scope.getCellId()); + if(loginPerson.getStatus().intValue() != Constant.PESON_SUATUS_NOMOR){ + return R.error("您还没有审核通过,请联系小区管理员"); + } + // TenPersonEntity loginPerson = tenPersonService.getById(tenPerson.getAppLoginPersonId(),tenPerson.getCellId()); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppInfoApiController.java b/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppInfoApiController.java index fa97977..f9e1c11 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppInfoApiController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/app/controller/AppInfoApiController.java @@ -250,6 +250,8 @@ public class AppInfoApiController { public R openDoorRecordList(@LoginUser AppUserEntity user,@RequestBody Map params){ AppUserScopeEntity scope = appUserScopeService.getById(user.getCurrentScopeId()); + params.put("tenantId",user.getTenantId()); + int during = Integer.parseInt((String)params.get("during")); String recordTimeStart = null; String recordTimeEnd = null; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/AppSecret.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/AppSecret.java index 65be025..e18aaf5 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/AppSecret.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/AppSecret.java @@ -1,34 +1,34 @@ -package net.shapelight.modules.dev; - -import lombok.Data; -import net.shapelight.common.config.GlobalValue; -import net.shapelight.common.utils.MD5Utils; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.Date; - -@Data -public class AppSecret { - private String sysAppId; - private String sysAppSecret; - private String appId; - private String appSecret; - private String timestamp;//毫秒 - private String sign; - public int check(){ - if(!appId.equals(sysAppId)){ - return 1; - } - long now = new Date().getTime(); - long c = (Long.parseLong(timestamp)-now)/1000; - long abs = Math.abs(c); - if(abs > 30){ - return 2; - } - String sysSign = MD5Utils.getMD5Str(appId+timestamp+sysAppSecret); - if(!sign.equals(sysSign)){ - return 3; - } - return 0; - } -} +//package net.shapelight.modules.dev; +// +//import lombok.Data; +//import net.shapelight.common.config.GlobalValue; +//import net.shapelight.common.utils.MD5Utils; +//import org.springframework.beans.factory.annotation.Autowired; +// +//import java.util.Date; +// +//@Data +//public class AppSecret { +// private String sysAppId; +// private String sysAppSecret; +// private String appId; +// private String appSecret; +// private String timestamp;//毫秒 +// private String sign; +// public int check(){ +// if(!appId.equals(sysAppId)){ +// return 1; +// } +// long now = new Date().getTime(); +// long c = (Long.parseLong(timestamp)-now)/1000; +// long abs = Math.abs(c); +// if(abs > 30){ +// return 2; +// } +// String sysSign = MD5Utils.getMD5Str(appId+timestamp+sysAppSecret); +// if(!sign.equals(sysSign)){ +// return 3; +// } +// return 0; +// } +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/controller/DeviceController.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/controller/DeviceController.java index 081f222..c78acf0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/controller/DeviceController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/controller/DeviceController.java @@ -1,257 +1,121 @@ -package net.shapelight.modules.dev.controller; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import io.minio.MinioClient; -import io.minio.PutObjectOptions; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -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.*; -import net.shapelight.commons.engine.sdk.PicSDK; -import net.shapelight.modules.dev.AppSecret; -import net.shapelight.modules.dev.mqtt.EmqHttpApi; -import net.shapelight.modules.sys.entity.SysFileEntity; -import net.shapelight.modules.sys.service.SysFileService; -import net.shapelight.modules.ten.entity.TenDeviceEntity; -import net.shapelight.modules.ten.entity.TenPersonEntity; -import net.shapelight.modules.ten.entity.TenRecordEntity; -import net.shapelight.modules.ten.service.*; -import net.shapelight.modules.vo.TenDoorCardVo; -import net.shapelight.modules.vo.TenPersonIdUpdateVo; -import net.shapelight.modules.vo.TenPersonVo; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.io.FilenameUtils; -import org.omg.CORBA.ObjectHelper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.util.unit.DataUnit; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.util.UriComponentsBuilder; - -import javax.imageio.ImageIO; -import javax.swing.text.html.parser.Entity; -import java.awt.image.BufferedImage; -import java.io.*; -import java.net.URI; -import java.util.*; -import java.util.regex.Pattern; - -/** - * 设备接口 - */ -@RestController -@RequestMapping("/api/device") -@Api("Device接口") -@Slf4j -public class DeviceController { - @Autowired - private TenDeviceService tenDeviceService; - @Autowired - private TenRecordService tenRecordService; - @Autowired - private SysFileService sysFileService; - @Autowired - private RedisUtils redisUtils; - @Autowired - private TenDoorCardService tenDoorCardService; - @Autowired - private TenPersonService tenPersonService; - @Autowired - private TenCellService tenCellService; - @Autowired - private EmqHttpApi emqHttpApi; - @Autowired - private GlobalValue globalValue; - @Autowired - private MinioClient minioClient; - @Autowired - private MinioConfig minioConfig; - @Autowired - private RestTemplate restTemplate; - /** - * 保存 - */ - @PostMapping("/getUpdatePerson") - @ApiOperation(value = "获取更新的人员",response = TenPersonVo.class) - @ApiImplicitParams({ - @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), - }) - public R getUpdatePerson(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// BeanUtils.copyProperties(params, sec); -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - String lastUpdateTime = (String)params.get("lastUpdateTime"); - String sn = (String)params.get("sn"); - TenDeviceEntity dev = tenDeviceService.findBySn(sn); - if (dev==null) { - return R.error("设备未绑定"); - } - - List list = tenDeviceService.findUpdatePerson(dev.getCellId(), - dev.getBuildId(), - dev.getRoomId(), - lastUpdateTime); - log.info("获取人员信息:sn:"+sn+"-"+lastUpdateTime+" count:"+list.size()); - return R.ok().put("data",list); - } - - - @PostMapping("/getAllPerson") - @ApiOperation(value = "获取全部人员id和lastupdatetime",response = TenPersonVo.class) - @ApiImplicitParams({ - @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), - }) - public R getAllPerson(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// BeanUtils.copyProperties(params, sec); -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - String lastUpdateTime = (String)params.get("lastUpdateTime"); - String sn = (String)params.get("sn"); - TenDeviceEntity dev = tenDeviceService.findBySn(sn); - if (dev==null) { - return R.error("设备未绑定"); - } - - List list = tenDeviceService.findAllPersonIdUpdate(dev.getCellId(), - dev.getBuildId(), - dev.getRoomId()); - log.info("获取人员信息:sn:"+sn+"-"+lastUpdateTime+" count:"+list.size()); - return R.ok().put("data",list); - } - - - - @PostMapping("/getOnePerson") - @ApiOperation(value = "获取一个人的信息",response = TenPersonVo.class) - @ApiImplicitParams({ - @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="memberId",value = "人员id",paramType = "query",dataType = "String",required = true), - }) - public R getOnePerson(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// BeanUtils.copyProperties(params, sec); -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - String sn = (String)params.get("sn"); - TenDeviceEntity dev = tenDeviceService.findBySn(sn); - if (dev==null) { - return R.error("设备未绑定"); - } - - Integer memberId = (Integer)params.get("memberId"); - TenPersonEntity p = tenPersonService.getByMemberId(memberId,dev.getCellId()); - TenPersonVo vo = new TenPersonVo(); - if (p!=null) { - try { - - BeanUtils.copyProperties(vo,p); - - if (vo.getFaceImage() != null && !vo.getFaceImage().isEmpty()) { - String encode = ""; - InputStream inStream = null; - ByteArrayOutputStream outStream = null; - try { - minioClient.statObject(minioConfig.getBucketName(), vo.getFaceImage()); - - inStream = minioClient.getObject(minioConfig.getBucketName(), vo.getFaceImage()); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } - encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); - vo.setFaceImageStr(encode); - } catch (Exception e) { - log.error("底库不存在:" + vo.getFaceImage()); - e.printStackTrace(); - } finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - log.debug("inputStream close IOException:" + e.getMessage()); - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - log.debug("outStream close IOException:" + e.getMessage()); - } - } - } - - - try { - minioClient.statObject(minioConfig.getBucketName(), vo.getOrgImage()); - - inStream = minioClient.getObject(minioConfig.getBucketName(), vo.getOrgImage()); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } - encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); - vo.setOrgImageStr(encode); - } catch (Exception e) { - log.error("原始照片不存在:" + vo.getOrgImage()); - e.printStackTrace(); - } finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - log.debug("inputStream close IOException:" + e.getMessage()); - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - log.debug("outStream close IOException:" + e.getMessage()); - } - } - } - } - - }catch (Exception e){ - return R.error("拷贝失败"); - } - } - return R.ok().put("data",vo); - } - - - - -// @PostMapping("/getAllPerson") +//package net.shapelight.modules.dev.controller; +// +//import com.alibaba.fastjson.JSONObject; +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import io.minio.MinioClient; +//import io.minio.PutObjectOptions; +//import io.swagger.annotations.Api; +//import io.swagger.annotations.ApiImplicitParam; +//import io.swagger.annotations.ApiImplicitParams; +//import io.swagger.annotations.ApiOperation; +//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.*; +//import net.shapelight.commons.engine.sdk.PicSDK; +//import net.shapelight.modules.dev.AppSecret; +//import net.shapelight.modules.dev.mqtt.EmqHttpApi; +//import net.shapelight.modules.sys.entity.SysFileEntity; +//import net.shapelight.modules.sys.service.SysFileService; +//import net.shapelight.modules.ten.entity.TenDeviceEntity; +//import net.shapelight.modules.ten.entity.TenPersonEntity; +//import net.shapelight.modules.ten.entity.TenRecordEntity; +//import net.shapelight.modules.ten.service.*; +//import net.shapelight.modules.vo.TenDoorCardVo; +//import net.shapelight.modules.vo.TenPersonIdUpdateVo; +//import net.shapelight.modules.vo.TenPersonVo; +//import org.apache.commons.beanutils.BeanUtils; +//import org.apache.commons.io.FilenameUtils; +//import org.omg.CORBA.ObjectHelper; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.http.HttpMethod; +//import org.springframework.http.MediaType; +//import org.springframework.http.RequestEntity; +//import org.springframework.http.ResponseEntity; +//import org.springframework.util.unit.DataUnit; +//import org.springframework.web.bind.annotation.*; +//import org.springframework.web.client.RestTemplate; +//import org.springframework.web.multipart.MultipartFile; +//import org.springframework.web.util.UriComponentsBuilder; +// +//import javax.imageio.ImageIO; +//import javax.swing.text.html.parser.Entity; +//import java.awt.image.BufferedImage; +//import java.io.*; +//import java.net.URI; +//import java.util.*; +//import java.util.regex.Pattern; +// +///** +// * 设备接口 +// */ +//@RestController +//@RequestMapping("/api/device") +//@Api("Device接口") +//@Slf4j +//public class DeviceController { +// @Autowired +// private TenDeviceService tenDeviceService; +// @Autowired +// private TenRecordService tenRecordService; +// @Autowired +// private SysFileService sysFileService; +// @Autowired +// private RedisUtils redisUtils; +// @Autowired +// private TenDoorCardService tenDoorCardService; +// @Autowired +// private TenPersonService tenPersonService; +// @Autowired +// private TenCellService tenCellService; +// @Autowired +// private EmqHttpApi emqHttpApi; +// @Autowired +// private GlobalValue globalValue; +// @Autowired +// private MinioClient minioClient; +// @Autowired +// private MinioConfig minioConfig; +// @Autowired +// private RestTemplate restTemplate; +// /** +// * 保存 +// */ +// @PostMapping("/getUpdatePerson") // @ApiOperation(value = "获取更新的人员",response = TenPersonVo.class) -//// @ApiImplicitParams({ -//// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), -//// @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), -//// }) +// @ApiImplicitParams({ +// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), +// }) +// public R getUpdatePerson(@RequestBody Map params){ +//// AppSecret sec = new AppSecret(); +//// BeanUtils.copyProperties(params, sec); +//// int checkIn = sec.check(); +//// if(checkIn!=0){ +//// return R.error("Authentication failure:"+checkIn); +//// } +// String lastUpdateTime = (String)params.get("lastUpdateTime"); +// String sn = (String)params.get("sn"); +// TenDeviceEntity dev = tenDeviceService.findBySn(sn); +// if (dev==null) { +// return R.error("设备未绑定"); +// } +// +// List list = tenDeviceService.findUpdatePerson(dev.getCellId(), +// dev.getBuildId(), +// dev.getRoomId(), +// lastUpdateTime); +// log.info("获取人员信息:sn:"+sn+"-"+lastUpdateTime+" count:"+list.size()); +// return R.ok().put("data",list); +// } +// +// +// @PostMapping("/getAllPerson") +// @ApiOperation(value = "获取全部人员id和lastupdatetime",response = TenPersonVo.class) +// @ApiImplicitParams({ +// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// }) // public R getAllPerson(@RequestBody Map params){ //// AppSecret sec = new AppSecret(); //// BeanUtils.copyProperties(params, sec); @@ -266,393 +130,529 @@ public class DeviceController { // return R.error("设备未绑定"); // } // -// List list = tenDeviceService.findAllPerson(dev.getCellId(), +// List list = tenDeviceService.findAllPersonIdUpdate(dev.getCellId(), // dev.getBuildId(), -// dev.getRoomId(), -// lastUpdateTime); +// dev.getRoomId()); // log.info("获取人员信息:sn:"+sn+"-"+lastUpdateTime+" count:"+list.size()); // return R.ok().put("data",list); // } - - - - @PostMapping("/getUpdateDoorCard") - @ApiOperation(value = "获取更新的卡号",response = TenDoorCardVo.class) - @ApiImplicitParams({ - @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), - }) - public R getUpdateDoorCard(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// BeanUtils.copyProperties(params, sec); -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - String lastUpdateTime = (String)params.get("lastUpdateTime"); - String sn = (String)params.get("sn"); - TenDeviceEntity dev = tenDeviceService.findBySn(sn); - if (dev==null) { - return R.error("设备未绑定"); - } - List list = tenDoorCardService.findUpdate(dev.getCellId(), - lastUpdateTime); - return R.ok().put("data",list); - } - - - /** - * 上传识别记录 - */ - @PostMapping("/upRecord") - @ApiOperation(value = "上传人脸识别记录") - @ApiImplicitParams({ - @ApiImplicitParam(name="deviceSn",value = "设备SN",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="personId",value = "人员ID",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="memberId",value = "IntID",paramType = "query",dataType = "int",required = true), - @ApiImplicitParam(name="openType",value = "开门方式",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="recordTime",value = "开门时间",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="recordFaceStr",value = "识别照片base64",paramType = "query",dataType = "String",required = true), - }) - public R upRecord(@RequestBody TenRecordEntity record){ - //log.error("识别记录:"+record.getDeviceSn()+"-"+record.getMemberId()+"-"+record.getRecordTime()); - - TenDeviceEntity dev = tenDeviceService.findBySn(record.getDeviceSn()); - if (dev==null) { - return R.error("设备未绑定"); - } - TenDeviceEntity tenDeviceEntity = tenDeviceService.findBySn(record.getDeviceSn()); - record.setCellId(tenDeviceEntity.getCellId()); - - TenPersonEntity person = tenPersonService.getByMemberId(record.getMemberId(),record.getCellId()); - record.setPersonId(person.getPersonId()); -// log.info("保存记录:----------------------"+record.getRecordTime()+"-"+record.getMemberId().intValue()); - tenRecordService.saveForFace(record); - return R.ok(); - } - - - /** - * 上传识别记录 - */ - @PostMapping("/upRecordForDoorCard") - @ApiOperation(value = "上传门卡识别记录") - @ApiImplicitParams({ - @ApiImplicitParam(name="deviceSn",value = "设备SN",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="openType",value = "开门方式",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="recordTime",value = "开门时间",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="doorCard",value = "开门卡号",paramType = "query",dataType = "String",required = true), - }) - public R upRecordForDoorCard(@RequestBody TenRecordEntity record){ - TenDeviceEntity dev = tenDeviceService.findBySn(record.getDeviceSn()); - if (dev==null) { - return R.error("设备未绑定"); - } - tenRecordService.saveForDoorCard(record); - return R.ok(); - } - - - /** - * 通过业务id获取文件 - */ -// @PostMapping("/getFile") -// @ApiOperation(value = "文件信息",response = SysFileEntity.class) +// +// +// +// @PostMapping("/getOnePerson") +// @ApiOperation(value = "获取一个人的信息",response = TenPersonVo.class) // @ApiImplicitParams({ -// @ApiImplicitParam(name="serviceId",value = "业务ID",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="memberId",value = "人员id",paramType = "query",dataType = "String",required = true), // }) -// public R getFile(@RequestBody Map params){ -// List sysFile = sysFileService.list(new QueryWrapper().eq("service_id",params.get("serviceId"))); -// List urls = new ArrayList<>(); -// for (SysFileEntity entity: sysFile){ -// urls.add(entity.getUrl()); -// } -// return R.ok().put("data", urls); -// } - - - /** - * 获取一个用户所有小区id - */ - @PostMapping("/getcell") - @ApiImplicitParams({ - @ApiImplicitParam(name="userID",value = "业务ID",paramType = "query",dataType = "String",required = true), - }) - public R getcell(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// sec.setSysAppId(globalValue.getDevAppId()); -// sec.setSysAppSecret(globalValue.getDevAppSecret()); -// try { -// BeanUtils.copyProperties(sec,params); -// }catch (Exception e){ -// return R.error(""); -// } - -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - Set cellIds = tenCellService.findUserCellIdList(Long.parseLong((String)params.get("userId"))); - List cls = emqHttpApi.getWebClients(); - return R.ok().put("data", cellIds).put("cellIds",cls); - } - - - - /** - * 获取访客二维码 - */ - @PostMapping("/getVisitorCode") - @ApiImplicitParams({ - @ApiImplicitParam(name="sn",value = "sn",paramType = "query",dataType = "String",required = true), - }) - @ApiOperation(value = "获取访客二维码") - public R getVisitorCode(@RequestBody Map params){ -// AppSecret sec = new AppSecret(); -// sec.setSysAppId(globalValue.getDevAppId()); -// sec.setSysAppSecret(globalValue.getDevAppSecret()); -// try { -// BeanUtils.copyProperties(sec,params); -// }catch (Exception e){ -// return R.error(""); +// public R getOnePerson(@RequestBody Map params){ +//// AppSecret sec = new AppSecret(); +//// BeanUtils.copyProperties(params, sec); +//// int checkIn = sec.check(); +//// if(checkIn!=0){ +//// return R.error("Authentication failure:"+checkIn); +//// } +// String sn = (String)params.get("sn"); +// TenDeviceEntity dev = tenDeviceService.findBySn(sn); +// if (dev==null) { +// return R.error("设备未绑定"); // } // -// int checkIn = sec.check(); -// if(checkIn!=0){ -// return R.error("Authentication failure:"+checkIn); -// } - - String sn = (String)params.get("sn"); - TenDeviceEntity dev = tenDeviceService.findBySn(sn); - if (dev==null) { - return R.error("设备未绑定"); - } - //获取小区ID - Long cellId = dev.getCellId(); - //获取二维码图片 - String codeFileUrl = globalValue.getImagesDir() + "/" + - cellId.toString() + "/vc.jpg"; - String encode = ""; - InputStream inStream = null; - ByteArrayOutputStream outStream = null; - try { - // 调用statObject()来判断对象是否存在。 - // 如果不存在, statObject()抛出异常, - // 否则则代表对象存在。 - minioClient.statObject(minioConfig.getBucketName(), codeFileUrl); - - inStream = minioClient.getObject(minioConfig.getBucketName(), codeFileUrl); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } -// encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); -// return R.ok().put("visitorCode",encode); - Map codeUrl = new HashMap<>(); - codeUrl.put("url",codeFileUrl); - return R.ok().put("data",codeUrl); - - } catch (Exception e) { - e.printStackTrace(); - - try { -// String extension = "jpg"; //后缀名 - String fileName = codeFileUrl; - //微信接口生成二维码 - //1.调用凭证 - //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxf59991f23f1f5500&secret=30b523b2bdd7b0739b7f06e9dc1519f8 - JSONObject appApprams = new JSONObject(); - StringBuffer tokenUrl = new StringBuffer(); - tokenUrl.append("https://api.weixin.qq.com/cgi-bin/token"); - tokenUrl.append("?"); - tokenUrl.append("grant_type="+"client_credential"); - tokenUrl.append("&appid="+globalValue.getWxAppid()); - tokenUrl.append("&secret="+globalValue.getWxSecret()); - ResponseEntity results = restTemplate.exchange(tokenUrl.toString(), HttpMethod.GET, null, String.class); - JSONObject resultJson = JSONObject.parseObject(results.getBody()); - String accessToken = resultJson.getString("access_token"); - if (accessToken==null) { - return R.error(resultJson.getString("errmsg")); - } - - //2.获取二维码 - //POST https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN - String cadeUrl = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="+accessToken; - JSONObject postData = new JSONObject(); - postData.put("path", "pages/add-visitor/add-visitor?cellId="+cellId); - postData.put("width", 300); -// InputStream postJson = restTemplate.postForObject(cadeUrl, postData, InputStream.class); - URI uri = UriComponentsBuilder.fromUriString(cadeUrl).build().toUri(); - RequestEntity requestEntity = RequestEntity.post(uri) - .accept(MediaType.APPLICATION_JSON) - .header("Content-Type", "application/json") - .body(postData.toJSONString()); - - ResponseEntity resultPost = restTemplate.exchange(cadeUrl, HttpMethod.POST, requestEntity, String.class); - byte[] bytes = resultPost.getBody().getBytes("ISO-8859-1"); - InputStream inputStream = new ByteArrayInputStream(bytes); - PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); - putObjectOptions.setContentType("image/jpeg"); - minioClient.putObject( - minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); - inputStream.close(); - - - // 调用statObject()来判断对象是否存在。 - // 如果不存在, statObject()抛出异常, - // 否则则代表对象存在。 - minioClient.statObject(minioConfig.getBucketName(), codeFileUrl); - - inStream = minioClient.getObject(minioConfig.getBucketName(), codeFileUrl); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } - encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); -// return R.ok().put("visitorCode",encode); - Map codeUrl = new HashMap<>(); - codeUrl.put("url",codeFileUrl); - return R.ok().put("data",codeUrl); - } catch (Exception ee) { - return R.error(ee.getMessage()); - } - }finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - log.debug("inputStream close IOException:" + e.getMessage()); - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - log.debug("outStream close IOException:" + e.getMessage()); - } - } - } - } - - - - /** - * 获取系统时间 - */ - @PostMapping("/getServerTime") - public R getServerTime(){ - String now = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN); - return R.ok().put("data", now); - } - - - - @PostMapping("/bachOrgImage") - @ApiOperation(value = "批处理",response = TenPersonVo.class) - @ApiImplicitParams({ - @ApiImplicitParam(name="cellId",value = "小区id",paramType = "query",dataType = "String",required = true), - }) - public R bachOrgImage(@RequestBody Map params){ - Long cellId = Long.parseLong((String)params.get("cellId")); - List list = tenPersonService.findAllByCellId(cellId); - - for (int i = 0;i 1080 || h > 1080) { - Thumbnails.of(orgFileStr) - .size(1080, 1080) - .toFile(orgFileStr); - } - - vo.setOrgImageStr("w:"+w+"h:"+h+orgFileStr); - }catch (Exception e){ - log.error("批处理图片大小失败"); - log.error(e.getMessage()); - } - } - } - - return R.ok().put("data",list); - } - - /** - * 获取一个用户所有小区id - */ - -// @PostMapping("/redisTest") -// public R redisTest(@RequestBody Map params){ -// TenPersonEntity personEntity = new TenPersonEntity(); -// Long id = new SnowflakeIdWorker().nextId(); -// personEntity.setPersonId(id); -// personEntity.setCellId(23420342L); -// personEntity.setStatus(Constant.PESON_SUATUS_DATE_OUT); -// redisUtils.set("s-"+id.toString()+"-"+"2323232",personEntity,5L); -// redisUtils.set("e-"+id.toString()+"-"+"2323232",personEntity,10L); -// return R.ok().put("data",personEntity); -// } - - // -// @PostMapping("/uploadTest") -// @ApiOperation("上传单个学生照片") -// public R uploadTest(@RequestParam("file") MultipartFile file){ -// try -// { -// String savePath = "/home/server001/project/cell/"; -//// String savePath = "d:/temp/images/"; -// String extension = FilenameUtils.getExtension(file.getOriginalFilename()); //后缀名 -// if(!extension.equalsIgnoreCase("jpg")){ -// return R.error("文件格式不对"); +// +// try { +// minioClient.statObject(minioConfig.getBucketName(), vo.getOrgImage()); +// +// inStream = minioClient.getObject(minioConfig.getBucketName(), vo.getOrgImage()); +// outStream = new ByteArrayOutputStream(); +// byte[] buffer = new byte[1024]; +// int length; +// while ((length = inStream.read(buffer)) != -1) { +// outStream.write(buffer, 0, length); +// } +// encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); +// vo.setOrgImageStr(encode); +// } catch (Exception e) { +// log.error("原始照片不存在:" + vo.getOrgImage()); +// e.printStackTrace(); +// } finally { +// if (inStream != null) { +// try { +// inStream.close(); +// } catch (IOException e) { +// log.debug("inputStream close IOException:" + e.getMessage()); +// } +// } +// if (outStream != null) { +// try { +// outStream.close(); +// } catch (IOException e) { +// log.debug("outStream close IOException:" + e.getMessage()); +// } +// } +// } +// } +// +// }catch (Exception e){ +// return R.error("拷贝失败"); // } -// //String filename = UUIDUtil.uuid()+"."+extension; //文件名 -// String uuid = UUIDUtil.uuid(); -// String orgStr = savePath+file.getOriginalFilename(); -// String faceStr = savePath+UUIDUtil.uuid()+".jpg"; -// -// File jpgFile = new File(orgStr); -// /*if (!jpgFile.exists()) -// { -// jpgFile.createNewFile(); -// }*/ -// file.transferTo(jpgFile); -// -// int res = PicSDK.getFace(orgStr, faceStr); -// log.info("截图:"+res); -// if(res == 0){ -// -// }else{ -// return R.error("图片不合格"); -// } -// -// return R.ok(); -// } -// catch (Exception e) -// { -// return R.error(e.getMessage()); // } +// return R.ok().put("data",vo); // } // // // // - - - - -} +//// @PostMapping("/getAllPerson") +//// @ApiOperation(value = "获取更新的人员",response = TenPersonVo.class) +////// @ApiImplicitParams({ +////// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), +////// @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), +////// }) +//// public R getAllPerson(@RequestBody Map params){ +////// AppSecret sec = new AppSecret(); +////// BeanUtils.copyProperties(params, sec); +////// int checkIn = sec.check(); +////// if(checkIn!=0){ +////// return R.error("Authentication failure:"+checkIn); +////// } +//// String lastUpdateTime = (String)params.get("lastUpdateTime"); +//// String sn = (String)params.get("sn"); +//// TenDeviceEntity dev = tenDeviceService.findBySn(sn); +//// if (dev==null) { +//// return R.error("设备未绑定"); +//// } +//// +//// List list = tenDeviceService.findAllPerson(dev.getCellId(), +//// dev.getBuildId(), +//// dev.getRoomId(), +//// lastUpdateTime); +//// log.info("获取人员信息:sn:"+sn+"-"+lastUpdateTime+" count:"+list.size()); +//// return R.ok().put("data",list); +//// } +// +// +// +// @PostMapping("/getUpdateDoorCard") +// @ApiOperation(value = "获取更新的卡号",response = TenDoorCardVo.class) +// @ApiImplicitParams({ +// @ApiImplicitParam(name="sn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="lastUpdateTime",value = "时间",paramType = "query",dataType = "String",required = true), +// }) +// public R getUpdateDoorCard(@RequestBody Map params){ +//// AppSecret sec = new AppSecret(); +//// BeanUtils.copyProperties(params, sec); +//// int checkIn = sec.check(); +//// if(checkIn!=0){ +//// return R.error("Authentication failure:"+checkIn); +//// } +// String lastUpdateTime = (String)params.get("lastUpdateTime"); +// String sn = (String)params.get("sn"); +// TenDeviceEntity dev = tenDeviceService.findBySn(sn); +// if (dev==null) { +// return R.error("设备未绑定"); +// } +// List list = tenDoorCardService.findUpdate(dev.getCellId(), +// lastUpdateTime); +// return R.ok().put("data",list); +// } +// +// +// /** +// * 上传识别记录 +// */ +// @PostMapping("/upRecord") +// @ApiOperation(value = "上传人脸识别记录") +// @ApiImplicitParams({ +// @ApiImplicitParam(name="deviceSn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="personId",value = "人员ID",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="memberId",value = "IntID",paramType = "query",dataType = "int",required = true), +// @ApiImplicitParam(name="openType",value = "开门方式",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="recordTime",value = "开门时间",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="recordFaceStr",value = "识别照片base64",paramType = "query",dataType = "String",required = true), +// }) +// public R upRecord(@RequestBody TenRecordEntity record){ +// //log.error("识别记录:"+record.getDeviceSn()+"-"+record.getMemberId()+"-"+record.getRecordTime()); +// +// TenDeviceEntity dev = tenDeviceService.findBySn(record.getDeviceSn()); +// if (dev==null) { +// return R.error("设备未绑定"); +// } +// TenDeviceEntity tenDeviceEntity = tenDeviceService.findBySn(record.getDeviceSn()); +// record.setCellId(tenDeviceEntity.getCellId()); +// +// TenPersonEntity person = tenPersonService.getByMemberId(record.getMemberId(),record.getCellId()); +// record.setPersonId(person.getPersonId()); +//// log.info("保存记录:----------------------"+record.getRecordTime()+"-"+record.getMemberId().intValue()); +// tenRecordService.saveForFace(record); +// return R.ok(); +// } +// +// +// /** +// * 上传识别记录 +// */ +// @PostMapping("/upRecordForDoorCard") +// @ApiOperation(value = "上传门卡识别记录") +// @ApiImplicitParams({ +// @ApiImplicitParam(name="deviceSn",value = "设备SN",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="openType",value = "开门方式",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="recordTime",value = "开门时间",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="doorCard",value = "开门卡号",paramType = "query",dataType = "String",required = true), +// }) +// public R upRecordForDoorCard(@RequestBody TenRecordEntity record){ +// TenDeviceEntity dev = tenDeviceService.findBySn(record.getDeviceSn()); +// if (dev==null) { +// return R.error("设备未绑定"); +// } +// tenRecordService.saveForDoorCard(record); +// return R.ok(); +// } +// +// +// /** +// * 通过业务id获取文件 +// */ +//// @PostMapping("/getFile") +//// @ApiOperation(value = "文件信息",response = SysFileEntity.class) +//// @ApiImplicitParams({ +//// @ApiImplicitParam(name="serviceId",value = "业务ID",paramType = "query",dataType = "String",required = true), +//// }) +//// public R getFile(@RequestBody Map params){ +//// List sysFile = sysFileService.list(new QueryWrapper().eq("service_id",params.get("serviceId"))); +//// List urls = new ArrayList<>(); +//// for (SysFileEntity entity: sysFile){ +//// urls.add(entity.getUrl()); +//// } +//// return R.ok().put("data", urls); +//// } +// +// +// /** +// * 获取一个用户所有小区id +// */ +// @PostMapping("/getcell") +// @ApiImplicitParams({ +// @ApiImplicitParam(name="userID",value = "业务ID",paramType = "query",dataType = "String",required = true), +// }) +// public R getcell(@RequestBody Map params){ +//// AppSecret sec = new AppSecret(); +//// sec.setSysAppId(globalValue.getDevAppId()); +//// sec.setSysAppSecret(globalValue.getDevAppSecret()); +//// try { +//// BeanUtils.copyProperties(sec,params); +//// }catch (Exception e){ +//// return R.error(""); +//// } +// +//// int checkIn = sec.check(); +//// if(checkIn!=0){ +//// return R.error("Authentication failure:"+checkIn); +//// } +// Set cellIds = tenCellService.findUserCellIdList(Long.parseLong((String)params.get("userId"))); +// List cls = emqHttpApi.getWebClients(); +// return R.ok().put("data", cellIds).put("cellIds",cls); +// } +// +// +// +// /** +// * 获取访客二维码 +// */ +// @PostMapping("/getVisitorCode") +// @ApiImplicitParams({ +// @ApiImplicitParam(name="sn",value = "sn",paramType = "query",dataType = "String",required = true), +// }) +// @ApiOperation(value = "获取访客二维码") +// public R getVisitorCode(@RequestBody Map params){ +//// AppSecret sec = new AppSecret(); +//// sec.setSysAppId(globalValue.getDevAppId()); +//// sec.setSysAppSecret(globalValue.getDevAppSecret()); +//// try { +//// BeanUtils.copyProperties(sec,params); +//// }catch (Exception e){ +//// return R.error(""); +//// } +//// +//// int checkIn = sec.check(); +//// if(checkIn!=0){ +//// return R.error("Authentication failure:"+checkIn); +//// } +// +// String sn = (String)params.get("sn"); +// TenDeviceEntity dev = tenDeviceService.findBySn(sn); +// if (dev==null) { +// return R.error("设备未绑定"); +// } +// //获取小区ID +// Long cellId = dev.getCellId(); +// //获取二维码图片 +// String codeFileUrl = globalValue.getImagesDir() + "/" + +// cellId.toString() + "/vc.jpg"; +// String encode = ""; +// InputStream inStream = null; +// ByteArrayOutputStream outStream = null; +// try { +// // 调用statObject()来判断对象是否存在。 +// // 如果不存在, statObject()抛出异常, +// // 否则则代表对象存在。 +// minioClient.statObject(minioConfig.getBucketName(), codeFileUrl); +// +// inStream = minioClient.getObject(minioConfig.getBucketName(), codeFileUrl); +// outStream = new ByteArrayOutputStream(); +// byte[] buffer = new byte[1024]; +// int length; +// while ((length = inStream.read(buffer)) != -1) { +// outStream.write(buffer, 0, length); +// } +//// encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); +//// return R.ok().put("visitorCode",encode); +// Map codeUrl = new HashMap<>(); +// codeUrl.put("url",codeFileUrl); +// return R.ok().put("data",codeUrl); +// +// } catch (Exception e) { +// e.printStackTrace(); +// +// try { +//// String extension = "jpg"; //后缀名 +// String fileName = codeFileUrl; +// //微信接口生成二维码 +// //1.调用凭证 +// //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxf59991f23f1f5500&secret=30b523b2bdd7b0739b7f06e9dc1519f8 +// JSONObject appApprams = new JSONObject(); +// StringBuffer tokenUrl = new StringBuffer(); +// tokenUrl.append("https://api.weixin.qq.com/cgi-bin/token"); +// tokenUrl.append("?"); +// tokenUrl.append("grant_type="+"client_credential"); +// tokenUrl.append("&appid="+globalValue.getWxAppid()); +// tokenUrl.append("&secret="+globalValue.getWxSecret()); +// ResponseEntity results = restTemplate.exchange(tokenUrl.toString(), HttpMethod.GET, null, String.class); +// JSONObject resultJson = JSONObject.parseObject(results.getBody()); +// String accessToken = resultJson.getString("access_token"); +// if (accessToken==null) { +// return R.error(resultJson.getString("errmsg")); +// } +// +// //2.获取二维码 +// //POST https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN +// String cadeUrl = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="+accessToken; +// JSONObject postData = new JSONObject(); +// postData.put("path", "pages/add-visitor/add-visitor?cellId="+cellId); +// postData.put("width", 300); +//// InputStream postJson = restTemplate.postForObject(cadeUrl, postData, InputStream.class); +// URI uri = UriComponentsBuilder.fromUriString(cadeUrl).build().toUri(); +// RequestEntity requestEntity = RequestEntity.post(uri) +// .accept(MediaType.APPLICATION_JSON) +// .header("Content-Type", "application/json") +// .body(postData.toJSONString()); +// +// ResponseEntity resultPost = restTemplate.exchange(cadeUrl, HttpMethod.POST, requestEntity, String.class); +// byte[] bytes = resultPost.getBody().getBytes("ISO-8859-1"); +// InputStream inputStream = new ByteArrayInputStream(bytes); +// PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); +// putObjectOptions.setContentType("image/jpeg"); +// minioClient.putObject( +// minioConfig.getBucketName(), fileName, inputStream, putObjectOptions); +// inputStream.close(); +// +// +// // 调用statObject()来判断对象是否存在。 +// // 如果不存在, statObject()抛出异常, +// // 否则则代表对象存在。 +// minioClient.statObject(minioConfig.getBucketName(), codeFileUrl); +// +// inStream = minioClient.getObject(minioConfig.getBucketName(), codeFileUrl); +// outStream = new ByteArrayOutputStream(); +// byte[] buffer = new byte[1024]; +// int length; +// while ((length = inStream.read(buffer)) != -1) { +// outStream.write(buffer, 0, length); +// } +// encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); +//// return R.ok().put("visitorCode",encode); +// Map codeUrl = new HashMap<>(); +// codeUrl.put("url",codeFileUrl); +// return R.ok().put("data",codeUrl); +// } catch (Exception ee) { +// return R.error(ee.getMessage()); +// } +// }finally { +// if (inStream != null) { +// try { +// inStream.close(); +// } catch (IOException e) { +// log.debug("inputStream close IOException:" + e.getMessage()); +// } +// } +// if (outStream != null) { +// try { +// outStream.close(); +// } catch (IOException e) { +// log.debug("outStream close IOException:" + e.getMessage()); +// } +// } +// } +// } +// +// +// +// /** +// * 获取系统时间 +// */ +// @PostMapping("/getServerTime") +// public R getServerTime(){ +// String now = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN); +// return R.ok().put("data", now); +// } +// +// +// +// @PostMapping("/bachOrgImage") +// @ApiOperation(value = "批处理",response = TenPersonVo.class) +// @ApiImplicitParams({ +// @ApiImplicitParam(name="cellId",value = "小区id",paramType = "query",dataType = "String",required = true), +// }) +// public R bachOrgImage(@RequestBody Map params){ +// Long cellId = Long.parseLong((String)params.get("cellId")); +// List list = tenPersonService.findAllByCellId(cellId); +// +// for (int i = 0;i 1080 || h > 1080) { +// Thumbnails.of(orgFileStr) +// .size(1080, 1080) +// .toFile(orgFileStr); +// } +// +// vo.setOrgImageStr("w:"+w+"h:"+h+orgFileStr); +// }catch (Exception e){ +// log.error("批处理图片大小失败"); +// log.error(e.getMessage()); +// } +// } +// } +// +// return R.ok().put("data",list); +// } +// +// /** +// * 获取一个用户所有小区id +// */ +// +//// @PostMapping("/redisTest") +//// public R redisTest(@RequestBody Map params){ +//// TenPersonEntity personEntity = new TenPersonEntity(); +//// Long id = new SnowflakeIdWorker().nextId(); +//// personEntity.setPersonId(id); +//// personEntity.setCellId(23420342L); +//// personEntity.setStatus(Constant.PESON_SUATUS_DATE_OUT); +//// redisUtils.set("s-"+id.toString()+"-"+"2323232",personEntity,5L); +//// redisUtils.set("e-"+id.toString()+"-"+"2323232",personEntity,10L); +//// return R.ok().put("data",personEntity); +//// } +// +// +//// +//// @PostMapping("/uploadTest") +//// @ApiOperation("上传单个学生照片") +//// public R uploadTest(@RequestParam("file") MultipartFile file){ +//// try +//// { +//// String savePath = "/home/server001/project/cell/"; +////// String savePath = "d:/temp/images/"; +//// String extension = FilenameUtils.getExtension(file.getOriginalFilename()); //后缀名 +//// if(!extension.equalsIgnoreCase("jpg")){ +//// return R.error("文件格式不对"); +//// } +//// //String filename = UUIDUtil.uuid()+"."+extension; //文件名 +//// String uuid = UUIDUtil.uuid(); +//// String orgStr = savePath+file.getOriginalFilename(); +//// String faceStr = savePath+UUIDUtil.uuid()+".jpg"; +//// +//// File jpgFile = new File(orgStr); +//// /*if (!jpgFile.exists()) +//// { +//// jpgFile.createNewFile(); +//// }*/ +//// file.transferTo(jpgFile); +//// +//// int res = PicSDK.getFace(orgStr, faceStr); +//// log.info("截图:"+res); +//// if(res == 0){ +//// +//// }else{ +//// return R.error("图片不合格"); +//// } +//// +//// return R.ok(); +//// } +//// catch (Exception e) +//// { +//// return R.error(e.getMessage()); +//// } +//// } +//// +//// +//// +//// +// +// +// +// +//} 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 d3b71ff..2a3ec4f 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 @@ -1,411 +1,411 @@ -package net.shapelight.modules.dev.mqtt; - - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.JsonObject; -import lombok.extern.slf4j.Slf4j; -import net.shapelight.common.utils.DateUtils; -import net.shapelight.common.utils.RedisUtils; -import net.shapelight.modules.ten.entity.TenDeviceAlertEntity; -import net.shapelight.modules.ten.entity.TenDeviceEntity; -import net.shapelight.modules.ten.entity.TenPersonEntity; -import net.shapelight.modules.ten.entity.TenRecordEntity; -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; - -import javax.annotation.PostConstruct; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@Component -public class CmdProcess { - private static CmdProcess cmdProcess; - - @Autowired - private RedisUtils redisUtils; - @Autowired - private TenDeviceService tenDeviceService; - - public void setRedisUtils(RedisUtils redisUtils) { - this.redisUtils = redisUtils; - } - - public void setTenDeviceService(TenDeviceService tenDeviceService) { - this.tenDeviceService = tenDeviceService; - } - - @PostConstruct - public void init(){ - cmdProcess = this; - cmdProcess.redisUtils = this.redisUtils; - cmdProcess.tenDeviceService = this.tenDeviceService; - } - - public static void execute(String topic, String content) { - JSONObject contentJson = JSONObject.parseObject(content); - String deviceSn = topic.substring(topic.indexOf("device/") + 7, topic.lastIndexOf("/client")); - String cmd = contentJson.getString("cmd"); - TopicCmdEnum cmdEnum = TopicCmdEnum.valueOf(cmd); - switch (cmdEnum) { - case remoteOpenDoor: - log.info("removeOpenDoor:", cmdEnum.getCmd()); - subscribeRemoteOpenDoor(deviceSn,content); - break; - case personChange: - log.info("personChange", cmdEnum.getCmd()); - break; - case cleanPerson: - log.info("cleanPerson", cmdEnum.getCmd()); - break; - case faceCount: - subFaceCount(deviceSn,content); - log.info("faceCount", cmdEnum.getCmd()); - break; - case alert: - subAlert(deviceSn,content); - log.info("alert", cmdEnum.getCmd()); - break; - case addPerson: - log.info("addPerson", cmdEnum.getCmd()); - break; - case getParam: - subGetParam(deviceSn,content); - log.info("getParam", cmdEnum.getCmd()); - break; - } - } - - /** - * { - * "cmd": "remoteOpenDoor", - * "data": { - * "personId": "721041148851781632", - * } - * } - * @param deviceSn - * @param memberId - */ - public static void publishRemoteOpenDoor(String deviceSn,Integer memberId){ - //获取 发送给 指定id 的app用户的topic - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); -// sendContent.put("cmd", cmd_id + "/response"); -// sendContent.put("ret", "0"); -// sendContent.put("msg", "测试消息已经处成功处理"); -// sendContent.put("code", 0); - Map data = new HashMap<>(); -// data.put("personId",personId); - TenDeviceEntity device = cmdProcess.tenDeviceService.findBySn(deviceSn); -// TenPersonEntity personEntity = cmdProcess.tenDeviceService.getByPersonId(Long.parseLong(personId),device.getCellId()); - data.put("memberId",memberId); - data.put("deviceSn",deviceSn); - sendContent.put("cmd", "remoteOpenDoor"); - sendContent.put("data", data); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - - } - - /** - * - * @param deviceSn - * @param content - * { - * "cmd":"remoteOpenDoor", - * "data":{ - * "personId":"721041148851781632", - * "recordTime":"2020-07-06 14:36:23", - * "openType":2, //1人脸识别2远程一键开门 - * "recordFaceStr":"/9j/4AAQSkZJRgABAQAAAQABAAD" - * } - * } - */ - private static void subscribeRemoteOpenDoor(String deviceSn,String content){ - JSONObject resJson = JSONObject.parseObject(content); - JSONObject data = resJson.getJSONObject("data"); -// String personId = data.getString("personId"); - Integer memberId = data.getInteger("memberId"); - String recordTime = data.getString("recordTime"); - Integer openType = data.getInteger("openType"); - - TenDeviceEntity device = cmdProcess.tenDeviceService.findBySn(deviceSn); - TenPersonEntity person = cmdProcess.tenDeviceService.getByMemberId(memberId,device.getCellId()); - - TenRecordEntity record = new TenRecordEntity(); - record.setDeviceSn(deviceSn); - record.setPersonId(person.getPersonId()); - record.setCellId(device.getCellId()); -// DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); -// LocalDateTime parse = LocalDateTime.parse(recordTime, dtf); - record.setRecordTime(new Date()); - record.setOpenType(openType); - //添加到redis -// cmdProcess.redisUtils.set(personId+"-"+deviceSn,openDate,60L); - cmdProcess.redisUtils.set(person.getPersonId()+"-"+deviceSn,recordTime,10L); - //添加到记录里 -// log.info("----------------------------------------收到意见开门记录"); - cmdProcess.tenDeviceService.upRecord(record); - } - - /** - * - * @param deviceSn - * - * { - * "cmd":" personChange", - * "data":{ - * } - * } - */ - - public static void publishPersonChange(String deviceSn){ - //获取 发送给 指定id 的app用户的topic - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); - Map data = new HashMap<>(); - sendContent.put("cmd", "personChange"); - sendContent.put("data", data); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } - - - /** - * - * @param deviceSn - * - * { - * "cmd":"addPerson", - * "data":{TenPersonVo - * } - * } - */ - - public static void publishAddPerson(String deviceSn, TenPersonVo personVo){ - //获取 发送给 指定id 的app用户的topic - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); -// Map data = new HashMap<>(); - sendContent.put("cmd", "addPerson"); - sendContent.put("data", personVo); -// if(((JSONObject)sendContent.get("data")).get("liveStart")!=null){ -// ((JSONObject)sendContent.get("data")).put("liveStart", DateUtils.format(personVo.getLiveStart(),DateUtils.DATE_TIME_PATTERN)); -// } +//package net.shapelight.modules.dev.mqtt; // -// if(((JSONObject)sendContent.get("data")).get("liveEnd")!=null){ -// ((JSONObject)sendContent.get("data")).put("liveEnd", DateUtils.format(personVo.getLiveEnd(),DateUtils.DATE_TIME_PATTERN)); +// +//import com.alibaba.fastjson.JSONArray; +//import com.alibaba.fastjson.JSONObject; +//import com.google.gson.JsonObject; +//import lombok.extern.slf4j.Slf4j; +//import net.shapelight.common.utils.DateUtils; +//import net.shapelight.common.utils.RedisUtils; +//import net.shapelight.modules.ten.entity.TenDeviceAlertEntity; +//import net.shapelight.modules.ten.entity.TenDeviceEntity; +//import net.shapelight.modules.ten.entity.TenPersonEntity; +//import net.shapelight.modules.ten.entity.TenRecordEntity; +//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; +// +//import javax.annotation.PostConstruct; +//import java.time.LocalDateTime; +//import java.time.format.DateTimeFormatter; +//import java.util.Date; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//@Slf4j +//@Component +//public class CmdProcess { +// private static CmdProcess cmdProcess; +// +// @Autowired +// private RedisUtils redisUtils; +// @Autowired +// private TenDeviceService tenDeviceService; +// +// public void setRedisUtils(RedisUtils redisUtils) { +// this.redisUtils = redisUtils; +// } +// +// public void setTenDeviceService(TenDeviceService tenDeviceService) { +// this.tenDeviceService = tenDeviceService; +// } +// +// @PostConstruct +// public void init(){ +// cmdProcess = this; +// cmdProcess.redisUtils = this.redisUtils; +// cmdProcess.tenDeviceService = this.tenDeviceService; +// } +// +// public static void execute(String topic, String content) { +// JSONObject contentJson = JSONObject.parseObject(content); +// String deviceSn = topic.substring(topic.indexOf("device/") + 7, topic.lastIndexOf("/client")); +// String cmd = contentJson.getString("cmd"); +// TopicCmdEnum cmdEnum = TopicCmdEnum.valueOf(cmd); +// switch (cmdEnum) { +// case remoteOpenDoor: +// log.info("removeOpenDoor:", cmdEnum.getCmd()); +// subscribeRemoteOpenDoor(deviceSn,content); +// break; +// case personChange: +// log.info("personChange", cmdEnum.getCmd()); +// break; +// case cleanPerson: +// log.info("cleanPerson", cmdEnum.getCmd()); +// break; +// case faceCount: +// subFaceCount(deviceSn,content); +// log.info("faceCount", cmdEnum.getCmd()); +// break; +// case alert: +// subAlert(deviceSn,content); +// log.info("alert", cmdEnum.getCmd()); +// break; +// case addPerson: +// log.info("addPerson", cmdEnum.getCmd()); +// break; +// case getParam: +// subGetParam(deviceSn,content); +// log.info("getParam", cmdEnum.getCmd()); +// break; // } - - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } - - - - - /** - * - * @param deviceSn - * - * { - * "cmd":" cleanPerson", - * "data":{ - * } - * } - */ - public static void publishCleanPerson(String deviceSn){ - //获取 发送给 指定id 的app用户的topic - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); - Map data = new HashMap<>(); - sendContent.put("cmd", "cleanPerson"); - sendContent.put("data", data); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } - - /** - * - * @param deviceSn - * - * { - * "cmd":" updateApp", - * "data":{ - * "apkUrl":"https://2222.apk" - * } - * } - */ - public static void publishUpdateApp(String deviceSn,String apkUrl){ - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); - Map data = new HashMap<>(); - data.put("apkUrl",apkUrl); - sendContent.put("cmd", "updateApp"); - sendContent.put("data", data); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } - - - - /** - * - * @param deviceSn - * @param content - * { - * "cmd": "faceCount" - * "data": { - * "faceCount":23, - * "faceFailurePerson": - * [730721748076462081, 730721748076462082, 730721748076462083] - * } - * } - */ - private static void subFaceCount(String deviceSn,String content){ - JSONObject resJson = JSONObject.parseObject(content); - JSONObject data = resJson.getJSONObject("data"); - Integer faceCount = data.getInteger("faceCount"); - if(faceCount!=null){ - log.info("收到人脸库个数:"+faceCount); - cmdProcess.tenDeviceService.updateFaceCount(deviceSn,faceCount); - } - JSONArray failPerson = data.getJSONArray("faceFailurePerson"); - if(failPerson!=null){ - List memberIdList = failPerson.toJavaList(Integer.class); - cmdProcess.tenDeviceService.updateFailurePerson(deviceSn,memberIdList); - } - } - - /** - * - * @param deviceSn - * @param content - * { - * "cmd": "alert" - * "data": { - * "sn":”2342342”, - * "alertType":”数据异常”, - * “alertLevel”:”严重”, - * “alertTime”:”2020-07-28 10:23:22”, - * “errorLog”:”数据同步失败” - * } - * } - */ - private static void subAlert(String deviceSn,String content){ - JSONObject resJson = JSONObject.parseObject(content); - JSONObject data = resJson.getJSONObject("data"); - TenDeviceAlertEntity alert = data.toJavaObject(TenDeviceAlertEntity.class); - cmdProcess.tenDeviceService.addDeviceAlert(alert); - } - - - - - /** - * - * @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 - * - * { - * "cmd":" setParam", - * "data":{ - * } - * } - */ - public static void publishSetParam(String deviceSn, TenDeviceParamVo paramVo){ - String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); - Map data = new HashMap<>(); - sendContent.put("cmd", "setParam"); - sendContent.put("data", paramVo); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } - - - /** - * - * @param sysUserId - * - * { - * "cmd":" upRecord", - * "data":{ - * } - * } - */ - - public static void publishUpRecord(Long sysUserId, TenRecordVo recordVo){ - //获取 发送给 指定id 的app用户的topic - String topic = MqttClientUtil.getWebPublishTopic(sysUserId); - //要发送消息的内容 - JSONObject sendContent = new JSONObject(); +// } +// +// /** +// * { +// * "cmd": "remoteOpenDoor", +// * "data": { +// * "personId": "721041148851781632", +// * } +// * } +// * @param deviceSn +// * @param memberId +// */ +// public static void publishRemoteOpenDoor(String deviceSn,Integer memberId){ +// //获取 发送给 指定id 的app用户的topic +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +//// sendContent.put("cmd", cmd_id + "/response"); +//// sendContent.put("ret", "0"); +//// sendContent.put("msg", "测试消息已经处成功处理"); +//// sendContent.put("code", 0); // Map data = new HashMap<>(); - sendContent.put("cmd", "upRecord"); - sendContent.put("data", recordVo); - //发布消息 - MqttClientUtil.publish_common(topic, sendContent.toString()); - } -} +//// data.put("personId",personId); +// TenDeviceEntity device = cmdProcess.tenDeviceService.findBySn(deviceSn); +//// TenPersonEntity personEntity = cmdProcess.tenDeviceService.getByPersonId(Long.parseLong(personId),device.getCellId()); +// data.put("memberId",memberId); +// data.put("deviceSn",deviceSn); +// sendContent.put("cmd", "remoteOpenDoor"); +// sendContent.put("data", data); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// +// } +// +// /** +// * +// * @param deviceSn +// * @param content +// * { +// * "cmd":"remoteOpenDoor", +// * "data":{ +// * "personId":"721041148851781632", +// * "recordTime":"2020-07-06 14:36:23", +// * "openType":2, //1人脸识别2远程一键开门 +// * "recordFaceStr":"/9j/4AAQSkZJRgABAQAAAQABAAD" +// * } +// * } +// */ +// private static void subscribeRemoteOpenDoor(String deviceSn,String content){ +// JSONObject resJson = JSONObject.parseObject(content); +// JSONObject data = resJson.getJSONObject("data"); +//// String personId = data.getString("personId"); +// Integer memberId = data.getInteger("memberId"); +// String recordTime = data.getString("recordTime"); +// Integer openType = data.getInteger("openType"); +// +// TenDeviceEntity device = cmdProcess.tenDeviceService.findBySn(deviceSn); +// TenPersonEntity person = cmdProcess.tenDeviceService.getByMemberId(memberId,device.getCellId()); +// +// TenRecordEntity record = new TenRecordEntity(); +// record.setDeviceSn(deviceSn); +// record.setPersonId(person.getPersonId()); +// record.setCellId(device.getCellId()); +//// DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); +//// LocalDateTime parse = LocalDateTime.parse(recordTime, dtf); +// record.setRecordTime(new Date()); +// record.setOpenType(openType); +// //添加到redis +//// cmdProcess.redisUtils.set(personId+"-"+deviceSn,openDate,60L); +// cmdProcess.redisUtils.set(person.getPersonId()+"-"+deviceSn,recordTime,10L); +// //添加到记录里 +//// log.info("----------------------------------------收到意见开门记录"); +// cmdProcess.tenDeviceService.upRecord(record); +// } +// +// /** +// * +// * @param deviceSn +// * +// * { +// * "cmd":" personChange", +// * "data":{ +// * } +// * } +// */ +// +// public static void publishPersonChange(String deviceSn){ +// //获取 发送给 指定id 的app用户的topic +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +// Map data = new HashMap<>(); +// sendContent.put("cmd", "personChange"); +// sendContent.put("data", data); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +// +// +// /** +// * +// * @param deviceSn +// * +// * { +// * "cmd":"addPerson", +// * "data":{TenPersonVo +// * } +// * } +// */ +// +// public static void publishAddPerson(String deviceSn, TenPersonVo personVo){ +// //获取 发送给 指定id 的app用户的topic +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +//// Map data = new HashMap<>(); +// sendContent.put("cmd", "addPerson"); +// sendContent.put("data", personVo); +//// if(((JSONObject)sendContent.get("data")).get("liveStart")!=null){ +//// ((JSONObject)sendContent.get("data")).put("liveStart", DateUtils.format(personVo.getLiveStart(),DateUtils.DATE_TIME_PATTERN)); +//// } +//// +//// if(((JSONObject)sendContent.get("data")).get("liveEnd")!=null){ +//// ((JSONObject)sendContent.get("data")).put("liveEnd", DateUtils.format(personVo.getLiveEnd(),DateUtils.DATE_TIME_PATTERN)); +//// } +// +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +// +// +// +// +// /** +// * +// * @param deviceSn +// * +// * { +// * "cmd":" cleanPerson", +// * "data":{ +// * } +// * } +// */ +// public static void publishCleanPerson(String deviceSn){ +// //获取 发送给 指定id 的app用户的topic +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +// Map data = new HashMap<>(); +// sendContent.put("cmd", "cleanPerson"); +// sendContent.put("data", data); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +// +// /** +// * +// * @param deviceSn +// * +// * { +// * "cmd":" updateApp", +// * "data":{ +// * "apkUrl":"https://2222.apk" +// * } +// * } +// */ +// public static void publishUpdateApp(String deviceSn,String apkUrl){ +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +// Map data = new HashMap<>(); +// data.put("apkUrl",apkUrl); +// sendContent.put("cmd", "updateApp"); +// sendContent.put("data", data); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +// +// +// +// /** +// * +// * @param deviceSn +// * @param content +// * { +// * "cmd": "faceCount" +// * "data": { +// * "faceCount":23, +// * "faceFailurePerson": +// * [730721748076462081, 730721748076462082, 730721748076462083] +// * } +// * } +// */ +// private static void subFaceCount(String deviceSn,String content){ +// JSONObject resJson = JSONObject.parseObject(content); +// JSONObject data = resJson.getJSONObject("data"); +// Integer faceCount = data.getInteger("faceCount"); +// if(faceCount!=null){ +// log.info("收到人脸库个数:"+faceCount); +// cmdProcess.tenDeviceService.updateFaceCount(deviceSn,faceCount); +// } +// JSONArray failPerson = data.getJSONArray("faceFailurePerson"); +// if(failPerson!=null){ +// List memberIdList = failPerson.toJavaList(Integer.class); +// cmdProcess.tenDeviceService.updateFailurePerson(deviceSn,memberIdList); +// } +// } +// +// /** +// * +// * @param deviceSn +// * @param content +// * { +// * "cmd": "alert" +// * "data": { +// * "sn":”2342342”, +// * "alertType":”数据异常”, +// * “alertLevel”:”严重”, +// * “alertTime”:”2020-07-28 10:23:22”, +// * “errorLog”:”数据同步失败” +// * } +// * } +// */ +// private static void subAlert(String deviceSn,String content){ +// JSONObject resJson = JSONObject.parseObject(content); +// JSONObject data = resJson.getJSONObject("data"); +// TenDeviceAlertEntity alert = data.toJavaObject(TenDeviceAlertEntity.class); +// cmdProcess.tenDeviceService.addDeviceAlert(alert); +// } +// +// +// +// +// /** +// * +// * @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 +// * +// * { +// * "cmd":" setParam", +// * "data":{ +// * } +// * } +// */ +// public static void publishSetParam(String deviceSn, TenDeviceParamVo paramVo){ +// String topic = MqttClientUtil.getDevicePublishTopic(deviceSn); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +// Map data = new HashMap<>(); +// sendContent.put("cmd", "setParam"); +// sendContent.put("data", paramVo); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +// +// +// /** +// * +// * @param sysUserId +// * +// * { +// * "cmd":" upRecord", +// * "data":{ +// * } +// * } +// */ +// +// public static void publishUpRecord(Long sysUserId, TenRecordVo recordVo){ +// //获取 发送给 指定id 的app用户的topic +// String topic = MqttClientUtil.getWebPublishTopic(sysUserId); +// //要发送消息的内容 +// JSONObject sendContent = new JSONObject(); +//// Map data = new HashMap<>(); +// sendContent.put("cmd", "upRecord"); +// sendContent.put("data", recordVo); +// //发布消息 +// MqttClientUtil.publish_common(topic, sendContent.toString()); +// } +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/EmqHttpApi.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/EmqHttpApi.java index ee1ebe0..4e6dc91 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/EmqHttpApi.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/EmqHttpApi.java @@ -1,162 +1,162 @@ -package net.shapelight.modules.dev.mqtt; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.google.gson.JsonObject; -import lombok.extern.slf4j.Slf4j; -import net.shapelight.common.config.GlobalValue; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -//import org.json.JSONArray; -//import org.json.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Component -public class EmqHttpApi { - private static final String getClients = "/api/v4/clients"; - private static final String getClient = "/api/v4/clients/"; - private static final String getWebClients = "/api/v4/clients/username/web"; - @Autowired - private GlobalValue globalValue; - -// private static String mqttUsername = "11f6a78ee6922"; -// private static String mqttPassword = "MjkzODM4Mzc2NTMyNjIzOTg3NTI5MDMwMzU3NjMwOTc2MDA"; -// private static String mqttApi = "http://192.168.1.111:8081"; - - - /** - * 查看设备在线状态 - * @param devSn - * @return - */ - public boolean getClient(String devSn){ - // 创建HttpClientBuilder - HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); - // 设置BasicAuth - CredentialsProvider provider = new BasicCredentialsProvider(); - // Create the authentication scope - AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); - // Create credential pair,在此处填写用户名和密码 - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(globalValue.getMqttUsername(), - globalValue.getMqttPassword()); - // Inject the credentials - provider.setCredentials(scope, credentials); - // Set the default credentials provider - httpClientBuilder.setDefaultCredentialsProvider(provider); - // HttpClient - CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); - - String result = ""; - HttpGet httpGet = null; - HttpResponse httpResponse = null; - HttpEntity entity = null; - httpGet = new HttpGet(globalValue.getMqttApi()+"/"+getClient+"/"+devSn); - try { - httpResponse = closeableHttpClient.execute(httpGet); - entity = httpResponse.getEntity(); - if( entity != null ){ - result = EntityUtils.toString(entity); - } - } catch (ClientProtocolException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - // 关闭连接 - try { - closeableHttpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - JSONObject json = JSONObject.parseObject(result); - JSONArray devArray = json.getJSONArray("data"); - -// JSONObject json = new JSONObject(result); +//package net.shapelight.modules.dev.mqtt; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONArray; +//import com.alibaba.fastjson.JSONObject; +//import com.google.gson.JsonObject; +//import lombok.extern.slf4j.Slf4j; +//import net.shapelight.common.config.GlobalValue; +//import org.apache.http.HttpEntity; +//import org.apache.http.HttpResponse; +//import org.apache.http.auth.AuthScope; +//import org.apache.http.auth.UsernamePasswordCredentials; +//import org.apache.http.client.ClientProtocolException; +//import org.apache.http.client.CredentialsProvider; +//import org.apache.http.client.methods.HttpGet; +//import org.apache.http.impl.client.BasicCredentialsProvider; +//import org.apache.http.impl.client.CloseableHttpClient; +//import org.apache.http.impl.client.HttpClientBuilder; +//import org.apache.http.util.EntityUtils; +////import org.json.JSONArray; +////import org.json.JSONObject; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Component; +// +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.List; +// +//@Slf4j +//@Component +//public class EmqHttpApi { +// private static final String getClients = "/api/v4/clients"; +// private static final String getClient = "/api/v4/clients/"; +// private static final String getWebClients = "/api/v4/clients/username/web"; +// @Autowired +// private GlobalValue globalValue; +// +//// private static String mqttUsername = "11f6a78ee6922"; +//// private static String mqttPassword = "MjkzODM4Mzc2NTMyNjIzOTg3NTI5MDMwMzU3NjMwOTc2MDA"; +//// private static String mqttApi = "http://192.168.1.111:8081"; +// +// +// /** +// * 查看设备在线状态 +// * @param devSn +// * @return +// */ +// public boolean getClient(String devSn){ +// // 创建HttpClientBuilder +// HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); +// // 设置BasicAuth +// CredentialsProvider provider = new BasicCredentialsProvider(); +// // Create the authentication scope +// AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); +// // Create credential pair,在此处填写用户名和密码 +// UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(globalValue.getMqttUsername(), +// globalValue.getMqttPassword()); +// // Inject the credentials +// provider.setCredentials(scope, credentials); +// // Set the default credentials provider +// httpClientBuilder.setDefaultCredentialsProvider(provider); +// // HttpClient +// CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); +// +// String result = ""; +// HttpGet httpGet = null; +// HttpResponse httpResponse = null; +// HttpEntity entity = null; +// httpGet = new HttpGet(globalValue.getMqttApi()+"/"+getClient+"/"+devSn); +// try { +// httpResponse = closeableHttpClient.execute(httpGet); +// entity = httpResponse.getEntity(); +// if( entity != null ){ +// result = EntityUtils.toString(entity); +// } +// } catch (ClientProtocolException e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// // 关闭连接 +// try { +// closeableHttpClient.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// JSONObject json = JSONObject.parseObject(result); // JSONArray devArray = json.getJSONArray("data"); - //log.info(result); - if(devArray.size() == 0){ - return false; - }else{ - return true; - } - } - - - - public List getWebClients(){ - // 创建HttpClientBuilder - HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); - // 设置BasicAuth - CredentialsProvider provider = new BasicCredentialsProvider(); - // Create the authentication scope - AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); - // Create credential pair,在此处填写用户名和密码 - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(globalValue.getMqttUsername(), - globalValue.getMqttPassword()); - // Inject the credentials - provider.setCredentials(scope, credentials); - // Set the default credentials provider - httpClientBuilder.setDefaultCredentialsProvider(provider); - // HttpClient - CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); - - String result = ""; - HttpGet httpGet = null; - HttpResponse httpResponse = null; - HttpEntity entity = null; - // 192.168.1.111:8081/api/v4/clients/username/web - httpGet = new HttpGet(globalValue.getMqttApi()+"/"+getWebClients); - try { - httpResponse = closeableHttpClient.execute(httpGet); - entity = httpResponse.getEntity(); - if( entity != null ){ - result = EntityUtils.toString(entity); - } - } catch (ClientProtocolException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - // 关闭连接 - try { - closeableHttpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - JSONObject json = JSONObject.parseObject(result); - JSONArray webArray = json.getJSONArray("data"); - List cellIds = new ArrayList<>(); - if(webArray.size()>0){ - for(int i = 0;i getWebClients(){ +// // 创建HttpClientBuilder +// HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); +// // 设置BasicAuth +// CredentialsProvider provider = new BasicCredentialsProvider(); +// // Create the authentication scope +// AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); +// // Create credential pair,在此处填写用户名和密码 +// UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(globalValue.getMqttUsername(), +// globalValue.getMqttPassword()); +// // Inject the credentials +// provider.setCredentials(scope, credentials); +// // Set the default credentials provider +// httpClientBuilder.setDefaultCredentialsProvider(provider); +// // HttpClient +// CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); +// +// String result = ""; +// HttpGet httpGet = null; +// HttpResponse httpResponse = null; +// HttpEntity entity = null; +// // 192.168.1.111:8081/api/v4/clients/username/web +// httpGet = new HttpGet(globalValue.getMqttApi()+"/"+getWebClients); +// try { +// httpResponse = closeableHttpClient.execute(httpGet); +// entity = httpResponse.getEntity(); +// if( entity != null ){ +// result = EntityUtils.toString(entity); +// } +// } catch (ClientProtocolException e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// // 关闭连接 +// try { +// closeableHttpClient.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// JSONObject json = JSONObject.parseObject(result); +// JSONArray webArray = json.getJSONArray("data"); +// List cellIds = new ArrayList<>(); +// if(webArray.size()>0){ +// for(int i = 0;i 0) { - try { -// JSONObject json = new JSONObject(content); - JSONObject json = JSON.parseObject(content); -// String cmd_id = json.optString("cmd"); - String cmd_id = json.getString("cmd"); - CmdProcess.execute(topic,content); - } catch (Throwable e) { - System.out.println("mqtt HandlerThread run"); - e.printStackTrace(); - } - } - } -} +//package net.shapelight.modules.dev.mqtt; +// +////import org.json.JSONObject; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONObject; +// +///** +// * @author +// */ +//public class HandlerThread implements Runnable { +// +// private String topic; +// private String content; +// +// public HandlerThread(String topic, String content) { +// this.topic = topic; +// this.content = content; +// } +// +// /* +// e.g., +//http://172.168.2.10/action/SetAudio +//下发body: +//{ +//"operator": "SetAudio", +//"info": { +//"DeviceID":1300001, +//"AudioType":0, +//"AudioName":"welcome.wav" +//} +//} +// */ +// +// @Override +// public void run() { +// if (this.content.length() > 0) { +// try { +//// JSONObject json = new JSONObject(content); +// JSONObject json = JSON.parseObject(content); +//// String cmd_id = json.optString("cmd"); +// String cmd_id = json.getString("cmd"); +// CmdProcess.execute(topic,content); +// } catch (Throwable e) { +// System.out.println("mqtt HandlerThread run"); +// e.printStackTrace(); +// } +// } +// } +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttClientUtil.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttClientUtil.java index 04e346d..c8963ad 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttClientUtil.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttClientUtil.java @@ -1,234 +1,234 @@ -package net.shapelight.modules.dev.mqtt; - -import lombok.extern.slf4j.Slf4j; -import net.shapelight.common.config.GlobalValue; -import org.eclipse.paho.client.mqttv3.*; -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * - */ -@Slf4j -@Component -public class MqttClientUtil { - private static MqttClientUtil mqttClientUtil; - - @Autowired - private GlobalValue globalValue; - - public static MqttAsyncClient mqttSubscribeClient; - public static MqttAsyncClient mqttPublishClient; - public static String TOPIC_PREFIX_DEVICE = "device"; -// public static String TOPIC_PREFIX_APP = "app"; -public static String TOPIC_PREFIX_WEB = "web"; - private static MqttSubscribeClientCallback mqttClientSubscribeCallback = new MqttSubscribeClientCallback(); - - /** - * 要发布的消息队列 - */ - private static LinkedBlockingQueue queue = new LinkedBlockingQueue(); - public static ExecutorService executorService = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors() + 1); - - /** - * mqtt broker 连接配置,填自己的mqtt地址,及账号密码 - */ -// private static String broker = globalValue.getMqttUrl(); -// private static String username = globalValue.getMqttUsername(); -// private static String password = globalValue.getMqttPassword(); - -// private static String broker = "tcp://192.168.1.111:1883"; -// private static String username = "admin"; -// private static String password = "public"; - - public void setGlobalValue(GlobalValue globalValue) { - this.globalValue = globalValue; - } - - @PostConstruct - public void init(){ - mqttClientUtil = this; - mqttClientUtil.globalValue = this.globalValue; - } - - public static void createClient() { -// System.out.println("mqtt createClient, " + broker); -// String clientId = "mqttserver";// + String.valueOf(System.currentTimeMillis()); -// System.out.println("mqtt sub_clientId="+clientId+",pub_clientId="+clientId+"-publish"); - try { - //subscribe client - mqttSubscribeClient = new MqttAsyncClient(mqttClientUtil.globalValue.getMqttUrl(), "server-sub-" + System.currentTimeMillis(), new MemoryPersistence()); - mqttSubscribeClient.setCallback(mqttClientSubscribeCallback); - - //publish client - mqttPublishClient = new MqttAsyncClient(mqttClientUtil.globalValue.getMqttUrl(), "server-pub-" + System.currentTimeMillis(), new MemoryPersistence()); - mqttPublishClient.setCallback(new MqttCallback() { - @Override - public void connectionLost(Throwable arg0) { - MqttClientUtil.publishReconnect(); - } - @Override - public void deliveryComplete(IMqttDeliveryToken arg0) { - } - @Override - public void messageArrived(String arg0, MqttMessage arg1) throws Exception { - } - }); - subscribeReconnect(); - publishReconnect(); - } catch (MqttException me) { -// log.error("reason " + me.getReasonCode()); -// log.error("msg " + me.getMessage()); -// log.error("loc " + me.getLocalizedMessage()); -// log.error("cause " + me.getCause()); -// System.out.println("reason " + me.getReasonCode()); -// System.out.println("msg " + me.getMessage()); -// System.out.println("loc " + me.getLocalizedMessage()); -// System.out.println("cause " + me.getCause()); -// System.out.println("excep " + me); - me.printStackTrace(); - } - - //启动发布消息的线程, 循环从队列queue 获取要发布的消息 发布。也就是说要发消息,只要将消息写入队列queue - new Thread(new PublishThread()).start(); - } - - /** - * 发布消息 - * @param topic - * @param content - */ - public static void publish_common(String topic, String content) { - String[] array = { topic, content }; - //要发布的消息,入队列。 - //PublishThread 会循环从这个队列获取消息发布. - queue.offer(array); - } - - public static String[] poll() { - return (String[]) queue.poll(); - } - - public static String getDeviceIdByTopic(String topic) { - String[] array = topic.split("/"); - if (array.length >= 2) { - return array[1]; - } - return ""; - } - - public static String getDevicePublishTopic(String deviceId) { - return TOPIC_PREFIX_DEVICE + "/" + deviceId + "/server"; - } - - public static String getWebPublishTopic(Long sysUserId) { - return TOPIC_PREFIX_WEB + "/" + sysUserId + "/server"; - } - -// public static String getAppPublishTopic(String deviceId) { -// return TOPIC_PREFIX_APP + "/" + deviceId + "/server"; +//package net.shapelight.modules.dev.mqtt; +// +//import lombok.extern.slf4j.Slf4j; +//import net.shapelight.common.config.GlobalValue; +//import org.eclipse.paho.client.mqttv3.*; +//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Component; +// +//import javax.annotation.PostConstruct; +//import java.util.concurrent.ExecutorService; +//import java.util.concurrent.Executors; +//import java.util.concurrent.LinkedBlockingQueue; +// +///** +// * +// */ +//@Slf4j +//@Component +//public class MqttClientUtil { +// private static MqttClientUtil mqttClientUtil; +// +// @Autowired +// private GlobalValue globalValue; +// +// public static MqttAsyncClient mqttSubscribeClient; +// public static MqttAsyncClient mqttPublishClient; +// public static String TOPIC_PREFIX_DEVICE = "device"; +//// public static String TOPIC_PREFIX_APP = "app"; +//public static String TOPIC_PREFIX_WEB = "web"; +// private static MqttSubscribeClientCallback mqttClientSubscribeCallback = new MqttSubscribeClientCallback(); +// +// /** +// * 要发布的消息队列 +// */ +// private static LinkedBlockingQueue queue = new LinkedBlockingQueue(); +// public static ExecutorService executorService = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors() + 1); +// +// /** +// * mqtt broker 连接配置,填自己的mqtt地址,及账号密码 +// */ +//// private static String broker = globalValue.getMqttUrl(); +//// private static String username = globalValue.getMqttUsername(); +//// private static String password = globalValue.getMqttPassword(); +// +//// private static String broker = "tcp://192.168.1.111:1883"; +//// private static String username = "admin"; +//// private static String password = "public"; +// +// public void setGlobalValue(GlobalValue globalValue) { +// this.globalValue = globalValue; +// } +// +// @PostConstruct +// public void init(){ +// mqttClientUtil = this; +// mqttClientUtil.globalValue = this.globalValue; +// } +// +// public static void createClient() { +//// System.out.println("mqtt createClient, " + broker); +//// String clientId = "mqttserver";// + String.valueOf(System.currentTimeMillis()); +//// System.out.println("mqtt sub_clientId="+clientId+",pub_clientId="+clientId+"-publish"); +// try { +// //subscribe client +// mqttSubscribeClient = new MqttAsyncClient(mqttClientUtil.globalValue.getMqttUrl(), "server-sub-" + System.currentTimeMillis(), new MemoryPersistence()); +// mqttSubscribeClient.setCallback(mqttClientSubscribeCallback); +// +// //publish client +// mqttPublishClient = new MqttAsyncClient(mqttClientUtil.globalValue.getMqttUrl(), "server-pub-" + System.currentTimeMillis(), new MemoryPersistence()); +// mqttPublishClient.setCallback(new MqttCallback() { +// @Override +// public void connectionLost(Throwable arg0) { +// MqttClientUtil.publishReconnect(); +// } +// @Override +// public void deliveryComplete(IMqttDeliveryToken arg0) { +// } +// @Override +// public void messageArrived(String arg0, MqttMessage arg1) throws Exception { +// } +// }); +// subscribeReconnect(); +// publishReconnect(); +// } catch (MqttException me) { +//// log.error("reason " + me.getReasonCode()); +//// log.error("msg " + me.getMessage()); +//// log.error("loc " + me.getLocalizedMessage()); +//// log.error("cause " + me.getCause()); +//// System.out.println("reason " + me.getReasonCode()); +//// System.out.println("msg " + me.getMessage()); +//// System.out.println("loc " + me.getLocalizedMessage()); +//// System.out.println("cause " + me.getCause()); +//// System.out.println("excep " + me); +// me.printStackTrace(); +// } +// +// //启动发布消息的线程, 循环从队列queue 获取要发布的消息 发布。也就是说要发消息,只要将消息写入队列queue +// new Thread(new PublishThread()).start(); // } - - /** - * 订阅连接 重连 - */ - public static void subscribeReconnect() { - if (mqttSubscribeClient != null) { -// System.out.println("mqtt subscribeReconnect"); - try { - MqttConnectOptions connOpts = new MqttConnectOptions(); - connOpts.setCleanSession(true); - connOpts.setMaxInflight(100000); - connOpts.setUserName(mqttClientUtil.globalValue.getMqttUsername()); - connOpts.setPassword(mqttClientUtil.globalValue.getMqttPassword().toCharArray()); - - mqttSubscribeClient.connect(connOpts, null, new IMqttActionListener() { - @Override - public void onSuccess(IMqttToken asyncActionToken) { - try { - log.info("mqtt 订阅连接 已连接!"); -// System.out.println("mqtt 已连接!"); - MqttClientUtil.mqttSubscribeClient.subscribe(MqttClientUtil.TOPIC_PREFIX_DEVICE + "/+/client", 0); -// MqttClientUtil.mqttSubscribeClient.subscribe(MqttClientUtil.TOPIC_PREFIX_APP + "/+/client", 0); - -// System.out.println("订阅主题:"+MqttClientUtil.TOPIC_PREFIX_DEVICE + "/+/client"); -// System.out.println("订阅主题:"+MqttClientUtil.TOPIC_PREFIX_APP + "/+/client"); - } catch (MqttException me) { -// System.out.println("reason " + me.getReasonCode()); -// System.out.println("msg " + me.getMessage()); -// System.out.println("loc " + me.getLocalizedMessage()); -// System.out.println("cause " + me.getCause()); -// System.out.println("excep " + me); - me.printStackTrace(); - } - } - - @Override - public void onFailure(IMqttToken asyncActionToken, Throwable exception) { -// System.out.println("mqtt 没有连接上:" + exception.getMessage()); - try { - Thread.sleep(60000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - MqttClientUtil.subscribeReconnect(); - } - }); - } catch (MqttException me) { -// System.out.println("reason " + me.getReasonCode()); -// System.out.println("msg " + me.getMessage()); -// System.out.println("loc " + me.getLocalizedMessage()); -// System.out.println("cause " + me.getCause()); -// System.out.println("excep " + me); - me.printStackTrace(); - } - } - } - - /** - * 发布连接 重连 - */ - public static void publishReconnect() { - if (mqttPublishClient != null) { -// System.out.println("mqtt publishReconnect"); - try { - MqttConnectOptions connOpts = new MqttConnectOptions(); - connOpts.setCleanSession(true); - connOpts.setMaxInflight(100000); - connOpts.setUserName(mqttClientUtil.globalValue.getMqttUsername()); - connOpts.setPassword(mqttClientUtil.globalValue.getMqttPassword().toCharArray()); - mqttPublishClient.connect(connOpts, null, new IMqttActionListener() { - @Override - public void onFailure(IMqttToken arg0, Throwable arg1) { -// System.out.println("mqtt publish client connect is failed" + arg1.getMessage()); - try { - Thread.sleep(30000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - MqttClientUtil.publishReconnect(); - } - - @Override - public void onSuccess(IMqttToken arg0) { - log.info("mqtt 发布连接 已连接!"); -// System.out.println("mqtt publish client is connected"); - } - }); - } catch (MqttException me) { -// System.out.println("reason " + me.getReasonCode()); -// System.out.println("msg " + me.getMessage()); -// System.out.println("loc " + me.getLocalizedMessage()); -// System.out.println("cause " + me.getCause()); -// System.out.println("excep " + me); - me.printStackTrace(); - } - } - } -} +// +// /** +// * 发布消息 +// * @param topic +// * @param content +// */ +// public static void publish_common(String topic, String content) { +// String[] array = { topic, content }; +// //要发布的消息,入队列。 +// //PublishThread 会循环从这个队列获取消息发布. +// queue.offer(array); +// } +// +// public static String[] poll() { +// return (String[]) queue.poll(); +// } +// +// public static String getDeviceIdByTopic(String topic) { +// String[] array = topic.split("/"); +// if (array.length >= 2) { +// return array[1]; +// } +// return ""; +// } +// +// public static String getDevicePublishTopic(String deviceId) { +// return TOPIC_PREFIX_DEVICE + "/" + deviceId + "/server"; +// } +// +// public static String getWebPublishTopic(Long sysUserId) { +// return TOPIC_PREFIX_WEB + "/" + sysUserId + "/server"; +// } +// +//// public static String getAppPublishTopic(String deviceId) { +//// return TOPIC_PREFIX_APP + "/" + deviceId + "/server"; +//// } +// +// /** +// * 订阅连接 重连 +// */ +// public static void subscribeReconnect() { +// if (mqttSubscribeClient != null) { +//// System.out.println("mqtt subscribeReconnect"); +// try { +// MqttConnectOptions connOpts = new MqttConnectOptions(); +// connOpts.setCleanSession(true); +// connOpts.setMaxInflight(100000); +// connOpts.setUserName(mqttClientUtil.globalValue.getMqttUsername()); +// connOpts.setPassword(mqttClientUtil.globalValue.getMqttPassword().toCharArray()); +// +// mqttSubscribeClient.connect(connOpts, null, new IMqttActionListener() { +// @Override +// public void onSuccess(IMqttToken asyncActionToken) { +// try { +// log.info("mqtt 订阅连接 已连接!"); +//// System.out.println("mqtt 已连接!"); +// MqttClientUtil.mqttSubscribeClient.subscribe(MqttClientUtil.TOPIC_PREFIX_DEVICE + "/+/client", 0); +//// MqttClientUtil.mqttSubscribeClient.subscribe(MqttClientUtil.TOPIC_PREFIX_APP + "/+/client", 0); +// +//// System.out.println("订阅主题:"+MqttClientUtil.TOPIC_PREFIX_DEVICE + "/+/client"); +//// System.out.println("订阅主题:"+MqttClientUtil.TOPIC_PREFIX_APP + "/+/client"); +// } catch (MqttException me) { +//// System.out.println("reason " + me.getReasonCode()); +//// System.out.println("msg " + me.getMessage()); +//// System.out.println("loc " + me.getLocalizedMessage()); +//// System.out.println("cause " + me.getCause()); +//// System.out.println("excep " + me); +// me.printStackTrace(); +// } +// } +// +// @Override +// public void onFailure(IMqttToken asyncActionToken, Throwable exception) { +//// System.out.println("mqtt 没有连接上:" + exception.getMessage()); +// try { +// Thread.sleep(60000L); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// MqttClientUtil.subscribeReconnect(); +// } +// }); +// } catch (MqttException me) { +//// System.out.println("reason " + me.getReasonCode()); +//// System.out.println("msg " + me.getMessage()); +//// System.out.println("loc " + me.getLocalizedMessage()); +//// System.out.println("cause " + me.getCause()); +//// System.out.println("excep " + me); +// me.printStackTrace(); +// } +// } +// } +// +// /** +// * 发布连接 重连 +// */ +// public static void publishReconnect() { +// if (mqttPublishClient != null) { +//// System.out.println("mqtt publishReconnect"); +// try { +// MqttConnectOptions connOpts = new MqttConnectOptions(); +// connOpts.setCleanSession(true); +// connOpts.setMaxInflight(100000); +// connOpts.setUserName(mqttClientUtil.globalValue.getMqttUsername()); +// connOpts.setPassword(mqttClientUtil.globalValue.getMqttPassword().toCharArray()); +// mqttPublishClient.connect(connOpts, null, new IMqttActionListener() { +// @Override +// public void onFailure(IMqttToken arg0, Throwable arg1) { +//// System.out.println("mqtt publish client connect is failed" + arg1.getMessage()); +// try { +// Thread.sleep(30000L); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// MqttClientUtil.publishReconnect(); +// } +// +// @Override +// public void onSuccess(IMqttToken arg0) { +// log.info("mqtt 发布连接 已连接!"); +//// System.out.println("mqtt publish client is connected"); +// } +// }); +// } catch (MqttException me) { +//// System.out.println("reason " + me.getReasonCode()); +//// System.out.println("msg " + me.getMessage()); +//// System.out.println("loc " + me.getLocalizedMessage()); +//// System.out.println("cause " + me.getCause()); +//// System.out.println("excep " + me); +// me.printStackTrace(); +// } +// } +// } +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttSubscribeClientCallback.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttSubscribeClientCallback.java index a41bfc1..6b5788c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttSubscribeClientCallback.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/MqttSubscribeClientCallback.java @@ -1,37 +1,37 @@ -package net.shapelight.modules.dev.mqtt; - -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; -import org.eclipse.paho.client.mqttv3.MqttCallback; -import org.eclipse.paho.client.mqttv3.MqttMessage; - -/** - * @author - */ -@Slf4j -public class MqttSubscribeClientCallback implements MqttCallback { - - @Override - public void connectionLost(Throwable arg0) { -// System.out.println("mqtt 失去了连接"); - log.info("mqtt 失去连接"); - MqttClientUtil.subscribeReconnect(); - } - - @Override - public void deliveryComplete(IMqttDeliveryToken arg0) { - log.info("mqtt 发送完成"); -// System.out.println("mqtt 发送完成!"); - } - - @Override - public void messageArrived(String topic, MqttMessage message) - throws Exception { - String content = new String(message.getPayload(), "utf-8"); -// System.out.println("收到mqtt消息,topic: " + topic + " ,content: " + content); - log.info("收到mqtt消息,topic: " + topic + " ,content: " + content+"\n"); - if (MqttClientUtil.executorService != null) { - MqttClientUtil.executorService.execute(new HandlerThread(topic, content)); - } - } -} +//package net.shapelight.modules.dev.mqtt; +// +//import lombok.extern.slf4j.Slf4j; +//import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +//import org.eclipse.paho.client.mqttv3.MqttCallback; +//import org.eclipse.paho.client.mqttv3.MqttMessage; +// +///** +// * @author +// */ +//@Slf4j +//public class MqttSubscribeClientCallback implements MqttCallback { +// +// @Override +// public void connectionLost(Throwable arg0) { +//// System.out.println("mqtt 失去了连接"); +// log.info("mqtt 失去连接"); +// MqttClientUtil.subscribeReconnect(); +// } +// +// @Override +// public void deliveryComplete(IMqttDeliveryToken arg0) { +// log.info("mqtt 发送完成"); +//// System.out.println("mqtt 发送完成!"); +// } +// +// @Override +// public void messageArrived(String topic, MqttMessage message) +// throws Exception { +// String content = new String(message.getPayload(), "utf-8"); +//// System.out.println("收到mqtt消息,topic: " + topic + " ,content: " + content); +// log.info("收到mqtt消息,topic: " + topic + " ,content: " + content+"\n"); +// if (MqttClientUtil.executorService != null) { +// MqttClientUtil.executorService.execute(new HandlerThread(topic, content)); +// } +// } +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/PublishThread.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/PublishThread.java index e194157..545f4c5 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/PublishThread.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/PublishThread.java @@ -1,61 +1,61 @@ -package net.shapelight.modules.dev.mqtt; - -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.eclipse.paho.client.mqttv3.MqttPersistenceException; - -import java.io.UnsupportedEncodingException; - -/** - * @author - */ -@Slf4j -public class PublishThread implements Runnable { - @Override - public void run() - { - String[] obj = null; -// System.out.println("mqtt publish thread start"); - while (true) - { - obj = MqttClientUtil.poll(); - if (obj != null) { - String topic = obj[0]; - String content = obj[1]; -// System.out.println("mqtt从队列取出topic:"+topic+",content:"+content); - byte[] array = null; - try { - array = content.getBytes("utf-8"); - } - catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - - MqttMessage message2 = new MqttMessage(array); - message2.setQos(1); - try - { - MqttClientUtil.mqttPublishClient.publish(topic, message2); - log.info("发送mqtt消息,topic: "+topic+" ,content: "+content); -// System.out.println("发送mqtt消息,topic: "+topic+" ,content: "+content); - } catch (MqttPersistenceException e) { - e.printStackTrace(); - } catch (MqttException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - else{ - try { - Thread.sleep(1000L); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - -} +//package net.shapelight.modules.dev.mqtt; +// +//import lombok.extern.slf4j.Slf4j; +//import org.eclipse.paho.client.mqttv3.MqttException; +//import org.eclipse.paho.client.mqttv3.MqttMessage; +//import org.eclipse.paho.client.mqttv3.MqttPersistenceException; +// +//import java.io.UnsupportedEncodingException; +// +///** +// * @author +// */ +//@Slf4j +//public class PublishThread implements Runnable { +// @Override +// public void run() +// { +// String[] obj = null; +//// System.out.println("mqtt publish thread start"); +// while (true) +// { +// obj = MqttClientUtil.poll(); +// if (obj != null) { +// String topic = obj[0]; +// String content = obj[1]; +//// System.out.println("mqtt从队列取出topic:"+topic+",content:"+content); +// byte[] array = null; +// try { +// array = content.getBytes("utf-8"); +// } +// catch (UnsupportedEncodingException e1) { +// e1.printStackTrace(); +// } +// +// MqttMessage message2 = new MqttMessage(array); +// message2.setQos(1); +// try +// { +// MqttClientUtil.mqttPublishClient.publish(topic, message2); +// log.info("发送mqtt消息,topic: "+topic+" ,content: "+content); +//// System.out.println("发送mqtt消息,topic: "+topic+" ,content: "+content); +// } catch (MqttPersistenceException e) { +// e.printStackTrace(); +// } catch (MqttException e) { +// e.printStackTrace(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// else{ +// try { +// Thread.sleep(1000L); +// } +// catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// +//} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/RunMqtt.java b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/RunMqtt.java index 5a77241..cda5d16 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/RunMqtt.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/dev/mqtt/RunMqtt.java @@ -1,21 +1,21 @@ -package net.shapelight.modules.dev.mqtt; - -public class RunMqtt { - public static void main(String[] args){ - //mqtt服务启动 - MqttClientUtil.createClient(); - - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - try { - //释放工作 - //... - - } catch (Throwable e) { - e.printStackTrace(); - } - } - }); - } -} +//package net.shapelight.modules.dev.mqtt; +// +//public class RunMqtt { +// public static void main(String[] args){ +// //mqtt服务启动 +// MqttClientUtil.createClient(); +// +// Runtime.getRuntime().addShutdownHook(new Thread() { +// @Override +// public void run() { +// try { +// //释放工作 +// //... +// +// } catch (Throwable e) { +// e.printStackTrace(); +// } +// } +// }); +// } +//} 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 4630cbc..bc3030f 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 @@ -1,23 +1,23 @@ -package net.shapelight.modules.dev.mqtt; - -public enum TopicCmdEnum { - remoteOpenDoor("remoteOpenDoor"), - personChange("personChange"), - cleanPerson("cleanPerson"), - faceCount("faceCount"), - alert("alert"), - upRecord("upRecord"), - addPerson("addPerson"), - getParam("getParam"); - - - private String cmd; - - TopicCmdEnum(String cmd){ - this.cmd = cmd; - } - - public String getCmd() { - return cmd; - } -} +//package net.shapelight.modules.dev.mqtt; +// +//public enum TopicCmdEnum { +// remoteOpenDoor("remoteOpenDoor"), +// personChange("personChange"), +// cleanPerson("cleanPerson"), +// faceCount("faceCount"), +// alert("alert"), +// upRecord("upRecord"), +// addPerson("addPerson"), +// getParam("getParam"); +// +// +// private String cmd; +// +// TopicCmdEnum(String cmd){ +// this.cmd = cmd; +// } +// +// public String getCmd() { +// return 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 d13dd0b..045ebc6 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 @@ -3,6 +3,7 @@ package net.shapelight.modules.excel.listener; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.fastjson.JSONObject; +import io.minio.PutObjectOptions; import lombok.Getter; import net.shapelight.common.utils.UUIDUtil; import net.shapelight.commons.engine.sdk.PicSDK; @@ -16,7 +17,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.InputStream; import java.util.*; import java.util.regex.Pattern; @@ -155,6 +158,9 @@ public class PersonExcelListener extends AnalysisEventListener { }else{ personModel.setOrgImage(image); } + + + //检测图片人脸 //--------------------------------------------------------------------- String tempPath = ""; @@ -165,14 +171,37 @@ public class PersonExcelListener extends AnalysisEventListener { } String tempFaceFileName = UUIDUtil.uuid() + ".jpg"; String tempFaceFilePath = tempPath + tempFaceFileName; - int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); - if (res != 0) { - personModel.setMessage("图片不合格,未检测到人脸"); - personModel.setStatus(0); - list.add(personModel); - return; + + + + String osName = System.getProperty("os.name");//获取指定键(即os.name)的系统属性,如:Windows 7。 + if (!Pattern.matches("Windows.*", osName)) { + int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); + if (res != 0) { + personModel.setMessage("图片不合格,未检测到人脸"); + personModel.setStatus(0); + list.add(personModel); + return; + } } + + +// int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); +// if (res != 0) { +// personModel.setMessage("图片不合格,未检测到人脸"); +// personModel.setStatus(0); +// list.add(personModel); +// return; +// } //--------------------------------------------------------------------- + +//门禁卡号 + String doorCard = personModel.getDoorCard(); + if(doorCard!=null&&doorCard.length()>0){ + personModel.setDoorCard(doorCard); + } + + personModel.setStatus(1); list.add(personModel); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/excel/model/PersonModel.java b/shapelight-admin/src/main/java/net/shapelight/modules/excel/model/PersonModel.java index 4a00010..8a7d3b1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/excel/model/PersonModel.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/excel/model/PersonModel.java @@ -35,6 +35,9 @@ public class PersonModel extends BaseRowModel implements Serializable { @ExcelProperty(value = "房间名称", index = 7) private String roomName; + @ExcelProperty(value = "门禁卡号", index = 8) + private String doorCard; + /** * 原始头像 */ diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonProcessTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonProcessTask.java new file mode 100644 index 0000000..93fb643 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonProcessTask.java @@ -0,0 +1,60 @@ + + +package net.shapelight.modules.job.task; + +import lombok.Data; +import net.shapelight.common.utils.Constant; +import net.shapelight.common.utils.DateUtils; +import net.shapelight.modules.nettyapi.service.ServerApiService; +import net.shapelight.modules.sys.entity.SysDbBakEntity; +import net.shapelight.modules.sys.service.SysDbBakService; +import net.shapelight.modules.ten.entity.TenPersonEntity; +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; +import net.shapelight.modules.ten.service.TenPersonService; +import net.shapelight.modules.ten.service.TenPersonSyncService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.*; +import java.util.Date; +import java.util.List; + +/** + * + */ +@Component("personProcessTask") +@Data +public class PersonProcessTask implements ITask { + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private TenPersonService tenPersonService; + @Autowired + private TenPersonSyncService tenPersonSyncService; + @Autowired + private ServerApiService serverApiService; + + @Override + public void run(String params) { + logger.debug("personProcessTask定时任务正在执行,参数为:{}", params); + //1. 遍历人员表,找出所有过期的访客并设置为过期不可用 + List guestList = tenPersonService.getAllExpireGuest(); + for (TenPersonEntity guest : guestList) { + guest.setStatus(Constant.PESON_SUATUS_GUEST_DATE_OUT); + //修改人员表 + tenPersonService.updateStatusById(guest); + //修改同步表 + List syncEntityList = tenPersonSyncService.findByPersonId(guest.getPersonId(),guest.getTenantId()); + for(TenPersonSyncEntity syncEntity: syncEntityList){ + syncEntity.setState(Constant.PERSON_SYNC_DELETE); + tenPersonSyncService.updateById(syncEntity); + } + } + //断开说有设备 + serverApiService.closeAll(); + logger.debug("personProcessTask定时任务执行完毕"); + } +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/MyMessageDecoder.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/MyMessageDecoder.java index f0f5557..87176db 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/MyMessageDecoder.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/config/MyMessageDecoder.java @@ -38,7 +38,7 @@ public class MyMessageDecoder extends ByteToMessageDecoder { if((c0&0xFF) != 0x58){ in.resetReaderIndex(); in.skipBytes(1); -// log.debug(String.format("c0:is 0x%x",c0)); + log.debug(String.format("c0:is 0x%x",c0)); return; } @@ -46,7 +46,7 @@ public class MyMessageDecoder extends ByteToMessageDecoder { if((c1&0xFF) != 0x49){ in.resetReaderIndex(); in.skipBytes(1); -// log.debug(String.format("c1:is 0x%x",c1)); + log.debug(String.format("c1:is 0x%x",c1)); return; } @@ -54,7 +54,7 @@ public class MyMessageDecoder extends ByteToMessageDecoder { if((c2&0xFF) != 0x54){ in.resetReaderIndex(); in.skipBytes(1); -// log.debug(String.format("c2:is 0x%x",c2)); + log.debug(String.format("c2:is 0x%x",c2)); return; } @@ -62,7 +62,7 @@ public class MyMessageDecoder extends ByteToMessageDecoder { if((c3&0xFF) != 0x55){ in.resetReaderIndex(); in.skipBytes(1); -// log.debug(String.format("c3:is 0x%x",c3)); + log.debug(String.format("c3:is 0x%x",c3)); return; } @@ -71,6 +71,9 @@ public class MyMessageDecoder extends ByteToMessageDecoder { final byte cmd = in.readByte(); final int dataLength = in.readInt(); + + log.debug(String.format("verson:is 0x%x,datatype:0x%x,cmd:0x%x,lenth:%d",version,dataType,cmd,dataLength)); + if(in.readableBytes() operationVoList); + + void cleanDataRes(Channel channel, String content); + + int close(String sn); + + void closeAll(); + } 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 6a6354d..d552d7d 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 @@ -8,16 +8,16 @@ import io.netty.channel.Channel; import lombok.Data; import lombok.extern.slf4j.Slf4j; import net.shapelight.common.config.GlobalValue; -import net.shapelight.common.utils.DateUtils; -import net.shapelight.common.utils.ImageUtils; -import net.shapelight.common.utils.TreeUtils; -import net.shapelight.common.utils.UUIDUtil; +import net.shapelight.common.utils.*; import net.shapelight.modules.nettyapi.config.ClientMap; import net.shapelight.modules.nettyapi.config.CmdConstant; import net.shapelight.modules.nettyapi.config.MyMessage; 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.service.SysDeviceAppService; +import net.shapelight.modules.sys.service.SysDeviceService; import net.shapelight.modules.ten.entity.*; import net.shapelight.modules.ten.service.*; import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; @@ -53,6 +53,12 @@ public class DeviceApiServiceImpl implements DeviceApiService { private TenDeviceAlertService tenDeviceAlertService; @Autowired private TenPersonExtractService tenPersonExtractService; + @Autowired + private TenPersonSyncService tenPersonSyncService; + @Autowired + private SysDeviceService sysDeviceService; + @Autowired + private TenDoorCardService tenDoorCardService; /* @@ -99,6 +105,7 @@ public class DeviceApiServiceImpl implements DeviceApiService { String appKey = loginJson.getString("app_key"); String appSecret = loginJson.getString("app_secret"); String devId = loginJson.getString("dev_id"); + String version = loginJson.getString("version_name"); if(appKey==null || appKey.length()==0 || appSecret == null || appSecret.length()==0 || !gAppKey.equals(appKey) || !gAppSecret.equals(appSecret)){ @@ -121,8 +128,26 @@ public class DeviceApiServiceImpl implements DeviceApiService { } - //1.判断sn是否存在 设备不存在1002 + SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper() + .eq("sn",devId)); + if(sysDeviceEntity == null){ + Result res = Result.error(201, "Device Is Not Bind"); + String resContent = JSONObject.toJSONString(res); + MyMessage message = new MyMessage(CmdConstant.CMD_LOGIN,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } + if(sysDeviceEntity.getState() == 0){ + Result res = Result.error(202, "Device Is Stop"); + String resContent = JSONObject.toJSONString(res); + MyMessage message = new MyMessage(CmdConstant.CMD_LOGIN,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } + + + //1.判断sn是否存在 设备不存在1002 TenDeviceEntity deviceEntity = tenDeviceService.findBySn(devId); if(deviceEntity == null){ Result res = Result.error(201, "Device Is Not Bind"); @@ -142,19 +167,26 @@ public class DeviceApiServiceImpl implements DeviceApiService { dataMap.put("building_name",cellEntity.getName()); Map configMap = new HashMap<>(); - configMap.put("work_mode",0); - configMap.put("recognize_interval",3); + configMap.put("work_mode",deviceEntity.getHealthCodeFlag()); + configMap.put("recognize_interval",deviceEntity.getRecSpace()); configMap.put("relay_suck_time",5); - configMap.put("support_liveness",true); - configMap.put("liveness_score",60); - configMap.put("recognize_score",65); - configMap.put("recognize_distance",2); - configMap.put("alert_temp_threshold",37.3); + if(deviceEntity.getLivenessFlag().intValue() == 1){ + configMap.put("support_liveness",true); + }else{ + configMap.put("support_liveness",false); + } + configMap.put("liveness_score",deviceEntity.getRgbLiveThd().intValue()); + configMap.put("recognize_score",deviceEntity.getRecThd().intValue()); + configMap.put("recognize_distance",1); + configMap.put("alert_temp_threshold",deviceEntity.getTemperatureAlert()); configMap.put("upload_face_pic",true); - configMap.put("upload_pic_mode",0); - configMap.put("upload_http_url","http://upload.face.com/face/pic/upload"); - configMap.put("support_stranger",false); - + configMap.put("upload_pic_mode",deviceEntity.getUploadImageFlag()); + configMap.put("upload_http_url",""); + if(deviceEntity.getStrangerFlag().intValue() == 1){ + configMap.put("support_stranger",true); + }else{ + configMap.put("support_stranger",false); + } dataMap.put("config",configMap); res.put("data",dataMap); @@ -164,7 +196,9 @@ public class DeviceApiServiceImpl implements DeviceApiService { clientMap.online(channel, devId); - tenDeviceService.updateById(deviceEntity); + + deviceEntity.setApkVersion(version); + tenDeviceService.evictupdateById(deviceEntity); log.debug("设备:" + devId + " 登录"); return; @@ -187,9 +221,24 @@ public class DeviceApiServiceImpl implements DeviceApiService { return; } - TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); + 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_GETALL,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } - List all = tenPersonService.findAllPersonIdUpdateAll(cellEntity.getCellId(),null,null); +// TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); + +// List all = tenPersonService.findAllPersonIdUpdateAll(cellEntity.getCellId(),null,null); + + List all = tenPersonSyncService.getDeviceAllPersonIdUpdateTime(deviceEntity.getDeviceId(),deviceEntity.getTenantId()); + + //删除状态为删除的人员 + tenPersonSyncService.removeAllDeletePersons(deviceEntity.getDeviceId(),deviceEntity.getTenantId()); Result res = new Result(); res.put("data",all); @@ -217,24 +266,71 @@ public class DeviceApiServiceImpl implements DeviceApiService { log.error("设备已删除"); 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()); TenUserVo puser = new TenUserVo(); + if (p==null) { + return; + }else{ + TenDoorCardEntity doorCardEntity = tenDoorCardService.getOne( + new QueryWrapper() + .eq("person_id",p.getPersonId()) + ); + if(doorCardEntity!=null){ + puser.setCard_id(doorCardEntity.getDoorCard()); + }else{ + TenDoorCardEntity doorCardRoom = tenDoorCardService.getOne( + new QueryWrapper() + .eq("room_id",p.getRoomId()) + ); + if(doorCardEntity!=null){ + puser.setCard_id(doorCardRoom.getDoorCard()); + } + + } + } + puser.setUid(p.getPersonId()); puser.setUser_name(p.getName()); puser.setUser_type(0); - puser.setActive_start_time(0); - puser.setActive_end_time(0); + if(p.getLiveStart()!=null){ + puser.setActive_start_time((int)(p.getLiveStart().getTime()/1000)); + } + if(p.getLiveEnd()!=null){ + puser.setActive_end_time((int)(p.getLiveEnd().getTime()/1000)); + } + +// puser.setActive_start_time(0); +// puser.setActive_end_time(0); + puser.setLast_update_stamp(p.getLastUpdateTime().getTime()); - puser.setCard_id(""); puser.setFace_pic_download_url(globalValue.getMinioEndpoint()+"/" + globalValue.getMinioBucketName()+"/" + p.getOrgImage()); puser.setFace_pic_base64(""); +// TenPersonSyncEntity syncEntity = tenPersonSyncService.getOne(new QueryWrapper() +// .eq("device_id",deviceEntity.getDeviceId()) +// .eq("person_id",p.getPersonId())); + + TenPersonSyncEntity syncEntity = tenPersonSyncService.findByDeviceIdAndPersonId(deviceEntity.getDeviceId(), + p.getPersonId(),deviceEntity.getTenantId()); + syncEntity.setState(Constant.PERSON_SYNC_OK); + + tenPersonSyncService.updateById(syncEntity); + Result res = new Result(); res.put("data",puser); @@ -272,9 +368,19 @@ public class DeviceApiServiceImpl implements DeviceApiService { return; } + SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper() + .eq("sn",sn)); + if(sysDeviceEntity.getState() == 0){ + Result res = Result.error(202, "Device Is Stop"); + String resContent = JSONObject.toJSONString(res); + MyMessage message = new MyMessage(CmdConstant.CMD_HART,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } + //保存人脸个数 deviceEntity.setFaceCount(faceCount); - tenDeviceService.updateById(deviceEntity); + tenDeviceService.evictupdateById(deviceEntity); TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); @@ -349,6 +455,18 @@ public class DeviceApiServiceImpl implements DeviceApiService { log.error("设备已删除"); return; } + + SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper() + .eq("sn",sn)); + if(sysDeviceEntity.getState() == 0){ + Result res = Result.error(202, "Device Is Stop"); + String resContent = JSONObject.toJSONString(res); + MyMessage message = new MyMessage(CmdConstant.CMD_UPRECORD,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } + + TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); TenRecordEntity record = new TenRecordEntity(); record.setDeviceSn(sn); @@ -394,6 +512,17 @@ public class DeviceApiServiceImpl implements DeviceApiService { log.error("设备已删除"); return; } + + SysDeviceEntity sysDeviceEntity = sysDeviceService.getOne(new QueryWrapper() + .eq("sn",sn)); + if(sysDeviceEntity.getState() == 0){ + Result res = Result.error(202, "Device Is Stop"); + String resContent = JSONObject.toJSONString(res); + MyMessage message = new MyMessage(CmdConstant.CMD_EXTRACT,resContent.length(),resContent.getBytes()); + channel.writeAndFlush(message); + return; + } + TenCellEntity cellEntity = tenCellService.getById(deviceEntity.getCellId()); 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 a40088a..16edae0 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 @@ -9,6 +9,7 @@ import net.shapelight.modules.nettyapi.config.CmdConstant; import net.shapelight.modules.nettyapi.config.MyMessage; import net.shapelight.modules.nettyapi.service.DeviceApiService; import net.shapelight.modules.nettyapi.service.MessageService; +import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.nettyapi.utils.Result; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; @@ -26,6 +27,8 @@ public class MessageServiceImpl implements MessageService { private ClientMap clientMap; @Autowired private CacheManager cacheManager; + @Autowired + private ServerApiService serverApiService; @Override public void receive(ChannelHandlerContext ctx, MyMessage msg) { @@ -133,6 +136,7 @@ public class MessageServiceImpl implements MessageService { case CmdConstant.CMD_CLEANDATA: { log.debug("清除数据:" + msg.cmd); + serverApiService.cleanDataRes(channel,content); break; } @@ -142,7 +146,7 @@ public class MessageServiceImpl implements MessageService { } default: - log.debug("unknown cmd type:" + msg.cmd); + log.debug("未知类型:" + msg.cmd); break; } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/ServerApiServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/ServerApiServiceImpl.java index 956cb5e..e3e6ecf 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/ServerApiServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/nettyapi/service/impl/ServerApiServiceImpl.java @@ -1,23 +1,35 @@ package net.shapelight.modules.nettyapi.service.impl; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.netty.channel.Channel; import lombok.extern.slf4j.Slf4j; import net.shapelight.modules.nettyapi.config.ClientMap; import net.shapelight.modules.nettyapi.config.CmdConstant; import net.shapelight.modules.nettyapi.config.MyMessage; 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.service.SysDeviceService; import net.shapelight.modules.ten.entity.TenDeviceEntity; +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; import net.shapelight.modules.ten.service.TenDeviceService; +import net.shapelight.modules.ten.service.TenPersonService; +import net.shapelight.modules.ten.service.TenPersonSyncService; import net.shapelight.modules.vo.TenAppVerison; import net.shapelight.modules.vo.TenDeviceConfig; +import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; +import net.shapelight.modules.vo.TenPersonOperationVo; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; @Slf4j @@ -27,6 +39,12 @@ public class ServerApiServiceImpl implements ServerApiService { ClientMap clientMap; @Autowired private TenDeviceService tenDeviceService; + @Autowired + private TenPersonService tenPersonService; + @Autowired + private TenPersonSyncService tenPersonSyncService; + @Autowired + private SysDeviceService sysDeviceService; @Override @@ -38,11 +56,36 @@ public class ServerApiServiceImpl implements ServerApiService { // Map data = new HashMap<>(); // data.put("data",data); String content = JSONObject.toJSONString(dc); - MyMessage message = new MyMessage(CmdConstant.CMD_CONFIG,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_CONFIG,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } + + @Override + public int personOperation(String sn,List operationVoList) { + Channel channel = clientMap.getChannelByUserId(sn); + if(channel == null){ + return -1; + } + String content = JSONObject.toJSONString(operationVoList); + MyMessage message = new MyMessage(CmdConstant.CMD_CHANGE,content.getBytes().length,content.getBytes()); + channel.writeAndFlush(message); + return 0; + } + +// @Override +// public int personOperation(String sn) { +// Channel channel = clientMap.getChannelByUserId(sn); +// if(channel == null){ +// return -1; +// } +// String content = JSONObject.toJSONString(operationVoList); +// MyMessage message = new MyMessage(CmdConstant.CMD_CHANGE,content.length(),content.getBytes()); +// channel.writeAndFlush(message); +// return 0; +// } + @Override public int openDoor(String sn,Long personId) { Channel channel = clientMap.getChannelByUserId(sn); @@ -53,7 +96,7 @@ public class ServerApiServiceImpl implements ServerApiService { data.put("dev_id",sn); data.put("uid",personId); String content = JSONObject.toJSONString(data); - MyMessage message = new MyMessage(CmdConstant.CMD_OPENDOOR,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_OPENDOOR,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } @@ -68,7 +111,7 @@ public class ServerApiServiceImpl implements ServerApiService { Map data = new HashMap<>(); data.put("dev_id",sn); String content = JSONObject.toJSONString(data); - MyMessage message = new MyMessage(CmdConstant.CMD_RESTART,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_RESTART,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } @@ -82,13 +125,13 @@ public class ServerApiServiceImpl implements ServerApiService { Map data = new HashMap<>(); data.put("dev_id",sn); String content = JSONObject.toJSONString(data); - MyMessage message = new MyMessage(CmdConstant.CMD_CLEANDATA,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_CLEANDATA,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } @Override - public int enableDevice(String sn) { + public int stopDevice(String sn) { Channel channel = clientMap.getChannelByUserId(sn); if(channel == null){ return -1; @@ -96,7 +139,7 @@ public class ServerApiServiceImpl implements ServerApiService { Map data = new HashMap<>(); data.put("dev_id",sn); String content = JSONObject.toJSONString(data); - MyMessage message = new MyMessage(CmdConstant.CMD_ENABLE,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_ENABLE,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } @@ -110,11 +153,58 @@ public class ServerApiServiceImpl implements ServerApiService { // Map data = new HashMap<>(); // data.put("data",data); String content = JSONObject.toJSONString(appVerison); - MyMessage message = new MyMessage(CmdConstant.CMD_APPUPDATE,content.length(),content.getBytes()); + MyMessage message = new MyMessage(CmdConstant.CMD_APPUPDATE,content.getBytes().length,content.getBytes()); channel.writeAndFlush(message); return 0; } + @Override + @Transactional(rollbackFor = Exception.class) + public void cleanDataRes(Channel channel, String content) { + String sn = clientMap.getUserIdByChannel(channel); + TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); + //1.删除同步表中数据 +// tenPersonSyncService.remove(new QueryWrapper() +// .eq("device_id",deviceEntity.getDeviceId())); + tenPersonSyncService.removeByDeviceId(deviceEntity.getDeviceId(),deviceEntity.getTenantId()); + //2.在同步表中插入所有信息 + List list = tenPersonService.findAllPersonIdUpdateAll(deviceEntity.getCellId(), + deviceEntity.getBuildId(), + deviceEntity.getRoomId()); +// List sList = new ArrayList<>(); + for(TenPersonIdUpdateAllVo vo:list){ + TenPersonSyncEntity entity = new TenPersonSyncEntity(); + entity.setDeviceId(deviceEntity.getDeviceId()); + entity.setDeviceSn(deviceEntity.getSn()); + entity.setLastUpdateTime(vo.getLast_update_stamp()); + entity.setPersonId(vo.getUid()); + entity.setState(0); + entity.setTenantId(deviceEntity.getTenantId()); + tenPersonSyncService.insert(entity); + } +// tenPersonSyncService.saveBatch(sList); + } + + + @Override + public int close(String sn) { + Channel channel = clientMap.getChannelByUserId(sn); + if(channel == null){ + return -1; + } + channel.close(); + return 0; + } + + @Override + public void closeAll() { + ConcurrentHashMap list = clientMap.getChannelMap(); + for(Map.Entry entry:list.entrySet()){ + Channel channel = entry.getValue(); + channel.close(); + log.debug("断开设备:"+entry.getKey()); + } + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceAppController.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceAppController.java index fd6736a..0c7419e 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceAppController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceAppController.java @@ -121,8 +121,9 @@ public class SysDeviceAppController { InputStream inputStream = null; try { String userFileUrl = globalValue.getApkDir() + "/"; - String extension = FilenameUtils.getExtension(file.getOriginalFilename()); //后缀名 - String fileName = userFileUrl + UUIDUtil.uuid() + "." + extension; +// String extension = FilenameUtils.getExtension(file.getOriginalFilename()); //后缀名 +// String fileName = userFileUrl + UUIDUtil.uuid() + "." + extension; + String fileName = userFileUrl + file.getOriginalFilename(); inputStream = file.getInputStream(); PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); putObjectOptions.setContentType(file.getContentType()); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java index 50771e3..fcd8e75 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/controller/SysDeviceController.java @@ -8,6 +8,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.entity.SysDeviceEntity; import net.shapelight.modules.sys.service.SysDeviceService; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -30,6 +31,9 @@ public class SysDeviceController { @Autowired private SysDeviceService sysDeviceService; + @Autowired + private ServerApiService serverApiService; + /** * 列表 */ @@ -85,6 +89,29 @@ public class SysDeviceController { return R.ok(); } + /** + * 停用 + */ + @PostMapping("/stop") + @RequiresPermissions("sys:device") + @ApiOperation(value = "修改") + public R stop(@RequestBody SysDeviceEntity sysDevice){ + if(sysDevice.getState().intValue() == 0){ + int flag = serverApiService.stopDevice(sysDevice.getSn()); + if(flag == -1){ + return R.error("设备不在线"); + }else { + sysDeviceService.updateById(sysDevice); + } + }else{ + sysDeviceService.updateById(sysDevice); + } + return R.ok(); + } + + + + /** * 删除 */ @@ -92,7 +119,7 @@ public class SysDeviceController { @RequiresPermissions("sys:device") @ApiOperation(value = "删除") public R delete(@RequestBody Long[] deviceIds){ - + sysDeviceService.removeByIds(Arrays.asList(deviceIds)); return R.ok(); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceAppEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceAppEntity.java index 2c70f53..d717b1c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceAppEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceAppEntity.java @@ -61,4 +61,9 @@ public class SysDeviceAppEntity implements Serializable { @ApiModelProperty("0未删除1删除") private Integer deleteFlag; + @TableField(exist=false) + private String deviceSn; + + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceEntity.java index e00b4ce..34ee78b 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/entity/SysDeviceEntity.java @@ -48,6 +48,9 @@ public class SysDeviceEntity implements Serializable { @ApiModelProperty("0未删除1删除") private Integer deleteFlag; + @ApiModelProperty("1正常0停用") + private Integer state; + /** diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/sys/service/impl/SysDeviceServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/sys/service/impl/SysDeviceServiceImpl.java index 5f2768f..9ea4391 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/sys/service/impl/SysDeviceServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/sys/service/impl/SysDeviceServiceImpl.java @@ -2,7 +2,8 @@ package net.shapelight.modules.sys.service.impl; import net.shapelight.common.utils.RedisUtils; import net.shapelight.common.utils.StringUtils; -import net.shapelight.modules.dev.mqtt.EmqHttpApi; +//import net.shapelight.modules.dev.mqtt.EmqHttpApi; +import net.shapelight.modules.nettyapi.service.DeviceApiService; import net.shapelight.modules.sys.dao.SysDeviceDao; import net.shapelight.modules.sys.entity.SysDeviceEntity; import net.shapelight.modules.sys.entity.SysDeviceTypeEntity; @@ -32,10 +33,12 @@ public class SysDeviceServiceImpl extends ServiceImpl params) { @@ -56,7 +59,8 @@ public class SysDeviceServiceImpl extends ServiceImpl i appUser.setCreateTime(new Date()); //app用户保存系统用户id号 appUser.setSysUserId(user.getUserId()); + appUser.setTenantId(user.getTenantId()); appUserService.save(appUser); //保存权限 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 cd2dbe3..5398e51 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 @@ -8,8 +8,8 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import net.shapelight.common.utils.Constant; -import net.shapelight.modules.dev.mqtt.CmdProcess; -import net.shapelight.modules.dev.mqtt.EmqHttpApi; +//import net.shapelight.modules.dev.mqtt.CmdProcess; +//import net.shapelight.modules.dev.mqtt.EmqHttpApi; import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.sys.entity.SysDeviceAppEntity; @@ -59,8 +59,8 @@ public class TenDeviceController extends AbstractController { private SysDeviceService sysDeviceService; @Autowired private SysDeviceAppService sysDeviceAppService; - @Autowired - private EmqHttpApi emqHttpApi; +// @Autowired +// private EmqHttpApi emqHttpApi; @Autowired private ServerApiService serverApiService; @@ -158,19 +158,87 @@ public class TenDeviceController extends AbstractController { }) public R cleanPerson(@RequestBody Map deviceSn){ String sn = (String)deviceSn.get("deviceSn"); - CmdProcess.publishCleanPerson(sn); +// CmdProcess.publishCleanPerson(sn); //清除数据 int r = serverApiService.cleanData(sn); //配置参数 - TenDeviceConfig dc = new TenDeviceConfig(); - int s = serverApiService.devConfig(sn,dc); - for(int i =0;i<1000;i++){ - - } +// TenDeviceConfig dc = new TenDeviceConfig(); +// int s = serverApiService.devConfig(sn,dc); +// for(int i =0;i<1000;i++){ +// +// } //升级app - TenAppVerison v = new TenAppVerison(); - int a = serverApiService.appUpdate(sn,v); +// TenAppVerison v = new TenAppVerison(); +// int a = serverApiService.appUpdate(sn,v); + + + if(r == -1){ + return R.error("设备离线"); + } + + //重新配置同步表 + + + + + + + return R.ok(); + } + + /** + * 远程重启 + */ + @PostMapping("/restart") + @ApiOperation(value = "远程重启") + @ApiImplicitParams({ + @ApiImplicitParam(name="deviceSn",value = "设备Sn",paramType = "query",dataType = "String",required = true), + }) + public R restart(@RequestBody Map deviceSn){ + String sn = (String)deviceSn.get("deviceSn"); +// CmdProcess.publishCleanPerson(sn); + //清除数据 + int r = serverApiService.restart(sn); + if(r == -1){ + return R.error("设备离线"); + } + return R.ok(); + } + + + /** + * 远程开门 + */ + @PostMapping("/opendoor") + @ApiOperation(value = "远程开门") + @ApiImplicitParams({ + @ApiImplicitParam(name="deviceSn",value = "设备Sn",paramType = "query",dataType = "String",required = true), + @ApiImplicitParam(name="personId",value = "人员id",paramType = "query",dataType = "String",required = true), + }) + public R opendoor(@RequestBody Map params){ + String sn = (String)params.get("deviceSn"); + Long personIdStr = Long.parseLong((String)params.get("personId")); + //远程开门 + int r = serverApiService.openDoor(sn,personIdStr); + if(r == -1){ + return R.error("设备离线"); + } + return R.ok(); + } + + /** + * 断开 + */ + @PostMapping("/close") + @ApiOperation(value = "断开设备") + @ApiImplicitParams({ + @ApiImplicitParam(name="deviceSn",value = "设备Sn",paramType = "query",dataType = "String",required = true), + }) + public R close(@RequestBody Map params){ + String sn = (String)params.get("deviceSn"); + //远程开门 + int r = serverApiService.close(sn); if(r == -1){ return R.error("设备离线"); } @@ -179,49 +247,113 @@ public class TenDeviceController extends AbstractController { - /** - * 获取设备参数 - */ - @GetMapping("/getParam/{sn}") - @ApiOperation(value = "获取设备参数") - public R getParam(@PathVariable("sn") String sn){ - boolean onlineFlag = emqHttpApi.getClient(sn); - if(onlineFlag){ +// /** +// * 获取设备参数 +// */ +// @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("获取失败,请重试"); +// } +// } - }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("获取失败,请重试"); - } - } /** - * 设置设备参数 + * 设置设备参数 TCP 设备 + private Integer work_mode; //0表示门禁模式,1表示门禁+测温模式,默认为0 health_code_flag + private Integer recognize_interval; //连续两次人脸识别时间间隔,默认3s rec_space + private Integer relay_suck_time; //继电器吸合开锁持续时间,默认5s + private Boolean support_liveness; //是否支持活体检测,默认true liveness_flag + private Integer liveness_score; //活体检测超过此值则判断为活体,默认60 rgb_live_thd + private Integer recognize_score; //人脸比对分值超过此值则判断为同一个人,默认65 rec_thd + private Integer recognize_distance; //默认1m + private Float alert_temp_threshold; //人脸温度超过此值则报警,默认5s temperature_alert + private Boolean upload_face_pic; //默认true upload_image_flag + private Integer upload_pic_mode; //枚举值0表示人脸图base64编码,和人脸识别记录同时上传, 1表示人脸图通过http协议post上传 + private String upload_http_url; //人脸图通过http上传的url地址 + private Boolean support_stranger; //是否支持陌生人抓拍 默认false stranger_flag + + public TenDeviceConfig(){ + this.work_mode = 0; + this.recognize_interval = 3; + this.relay_suck_time = 5; + this.support_liveness = true; + this.liveness_score = 60; + this.recognize_score = 65; + this.recognize_distance = 1; + this.alert_temp_threshold = 37.3f; + this.upload_face_pic = true; + this.upload_pic_mode = 0; + this.upload_http_url = ""; + this.support_stranger = true; + } */ - @PostMapping("/setParam") + @PostMapping("/setConfig") @ApiOperation(value = "设置设备参数") - public R setParam(@RequestBody TenDeviceParamVo paramVo){ - String sn = paramVo.getSn(); - boolean onlineFlag = emqHttpApi.getClient(sn); - if(onlineFlag){ - - }else{ - return R.error("设备离线,无法更新"); + public R setConfig(@RequestBody TenDeviceEntity tenDevice){ + TenDeviceConfig config = new TenDeviceConfig(); + config.setWork_mode(tenDevice.getHeartbeatCycle()); + config.setRecognize_interval(tenDevice.getRecSpace()); + config.setRelay_suck_time(5); + if(tenDevice.getLivenessFlag().intValue() == 1){ + config.setSupport_liveness(true); + }else{ + config.setSupport_liveness(false); + } + config.setLiveness_score(tenDevice.getRgbLiveThd().intValue()); + config.setRecognize_score(tenDevice.getRecThd().intValue()); + config.setRecognize_distance(1); + config.setAlert_temp_threshold(tenDevice.getTemperatureAlert()); + config.setUpload_pic_mode(tenDevice.getUploadImageFlag()); + config.setUpload_http_url(""); + if(tenDevice.getStrangerFlag().intValue() == 1){ + config.setSupport_stranger(true); + }else{ + config.setSupport_stranger(false); + } + //配置推送 + int r = serverApiService.devConfig(tenDevice.getSn(),config); + if(r == -1){ + return R.error("设备离线"); } - CmdProcess.publishSetParam(paramVo.getSn(),paramVo); - return R.ok(); + tenDeviceService.evictupdateById(tenDevice); + return R.ok(); } +// /** +// * 设置设备参数 +// */ +// @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(); +// } + + /** * 查询设备版本号 */ @@ -243,22 +375,45 @@ public class TenDeviceController extends AbstractController { /** * 下发app版本 */ +// @PostMapping("/updateApp") +// @ApiOperation(value = "升级app版本") +// @ApiImplicitParams({ +// @ApiImplicitParam(name="deviceSn",value = "设备Sn",paramType = "query",dataType = "String",required = true), +// @ApiImplicitParam(name="apkUrl",value = "apk下载地址",paramType = "query",dataType = "String",required = true), +// }) +// public R updateApp(@RequestBody Map params){ +// String sn = (String)params.get("deviceSn"); +// String apkUrl = (String)params.get("apkUrl"); +// boolean onlineFlag = emqHttpApi.getClient(sn); +// if(onlineFlag){ +// +// }else{ +// return R.error("设备离线,无法更新"); +// } +// CmdProcess.publishUpdateApp(sn,apkUrl); +// return R.ok(); +// } + + @PostMapping("/updateApp") @ApiOperation(value = "升级app版本") - @ApiImplicitParams({ - @ApiImplicitParam(name="deviceSn",value = "设备Sn",paramType = "query",dataType = "String",required = true), - @ApiImplicitParam(name="apkUrl",value = "apk下载地址",paramType = "query",dataType = "String",required = true), - }) - public R updateApp(@RequestBody Map params){ - String sn = (String)params.get("deviceSn"); - String apkUrl = (String)params.get("apkUrl"); - boolean onlineFlag = emqHttpApi.getClient(sn); - if(onlineFlag){ + public R updateApp(@RequestBody SysDeviceAppEntity app){ - }else{ - return R.error("设备离线,无法更新"); + TenAppVerison appVerison = new TenAppVerison(); + appVerison.setApk_url(app.getUrl()); + appVerison.setApp_name(app.getAppName()); + appVerison.setDev_id(app.getDeviceSn()); + appVerison.setDesc(app.getRemark()); + appVerison.setLatest_version(Integer.parseInt(app.getVersion())); + + String sn = app.getDeviceSn(); + //清除数据 + int r = serverApiService.appUpdate(sn,appVerison); + if(r == -1){ + return R.error("设备离线"); } - CmdProcess.publishUpdateApp(sn,apkUrl); return R.ok(); } + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java index ead3a7f..6cf3b8c 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonController.java @@ -20,21 +20,21 @@ import net.shapelight.commons.engine.sdk.PicSDK; import net.shapelight.modules.app.entity.AppUserEntity; import net.shapelight.modules.app.service.AppUserService; import net.shapelight.modules.excel.model.PersonModel; +import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.sys.entity.SysUserEntity; import net.shapelight.modules.sys.service.SysUserRoleService; import net.shapelight.modules.sys.service.SysUserService; -import net.shapelight.modules.ten.entity.TenCellEntity; -import net.shapelight.modules.ten.entity.TenDoorCardEntity; -import net.shapelight.modules.ten.entity.TenUserScopeEntity; +import net.shapelight.modules.ten.entity.*; import net.shapelight.modules.ten.service.*; +import net.shapelight.modules.vo.TenDeviceVo; +import net.shapelight.modules.vo.TenPersonOperationVo; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import net.shapelight.modules.ten.entity.TenPersonEntity; import org.springframework.web.multipart.MultipartFile; @@ -70,6 +70,12 @@ public class TenPersonController extends AbstractController { private TenRecordService tenRecordService; @Autowired private SysUserService sysUserService; + @Autowired + private TenDeviceService tenDeviceService; + @Autowired + private TenPersonSyncService tenPersonSyncService; + @Autowired + private ServerApiService serverApiService; /** @@ -261,7 +267,7 @@ public class TenPersonController extends AbstractController { } person.setDoorCardEntity(doorCard); - String lastRecordTime = tenRecordService.findLastRecordTime(personId,cellId); + String lastRecordTime = tenRecordService.findLastRecordTime(personId,person.getTenantId()); person.setLastRecordTime(lastRecordTime); String lastLoginTime = appUserService.findLastLoginTime(personId, cellId); @@ -350,6 +356,7 @@ public class TenPersonController extends AbstractController { tenPerson.setCreateBy(getUser().getUsername()); tenPerson.setCreateTime(new Date()); tenPerson.setRegisterType(Constant.RESGISTER_TYPE_WEB); + tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR); int res = tenPersonService.save(tenPerson); if (res==2) { return R.error("照片未检测到人脸"); @@ -392,7 +399,7 @@ public class TenPersonController extends AbstractController { /** - * 修改状态,审核人员 + * 修改状态,审核人员 停用禁用 */ @PostMapping("/updateStatus") @RequiresPermissions("ten:person") @@ -402,6 +409,71 @@ public class TenPersonController extends AbstractController { tenPerson.setLastUpdateBy(getUser().getUsername()); tenPerson.setLastUpdateTime(new Date()); tenPersonService.updateStatusById(tenPerson); + //一下推送 + //状态为正常时,添加到同步表并推送 + List devList = tenDeviceService.findByCellId(tenPerson.getCellId()); + if(tenPerson.getStatus().intValue() == Constant.PESON_SUATUS_NOMOR){ + //状态是0正常,发送推送 + for (TenDeviceVo dev : devList) { + //添加到同步表,下发设备通知 + TenPersonSyncEntity syncEntity = tenPersonSyncService.findByDeviceIdAndPersonId(dev.getDeviceId(),tenPerson.getPersonId(),tenPerson.getTenantId()); + if(syncEntity==null){ + syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(tenPerson.getPersonId()); + syncEntity.setTenantId(tenPerson.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(Constant.PERSON_SYNC_ADD); + syncEntity.setLastUpdateTime(tenPerson.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(Constant.PERSON_SYNC_ADD); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(dev.getSn(),list); + }else{ + syncEntity.setState(Constant.PERSON_SYNC_MODIFY); + syncEntity.setLastUpdateTime(tenPerson.getLastUpdateTime()); + tenPersonSyncService.updateById(syncEntity); + + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(Constant.PERSON_SYNC_MODIFY); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(dev.getSn(),list); + } + } + } + //状态为其他时,删除同步表中的数据,并推送 + else{ + for (TenDeviceVo dev : devList) { + //添加到同步表,下发设备通知 + TenPersonSyncEntity syncEntity = tenPersonSyncService.findByDeviceIdAndPersonId(dev.getDeviceId(),tenPerson.getPersonId(),tenPerson.getTenantId()); + if(syncEntity!=null){ + syncEntity.setState(Constant.PERSON_SYNC_DELETE); + syncEntity.setLastUpdateTime(tenPerson.getLastUpdateTime()); + tenPersonSyncService.updateById(syncEntity); + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(Constant.PERSON_SYNC_DELETE); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + int flag = serverApiService.personOperation(dev.getSn(),list); + if(flag!= -1){ + tenPersonSyncService.removeByPersonSyncId(syncEntity.getPersonSyncId(),syncEntity.getTenantId()); + } + } + } + } return R.ok(); } @@ -458,6 +530,7 @@ public class TenPersonController extends AbstractController { }) public R delete(@RequestBody List> params) { //tenRoomService.removeByIds(Arrays.asList(roomIds)); + tenPersonService.removeByIdList(params); return R.ok(); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonExtractController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonExtractController.java index ffd7a8c..48ff6a4 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonExtractController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonExtractController.java @@ -3,6 +3,9 @@ package net.shapelight.modules.ten.controller; import java.util.Arrays; import java.util.Map; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import net.shapelight.modules.sys.controller.AbstractController; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -20,7 +23,7 @@ import net.shapelight.common.utils.R; */ @RestController @RequestMapping("ten/personextract") -public class TenPersonExtractController { +public class TenPersonExtractController extends AbstractController { @Autowired private TenPersonExtractService tenPersonExtractService; @@ -29,7 +32,13 @@ public class TenPersonExtractController { */ @GetMapping("/list") @RequiresPermissions("ten:personextract:list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "String", required = true), + @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "String", required = true), + @ApiImplicitParam(name = "name", value = "姓名", paramType = "query", dataType = "String", required = true), + }) public R list(@RequestParam Map params){ + params.put("tenantId",getUser().getTenantId()); PageUtils page = tenPersonExtractService.queryPage(params); return R.ok().put("data", page); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonSyncController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonSyncController.java new file mode 100644 index 0000000..a80cb60 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenPersonSyncController.java @@ -0,0 +1,83 @@ +package net.shapelight.modules.ten.controller; + +import java.util.Arrays; +import java.util.Map; + +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; +import net.shapelight.modules.ten.service.TenPersonSyncService; +import net.shapelight.common.utils.PageUtils; +import net.shapelight.common.utils.R; + + + +/** + * + * + */ +@RestController +@RequestMapping("ten/personsync") +public class TenPersonSyncController { + @Autowired + private TenPersonSyncService tenPersonSyncService; + +// /** +// * 列表 +// */ +// @GetMapping("/list") +// @RequiresPermissions("ten:personsync:list") +// public R list(@RequestParam Map params){ +// PageUtils page = tenPersonSyncService.queryPage(params); +// +// return R.ok().put("data", page); +// } +// +// +// /** +// * 信息 +// */ +// @GetMapping("/info/{personSyncId}") +// @RequiresPermissions("ten:personsync:info") +// public R info(@PathVariable("personSyncId") Long personSyncId){ +// TenPersonSyncEntity tenPersonSync = tenPersonSyncService.getById(personSyncId); +// +// return R.ok().put("data", tenPersonSync); +// } +// +// /** +// * 保存 +// */ +// @PostMapping("/save") +// @RequiresPermissions("ten:personsync:save") +// public R save(@RequestBody TenPersonSyncEntity tenPersonSync){ +// tenPersonSyncService.save(tenPersonSync); +// +// return R.ok(); +// } +// +// /** +// * 修改 +// */ +// @PostMapping("/update") +// @RequiresPermissions("ten:personsync:update") +// public R update(@RequestBody TenPersonSyncEntity tenPersonSync){ +// tenPersonSyncService.updateById(tenPersonSync); +// +// return R.ok(); +// } +// +// /** +// * 删除 +// */ +// @PostMapping("/delete") +// @RequiresPermissions("ten:personsync:delete") +// public R delete(@RequestBody Long[] personSyncIds){ +// tenPersonSyncService.removeByIds(Arrays.asList(personSyncIds)); +// +// return R.ok(); +// } + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenRecordController.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenRecordController.java index 4c226ef..09c5fcb 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenRecordController.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/controller/TenRecordController.java @@ -108,8 +108,10 @@ public class TenRecordController extends AbstractController { // @RequiresPermissions("ten:tenrecord:info") public R info(@PathVariable("recordId") Long recordId,@PathVariable("cellId") Long cellId){ - TenRecordEntity tenRecord = tenRecordService.getById(recordId,cellId); - return R.ok().put("data", tenRecord); +// String tenantId = getUser().getTenantId()+""; +//// params.put("tenantId",tenantId+""); +// TenRecordEntity tenRecord = tenRecordService.getById(recordId,cellId); + return R.ok().put("data", null); } /** diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenCellDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenCellDao.java index 5bcdcaa..bb9b827 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenCellDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenCellDao.java @@ -17,12 +17,14 @@ import java.util.Map; @Mapper public interface TenCellDao extends BaseMapper { - void createTenBuild(@Param("cellId")String cellId); - void createTenRoom(@Param("cellId")String cellId); - void createTenPerson(@Param("cellId")String cellId); - void createTenRecord(@Param("cellId")String cellId); - void createTenCar(@Param("cellId")String cellId); - void createTenPackRecord(@Param("cellId")String cellId); + void createTenBuild(@Param("tenantId")String tenantId); + void createTenRoom(@Param("tenantId")String tenantId); + void createTenPerson(@Param("tenantId")String tenantId); + void createTenRecord(@Param("tenantId")String tenantId); + void createTenCar(@Param("tenantId")String tenantId); + void createTenPackRecord(@Param("tenantId")String tenantId); + void createTenPersonExtract(@Param("tenantId")String tenantId); + void createTenPersonSync(@Param("tenantId")String tenantId); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java index 310b362..9b21cc1 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonDao.java @@ -77,4 +77,9 @@ public interface TenPersonDao { @Param("roomId")Long roomId, @Param("cellId")Long cellId); + + List getAllExpireGuest(); + + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java new file mode 100644 index 0000000..0b9d0cf --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenPersonSyncDao.java @@ -0,0 +1,40 @@ +package net.shapelight.modules.ten.dao; + +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * + * + */ +@Mapper +public interface TenPersonSyncDao { + + List getDeviceAllPersonIdUpdateTime(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); + + int insert(TenPersonSyncEntity tenLicenseEntity); + int updateById(TenPersonSyncEntity entity); + + void removeByDeviceId(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); + + void removeAllDeletePersons(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); + + TenPersonSyncEntity findByDeviceIdAndPersonId(@Param("deviceId")Long deviceId, @Param("personId")Long personId, @Param("tenantId")Long tenantId); + + List findByPersonId(@Param("personId")Long personId, @Param("tenantId")Long tenantId); + + List> findGroupDevicePersons(@Param("personIds")List personIds, @Param("tenantId")Long tenantId); + + List findDeviceAllDeletePersons(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); + + List findDeviceAllAddPersons(@Param("deviceId")Long deviceId,@Param("tenantId")Long tenantId); + + void removePersonSyncId(@Param("personSyncId")Long personSyncId,@Param("tenantId")Long tenantId); + +} diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java index 95b05a8..90f7719 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/dao/TenRecordDao.java @@ -17,9 +17,9 @@ import java.util.Map; @Mapper public interface TenRecordDao{ int insert(TenRecordEntity tenRecordEntity); - int deleteById(@Param("recordId")Long id, @Param("cellId")Long cellId); + int deleteById(@Param("recordId")Long id, @Param("tenantId")Long tenantId); boolean updateById(TenRecordEntity entity); - TenRecordEntity selectById(@Param("recordId")Long recordId,@Param("cellId")Long cellId); + TenRecordEntity selectById(@Param("recordId")Long recordId,@Param("tenantId")Long tenantId); IPage findPageAll(Page page, @Param("cellIds")List cellIds, @Param("params") Map params); List findAll(@Param("cellIds")List cellIds, @Param("params") Map params); @@ -30,7 +30,7 @@ public interface TenRecordDao{ IPage findPageRoomRecord(Page page,@Param("params") Map params); - String findLastRecordTime(@Param("personId")Long personId,@Param("cellId")Long cellId); + String findLastRecordTime(@Param("personId")Long personId,@Param("tenantId")Long tenantId); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCarEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCarEntity.java index 41b8b06..361b420 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCarEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenCarEntity.java @@ -110,7 +110,7 @@ import lombok.Data; * */ @Data -//@TableName("ten_car") +@TableName("ten_car") public class TenCarEntity implements Serializable { private static final long serialVersionUID = 1L; 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 bf526a5..2c6fa7c 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 @@ -226,6 +226,8 @@ public class TenDeviceEntity extends BaseEntity implements Serializable { private String scope; + + // @TableField(exist=false) // @ApiModelProperty("小区名称") // private String cellName; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPackRecordEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPackRecordEntity.java index 7a14350..2fddae2 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPackRecordEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPackRecordEntity.java @@ -115,7 +115,7 @@ import lombok.Data; * */ @Data -//@TableName("ten_pack_record") +@TableName("ten_pack_record") public class TenPackRecordEntity implements Serializable { private static final long serialVersionUID = 1L; 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 7a60675..be53963 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 @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import java.util.Date; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; @@ -20,7 +21,7 @@ import net.shapelight.common.base.BaseEntity; * 人员表 */ @Data -//@TableName("ten_person") +@TableName("ten_person") public class TenPersonEntity extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -315,5 +316,14 @@ public class TenPersonEntity extends BaseEntity implements Serializable { private String doorNumber; + @ApiModelProperty("提取失败log个数") + @TableField(exist = false) + private Integer extractCount; + + @ApiModelProperty("提取失败log个数") + @TableField(exist = false) + private List extractList; + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonExtractEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonExtractEntity.java index bfac423..0f93202 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonExtractEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonExtractEntity.java @@ -7,6 +7,9 @@ import java.io.Serializable; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -51,6 +54,8 @@ public class TenPersonExtractEntity implements Serializable { /** * 运营商ID */ + @ApiModelProperty("运营商ID") + @JsonSerialize(using = ToStringSerializer.class) private Long tenantId; } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonSyncEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonSyncEntity.java new file mode 100644 index 0000000..36af167 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenPersonSyncEntity.java @@ -0,0 +1,58 @@ +package net.shapelight.modules.ten.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +import java.io.Serializable; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * + * + */ +@Data +@TableName("ten_person_sync") +public class TenPersonSyncEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @TableId + private Long personSyncId; + /** + * 设备id + */ + private Long deviceId; + /** + * 设备sn + */ + private String deviceSn; + /** + * 人员id + */ + private Long personId; + /** + * 0未同步4已同步1新增2修改3删除 + */ + private Integer state; + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date lastUpdateTime; + + /** + * 运营商ID + */ + @ApiModelProperty("运营商ID") + @JsonSerialize(using = ToStringSerializer.class) + private Long tenantId; + +} 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 964a4b5..debb576 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 @@ -19,7 +19,7 @@ import lombok.Data; * */ @Data -//@TableName("ten_record") +@TableName("ten_record") public class TenRecordEntity implements Serializable { private static final long serialVersionUID = 1L; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRoomEntity.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRoomEntity.java index ed71dfd..70ddaf6 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRoomEntity.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/entity/TenRoomEntity.java @@ -13,10 +13,10 @@ import net.shapelight.common.base.BaseEntity; /** * 户室表 - * + * */ @Data -//@TableName("ten_room") +@TableName("ten_room") public class TenRoomEntity extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenDeviceService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenDeviceService.java index 71b2890..318fe99 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenDeviceService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenDeviceService.java @@ -25,7 +25,7 @@ public interface TenDeviceService extends IService { PageUtils queryPage(Map params); List findByCellId(long cellId); - boolean remoteOpenDoor(String deviceSn,String personId,Integer memberId); + boolean remoteOpenDoor(String deviceSn,Long personId,Integer memberId); TenDeviceEntity findBySn(String sn); List findAllSn(); List findUpdatePerson(Long cellId, @@ -68,5 +68,7 @@ public interface TenDeviceService extends IService { void evictupdateById(TenDeviceEntity tenDevice); + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java index 0a0b88f..0dff100 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonService.java @@ -29,7 +29,7 @@ public interface TenPersonService { int save(TenPersonEntity entity); boolean saveOtherRoom(TenPersonEntity entity); - boolean removeById(Long roomId,Long cellId); +// boolean removeById(Long roomId,Long cellId); boolean removeByIdList(List> roomIdList); @@ -107,5 +107,9 @@ public interface TenPersonService { int getAllCount(Map params); + + List getAllExpireGuest(); + + } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java new file mode 100644 index 0000000..eb721c9 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenPersonSyncService.java @@ -0,0 +1,42 @@ +package net.shapelight.modules.ten.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import net.shapelight.common.utils.PageUtils; +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; +import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * + * + */ +public interface TenPersonSyncService { + + + List getDeviceAllPersonIdUpdateTime(Long deviceId,Long tenantId); + + int insert(TenPersonSyncEntity tenLicenseEntity); + int updateById(TenPersonSyncEntity entity); + + void removeByDeviceId(Long deviceId, Long tenantId); + + void removeByPersonSyncId(Long personSyncId, Long tenantId); + + void removeAllDeletePersons(Long deviceId,Long tenantId); + + TenPersonSyncEntity findByDeviceIdAndPersonId(Long deviceId, Long personId,Long tenantId); + + List findByPersonId(Long personId,Long tenantId); + + List> findGroupDevicePersons(List personIds, Long tenantId); + + List findDeviceAllDeletePersons(Long deviceId, Long tenantId); + + List findDeviceAllAddPersons(Long deviceId, Long tenantId); + + +} + diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java index 51f2e01..465bc51 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/TenRecordService.java @@ -25,9 +25,9 @@ public interface TenRecordService { boolean updateById(TenRecordEntity entity); - TenRecordEntity getById(Long id,Long cellId); + TenRecordEntity getById(Long id,Long tenantId); - String findLastRecordTime(Long personId,Long cellId); + String findLastRecordTime(Long personId,Long tenantId); int getCount(Map params); int getHourCount(Map params); diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java index 2e82ce3..f0ec171 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenCellServiceImpl.java @@ -77,12 +77,15 @@ public class TenCellServiceImpl extends ServiceImpl i @CacheEvict(value = "TenCell", allEntries = true) public boolean save(TenCellEntity entity) { String cellId = entity.getCellId().toString(); - tenCellDao.createTenBuild(cellId); - tenCellDao.createTenRoom(cellId); - tenCellDao.createTenPerson(cellId); - tenCellDao.createTenRecord(cellId); - tenCellDao.createTenCar(cellId); - tenCellDao.createTenPackRecord(cellId); + String tenantId = entity.getTenantId().toString(); +// tenCellDao.createTenBuild(cellId); +// tenCellDao.createTenRoom(cellId); +// tenCellDao.createTenPerson(tenantId); + tenCellDao.createTenRecord(tenantId); +// tenCellDao.createTenCar(cellId); +// tenCellDao.createTenPackRecord(cellId); +// tenCellDao.createTenPersonExtract(tenantId); + tenCellDao.createTenPersonSync(tenantId); return super.save(entity); } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java index 301c611..4b289a4 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenDeviceServiceImpl.java @@ -1,14 +1,15 @@ package net.shapelight.modules.ten.service.impl; import lombok.extern.slf4j.Slf4j; -import net.shapelight.common.utils.Constant; -import net.shapelight.common.utils.RedisUtils; -import net.shapelight.modules.dev.mqtt.CmdProcess; -import net.shapelight.modules.dev.mqtt.EmqHttpApi; +import net.shapelight.common.utils.*; +//import net.shapelight.modules.dev.mqtt.CmdProcess; +//import net.shapelight.modules.dev.mqtt.EmqHttpApi; import net.shapelight.modules.nettyapi.service.DeviceApiService; +import net.shapelight.modules.nettyapi.service.ServerApiService; import net.shapelight.modules.ten.entity.*; import net.shapelight.modules.ten.service.*; import net.shapelight.modules.vo.TenDeviceVo; +import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; import net.shapelight.modules.vo.TenPersonIdUpdateVo; import net.shapelight.modules.vo.TenPersonVo; import org.apache.commons.beanutils.BeanUtils; @@ -26,8 +27,6 @@ import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import net.shapelight.common.utils.PageUtils; -import net.shapelight.common.utils.Query; import net.shapelight.modules.ten.dao.TenDeviceDao; import org.springframework.transaction.annotation.Transactional; @@ -51,12 +50,16 @@ public class TenDeviceServiceImpl extends ServiceImpl params) { @@ -131,8 +134,15 @@ public class TenDeviceServiceImpl extends ServiceImpl0){ for(TenDeviceEntity dev: devList){ - boolean onlineFlag = emqHttpApi.getClient(dev.getSn()); - if(onlineFlag){ +// boolean onlineFlag = emqHttpApi.getClient(dev.getSn()); +// if(onlineFlag){ +// dev.setStatus(1); +// }else{ +// dev.setStatus(0); +// } + + Boolean flag = deviceApiService.isOnline(dev.getSn()); + if (flag) { dev.setStatus(1); }else{ dev.setStatus(0); @@ -152,8 +162,16 @@ public class TenDeviceServiceImpl extends ServiceImpl=0) { for(TenDeviceEntity dev: list){ - boolean onlineFlag = emqHttpApi.getClient(dev.getSn()); +// boolean onlineFlag = emqHttpApi.getClient(dev.getSn()); + boolean onlineFlag = deviceApiService.isOnline(dev.getSn()); if(onlineFlag){ onlineCount++; } @@ -303,8 +322,26 @@ public class TenDeviceServiceImpl extends ServiceImpl list = tenPersonService.findAllPersonIdUpdateAll(deviceEntity.getCellId(), + deviceEntity.getBuildId(), + deviceEntity.getRoomId()); +// List sList = new ArrayList<>(); + for(TenPersonIdUpdateAllVo vo:list){ + TenPersonSyncEntity entity = new TenPersonSyncEntity(); + entity.setDeviceId(deviceEntity.getDeviceId()); + entity.setDeviceSn(deviceEntity.getSn()); + entity.setLastUpdateTime(vo.getLast_update_stamp()); + entity.setPersonId(vo.getUid()); + entity.setState(0); + entity.setTenantId(deviceEntity.getTenantId()); +// sList.add(entity); + tenPersonSyncService.insert(entity); + } +// tenPersonSyncService.saveBatch(sList); } @Override diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonExtractServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonExtractServiceImpl.java index 375647c..7690264 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonExtractServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonExtractServiceImpl.java @@ -26,4 +26,4 @@ public class TenPersonExtractServiceImpl extends ServiceImpl page = tenPersonDao.findPageAll(pageParam, cellIds, params); + for(TenPersonEntity personEntity: page.getRecords()){ + List extracts = tenPersonExtractService.list( + new QueryWrapper() + .eq("person_id",personEntity.getPersonId()) + ); + if(extracts!=null){ + personEntity.setExtractCount(extracts.size()); + personEntity.setExtractList(extracts); + }else{ + personEntity.setExtractCount(0); + personEntity.setExtractList(new ArrayList<>()); + } + } return new PageUtils(page); } @@ -315,6 +332,9 @@ public class TenPersonServiceImpl implements TenPersonService { } String password = entity.getPassword(); entity.setPassword(""); + Date now = new Date(); + entity.setCreateTime(now); + entity.setLastUpdateTime(now); ////访客添加状态 // Date now = new Date(); @@ -357,7 +377,7 @@ public class TenPersonServiceImpl implements TenPersonService { card.setValidBegin(entity.getDoorCardEntity().getValidBegin()); card.setValidEnd(entity.getDoorCardEntity().getValidEnd()); - Date now = new Date(); +// Date now = new Date(); // card.setCreateBy(getUser().getUsername()); card.setCreateTime(now); card.setLastUpdateTime(now); @@ -375,6 +395,7 @@ public class TenPersonServiceImpl implements TenPersonService { // appUser.setSalt(salt); appUser.setPassword(DigestUtils.sha256Hex(password)); appUser.setCreateTime(new Date()); + appUser.setTenantId(entity.getTenantId()); appUserService.save(appUser); @@ -392,48 +413,28 @@ public class TenPersonServiceImpl implements TenPersonService { //发送设备通知 List devList = tenDeviceService.findByCellId(entity.getCellId()); - TenPersonEntity personDo = tenPersonDao.selectById(entity.getPersonId(),entity.getCellId()); - for (TenDeviceVo dev : devList) { - TenPersonVo vo = new TenPersonVo(); - BeanUtils.copyProperties(personDo,vo); - if (vo.getFaceImage() != null && !vo.getFaceImage().isEmpty()) { - String encode = ""; - InputStream inStream = null; - ByteArrayOutputStream outStream = null; - try { - minioClient.statObject(minioConfig.getBucketName(), vo.getFaceImage()); - inStream = minioClient.getObject(minioConfig.getBucketName(), vo.getFaceImage()); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } - encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); - vo.setFaceImageStr(encode); - } catch (Exception e) { - log.error("底库不存在:" + vo.getFaceImage()); - e.printStackTrace(); - } finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - log.debug("inputStream close IOException:" + e.getMessage()); - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - log.debug("outStream close IOException:" + e.getMessage()); - } - } - } - } -// CmdProcess.publishPersonChange(dev.getSn()); - CmdProcess.publishAddPerson(dev.getSn(),vo); + //状态是0正常,发送推送 + if(entity.getStatus().intValue() == Constant.PESON_SUATUS_NOMOR){ + for (TenDeviceVo dev : devList) { + //添加到同步表,下发设备通知 + TenPersonSyncEntity syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(entity.getPersonId()); + syncEntity.setTenantId(entity.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(1); + syncEntity.setLastUpdateTime(entity.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(1); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(dev.getSn(),list); + } } return 0; } @@ -441,6 +442,7 @@ public class TenPersonServiceImpl implements TenPersonService { } + //添加多个房产 @Override @Transactional(rollbackFor = Exception.class) public boolean saveOtherRoom(TenPersonEntity entity) { @@ -448,47 +450,6 @@ public class TenPersonServiceImpl implements TenPersonService { entity.getCellId().toString() + "/" + entity.getPersonId().toString() + "/"; try { - //保存原始图片 -// String tempOrgImageFile = entity.getOrgImageTemp(); -// String tempIdFrontImage = entity.getIdFrontImageTemp(); -// String tempIdBackImage = entity.getIdBackImageTemp(); -// if (tempOrgImageFile != null && !tempOrgImageFile.isEmpty()) { -// String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg"; -// String faceImageFileName = userFileUrl + "s_" + UUIDUtil.uuid() + ".jpg"; -//// MinioClient minioClient = MinioUtil.getMinioClient(); -// try { -// // 调用statObject()来判断对象是否存在。 -// // 如果不存在, statObject()抛出异常, -// // 否则则代表对象存在。 -// minioClient.statObject(minioConfig.getBucketName(), tempOrgImageFile); -// minioClient.copyObject( -// minioConfig.getBucketName(), -// orgImageFileName, -// null, -// null, -// minioConfig.getBucketName(), -// tempOrgImageFile, -// null, -// null); -// -// minioClient.copyObject( -// minioConfig.getBucketName(), -// faceImageFileName, -// null, -// null, -// minioConfig.getBucketName(), -// tempOrgImageFile, -// null, -// null); -// entity.setOrgImage(orgImageFileName); -// entity.setFaceImage(faceImageFileName); -// } catch (Exception e) { -// entity.setOrgImage(""); -// e.printStackTrace(); -// } -// } - - //保存原始图片 String tempOrgImageFile = entity.getOrgImageTemp(); String tempIdFrontImage = entity.getIdFrontImage(); @@ -622,10 +583,12 @@ public class TenPersonServiceImpl implements TenPersonService { } // String password = entity.getPassword(); // entity.setPassword(""); + entity.setStatus(Constant.PESON_SUATUS_NOMOR); int flag = tenPersonDao.insert(entity); if (flag == 1) { //保存App用户 if (entity.getAppFlag() == Constant.APP_LOGIN_YES) { + //已经是app用户了,不用添加app账户 // AppUserEntity appUser = new AppUserEntity(); // appUser.setUsername(entity.getUsername()); // appUser.setMobile(entity.getMobile()); @@ -651,71 +614,47 @@ public class TenPersonServiceImpl implements TenPersonService { //发送设备通知 - List devList = tenDeviceService.findByCellId(entity.getCellId()); - TenPersonEntity personDo = tenPersonDao.selectById(entity.getPersonId(),entity.getCellId()); - for (TenDeviceVo dev : devList) { - TenPersonVo vo = new TenPersonVo(); - BeanUtils.copyProperties(personDo,vo); - if (vo.getFaceImage() != null && !vo.getFaceImage().isEmpty()) { - String encode = ""; - InputStream inStream = null; - ByteArrayOutputStream outStream = null; - try { - minioClient.statObject(minioConfig.getBucketName(), vo.getFaceImage()); - inStream = minioClient.getObject(minioConfig.getBucketName(), vo.getFaceImage()); - outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int length; - while ((length = inStream.read(buffer)) != -1) { - outStream.write(buffer, 0, length); - } - encode = Base64.getEncoder().encodeToString(outStream.toByteArray()); - vo.setFaceImageStr(encode); - } catch (Exception e) { - log.error("底库不存在:" + vo.getFaceImage()); - e.printStackTrace(); - } finally { - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - log.debug("inputStream close IOException:" + e.getMessage()); - } - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - log.debug("outStream close IOException:" + e.getMessage()); - } - } - } - } -// CmdProcess.publishPersonChange(dev.getSn()); - CmdProcess.publishAddPerson(dev.getSn(),vo); - } - - - // List devList = tenDeviceService.findByCellId(entity.getCellId()); -// for (TenDeviceVo dev : devList) { -// CmdProcess.publishPersonChange(dev.getSn()); -// } + //发送设备通知 + List devList = tenDeviceService.findByCellId(entity.getCellId()); + //状态是0正常,发送推送 + if(entity.getStatus().intValue() == Constant.PESON_SUATUS_NOMOR){ + for (TenDeviceVo dev : devList) { + //添加到同步表,下发设备通知 + TenPersonSyncEntity syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(entity.getPersonId()); + syncEntity.setTenantId(entity.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(1); + syncEntity.setLastUpdateTime(entity.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(1); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(dev.getSn(),list); + } + } return true; } return false; } - @Override - @CacheEvict(value = "TenPerson", key = "#personId+'-'+#cellId") - public boolean removeById(Long personId, Long cellId) { - int flag = tenPersonDao.logicDeleteById(personId, cellId); - if (flag == 1) { - return true; - } - return false; - } +// @Override +// @CacheEvict(value = "TenPerson", key = "#personId+'-'+#cellId") +// public boolean removeById(Long personId, Long cellId) { +// int flag = tenPersonDao.logicDeleteById(personId, cellId); +// if (flag == 1) { +// return true; +// } +// return false; +// } @Override @Transactional(rollbackFor = Exception.class) @@ -723,6 +662,8 @@ public class TenPersonServiceImpl implements TenPersonService { @CacheEvict(value = "TenPerson", allEntries = true) public boolean removeByIdList(List> roomIdList) { Long cellId = 0L; + List personIds = new ArrayList<>(); + Long tenantId = 0l; for (Map param : roomIdList) { Long personId = Long.parseLong(param.get("personId")); cellId = Long.parseLong(param.get("cellId")); @@ -730,6 +671,7 @@ public class TenPersonServiceImpl implements TenPersonService { entity.setLastUpdateTime(new Date()); entity.setFaceFailure(Constant.FACE_FAILURE_OK); tenPersonDao.updateById(entity); + tenantId = entity.getTenantId(); //删除app用户 AppUserScopeEntity as = appUserScopeService.getOne(new QueryWrapper() .eq("person_id", personId) @@ -751,12 +693,45 @@ public class TenPersonServiceImpl implements TenPersonService { // } //删除人员 tenPersonDao.logicDeleteById(personId, cellId); - } - List devList = tenDeviceService.findByCellId(cellId); - for (TenDeviceVo dev : devList) { - CmdProcess.publishPersonChange(dev.getSn()); + + //记录所有人员id + personIds.add(personId); } + //配置同步信息并推送 + + List> snPersonsList = tenPersonSyncService.findGroupDevicePersons(personIds,tenantId); + for(Map snPersons: snPersonsList){ + String sn = snPersons.get("deviceSn"); + TenDeviceEntity deviceEntity = tenDeviceService.findBySn(sn); + String[] persons = snPersons.get("plist").split(","); + List list = new ArrayList<>(); + for(String personStr: persons){ + String[] personInfoStr = personStr.split("_"); + Long personId = Long.parseLong(personInfoStr[0]); + Date lastUpdateTime = DateUtils.stringToDate(personInfoStr[1],DateUtils.DATE_TIME_PATTERN); + + TenPersonSyncEntity syncEntity = tenPersonSyncService.findByDeviceIdAndPersonId(deviceEntity.getDeviceId(),personId,tenantId); + syncEntity.setLastUpdateTime(lastUpdateTime); + syncEntity.setState(Constant.PERSON_SYNC_DELETE); + tenPersonSyncService.updateById(syncEntity); + } + //下发通知 + List allDelete = tenPersonSyncService.findDeviceAllDeletePersons(deviceEntity.getDeviceId(),deviceEntity.getTenantId()); + for(TenPersonSyncEntity syncEntity: allDelete){ + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(Constant.PERSON_SYNC_DELETE); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + list.add(vo); + } + + int flag = serverApiService.personOperation(sn,list); + if(flag == 0){ + //下发成功,删除状态为删除的同步人员 + tenPersonSyncService.removeAllDeletePersons(deviceEntity.getDeviceId(),tenantId); + } + } return true; } @@ -772,12 +747,44 @@ public class TenPersonServiceImpl implements TenPersonService { entity.setLastUpdateTime(new Date()); entity.setStatus(Constant.PESON_SUATUS_NOMOR); tenPersonDao.updateById(entity); + + //添加到同步表, + List devList = tenDeviceService.findByCellId(cellId); + for (TenDeviceVo dev : devList) { + TenPersonSyncEntity syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(entity.getPersonId()); + syncEntity.setTenantId(entity.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(Constant.PERSON_SYNC_ADD); + syncEntity.setLastUpdateTime(entity.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + } } + //下发设备通知 List devList = tenDeviceService.findByCellId(cellId); - for (TenDeviceVo dev : devList) { - CmdProcess.publishPersonChange(dev.getSn()); + for(TenDeviceVo deviceVo: devList){ + List operationList = tenPersonSyncService.findDeviceAllAddPersons(deviceVo.getDeviceId(),deviceVo.getTenantId()); + List voList = new ArrayList<>(); + for(TenPersonSyncEntity syncEntity: operationList){ + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(syncEntity.getState()); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + voList.add(vo); + } + + int flag = serverApiService.personOperation(deviceVo.getSn(),voList); + if(flag == 0){ + //下发成功,删除状态为删除的同步人员 +// tenPersonSyncService.removeAllDeletePersons(deviceEntity.getDeviceId(),tenantId); + } } + + + + return true; } @@ -1042,7 +1049,9 @@ public class TenPersonServiceImpl implements TenPersonService { } else { //以前不支持app现在支持app登录 if (entity.getAppFlag() == Constant.APP_LOGIN_YES) { //默认密码:123456 - entity.setPassword("123456"); + if(entity.getPassword()==null || entity.getPassword().length()==0){ + entity.setPassword("123456"); + } //1.验证用户名 AppUserEntity checkUser = appUserService.findByUsername(entity.getUsername()); // if (checkUser != null) { @@ -1058,10 +1067,14 @@ public class TenPersonServiceImpl implements TenPersonService { appUser.setMobile(entity.getMobile()); //sha256加密 - String salt = RandomStringUtils.randomAlphanumeric(20); - appUser.setPassword(new Sha256Hash(entity.getPassword(), salt).toHex()); - appUser.setSalt(salt); +// String salt = RandomStringUtils.randomAlphanumeric(20); +// appUser.setPassword(new Sha256Hash(entity.getPassword(), salt).toHex()); +// appUser.setSalt(salt); + + appUser.setPassword(DigestUtils.sha256Hex(entity.getPassword())); + appUser.setCreateTime(new Date()); + appUser.setTenantId(entity.getTenantId()); appUserService.save(appUser); //保存房产信息 @@ -1164,11 +1177,31 @@ public class TenPersonServiceImpl implements TenPersonService { } tenPersonDao.updateById(entity); - - List devList = tenDeviceService.findByCellId(entity.getCellId()); - for (TenDeviceVo dev : devList) { - CmdProcess.publishPersonChange(dev.getSn()); + //配置同步数据 + List syncEntitys = tenPersonSyncService.findByPersonId(entity.getPersonId(),entity.getTenantId()); + for(TenPersonSyncEntity syncEn: syncEntitys){ + syncEn.setLastUpdateTime(entity.getLastUpdateTime()); + syncEn.setState(2); + tenPersonSyncService.updateById(syncEn); + //下发通知 + List list = new ArrayList<>(); + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(entity.getPersonId()); + vo.setOperation(2); + vo.setLast_update_stamp(entity.getLastUpdateTime()); + list.add(vo); + serverApiService.personOperation(syncEn.getDeviceSn(),list); } + +// List devList = tenDeviceService.findByCellId(entity.getCellId()); +// for (TenDeviceVo dev : devList) { +// CmdProcess.publishPersonChange(dev.getSn()); +// } + + + + + return "OK"; } @@ -1194,10 +1227,10 @@ public class TenPersonServiceImpl implements TenPersonService { // } // } int flag = tenPersonDao.updateById(entity); - List devList = tenDeviceService.findByCellId(entity.getCellId()); - for (TenDeviceVo dev : devList) { - CmdProcess.publishPersonChange(dev.getSn()); - } +// List devList = tenDeviceService.findByCellId(entity.getCellId()); +// for (TenDeviceVo dev : devList) { +// CmdProcess.publishPersonChange(dev.getSn()); +// } if (flag == 1) { return true; } @@ -1694,9 +1727,12 @@ public class TenPersonServiceImpl implements TenPersonService { @Transactional(rollbackFor = Exception.class) public void savePersonModelList(List list) { List addList = new ArrayList<>(); + Long cellId = 0l; for (PersonModel personModel : list) { if (personModel.getStatus() == 1) { TenPersonEntity tenPerson = new TenPersonEntity(); + + TenCellEntity cellEntity = findCellByCellName(personModel.getCellName(), personModel.getTenantId()); TenBuildEntity tenBuildEntity = findBuildByNameAndUnit(personModel.getBuildName(), personModel.getBuildUnit().replace("单元", ""), @@ -1709,6 +1745,8 @@ public class TenPersonServiceImpl implements TenPersonService { tenPerson.setBuildId(tenBuildEntity.getBuildId()); tenPerson.setRoomId(tenRoomEntity.getRoomId()); + cellId = cellEntity.getCellId(); + tenPerson.setName(personModel.getName()); if (personModel.getGender().equals("男")) { tenPerson.setGender(1); @@ -1725,7 +1763,9 @@ public class TenPersonServiceImpl implements TenPersonService { tenPerson.setUuid(UUIDUtil.uuid()); tenPerson.setTenantId(Long.parseLong(personModel.getTenantId())); // tenPerson.setCreateBy(getUser().getUsername()); - tenPerson.setCreateTime(new Date()); + Date now = new Date(); + tenPerson.setCreateTime(now); + tenPerson.setLastUpdateTime(now); tenPerson.setRegisterType(Constant.RESGISTER_TYPE_FILE); String userFileUrl = globalValue.getImagesDir() + "/" + @@ -1763,19 +1803,56 @@ public class TenPersonServiceImpl implements TenPersonService { } String tempFaceFileName = UUIDUtil.uuid() + ".jpg"; String tempFaceFilePath = tempPath + tempFaceFileName; - int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); - if (res != 0) { - return; - } else { - //1. 保存人脸图片 - InputStream inputStreamFace = new FileInputStream(tempFaceFilePath); - PutObjectOptions putObjectOptionsFace = new PutObjectOptions(inputStreamFace.available(), -1); - putObjectOptions.setContentType("image/jpg"); - minioClient.putObject( - minioConfig.getBucketName(), faceImageFileName, inputStreamFace, putObjectOptionsFace); - inputStreamFace.close(); - tenPerson.setFaceImage(faceImageFileName); + + + String osName = System.getProperty("os.name");//获取指定键(即os.name)的系统属性,如:Windows 7。 + if (!Pattern.matches("Windows.*", osName)) { + int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); + if (res != 0) { + return; + } else { + //1. 保存人脸图片 + InputStream inputStreamFace = new FileInputStream(tempFaceFilePath); + PutObjectOptions putObjectOptionsFace = new PutObjectOptions(inputStreamFace.available(), -1); + putObjectOptions.setContentType("image/jpg"); + minioClient.putObject( + minioConfig.getBucketName(), faceImageFileName, inputStreamFace, putObjectOptionsFace); + inputStreamFace.close(); + tenPerson.setFaceImage(faceImageFileName); + } + }else{ + //windows 保存原始头像 + tenPerson.setFaceImage(orgImageFileName); } + + + +// int res = PicSDK.getFace(personModel.getOrgImage(), tempFaceFilePath); +// if (res != 0) { +// return; +// } else { +// //1. 保存人脸图片 +// InputStream inputStreamFace = new FileInputStream(tempFaceFilePath); +// PutObjectOptions putObjectOptionsFace = new PutObjectOptions(inputStreamFace.available(), -1); +// putObjectOptions.setContentType("image/jpg"); +// minioClient.putObject( +// minioConfig.getBucketName(), faceImageFileName, inputStreamFace, putObjectOptionsFace); +// inputStreamFace.close(); +// tenPerson.setFaceImage(faceImageFileName); +// } + + +// //1. 保存人脸图片 +// InputStream inputStreamFace = new FileInputStream(tempFaceFilePath); +// PutObjectOptions putObjectOptionsFace = new PutObjectOptions(inputStreamFace.available(), -1); +// putObjectOptions.setContentType("image/jpg"); +// minioClient.putObject( +// minioConfig.getBucketName(), faceImageFileName, inputStreamFace, putObjectOptionsFace); +// inputStreamFace.close(); +// tenPerson.setFaceImage(faceImageFileName); + + + // tenPerson.setFaceImage(orgImageFileName); //-------------------------------------------------------------------- @@ -1802,8 +1879,6 @@ public class TenPersonServiceImpl implements TenPersonService { } //--------------------------------处理图片大小------------------------------------------------------ - - } catch (Exception e) { e.printStackTrace(); tenPerson.setStatus(0); @@ -1811,6 +1886,49 @@ public class TenPersonServiceImpl implements TenPersonService { continue; } tenPersonDao.insert(tenPerson); + + //门禁表 + if(personModel.getDoorCard()!=null && personModel.getDoorCard().length()>0){ + TenDoorCardEntity doorCardEntity = new TenDoorCardEntity(); + doorCardEntity.setDoorCard(personModel.getDoorCard()); + doorCardEntity.setCellId(tenPerson.getCellId()); + doorCardEntity.setPersonId(tenPerson.getPersonId()); + tenDoorCardService.save(doorCardEntity); + } + + + //添加到同步表, + List devList = tenDeviceService.findByCellId(cellEntity.getCellId()); + for (TenDeviceVo dev : devList) { + TenPersonSyncEntity syncEntity = new TenPersonSyncEntity(); + syncEntity.setPersonId(tenPerson.getPersonId()); + syncEntity.setTenantId(tenPerson.getTenantId()); + syncEntity.setDeviceSn(dev.getSn()); + syncEntity.setDeviceId(dev.getDeviceId()); + syncEntity.setState(1); + syncEntity.setLastUpdateTime(tenPerson.getLastUpdateTime()); + tenPersonSyncService.insert(syncEntity); + } + } + } + +//下发设备通知 + List devList = tenDeviceService.findByCellId(cellId); + for(TenDeviceVo deviceVo: devList){ + List operationList = tenPersonSyncService.findDeviceAllAddPersons(deviceVo.getDeviceId(),deviceVo.getTenantId()); + List voList = new ArrayList<>(); + for(TenPersonSyncEntity syncEntity: operationList){ + TenPersonOperationVo vo = new TenPersonOperationVo(); + vo.setUid(syncEntity.getPersonId()); + vo.setOperation(syncEntity.getState()); + vo.setLast_update_stamp(syncEntity.getLastUpdateTime()); + voList.add(vo); + } + + int flag = serverApiService.personOperation(deviceVo.getSn(),voList); + if(flag == 0){ + //下发成功,删除状态为删除的同步人员 +// tenPersonSyncService.removeAllDeletePersons(deviceEntity.getDeviceId(),tenantId); } } } @@ -1850,4 +1968,9 @@ public class TenPersonServiceImpl implements TenPersonService { return c; } + + @Override + public List getAllExpireGuest() { + return tenPersonDao.getAllExpireGuest(); + } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java new file mode 100644 index 0000000..41e4c27 --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenPersonSyncServiceImpl.java @@ -0,0 +1,80 @@ +package net.shapelight.modules.ten.service.impl; + +import net.shapelight.modules.vo.TenPersonIdUpdateAllVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import net.shapelight.common.utils.PageUtils; +import net.shapelight.common.utils.Query; + +import net.shapelight.modules.ten.dao.TenPersonSyncDao; +import net.shapelight.modules.ten.entity.TenPersonSyncEntity; +import net.shapelight.modules.ten.service.TenPersonSyncService; + + +@Service("tenPersonSyncService") +public class TenPersonSyncServiceImpl implements TenPersonSyncService { + @Autowired + private TenPersonSyncDao tenPersonSyncDao; + + + @Override + public List getDeviceAllPersonIdUpdateTime(Long deviceId,Long tenantId) { + return tenPersonSyncDao.getDeviceAllPersonIdUpdateTime(deviceId,tenantId); + } + + @Override + public int insert(TenPersonSyncEntity tenLicenseEntity) { + return tenPersonSyncDao.insert(tenLicenseEntity); + } + + @Override + public int updateById(TenPersonSyncEntity entity) { + return tenPersonSyncDao.updateById(entity); + } + + @Override + public void removeByDeviceId(Long deviceId,Long tenantId) { + tenPersonSyncDao.removeByDeviceId(deviceId,tenantId); + } + + @Override + public void removeByPersonSyncId(Long personSyncId, Long tenantId) { + tenPersonSyncDao.removePersonSyncId(personSyncId, tenantId); + } + + @Override + public void removeAllDeletePersons(Long deviceId, Long tenantId) { + tenPersonSyncDao.removeAllDeletePersons(deviceId, tenantId); + } + + @Override + public TenPersonSyncEntity findByDeviceIdAndPersonId(Long deviceId, Long personId, Long tenantId) { + return tenPersonSyncDao.findByDeviceIdAndPersonId(deviceId, personId, tenantId); + } + + @Override + public List findByPersonId(Long personId, Long tenantId) { + return tenPersonSyncDao.findByPersonId(personId, tenantId); + } + + @Override + public List> findGroupDevicePersons(List personIds, Long tenantId) { + return tenPersonSyncDao.findGroupDevicePersons(personIds, tenantId); + } + + @Override + public List findDeviceAllDeletePersons(Long deviceId, Long tenantId) { + return tenPersonSyncDao.findDeviceAllDeletePersons(deviceId,tenantId); + } + + @Override + public List findDeviceAllAddPersons(Long deviceId, Long tenantId) { + return tenPersonSyncDao.findDeviceAllAddPersons(deviceId,tenantId); + } +} 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 a4b3d04..3caae56 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 @@ -6,8 +6,8 @@ import io.minio.PutObjectOptions; import net.shapelight.common.config.GlobalValue; import net.shapelight.common.config.MinioConfig; import net.shapelight.common.utils.*; -import net.shapelight.modules.dev.mqtt.CmdProcess; -import net.shapelight.modules.dev.mqtt.EmqHttpApi; +//import net.shapelight.modules.dev.mqtt.CmdProcess; +//import net.shapelight.modules.dev.mqtt.EmqHttpApi; import net.shapelight.modules.ten.dao.TenBuildDao; import net.shapelight.modules.ten.entity.*; import net.shapelight.modules.ten.service.*; @@ -53,8 +53,8 @@ public class TenRecordServiceImpl implements TenRecordService { private TenRoomService tenRoomService; @Autowired private TenBuildService tenBuildService; - @Autowired - private EmqHttpApi emqHttpApi; +// @Autowired +// private EmqHttpApi emqHttpApi; @Override public PageUtils queryPage(Map params) { @@ -240,13 +240,13 @@ public class TenRecordServiceImpl implements TenRecordService { } @Override - public TenRecordEntity getById(Long id, Long cellId) { - return tenRecordDao.selectById(id, cellId); + public TenRecordEntity getById(Long id, Long tenantId) { + return tenRecordDao.selectById(id, tenantId); } @Override - public String findLastRecordTime(Long personId, Long cellId) { - return tenRecordDao.findLastRecordTime(personId, cellId); + public String findLastRecordTime(Long personId, Long tenantId) { + return tenRecordDao.findLastRecordTime(personId, tenantId); } @Override @@ -303,16 +303,16 @@ public class TenRecordServiceImpl implements TenRecordService { vo.setAddress(p.getCellName()+p.getBuildName()+p.getRoomName()); } } - List webClients = emqHttpApi.getWebClients(); - if(webClients.size()>0){ - for(Long sysUserId: webClients){ - Set cellIds = tenCellService.findUserCellIdList(sysUserId); - if(cellIds.contains(entity.getCellId())){ - //发布websocket消息 - CmdProcess.publishUpRecord(sysUserId,vo); - } - } - } +// List webClients = emqHttpApi.getWebClients(); +// if(webClients.size()>0){ +// for(Long sysUserId: webClients){ +// Set cellIds = tenCellService.findUserCellIdList(sysUserId); +// if(cellIds.contains(entity.getCellId())){ +// //发布websocket消息 +// CmdProcess.publishUpRecord(sysUserId,vo); +// } +// } +// } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenUserServiceImpl.java b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenUserServiceImpl.java index 315846b..f46aac0 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenUserServiceImpl.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/ten/service/impl/TenUserServiceImpl.java @@ -149,6 +149,8 @@ public class TenUserServiceImpl extends ServiceImpl i } } sysUserService.removeById(userId); + tenUserScopeService.remove(new QueryWrapper() + .eq("user_id",user.getUserId())); } } } diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceConfig.java b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceConfig.java index f519e92..e773439 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceConfig.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenDeviceConfig.java @@ -23,18 +23,18 @@ public class TenDeviceConfig { } */ - private Integer work_mode; - private Integer recognize_interval; - private Integer relay_suck_time; - private Boolean support_liveness; - private Integer liveness_score; - private Integer recognize_score; - private Integer recognize_distance; - private Float alert_temp_threshold; - private Boolean upload_face_pic; - private Integer upload_pic_mode; - private String upload_http_url; - private Boolean support_stranger; + private Integer work_mode; //0表示门禁模式,1表示门禁+测温模式,默认为0 health_code_flag + private Integer recognize_interval; //连续两次人脸识别时间间隔,默认3s rec_space + private Integer relay_suck_time; //继电器吸合开锁持续时间,默认5s + private Boolean support_liveness; //是否支持活体检测,默认true liveness_flag + private Integer liveness_score; //活体检测超过此值则判断为活体,默认60 rgb_live_thd + private Integer recognize_score; //人脸比对分值超过此值则判断为同一个人,默认65 rec_thd + private Integer recognize_distance; //默认1m + private Float alert_temp_threshold; //人脸温度超过此值则报警,默认5s temperature_alert + private Boolean upload_face_pic; //默认true upload_image_flag + private Integer upload_pic_mode; //枚举值0表示人脸图base64编码,和人脸识别记录同时上传, 1表示人脸图通过http协议post上传 + private String upload_http_url; //人脸图通过http上传的url地址 + private Boolean support_stranger; //是否支持陌生人抓拍 默认false stranger_flag public TenDeviceConfig(){ this.work_mode = 0; diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenPersonOperationVo.java b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenPersonOperationVo.java new file mode 100644 index 0000000..e8aa08d --- /dev/null +++ b/shapelight-admin/src/main/java/net/shapelight/modules/vo/TenPersonOperationVo.java @@ -0,0 +1,26 @@ +package net.shapelight.modules.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + + +@Data +public class TenPersonOperationVo { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("人员ID") + private Long uid; + + /** + * 更新时间 + */ + @ApiModelProperty("更新时间") +// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") +// @JSONField(format="yyyy-MM-dd HH:mm:ss") + private Date last_update_stamp; + + private Integer operation; +} diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenBuildDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenBuildDao.xml index 0882a19..0bf9229 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenBuildDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenBuildDao.xml @@ -54,7 +54,7 @@ - insert into ten_build_${cellId} + insert into ten_build build_id, @@ -166,7 +166,7 @@ - update ten_build_${cellId} + update ten_build build_id = #{buildId,jdbcType=BIGINT}, @@ -225,37 +225,37 @@ - update ten_build_${cellId} set delete_flag = 1 + update ten_build set delete_flag = 1 where build_id = #{buildId,jdbcType=BIGINT} - update ten_build_${cellId} set delete_flag = 1 + update ten_build set delete_flag = 1 where cell_id = #{cellId,jdbcType=BIGINT} - delete from ten_build_${cellId} + delete from ten_build where build_id = #{buildId,jdbcType=BIGINT} @@ -265,39 +265,69 @@ diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenCarDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenCarDao.xml index 00470f2..e2f30bd 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenCarDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenCarDao.xml @@ -26,7 +26,7 @@ - insert into ten_car_${cellId} + insert into ten_car car_id, @@ -130,12 +130,12 @@ - delete from ten_car_${cellId} + delete from ten_car where car_id = #{carId,jdbcType=BIGINT} - update ten_car_${cellId} + update ten_car car_id = #{carId,jdbcType=BIGINT}, @@ -190,25 +190,41 @@ diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenCellDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenCellDao.xml index e43214e..0264ce6 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenCellDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenCellDao.xml @@ -35,29 +35,37 @@ - create table if not exists `ten_build_${cellId}` like `ten_build_0`; + create table if not exists `ten_build_${tenantId}` like `ten_build_0`; - create table if not exists `ten_room_${cellId}` like `ten_room_0`; + create table if not exists `ten_room_${tenantId}` like `ten_room_0`; - create table if not exists `ten_person_${cellId}` like `ten_person_0`; + create table if not exists `ten_person_${tenantId}` like `ten_person_0`; - create table if not exists `ten_record_${cellId}` like `ten_record_0`; + create table if not exists `ten_record_${tenantId}` like `ten_record_0`; - create table if not exists `ten_car_${cellId}` like `ten_car_0`; + create table if not exists `ten_car_${tenantId}` like `ten_car_0`; - create table if not exists `ten_pack_record_${cellId}` like `ten_pack_record_0`; + create table if not exists `ten_pack_record_${tenantId}` like `ten_pack_record_0`; + + + + create table if not exists `ten_person_extract_${tenantId}` like `ten_person_extract_0`; + + + + create table if not exists `ten_person_sync_${tenantId}` like `ten_person_sync_0`; - select * from ten_pack_record_${cellId} + select * from ten_pack_record where record_id = #{recordId} and park_id = #{parkId} + and cellId = #{cellId} diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml index a39d780..2e14692 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenPersonDao.xml @@ -99,7 +99,7 @@ - insert into ten_person_${cellId} + insert into ten_person person_id, @@ -342,7 +342,7 @@ - update ten_person_${cellId} + update ten_person person_id = #{personId,jdbcType=BIGINT}, @@ -467,26 +467,26 @@ - delete from ten_person_${cellId} + delete from ten_person where person_id = #{personId,jdbcType=BIGINT} - update ten_person_${cellId} set delete_flag = 1 + update ten_person set delete_flag = 1 where person_id = #{personId} - select * from ten_person_${cellId} + select * from ten_person where room_id = #{roomId} and delete_flag = 0 and name = #{name} and (person_type = 5000 or person_type = 5001 or person_type = 5002) - select member_id,last_update_time from ten_person_${cellId} + select member_id,last_update_time from ten_person where 1=1 and cell_id = #{cellId} @@ -670,8 +780,8 @@ - select * from ten_person_${cellId} + select * from ten_person where 1=1 and cell_id = #{cellId} @@ -702,11 +812,12 @@ + + + diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml new file mode 100644 index 0000000..e3a506f --- /dev/null +++ b/shapelight-admin/src/main/resources/mapper/ten/TenPersonSyncDao.xml @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + + + + + + insert into ten_person_sync_${tenantId} + + + person_sync_id, + + + device_id, + + + device_sn, + + + person_id, + + + state, + + + last_update_time, + + + tenant_id + + + + + #{personSyncId,jdbcType=BIGINT}, + + + #{deviceId,jdbcType=BIGINT}, + + + #{deviceSn}, + + + #{personId,jdbcType=BIGINT}, + + + #{state,jdbcType=TINYINT}, + + + #{lastUpdateTime,jdbcType=TIMESTAMP}, + + + #{tenantId,jdbcType=BIGINT}, + + + + + + + update ten_person_sync_${tenantId} + + + person_sync_id = #{personSyncId,jdbcType=BIGINT}, + + + device_id = #{deviceId,jdbcType=BIGINT}, + + + device_sn = #{deviceSn}, + + + person_id = #{personId,jdbcType=BIGINT}, + + + state = #{state,jdbcType=TINYINT}, + + + last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}, + + + tenant_id = #{tenantId,jdbcType=TIMESTAMP}, + + + where person_sync_id = #{personSyncId,jdbcType=BIGINT} + + + + + + + + delete from ten_person_sync_${tenantId} + where device_id = #{deviceId} + and state = 3 + + + + + delete from ten_person_sync_${tenantId} + where device_id = #{deviceId} + + + + delete from ten_person_sync_${tenantId} + where person_sync_id = #{personSyncId} + + + + + + + + + + + + + + + diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml index 4f9cc9c..870d976 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenRecordDao.xml @@ -21,7 +21,7 @@ - insert into ten_record_${cellId} + insert into ten_record_${tenantId} record_id, @@ -102,7 +102,7 @@ - update ten_record_${cellId} + update ten_record_${tenantId} record_id = #{recordId,jdbcType=BIGINT}, @@ -146,24 +146,40 @@ - delete from ten_record_${cellId} + delete from ten_record_${tenantId} where record_id = #{recordId,jdbcType=BIGINT} - select record_time from ten_record_${cellId} - where person_id = #{personId} order by record_time desc limit 1 + select record_time from ten_record_${tenantId} + where person_id = #{personId} + order by record_time desc limit 1 diff --git a/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml b/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml index 795a7f3..a06bd36 100644 --- a/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml +++ b/shapelight-admin/src/main/resources/mapper/ten/TenRoomDao.xml @@ -42,7 +42,7 @@ - insert into ten_room_${cellId} + insert into ten_room room_id, @@ -190,7 +190,7 @@ - update ten_room_${cellId} + update ten_room room_id = #{roomId,jdbcType=BIGINT}, @@ -266,27 +266,27 @@ - delete from ten_room_${cellId} + delete from ten_room where room_id = #{roomId,jdbcType=BIGINT} - update ten_room_${cellId} set delete_flag = 1 + update ten_room_$ set delete_flag = 1 where room_id = #{roomId,jdbcType=BIGINT} - update ten_room_${cellId} set delete_flag = 1 + update ten_room set delete_flag = 1 where build_id = #{buildId,jdbcType=BIGINT} - update ten_room_${cellId} set delete_flag = 1 + update ten_room set delete_flag = 1 where cell_id = #{cellId,jdbcType=BIGINT} @@ -295,16 +295,30 @@ diff --git a/shapelight-admin/src/test/java/gb/Cities.java b/shapelight-admin/src/test/java/gb/Cities.java new file mode 100644 index 0000000..fe14292 --- /dev/null +++ b/shapelight-admin/src/test/java/gb/Cities.java @@ -0,0 +1,7 @@ +package gb; + +public class Cities { + static final int cities [] = { + 350602, 370782, 513431, 532624, 530426, 370203, 350128, 421002, 350624, 430225, 360300, 350203, 220211, 420822, 530625, 653126, 420203, 220182, 230603, 533323, 430121, 621225, 652827, 511500, 450205, 652824, 411402, 440781, 469022, 370214, 542521, 433101, 460100, 530381, 411722, 533400, 110229, 640300, 210700, 450127, 440105, 530828, 120000, 420000, 211402, 341823, 220402, 330500, 371324, 150500, 150927, 321284, 230231, 150926, 630123, 341700, 441400, 542330, 370684, 370828, 654326, 610831, 140300, 350581, 421182, 421200, 341124, 371423, 445302, 513225, 532522, 469026, 450102, 433130, 222406, 511325, 410328, 210422, 430405, 341100, 140212, 445222, 350403, 430521, 520111, 652924, 522201, 542327, 110103, 530826, 630122, 610527, 330481, 522424, 820000, 231081, 410103, 431223, 230524, 441284, 500226, 152524, 211382, 530300, 411102, 410727, 152223, 451200, 610203, 230805, 500116, 341222, 420324, 610500, 141128, 371202, 140426, 510181, 341021, 340421, 130623, 152529, 130626, 530902, 220102, 532801, 220183, 632122, 371622, 140721, 340121, 420503, 632524, 610327, 130500, 152923, 150422, 420528, 140221, 430502, 610921, 422822, 130627, 430105, 410926, 340603, 510321, 211202, 522729, 653100, 421123, 310104, 341282, 410602, 510304, 230712, 320481, 532627, 610800, 610522, 360829, 410105, 410106, 431126, 330127, 131126, 350428, 130930, 430621, 130724, 450681, 411381, 130208, 411200, 522327, 640105, 321282, 632323, 371481, 420800, 621124, 341825, 340300, 450923, 530500, 411423, 150302, 530821, 140802, 310115, 410203, 420116, 371724, 430922, 130800, 150502, 210711, 230207, 511529, 530325, 320402, 542300, 140723, 542221, 511800, 150430, 440700, 220421, 350181, 520329, 350784, 440115, 330304, 411221, 510107, 360803, 520221, 350603, 421003, 411522, 150205, 220503, 620421, 370303, 451031, 150525, 360700, 340711, 620403, 610924, 500117, 542626, 511922, 620800, 450123, 533123, 320900, 410423, 330902, 451002, 623027, 620923, 220204, 420923, 210922, 150429, 150929, 420684, 610427, 150624, 340702, 360313, 320300, 320600, 431228, 621000, 370323, 530421, 640104, 370503, 533421, 420102, 371428, 220105, 350981, 370113, 230503, 130925, 231025, 620300, 341524, 130127, 231200, 130224, 420606, 652922, 371426, 130402, 140826, 511304, 610724, 511823, 542100, 510303, 440113, 500114, 542337, 451381, 513336, 441427, 450311, 630105, 361122, 610829, 360425, 130128, 350105, 511525, 220202, 632724, 350205, 310112, 640303, 623023, 140726, 513229, 330103, 420204, 140725, 350500, 511826, 211322, 630102, 230822, 653022, 130426, 371121, 632200, 640521, 621100, 511524, 130803, 130982, 451202, 350600, 450324, 130424, 510800, 640324, 131028, 450305, 340828, 140423, 654028, 110114, 340503, 653128, 610823, 510184, 310105, 542622, 610821, 511602, 522730, 331000, 360100, 410421, 450107, 150826, 610525, 140922, 140107, 632522, 130283, 130121, 130431, 632523, 430223, 530112, 361023, 361181, 411421, 340302, 654325, 360733, 370322, 450126, 632721, 320924, 430321, 532625, 652927, 440523, 230302, 511702, 361025, 150725, 360731, 321183, 451024, 440404, 320205, 321302, 370306, 371322, 510311, 360102, 431124, 410883, 500238, 230110, 522422, 331123, 411403, 522229, 520424, 510682, 320000, 231102, 652101, 371000, 130107, 420527, 542121, 500112, 150425, 140225, 341623, 331100, 430522, 540123, 500000, 652923, 130726, 150223, 420529, 440783, 530921, 211003, 320281, 513223, 530700, 450400, 331004, 410303, 511681, 640205, 640424, 620821, 441424, 530522, 630000, 370634, 360726, 230604, 150523, 371302, 340323, 141023, 220581, 610431, 610524, 220724, 150922, 410600, 211103, 440800, 632222, 230505, 330211, 360721, 130406, 522627, 422826, 220122, 210882, 230826, 530102, 130921, 469002, 360424, 340123, 220502, 120112, 450422, 370830, 152201, 320107, 361028, 510104, 440923, 654000, 330621, 141034, 450803, 510727, 621222, 530000, 610825, 610302, 510400, 450109, 441202, 429021, 654201, 211300, 140624, 360302, 511528, 130108, 532527, 652826, 520303, 530825, 330322, 511600, 430281, 340406, 230624, 522223, 500235, 220281, 411503, 610322, 411330, 533100, 210122, 411726, 341102, 220181, 530626, 130826, 411622, 232722, 340825, 230102, 441500, 360826, 420111, 141082, 141182, 231281, 620200, 441581, 431129, 440183, 130604, 220800, 532329, 620321, 610526, 510000, 411224, 621022, 130428, 340521, 130205, 421087, 532621, 130628, 310118, 440902, 510502, 321000, 420583, 130804, 542522, 360103, 410800, 420113, 530829, 532524, 421125, 542301, 513424, 460107, 320830, 421000, 513230, 331024, 360222, 220303, 530602, 511522, 130823, 441802, 420881, 330200, 330727, 361124, 530113, 330803, 440114, 210211, 430726, 152526, 533321, 460000, 510600, 411282, 420281, 500118, 522625, 350426, 150522, 330382, 530424, 611023, 130532, 231084, 469031, 150300, 210600, 341302, 130185, 320400, 450330, 445102, 150404, 420506, 410311, 411623, 522401, 440803, 421022, 320114, 451226, 211421, 611024, 360200, 410700, 150222, 371203, 360123, 320703, 210282, 320322, 211221, 433100, 623025, 350505, 330108, 230803, 360732, 510124, 510302, 420106, 430211, 330183, 420205, 640323, 140224, 653226, 321102, 420984, 330424, 441882, 210800, 340500, 140932, 510703, 522631, 230127, 420582, 211302, 330503, 500242, 652302, 371626, 433123, 520321, 210900, 652900, 410184, 654221, 330881, 371081, 410104, 370829, 150104, 450521, 441223, 420600, 460106, 433125, 130630, 370211, 520114, 451423, 230381, 231085, 360321, 340223, 430412, 410811, 130303, 542127, 632621, 220103, 610830, 211121, 650106, 451324, 654322, 430224, 610626, 341821, 150981, 421023, 430203, 441827, 653201, 411000, 211081, 632127, 610624, 370321, 130638, 532530, 210204, 451321, 510525, 140924, 330326, 230203, 520328, 321081, 330782, 350583, 510623, 621025, 622926, 450222, 610404, 431322, 350123, 611021, 371400, 360900, 131023, 360111, 370902, 440281, 131081, 150421, 330329, 340104, 140200, 520200, 610822, 370700, 411600, 341721, 210811, 230705, 341502, 522623, 220622, 130184, 152200, 542424, 130200, 130730, 130400, 430721, 431026, 230902, 140729, 152502, 130522, 652925, 450303, 632626, 350504, 230100, 211011, 530428, 451030, 610422, 450405, 532327, 310108, 371327, 210100, 500113, 371102, 410221, 511821, 542122, 360122, 610828, 350721, 450502, 445321, 511825, 140108, 320504, 513432, 371325, 610623, 431202, 330825, 511725, 150621, 511129, 350623, 430682, 511133, 150103, 110116, 152202, 350481, 451425, 420504, 440300, 522425, 360823, 510403, 620103, 320382, 632722, 421024, 410326, 450421, 220882, 350724, 542329, 370900, 610304, 230500, 341800, 341000, 230882, 610622, 522626, 653124, 230700, 431123, 450122, 620402, 370523, 532628, 451227, 620422, 320721, 210681, 451302, 230707, 130525, 210727, 341421, 420922, 110109, 410402, 350925, 640400, 371122, 450100, 513430, 231224, 433122, 230208, 610727, 610303, 140226, 140429, 330102, 653225, 632726, 522230, 542125, 230703, 341723, 130207, 532502, 620724, 530321, 469028, 131128, 320115, 610402, 320723, 610328, 231002, 140702, 330683, 371312, 230421, 411121, 211303, 410922, 441624, 220700, 370405, 420300, 220282, 370784, 632625, 430529, 510524, 141123, 650200, 140430, 361123, 110000, 370283, 430124, 141181, 420105, 330122, 150100, 511521, 431122, 440308, 222424, 330903, 130625, 210102, 610423, 632624, 513200, 513231, 610521, 440229, 130727, 230230, 210202, 511621, 130404, 520422, 430681, 510521, 532532, 410204, 532323, 130126, 411625, 511100, 320623, 530822, 420381, 350423, 654202, 512022, 220702, 361030, 230711, 210111, 530128, 431302, 341321, 532328, 542334, 140121, 542523, 320507, 620902, 450221, 370612, 410724, 520122, 131182, 431002, 321300, 610502, 522222, 621121, 210403, 370284, 522300, 210423, 420302, 450602, 530326, 350902, 530722, 350781, 330109, 310230, 522723, 610326, 320111, 620822, 350525, 510823, 450981, 630100, 500240, 320305, 361128, 361024, 232700, 341023, 350782, 650202, 532926, 610103, 610923, 350200, 141028, 450512, 513332, 411721, 441481, 431381, 511000, 440205, 430703, 522325, 361129, 130132, 350924, 610632, 131121, 350211, 140421, 421100, 410803, 510626, 321181, 150428, 530624, 361027, 450902, 331082, 360921, 222403, 340881, 231182, 431025, 610926, 511400, 420625, 140322, 370786, 710000, 522328, 370304, 620121, 371523, 420683, 450702, 540124, 360428, 420505, 140105, 411323, 430921, 450921, 320206, 140223, 320506, 620623, 370212, 441200, 360983, 310120, 410400, 430423, 371723, 530422, 320724, 513325, 441324, 530600, 370400, 230722, 610728, 513335, 620982, 110107, 350429, 623021, 230708, 371328, 131082, 441825, 370783, 610400, 140781, 421122, 430300, 513429, 522634, 350825, 500115, 210504, 130722, 430923, 370686, 422827, 141030, 420802, 140603, 422828, 140923, 131026, 542200, 220623, 141027, 360203, 222402, 350824, 513331, 632801, 430603, 140823, 440513, 110102, 120225, 610429, 610826, 350430, 542231, 532531, 420100, 441881, 450200, 532525, 621002, 440606, 511822, 370681, 500101, 371326, 430100, 410900, 532822, 130824, 441226, 410482, 370831, 210321, 513427, 340404, 420104, 610621, 371700, 530622, 511421, 140500, 140829, 371103, 650100, 460108, 360600, 370881, 361021, 371082, 522732, 542226, 150800, 210323, 532301, 430722, 441625, 622901, 371425, 513333, 411321, 440811, 130721, 533325, 530111, 410782, 430624, 210702, 130130, 421222, 411327, 130624, 230108, 231222, 610582, 430981, 410224, 610700, 360830, 130705, 530802, 361125, 220106, 542427, 320411, 652926, 210903, 120223, 330682, 140600, 430700, 411602, 430702, 371726, 440282, 440982, 540122, 360827, 653121, 230715, 530323, 620721, 141031, 610112, 140902, 130183, 622923, 371625, 210603, 532325, 532500, 321100, 320113, 411023, 652122, 513434, 320321, 510105, 430304, 330104, 361127, 440608, 230123, 520112, 542129, 350122, 632128, 654300, 130635, 410381, 650105, 370205, 410181, 511181, 211321, 130733, 542128, 445323, 450821, 621221, 361000, 450329, 360622, 340207, 522428, 530827, 141130, 610631, 620111, 410000, 210522, 220104, 130631, 610102, 140825, 230710, 341702, 650103, 150727, 320802, 542126, 445122, 532528, 522722, 130433, 140921, 522725, 320684, 522200, 440605, 370685, 510903, 652825, 441521, 310103, 320103, 220221, 410711, 623026, 370124, 532600, 130421, 230111, 445100, 320505, 350104, 542422, 230621, 520421, 220323, 130302, 520302, 320405, 331021, 411624, 130203, 469027, 152523, 130133, 542338, 441323, 620500, 420981, 150221, 360782, 150802, 411082, 141100, 610323, 130923, 430611, 360423, 620722, 330206, 640381, 620700, 150921, 370406, 654002, 540127, 410222, 330411, 130629, 510802, 511025, 130322, 450000, 451402, 420321, 150124, 610723, 120110, 371100, 370000, 522601, 150823, 230206, 361026, 610000, 310114, 130223, 530924, 141021, 360802, 420902, 542623, 430725, 451300, 130125, 450332, 632700, 469033, 411329, 530721, 430406, 130637, 331023, 420114, 622921, 150822, 530630, 632725, 421221, 610104, 320705, 370481, 440400, 621126, 530328, 513437, 220723, 450105, 140728, 510812, 230605, 350722, 441623, 520121, 410325, 500236, 140727, 131181, 610116, 370403, 210000, 410411, 469023, 130100, 410122, 410523, 411681, 140122, 360730, 330324, 510421, 320700, 350527, 371500, 440402, 640302, 411024, 500107, 320124, 370921, 370682, 230225, 530900, 530124, 532523, 810000, 371422, 511527, 620823, 411081, 411724, 430822, 340403, 330802, 421083, 421281, 130928, 430811, 210802, 522624, 445281, 520102, 140927, 150625, 511523, 420325, 513330, 140623, 410324, 440825, 431221, 654003, 445300, 341004, 130521, 340208, 410802, 440000, 410183, 422823, 542222, 522426, 621200, 150928, 210803, 650203, 654301, 320903, 341422, 430202, 632121, 650204, 430524, 130481, 542430, 130981, 320324, 210400, 330381, 230183, 431128, 653130, 130929, 321088, 431127, 320921, 330824, 420322, 640181, 530126, 120111, 320804, 371321, 140621, 530628, 150304, 230300, 510114, 542331, 370826, 230704, 610426, 430511, 341622, 430602, 350821, 445202, 371323, 451229, 652829, 533423, 210283, 450600, 230321, 130523, 620100, 530400, 321322, 610824, 451027, 321011, 654223, 410725, 441300, 620522, 411729, 370882, 370785, 520113, 360430, 440233, 542524, 610329, 520325, 110112, 520203, 640122, 659001, 331126, 632822, 361126, 610222, 371524, 231004, 140181, 370305, 350926, 330282, 469006, 610114, 150303, 420624, 340321, 350400, 430421, 430781, 610204, 130534, 451400, 450500, 440785, 340405, 450300, 231000, 410200, 511111, 131003, 620922, 659004, 611000, 610100, 321111, 410825, 542333, 340811, 410225, 532324, 420804, 650205, 640100, 411324, 230804, 140425, 150627, 341802, 130530, 469007, 321023, 652300, 360426, 370213, 411525, 370704, 371424, 542124, 542133, 150200, 542527, 130634, 110104, 230184, 150423, 370102, 421121, 511028, 652328, 130123, 440604, 130535, 210726, 130432, 130706, 232723, 130229, 621228, 320323, 632622, 640121, 230304, 430424, 621224, 610702, 450223, 513224, 330783, 320800, 231202, 510723, 530621, 211422, 530129, 451026, 341221, 152531, 330600, 441900, 340803, 451102, 210213, 622922, 150700, 152221, 320482, 141033, 230900, 230124, 530103, 440222, 451025, 320582, 511902, 210604, 230422, 341822, 410108, 431027, 451225, 130723, 370200, 442000, 652123, 410526, 152530, 520402, 140424, 430381, 500225, 610902, 410302, 440983, 500232, 130225, 440512, 440232, 621026, 410182, 330900, 230221, 361022, 513401, 130300, 411727, 360429, 440802, 610929, 650121, 532927, 230523, 421102, 530925, 360727, 513300, 610722, 654023, 210505, 411122, 321324, 441423, 140123, 469000, 141122, 152900, 371525, 140830, 500233, 211102, 220881, 140722, 150821, 130527, 150207, 620981, 441203, 360728, 653224, 532331, 450503, 330212, 532823, 611002, 620702, 542332, 130429, 130430, 350723, 632600, 542624, 542526, 450226, 130632, 510725, 650107, 230903, 350402, 411100, 360403, 512081, 542132, 152921, 340400, 420500, 450721, 450722, 370112, 530823, 340602, 650104, 340700, 370125, 542232, 530423, 430103, 420700, 540121, 610481, 350305, 330602, 469029, 440882, 220822, 341225, 371721, 130822, 610802, 522726, 511722, 210300, 533124, 653123, 150924, 341003, 532322, 420525, 340800, 370285, 640200, 513433, 350923, 410702, 620621, 130529, 371600, 510724, 610625, 310116, 510122, 410306, 130984, 230904, 130321, 420117, 430426, 542225, 310109, 152522, 411104, 500231, 632802, 340122, 150902, 513328, 410425, 632221, 520330, 532526, 542425, 652100, 532932, 431300, 230702, 420682, 152222, 441426, 320502, 350503, 370687, 510106, 440600, 120115, 652800, 130304, 152525, 451222, 330182, 610126, 340304, 659003, 320200, 430382, 340504, 350425, 640422, 130000, 130423, 522633, 150923, 410928, 320811, 330681, 350900, 130204, 330784, 441602, 360322, 360502, 430581, 440305, 632300, 510704, 610428, 652928, 230128, 220721, 430723, 652929, 210411, 411723, 330110, 140106, 350783, 220722, 410422, 340823, 220300, 632800, 320105, 330522, 230223, 510683, 542123, 360781, 110106, 513322, 360923, 640106, 441823, 542400, 411502, 370602, 610122, 451023, 451481, 320923, 654200, 371502, 532922, 130202, 150526, 542336, 411425, 131002, 371623, 530502, 220582, 370703, 210112, 530922, 653122, 654021, 654022, 500109, 330303, 320585, 450403, 150723, 411728, 341125, 441700, 420581, 420626, 532623, 411500, 620924, 210224, 623022, 421224, 513221, 321323, 632123, 430821, 340621, 371522, 511102, 440306, 500111, 450881, 140900, 611025, 632525, 440511, 622924, 140400, 411103, 141081, 421181, 510811, 441303, 230306, 371402, 230303, 440224, 320826, 410923, 431081, 360724, 411002, 410102, 630104, 522622, 211282, 152528, 654024, 510108, 532326, 429006, 150125, 530181, 211481, 510182, 610528, 650109, 210781, 330300, 370404, 230716, 340822, 220100, 211005, 421126, 350100, 411481, 350524, 542627, 469021, 152224, 320621, 330502, 410527, 420112, 430481, 513323, 652200, 130636, 230407, 130582, 140321, 620600, 360800, 420921, 140100, 411422, 340802, 220284, 350921, 341024, 469003, 410726, 110117, 230307, 510921, 341522, 510132, 440903, 420526, 150900, 130633, 230281, 654025, 231024, 522224, 620400, 510411, 542335, 320211, 410500, 610730, 510300, 510681, 410223, 620104, 150400, 530402, 340000, 141125, 341402, 542421, 350700, 150782, 654321, 420222, 420821, 500241, 410505, 513329, 222400, 522632, 360725, 371200, 310117, 140800, 320503, 371728, 320381, 331122, 230600, 321182, 450302, 360926, 621021, 231005, 141002, 513428, 422801, 220521, 341503, 130903, 621024, 210113, 320202, 640202, 110113, 654027, 650000, 421124, 320304, 340102, 350303, 360602, 140929, 340311, 520327, 421202, 533122, 621102, 620000, 623001, 420107, 610726, 440106, 440100, 451000, 431028, 430400, 610430, 653125, 530723, 653200, 141121, 230200, 532925, 542233, 131100, 410581, 530322, 130926, 320682, 141102, 130181, 130621, 320611, 130983, 131025, 230781, 371482, 533324, 512000, 210503, 430221, 650201, 520181, 441781, 230400, 410404, 371526, 321202, 152527, 371521, 341181, 330921, 340604, 370923, 410704, 510522, 620824, 120105, 510900, 140622, 621023, 130227, 513334, 340200, 370302, 230125, 130182, 540125, 422825, 431230, 441302, 410822, 220681, 130324, 620826, 210181, 511781, 522728, 650102, 522600, 321112, 411281, 150602, 210203, 320829, 330726, 411725, 411523, 130703, 530425, 430122, 411527, 652722, 410728, 440804, 500106, 440900, 513233, 211404, 540000, 370725, 130425, 231121, 500103, 510781, 350111, 130683, 341400, 431022, 441702, 420103, 510504, 211122, 321084, 522727, 610324, 431003, 150206, 450922, 431102, 450224, 360922, 469005, 341521, 429004, 510700, 150783, 410211, 231100, 130524, 130528, 522225, 350213, 230713, 640221, 512002, 511402, 150724, 451224, 141022, 522226, 361100, 370521, 450423, 530324, 360824, 360500, 420702, 130732, 140928, 131022, 451228, 330402, 341203, 350625, 341002, 654225, 410403, 510821, 130827, 522629, 630103, 411325, 370832, 360734, 340111, 542600, 320584, 542328, 500102, 430407, 371727, 410506, 520323, 430302, 450481, 653127, 230714, 140222, 610725, 433126, 150600, 330100, 222404, 141026, 110101, 469030, 350103, 360681, 522322, 510129, 341200, 220322, 441225, 522630, 610827, 640423, 542223, 211004, 131127, 210281, 140428, 341722, 341103, 632821, 500243, 469001, 231123, 360481, 430500, 640522, 440184, 110111, 361002, 653131, 340703, 360729, 370983, 431121, 511123, 320100, 211223, 141025, 522423, 130434, 441422, 532928, 210402, 410781, 513400, 150825, 610331, 441821, 441502, 360825, 440500, 331003, 371624, 370126, 130922, 140211, 350702, 542228, 652901, 410304, 652723, 440104, 150121, 360521, 430104, 450321, 610424, 522702, 320412, 411303, 450124, 510322, 654226, 440103, 451323, 520123, 340303, 520322, 140881, 429005, 411700, 140581, 451021, 620523, 530926, 140981, 451028, 360202, 370300, 411025, 140602, 140524, 150781, 230706, 500237, 610900, 130581, 653101, 320925, 331102, 360881, 542429, 610928, 330203, 450700, 652700, 450802, 210602, 211381, 220602, 451424, 330483, 430528, 441402, 511622, 430111, 420602, 220400, 231221, 360281, 441800, 510402, 130700, 430800, 530627, 652327, 621227, 210421, 330723, 610425, 431224, 120103, 522636, 450804, 230202, 511126, 220422, 150626, 220802, 230305, 441224, 430408, 231083, 371427, 350822, 610628, 500200, 350212, 350000, 210304, 130825, 430626, 231003, 371311, 140110, 230227, 410927, 450621, 230229, 430802, 411626, 440307, 361029, 210804, 621122, 320203, 410603, 130900, 130681, 320583, 411426, 140822, 220605, 320982, 370100, 321003, 441322, 211281, 652223, 371621, 341600, 511300, 610630, 371083, 350124, 230204, 320102, 350521, 542525, 654224, 360735, 450103, 511425, 210911, 513426, 510100, 211403, 150424, 120114, 510121, 532800, 450326, 140522, 210624, 150721, 431100, 330800, 510115, 150123, 450703, 445224, 330105, 330328, 141029, 230406, 350725, 320922, 150403, 360925, 230623, 513326, 513338, 340824, 513232, 430600, 341423, 341424, 150521, 370282, 441283, 320282, 370827, 341324, 420900, 361102, 511424, 330000, 350626, 370281, 511721, 530121, 340203, 321200, 210124, 360121, 532622, 411322, 653024, 140521, 341202, 441600, 522326, 530125, 330226, 511422, 520425, 140427, 210404, 420303, 632521, 150581, 500108, 533300, 230205, 140824, 640402, 511302, 211224, 450924, 451123, 610922, 620524, 530824, 430482, 542426, 422800, 141126, 350622, 320404, 433124, 210104, 430527, 230521, 371300, 231124, 350182, 120221, 431321, 321203, 330283, 440112, 430204, 410202, 430724, 331181, 130927, 542621, 232721, 130924, 130129, 152500, 520100, 341323, 131000, 330523, 331125, 542625, 511024, 513327, 610925, 410300, 220600, 450203, 441721, 431200, 530523, 350982, 411702, 441622, 653000, 370781, 421300, 610581, 522700, 440304, 341122, 410503, 110228, 230800, 640502, 220524, 150785, 511323, 511423, 371581, 320116, 320681, 222405, 341525, 542428, 440116, 430503, 510922, 632100, 130725, 360981, 320104, 450108, 310106, 130728, 330624, 420323, 511923, 522635, 520326, 330400, 340502, 532300, 433127, 421381, 511303, 130702, 500222, 610927, 231223, 130403, 141024, 640000, 431225, 430422, 141129, 630121, 350628, 513436, 620122, 341824, 511124, 460105, 431281, 511322, 530927, 530427, 431024, 653223, 131124, 231283, 640425, 451223, 110108, 140000, 513222, 632321, 340827, 140926, 130435, 320125, 611026, 621123, 220621, 231225, 130427, 230828, 150524, 610111, 610403, 500234, 140525, 520103, 410882, 110115, 540100, 530800, 511526, 230104, 210682, 360821, 410185, 370982, 330482, 361121, 451221, 350424, 340402, 610202, 131122, 211100, 321281, 510503, 370522, 623024, 421081, 210782, 431103, 653023, 130821, 532930, 652823, 510722, 620725, 632224, 410323, 141127, 222426, 469032, 440981, 120113, 513226, 511011, 230709, 320902, 370500, 360124, 532900, 350322, 340202, 532501, 231282, 640500, 341204, 350526, 140930, 411400, 420607, 440784, 520381, 530629, 220500, 542325, 659000, 211400, 440203, 542322, 321002, 411627, 230502, 350800, 620302, 130828, 451121, 411628, 652325, 431226, 520400, 510112, 610721, 150925, 210521, 450603, 140109, 331002, 450800, 522400, 621223, 220000, 340322, 370105, 130729, 210114, 350206, 533422, 371722, 511381, 511724, 542423, 341621, 542229, 230403, 330204, 620825, 350302, 211002, 152501, 320303, 230109, 370800, 340721, 431000, 150702, 211324, 522323, 130682, 419001, 360000, 450331, 140724, 530524, 130684, 360828, 532626, 130533, 140481, 220200, 230833, 522731, 530127, 360402, 441826, 411521, 222401, 140827, 540126, 330521, 532929, 500119, 610602, 340221, 330185, 360421, 610729, 211021, 130531, 411202, 150000, 445121, 410327, 230382, 610330, 510904, 341523, 611022, 620105, 130731, 411528, 150426, 513337, 445221, 350427, 230000, 310101, 410305, 511132, 420703, 360723, 513324, 210502, 360105, 451122, 341226, 500223, 430525, 130230, 330822, 620503, 451281, 220203, 320803, 370502, 610627, 510603, 511502, 610124, 654026, 621226, 321283, 632623, 652222, 131125, 411621, 410322, 440507, 430623, 652301, 513435, 652201, 450900, 420502, 370181, 370705, 371329, 360104, 140931, 410100, 341602, 330702, 410502, 150105, 150623, 451322, 230129, 445200, 510500, 441523, 410821, 211000, 532931, 140821, 450328, 331022, 542323, 140227, 532901, 610113, 512021, 420704, 220821, 140431, 440883, 130526, 610115, 340103, 532923, 410329, 410522, 350823, 430102, 120104, 652801, 620423, 522228, 130600, 654323, 210881, 310000, 620521, 331124, 210200, 130131, 330703, 511112, 622925, 431382, 513321, 632324, 220382, 360400, 320706, 632322, 341022, 610600, 150722, 620622, 360924, 532529, 510726, 431227, 500110, 510113, 320831, 511900, 510923, 371421, 530923, 140828, 430902, 652828, 451421, 450225, 210381, 210905, 620123, 420200, 360427, 431222, 500229, 511321, 520324, 131123, 360902, 440204, 542224, 230405, 141124, 410611, 430903, 210921, 653001, 622900, 440607, 511827, 341322, 350681, 410721, 510824, 530521, 150622, 620900, 370683, 652323, 230606, 450325, 421127, 659002, 530623, 370811, 411424, 410823, 220302, 430523, 511802, 511921, 430200, 231226, 620802, 350582, 445381, 511700, 511623, 230103, 513422, 141000, 411526, 610523, 370613, 210904, 450322, 210703, 632723, 331127, 150726, 350629, 620525, 371725, 530100, 230602, 520382, 510822, 511824, 130281, 430900, 341500, 150784, 310110, 210123, 371602, 542227, 411300, 440515, 220381, 361130, 410902, 520201, 451422, 130603, 500105, 500230, 440703, 230182, 440303, 330421, 450304, 522324, 441723, 653221, 350802, 431229, 220112, 370600, 230921, 210500, 450327, 469025, 341300, 411302, 632823, 513227, 440823, 511723, 653129, 410621, 430000, 620602, 350922, 513423, 131102, 632126, 140925, 410703, 440705, 411328, 130622, 621125, 341182, 410804, 120106, 500104, 520423, 653222, 430181, 445322, 450204, 350502, 230224, 620921, 370202, 370883, 330700, 410205, 320981, 350300, 370724, 320311, 450404, 130124, 150203, 140700, 331121, 530724, 622927, 542324, 230126, 511113, 620502, 653227, 140303, 230622, 360323, 610125, 230881, 610629, 350627, 510183, 150122, 210103, 341881, 371702, 340222, 360702, 230522, 520222, 330225, 520000, 320581, 530122, 140882, 511324, 371002, 370611, 440514, 513425, 620723, 533103, 441621, 411326, 522227, 500224, 141032, 331081, 320722, 360982, 220283, 130323, 231181, 421223, 522628, 450125, 350421, 370911, 350125, 440403, 652324, 469024, 411222, 533102, 422802, 210212, 510422, 150402, 152922, 431023, 522427, 610300, 340826, 360722, 370104, 530302, 654324, 330281, 421303, 623000, 632500, 210311, 460200, 441421, 500227, 150824, 510131, 410481, 310113, 321311, 150202, 131024, 340600, 652701, 420982, 431125, 652822, 370702, 330302, 330327, 431021, 330922, 522301, 532924, 211200, 350881, 542326, 360822, 620102, 542500, 621202, 621027, 450323, 440200, 420202, 500228, 520300, 340100, 220523, 440704, 320500, 320204, 210105, 330781, 451022, 451029, 632223, 513228, 411524, 341126, 451100, 530702, 440881, 410622, 350121, 420115, 610200, 350304, 320602, 522701 + }; +} diff --git a/shapelight-admin/src/test/java/gb/ImageTest.java b/shapelight-admin/src/test/java/gb/ImageTest.java new file mode 100644 index 0000000..0a8537d --- /dev/null +++ b/shapelight-admin/src/test/java/gb/ImageTest.java @@ -0,0 +1,42 @@ +package gb; + +import net.coobird.thumbnailator.Thumbnails; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; + +public class ImageTest { + + public static void main(String args[]){ + try { + File picture = new File("d:\\temp\\101.png"); + BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture)); + int w = sourceImg.getWidth(); + int h = sourceImg.getHeight(); + if (w > 1080 || h > 1080) { + Thumbnails.of("d:\\temp\\101.png") + .size(1080, 1080) + .toFile("d:\\temp\\33.png"); + + } + }catch (Exception e){ + } + + + try { + File picture = new File("d:\\temp\\11.jpg"); + BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture)); + int w = sourceImg.getWidth(); + int h = sourceImg.getHeight(); + if (w > 1080 || h > 1080) { + Thumbnails.of("d:\\temp\\11.jpg") + .size(1080, 1080) + .toFile("d:\\temp\\11.jpg"); + } + }catch (Exception e){ + } + + } +} diff --git a/shapelight-admin/src/test/java/gb/RandomValue.java b/shapelight-admin/src/test/java/gb/RandomValue.java new file mode 100644 index 0000000..6e8fad4 --- /dev/null +++ b/shapelight-admin/src/test/java/gb/RandomValue.java @@ -0,0 +1,186 @@ +package gb; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** + * 随机生成中文姓名,性别,Email,手机号,住址 + * @author X-rapido + */ +public class RandomValue { + public static String base = "abcdefghijklmnopqrstuvwxyz0123456789"; + private static String firstName="赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚阎法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福百家姓续"; + private static String girl="秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽 "; + private static String boy="伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘"; + private static String[] road="重庆大厦,黑龙江路,十梅庵街,遵义路,湘潭街,瑞金广场,仙山街,仙山东路,仙山西大厦,白沙河路,赵红广场,机场路,民航街,长城南路,流亭立交桥,虹桥广场,长城大厦,礼阳路,风岗街,中川路,白塔广场,兴阳路,文阳街,绣城路,河城大厦,锦城广场,崇阳街,华城路,康城街,正阳路,和阳广场,中城路,江城大厦,顺城路,安城街,山城广场,春城街,国城路,泰城街,德阳路,明阳大厦,春阳路,艳阳街,秋阳路,硕阳街,青威高速,瑞阳街,丰海路,双元大厦,惜福镇街道,夏庄街道,古庙工业园,中山街,太平路,广西街,潍县广场,博山大厦,湖南路,济宁街,芝罘路,易州广场,荷泽四路,荷泽二街,荷泽一路,荷泽三大厦,观海二广场,广西支街,观海一路,济宁支街,莒县路,平度广场,明水路,蒙阴大厦,青岛路,湖北街,江宁广场,郯城街,天津路,保定街,安徽路,河北大厦,黄岛路,北京街,莘县路,济南街,宁阳广场,日照街,德县路,新泰大厦,荷泽路,山西广场,沂水路,肥城街,兰山路,四方街,平原广场,泗水大厦,浙江路,曲阜街,寿康路,河南广场,泰安路,大沽街,红山峡支路,西陵峡一大厦,台西纬一广场,台西纬四街,台西纬二路,西陵峡二街,西陵峡三路,台西纬三广场,台西纬五路,明月峡大厦,青铜峡路,台西二街,观音峡广场,瞿塘峡街,团岛二路,团岛一街,台西三路,台西一大厦,郓城南路,团岛三街,刘家峡路,西藏二街,西藏一广场,台西四街,三门峡路,城武支大厦,红山峡路,郓城北广场,龙羊峡路,西陵峡街,台西五路,团岛四街,石村广场,巫峡大厦,四川路,寿张街,嘉祥路,南村广场,范县路,西康街,云南路,巨野大厦,西江广场,鱼台街,单县路,定陶街,滕县路,钜野广场,观城路,汶上大厦,朝城路,滋阳街,邹县广场,濮县街,磁山路,汶水街,西藏路,城武大厦,团岛路,南阳街,广州路,东平街,枣庄广场,贵州街,费县路,南海大厦,登州路,文登广场,信号山支路,延安一街,信号山路,兴安支街,福山支广场,红岛支大厦,莱芜二路,吴县一街,金口三路,金口一广场,伏龙山路,鱼山支街,观象二路,吴县二大厦,莱芜一广场,金口二街,海阳路,龙口街,恒山路,鱼山广场,掖县路,福山大厦,红岛路,常州街,大学广场,龙华街,齐河路,莱阳街,黄县路,张店大厦,祚山路,苏州街,华山路,伏龙街,江苏广场,龙江街,王村路,琴屿大厦,齐东路,京山广场,龙山路,牟平街,延安三路,延吉街,南京广场,东海东大厦,银川西路,海口街,山东路,绍兴广场,芝泉路,东海中街,宁夏路,香港西大厦,隆德广场,扬州街,郧阳路,太平角一街,宁国二支路,太平角二广场,天台东一路,太平角三大厦,漳州路一路,漳州街二街,宁国一支广场,太平角六街,太平角四路,天台东二街,太平角五路,宁国三大厦,澳门三路,江西支街,澳门二路,宁国四街,大尧一广场,咸阳支街,洪泽湖路,吴兴二大厦,澄海三路,天台一广场,新湛二路,三明北街,新湛支路,湛山五街,泰州三广场,湛山四大厦,闽江三路,澳门四街,南海支路,吴兴三广场,三明南路,湛山二街,二轻新村镇,江南大厦,吴兴一广场,珠海二街,嘉峪关路,高邮湖街,湛山三路,澳门六广场,泰州二路,东海一大厦,天台二路,微山湖街,洞庭湖广场,珠海支街,福州南路,澄海二街,泰州四路,香港中大厦,澳门五路,新湛三街,澳门一路,正阳关街,宁武关广场,闽江四街,新湛一路,宁国一大厦,王家麦岛,澳门七广场,泰州一路,泰州六街,大尧二路,青大一街,闽江二广场,闽江一大厦,屏东支路,湛山一街,东海西路,徐家麦岛函谷关广场,大尧三路,晓望支街,秀湛二路,逍遥三大厦,澳门九广场,泰州五街,澄海一路,澳门八街,福州北路,珠海一广场,宁国二路,临淮关大厦,燕儿岛路,紫荆关街,武胜关广场,逍遥一街,秀湛四路,居庸关街,山海关路,鄱阳湖大厦,新湛路,漳州街,仙游路,花莲街,乐清广场,巢湖街,台南路,吴兴大厦,新田路,福清广场,澄海路,莆田街,海游路,镇江街,石岛广场,宜兴大厦,三明路,仰口街,沛县路,漳浦广场,大麦岛,台湾街,天台路,金湖大厦,高雄广场,海江街,岳阳路,善化街,荣成路,澳门广场,武昌路,闽江大厦,台北路,龙岩街,咸阳广场,宁德街,龙泉路,丽水街,海川路,彰化大厦,金田路,泰州街,太湖路,江西街,泰兴广场,青大街,金门路,南通大厦,旌德路,汇泉广场,宁国路,泉州街,如东路,奉化街,鹊山广场,莲岛大厦,华严路,嘉义街,古田路,南平广场,秀湛路,长汀街,湛山路,徐州大厦,丰县广场,汕头街,新竹路,黄海街,安庆路,基隆广场,韶关路,云霄大厦,新安路,仙居街,屏东广场,晓望街,海门路,珠海街,上杭路,永嘉大厦,漳平路,盐城街,新浦路,新昌街,高田广场,市场三街,金乡东路,市场二大厦,上海支路,李村支广场,惠民南路,市场纬街,长安南路,陵县支街,冠县支广场,小港一大厦,市场一路,小港二街,清平路,广东广场,新疆路,博平街,港通路,小港沿,福建广场,高唐街,茌平路,港青街,高密路,阳谷广场,平阴路,夏津大厦,邱县路,渤海街,恩县广场,旅顺街,堂邑路,李村街,即墨路,港华大厦,港环路,馆陶街,普集路,朝阳街,甘肃广场,港夏街,港联路,陵县大厦,上海路,宝山广场,武定路,长清街,长安路,惠民街,武城广场,聊城大厦,海泊路,沧口街,宁波路,胶州广场,莱州路,招远街,冠县路,六码头,金乡广场,禹城街,临清路,东阿街,吴淞路,大港沿,辽宁路,棣纬二大厦,大港纬一路,贮水山支街,无棣纬一广场,大港纬三街,大港纬五路,大港纬四街,大港纬二路,无棣二大厦,吉林支路,大港四街,普集支路,无棣三街,黄台支广场,大港三街,无棣一路,贮水山大厦,泰山支路,大港一广场,无棣四路,大连支街,大港二路,锦州支街,德平广场,高苑大厦,长山路,乐陵街,临邑路,嫩江广场,合江路,大连街,博兴路,蒲台大厦,黄台广场,城阳街,临淄路,安邱街,临朐路,青城广场,商河路,热河大厦,济阳路,承德街,淄川广场,辽北街,阳信路,益都街,松江路,流亭大厦,吉林路,恒台街,包头路,无棣街,铁山广场,锦州街,桓台路,兴安大厦,邹平路,胶东广场,章丘路,丹东街,华阳路,青海街,泰山广场,周村大厦,四平路,台东西七街,台东东二路,台东东七广场,台东西二路,东五街,云门二路,芙蓉山村,延安二广场,云门一街,台东四路,台东一街,台东二路,杭州支广场,内蒙古路,台东七大厦,台东六路,广饶支街,台东八广场,台东三街,四平支路,郭口东街,青海支路,沈阳支大厦,菜市二路,菜市一街,北仲三路,瑞云街,滨县广场,庆祥街,万寿路,大成大厦,芙蓉路,历城广场,大名路,昌平街,平定路,长兴街,浦口广场,诸城大厦,和兴路,德盛街,宁海路,威海广场,东山路,清和街,姜沟路,雒口大厦,松山广场,长春街,昆明路,顺兴街,利津路,阳明广场,人和路,郭口大厦,营口路,昌邑街,孟庄广场,丰盛街,埕口路,丹阳街,汉口路,洮南大厦,桑梓路,沾化街,山口路,沈阳街,南口广场,振兴街,通化路,福寺大厦,峄县路,寿光广场,曹县路,昌乐街,道口路,南九水街,台湛广场,东光大厦,驼峰路,太平山,标山路,云溪广场,太清路".split(","); + private static final String[] email_suffix="@gmail.com,@yahoo.com,@msn.com,@hotmail.com,@aol.com,@ask.com,@live.com,@qq.com,@0355.net,@163.com,@163.net,@263.net,@3721.net,@yeah.net,@googlemail.com,@126.com,@sina.com,@sohu.com,@yahoo.com.cn".split(","); + + + + + public static int getNum(int start,int end) { + return (int)(Math.random()*(end-start+1)+start); + } + + /** + * 返回Email + * @param lMin 最小长度 + * @param lMax 最大长度 + * @return + */ + public static String getEmail(int lMin,int lMax) { + int length=getNum(lMin,lMax); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + int number = (int)(Math.random()*base.length()); + sb.append(base.charAt(number)); + } + sb.append(email_suffix[(int)(Math.random()*email_suffix.length)]); + return sb.toString(); + } + + /** + * 返回手机号码 + */ + private static String[] telFirst="134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(","); + public static String getTel() { + int index=getNum(0,telFirst.length-1); + String first=telFirst[index]; + String second=String.valueOf(getNum(1,888)+10000).substring(1); + String third=String.valueOf(getNum(1,9100)+10000).substring(1); + return first+second+third; + } + + /** + * 返回中文姓名 + */ + private static String name_sex = ""; + public static String getChineseName() { + int index=getNum(0, firstName.length()-1); + String first=firstName.substring(index, index+1); + int sex=getNum(0,1); + String str=boy; + int length=boy.length(); + if(sex==0){ + str=girl; + length=girl.length(); + name_sex = "女"; + }else { + name_sex="男"; + } + index=getNum(0,length-1); + String second=str.substring(index, index+1); + int hasThird=getNum(0,1); + String third=""; + if(hasThird==1){ + index=getNum(0,length-1); + third=str.substring(index, index+1); + } + return first+second+third; + } + + /** + * 返回地址 + * @return + */ + private static String getRoad() { + int index=getNum(0,road.length-1); + String first=road[index]; + String second=String.valueOf(getNum(11,150))+"号"; + String third="-"+getNum(1,20)+"-"+getNum(1,10); + return first+second+third; + } + + /** + * 数据封装 + * @return + */ + public static Map getAddress() { + Map map=new HashMap(); + map.put("name", getChineseName()); + map.put("sex", name_sex); + map.put("road", getRoad()); + map.put("tel", getTel()); + map.put("email", getEmail(6,9)); + return map; + } + + + public static String getIdNo(boolean male){ + //随机生成生日 1~99岁 + long begin = System.currentTimeMillis() - 3153600000000L;//100年内 + long end = System.currentTimeMillis() - 31536000000L; //1年内 + long rtn = begin + (long) (Math.random() * (end - begin)); + Date date = new Date(rtn); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); + String birth = simpleDateFormat.format(date); + return getIdNo(birth,male); + } + public static String getIdNo(String birth,boolean male){ + StringBuilder sb = new StringBuilder(); + Random random = new Random(); + int value = random.nextInt(Cities.cities.length); + sb.append(Cities.cities[value]); + sb.append(birth); + value = random.nextInt(999) + 1; + if(male && value % 2 == 0){ + value++; + } + if(!male && value % 2 == 1){ + value++; + } + if(value >= 100){ + sb.append(value); + }else if(value >= 10){ + sb.append('0').append(value); + }else{ + sb.append("00").append(value); + } + sb.append(calcTrailingNumber(sb)); + return sb.toString(); + } + private static final int[] calcC = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }; + private static final char[] calcR = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' }; + /* + *

18位身份证验证

+ * 根据〖中华人民共和国国家标准 GB 11643-1999〗中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本体码和一位数字校验码组成。 + * 排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。 + * 第十八位数字(校验码)的计算方法为: + * 1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 + * 2.将这17位数字和系数相乘的结果相加。 + * 3.用加出来和除以11,看余数是多少? + * 4.余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2。 + * 5.通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。 + */ + private static char calcTrailingNumber(StringBuilder sb) { + int[] n = new int[17]; + int result = 0; + for (int i = 0; i < n.length; i++) { + n[i] = Integer.parseInt(String.valueOf(sb.charAt(i))); + } + for (int i = 0; i < n.length; i++) { + result += calcC[i] * n[i]; + } + return calcR[result % 11]; + } + public static void main(String[] args) { + long a = System.currentTimeMillis(); + System.out.println(getIdNo("19790306",true)); + System.out.println(getIdNo("20100112",false)); + System.out.println(getIdNo(true)); + System.out.println(getIdNo(false)); + a = System.currentTimeMillis() - a; + System.out.println(a); + } + +// public static void main(String[] args) { +// for (int i = 0; i < 100; i++) { +// System.out.println(getAddress()); +// } +// } + + + +} diff --git a/shapelight-admin/src/test/java/net/MyTest.java b/shapelight-admin/src/test/java/net/MyTest.java new file mode 100644 index 0000000..e9f1ee6 --- /dev/null +++ b/shapelight-admin/src/test/java/net/MyTest.java @@ -0,0 +1,167 @@ +package net; + +import gb.RandomValue; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +public class MyTest { + + /** + * 修改文件名 + * + * @param oldFilePath 原文件路径 + * @param newFileName 新文件名称 + * @param overriding 判断标志(如果存在相同名的文件是否覆盖) + * @return + */ + public static boolean renameFile(String oldFilePath, String newFileName, boolean overriding) { + File oldfile = new File(oldFilePath); + if (!oldfile.exists()) { + return false; + } + String newFilepath = oldfile.getParent() + File.separator + newFileName; + File newFile = new File(newFilepath); + if (!newFile.exists()) { + return oldfile.renameTo(newFile); + } else { + if (overriding) { + newFile.delete(); + return oldfile.renameTo(newFile); + } else { + return false; + } + } + } + + public static boolean renameFile(File oldFile, String newFileName, boolean overriding) { + String newFilepath = oldFile.getParent() + File.separator + newFileName; + File newFile = new File(newFilepath); + if (!newFile.exists()) { + return oldFile.renameTo(newFile); + } else { + if (overriding) { + newFile.delete(); + return oldFile.renameTo(newFile); + } else { + return false; + } + } + } + + public static void main(String args[]) { + + //----------------------------- 重命名文件开始 --------------------------------------// +// String baseDir = "D:\\facestore\\cface\\f10_2000"; +// File faceDir = new File(baseDir); +// File[] iamges = faceDir.listFiles(); +// for(File file: iamges){ +// String id = RandomValue.getIdNo(true); +// renameFile(file,id+".jpg",true); +// } + //----------------------------- 重命名文件结束 --------------------------------------// + + + + + + //----------------------------- 随机生成姓名,性别,手机号 --------------------------------------// + +// String baseDir = "D:\\facestore\\cface\\f10_2000"; +// String idFile = "D:\\facestore\\cface\\f1_100\\id.txt"; + + String baseDir = "D:\\facestore\\2020博士统考照片"; + + String idFile = baseDir+"\\id.txt"; + File faceDir = new File(baseDir); + File[] iamges = faceDir.listFiles(); + File outFile = new File(idFile); + if (!outFile.exists()) { + try { + outFile.createNewFile(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + StringBuffer idBuffer = new StringBuffer(); + for (File file : iamges) { + String fileName = file.getName(); + String id = fileName.substring(0, fileName.lastIndexOf(".")); + + //1.姓名 + idBuffer.append(RandomValue.getChineseName()+"\t"); + //2.性别 + String sex=Math.random()>0.5?"男":"女"; + idBuffer.append(sex+"\t"); + //3.手机号 + idBuffer.append(RandomValue.getTel()+"\t"); + //4.身份证号 + idBuffer.append(id); + idBuffer.append("\r\n"); + System.out.println(idBuffer.toString()); + } + + + FileWriter outWriter = null; + try { + outWriter = new FileWriter(idFile, true); + outWriter.write(idBuffer.toString()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + outWriter.flush(); + outWriter.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } +//----------------------------- 随机生成姓名,性别,手机号 结束 --------------------------------------// + + +// String n = String.format("%02d%s",Integer.parseInt("4"),"1002室"); +// System.out.println(n); + + +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); +// Calendar cal = Calendar.getInstance(); +// //设置一个星期的第一天,按中国的习惯一个星期的第一天是星期一 +// cal.setFirstDayOfWeek(Calendar.MONDAY); +// //获得当前日期是一个星期的第几天 +// int dayWeek = cal.get(Calendar.DAY_OF_WEEK); +// if(dayWeek==1){ +// dayWeek = 8; +// } +// +// // 根据日历的规则,给当前日期减去星期几与一个星期第一天的差值 +// cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - dayWeek); +// Date mondayDate = cal.getTime(); +// String weekBegin = sdf.format(mondayDate); +// System.out.println("所在周星期一的日期:" + weekBegin); +// +// +// cal.add(Calendar.DATE, 4 +cal.getFirstDayOfWeek()); +// Date sundayDate = cal.getTime(); +// String weekEnd = sdf.format(sundayDate); +// System.out.println("所在周星期日的日期:" + weekEnd); +// +// +// +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(new Date()); +// calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); +// System.out.println("所在周星期日的日期:" + sdf.format(calendar.getTime())); +// +// +// Calendar calendar2 = Calendar.getInstance(); +// calendar2.setTime(new Date()); +// calendar2.set(Calendar.DAY_OF_MONTH, calendar2.getActualMaximum(Calendar.DAY_OF_MONTH)); +// System.out.println("所在周星期日的日期:" + sdf.format(calendar2.getTime())); + + } +} diff --git a/shapelight-admin/src/test/java/net/ProcessImages.java b/shapelight-admin/src/test/java/net/ProcessImages.java new file mode 100644 index 0000000..73b9922 --- /dev/null +++ b/shapelight-admin/src/test/java/net/ProcessImages.java @@ -0,0 +1,34 @@ +package net; + +import net.shapelight.modules.ten.entity.TenRecordEntity; +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProcessImages { + + @Test + public void test() { +// String baseDir = "D:\\facestore\\site\\member_org"; + String baseDir = "D:\\facestore\\test"; + + File faceDir = new File(baseDir); + File[] iamges = faceDir.listFiles(); + for(File file: iamges){ + String fileName = file.getName(); + String id = fileName.substring(fileName.lastIndexOf("\\"),fileName.lastIndexOf(".")); + } + + } +} diff --git a/shapelight-admin/src/test/java/net/shapelight/BasicTest.java b/shapelight-admin/src/test/java/net/shapelight/BasicTest.java new file mode 100644 index 0000000..8f2b014 --- /dev/null +++ b/shapelight-admin/src/test/java/net/shapelight/BasicTest.java @@ -0,0 +1,68 @@ +package net.shapelight; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; + +public class BasicTest { + + public static void main(String args[]) { + + String host = "192.168.1.111"; + int port = 8081; + String URI = "/api/v4/clients"; + + // 创建HttpClientBuilder + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + // 设置BasicAuth + CredentialsProvider provider = new BasicCredentialsProvider(); + // Create the authentication scope + AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); + // Create credential pair,在此处填写用户名和密码 + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("11f6a78ee6922", "MjkzODM4Mzc2NTMyNjIzOTg3NTI5MDMwMzU3NjMwOTc2MDA"); + // Inject the credentials + provider.setCredentials(scope, credentials); + // Set the default credentials provider + httpClientBuilder.setDefaultCredentialsProvider(provider); + // HttpClient + CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); + + String result = ""; + HttpGet httpGet = null; + HttpResponse httpResponse = null; + HttpEntity entity = null; + httpGet = new HttpGet("http://"+host+":"+port+URI); + try { + httpResponse = closeableHttpClient.execute(httpGet); + entity = httpResponse.getEntity(); + if( entity != null ){ + result = EntityUtils.toString(entity); + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + // 关闭连接 + try { + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + // + System.out.println(result); + + } +} diff --git a/shapelight-admin/src/test/java/net/shapelight/RedisTest.java b/shapelight-admin/src/test/java/net/shapelight/RedisTest.java new file mode 100644 index 0000000..a8a45f8 --- /dev/null +++ b/shapelight-admin/src/test/java/net/shapelight/RedisTest.java @@ -0,0 +1,30 @@ +package net.shapelight; + +import net.shapelight.common.utils.RedisUtils; +import net.shapelight.modules.sys.entity.SysUserEntity; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class RedisTest { + @Autowired + private RedisUtils redisUtils; + + @Test + public void contextLoads() { + SysUserEntity user = new SysUserEntity(); + user.setEmail("123456@qq.com"); + redisUtils.set("user", user); + + SysUserEntity ss = (SysUserEntity) redisUtils.get("user"); + System.out.println(ss.getEmail()); + +// System.out.println(ToStringBuilder.reflectionToString(redisUtils.get("user", SysUserEntity.class))); + } + +} diff --git a/shapelight-admin/src/test/java/net/shapelight/SwaggerTo.java b/shapelight-admin/src/test/java/net/shapelight/SwaggerTo.java new file mode 100644 index 0000000..23d0b3f --- /dev/null +++ b/shapelight-admin/src/test/java/net/shapelight/SwaggerTo.java @@ -0,0 +1,123 @@ +package net.shapelight; +import io.github.swagger2markup.GroupBy; +import io.github.swagger2markup.Language; +import io.github.swagger2markup.Swagger2MarkupConfig; +import io.github.swagger2markup.Swagger2MarkupConverter; +import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; +import io.github.swagger2markup.markup.builder.MarkupLanguage; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.URL; +import java.nio.file.Paths; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class SwaggerTo { + + /** + * 生成AsciiDocs格式文档 + * @throws Exception + */ + @Test + public void generateAsciiDocs() throws Exception { + // 输出Ascii格式 + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(MarkupLanguage.ASCIIDOC) + .withOutputLanguage(Language.ZH) + .withPathsGroupedBy(GroupBy.TAGS) + .withGeneratedExamples() + .withoutInlineSchema() + .build(); + + Swagger2MarkupConverter.from(new URL("http://localhost:8018/cell/v2/api-docs")) + .withConfig(config) + .build() + .toFolder(Paths.get("./docs/asciidoc/generated")); + } + + /** + * 生成Markdown格式文档 + * @throws Exception + */ + @Test + public void generateMarkdownDocs() throws Exception { + // 输出Markdown格式 + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .withOutputLanguage(Language.ZH) + .withPathsGroupedBy(GroupBy.TAGS) + .withGeneratedExamples() + .withoutInlineSchema() + .build(); + + Swagger2MarkupConverter.from(new URL("http://localhost:8018/cell/v2/api-docs")) + .withConfig(config) + .build() + .toFolder(Paths.get("./docs/markdown/generated")); + } +// /** +// * 生成Confluence格式文档 +// * @throws Exception +// */ +// @Test +// public void generateConfluenceDocs() throws Exception { +// // 输出Confluence使用的格式 +// Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() +// .withMarkupLanguage(MarkupLanguage.CONFLUENCE_MARKUP) +// .withOutputLanguage(Language.ZH) +// .withPathsGroupedBy(GroupBy.TAGS) +// .withGeneratedExamples() +// .withoutInlineSchema() +// .build(); +// +// Swagger2MarkupConverter.from(new URL("http://localhost:8016/v2/api-docs")) +// .withConfig(config) +// .build() +// .toFolder(Paths.get("./docs/confluence/generated")); +// } + + /** + * 生成AsciiDocs格式文档,并汇总成一个文件 + * @throws Exception + */ + @Test + public void generateAsciiDocsToFile() throws Exception { + // 输出Ascii到单文件 + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(MarkupLanguage.ASCIIDOC) + .withOutputLanguage(Language.ZH) + .withPathsGroupedBy(GroupBy.TAGS) + .withGeneratedExamples() + .withoutInlineSchema() + .build(); + + Swagger2MarkupConverter.from(new URL("http://localhost:8018/cell/v2/api-docs")) + .withConfig(config) + .build() + .toFile(Paths.get("./docs/asciidoc/generated/all")); + } + + /** + * 生成Markdown格式文档,并汇总成一个文件 + * @throws Exception + */ + @Test + public void generateMarkdownDocsToFile() throws Exception { + // 输出Markdown到单文件 + Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .withOutputLanguage(Language.ZH) + .withPathsGroupedBy(GroupBy.TAGS) + .withGeneratedExamples() + .withoutInlineSchema() + .build(); + + Swagger2MarkupConverter.from(new URL("http://localhost:8018/cell/v2/api-docs")) + .withConfig(config) + .build() + .toFile(Paths.get("./docs/markdown/generated/all")); + } +}