Sunshine
2024-11-04 7f1a0e49c1fe0c3f9f8a2493f30451d90b62ab64
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
package com.nova.sankuai.controller.v1;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nova.sankuai.domain.dto.BlankCustomerVisitDto;
import com.nova.sankuai.domain.dto.LoanMarketConfigDto;
import com.nova.sankuai.domain.dto.LoanSupermarketPageDto;
import com.nova.sankuai.domain.dto.LoanSupermarketVisitDto;
import com.nova.sankuai.domain.entity.LoanSupermarket;
import com.nova.sankuai.domain.entity.SystemParam;
import com.nova.sankuai.domain.vo.LoanSupermarketVo;
import com.nova.sankuai.domain.vo.SystemSwitchParamVo;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.constants.ResultCode;
import com.nova.sankuai.infra.utils.PageRequest;
import com.nova.sankuai.infra.utils.ResultJson;
import com.nova.sankuai.infra.utils.UserUtil;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
 * @author weikangdi
 */
@Api(tags = "贷款超市")
@RestController
@RequestMapping(value = "/api/v1/loanSupermarket")
@AllArgsConstructor
@Slf4j
public class LoanSupermarketController {
 
    private final ILoanSupermarketService supermarketService;
 
    private final IChannelInfoService channelInfoService;
 
    private final ICustomerService customerService;
 
    private final ISystemParamService systemParamService;
 
    private final IChannelLogService channelLogService;
 
    @PostMapping("/add")
    @ApiOperation(value = "新增贷款超市")
    @PreAuthorize("hasAuthority('loanSupermarket.add')")
    public ResultJson<Void> add(@RequestBody LoanSupermarket supermarket) {
        supermarketService.addLoanSupermarket(supermarket);
        return ResultJson.success();
    }
 
    @PutMapping("/edit")
    @ApiOperation(value = "编辑贷款超市")
    @PreAuthorize("hasAuthority('loanSupermarket.edit')")
    public ResultJson<Void> edit(@RequestBody LoanSupermarket supermarket) {
        supermarketService.edit(supermarket);
        return ResultJson.success();
    }
 
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除贷款超市")
    @PreAuthorize("hasAuthority('loanSupermarket.delete')")
    public ResultJson<Void> delete(@PathVariable("id") Long id) {
        supermarketService.delete(id);
        return ResultJson.success();
    }
 
    @GetMapping("/page")
    @ApiOperation(value = "分页获取贷款超市列表")
    @PreAuthorize("hasAuthority('loanSupermarket.page')")
    public ResultJson<IPage<LoanSupermarketVo>> page(PageRequest pageRequest, LoanSupermarketPageDto pageDto) {
        IPage<LoanSupermarketVo> page = supermarketService.pageModel(pageRequest, pageDto);
        return ResultJson.ok(page);
    }
 
    @GetMapping(value = "/list")
    @ApiOperation(value = "获取贷款超市列表")
    public ResultJson<List<LoanSupermarket>> list() {
        List<LoanSupermarket> result = supermarketService.getSupermarketList();
        return ResultJson.ok(result);
    }
 
    @GetMapping(value = "/addVisitRecord")
    @ApiOperation(value = "新增贷款超市访问记录")
    @PreAuthorize("hasAuthority('loanSupermarket.addVisitRecord')")
    public ResultJson<Void> addVisitRecord(LoanSupermarketVisitDto visitDto) {
        supermarketService.addVisitRecord(visitDto);
        return ResultJson.success();
    }
 
    @GetMapping(value = "/getSupermarketListByKey")
    @ApiOperation(value = "根据渠道Key获取可用贷超列表")
    public ResultJson<List<LoanSupermarketVo>> getSupermarketListByKey(String appId, HttpServletRequest request) {
        UserDetail user = UserUtil.getUser(request.getHeader("Authorization"));
        String phone = null;
        if (user != null) {
            phone = user.getPhone();
        }
        List<LoanSupermarketVo> result = channelInfoService.getSupermarketListByKey(appId, phone);
        return ResultJson.ok(result);
    }
 
