GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
fujun
/
dxCard-service
Browse code
提交预约及开卡任务问题修复
master
1 parent
aac3186
commit
a61a6691bcfd5cb898c7f5b721474a591c64f6ce
YFJ
authored
7 days ago
Patch
Showing
1 changed file
jeecg-boot-module/jeecg-module-service/src/main/java/org/jeecg/modules/service/service/impl/AuthUserServiceImpl.java
Ignore Space
Show notes
View
jeecg-boot-module/jeecg-module-service/src/main/java/org/jeecg/modules/service/service/impl/AuthUserServiceImpl.java
package org.jeecg.modules.service.service.impl; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import jakarta.annotation.Resource; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.service.entity.AuthUser; import org.jeecg.modules.service.entity.GroupMembers; import org.jeecg.modules.service.entity.GroupRecord; import org.jeecg.modules.service.mapper.AuthUserMapper; import org.jeecg.modules.service.mapper.GroupMembersMapper; import org.jeecg.modules.service.mapper.GroupRecordMapper; import org.jeecg.modules.service.service.IAuthUserService; import org.jeecg.modules.service.vo.*; import org.jeecg.modules.system.entity.CardApplicationCustomers; import org.jeecg.modules.system.entity.CardDeliveryPerson; import org.jeecg.modules.system.mapper.CardApplicationCustomersMapper; import org.jeecg.modules.system.mapper.CardDeliveryPersonMapper; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * @Description: 微信用户档案 * @Author: jeecg-boot * @Date: 2025-09-28 * @Version: V1.0 */ @Service public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, AuthUser> implements IAuthUserService { @Resource private AuthUserMapper authUserMapper; @Resource private CardApplicationCustomersMapper cardApplicationCustomersMapper; @Resource private CardDeliveryPersonMapper cardDeliveryPersonMapper; @Resource private GroupMembersMapper groupMembersMapper; @Resource private GroupRecordMapper groupRecordMapper; @Override public RecommendUserVO recommendUser(String userId) { RecommendUserVO recommendUserVO = new RecommendUserVO(); recommendUserVO.setAmount(BigDecimal.ZERO); recommendUserVO.setDetails(new ArrayList<>()); //查询所有分销人为当前用户的数据 QueryWrapper<CardApplicationCustomers> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("distribution_customers_id", userId); queryWrapper.isNotNull("actual_commission"); List<CardApplicationCustomers> list = cardApplicationCustomersMapper.selectList(queryWrapper); for (CardApplicationCustomers cardApplicationCustomers : list){ CardApplicationVO cardApplicationVO = new CardApplicationVO(); cardApplicationVO.setId(cardApplicationCustomers.getId()); //查询办卡用户信息 AuthUser authUser = authUserMapper.selectById(cardApplicationCustomers.getCardApplicationId()); if(authUser != null){ cardApplicationVO.setAvatar(authUser.getAvatar()); cardApplicationVO.setName(authUser.getWxName()); cardApplicationVO.setReservationTime(DateUtil.format(cardApplicationCustomers.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); } cardApplicationVO.setAmount(cardApplicationCustomers.getActualCommission()); recommendUserVO.setAmount(recommendUserVO.getAmount().add(cardApplicationCustomers.getActualCommission())); recommendUserVO.getDetails().add(cardApplicationVO); } return recommendUserVO; } @Override public List<MyGroupMemberVO> myGroupMemberList(String userId) { List<MyGroupMemberVO> list = new ArrayList<>(); if (userId == null || userId.isEmpty()) { return list; } // 查询我的团成员信息 QueryWrapper<GroupMembers> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("client_id", userId); List<GroupMembers> groupMembers = groupMembersMapper.selectList(queryWrapper); if (groupMembers == null || groupMembers.isEmpty()) { return list; } // 提前收集所有需要查询的 ID Set<String> groupIds = groupMembers.stream() .map(GroupMembers::getGroupId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Map<String,GroupRecord> groupRecords = groupRecordMapper.selectList( new QueryWrapper<GroupRecord>().in("id", groupIds)).stream() .collect(Collectors.toMap(GroupRecord::getId, record -> record)); Set<String> clientIds = groupRecords.values().stream() .map(GroupRecord::getGroupLeaderId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Set<String> reservationIds = groupMembers.stream() .map(GroupMembers::getReservationId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Map<String, AuthUser> authUserMap = new HashMap<>(); Map<String, CardApplicationCustomers> reservationMap = new HashMap<>(); try { // 批量查询用户信息 if (!clientIds.isEmpty()) { QueryWrapper<AuthUser> userQueryWrapper = new QueryWrapper<>(); userQueryWrapper.in("id", clientIds); List<AuthUser> authUsers = authUserMapper.selectList(userQueryWrapper); authUserMap = authUsers.stream() .collect(Collectors.toMap(AuthUser::getId, user -> user)); } // 批量查询预约信息 if (!reservationIds.isEmpty()) { QueryWrapper<CardApplicationCustomers> reservationQueryWrapper = new QueryWrapper<>(); reservationQueryWrapper.in("id", reservationIds); List<CardApplicationCustomers> reservations = cardApplicationCustomersMapper.selectList(reservationQueryWrapper); reservationMap = reservations.stream() .collect(Collectors.toMap(CardApplicationCustomers::getId, r -> r)); } } catch (Exception e) { throw new RuntimeException("查询团成员相关信息失败", e); } // 组装 VO for (GroupMembers groupMember : groupMembers) { MyGroupMemberVO vo = new MyGroupMemberVO(); GroupRecord groupRecord = groupRecords.get(groupMember.getGroupId()); if (groupRecord != null){ AuthUser authUser = authUserMap.get(groupRecord.getGroupLeaderId()); if (authUser != null) { vo.setName(authUser.getWxName()); vo.setAvatar(authUser.getAvatar()); } } CardApplicationCustomers reservation = reservationMap.get(groupMember.getReservationId()); if (reservation != null) { vo.setReservationTime(DateUtil.format(reservation.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); vo.setPhone(reservation.getCardApplicationPhone()); } list.add(vo); } return list; } @Override public List<DispatchUserVO> dispatchUser(String userId) { List<DispatchUserVO> list = new ArrayList<>(); //查询办卡人员 AuthUser authUser = authUserMapper.selectById(userId); if (authUser == null){ throw new JeecgBootException("用户不存在"); } QueryWrapper<CardDeliveryPerson> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("status", "1"); queryWrapper.eq("phone", authUser.getWxPhone()); CardDeliveryPerson cardDeliveryPerson = cardDeliveryPersonMapper.selectOne(queryWrapper); if (cardDeliveryPerson == null){ throw new JeecgBootException("当前用户非办卡人员"); } QueryWrapper<CardApplicationCustomers> queryWrapper1 = new QueryWrapper<>(); queryWrapper1.eq("card_delivery_person", cardDeliveryPerson.getId()); List<CardApplicationCustomers> cardApplicationCustomers = cardApplicationCustomersMapper.selectList(queryWrapper1); for (CardApplicationCustomers cardApplicationCustomer : cardApplicationCustomers) { DispatchUserVO dispatchUserVO = new DispatchUserVO(); dispatchUserVO.setId(cardApplicationCustomer.getId()); dispatchUserVO.setName(cardApplicationCustomer.getCardApplicationName()); dispatchUserVO.setPhone(cardApplicationCustomer.getCardApplicationPhone()); dispatchUserVO.setReservationTime(DateUtil.format(cardApplicationCustomer.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); dispatchUserVO.setIsApplication(cardApplicationCustomer.getStatus().equals("2")); list.add(dispatchUserVO); } if (!list.isEmpty()){ //未办卡的排前面,按预约时间正序排列 // 在排序逻辑中添加null安全处理 list = list.stream() .sorted(Comparator.comparing(DispatchUserVO::getIsApplication, Comparator.nullsLast(Boolean::compareTo)) .thenComparing(DispatchUserVO::getReservationTime, Comparator.nullsLast(String::compareTo))) .collect(Collectors.toList()); } return list; } @Override public DispatchDetailVO dispatchUserDetail(String id) { DispatchDetailVO dispatchDetailVO = new DispatchDetailVO(); CardApplicationCustomers cardApplicationCustomers = cardApplicationCustomersMapper.selectById(id); if (cardApplicationCustomers == null){ throw new JeecgBootException("预约单不存在"); } dispatchDetailVO.setId(cardApplicationCustomers.getId()); dispatchDetailVO.setCreateTime(DateUtil.format(cardApplicationCustomers.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); dispatchDetailVO.setName(cardApplicationCustomers.getCardApplicationName()); dispatchDetailVO.setPhone(cardApplicationCustomers.getCardApplicationPhone()); dispatchDetailVO.setReservationTime(DateUtil.format(cardApplicationCustomers.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); dispatchDetailVO.setProvince(cardApplicationCustomers.getProvince()); dispatchDetailVO.setCity(cardApplicationCustomers.getCity()); dispatchDetailVO.setArea(cardApplicationCustomers.getArea()); dispatchDetailVO.setAddress(cardApplicationCustomers.getProvince() + cardApplicationCustomers.getCity() + cardApplicationCustomers.getArea() + cardApplicationCustomers.getAddress()); dispatchDetailVO.setTransactionPhone(cardApplicationCustomers.getTransactionPhone()); dispatchDetailVO.setAmount(cardApplicationCustomers.getAmount()); return dispatchDetailVO; } }
package org.jeecg.modules.service.service.impl; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import jakarta.annotation.Resource; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.service.entity.AuthUser; import org.jeecg.modules.service.entity.GroupMembers; import org.jeecg.modules.service.entity.GroupRecord; import org.jeecg.modules.service.mapper.AuthUserMapper; import org.jeecg.modules.service.mapper.GroupMembersMapper; import org.jeecg.modules.service.mapper.GroupRecordMapper; import org.jeecg.modules.service.service.IAuthUserService; import org.jeecg.modules.service.vo.*; import org.jeecg.modules.system.entity.CardApplicationCustomers; import org.jeecg.modules.system.entity.CardDeliveryPerson; import org.jeecg.modules.system.mapper.CardApplicationCustomersMapper; import org.jeecg.modules.system.mapper.CardDeliveryPersonMapper; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * @Description: 微信用户档案 * @Author: jeecg-boot * @Date: 2025-09-28 * @Version: V1.0 */ @Service public class AuthUserServiceImpl extends ServiceImpl<AuthUserMapper, AuthUser> implements IAuthUserService { @Resource private AuthUserMapper authUserMapper; @Resource private CardApplicationCustomersMapper cardApplicationCustomersMapper; @Resource private CardDeliveryPersonMapper cardDeliveryPersonMapper; @Resource private GroupMembersMapper groupMembersMapper; @Resource private GroupRecordMapper groupRecordMapper; @Override public RecommendUserVO recommendUser(String userId) { RecommendUserVO recommendUserVO = new RecommendUserVO(); recommendUserVO.setAmount(BigDecimal.ZERO); recommendUserVO.setDetails(new ArrayList<>()); //查询所有分销人为当前用户的数据 QueryWrapper<CardApplicationCustomers> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("distribution_customers_id", userId); queryWrapper.isNotNull("actual_commission"); List<CardApplicationCustomers> list = cardApplicationCustomersMapper.selectList(queryWrapper); for (CardApplicationCustomers cardApplicationCustomers : list){ CardApplicationVO cardApplicationVO = new CardApplicationVO(); cardApplicationVO.setId(cardApplicationCustomers.getId()); //查询办卡用户信息 AuthUser authUser = authUserMapper.selectById(cardApplicationCustomers.getCardApplicationId()); if(authUser != null){ cardApplicationVO.setAvatar(authUser.getAvatar()); cardApplicationVO.setName(authUser.getWxName()); cardApplicationVO.setReservationTime(DateUtil.format(cardApplicationCustomers.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); } cardApplicationVO.setAmount(cardApplicationCustomers.getActualCommission()); recommendUserVO.setAmount(recommendUserVO.getAmount().add(cardApplicationCustomers.getActualCommission())); recommendUserVO.getDetails().add(cardApplicationVO); } return recommendUserVO; } @Override public List<MyGroupMemberVO> myGroupMemberList(String userId) { List<MyGroupMemberVO> list = new ArrayList<>(); if (userId == null || userId.isEmpty()) { return list; } // 查询我的团成员信息 QueryWrapper<GroupMembers> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("client_id", userId); List<GroupMembers> groupMembers = groupMembersMapper.selectList(queryWrapper); if (groupMembers == null || groupMembers.isEmpty()) { return list; } // 提前收集所有需要查询的 ID Set<String> groupIds = groupMembers.stream() .map(GroupMembers::getGroupId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Map<String,GroupRecord> groupRecords = groupRecordMapper.selectList( new QueryWrapper<GroupRecord>().in("id", groupIds)).stream() .collect(Collectors.toMap(GroupRecord::getId, record -> record)); Set<String> clientIds = groupRecords.values().stream() .map(GroupRecord::getGroupLeaderId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Set<String> reservationIds = groupMembers.stream() .map(GroupMembers::getReservationId) .filter(Objects::nonNull) .collect(Collectors.toSet()); Map<String, AuthUser> authUserMap = new HashMap<>(); Map<String, CardApplicationCustomers> reservationMap = new HashMap<>(); try { // 批量查询用户信息 if (!clientIds.isEmpty()) { QueryWrapper<AuthUser> userQueryWrapper = new QueryWrapper<>(); userQueryWrapper.in("id", clientIds); List<AuthUser> authUsers = authUserMapper.selectList(userQueryWrapper); authUserMap = authUsers.stream() .collect(Collectors.toMap(AuthUser::getId, user -> user)); } // 批量查询预约信息 if (!reservationIds.isEmpty()) { QueryWrapper<CardApplicationCustomers> reservationQueryWrapper = new QueryWrapper<>(); reservationQueryWrapper.in("id", reservationIds); List<CardApplicationCustomers> reservations = cardApplicationCustomersMapper.selectList(reservationQueryWrapper); reservationMap = reservations.stream() .collect(Collectors.toMap(CardApplicationCustomers::getId, r -> r)); } } catch (Exception e) { throw new RuntimeException("查询团成员相关信息失败", e); } // 组装 VO for (GroupMembers groupMember : groupMembers) { MyGroupMemberVO vo = new MyGroupMemberVO(); GroupRecord groupRecord = groupRecords.get(groupMember.getGroupId()); if (groupRecord != null){ AuthUser authUser = authUserMap.get(groupRecord.getGroupLeaderId()); if (authUser != null) { vo.setName(authUser.getWxName()); vo.setAvatar(authUser.getAvatar()); } } CardApplicationCustomers reservation = reservationMap.get(groupMember.getReservationId()); if (reservation != null) { vo.setReservationTime(DateUtil.format(reservation.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); vo.setPhone(reservation.getCardApplicationPhone()); } list.add(vo); } return list; } @Override public List<DispatchUserVO> dispatchUser(String userId) { List<DispatchUserVO> list = new ArrayList<>(); //查询办卡人员 AuthUser authUser = authUserMapper.selectById(userId); if (authUser == null){ throw new JeecgBootException("用户不存在"); } QueryWrapper<CardDeliveryPerson> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("status", "1"); queryWrapper.eq("phone", authUser.getWxPhone()); CardDeliveryPerson cardDeliveryPerson = cardDeliveryPersonMapper.selectOne(queryWrapper); if (cardDeliveryPerson == null){ throw new JeecgBootException("当前用户非办卡人员"); } QueryWrapper<CardApplicationCustomers> queryWrapper1 = new QueryWrapper<>(); queryWrapper1.eq("card_delivery_person", cardDeliveryPerson.getId()); List<CardApplicationCustomers> cardApplicationCustomers = cardApplicationCustomersMapper.selectList(queryWrapper1); for (CardApplicationCustomers cardApplicationCustomer : cardApplicationCustomers) { DispatchUserVO dispatchUserVO = new DispatchUserVO(); dispatchUserVO.setId(cardApplicationCustomer.getId()); dispatchUserVO.setName(cardApplicationCustomer.getCardApplicationName()); dispatchUserVO.setPhone(cardApplicationCustomer.getCardApplicationPhone()); dispatchUserVO.setReservationTime(DateUtil.format(cardApplicationCustomer.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); dispatchUserVO.setIsApplication(cardApplicationCustomer.getStatus().equals("2")); list.add(dispatchUserVO); } if (!list.isEmpty()){ //未办卡的排前面,按预约时间正序排列 list = list.stream() .sorted(Comparator.comparing(DispatchUserVO::getIsApplication) .thenComparing(DispatchUserVO::getReservationTime)) .collect(Collectors.toList()); } return list; } @Override public DispatchDetailVO dispatchUserDetail(String id) { DispatchDetailVO dispatchDetailVO = new DispatchDetailVO(); CardApplicationCustomers cardApplicationCustomers = cardApplicationCustomersMapper.selectById(id); if (cardApplicationCustomers == null){ throw new JeecgBootException("预约单不存在"); } dispatchDetailVO.setId(cardApplicationCustomers.getId()); dispatchDetailVO.setCreateTime(DateUtil.format(cardApplicationCustomers.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); dispatchDetailVO.setName(cardApplicationCustomers.getCardApplicationName()); dispatchDetailVO.setPhone(cardApplicationCustomers.getCardApplicationPhone()); dispatchDetailVO.setReservationTime(DateUtil.format(cardApplicationCustomers.getReservationTime(), "yyyy-MM-dd HH:mm:ss")); dispatchDetailVO.setProvince(cardApplicationCustomers.getProvince()); dispatchDetailVO.setCity(cardApplicationCustomers.getCity()); dispatchDetailVO.setArea(cardApplicationCustomers.getArea()); dispatchDetailVO.setAddress(cardApplicationCustomers.getProvince() + cardApplicationCustomers.getCity() + cardApplicationCustomers.getArea() + cardApplicationCustomers.getAddress()); dispatchDetailVO.setTransactionPhone(cardApplicationCustomers.getTransactionPhone()); dispatchDetailVO.setAmount(cardApplicationCustomers.getAmount()); return dispatchDetailVO; } }
Show line notes below