Blame view

service-common/src/main/java/com/java110/common/cmd/machine/GetQRcodeCmd.java 3.73 KB
88e030b7   王彪总   init project
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
  package com.java110.common.cmd.machine;
  
  import com.alibaba.fastjson.JSONObject;
  import com.java110.core.annotation.Java110Cmd;
  import com.java110.core.context.CmdContextUtils;
  import com.java110.core.context.ICmdDataFlowContext;
  import com.java110.core.event.cmd.Cmd;
  import com.java110.core.event.cmd.CmdEvent;
  import com.java110.dto.IotDataDto;
  import com.java110.dto.machine.MachineDto;
  import com.java110.dto.owner.OwnerAppUserDto;
  import com.java110.dto.owner.OwnerDto;
  import com.java110.dto.user.UserDto;
  import com.java110.intf.common.IMachineInnerServiceSMO;
  import com.java110.intf.common.IMachineV1InnerServiceSMO;
  import com.java110.intf.job.IDataBusInnerServiceSMO;
  import com.java110.intf.job.IIotInnerServiceSMO;
  import com.java110.intf.user.IOwnerAppUserV1InnerServiceSMO;
  import com.java110.intf.user.IOwnerInnerServiceSMO;
  import com.java110.intf.user.IUserInnerServiceSMO;
  import com.java110.intf.user.IUserV1InnerServiceSMO;
  import com.java110.utils.exception.CmdException;
  import com.java110.utils.util.Assert;
  import com.java110.utils.util.ListUtil;
  import com.java110.vo.ResultVo;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.ResponseEntity;
  
  import java.text.ParseException;
  import java.util.List;
  
  /**
   * 设备 二维码生成
   */
  @Java110Cmd(serviceCode = "/machine/getQRcode")
  public class GetQRcodeCmd extends Cmd {
  
      @Autowired
      IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
      @Autowired
      private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
  
      @Autowired
      private IMachineInnerServiceSMO machineV1InnerServiceSMOImpl;
  
      @Autowired
      private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
  
      @Autowired
      private IIotInnerServiceSMO iotInnerServiceSMOImpl;
  
      @Autowired
      private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
  
      @Override
      public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
          Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息");
          Assert.hasKeyAndValue(reqJson, "machineCode", "请求报文中未包含设备信息");
      }
  
      @Override
      public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
          ResponseEntity<String> responseEntity = null;
  
          String userId = CmdContextUtils.getUserId(context);
          OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
          ownerAppUserDto.setUserId(userId);
          List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  
          if(ListUtil.isNull(ownerAppUserDtos)){
              throw new CmdException("未认证业主");
          }
  
          String memberId = ownerAppUserDtos.get(0).getMemberId();
          if("-1".equals(memberId)){
              throw new CmdException("未认证业主");
          }
  
          //todo 如果是业主 限制开门次数
          OwnerDto ownerDto = new OwnerDto();
          ownerDto.setMemberId(memberId);
          ownerDto.setCommunityId(reqJson.getString("communityId"));
          List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
          if (ListUtil.isNull(ownerDtos)) {
              throw new CmdException("没有权限开门");
          }
  
          //todo 校验设备到底在不在,不在就报错!!!
  
          reqJson.put("link",ownerDtos.get(0).getLink());
  
          ResultVo resultVo = iotInnerServiceSMOImpl.postIotData(new IotDataDto("getAccessControlQrcodeBmoImpl", reqJson));
  
          if (resultVo.getCode() != ResultVo.CODE_OK) {
              throw new CmdException(resultVo.getMsg());
          }
  
          context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
      }
  }