人脸识别平台批量导入绑定设备的一种方法

        因为原先平台绑定设备是通过一个界面进行人工选择绑定或一个人一个人绑定设备。如下:

人脸识别平台批量导入绑定设备的一种方法_第1张图片

 但有时候需要在几千个里选择出几百个,那这种方式就不大现实了,需要另外一种方法。

  目前相到可以通过导入批量数据进行绑定的方式。

一、前端

主要是显示选择文件与设备




界面如下:

人脸识别平台批量导入绑定设备的一种方法_第2张图片

 二、后端代码

接口代码

@PostMapping("/importBind")
    @ApiOperation("批量导入员工数据绑定设备")
    public ResultBean importBind(@ApiParam(name = "excelPath", value = "基础信息文件存储URL", required = true) @RequestParam String excelPath,
                                     @ApiParam(name = "companyId", value = "企业ID", required = true) @RequestParam Integer companyId,
                                     @ApiParam(name = "devId", value = "设备ID(','分隔)") @RequestParam(required = false) String devId) {
        // 错误信息存储列表
        List userErrorList = new ArrayList<>();
        List imgErrorList = new ArrayList<>();

        Assert.notNull(companyId, ReturnCode.Params_Error);
        userService.importBind(companyId, getLoginId(), excelPath, userErrorList, imgErrorList, devId);

        // 返回结果
        if (userErrorList.size() == 0 && imgErrorList.size() == 0) {
            return Results.success();
        } else {
            Map errorLists = new HashMap<>();
            errorLists.put("dataList", userErrorList);
            errorLists.put("imgMap", imgErrorList);
            return new ResultBean<>(2, ReturnCode.File_Exist_Error_Data.getDetail(), errorLists);
        }
    }

绑定的主要逻辑如下:

@Override
	public void importBind(Integer companyId, Integer loginId, String excelPath, List userErrorList,
			List imgErrorList, String devId) {
		// 1. 解析EXCEL数据映射成原始数据信息列表
        List> dataList = parseExcelToRawdata(excelPath);

        // 2. 过滤原始数据信息, 并转换成员工信息列表
        List users = filterToUsersForBind(companyId, loginId, dataList, userErrorList);
        // 3. 批量绑定设备
        if(users.size()>0)
        {
        	batchBind(users,devId);
        }
	}

@Transactional
    @OperLogInject("批量绑定员工信息")
    public void batchBind(List users, String devId) {

    	if (!devId.isEmpty() && !users.isEmpty()) {
            String userId = String.join(",", users.stream().map(u -> u.getId().toString()).collect(Collectors.toList()));
            try {
                ResultBean bindResult = devService.bindUser(devId,null, userId, true,1);
                Assert.isTrue(bindResult.getCode() == 1, ReturnCode.User_Bind_Error);
            } catch (Exception e) {
                throw new CustomException(ReturnCode.User_Bind_Error);
            }
        }
    }

你可能感兴趣的:(java开发,mysql,linux,vue.js,elementui,前端)