Эх сурвалжийг харах

refactor(national-motion-module):重构设备添加和编辑逻辑

- 优化了设备添加和编辑的接口调用逻辑
-增加了对站点 ID 的空值检查
- 移除了不必要的权限注解
- 统一了异常处理方式
- 更新了海康开放平台的 app key 和 secret
SheepHy 3 долоо хоног өмнө
parent
commit
67a9c8443a

+ 12 - 16
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -967,22 +967,18 @@ public class OrderServiceImpl implements IOrderService {
                 appIsinMapper.insert(appIsin);
             }
             if (Objects.equals(appOrderProInfo.getType(), CommonConstant.ORDER_PRO_INFO_TYPE_0)) {
-                appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getOrgCode, appOrder.getOrgCode())).forEach(appDevice -> {
-                    try {
-                        String addUser = addUser(appSitePriceRulesMapper.selectById(appOrderProInfo.getProductId()).getDateOfSale(),
-                                appDevice.getDeviceSerial(),
-                                appOrderProInfo.getUserName(),
-                                appOrderProInfo.getId());
-                        String addFace = addFace(appDevice.getDeviceSerial(), appOrderProInfo.getId(),
-                                familyMembersMapper.selectById(appOrderProInfo.getFamilyUserId()).getRealNameImg());
-                        JsonObject addUserJson = JsonParser.parseString(addUser).getAsJsonObject();
-                        JsonObject addFaceJson = JsonParser.parseString(addFace).getAsJsonObject();
-                        if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0)
-                            throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
-                    } catch (Exception e) {
-                        throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
-                    }
-                });
+                for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getOrgCode, appOrder.getOrgCode()))) {
+                    String addUser = addUser(appSitePriceRulesMapper.selectById(appOrderProInfo.getProductId()).getDateOfSale(),
+                            appDevice.getDeviceSerial(),
+                            appOrderProInfo.getUserName(),
+                            appOrderProInfo.getId());
+                    String addFace = addFace(appDevice.getDeviceSerial(), appOrderProInfo.getId(),
+                            familyMembersMapper.selectById(appOrderProInfo.getFamilyUserId()).getRealNameImg());
+                    JsonObject addUserJson = JsonParser.parseString(addUser).getAsJsonObject();
+                    JsonObject addFaceJson = JsonParser.parseString(addFace).getAsJsonObject();
+                    if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0) throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
+                }
+
             }
         }
 

+ 4 - 4
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/hikiot/HikiotConstant.java

