xiaoyong931011
2021-07-15 4e427230f8b2b24cbeda4ca9d2be12c0df94df6e
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package com.xzx.gc.user.controller;
 
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.annotations.valid.Insert;
import com.xzx.gc.common.annotations.valid.InsertExtend;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.dto.SimplePage;
import com.xzx.gc.common.dto.log.OperationAppLog;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.common.utils.MqUtil;
import com.xzx.gc.common.utils.RedisUtil;
import com.xzx.gc.entity.UserInfo;
import com.xzx.gc.entity.UserTargetInfo;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.model.admin.TargetUserModel;
import com.xzx.gc.model.user.UserInfoVo;
import com.xzx.gc.model.user.UserReq;
import com.xzx.gc.user.dto.*;
import com.xzx.gc.user.mapper.AddressMapper;
import com.xzx.gc.user.mapper.OtherUserMapper;
import com.xzx.gc.user.mapper.UserTargetInfoMapper;
import com.xzx.gc.user.service.UserService;
import com.xzx.gc.user.service.UserTargetInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
 
@RestController
@Validated
@Slf4j
@Api(tags = "意向客户")
public class UserTargetInfoController extends BaseController {
 
 
    @Autowired
    private UserTargetInfoService userTargetInfoService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private UserTargetInfoMapper userTargetInfoMapper;
    @Autowired
    private OtherUserMapper otherUserMapper;
 
    @Autowired
    private MqUtil mqUtil;
 
 
 
