| 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);  | 
|   | 
|     }  | 
|   | 
| }  |