| | |
| | | package com.ruoyi.other.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.AppUserShopClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.AppUserShop; |
| | | import com.ruoyi.account.api.model.UserAddress; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.feignClient.RemoteOrderGoodsClient; |
| | | import com.ruoyi.other.api.domain.Technician; |
| | | import com.ruoyi.other.api.domain.TechnicianSubscribe; |
| | | import com.ruoyi.other.enums.TechnicianStatus; |
| | | import com.ruoyi.other.mapper.TechnicianSubscribeMapper; |
| | | import com.ruoyi.other.service.TechnicianService; |
| | | import com.ruoyi.other.service.TechnicianSubscribeService; |
| | | import com.ruoyi.other.vo.TechnicianSubscribeVO; |
| | | import org.springframework.data.redis.connection.RedisZSetCommands; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.ZoneOffset; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RemoteOrderGoodsClient orderGoodsClient; |
| | | @Resource |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private AppUserShopClient appUserShopClient; |
| | | @Resource |
| | | private TechnicianService technicianService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop(Long shopId, Integer status) { |
| | | List<TechnicianSubscribeVO> list = technicianSubscribeMapper.getTechnicianSubscribeByUserAndShop(shopId, status); |
| | | public PageInfo<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop(Long shopId, Integer status, Integer pageCurr, Integer pageSize) { |
| | | PageInfo<TechnicianSubscribeVO> pageInfo = new PageInfo(pageCurr, pageSize); |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | List<AppUserShop> data = appUserShopClient.getAppUserShop(userid).getData(); |
| | | Optional<AppUserShop> first = data.stream().filter(s -> s.getShopId() == shopId.intValue() && s.getRoleType() == 3).findFirst(); |
| | | Integer technicianId = null; |
| | | if(first.isPresent()){ |
| | | //既是店员又是技师,需要取员工身份获取列表数据 |
| | | Optional<AppUserShop> first1 = data.stream().filter(s -> s.getShopId() == shopId.intValue() && s.getRoleType() != 3).findFirst(); |
| | | if(!first1.isPresent()){ |
| | | AppUserShop appUserShop = first.get(); |
| | | Technician technician = technicianService.getOne(new LambdaQueryWrapper<Technician>().eq(Technician::getAppUserId, appUserShop.getAppUserId()) |
| | | .eq(Technician::getShopId, appUserShop.getShopId()).eq(Technician::getDelFlag, 0).eq(Technician::getStatus, 2)); |
| | | if(null != technician){ |
| | | technicianId = technician.getId(); |
| | | } |
| | | } |
| | | } |
| | | List<TechnicianSubscribeVO> list = technicianSubscribeMapper.getTechnicianSubscribeByUserAndShop(pageInfo, shopId, status, technicianId); |
| | | for (TechnicianSubscribeVO technicianSubscribeVO : list) { |
| | | Long id = technicianSubscribeVO.getId(); |
| | | String id = technicianSubscribeVO.getId(); |
| | | TechnicianSubscribe technicianSubscribe = this.getById(id); |
| | | AppUser appUser = appUserClient.getAppUserById(technicianSubscribe.getAppUserId()); |
| | | technicianSubscribeVO.setUserName(appUser.getName()); |
| | | technicianSubscribeVO.setPhone(appUser.getPhone()); |
| | | if(null != appUser){ |
| | | technicianSubscribeVO.setUserName(appUser.getName()); |
| | | technicianSubscribeVO.setPhone(appUser.getPhone()); |
| | | } |
| | | Integer serviceMode = technicianSubscribeVO.getServiceMode(); |
| | | if(1 == serviceMode){ |
| | | UserAddress userAddress = JSON.parseObject(technicianSubscribeVO.getUserAddress(), UserAddress.class); |
| | | technicianSubscribeVO.setUserAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress()); |
| | | } |
| | | } |
| | | return list; |
| | | return pageInfo.setRecords(list); |
| | | } |
| | | @Override |
| | | public List<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop1(Long shopId, Integer status ,String phone, |
| | | String name, |
| | | Integer serviceMode) { |
| | | return technicianSubscribeMapper.getTechnicianSubscribeByUserAndShop1(shopId,status,phone,name,serviceMode); |
| | | public PageInfo<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop1(Long shopId, Integer status , String phone, |
| | | String name, |
| | | Integer serviceMode, Integer pageCurr, Integer pageSize) { |
| | | PageInfo<TechnicianSubscribeVO> pageInfo = new PageInfo(pageCurr, pageSize); |
| | | List<TechnicianSubscribeVO> technicianSubscribeByUserAndShop1 = technicianSubscribeMapper.getTechnicianSubscribeByUserAndShop1(pageInfo, shopId, status, phone, name, serviceMode); |
| | | if (StringUtils.isNotEmpty(name)){ |
| | | List<AppUser> nameIds = appUserClient.getAppUserByName(name).getData(); |
| | | List<Long> collect = nameIds.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | if (collect.isEmpty())collect.add(-1L); |
| | | technicianSubscribeByUserAndShop1 = technicianSubscribeByUserAndShop1.stream().filter(e -> collect.contains(e.getAppUserId())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | if (StringUtils.isNotEmpty(phone)){ |
| | | List<AppUser> phoneIds = appUserClient.getAppUserByPhone(phone).getData(); |
| | | List<Long> collect = phoneIds.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | if (collect.isEmpty())collect.add(-1L); |
| | | technicianSubscribeByUserAndShop1 = technicianSubscribeByUserAndShop1.stream().filter(e -> collect.contains(e.getAppUserId())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | for (TechnicianSubscribeVO technicianSubscribeVO : technicianSubscribeByUserAndShop1) { |
| | | AppUser appUser = appUserClient.getAppUserById(technicianSubscribeVO.getAppUserId()); |
| | | if(appUser!=null){ |
| | | technicianSubscribeVO.setUserName(appUser.getName()); |
| | | technicianSubscribeVO.setPhone(appUser.getPhone()); |
| | | } |
| | | } |
| | | return pageInfo.setRecords(technicianSubscribeByUserAndShop1); |
| | | } |
| | | @Override |
| | | public IPage<TechnicianSubscribeVO> getTechnicianSubscribeByUser(Page<TechnicianSubscribe> page, Long userId, Integer status) { |
| | | return technicianSubscribeMapper.getTechnicianSubscribeByUser(page, userId, status); |
| | | IPage<TechnicianSubscribeVO> technicianSubscribeByUser = technicianSubscribeMapper.getTechnicianSubscribeByUser(page, userId, status); |
| | | technicianSubscribeByUser.getRecords().forEach(technicianSubscribeVO -> { |
| | | UserAddress userAddress = JSON.parseObject(technicianSubscribeVO.getUserAddress(), UserAddress.class); |
| | | if (userAddress != null){ |
| | | technicianSubscribeVO.setUserAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress()); |
| | | } |
| | | }); |
| | | return technicianSubscribeByUser; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (subscribe.getOrderId() != null){ |
| | | orderGoodsClient.subscribe(subscribe.getOrderId(), subscribe.getTechnicianId()); |
| | | } |
| | | LocalDateTime subscribeTime = subscribe.getSubscribeTime(); |
| | | long deadlineTimestamp = subscribeTime.atZone(ZoneId.systemDefault()).toEpochSecond(); |
| | | redisTemplate.opsForZSet().add("delay_queue:subscribe", subscribe.getId().toString(), deadlineTimestamp); |
| | | //添加到redis有序队列中用于定时处理状态 |
| | | redisTemplate.opsForZSet().add("technician_subscribe", subscribe.getId().toString(), subscribe.getSubscribeTime().toEpochSecond(ZoneOffset.UTC)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 定时修改到期状态 |
| | | */ |
| | | @Override |
| | | public void taskEditStstus() { |
| | | long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); |
| | | Set<String> technician_subscribe = redisTemplate.opsForZSet().rangeByScore("technician_subscribe", 0, second); |
| | | if(technician_subscribe.size() > 0){ |
| | | List<TechnicianSubscribe> list = this.listByIds(technician_subscribe); |
| | | list.forEach(s->s.setStatus(3)); |
| | | this.updateBatchById(list); |
| | | redisTemplate.opsForZSet().remove("technician_subscribe", technician_subscribe.toArray()); |
| | | } |
| | | } |
| | | } |