Blame view

service-user/src/main/java/com/java110/user/cmd/owner/QueryAppOwnerMembersCmd.java 4.38 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  package com.java110.user.cmd.owner;
  
  import com.alibaba.fastjson.JSONObject;
  import com.java110.core.annotation.Java110Cmd;
  import com.java110.core.context.ICmdDataFlowContext;
  import com.java110.core.event.cmd.Cmd;
  import com.java110.core.event.cmd.CmdEvent;
  import com.java110.dto.file.FileRelDto;
  import com.java110.dto.owner.OwnerAppUserDto;
  import com.java110.dto.owner.OwnerDto;
  import com.java110.dto.privilege.BasePrivilegeDto;
  import com.java110.intf.common.IFileRelInnerServiceSMO;
  import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
  import com.java110.intf.user.IOwnerAppUserV1InnerServiceSMO;
  import com.java110.intf.user.IOwnerInnerServiceSMO;
  import com.java110.intf.user.IOwnerV1InnerServiceSMO;
  import com.java110.utils.cache.MappingCache;
  import com.java110.utils.constant.MappingConstant;
  import com.java110.utils.exception.CmdException;
  import com.java110.utils.util.Assert;
  import com.java110.utils.util.BeanConvertUtil;
  import com.java110.utils.util.ListUtil;
  import com.java110.utils.util.StringUtil;
  import com.java110.vo.ResultVo;
  import com.java110.vo.api.ApiOwnerDataVo;
  import com.java110.vo.api.ApiOwnerVo;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  
  import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  /**
   * 查询app 成员
   */
  @Java110Cmd(serviceCode = "owner.queryAppOwnerMembers")
  public class QueryAppOwnerMembersCmd extends Cmd {
  
      @Autowired
      private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
  
      @Autowired
      private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
  
      @Autowired
      private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
  
      @Autowired
      private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
  
      @Override
      public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
          Assert.jsonObjectHaveKey(reqJson, "communityId", "请求中未包含communityId信息");
          // Assert.jsonObjectHaveKey(reqJson, "ownerTypeCd", "请求中未包含ownerTypeCd信息");
          if (!reqJson.containsKey("page")) {
              reqJson.put("page", 1);
          }
          if (!reqJson.containsKey("row")) {
              reqJson.put("row", 50);
          }
  
          String userId = context.getReqHeaders().get("user-id");
  
          OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
          ownerAppUserDto.setUserId(userId);
          ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
          List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  
          if (ListUtil.isNull(ownerAppUserDtos)) {
              throw new CmdException("未绑定业主");
          }
  
          String memberId = "";
          for (OwnerAppUserDto tmpOwnerAppUserDto : ownerAppUserDtos) {
              if ("-1".equals(tmpOwnerAppUserDto.getMemberId())) {
                  continue;
              }
  
              memberId = tmpOwnerAppUserDto.getMemberId();
          }
  
          if (StringUtil.isEmpty(memberId)) {
              throw new CmdException("未绑定业主");
          }
  
          OwnerDto ownerDto = new OwnerDto();
          ownerDto.setCommunityId(reqJson.getString("communityId"));
          ownerDto.setMemberId(memberId);
          List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
  
          Assert.listOnlyOne(ownerDtos, "业主不存在");
  
          reqJson.put("ownerId", ownerDtos.get(0).getOwnerId());
  
      }
  
      @Override
      public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
          OwnerDto ownerDto = BeanConvertUtil.covertBean(reqJson, OwnerDto.class);
          ownerDto.setOwnerTypeCd(OwnerDto.OWNER_TYPE_CD_MEMBER);
  
          int row = reqJson.getInteger("row");
          //查询总记录数
          int total = ownerInnerServiceSMOImpl.queryOwnersMemberCount(ownerDto);
  
          List<OwnerDto> ownerDtoList = null;
          if (total > 0) {
              ownerDtoList = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
          } else {
              ownerDtoList = new ArrayList<>();
          }
  
          ResponseEntity<String> responseEntity = ResultVo.createResponseEntity((int) Math.ceil((double) total / (double) row), total, ownerDtoList);
          context.setResponseEntity(responseEntity);
      }
  }