@@ -13,16 +13,16 @@ public interface HikiotConstant {
     String USER_ACCESS_TOKEN = "User-Access-Token";
     String USER_NAME = "userName";
     String PASSWORD = "password";
-    String USER_NAME_VALUE = "18908510411";
-    String PASSWORD_VALUE = "ziyan515.";
+    String USER_NAME_VALUE = "18984144104";
+    String PASSWORD_VALUE = "zswl8812";
     String APP_ACCESS_TOKEN_AUTH_HEADER = "App-Access-Token";
     String REDIRECT_URL = "redirectUrl";
     String VISITOR = "visitor";
     String REDIRECT_URL_VALUE = "http://o3878n6548.wicp.vip";
     /**APP KEY*/
-    String APP_KEY_VALUE = "1954824074366873616";
+    String APP_KEY_VALUE = "1960624697469370436";
     /**APP SECRET*/
-    String APP_SECRET_VALUE = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAK450rptZVPVc2cqJWZgf6wT0rTsmrIAXxZ+7J4ILS+cUFEMPpLlDbq5+F6KJB6p2cSI9QVBrAdr84dZC9FD2lYgFVy6SzafiesJsdCFbogocZB3L70TNKCwNj+TAXmb5m2APFy1hVJiV+VvPCnZTzXmrvG8+mFqKQLlG+eTeWY5AgMBAAECgYAFD8j/gY4gEWN469CKWONcrHbCqt0Trs8UaDuXm8U0TOZIdIKc4eq0MhL1LC5Adc7N1uzHalEFJi29EOk2+zGsopRpf9vm1ObqFougip5iMR369Rz3OUphOo/jPbjZIJ8DPPSxsfJbkWmYftBoWX5tN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qzMc4DVq0VsmV7zvXhUYvok5O5vEBmsMWpL/6llKSOcMErqtx06D8DNLJfY10wcgpRruLKloLzNWkRsPRwJBAIU29uO5/YWA8QuSdHIsjtO6me/VPO0JzOA9G6Jp+o98Uc46cGlqqf8E1gbsGadxFg6/oXTi/7N8UPrSOHCYYgkCQBpdtFy2e6hHiKFhSgDwSkAOhs5A8zIcT8qRPE2Fv58Wmqqx9y7jkiv10ZJtDjSSt75f97jKHejSVJ+z5CQ5qGs=";
     /**获取访问凭证URL*/
     String GET_ACCESS_TOKEN_URL = "https://open-api.hikiot.com/auth/exchangeAppToken";
     /**刷新应用访问凭证URL*/

+ 14 - 11
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/hikiot/HikiotTool.java

@@ -70,7 +70,7 @@ public class HikiotTool {
      * @param url 完整请求地址(包含查询参数)
      * @return 响应结果
      */
-    public static String sendGetRequest(String url, Map<String, String> headers) throws IOException, InterruptedException {
+    public static String sendGetRequest(String url, Map<String, String> headers){
         // 获取访问凭证
         JsonObject appAccessToken = JsonParser.parseString(HikiotTool.getAppAccessToken()).getAsJsonObject();
         if (appAccessToken.get("code").getAsInt() == 0) {
@@ -93,9 +93,12 @@ public class HikiotTool {
 
         // 构建最终请求
         HttpRequest request = requestBuilder.build();
-
-        // 发送请求
-        HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        HttpResponse<String> response = null;
+        try {
+            response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+        }catch (Exception e){
+            throw new JeecgBootException("请求海康开放平台接口异常", e);
+        }
         return response.body();
     }
 
@@ -146,7 +149,7 @@ public class HikiotTool {
      * @Param
      * @return
      **/
-    public static String getUserAccessToken() throws IOException, InterruptedException {
+    public static String getUserAccessToken() {
         JsonObject dataAuthCode = JsonParser.parseString(HikiotTool.getAuthCode()).getAsJsonObject();
         if (dataAuthCode.get("code").getAsInt() == 0) {
             dataAuthCode = dataAuthCode.getAsJsonObject("data");
@@ -161,7 +164,7 @@ public class HikiotTool {
      * @Description 新增/修改人员
      * @Date 9:35 2025/8/15
      **/
-    public static String addUser(Date inputDate,String deviceSerial,String name,String employeeNo) throws IOException, InterruptedException {
+    public static String addUser(Date inputDate,String deviceSerial,String name,String employeeNo){
         LocalDateTime now = inputDate.toInstant()
                 .atZone(ZoneId.systemDefault())
                 .toLocalDateTime();
@@ -193,7 +196,7 @@ public class HikiotTool {
      * @Description 设备添加
      * @Date 10:47 2025/8/15
      **/
-    public static String addDevice(String deviceSerial,String validateCode) throws IOException, InterruptedException {
+    public static String addDevice(String deviceSerial,String validateCode){
         Map<String, String> device = new HashMap<>();
         device.put("deviceSerial", deviceSerial);
         device.put("validateCode", validateCode);
@@ -207,7 +210,7 @@ public class HikiotTool {
      * @Description 设置请求头
      * @Date 10:56 2025/8/15
      **/
-    private static Map<String, String> setHeaders() throws IOException, InterruptedException {
+    private static Map<String, String> setHeaders() {
         Map<String, String> variables = new HashMap<>();
         JsonObject appAccessToken = JsonParser.parseString(HikiotTool.getAppAccessToken()).getAsJsonObject();
         JsonObject userAccessToken = JsonParser.parseString(HikiotTool.getUserAccessToken()).getAsJsonObject();
@@ -242,7 +245,7 @@ public class HikiotTool {
      * @Description 新增/修改人脸
      * @Date 14:28 2025/8/15
      **/
-    public static String addFace(String deviceSerial,String employeeNo,String url) throws IOException, InterruptedException {
+    public static String addFace(String deviceSerial,String employeeNo,String url){
         AddFaceRequestDTO addFaceRequestDTO = new AddFaceRequestDTO();
         addFaceRequestDTO.setDeviceSerial(deviceSerial);
         addFaceRequestDTO.setPayload(new AddFaceRequestDTO.Payload()
@@ -269,7 +272,7 @@ public class HikiotTool {
      * @Description 配置人员周计划
      * @Date 16:12 2025/8/15
      **/
-    public static String addUserWeekPlan(String deviceSerial) throws IOException, InterruptedException {
+    public static String addUserWeekPlan(String deviceSerial) {
         AddUserWeekPlanDTO dto = new AddUserWeekPlanDTO();
 
         // 基础配置
@@ -323,7 +326,7 @@ public class HikiotTool {
      * @Description 配置人员计划模板
      * @Date 17:09 2025/8/15
      **/
-    public static String addUserPlanTemplate(String deviceSerial) throws IOException, InterruptedException {
+    public static String addUserPlanTemplate(String deviceSerial){
         String addUserPlanTemplate = "{\n" +
                 "    \"deviceSerial\": \"" + deviceSerial +"\",\n" +
                 "    \"payload\": {\n" +

+ 26 - 32
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/controller/AppDeviceController.java

@@ -9,10 +9,8 @@ import com.google.gson.JsonParser;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
-import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.modules.system.app.entity.AppDevice;
@@ -68,7 +66,9 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 		Page<AppDevice> page = new Page<AppDevice>(pageNo, pageSize);
 		IPage<AppDevice> pageList = AppDeviceService.page(page, queryWrapper);
 		pageList.getRecords().forEach(item->{
-			item.setSiteName(appSiteMapper.selectById(item.getSiteId()).getName());
+			if(!item.getSiteId().isEmpty()){
+				item.setSiteName(appSiteMapper.selectById(item.getSiteId()).getName());
+			}
 		});
 		return Result.OK(pageList);
 	}
@@ -80,7 +80,6 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 	 */
 	@AutoLog(value = "nm_device-添加")
 	@Operation(summary="nm_device-添加")
-	@RequiresPermissions("com:nm_device:add")
 	@PostMapping(value = "/add")
 	@Transactional
 	public Result<String> add(@RequestBody AppDevice appDevice){
@@ -91,40 +90,37 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 			return Result.error("设备已存在!");
 		}
 		AppDeviceService.save(appDevice);
-		try {
-			if(appDevice.getDeviceSerial() != null && appDevice.getValidateCode() != null){
-				String addDevice = addDevice(appDevice.getDeviceSerial(), appDevice.getValidateCode());
-				String userWeekPlan = addUserWeekPlan(appDevice.getDeviceSerial());
-				String userPlanTemplate = addUserPlanTemplate(appDevice.getDeviceSerial());
-				JsonObject deviceJson = JsonParser.parseString(addDevice).getAsJsonObject();
-				JsonObject userWeekPlanJson = JsonParser.parseString(userWeekPlan).getAsJsonObject();
-				JsonObject userPlanTemplateJson = JsonParser.parseString(userPlanTemplate).getAsJsonObject();
-				if(deviceJson.get("code").getAsInt() == 0
-						&& userWeekPlanJson.get("code").getAsInt() == 0
-						&& userPlanTemplateJson.get("code").getAsInt() == 0){
-					return Result.OK("添加成功!");
-				}else {
-					return Result.OK("添加失败!");
-				}
-			}
-		}catch (Exception e){
-			throw new JeecgBootException("添加失败!");
-		}
 		return Result.OK("添加成功!");
 	}
 	
 	/**
 	 *  编辑
 	 *
-	 * @param AppDevice
+	 * @param appDevice
 	 * @return
 	 */
 	@AutoLog(value = "nm_device-编辑")
 	@Operation(summary="nm_device-编辑")
-	@RequiresPermissions("com:nm_device:edit")
 	@PostMapping(value = "/edit")
-	public Result<String> edit(@RequestBody AppDevice AppDevice) {
-		AppDeviceService.updateById(AppDevice);
+	@Transactional
+	public Result<String> edit(@RequestBody AppDevice appDevice) {
+		appDevice.setOrgCode(appSiteMapper.selectById(appDevice.getSiteId()).getOrgCode());
+		AppDeviceService.updateById(appDevice);
+		if(appDevice.getDeviceSerial() != null && appDevice.getValidateCode() != null && appDevice.getSiteId() != null){
+			String addDevice = addDevice(appDevice.getDeviceSerial(), appDevice.getValidateCode());
+			String userWeekPlan = addUserWeekPlan(appDevice.getDeviceSerial());
+			String userPlanTemplate = addUserPlanTemplate(appDevice.getDeviceSerial());
+			JsonObject deviceJson = JsonParser.parseString(addDevice).getAsJsonObject();
+			JsonObject userWeekPlanJson = JsonParser.parseString(userWeekPlan).getAsJsonObject();
+			JsonObject userPlanTemplateJson = JsonParser.parseString(userPlanTemplate).getAsJsonObject();
+			if(deviceJson.get("code").getAsInt() == 0
+					&& userWeekPlanJson.get("code").getAsInt() == 0
+					&& userPlanTemplateJson.get("code").getAsInt() == 0){
+				return Result.OK("添加成功!");
+			}else {
+				return Result.OK("添加失败!");
+			}
+		}
 		return Result.OK("编辑成功!");
 	}
 	
@@ -136,7 +132,6 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 	 */
 	@AutoLog(value = "nm_device-通过id删除")
 	@Operation(summary="nm_device-通过id删除")
-	@RequiresPermissions("com:nm_device:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
 		AppDeviceService.removeById(id);
@@ -151,7 +146,6 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 	 */
 	@AutoLog(value = "nm_device-批量删除")
 	@Operation(summary="nm_device-批量删除")
-	@RequiresPermissions("com:nm_device:deleteBatch")
 	@DeleteMapping(value = "/deleteBatch")
 	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
 		this.AppDeviceService.removeByIds(Arrays.asList(ids.split(",")));
@@ -172,7 +166,9 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
 		if(appDevice==null) {
 			return Result.error("未找到对应数据");
 		}
-		appDevice.setSiteName(appSiteMapper.selectById(appDevice.getSiteId()).getName());
+		if(!appDevice.getSiteId().isEmpty()){
+			appDevice.setSiteName(appSiteMapper.selectById(appDevice.getSiteId()).getName());
+		}
 		return Result.OK(appDevice);
 	}
 
@@ -182,7 +178,6 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
     * @param request
     * @param AppDevice
     */
-    @RequiresPermissions("com:nm_device:exportXls")
     @RequestMapping(value = "/exportXls")
     public ModelAndView exportXls(HttpServletRequest request, AppDevice AppDevice) {
         return super.exportXls(request, AppDevice, AppDevice.class, "nm_device");
@@ -195,7 +190,6 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
     * @param response
     * @return
     */
-    @RequiresPermissions("com:nm_device:importExcel")
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
         return super.importExcel(request, response, AppDevice.class);