feat: 查询用户预约时增加显示团队负责人信息
This commit is contained in:
parent
bbf03e2254
commit
1b2753c9a3
@ -2,8 +2,16 @@ package github.benjamin.equipreservebackend.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import github.benjamin.equipreservebackend.entity.User;
|
import github.benjamin.equipreservebackend.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.MapKey;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserMapper extends BaseMapper<User> {
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
@MapKey("teamId")
|
||||||
|
Map<Long, User> selectLeaderByTeamIds(List<Long> teamIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,10 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(Device::getId, Function.identity()));
|
.collect(Collectors.toMap(Device::getId, Function.identity()));
|
||||||
|
|
||||||
|
List<Long> teamIds = deviceNameMap.values().stream().map(Device::getTeamId).toList();
|
||||||
|
|
||||||
|
Map<Long, User> teamLeaderMap = userMapper.selectLeaderByTeamIds(teamIds);
|
||||||
|
|
||||||
// 获取设备管理员信息
|
// 获取设备管理员信息
|
||||||
List<Long> deviceAdminIDs = reservations.getRecords().stream()
|
List<Long> deviceAdminIDs = reservations.getRecords().stream()
|
||||||
.map(Reservation::getDeviceAdminId)
|
.map(Reservation::getDeviceAdminId)
|
||||||
@ -93,7 +97,6 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|
||||||
List<UserReservationVO> vos;
|
List<UserReservationVO> vos;
|
||||||
Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>()
|
Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>()
|
||||||
.in(User::getId, deviceAdminIDs))
|
.in(User::getId, deviceAdminIDs))
|
||||||
@ -101,7 +104,7 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
.collect(Collectors.toMap(User::getId, Function.identity()));
|
.collect(Collectors.toMap(User::getId, Function.identity()));
|
||||||
|
|
||||||
vos = reservations.getRecords().stream()
|
vos = reservations.getRecords().stream()
|
||||||
.map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap))
|
.map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap, teamLeaderMap))
|
||||||
.toList();
|
.toList();
|
||||||
res.setRecords(vos);
|
res.setRecords(vos);
|
||||||
return res;
|
return res;
|
||||||
|
@ -22,12 +22,13 @@ public class UserReservationVO {
|
|||||||
private LocalDate startTime;
|
private LocalDate startTime;
|
||||||
private LocalDate endTime;
|
private LocalDate endTime;
|
||||||
private String statusLabel;
|
private String statusLabel;
|
||||||
|
private String deviceLeaderName;
|
||||||
|
private String deviceLeaderContact;
|
||||||
private String deviceAdminName;
|
private String deviceAdminName;
|
||||||
private String deviceAdminContact;
|
private String deviceAdminContact;
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
|
public UserReservationVO(Reservation r, Map<Long, Device> deviceMap, Map<Long, User> deviceAdminMap, Map<Long, User> teamLeaderMap) {
|
||||||
public UserReservationVO(Reservation r, Map<Long, Device> deviceMap, Map<Long, User> deviceAdminMap) {
|
|
||||||
this.reservationId = r.getId().toString();
|
this.reservationId = r.getId().toString();
|
||||||
this.deviceName = deviceMap.get(r.getDeviceId()).getName();
|
this.deviceName = deviceMap.get(r.getDeviceId()).getName();
|
||||||
this.startTime = r.getStartTime();
|
this.startTime = r.getStartTime();
|
||||||
@ -41,6 +42,14 @@ public class UserReservationVO {
|
|||||||
this.deviceAdminName = "该管理员不存在,请联系设备相关人员";
|
this.deviceAdminName = "该管理员不存在,请联系设备相关人员";
|
||||||
this.deviceAdminContact = "";
|
this.deviceAdminContact = "";
|
||||||
}
|
}
|
||||||
|
User teamLeader = teamLeaderMap.get(deviceMap.get(r.getDeviceId()).getTeamId());
|
||||||
|
if (Objects.nonNull(teamLeader)) {
|
||||||
|
this.deviceLeaderName = teamLeader.getName();
|
||||||
|
this.deviceLeaderContact = teamLeader.getPhone();
|
||||||
|
} else {
|
||||||
|
this.deviceLeaderName = "该负责人不存在,请联系设备相关人员";
|
||||||
|
this.deviceLeaderContact = "";
|
||||||
|
}
|
||||||
this.createdTime = r.getCreatedTime();
|
this.createdTime = r.getCreatedTime();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
16
src/main/resources/mapper/UserMapper.xml
Normal file
16
src/main/resources/mapper/UserMapper.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="github.benjamin.equipreservebackend.mapper.UserMapper">
|
||||||
|
|
||||||
|
<select id="selectLeaderByTeamIds" resultType="github.benjamin.equipreservebackend.entity.User">
|
||||||
|
SELECT u.* FROM users u LEFT JOIN user_roles ur ON u.id = ur.user_id
|
||||||
|
where ur.role_id = 2
|
||||||
|
AND u.team_id in
|
||||||
|
<foreach collection="teamIds" open="(" separator="," close=")" item="teamId">
|
||||||
|
#{teamId}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user