Sunshine
2024-11-04 177f10973fd9bc1f0930369bb086ad9f0053440c
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
package com.nova.sankuai.controller.v1;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nova.sankuai.domain.dto.CustomerPageDto;
import com.nova.sankuai.domain.dto.InletFlowProportionDto;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.domain.enums.UserTypeEnum;
import com.nova.sankuai.domain.vo.InletFlowProportionListVo;
import com.nova.sankuai.domain.vo.common.MapVo;
import com.nova.sankuai.domain.vo.customer.CustomerDetail;
import com.nova.sankuai.domain.vo.customer.CustomerMechanismConfigVo;
import com.nova.sankuai.domain.vo.customer.CustomerVo;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.constants.ResultCode;
import com.nova.sankuai.infra.utils.MapUtil;
import com.nova.sankuai.infra.utils.PageRequest;
import com.nova.sankuai.infra.utils.ResultJson;
import com.nova.sankuai.security.UserDetail;
import com.nova.sankuai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.List;
import java.util.Map;
import java.util.Set;
 
/**
 * @author weikangdi
 */
@Api(tags = "客户管理")
@RestController
@RequestMapping(value = "/api/v1/customer")
@AllArgsConstructor
public class CustomerController {
 
    private final ICustomerService customerService;
 
    private final IChannelInfoService channelInfoService;
 
    private final IYiXinService yiXinService;
 
    private final IChannelLogService channelLogService;
 
    private final IMemberRightService memberRightService;
 
    @PostMapping(value = "/add")
    @ApiOperation(value = "H5新增客户")
    @PreAuthorize("hasAuthority('customer.add')")
    public ResultJson<String> add(@RequestBody Customer customer, String appId) {
        ResultJson checkResult = channelInfoService.checkChannel(appId, customer.toString());
        if (checkResult != null) {
            return checkResult;
        }
        String id = customerService.add(customer, appId);
        return ResultJson.ok(id);
    }
 
 
    @PostMapping(value = "/calculateMechanism")
    @ApiOperation(value = "获取匹配机构")
    @PreAuthorize("hasAuthority('customer.calculateMechanism')")
    public ResultJson<Customer> calculateMechanism(@RequestBody Customer customer) {
        customer = customerService.calculate(customer);
        return ResultJson.ok(customer);
    }
 
    @PostMapping("/uploadFile")
    @ApiOperation(value = "上传图片")
    @PreAuthorize("hasAuthority('customer.uploadFile')")
    public ResultJson<String> uploadFile(@RequestBody MultipartFile file) {
        String fileName = "";
        return ResultJson.ok(fileName);
    }
 
    @GetMapping("/searchPlace")
    @ApiOperation(value = "地址联想")
    @PreAuthorize("hasAuthority('customer.searchPlace')")
    public ResultJson<List<MapVo>> searchPlace(String query, String city) {
        if (StringUtils.isEmpty(query)) {
            return ResultJson.failure(ResultCode.SERVER_ERROR, "搜索关键字不能为空");
        }
        List<MapVo> place = MapUtil.searchPlace(query, city);
        return ResultJson.ok(place);
    }
 
    @PostMapping(value = "/addLargeCustomer")
    @ApiOperation(value = "新增大额H5客户")
    public ResultJson<CustomerMechanismConfigVo> addLargeCustomer(@RequestBody Customer customer, String code, String appId) {
        ResultJson checkResult = channelInfoService.checkChannel(appId, customer.toString());
        if (checkResult != null) {
            return checkResult;
        }
        CustomerMechanismConfigVo configVo = customerService.addLargeCustomer(customer, code, appId);
        return ResultJson.ok(configVo);
    }
 
 
    @GetMapping(value = "/pageCustomers")
    @ApiOperation(value = "分页查询客户信息")
    @PreAuthorize("hasAuthority('customer.pageCustomers')")
    public ResultJson<IPage<CustomerVo>> pageCustomers(CustomerPageDto customerPageDto, PageRequest pageRequest, @AuthenticationPrincipal UserDetail userDetail) {
        if (UserTypeEnum.USER.getCode().equals(userDetail.getType())) {
            customerPageDto.setMechanismId(userDetail.getId());
        } else {
            customerPageDto.setMechanismId(null);
        }
        IPage<CustomerVo> result = customerService.page(customerPageDto, pageRequest);
        return ResultJson.ok(result);
    }
 