    @ApiOperation(value = "二维码扫描录入意向客户")
    @PostMapping("/targetInfo/acode")
    public Result acode(@Validated(value = {InsertExtend.class}) @RequestBody UserTargetInfoAddDto userTargetInfoAddDto,HttpServletRequest request) {
 
        Result result = new Result();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(userTargetInfoAddDto.getNickName())) {
            if (!com.xzx.gc.common.utils.StringUtils.isBase64(userTargetInfoAddDto.getNickName())) {
                userTargetInfoAddDto.setNickName(Base64.encode(userTargetInfoAddDto.getNickName()));
            }
        }
        UserReq userReq = new UserReq();
        userReq.setMobilePhone(userTargetInfoAddDto.getMobile());
        List<UserInfoVo> list = userService.queryUserInfo(userReq);
        if (CollectionUtils.isEmpty(list)) {
            log.info("二维码扫描录入意向客户失败,该用户{}未注册", userReq.getMobilePhone());
        } else {
            UserTargetInfo userTargetInfo = new UserTargetInfo();
            BeanUtils.copyProperties(userTargetInfoAddDto, userTargetInfo);
            userTargetInfoService.acode(userTargetInfo);
 
//            String s = redisUtil.hget(Constants.REDIS_USER_KEY + "promoters:addr", userTargetInfoAddDto.getUserId());
//            if(StrUtil.isNotBlank(s)){
//                AddressDto addressDto = JSONUtil.toBean(s, AddressDto.class);
//                String lon = addressDto.getLongitude();
//                String lan= addressDto.getLatitude();
////                userTargetInfoService.updateTargetUserLon(userTargetInfoAddDto.getMobile(),lon,lan);
//            }
        }
 
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request),0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.USER_MODUL_NAME).operateAction("二维码扫描录入意向客户-"+userTargetInfoAddDto.getMobile()).build();
        mqUtil.sendApp(build);
 
        return result;
    }
 
    @ApiOperation(value = "录入意向客户")
    @PostMapping("/targetInfo")
    public Result add(@Validated(value = {Insert.class}) @RequestBody UserTargetInfoAddDto userTargetInfoAddDto,HttpServletRequest request) {
        Result result = new Result();
 
        UserTargetInfo userTargetInfo = new UserTargetInfo();
        BeanUtils.copyProperties(userTargetInfoAddDto, userTargetInfo);
 
        //提交时用户已注册(不是通过该推广员注册的或自己注册的)---提示:提交失该用户已注册
        UserReq userReq = new UserReq();
        userReq.setMobilePhone(userTargetInfo.getMobile());
        List<UserInfoVo> list = userService.queryUserInfo(userReq);
 
        //判断该手机号是不是已录入
        List<UserTargetInfo> byMobile1 = userTargetInfoService.findByMobile(userTargetInfo.getMobile());
        if(CollUtil.isNotEmpty(byMobile1)){
            result.setCode(-1);
            result.setMsg("手机号码已重复录入");
            return result;
        }
        UserTargetInfo byMobile = userTargetInfoService.findByMobileAndUserId(userTargetInfo.getMobile(), userTargetInfo.getUserId());
        if (byMobile != null) {
            result.setCode(-1);
            result.setMsg("该用户您已录入");
        } else {
            if (!CollectionUtils.isEmpty(list)) {
                //自己注册的。
                result.setCode(-1);
                result.setMsg("提交失败,该用户已注册");
            } else {
                userTargetInfo.setRegsterType(1);
                userTargetInfoService.add(userTargetInfo);
            }
        }
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request),0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.USER_MODUL_NAME).operateAction("录入意向客户-"+userTargetInfoAddDto.getMobile()).build();
        mqUtil.sendApp(build);
 
 
        return result;
    }
 
 
 
    @ApiOperation(value = "编辑客户信息")
    @PostMapping("/targetInfo/update")
    public Result update(@Validated @RequestBody UserTargetInfoEditDto userTargetInfoEditDto,HttpServletRequest request) {
        Result result = new Result();
 
 
        UserTargetInfo userTargetInfo = new UserTargetInfo();
        BeanUtils.copyProperties(userTargetInfoEditDto, userTargetInfo);
 
        if(Convert.toShort(1).equals(userTargetInfoEditDto.getTopFlag())){
            userTargetInfo.setTopFlagUser(request.getHeader("userId"));
        }
 
        UserTargetInfo userTargetInfo1 = userTargetInfoMapper.selectByPrimaryKey(userTargetInfoEditDto.getId());
 
        if (userTargetInfoEditDto.getOldMobile().equals(userTargetInfoEditDto.getMobile())) {
 
            if (userTargetInfo1.getRegsterType() != 1) {
                userTargetInfo.setMobile(null);
            }
            userTargetInfoService.update(userTargetInfo);
        } else {
 
            UserReq userReq = new UserReq();
            userReq.setMobilePhone(userTargetInfo.getMobile());
            List<UserInfoVo> list = userService.queryUserInfo(userReq);
            UserTargetInfo byMobile = userTargetInfoService.findByMobileAndUserId(userTargetInfo.getMobile(), userTargetInfo1.getUserId());
            if (byMobile != null) {
                result.setCode(-1);
                result.setMsg("该用户您已录入");
            } else {
                if (!CollectionUtils.isEmpty(list)) {
                    //自己注册的。
                    result.setCode(-1);
                    result.setMsg("提交失败,该用户已注册");
                } else {
                    if (userTargetInfo1.getRegsterType() != 1) {
                        userTargetInfo.setMobile(null);
                    }
                    userTargetInfoService.update(userTargetInfo);
                }
            }
 
 
        }
 
 
        String mobilePhone = userService.findOtherByUserId(getUserId(request),0);
        OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                .methodName(Constants.USER_MODUL_NAME).operateAction("编辑客户信息-"+userTargetInfoEditDto.getId()).build();
        mqUtil.sendApp(build);
 
        return result;
    }
 
 
    @ApiOperation(value = "我的客户")
    @PostMapping("/targetInfo/list")
    public Result<PageInfo<UserTargetInfo>> list(HttpServletRequest request,@RequestBody UserTargetInfoFindDto userTargetInfoFindDto) {
        Result result = new Result();
        PageInfo<UserTargetInfo> list = userTargetInfoService.find(userTargetInfoFindDto);
        result.setData(list);
        return result;
 
    }
 
    @ApiOperation(value = "我的客户地图")
    @PostMapping("/targetInfo/map")
    public Result<List<UserInfo>> map(HttpServletRequest request, @RequestBody UserTargetInfoMapDto  userTargetInfoMapDto) {
        Result result = new Result();
        List<UserInfo> list = userTargetInfoService.map(userTargetInfoMapDto);
        result.setData(list);
        return result;
 
    }
 
 
    @ApiOperation(value = "推荐搜索",notes = "extra传用户类型")
    @PostMapping("/targetInfo/recommend")
    public Result<PageInfo<UserTargetInfo>> recommend(@RequestBody SimplePage simplePage,HttpServletRequest request) {
        Result result = new Result();
        String partnerId = otherUserMapper.selectByPrimaryKey(getUserId(request)).getPartnerId();
        PageHelper.startPage(simplePage.getPageNo(),simplePage.getPageSize());
 
        //运营员身份推荐搜索 按时间推荐成交的所有用户   推广员则只推荐自己成交的
        String userId=null;
        if(CommonEnum.推广员.getValue().equals(simplePage.getExtra())){
            userId=getUserId(request);
        }
        List<UserTargetInfo> list = userTargetInfoService.findOrderUser(userId,partnerId);
        result.setData(list);
        return result;
    }
 
 
 
    @ApiOperation(value = "统计")
    @PostMapping("/targetInfo/statistic")
    public Result<UserTargetInfoStatisticResDto> statisticPost( @RequestBody  UserTargetInfoStatisticDto userTargetInfoStatisticDto) {
        Result result = new Result();
        UserTargetInfoStatisticResDto userTargetInfoStatisticResDto = userTargetInfoService.statistic(userTargetInfoStatisticDto);
        result.setData(userTargetInfoStatisticResDto);
 
        return result;
 
    }
 
    @PostMapping("/admin/queryListMap.json")
    @ResponseBody
    public JsonResult<Map<String, Object>> queryListMap(@RequestBody  TargetUserModel model){
        Map<String, Object> result = userTargetInfoService.queryListMap(model);
        return JsonResult.success(result);
 
    }
 
}