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