From 1b3a14a25d8f5013158ef2842e9be0e24240f2b5 Mon Sep 17 00:00:00 2001 From: 张晓波 <bingbo1993@126.com> Date: 星期一, 30 十月 2023 08:52:26 +0800 Subject: [PATCH] 人脸 缓存同步菜单 --- hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java | 18 +++ hd/pipe/UserCore/src/main/resources/mapping/SysMenusMapper.xml | 79 +++++++++++++++ hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml | 36 +++++++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/config/StartListener.java | 25 +++++ hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/impl/SysMenusServiceImpl.java | 16 +++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java | 10 ++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/GetUserTask.java | 45 +++++++++ hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java | 2 hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/entity/PlatUser.java | 2 hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/controller/SysMenusController.java | 23 ++++ hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/mapper/SysMenusMapper.java | 2 hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/ISysMenusService.java | 3 hd/pipe/common/src/main/java/com/thhy/general/config/InsertAop.java | 5 hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java | 4 14 files changed, 267 insertions(+), 3 deletions(-) diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/config/StartListener.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/config/StartListener.java new file mode 100644 index 0000000..ea8eeab --- /dev/null +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/config/StartListener.java @@ -0,0 +1,25 @@ +package com.thhy.staff.config; + +import com.thhy.staff.modules.biz.face.controller.GetUserTask; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.context.annotation.Configuration; + +import java.util.Timer; + +@Configuration +public class StartListener implements ApplicationRunner { + + + @Value("${file.vfprefix}") + private String vfPrefix; + + @Override + public void run(ApplicationArguments args) throws Exception { + GetUserTask gutask = new GetUserTask(vfPrefix); + Timer timer = new Timer(); + timer.schedule(gutask,1000,300000); + } +} diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java index 2e948f2..e8aad12 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/FaceController.java @@ -112,5 +112,15 @@ } } + @RequestMapping("/allPerson") + public JSONObject allPerson(@RequestBody String mess){ + faceServer.allPerson(mess); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code",0); + jsonObject.put("msg","OK"); + jsonObject.put("success",true); + return jsonObject; + } + } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/GetUserTask.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/GetUserTask.java new file mode 100644 index 0000000..7dc7260 --- /dev/null +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/controller/GetUserTask.java @@ -0,0 +1,45 @@ +package com.thhy.staff.modules.biz.face.controller; + +import com.alibaba.fastjson.JSONObject; +import com.thhy.general.utils.SpringContextUtils; +import com.thhy.staff.config.EmqxConfig; +import com.thhy.staff.modules.biz.face.mapper.FaceDeviceMapper; +import com.thhy.staff.utils.MqUtils; +import java.util.List; +import java.util.TimerTask; + +public class GetUserTask extends TimerTask { + + private String prefix; + + private FaceDeviceMapper faceDeviceMapper; + + public FaceDeviceMapper getFaceDeviceMapper() { + return SpringContextUtils.getBean(FaceDeviceMapper.class); + } + + private EmqxConfig emqxConfig; + + public EmqxConfig getEmqxConfig() { + return SpringContextUtils.getBean(EmqxConfig.class); + } + + public GetUserTask(String urlPrefix) { + this.prefix = urlPrefix; + } + + @Override + public void run() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("method","get_person_all"); + + JSONObject dataJson = new JSONObject(); + dataJson.put("path",prefix+"allPerson"); + jsonObject.put("data",dataJson); + jsonObject.put("params",new JSONObject()); + EmqxConfig emqxConfig = getEmqxConfig(); + FaceDeviceMapper faceDeviceMapper = getFaceDeviceMapper(); + List<String> sns = faceDeviceMapper.queryDevSn(); + MqUtils.createClient(emqxConfig,sns,jsonObject.toJSONString()); + } +} diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java index 0c57764..31cdbbd 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/FaceServer.java @@ -20,4 +20,6 @@ void removeNotify(String mess); String queryOriStrById(String id); + + void allPerson(String mess); } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java index 707b5d1..a5ef6e8 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/face/service/impl/FaceServerImpl.java @@ -12,6 +12,7 @@ import com.thhy.staff.modules.biz.face.mapper.FaceDeviceMapper; import com.thhy.staff.modules.biz.face.service.FaceServer; import com.thhy.staff.modules.biz.platuser.entity.DoorLis; +import com.thhy.staff.modules.biz.platuser.entity.PlatUser; import com.thhy.staff.modules.biz.platuser.mapper.PlatUserMapper; import com.thhy.staff.utils.MqUtils; import org.checkerframework.checker.units.qual.A; @@ -172,6 +173,23 @@ return userMapper.queryOriStrById(id); } + @Override + public void allPerson(String mess) { + JSONObject jsonObject = JSONObject.parseObject(mess); + JSONArray jsonArray = jsonObject.getJSONArray("person_list"); + for(Object obj : jsonArray){ + JSONObject personJson = JSON.parseObject(obj.toString()); + String faceId = personJson.getString("person_id"); + int count = userMapper.countByFaceId(faceId); + if(count>0)continue; + PlatUser platUser = new PlatUser(); + platUser.setFaceId(faceId); + platUser.setIdNo(personJson.getString("id_card")); + platUser.setRealName(personJson.getString("name")); + userMapper.insertSamplePlatUser(platUser); + } + } + public static void main(String[] args) { JSONObject jsonObject = new JSONObject(); jsonObject.put("method","delete_person"); diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/entity/PlatUser.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/entity/PlatUser.java index 42f9162..9cc2101 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/entity/PlatUser.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/entity/PlatUser.java @@ -144,4 +144,6 @@ private Integer isLogin; private String phone; + + private String faceId; } diff --git a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java index b988c39..c9398a4 100644 --- a/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java +++ b/hd/pipe/StaffManage/src/main/java/com/thhy/staff/modules/biz/platuser/mapper/PlatUserMapper.java @@ -115,4 +115,8 @@ void syncFail(@Param("userId") String userId,@Param("syncFailReason")String syncFailReason); String queryOriStrById(String id); + + int countByFaceId(String faceId); + + void insertSamplePlatUser(PlatUser platUser); } diff --git a/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml b/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml index 4591523..70a6c79 100644 --- a/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml +++ b/hd/pipe/StaffManage/src/main/resources/mapping/PlatUserMapper.xml @@ -930,4 +930,40 @@ update sys_plat_user set sync_success = 2,sync_fail_reason = #{syncFailReason} where user_id = #{userId} </update> + <select id="countByFaceId" resultType="int"> + select count(user_id) from sys_plat_user where face_id = #{faceId} + </select> + + <insert id="insertSamplePlatUser"> + insert into sys_plat_user + <trim prefix="(" suffixOverrides="," suffix=")"> + <if test="userId != null and userId != ''"> + user_id, + </if> + <if test="realName != null and realName != ''"> + real_name, + </if> + <if test="faceId != null and faceId != ''"> + face_id, + </if> + <if test="idNo != null and idNo != ''"> + id_no, + </if> + </trim> + <trim prefix="values (" suffixOverrides="," suffix=")"> + <if test="userId != null and userId != ''"> + #{userId}, + </if> + <if test="realName != null and realName != ''"> + #{realName}, + </if> + <if test="faceId != null and faceId != ''"> + #{faceId}, + </if> + <if test="idNo != null and idNo != ''"> + #{idNo}, + </if> + </trim> + </insert> + </mapper> diff --git a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/controller/SysMenusController.java b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/controller/SysMenusController.java index 88a954d..a306cfd 100644 --- a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/controller/SysMenusController.java +++ b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/controller/SysMenusController.java @@ -1,6 +1,9 @@ package com.thhy.usercore.modules.sys.sysmenu.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.JSONToken; import com.github.pagehelper.PageInfo; import com.thhy.general.utils.PagingUtils; import com.thhy.general.common.BasicResult; @@ -17,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; -import java.io.Serializable; +import java.io.*; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -74,6 +77,24 @@ return BasicResult.success(sysMenusList); } + @RequestMapping("syncMenu") + public BasicResult syncMenu(){ + String value = ""; + try { + InputStream ins = new FileInputStream(new File("D:\\dd.txt")); + byte[] bytes = new byte[ins.available()]; + ins.read(bytes); + value = new String(bytes,"UTF-8"); + + } catch (Exception e) { + throw new RuntimeException(e); + } + + List<MenuTreeVo> sysMenusList = JSONArray.parseArray(value,MenuTreeVo.class); + sysMenusService.syncMenu(sysMenusList); + return BasicResult.success(sysMenusList); + } + @RequestMapping("allRoleMenu") public BasicResult allRoleMenu(@RequestBody MenuDto menuDto){ menuDto.setParentId("0"); diff --git a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/mapper/SysMenusMapper.java b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/mapper/SysMenusMapper.java index a68cd06..9fa353d 100644 --- a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/mapper/SysMenusMapper.java +++ b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/mapper/SysMenusMapper.java @@ -28,6 +28,8 @@ void insert(SysMenus sysmenus); + void insertVo(MenuTreeVo menuTreeVo); + void update(SysMenus sysmenus); int deletelogic(Serializable menuId); diff --git a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/ISysMenusService.java b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/ISysMenusService.java index 2ea58dc..bc74ef3 100644 --- a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/ISysMenusService.java +++ b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/ISysMenusService.java @@ -1,5 +1,6 @@ package com.thhy.usercore.modules.sys.sysmenu.service; +import com.alibaba.fastjson.JSONObject; import com.thhy.usercore.modules.sys.sysmenu.entity.*; import com.thhy.usercore.modules.sys.sysmenubutton.entity.MenuButtonVo; @@ -34,6 +35,8 @@ List<MenuTreeVo> findAllTree(MenuDto menuDto); + void syncMenu(List<MenuTreeVo> sysMenusList); + List<MenuButtonTreeVo> allRoleMenu(MenuDto menuDto); List<MenuButtonVo> MenuEnableButtons(MenuButtonDto menuButtonDto); diff --git a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/impl/SysMenusServiceImpl.java b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/impl/SysMenusServiceImpl.java index 5aed559..bdbf448 100644 --- a/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/impl/SysMenusServiceImpl.java +++ b/hd/pipe/UserCore/src/main/java/com/thhy/usercore/modules/sys/sysmenu/service/impl/SysMenusServiceImpl.java @@ -1,5 +1,8 @@ package com.thhy.usercore.modules.sys.sysmenu.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.thhy.general.utils.UserInfoUtils; import com.thhy.general.common.BasicStatus; import com.thhy.general.exception.BasicException; @@ -138,6 +141,19 @@ } @Override + @Transactional + public void syncMenu(List<MenuTreeVo> sysMenusList) { + for(MenuTreeVo tree : sysMenusList){ + + sysMenusMapper.insertVo(tree); + if(tree.getChildrens().size()>0){ + + syncMenu(tree.getChildrens()); + } + } + } + + @Override public List<MenuButtonTreeVo> allRoleMenu(MenuDto menuDto) { List<MenuButtonTreeVo> sysMenusList = sysMenusMapper.menuRoleTree(menuDto); for(MenuButtonTreeVo mv : sysMenusList){ diff --git a/hd/pipe/UserCore/src/main/resources/mapping/SysMenusMapper.xml b/hd/pipe/UserCore/src/main/resources/mapping/SysMenusMapper.xml index 6f8e3d6..51ae824 100644 --- a/hd/pipe/UserCore/src/main/resources/mapping/SysMenusMapper.xml +++ b/hd/pipe/UserCore/src/main/resources/mapping/SysMenusMapper.xml @@ -195,7 +195,86 @@ </trim> </insert> + <insert id="insertVo"> + insert into sys_menus + <trim prefix="(" suffix=")" suffixOverrides="," > + <if test="menuId != null"> + menu_id, + </if> + <if test="isUse != null"> + is_use, + </if> + <if test="path != null"> + path, + </if> + <if test="name != null"> + name, + </if> + <if test="hidden != null"> + hidden, + </if> + <if test="redirect != null"> + redirect, + </if> + <if test="parentId != null"> + parent_id, + </if> + <if test="title != null"> + title, + </if> + <if test="icon != null"> + icon, + </if> + <if test="component != null"> + component, + </if> + <if test="level != null"> + level, + </if> + <if test="isDefault != null"> + is_default, + </if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides="," > + <if test="menuId != null"> + #{menuId}, + </if> + <if test="isUse != null"> + #{isUse}, + </if> + <if test="path != null"> + #{path}, + </if> + <if test="name != null"> + #{name}, + </if> + <if test="hidden != null"> + #{hidden}, + </if> + <if test="redirect != null"> + #{redirect}, + </if> + <if test="parentId != null"> + #{parentId}, + </if> + <if test="title != null"> + #{title}, + </if> + <if test="icon != null"> + #{icon}, + </if> + <if test="component != null"> + #{component}, + </if> + <if test="level != null"> + #{level}, + </if> + <if test="isDefault != null"> + #{isDefault}, + </if> + </trim> + </insert> <!--更新操作--> <update id="update"> update sys_menus diff --git a/hd/pipe/common/src/main/java/com/thhy/general/config/InsertAop.java b/hd/pipe/common/src/main/java/com/thhy/general/config/InsertAop.java index 4ee1449..c764fa9 100644 --- a/hd/pipe/common/src/main/java/com/thhy/general/config/InsertAop.java +++ b/hd/pipe/common/src/main/java/com/thhy/general/config/InsertAop.java @@ -26,7 +26,7 @@ @Around("pointcut()") public Object invoke(ProceedingJoinPoint invocation) throws Throwable { - String methodName = invocation.getSignature().getName(); + /*String methodName = invocation.getSignature().getName(); if(methodName.contains("insert")||methodName.contains("Insert")){ Object j = invocation.getArgs()[0]; @@ -65,7 +65,8 @@ return invocation.proceed(); }else{ return invocation.proceed(); - } + }*/ + return invocation.proceed(); } -- Gitblit v1.9.3