Your Name
2023-01-20 3fc509eab4e928c8e50e024788603002bd03ec63
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
package com.java110.user.cmd.owner;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.client.OutRestTemplate;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.owner.OwnerAttrDto;
import com.java110.intf.user.IOwnerAttrInnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
 
import java.text.ParseException;
import java.util.List;
 
/***
 * 特定三方平台专用
 */
@Java110Cmd(serviceCode = "owner.syncThridOwner")
public class SyncThridOwnerCmd extends Cmd {
 
    @Autowired
    private IOwnerAttrInnerServiceSMO ownerAttrInnerServiceSMOImpl;
 
    @Autowired
    private OutRestTemplate outRestTemplate;
 
    private static final String getUserInfo = "https://lgtest.iflysec.com/visitorUser/api/user/userInfo";
 
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        Assert.hasKeyAndValue(reqJson, "token", "未包含token");
        Assert.hasKeyAndValue(reqJson, "userId", "未包含userId");
    }
 
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
 
        OwnerAttrDto ownerAttrDto = new OwnerAttrDto();
        ownerAttrDto.setSpecCd(OwnerAttrDto.SPEC_CD_EXT_OWNER_ID);
        ownerAttrDto.setValue(reqJson.getString("userId"));
        List<OwnerAttrDto> ownerAttrDtos = ownerAttrInnerServiceSMOImpl.queryOwnerAttrs(ownerAttrDto);
 
        String ownerId = "";
 
        if (ownerAttrDtos == null || ownerAttrDtos.size() < 1) {
            ownerId = saveOwner(reqJson);
        }
 
        context.setResponseEntity(ResultVo.createResponseEntity(ownerId));
    }
 
    /**
     * 添加业主
     * @param reqJson
     * @return
     */
    private String saveOwner(JSONObject reqJson) {
 
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization","Bearer "+reqJson.getString("token"));
 
        HttpEntity httpEntity = new HttpEntity("",headers);
 
        ResponseEntity<String> userInfo = outRestTemplate.exchange(getUserInfo+"?userId="+reqJson.getString("userId"), HttpMethod.GET,httpEntity,String.class);
 
 
        return "";
    }
}