fix
Helius
2021-08-05 8bbb027dc36b3f3c7f2d505fc75180261fb4d640
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
package com.xzx.gc.user.service;
 
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.constant.RedisKeyConstant;
import com.xzx.gc.common.constant.UserEnum;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.utils.RedisUtil;
import com.xzx.gc.common.utils.TokenUtil;
import com.xzx.gc.entity.*;
import com.xzx.gc.model.user.UserGatherListParDTO;
import com.xzx.gc.model.user.UserInfoVo;
import com.xzx.gc.user.mapper.UserGatherInfoMapper;
import org.apache.tomcat.jni.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
@Transactional
public class UserGatherInfoService {
 
    @Autowired
    private UserGatherInfoMapper userGatherInfoMapper;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Autowired
    private AddressService addressService;
 
    @Autowired
    private OrderService orderService;
 
    public void add(UserGatherInfo userGatherInfo) {
        userGatherInfo.setRegistTime(DateUtil.now());
        userGatherInfo.setDelFlag(Constants.DEL_NOT_FLAG);
        userGatherInfo.setIsProhibit(false);
        userGatherInfo.setUserType(CommonEnum.集货员.getValue());
        userGatherInfo.setRegistType(Convert.toShort(CommonEnum.正常注册用户.getValue()));
        userGatherInfoMapper.insertSelective(userGatherInfo);
    }
 
    public UserGatherInfo findById(String id){
        return userGatherInfoMapper.selectByPrimaryKey(id);
    }
 
    public void updateById(UserGatherInfo userGatherInfo){
        userGatherInfoMapper.updateByPrimaryKeySelective(userGatherInfo);
    }
 
    public UserGatherInfo findByMobileForBidden(String mobile) {
        UserGatherInfo otherUserInfo=new UserGatherInfo();
        otherUserInfo.setDelFlag(Constants.DEL_NOT_FLAG);
        otherUserInfo.setMobilePhone(mobile);
        return userGatherInfoMapper.selectOne(otherUserInfo);
    }
 
    /**
     * 根据经纬度查找最近500米的集货员
     * @param lon
     * @param lat
     * @return
     */
    public UserGatherInfo findNearestByLocation(String lon,String lat){
        return userGatherInfoMapper.findNearestByLocation(lon,lat);
    }
 
    public List<UserGatherInfo> list(UserGatherListParDTO userGatherListParDTO) {
        //注意申请表会出现多条记录 需要根据时间排序后取第一条
        return userGatherInfoMapper.list(userGatherListParDTO);
    }
 
    public void deleteById(String id) {
 
        //删除集货员前判断是否有单
        int fwzNum = orderService.findFwzNum(id);
        if(fwzNum>0){
            throw new RestException("还有未完成的订单");
        }
 
        UserGatherInfo userGatherInfo=new UserGatherInfo();
        userGatherInfo.setUserId(id);
        userGatherInfo.setDelFlag(Constants.DEL_FLAG);
        userGatherInfoMapper.updateByPrimaryKeySelective(userGatherInfo);
 
        UserInfo userInfo=new UserInfo();
        userInfo.setUserId(id);
        userInfo.setUserType(CommonEnum.普通用户.getValue());
        userService.updateById(userInfo);
 
        //拿货地址是用来判断是否集货员地址的标识
        List<AddressInfo> allByUserId = addressService.findAllByUserId(id);
        for (AddressInfo addressInfo : allByUserId) {
            if(StrUtil.isNotBlank(addressInfo.getReceiveAddress())){
                addressInfo.setReceiveAddress(null);
                addressService.updateAllById(addressInfo);
            }
        }
 
        //更新缓存
        redisUtil.del(RedisKeyConstant.TOKEN+id);
 
 
    }
}