AuthOwnerCmd.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package com.java110.user.cmd.owner;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.java110.core.annotation.Java110Cmd;
  4. import com.java110.core.context.CmdContextUtils;
  5. import com.java110.core.context.ICmdDataFlowContext;
  6. import com.java110.core.event.cmd.Cmd;
  7. import com.java110.core.event.cmd.CmdEvent;
  8. import com.java110.core.factory.GenerateCodeFactory;
  9. import com.java110.dto.community.CommunityDto;
  10. import com.java110.dto.owner.OwnerAppUserDto;
  11. import com.java110.dto.owner.OwnerDto;
  12. import com.java110.dto.owner.OwnerRoomRelDto;
  13. import com.java110.dto.room.RoomDto;
  14. import com.java110.dto.user.UserAttrDto;
  15. import com.java110.dto.user.UserDto;
  16. import com.java110.intf.community.ICommunityInnerServiceSMO;
  17. import com.java110.intf.community.IRoomV1InnerServiceSMO;
  18. import com.java110.intf.user.*;
  19. import com.java110.po.owner.OwnerAppUserPo;
  20. import com.java110.utils.exception.CmdException;
  21. import com.java110.utils.util.Assert;
  22. import com.java110.utils.util.ListUtil;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import java.text.ParseException;
  25. import java.util.List;
  26. @Java110Cmd(serviceCode = "owner.authOwner")
  27. public class AuthOwnerCmd extends Cmd {
  28. @Autowired
  29. private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
  30. @Autowired
  31. private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
  32. @Autowired
  33. private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
  34. @Autowired
  35. private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
  36. @Autowired
  37. private IOwnerRoomRelV1InnerServiceSMO ownerRoomRelV1InnerServiceSMOImpl;
  38. @Autowired
  39. private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
  40. @Autowired
  41. private IUserAttrV1InnerServiceSMO userAttrV1InnerServiceSMOImpl;
  42. /**
  43. * {"communityId":"2023052267100146","roomName":"1-1-888","roomId":"752024021967653523","link":"15509711111","ownerName":"张三","ownerTypeCd":"1001"}
  44. *
  45. * @param event 事件对象
  46. * @param context 请求报文数据
  47. * @param reqJson
  48. * @throws CmdException
  49. * @throws ParseException
  50. */
  51. @Override
  52. public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  53. Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区");
  54. Assert.hasKeyAndValue(reqJson, "roomName", "未包含房屋");
  55. Assert.hasKeyAndValue(reqJson, "roomId", "未包含房屋");
  56. Assert.hasKeyAndValue(reqJson, "link", "未包含手机号");
  57. Assert.hasKeyAndValue(reqJson, "ownerName", "未包含人员名称");
  58. Assert.hasKeyAndValue(reqJson, "ownerTypeCd", "未包含人员类型");
  59. //todo 根据手机号查询 是否已经认证过,如果认证过则不能再次认证
  60. // OwnerDto ownerDto = new OwnerDto();
  61. // ownerDto.setLink(reqJson.getString("link"));
  62. // ownerDto.setCommunityId(reqJson.getString("communityId"));
  63. // List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
  64. // if(ListUtil.isNull(ownerDtos)){
  65. // return;
  66. // }
  67. String userId = CmdContextUtils.getUserId(context);
  68. UserDto userDto = new UserDto();
  69. userDto.setUserId(userId);
  70. List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
  71. Assert.listOnlyOne(userDtos, "用户未登录");
  72. if (!userDtos.get(0).getTel().equals(reqJson.getString("link"))) {
  73. throw new CmdException("手机号错误,不是注册时的手机号");
  74. }
  75. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  76. ownerAppUserDto.setLink(reqJson.getString("link"));
  77. ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
  78. ownerAppUserDto.setStates(new String[]{
  79. OwnerAppUserDto.STATE_AUDITING,
  80. OwnerAppUserDto.STATE_AUDIT_SUCCESS
  81. });
  82. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  83. if (!ListUtil.isNull(ownerAppUserDtos)) {
  84. throw new CmdException("已存在认证关系,请勿重复认证");
  85. }
  86. RoomDto roomDto = new RoomDto();
  87. roomDto.setRoomId(reqJson.getString("roomId"));
  88. roomDto.setCommunityId(reqJson.getString("communityId"));
  89. List<RoomDto> roomDtos = roomV1InnerServiceSMOImpl.queryRooms(roomDto);
  90. Assert.listOnlyOne(roomDtos, "房屋不存在");
  91. if (!OwnerDto.OWNER_TYPE_CD_OWNER.equals(reqJson.getString("ownerTypeCd"))) {
  92. return;
  93. }
  94. OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
  95. ownerRoomRelDto.setRoomId(roomDtos.get(0).getRoomId());
  96. List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelV1InnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
  97. if (ListUtil.isNull(ownerRoomRelDtos)) {
  98. return;
  99. }
  100. ownerAppUserDto = new OwnerAppUserDto();
  101. ownerAppUserDto.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
  102. ownerAppUserDto.setCommunityId(reqJson.getString("communityId"));
  103. ownerAppUserDto.setStates(new String[]{
  104. OwnerAppUserDto.STATE_AUDITING,
  105. OwnerAppUserDto.STATE_AUDIT_SUCCESS
  106. });
  107. ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  108. if (!ListUtil.isNull(ownerAppUserDtos)) {
  109. throw new CmdException("业主已经被认证");
  110. }
  111. }
  112. /**
  113. * {"communityId":"2023052267100146","roomName":"1-1-888","roomId":"752024021967653523","link":"15509711111","ownerName":"张三","ownerTypeCd":"1001"}
  114. *
  115. * @param event 事件对象
  116. * @param context 数据上文对象
  117. * @param reqJson 请求报文
  118. * @throws CmdException
  119. * @throws ParseException
  120. */
  121. @Override
  122. public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
  123. String userId = CmdContextUtils.getUserId(context);
  124. CommunityDto communityDto = new CommunityDto();
  125. communityDto.setCommunityId(reqJson.getString("communityId"));
  126. List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
  127. Assert.listNotNull(communityDtos, "未包含小区信息");
  128. CommunityDto tmpCommunityDto = communityDtos.get(0);
  129. OwnerAppUserPo ownerAppUserPo = new OwnerAppUserPo();
  130. //状态类型,10000 审核中,12000 审核成功,13000 审核失败
  131. ownerAppUserPo.setState("12000");
  132. ownerAppUserPo.setAppTypeCd("10010");
  133. ownerAppUserPo.setAppUserId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_appUserId));
  134. ownerAppUserPo.setMemberId("-1");
  135. ownerAppUserPo.setCommunityName(tmpCommunityDto.getName());
  136. ownerAppUserPo.setCommunityId(tmpCommunityDto.getCommunityId());
  137. ownerAppUserPo.setAppUserName(reqJson.getString("ownerName"));
  138. ownerAppUserPo.setAppType("WECHAT");
  139. ownerAppUserPo.setLink(reqJson.getString("link"));
  140. ownerAppUserPo.setUserId(userId);
  141. ownerAppUserPo.setOpenId("-1");
  142. ownerAppUserPo.setRoomId(reqJson.getString("roomId"));
  143. ownerAppUserPo.setRoomName(reqJson.getString("roomName"));
  144. ownerAppUserPo.setOwnerTypeCd(reqJson.getString("ownerTypeCd"));
  145. UserAttrDto userAttrDto = new UserAttrDto();
  146. userAttrDto.setUserId(userId);
  147. userAttrDto.setSpecCd(UserAttrDto.SPEC_OPEN_ID);
  148. List<UserAttrDto> userAttrDtos = userAttrV1InnerServiceSMOImpl.queryUserAttrs(userAttrDto);
  149. if (!ListUtil.isNull(userAttrDtos)) {
  150. ownerAppUserPo.setOpenId(userAttrDtos.get(0).getValue());
  151. }
  152. ownerAppUserV1InnerServiceSMOImpl.saveOwnerAppUser(ownerAppUserPo);
  153. }
  154. }