From c18ec3846c8483975de2224c1ecac9470e9b2804 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期三, 16 八月 2023 19:21:36 +0800 Subject: [PATCH] 同步代码 --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java | 187 +++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 175 insertions(+), 12 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java index cb78e30..4fde3d3 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java @@ -5,13 +5,16 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.user.core.util.ToolUtil; import com.supersavedriving.user.modular.system.dao.DriverMapper; -import com.supersavedriving.user.modular.system.model.Driver; -import com.supersavedriving.user.modular.system.model.DriverWork; -import com.supersavedriving.user.modular.system.service.IDriverService; -import com.supersavedriving.user.modular.system.service.IDriverWorkService; +import com.supersavedriving.user.modular.system.model.*; +import com.supersavedriving.user.modular.system.service.*; import com.supersavedriving.user.modular.system.util.GeodesyUtil; import com.supersavedriving.user.modular.system.util.RedisUtil; +import com.supersavedriving.user.modular.system.util.ResultUtil; +import com.supersavedriving.user.modular.system.util.UUIDUtil; +import com.supersavedriving.user.modular.system.util.huawei.OBSUtil; import com.supersavedriving.user.modular.system.util.mongodb.model.Location; +import com.supersavedriving.user.modular.system.util.weChat.WeChatUtil; +import com.supersavedriving.user.modular.system.warpper.DriverRegisterWarpper; import com.supersavedriving.user.modular.system.warpper.NearbyDriverWarpper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.geo.Circle; @@ -23,7 +26,10 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; +import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -45,6 +51,25 @@ @Autowired private RedisUtil redisUtil; + @Autowired + private IAppUserService appUserService; + + @Autowired + private WeChatUtil weChatUtil; + + @Autowired + private IBranchOfficeService branchOfficeService; + + @Autowired + private ISystemConfigService systemConfigService; + + @Autowired + private IAccountChangeDetailService accountChangeDetailService; + + + + + /** * 获取5公里范围内的司机 @@ -65,27 +90,165 @@ // 构造query对象 Query query = Query.query(Criteria.where("location").withinSphere(circle)); List<Location> locations = mongoTemplate.find(query, Location.class); -// System.err.println("附近空闲司机" + JSON.toJSONString(locations)); List<Integer> collect = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); + if(collect.size() == 0){ + return list; + } + List<Driver> drivers = this.selectList(new EntityWrapper<Driver>().in("id", collect).eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1)); + collect = drivers.stream().map(Driver::getId).collect(Collectors.toList()); + if(collect.size() == 0){ + return list; + } List<DriverWork> driverWorks = driverWorkService.selectList(new EntityWrapper<DriverWork>().in("driverId", collect).eq("status", 1)); for (DriverWork driverWork : driverWorks) { String value = redisUtil.getValue("DRIVER" + driverWork.getDriverId()); - if(ToolUtil.isNotEmpty(value)){ - NearbyDriverWarpper nearbyDriverWarpper = new NearbyDriverWarpper(); - nearbyDriverWarpper.setLonLat(value); - Map<String, Double> distance = GeodesyUtil.getDistance(value, lon + "," + lat); - nearbyDriverWarpper.setDistance(distance.get("WGS84") / 1000); - nearbyDriverWarpper.setDriverId(driverWork.getDriverId()); - list.add(nearbyDriverWarpper); + if(ToolUtil.isEmpty(value)){ + continue; } + NearbyDriverWarpper nearbyDriverWarpper = new NearbyDriverWarpper(); + nearbyDriverWarpper.setLonLat(value); + Map<String, Double> distance = GeodesyUtil.getDistance(value, lon + "," + lat); + nearbyDriverWarpper.setDistance(distance.get("WGS84") / 1000); + nearbyDriverWarpper.setDriverId(driverWork.getDriverId()); + list.add(nearbyDriverWarpper); } return list; } + /** + * 注册司机 + * @param uid + * @param driverRegisterWarpper + * @return + * @throws Exception + */ + @Override + public ResultUtil driverRegister(Integer uid, DriverRegisterWarpper driverRegisterWarpper) throws Exception { + Driver driver = this.selectOne(new EntityWrapper<Driver>().eq("phone", driverRegisterWarpper.getPhone()).ne("status", 3)); + if(null != driver && driver.getStatus() == 2){ + return ResultUtil.error("该手机账号已被冻结,请联系管理员。"); + } + if(null != driver && driver.getApprovalStatus() == 1){ + return ResultUtil.error("该手机账号正在审核中。"); + } + if(null != driver && driver.getApprovalStatus() == 2){ + return ResultUtil.error("该手机账号已审核通过,请直接登录。"); + } + + //账号审核拒绝后的处理 + if(null != driver && driver.getApprovalStatus() == 3){ + try { + driver = setDriverParamete(driver, driverRegisterWarpper); + }catch (Exception e){ + return ResultUtil.error(e.getMessage()); + } + this.updateAllColumnById(driver); + } + + AppUser appUser = appUserService.selectById(uid); + //新账号 + if(null == driver){ + driver = new Driver(); + driver.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); + try { + driver = setDriverParamete(driver, driverRegisterWarpper); + }catch (Exception e){ + return ResultUtil.error(e.getMessage()); + } + + driver.setCreateTime(new Date()); + driver.setInviterId(appUser.getInviterId()); + driver.setInviterType(appUser.getInviterType()); + this.insert(driver); + String s = wechatMiniProgramORCode(driver.getId()); + driver.setReferralCode(s); + this.updateById(driver); + + + //司机邀请注册奖励 + if(null != driver.getInviterId()){ + Driver driver1 = this.selectById(driver.getInviterId()); + SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 4)); + if(null != systemConfig){ + Integer num7 = JSON.parseObject(systemConfig.getContent()).getInteger("num7"); + if(num7 > 0){ + AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); + accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); + accountChangeDetail.setUserType(2); + accountChangeDetail.setUserId(driver1.getId()); + accountChangeDetail.setType(2); + accountChangeDetail.setChangeType(5); + accountChangeDetail.setOldData(driver1.getIntegral().doubleValue()); + driver1.setIntegral(driver1.getIntegral() + num7); + accountChangeDetail.setNewData(driver1.getIntegral().doubleValue()); + accountChangeDetail.setExplain("邀请司机注册奖励"); + accountChangeDetailService.saveData(accountChangeDetail); + this.updateById(driver1); + } + } + } + } + return ResultUtil.success(); + } + /** + * 组装个人信息 + * @param driver + * @param driverRegisterWarpper + * @return + */ + public Driver setDriverParamete(Driver driver, DriverRegisterWarpper driverRegisterWarpper) throws Exception{ + driver.setAvatar(driverRegisterWarpper.getAvatar()); + driver.setName(driverRegisterWarpper.getName()); + driver.setPhone(driverRegisterWarpper.getPhone()); + driver.setEmergencyContact(driverRegisterWarpper.getEmergencyContact()); + driver.setEmergencyPhone(driverRegisterWarpper.getEmergencyPhone()); + driver.setIdcardBack(driverRegisterWarpper.getIdcardBack()); + driver.setIdcardFront(driverRegisterWarpper.getIdcardFront()); + driver.setDriverLicense(driverRegisterWarpper.getDriverLicense()); + if(ToolUtil.isNotEmpty(driverRegisterWarpper.getFirstCertificateTime())){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + driver.setFirstCertificateTime(sdf.parse(driverRegisterWarpper.getFirstCertificateTime())); + } + //注册地 + String code = driverRegisterWarpper.getCode(); + BranchOffice branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("districtCode", code).eq("status", 1)); + if(null == branchOffice){ + branchOffice = branchOfficeService.selectOne(new EntityWrapper<BranchOffice>().eq("cityCode", code).eq("status", 1)); + if(null == branchOffice){ + throw new Exception("该区域无服务商"); + } + } + driver.setBranchOfficeId(branchOffice.getId()); + driver.setAgentId(branchOffice.getAgentId()); + driver.setProvinceCode(branchOffice.getProvinceCode()); + driver.setProvinceName(branchOffice.getProvinceName()); + driver.setCityName(branchOffice.getCityName()); + driver.setCityCode(branchOffice.getCityCode()); + driver.setAreaCode(branchOffice.getDistrictCode()); + driver.setAreaName(branchOffice.getDistrictName()); + if(null != driverRegisterWarpper.getInviterId()){ + driver.setInviterType(driverRegisterWarpper.getInviterType()); + driver.setInviterId(driverRegisterWarpper.getInviterId()); + } + driver.setApprovalStatus(1); + driver.setApprovalNotes(""); + driver.setApprovalTime(null); + driver.setApprovalUserId(null); + driver.setStatus(1); + driver.setSource(driverRegisterWarpper.getSource()); + return driver; + } + + //生成小程序二维码 + public String wechatMiniProgramORCode(Integer driverId) throws Exception{ + InputStream release = weChatUtil.getwxacodeunlimit("pages/index/index", "driverId=" + driverId, "release"); + String s = OBSUtil.putObjectToBucket(release, "driver_" + driverId); + return s; + } } -- Gitblit v1.7.1