    @GetMapping(value = "/addBlankVisitRecord")
    @ApiOperation(value = "新增空白客户贷超访问记录")
    @PreAuthorize("hasAuthority('loanSupermarket.addBlankVisitRecord')")
    public ResultJson<Void> addBlankVisitRecord(BlankCustomerVisitDto visitDto) {
        log.info("新增空白贷超客户访问记录开始,原始数据:" + visitDto.toString());
        if (StringUtils.isEmpty(visitDto.getPhone())) {
            throw new CommonException("客户手机号不能为空");
        }
        customerService.addBlankVisitRecord(visitDto);
        return ResultJson.success();
    }
 
    @GetMapping(value = "/updateLoanMarketArray")
    @ApiOperation(value = "更新贷超排列配置")
    @PreAuthorize("hasAuthority('loanSupermarket.updateLoanMarketArray')")
    public ResultJson<Void> updateLoanMarketArray(Integer type) {
        systemParamService.updateLoanMarketArray(type);
        return ResultJson.success();
    }
 
    @GetMapping(value = "/addJYDLoanMarketRecord")
    @ApiOperation(value = "新增APP贷超访问记录")
    public ResultJson<Void> addJYDLoanMarketRecord(Long loanMarkId, @AuthenticationPrincipal UserDetail userDetail) {
        if (loanMarkId == null) {
            throw new CommonException("贷款超市不能为空");
        }
        log.info("新增戒易贷贷超访问记录开始,原始贷超Id:" + loanMarkId + "用户信息" + userDetail.toString());
        channelLogService.addJYDLoanMarketRecord(loanMarkId, userDetail);
        return ResultJson.success();
    }
 
    @PutMapping("/editChannelConfig")
    @ApiOperation(value = "编辑贷超渠道配置")
    @PreAuthorize("hasAuthority('loanSupermarket.edit')")
    public ResultJson<Void> editChannelConfig(@RequestBody LoanMarketConfigDto configDto) {
        supermarketService.editChannelConfig(configDto);
        return ResultJson.success();
    }
 
 
    @GetMapping(value = "/checkLoanMarketHotLinkRely")
    @ApiOperation(value = "检测贷款超市直链引用")
    @PreAuthorize("hasAuthority('loanSupermarket.checkLoanMarketHotLinkRely')")
    public ResultJson<Boolean> checkLoanMarketHotLinkRely(Long loanMarketId) {
        boolean result = supermarketService.checkLoanMarketHotLinkRely(loanMarketId);
        return ResultJson.ok(result);
    }
 
    /**
     * 于2022.10.11新增:系统开关编辑
     * @param param
     * @return
     */
    @PutMapping("/systemSwitchConfig")
    @ApiOperation(value = "编辑系统开关")
//    @PreAuthorize("hasAuthority('systemSwitchConfig.switch')")
    public ResultJson<Void> systemSwitchConfig(@RequestBody SystemSwitchParamVo param) {
        SystemParam systemParam = new SystemParam();
        BeanUtils.copyProperties(param, systemParam);
        return systemParamService.updateById(systemParam) ? ResultJson.success() : ResultJson.failure(ResultCode.SERVER_ERROR);
    }
 
    /**
     * 于2022.10.11新增:获取系统开关
     * @return
     */
    @GetMapping("/getSystemSwitch")
    @ApiOperation(value = "获取系统开关")
//    @PreAuthorize("hasAuthority('systemSwitchConfig.switch')")
    public ResultJson<SystemSwitchParamVo> getSystemSwitch() {
        QueryWrapper<SystemParam> wrapper = new QueryWrapper<>();
        wrapper.ge("id", 0);
        SystemParam param = systemParamService.getOne(wrapper);
        SystemSwitchParamVo paramVo = new SystemSwitchParamVo();
        BeanUtils.copyProperties(param, paramVo);
        return ResultJson.ok(paramVo);
    }
}