1098226878@qq.com
2021-12-28 745d27feae34022ccb708aba034123e08e4e9e14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.java110.user.bmo.rentingAppointment.impl;
 
import com.java110.dto.RoomDto;
import com.java110.dto.rentingAppointment.RentingAppointmentDto;
import com.java110.intf.user.IRentingAppointmentInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.user.bmo.rentingAppointment.IGetRentingAppointmentBMO;
import com.java110.vo.ResultVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service("getRentingAppointmentBMOImpl")
public class GetRentingAppointmentBMOImpl implements IGetRentingAppointmentBMO {
 
    @Autowired
    private IRentingAppointmentInnerServiceSMO rentingAppointmentInnerServiceSMOImpl;
 
 
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
 
    /**
     * @param rentingAppointmentDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(RentingAppointmentDto rentingAppointmentDto) {
 
 
        int count = rentingAppointmentInnerServiceSMOImpl.queryRentingAppointmentsCount(rentingAppointmentDto);
 
        List<RentingAppointmentDto> rentingAppointmentDtos = null;
        if (count > 0) {
            rentingAppointmentDtos = rentingAppointmentInnerServiceSMOImpl.queryRentingAppointments(rentingAppointmentDto);
 
            refreshEveryRoom(rentingAppointmentDtos);
        } else {
            rentingAppointmentDtos = new ArrayList<>();
        }
 
        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) rentingAppointmentDto.getRow()), count, rentingAppointmentDtos);
 
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
        return responseEntity;
    }
 
    private void refreshRoom(List<RentingAppointmentDto> rentingAppointmentDtos) {
 
        List<String> roomIds = new ArrayList<>();
 
        for (RentingAppointmentDto rentingAppointmentDto : rentingAppointmentDtos) {
            if (!StringUtils.isEmpty(rentingAppointmentDto.getAppointmentRoomId())) {
                roomIds.add(rentingAppointmentDto.getAppointmentRoomId());
            }
 
            if (!StringUtils.isEmpty(rentingAppointmentDto.getRoomId())) {
                roomIds.add(rentingAppointmentDto.getAppointmentRoomId());
            }
        }
 
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(roomIds.toArray(new String[roomIds.size()]));
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
 
 
        for (RoomDto tmpRoomDto : roomDtos) {
            for (RentingAppointmentDto rentingAppointmentDto : rentingAppointmentDtos) {
                if (tmpRoomDto.getRoomId().equals(rentingAppointmentDto.getAppointmentRoomId())) {
                    rentingAppointmentDto.setAppointmentRoomName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
                }
 
                if (tmpRoomDto.getRoomId().equals(rentingAppointmentDto.getRoomId())) {
                    rentingAppointmentDto.setRoomName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
                }
            }
        }
 
    }
 
    private void refreshEveryRoom(List<RentingAppointmentDto> rentingAppointmentDtos) {
 
        List<Map> roomInfos = new ArrayList<>();
 
        Map room = null;
        for (RentingAppointmentDto rentingAppointmentDto : rentingAppointmentDtos) {
            if (!StringUtils.isEmpty(rentingAppointmentDto.getAppointmentRoomId()) && !StringUtils.isEmpty(rentingAppointmentDto.getAppointmentCommunityId())) {
                room = new HashMap();
                room.put("roomId", rentingAppointmentDto.getAppointmentRoomId());
                room.put("communityId", rentingAppointmentDto.getAppointmentCommunityId());
                roomInfos.add(room);
            }
            if (!StringUtils.isEmpty(rentingAppointmentDto.getRoomId())&&!StringUtils.isEmpty(rentingAppointmentDto.getCommunityId())) {
                room = new HashMap();
                room.put("roomId", rentingAppointmentDto.getRoomId());
                room.put("communityId", rentingAppointmentDto.getCommunityId());
                roomInfos.add(room);
            }
        }
 
        if (roomInfos.size() < 1) {
            return;
        }
        List<Map> newRoomInfos = new ArrayList<>();
        Boolean hasRoom = false;
        for (Map roomMap : roomInfos) {
            hasRoom = false;
            for (Map newRoomInfo : newRoomInfos) {
                if (roomMap.get("roomId").equals(newRoomInfo.get("roomId"))) {
                    hasRoom = true;
                    break;
                }
            }
            if (!hasRoom) {
                newRoomInfos.add(roomMap);
            }
        }
        RoomDto roomDto = new RoomDto();
        for (Map newRoomInfo : newRoomInfos) {
            roomDto.setRoomId(newRoomInfo.get("roomId").toString());
            roomDto.setCommunityId(newRoomInfo.get("communityId").toString());
            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
 
            if (roomDtos == null || roomDtos.size() < 1) {
                continue;
            }
            RoomDto tmpRoomDto = roomDtos.get(0);
            newRoomInfo.put("roomName", tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
        }
 
 
 
        for (Map newRoomInfo : newRoomInfos) {
            for (RentingAppointmentDto rentingAppointmentDto : rentingAppointmentDtos) {
                if (newRoomInfo.get("roomId").equals(rentingAppointmentDto.getAppointmentRoomId())) {
                    rentingAppointmentDto.setAppointmentRoomName(newRoomInfo.get("roomName").toString());
                }
 
                if (newRoomInfo.get("roomId").equals(rentingAppointmentDto.getRoomId())) {
                    rentingAppointmentDto.setRoomName(newRoomInfo.get("roomName").toString());
                }
            }
        }
 
    }
 
}