| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.errand.constant.AppUserStatusConstant; |
| | | import com.ruoyi.errand.constant.DelFlagConstant; |
| | | import com.ruoyi.errand.constant.IsFirstLoginConstant; |
| | | import com.ruoyi.errand.constant.IsFirstOrder; |
| | | import com.ruoyi.errand.domain.*; |
| | | import com.ruoyi.errand.mapper.*; |
| | | import com.ruoyi.errand.object.dto.sys.AddCourierDTO; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | private AppUserMapper appUserMapper; |
| | | @Autowired |
| | | private CommunityMapper communityMapper; |
| | | @Autowired |
| | | private AppUserService appUserService; |
| | | @Autowired |
| | | private CourierMapper courierMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public IPage<CourierOrderListVO> getCourierOrderList(Integer pageNum, Integer pageSize, Integer orderStatus) { |
| | | AppUser appuser = (AppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| | | if(appuser.getCourierId()==null){ |
| | | throw new ServiceException("您已不是跑腿员"); |
| | | } |
| | | IPage<CourierOrderListVO> page=new Page<>(pageNum, pageSize); |
| | | return this.baseMapper.getCourierOrderList(page,orderStatus,appuser.getCourierId()); |
| | | CommunityCourier communityCourier = communityCourierMapper.selectOne(new LambdaQueryWrapper<CommunityCourier>().eq(CommunityCourier::getCourierId, appuser.getCourierId())); |
| | | if (communityCourier==null){ |
| | | throw new ServiceException("您还未绑定需代办的小区"); |
| | | } |
| | | return this.baseMapper.getCourierOrderList(page,appuser.getCourierId(),orderStatus,communityCourier.getCommunityId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | AppUser appuser = (AppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| | | if (appuser.getCourierId()==null){ |
| | | throw new ServiceException("您还不是跑腿员"); |
| | | } |
| | | Courier courier = courierMapper.selectById(appuser.getCourierId()); |
| | | if (courier==null || courier.getDelFlag().equals(DelFlagConstant.DELETE)){ |
| | | throw new ServiceException("绑定的跑腿账号已失效"); |
| | | } |
| | | if (courier.getStatus().equals(0)){ |
| | | throw new ServiceException("跑腿账号已在离职中,不能接单"); |
| | | } |
| | | CommunityCourier communityCourier = communityCourierMapper.selectOne(new LambdaQueryWrapper<CommunityCourier>().eq(CommunityCourier::getCourierId, appuser.getCourierId())); |
| | | if(communityCourier==null){ |
| | |
| | | |
| | | //修改订单状态 |
| | | order.setOrderStatus(2); |
| | | order.setCourierId(appuser.getCourierId()); |
| | | order.setReceivingTime(LocalDateTime.now()); |
| | | orderMapper.updateById(order); |
| | | |
| | |
| | | List<Order> orderList = orderMapper.selectList(new LambdaUpdateWrapper<Order>() |
| | | .eq(Order::getCourierId, x.getId()) |
| | | .eq(Order::getDelFlag,DelFlagConstant.UNDELETE) |
| | | .eq(Order::getPayMethod,2)); |
| | | .notIn(Order::getOrderStatus,Arrays.asList(1,3)) |
| | | .eq(Order::getPayStatus,2)); |
| | | if (orderList!=null&& !orderList.isEmpty()){ |
| | | //当天接单量 |
| | | LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); |
| | |
| | | List<Order> orderList = orderMapper.selectList(new LambdaUpdateWrapper<Order>() |
| | | .eq(Order::getCourierId, id) |
| | | .eq(Order::getDelFlag,DelFlagConstant.UNDELETE) |
| | | .eq(Order::getPayMethod,2)); |
| | | .notIn(Order::getOrderStatus,Arrays.asList(1,3)) //未接单 取消掉的不要 |
| | | .eq(Order::getPayStatus,2)); |
| | | if (orderList!=null&& !orderList.isEmpty()){ |
| | | //当天接单量 |
| | | LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); |
| | |
| | | |
| | | return vo; |
| | | } |
| | | |
| | | private static final String DEFAULT_AVATAR_URL = "http://qijishenghuiyuan.obs.cn-southwest-2.myhuaweicloud.com/admin/aedfbbb41280471f8d9fa7905298b65f.png"; |
| | | @Override |
| | | public void add(AddCourierDTO addCourierDTO) { |
| | | AppUser appUser = appUserMapper.selectOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, addCourierDTO.getPhone()). |
| | | eq(AppUser::getDelFlag, DelFlagConstant.UNDELETE)); |
| | | if (appUser == null) { |
| | | throw new ServiceException("请先注册小程序"); |
| | | appUser=new AppUser(); |
| | | appUser.setPhone(addCourierDTO.getPhone()); |
| | | appUser.setDelFlag(DelFlagConstant.UNDELETE); |
| | | appUser.setStatus(AppUserStatusConstant.NORMAL); |
| | | appUser.setAvatar(DEFAULT_AVATAR_URL); |
| | | appUser.setFirstLogin(IsFirstLoginConstant.YES); |
| | | appUser.setFirstOrder(IsFirstOrder.YES); |
| | | appUser.setName(addCourierDTO.getPhone()); |
| | | } |
| | | //手机号是否存在 |
| | | Courier courier = this.getBaseMapper().selectOne(new LambdaQueryWrapper<Courier>().eq(Courier::getPhone, addCourierDTO.getPhone()) |
| | |
| | | //保存跑腿人员 |
| | | Courier courier1 = new Courier(); |
| | | BeanUtils.copyProperties(addCourierDTO, courier1); |
| | | courier1.setCreateTime(LocalDateTime.now()); |
| | | this.save(courier1); |
| | | //绑定小区 |
| | | if (addCourierDTO.getCommunityId() != null) { |
| | |
| | | communityCourier.setCourierId(courier1.getId()); |
| | | communityCourierMapper.insert(communityCourier); |
| | | } |
| | | appUser.setCourierId(courier1.getId()); |
| | | appUserService.saveOrUpdate(appUser); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | //是否更改了手机号 |
| | | if (!courier.getPhone().equals(editCourierDTO.getPhone())) { |
| | | //更改了手机号 |
| | | /*//更改了手机号 |
| | | AppUser appUser = appUserMapper.selectOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, editCourierDTO.getPhone()). |
| | | eq(AppUser::getDelFlag, DelFlagConstant.UNDELETE)); |
| | | if (appUser == null) { |
| | |
| | | .eq(Courier::getDelFlag, DelFlagConstant.UNDELETE)); |
| | | if (courier1 != null ) { |
| | | throw new ServiceException("该手机号的跑腿员已存在"); |
| | | } |
| | | }*/ |
| | | throw new ServiceException("不能修该手机号"); |
| | | } |
| | | //是否更改了小区 |
| | | CommunityCourier communityCourier = communityCourierMapper.selectOne(new LambdaQueryWrapper<CommunityCourier>().eq(CommunityCourier::getCourierId, editCourierDTO.getId())); |
| | | if (communityCourier != null) { |
| | | //之前有绑定小区 |
| | | if (editCourierDTO.getCommunityId() == null) { |
| | | //现在没有绑定,之前的要解绑 |
| | | //现在没有绑定 |
| | | extracted(courier.getId(), "该跑腿员还有订单未完成,无法变更小区"); |
| | | //解绑之前的 |
| | | communityCourierMapper.deleteById(communityCourier.getId()); |
| | | |
| | | }else if (!editCourierDTO.getCommunityId().equals(communityCourier.getCommunityId())) { |
| | | //现在绑定了,不和之前的一样 |
| | | extracted(courier.getId(), "该跑腿员还有订单未完成,无法变更小区"); |
| | | //绑定的小区是否存在 |
| | | Community community = communityMapper.selectById(editCourierDTO.getCommunityId()); |
| | | if (community == null|| Objects.equals(community.getDelFlag(), DelFlagConstant.DELETE)) { |
| | |
| | | } |
| | | //修改 |
| | | communityCourier.setCommunityId(editCourierDTO.getCommunityId()); |
| | | communityCourier.setCourierId(editCourierDTO.getId()); |
| | | communityCourier.setUpdateTime(LocalDateTime.now()); |
| | | communityCourierMapper.updateById(communityCourier); |
| | | } |
| | | }else { |
| | | //之前没绑定 现在绑定 |
| | | if (editCourierDTO.getCommunityId() != null) { |
| | | Community community = communityMapper.selectById(editCourierDTO.getCommunityId()); |
| | | if (community == null|| Objects.equals(community.getDelFlag(), DelFlagConstant.DELETE)) { |
| | | throw new ServiceException("绑定的小区不存在"); |
| | | } |
| | | //绑定的小区是否被别人绑定了 |
| | | CommunityCourier communityCourier1 = communityCourierMapper.selectOne(new LambdaQueryWrapper<CommunityCourier>() |
| | | .eq(CommunityCourier::getCommunityId, editCourierDTO.getCommunityId())); |
| | | if (communityCourier1 != null) { |
| | | throw new ServiceException("该小区已被绑定"); |
| | | } |
| | | //修改 |
| | | communityCourier = new CommunityCourier(); |
| | | communityCourier.setCommunityId(editCourierDTO.getCommunityId()); |
| | | communityCourier.setCourierId(editCourierDTO.getId()); |
| | | communityCourier.setUpdateTime(LocalDateTime.now()); |
| | | communityCourierMapper.insert(communityCourier); |
| | | } |
| | | } |
| | | //修改 |
| | |
| | | |
| | | } |
| | | |
| | | private void extracted(Integer courier, String message) { |
| | | //判断该小区订单是否完成 |
| | | Long count = orderMapper.selectCount(new LambdaUpdateWrapper<Order>() |
| | | .eq(Order::getCourierId, courier) |
| | | .eq(Order::getPayStatus, 2) |
| | | .eq(Order::getDelFlag, DelFlagConstant.UNDELETE) |
| | | .eq(Order::getOrderStatus, 2)); |
| | | if (count > 0) { |
| | | throw new ServiceException(message); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void froze(Integer id) { |
| | | Courier courier= this.getById(id); |
| | | if (courier == null||courier.getDelFlag().equals(DelFlagConstant.DELETE)) { |
| | | throw new ServiceException("该跑腿员不存在"); |
| | | } |
| | | //如果是离职,判断是否还有订单在进行中 |
| | | if (courier.getStatus().equals(1)){ |
| | | extracted(id, "该跑腿员还有订单未完成,无法离职"); |
| | | } |
| | | courier.setStatus(courier.getStatus()==0?1:0); |
| | | courier.setUpdateTime(LocalDateTime.now()); |
| | |
| | | if (courier == null||courier.getDelFlag().equals(DelFlagConstant.DELETE)) { |
| | | throw new ServiceException("该跑腿员不存在"); |
| | | } |
| | | |
| | | //判断是否还有订单在进行中 |
| | | extracted(id, "该跑腿员还有订单未完成,无法注销"); |
| | | |
| | | //判断跑腿员是否绑定了小区 |
| | | CommunityCourier communityCourier = communityCourierMapper.selectOne(new LambdaQueryWrapper<CommunityCourier>().eq(CommunityCourier::getCourierId, id)); |
| | | if (communityCourier != null) { |
| | | communityCourierMapper.deleteById(communityCourier.getId());//解绑 |
| | | } |
| | | //判断用户是否存在,删除用户中跑腿员的信息 |
| | | AppUser appUser = appUserMapper.selectOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getCourierId, id).eq(AppUser::getDelFlag, DelFlagConstant.UNDELETE)); |
| | | UpdateWrapper<AppUser> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", appUser.getId()) |
| | | .set("courier_id", null); |
| | | |
| | | appUserMapper.update(null, updateWrapper); |
| | | |
| | | //删除跑腿员 |
| | | courier.setDelFlag(DelFlagConstant.DELETE); |
| | | courier.setUpdateTime(LocalDateTime.now()); |
| | | this.updateById(courier); |
| | |
| | | |
| | | private static long countByTimeRange(List<Order> orderList, LocalDateTime start, LocalDateTime end) { |
| | | return orderList.stream() |
| | | .filter(order -> order.getOrderTime() != null) // 过滤空时间 |
| | | .filter(order -> order.getOrderTime().isAfter(start.minusNanos(1))) // 大于等于 start |
| | | .filter(order -> order.getOrderTime().isBefore(end.plusNanos(1))) // 小于等于 end |
| | | .filter(order -> order.getReceivingTime() != null) // 过滤空时间 |
| | | .filter(order -> order.getReceivingTime().isAfter(start.minusNanos(1))) // 大于等于 start |
| | | .filter(order -> order.getReceivingTime().isBefore(end.plusNanos(1))) // 小于等于 end |
| | | .count(); |
| | | } |
| | | |