liujie
2026-09-15 7e97fc9053029b1761294d52445759a2afe94934
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.ruoyi.web.controller.api;
 
 
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.domain.Employee;
import com.ruoyi.system.domain.SysVisitorMachine;
import com.ruoyi.system.dto.ApiVisitorMachineRequest;
import com.ruoyi.system.dto.CardVerifyRequest;
import com.ruoyi.system.dto.EmployeeDto;
import com.ruoyi.system.dto.SysVisitorMachineDetailRequest;
import com.ruoyi.system.mapper.EmployeeMapper;
import com.ruoyi.system.mapper.SysVisitorMachineMapper;
import com.ruoyi.system.service.EmployeeVerifyService;
import com.ruoyi.system.service.ISysVisitorMachineService;
import com.ruoyi.system.utils.EmployeePhoneCrypto;
import com.ruoyi.system.vo.SysVisitorMachineVO;
import com.ruoyi.web.controller.tool.ImageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 接待人(被访者)刷卡验证接口。
 * 数据源:t_employee 员工管理表(含内部员工及已授权的外部人员)。
 */
@Api(tags = "接待人验证接口-查询所有员工接口")
@RestController
@RequestMapping("/api/employee/verify")
public class EmployeeVerifyController extends BaseController {
 
    @Resource
    private EmployeeVerifyService employeeVerifyService;
    @Resource
    private EmployeeMapper employeeMapper;
    @Autowired
    private SysVisitorMachineMapper visitorMachineMapper;
 
    /**
     * 刷卡验证:现场读卡器读取卡号后调用本接口,与接待人绑定的卡号比对。
     */
    @PostMapping("/card")
    @ApiOperation(value = "接待人刷卡验证", notes = "根据传入的卡号与接待人(employeeId)绑定的卡号进行比对,"
            + "仅对启用且未删除的接待人生效")
    public AjaxResult verifyByCard(@RequestBody @Valid CardVerifyRequest request) {
        return employeeVerifyService.verifyByCard(request);
    }
 
    /**
     * 刷卡验证:现场读卡器读取卡号后调用本接口,与接待人绑定的卡号比对。
     */
    @PostMapping("/allEmployee")
    @ApiOperation(value = "查询所有员工接口")
    public AjaxResult getAllEmployee() {
//        SysVisitorMachine detail = visitorMachineMapper.checkDeviceIdUnique(request.getMachineId(),null);
//        if (detail == null || !detail.getEnabled()) {
//            throw new ServiceException("未找到有效设备");
//        }
 
        List<Employee> employees = employeeMapper.selectAllEnabled();
        if (employees == null || employees.isEmpty()) {
            return success(new ArrayList<>());
        }
 
        List<EmployeeDto> employeeDtoList = employees.stream()
                .map(employee -> {
                    EmployeeDto dto = new EmployeeDto();
                    BeanUtils.copyProperties(employee, dto);
 
                    // 将图片地址转为 Base64
                    if (StringUtils.isNotEmpty(employee.getFaceImage())) {
                        String base64 = ImageUtil.imageUrlToBase64(employee.getFaceImage());
                        dto.setFaceImage(base64);
                    }
 
                    if (StringUtils.isNotEmpty(employee.getContactPhoneCipher())) {
                        String phone = EmployeePhoneCrypto.decrypt(employee.getContactPhoneCipher());
                        dto.setPhone(phone);
                    }
                    dto.setContactPhoneCipher(null);
 
                    return dto;
                })
                .collect(Collectors.toList());
 
        return success(employeeDtoList);
    }
}