Helius
2021-08-05 fdb91cc72f7cbe8c095a1ce6442c9259ff01ff06
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
package com.xzx.gc.user.controller;
 
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.annotations.PassToken;
import com.xzx.gc.common.constant.Constants;
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.entity.AddressLevelInfo;
import com.xzx.gc.entity.PartnerTarget;
import com.xzx.gc.user.mapper.PartnerTargetMapper;
import com.xzx.gc.user.service.AddressLevelService;
import com.xzx.gc.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
@Api(tags = "意向合伙人管理")
@RestController
@Slf4j
@Validated
public class PartnerTargetController extends BaseController {
 
 
    @Autowired
    private PartnerTargetMapper partnerTargetMapper;
 
    @Autowired
    private AddressLevelService addressLevelService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private MqUtil mqUtil;
 
 
 
    @ApiOperation( value = "新增意向合伙人")
    @PostMapping("/partnerTarget/add")
    @PassToken
    public Result partnerTargetAdd(HttpServletRequest request, @RequestBody PartnerTarget partnerTarget) {
 
 
        //根据名字和手机号去重
        PartnerTarget partnerTarget1=new PartnerTarget();
        partnerTarget1.setName(partnerTarget.getName());
        partnerTarget1.setMobile(partnerTarget.getMobile());
        int i = partnerTargetMapper.selectCount(partnerTarget1);
 
        if(i==0) {
            partnerTarget.setCreateTime(DateUtil.now());
            AddressLevelInfo addressLevelInfo = new AddressLevelInfo();
            addressLevelInfo.setLevel1Name(partnerTarget.getProviceName());
            addressLevelInfo.setLevel2Name(partnerTarget.getCityName());
            List<AddressLevelInfo> byAny = addressLevelService.findByAny(addressLevelInfo);
            if (CollUtil.isNotEmpty(byAny)) {
                partnerTarget.setProviceId(Convert.toInt(byAny.get(0).getLevel1Id()));
                partnerTarget.setCityId(Convert.toInt(byAny.get(0).getLevel2Id()));
            }
            partnerTargetMapper.insertSelective(partnerTarget);
 
            String mobilePhone = userService.findOtherByUserId(getUserId(request), 0);
            OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)
                    .methodName(Constants.USER_MODUL_NAME).operateAction("新增意向合伙人-" + partnerTarget.getId()).build();
            mqUtil.sendApp(build);
        }
        return Result.success(null);
    }
}