wuxw
2024-09-12 7935724516cb699835da888d59cd5b7bec5c6049
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package com.java110.user.cmd.owner;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
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.core.factory.GenerateCodeFactory;
import com.java110.dto.account.AccountDto;
import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.dto.owner.OwnerDto;
import com.java110.dto.owner.OwnerRoomRelDto;
import com.java110.dto.user.UserDto;
import com.java110.intf.acct.IAccountInnerServiceSMO;
import com.java110.intf.user.*;
import com.java110.po.account.AccountPo;
import com.java110.po.owner.OwnerAppUserPo;
import com.java110.po.owner.OwnerPo;
import com.java110.po.user.UserPo;
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 org.springframework.beans.factory.annotation.Autowired;
 
import java.util.List;
 
/**
 * 业主房屋认证审核
 */
@Java110Cmd(serviceCode = "owner.auditAuthOwner")
public class AuditAuthOwnerCmd extends Cmd {
 
    @Autowired
    private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
 
    @Autowired
    private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
 
    @Autowired
    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
    @Autowired
    private IOwnerRoomRelInnerServiceSMO ownerRoomRelInnerServiceSMOImpl;
 
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Autowired
    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "appUserId", "绑定ID不能为空");
        Assert.hasKeyAndValue(reqJson, "state", "必填,请填写状态");
        Assert.hasKeyAndValue(reqJson, "remark", "必填,请填写审核说明");
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
 
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setAppUserId(reqJson.getString("appUserId"));
        ownerAppUserDto.setState(OwnerAppUserDto.STATE_AUDITING);
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
        Assert.listOnlyOne(ownerAppUserDtos, "审核记录不存在");
    }
 
    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
 
        String userId = CmdContextUtils.getUserId(context);
 
        String state = "";
        // todo 审核拒绝
        if ("1200".equals(reqJson.getString("state"))) {
            OwnerAppUserPo ownerAppUserPo = new OwnerAppUserPo();
            ownerAppUserPo.setAppUserId(reqJson.getString("appUserId"));
            ownerAppUserPo.setState(OwnerAppUserDto.STATE_AUDIT_ERROR);
            ownerAppUserPo.setRemark(reqJson.getString("remark"));
            int flag = ownerAppUserV1InnerServiceSMOImpl.updateOwnerAppUser(ownerAppUserPo);
            if (flag < 1) {
                throw new CmdException("修改绑定失败");
            }
            return;
        }
 
        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
        ownerAppUserDto.setAppUserId(reqJson.getString("appUserId"));
        ownerAppUserDto.setState(OwnerAppUserDto.STATE_AUDITING);
        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
 
        String memberId = "";
        // todo 如果是业主
        if(OwnerDto.OWNER_TYPE_CD_OWNER.equals(ownerAppUserDtos.get(0).getOwnerTypeCd())){
            memberId = bindOwner(ownerAppUserDtos.get(0));
        }else {
            //todo 如果是成员
            memberId = bindOwnerMember(ownerAppUserDtos.get(0),userId);
        }
 
 
        UserPo userPo = new UserPo();
        userPo.setName(ownerAppUserDtos.get(0).getAppUserName());
        userPo.setUserId(ownerAppUserDtos.get(0).getUserId());
        userV1InnerServiceSMOImpl.updateUser(userPo);
 
        OwnerAppUserPo ownerAppUserPo = new OwnerAppUserPo();
        ownerAppUserPo.setAppUserId(reqJson.getString("appUserId"));
        ownerAppUserPo.setState(OwnerAppUserDto.STATE_AUDIT_SUCCESS);
        ownerAppUserPo.setRemark(reqJson.getString("remark"));
        ownerAppUserPo.setMemberId(memberId);
        int flag = ownerAppUserV1InnerServiceSMOImpl.updateOwnerAppUser(ownerAppUserPo);
        if (flag < 1) {
            throw new CmdException("修改绑定失败");
        }
 
    }
 
    /**
     * 绑定成员
     * @param ownerAppUserDto
     * @return
     */
    private String bindOwnerMember(OwnerAppUserDto ownerAppUserDto,String userId) {
        // todo 查看 房屋是否有业主,如果没有添加业主
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setRoomId(ownerAppUserDto.getRoomId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        if(ListUtil.isNull(ownerRoomRelDtos)){
            throw new CmdException("房屋未绑定业主");
        }
 
        //todo 根据手机号和小区查询 家庭成员是否存在
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setOwnerId(ownerRoomRelDtos.get(0).getOwnerId());
        ownerDto.setLink(ownerAppUserDto.getLink());
        ownerDto.setCommunityId(ownerAppUserDto.getCommunityId());
        ownerDto.setOwnerTypeCds(new String[]{
                OwnerDto.OWNER_TYPE_CD_MEMBER
//                ,
//                OwnerDto.OWNER_TYPE_CD_RENTING,
//                OwnerDto.OWNER_TYPE_CD_OTHER,
//                OwnerDto.OWNER_TYPE_CD_TEMP
        });
        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
 
        if(!ListUtil.isNull(ownerDtos)){
            return ownerDtos.get(0).getMemberId();
        }
 
        OwnerPo ownerPo = new OwnerPo();
        ownerPo.setMemberId(GenerateCodeFactory.getGeneratorId("11"));
        ownerPo.setOwnerId(ownerRoomRelDtos.get(0).getOwnerId());
        ownerPo.setName(ownerAppUserDto.getAppUserName());
        ownerPo.setSex("0");
        ownerPo.setLink(ownerAppUserDto.getLink());
        ownerPo.setUserId(userId);
        ownerPo.setRemark("业主认证,审核添加");
        ownerPo.setOwnerTypeCd(ownerAppUserDto.getOwnerTypeCd());
        ownerPo.setCommunityId(ownerAppUserDto.getCommunityId());
        ownerPo.setIdCard(ownerAppUserDto.getIdCard());
        ownerPo.setState(OwnerDto.STATE_FINISH);
        ownerPo.setOwnerFlag(OwnerDto.OWNER_FLAG_TRUE);
        ownerPo.setAddress("无");
        ownerV1InnerServiceSMOImpl.saveOwner(ownerPo);
 
        return ownerPo.getMemberId();
    }
 
    /**
     * 绑定业主
     * @param ownerAppUserDto
     * @return
     */
    private String bindOwner(OwnerAppUserDto ownerAppUserDto) {
 
        // todo 查看 房屋是否有业主,如果没有添加业主
        OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
        ownerRoomRelDto.setRoomId(ownerAppUserDto.getRoomId());
        List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
 
        if(ListUtil.isNull(ownerRoomRelDtos)){
            throw new CmdException("房屋未绑定业主");
        }
 
        OwnerPo ownerPo = new OwnerPo();
        ownerPo.setLink(ownerAppUserDto.getLink());
       // ownerPo.setName(ownerAppUserDto.getAppUserName());
        ownerPo.setMemberId(ownerRoomRelDtos.get(0).getOwnerId());
        ownerPo.setOwnerId(ownerRoomRelDtos.get(0).getOwnerId());
        ownerV1InnerServiceSMOImpl.updateOwner(ownerPo);
 
        AccountDto accountDto = new AccountDto();
        accountDto.setObjId(ownerRoomRelDtos.get(0).getOwnerId());
        accountDto.setPartId(ownerRoomRelDtos.get(0).getCommunityId());
        List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
        if (ListUtil.isNull(accountDtos)) {
            return ownerRoomRelDtos.get(0).getOwnerId();
        }
 
        AccountPo accountPo = new AccountPo();
        accountPo.setoLink(ownerAppUserDto.getLink());
        accountPo.setAcctId(accountDtos.get(0).getAcctId());
        accountInnerServiceSMOImpl.updateAccount(accountPo);
 
 
        return ownerRoomRelDtos.get(0).getOwnerId();
 
    }
}