123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package face
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/mqtt"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "property-mqtt/errors"
- "property-mqtt/mqtt_utils"
- pb_v1 "property-mqtt/pb/v1"
- )
- func checkFaceWhiteDelParam(req *pb_v1.FaceWhiteDelRequest) error {
- if req.Sn == "" {
- return status.Error(10003, "设备sn不能为空")
- }
- if len(req.CustomIds) == 0 {
- return status.Error(10003, "用户不能为空")
- }
- for _, v := range req.CustomIds {
- if v == "" {
- return status.Error(10003, "用户不能为空")
- }
- }
- return nil
- }
- func FaceWhiteDel(ctx context.Context, req *pb_v1.FaceWhiteDelRequest) (reply *pb_v1.FaceWhiteDelReply, err error) {
- reply = &pb_v1.FaceWhiteDelReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- err = checkFaceWhiteDelParam(req)
- if err != nil {
- return nil, err
- }
- if !mqtt_utils.Wait(req.Sn) {
- return nil, status.Error(10003, "系统繁忙")
- }
- messageId := mqtt_utils.GenerateMsgId(req.Sn)
- mreq := mqtt_utils.DeletePersonsCmd{
- Operator: "DeletePersons",
- MessageId: messageId,
- DataBegin: "BeginFlag",
- DataEnd: "EndFlag",
- PersonNum: len(req.CustomIds),
- Info: mqtt_utils.DeletePersonsInfo{CustomId: req.CustomIds},
- }
- bytes, _ := json.Marshal(&mreq)
- // 先缓存命令,mqtt收到响应后会做响应处理
- //mqtt_utils.CacheCommand(req.Sn, string(bytes), messageId)
- // 向mqtt发送命令
- err = mqtt.Publish(mqtt.MqttCli, mqtt_utils.GetTopic(req.Sn), bytes)
- if err != nil {
- logger.Error("func",
- zap.String("call", "mqtt.Publish"),
- zap.String("error", err.Error()))
- // 失败删除命令
- //mqtt_utils.DelCommand(req.DeviceId, messageId)
- return nil, errors.MqttError
- }
- return reply, nil
- }
|