    @GetMapping(value = "/getCustomerDetail/{id}")
    @ApiOperation(value = "获取客户详情")
    @PreAuthorize("hasAuthority('customer.getCustomerDetail')")
    public ResultJson<CustomerDetail> getCustomerDetail(@PathVariable("id") Long id) {
        CustomerDetail detail = customerService.getCustomerDetail(id);
        return ResultJson.ok(detail);
    }
 
    @GetMapping("/updateMatchMechanism")
    @ApiOperation(value = "更新大额H5的匹配机构")
    public ResultJson<Void> updateMatchMechanism(Long customerId, Long mechanismId) {
        if (customerId == null || mechanismId == null) {
            throw new CommonException("客户Id和机构Id不能为空");
        }
        customerService.updateMatchMechanism(customerId, mechanismId);
        return ResultJson.success();
    }
 
    @GetMapping("/assignMechanism")
    @ApiOperation(value = "重新分配机构")
    @PreAuthorize("hasAuthority('customer.assignMechanism')")
    public ResultJson<Void> assignMechanism(Long customerId, Long mechanismId) {
        if (customerId == null || mechanismId == null) {
            throw new CommonException("客户Id和机构Id不能为空");
        }
        customerService.assignMechanism(customerId, mechanismId);
        return ResultJson.success();
    }
 
    @GetMapping("/checkMechanism")
    @ApiOperation(value = "检测机构是否达到上限")
    @PreAuthorize("hasAuthority('customer.checkMechanism')")
    public ResultJson<Void> checkMechanism(Long mechanismId) {
        Set<String> result = customerService.checkMechanism(mechanismId);
        if (result != null && result.size() > 0) {
            return ResultJson.failure(ResultCode.SERVER_ERROR, result);
        }
        return ResultJson.success();
    }
 
    @PostMapping(value = "/yxAuditCallback")
    @ApiOperation(value = "绿地授信审批结果通知")
    public String yxAuditCallback(@RequestBody Map<String, String> request) throws Exception {
        String result = yiXinService.yxAuditCallback(request);
        return result;
    }
 
    @PostMapping(value = "/getInletFlowProportion")
    @ApiOperation(value = "查看入口流量占比")
    @PreAuthorize("hasAuthority('inletFlowProportion.getInletFlowProportion')")
    public ResultJson<List<InletFlowProportionListVo>> getInletFlowProportion(@RequestBody InletFlowProportionDto inletFlowProportionDto) {
        List<InletFlowProportionListVo> inletFlowProportion = channelLogService.getInletFlowProportion(inletFlowProportionDto);
        return ResultJson.ok(inletFlowProportion);
    }
 
 
    @ApiOperation(value = "会员权益兑换")
    @GetMapping("/membershipInterests")
    @PreAuthorize("hasAuthority('customer.membershipInterests')")
    public ResultJson<String> backTongBaoMembershipInterests(@RequestParam String phone) {
        String result = memberRightService.manualMembershipInterests(phone);
        return ResultJson.ok(result);
    }
 
    @PostMapping(value = "/yxLoanApplyCallback")
    @ApiOperation(value = "绿地用信结果通知")
    public String yxLoanApplyCallback(@RequestBody Map<String, String> request) throws Exception {
        String result = yiXinService.yxLoanApplyCallback(request);
        return result;
    }
 
    @PostMapping(value = "/yxRepayPlanCallback")
    @ApiOperation(value = "绿地还款计划变动通知")
    public String yxRepayApplyCallback(@RequestBody Map<String, String> request) throws Exception {
        String result = yiXinService.yxRepayPlanCallback(request);
        return result;
    }
 
 
    @PostMapping(value = "/yxRepayResultCallback")
    @ApiOperation(value = "绿地还款结果通知")
    public String yxRepayResultCallback(@RequestBody Map<String, String> request) throws Exception {
        String result = yiXinService.yxRepayResultCallback(request);
        return result;
    }
 
}