OwnerCommunityCmd.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.annotation.Java110Transactional;
  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.intf.community.ICommunityInnerServiceSMO;
  13. import com.java110.intf.user.*;
  14. import com.java110.po.owner.OwnerAppUserPo;
  15. import com.java110.utils.exception.CmdException;
  16. import com.java110.utils.util.Assert;
  17. import com.java110.utils.util.BeanConvertUtil;
  18. import com.java110.vo.ResultVo;
  19. import org.slf4j.Logger;
  20. import com.java110.core.log.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. /**
  25. * 服务注册功能迁移
  26. */
  27. @Java110Cmd(serviceCode = "owner.ownerCommunity")
  28. public class OwnerCommunityCmd extends Cmd {
  29. private final static Logger logger = LoggerFactory.getLogger(OwnerCommunityCmd.class);
  30. @Autowired
  31. private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
  32. @Autowired
  33. private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
  34. @Autowired
  35. private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
  36. @Override
  37. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  38. Assert.hasKeyAndValue(reqJson, "link", "未包含联系电话");
  39. }
  40. @Override
  41. @Java110Transactional
  42. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  43. OwnerDto ownerDto = new OwnerDto();
  44. ownerDto.setLink(reqJson.getString("link"));
  45. List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
  46. if (ownerDtos == null || ownerDtos.size() < 1) {
  47. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  48. return;
  49. }
  50. List<String> communityIds = new ArrayList<>();
  51. for (OwnerDto tmpOwnerDto : ownerDtos) {
  52. communityIds.add(tmpOwnerDto.getCommunityId());
  53. tmpOwnerDto.setAppUserName(tmpOwnerDto.getName());
  54. }
  55. CommunityDto communityDto = new CommunityDto();
  56. communityDto.setState("1100");
  57. communityDto.setCommunityIds(communityIds.toArray(new String[communityIds.size()]));
  58. List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
  59. if(communityDtos == null || communityDtos.size()<1){
  60. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  61. return ;
  62. }
  63. for (OwnerDto tmpOwnerDto : ownerDtos) {
  64. for (CommunityDto tmpCommunityDto : communityDtos) {
  65. if (!tmpCommunityDto.getCommunityId().equals(tmpOwnerDto.getCommunityId())) {
  66. continue;
  67. }
  68. tmpOwnerDto.setCommunityName(tmpCommunityDto.getName());
  69. tmpOwnerDto.setsCommunityTel(tmpCommunityDto.getTel());
  70. tmpOwnerDto.setCommunityQrCode(tmpCommunityDto.getQrCode());
  71. }
  72. }
  73. //在判断 是否在 owner_app_user 表中
  74. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  75. ownerAppUserDto.setLink(reqJson.getString("link"));
  76. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserV1InnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  77. for (OwnerDto tmpOwnerDto : ownerDtos) {
  78. if (hasOwnerAppUser(tmpOwnerDto, ownerAppUserDtos)) {
  79. continue;
  80. }
  81. addOwnerAppUser(tmpOwnerDto, ownerAppUserDtos.get(0));
  82. }
  83. cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(ownerDtos));
  84. }
  85. /**
  86. * @param ownerDto
  87. * @param ownerAppUserDtos
  88. * @return
  89. */
  90. private boolean hasOwnerAppUser(OwnerDto ownerDto, List<OwnerAppUserDto> ownerAppUserDtos) {
  91. if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
  92. return false;
  93. }
  94. for (OwnerAppUserDto ownerAppUserDto : ownerAppUserDtos) {
  95. if (ownerDto.getLink().equals(ownerAppUserDto.getLink())
  96. && ownerDto.getMemberId().equals(ownerAppUserDto.getMemberId())) {
  97. return true;
  98. }
  99. }
  100. return false;
  101. }
  102. private void addOwnerAppUser(OwnerDto ownerDto, OwnerAppUserDto ownerAppUserDto) {
  103. OwnerAppUserPo ownerAppUserPo = BeanConvertUtil.covertBean(ownerAppUserDto, OwnerAppUserPo.class);
  104. //状态类型,10000 审核中,12000 审核成功,13000 审核失败
  105. ownerAppUserPo.setAppUserId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_appUserId));
  106. ownerAppUserPo.setMemberId(ownerDto.getMemberId());
  107. ownerAppUserPo.setCommunityName(ownerDto.getCommunityName());
  108. ownerAppUserPo.setCommunityId(ownerDto.getCommunityId());
  109. ownerAppUserPo.setAppUserName(ownerDto.getName());
  110. ownerAppUserPo.setIdCard(ownerDto.getIdCard());
  111. int flag = ownerAppUserV1InnerServiceSMOImpl.saveOwnerAppUser(ownerAppUserPo);
  112. if (flag < 1) {
  113. throw new CmdException("添加用户业主关系失败");
  114. }
  115. }
  116. }