叶松
2023-10-30 6a9372d8683ccff59efdecde0792938e774b7e3a
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.thhy.staff.modules.biz.face.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.thhy.general.common.BasicResult;
import com.thhy.staff.modules.biz.face.entity.FaceResult;
import com.thhy.staff.modules.biz.face.service.FaceDeviceService;
import com.thhy.staff.modules.biz.face.service.FaceServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Base64;
 
@RestController
@RequestMapping("face")
public class FaceController {
 
    @Autowired
    private FaceServer faceServer;
 
    @Autowired
    private FaceDeviceService deviceService;
 
    @RequestMapping("/device/login")
    public FaceResult login(@RequestBody String mess){
        FaceResult faceResult = faceServer.login(mess);
        return faceResult;
    }
 
 
    @RequestMapping("/syncPerson")
    public JSONObject syncPerson(@RequestBody String mess){
        JSONObject jsonObject = faceServer.syncPerson(mess);
        return jsonObject;
    }
 
    @RequestMapping("/syncPersonSingle")
    public JSONObject syncPersonSingle(@RequestBody String mess){
        JSONObject jsonObject = faceServer.syncPersonSingle(mess);
        return jsonObject;
    }
 
    @RequestMapping("/sp/notify")
    public JSONObject personNotify(@RequestBody String mess){
        faceServer.personNotify(mess);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","OK");
        jsonObject.put("success",true);
        return jsonObject;
    }
 
    @RequestMapping("/record/upload/online")
    public JSONObject record(@RequestBody String mess){
        faceServer.record(mess);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","OK");
        jsonObject.put("success",true);
        return jsonObject;
    }
 
    @RequestMapping("/queryPer")
    public BasicResult queryPer(String perId){
        faceServer.queryPer(perId);
        return BasicResult.success();
    }
 
    @RequestMapping("/getPersonDetail")
    public BasicResult getPersonDetail(@RequestBody String mess){
        Logger logger = LoggerFactory.getLogger(FaceController.class);
        logger.info("查询结果"+mess);
        return BasicResult.success();
    }
 
 
    @RequestMapping("/deleteNotify")
    public JSONObject deleteNotify(@RequestBody String mess){
        faceServer.removeNotify(mess);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","OK");
        jsonObject.put("success",true);
        return jsonObject;
    }
 
    @RequestMapping("/showFaceImg")
    public void showFaceImg(String recordId, HttpServletResponse response){
        String oriStr = faceServer.queryOriStrById(recordId);
        byte[] bytes = Base64.getDecoder().decode(oriStr);
        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            outputStream.write(bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (outputStream!=null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
 
    @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;
    }
 
 
}