2
sunshine
2024-11-05 69fd283ab500241947e8eac9192c39f4a6092b51
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
package com.nova.sankuai.controller.v1.platform;
 
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaResponse;
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaUtil;
import com.nova.sankuai.domain.entity.ApiCompany;
import com.nova.sankuai.domain.entity.ApiCompanyRecord;
import com.nova.sankuai.domain.entity.CustomerUser;
import com.nova.sankuai.domain.entity.ProtocolInfo;
import com.nova.sankuai.domain.enums.ApiCompanyCodeEnum;
import com.nova.sankuai.domain.vo.platform.ImportCustomerParameter;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.constants.ResultCode;
import com.nova.sankuai.infra.utils.ResultJson;
import com.nova.sankuai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Objects;
 
/**
 * <p>
 * 平台提供给其他系统调用的接口
 * </p>
 *
 * @author Zhangjc
 * @since 2021/11/18
 */
@Api(tags = "平台提供给其他系统调用的接口")
@RestController()
@RequestMapping("/api/v1/largecredit")
@RequiredArgsConstructor
@Slf4j
public class LargeCreditController {
 
    private final ICustomerService customerService;
 
    private final IChannelInfoService channelInfoService;
 
    private final IApiCompanyService apiCompanyService;
 
    private final IApiCompanyRecordService apiCompanyRecordService;
 
    private final IProtocolInfoService protocolInfoService;
 
    private final ICustomerUserService customerUserService;
 
    @ApiOperation("撞库测试")
    @GetMapping("/customCheck")
    public ResultJson<Boolean> checkCustomer(@RequestParam(name = "phone",required = false) String phone, @RequestParam(name = "phone_md5",required = false) String phoneMD5) {
        ResultJson<Boolean> result = new ResultJson<>(ResultCode.SUCCESS);
        if (StringUtils.isEmpty(phone) && StringUtils.isEmpty(phoneMD5)) {
            result.setData(false);
            result.setMsg("失败");
            result.setCode(ResultCode.BAD_REQUEST.getCode());
            return result;
        }
        CustomerUser customerUser = customerUserService.checkCustomer(phone, phoneMD5);
        if (customerUser == null) {
            result.setMsg("成功");
            result.setData(true);
        } else {
            result.setMsg("失败");
            result.setData(false);
        }
        return result;
    }
 
    @ApiOperation("爱助贷撞库测试")
    @GetMapping("/aizhudai/customCheck")
    public ResultJson<?> aizhudaiCustomCheck(@RequestParam String phone) {
        ApiCompany one = apiCompanyService.lambdaQuery()
                .eq(ApiCompany::getCompanyCode, ApiCompanyCodeEnum.XiaMenZhongHeYinHua.getCode())
                .eq(ApiCompany::getEnableFlag, 1).one();
        if (one != null) {
            Integer count = apiCompanyRecordService.lambdaQuery().eq(ApiCompanyRecord::getCompanyId, one.getId())
                    .eq(ApiCompanyRecord::getStatus, ApiCompanyRecord.SUCCESS).count();
            if (one.getCustomerNum() == null || count < one.getCustomerNum()) {
                XiaMenZhongHeYinHuaResponse checkResp = XiaMenZhongHeYinHuaUtil.phoneCheckExists(phone);
                if (Objects.equals(checkResp.getCode(), 0)) {
                    return ResultJson.ok(true);
                }
            }
        }
        return ResultJson.ok(false);
    }
 
    @ApiOperation("同步用户信息")
    @PostMapping("/customImport")
    public ResultJson<Boolean> importCustomer(@RequestBody @Valid ImportCustomerParameter parameter) {
        ResultJson<Boolean> result = new ResultJson<>(ResultCode.SUCCESS);
        CustomerUser customerUser = customerUserService.checkCustomer(parameter.getPhone(), null);
        if (customerUser != null) {
            log.info("撞库失败:手机号为:" + parameter.getPhone());
            result.setCode(ResultCode.SERVER_ERROR.getCode());
            result.setMsg("失败");
            result.setData(false);
            return result;
        }
        try {
            ResultJson checkResult = channelInfoService.checkChannel(parameter.getAppid(), parameter.toString());
            if (checkResult != null) {
                return checkResult;
            }
            log.info("导入其他平台用户开始,原始数据:" + parameter.toString());
            customerService.importCustomerFromPlatform(parameter);
            result.setMsg("成功");
            result.setData(true);
        } catch (CommonException e) {
            log.error("导入其他平台用户出错", e);
            result.setCode(ResultCode.SERVER_ERROR.getCode());
            result.setMsg(e.getMessage());
            result.setData(false);
        }
        return result;
    }
 
    @ApiOperation("爱助贷同步用户信息")
    @PostMapping("/aizhudai/customImport")
    public ResultJson aizhudaiCustomImport(@RequestBody @Valid ImportCustomerParameter parameter) {
        ResultJson<Boolean> result = new ResultJson<>(ResultCode.SUCCESS);
        try {
            ResultJson<?> checkResult = channelInfoService.checkChannel(parameter.getAppid(), parameter.toString());
            if (checkResult != null) {
                return checkResult;
            }
            log.info("爱助贷同步用户信息开始,原始数据:" + parameter);
            customerService.aizhudaiCustomImport(parameter);
            result.setMsg("成功");
            result.setData(true);
            log.info("爱助贷同步用户信息结束");
        } catch (CommonException e) {
            log.error("爱助贷同步用户信息出错", e);
            result.setCode(ResultCode.SERVER_ERROR.getCode());
            result.setMsg(e.getMessage());
            result.setData(false);
        }
        return result;
    }
 
    @GetMapping(value = "/getProtocol")
    @ApiOperation(value = "获取协议")
    public String getProtocol(String code) {
        ProtocolInfo protocolInfo = protocolInfoService.lambdaQuery().eq(ProtocolInfo::getCode, code).one();
        String content = "";
        if (protocolInfo != null) {
            content = String.format("<!DOCTYPE html><head><title></title><script>document.title=\"\\u200E\"</script></head><body>%s</body></html>", protocolInfo.getContent());
        }
        return content;
    }
}