Commit 86ba4804 by 吕明尚

修改房间分页,因排序和LIMIT冲突导致数据异常

parent 990b5277
package share.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import share.common.annotation.Log;
import share.common.core.controller.BaseController;
import share.common.core.domain.AjaxResult;
import share.common.core.page.TableDataInfo;
import share.common.enums.BusinessType;
import share.common.utils.poi.ExcelUtil;
import share.system.domain.Device;
import share.system.domain.SRoom;
import share.system.domain.vo.SRoomVo;
import share.system.service.ISRoomService;
import share.common.utils.poi.ExcelUtil;
import share.common.core.page.TableDataInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 房间Controller
......@@ -43,9 +36,7 @@ public class SRoomController extends BaseController
@GetMapping("/list")
public TableDataInfo list(SRoom sRoom)
{
startPage();
List<SRoom> list = sRoomService.selectSRoomList(sRoom);
return getDataTable(list);
return sRoomService.pageList(sRoom);
}
/**
......
package share.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import share.common.core.page.TableDataInfo;
import share.system.domain.Device;
import share.system.domain.SPack;
import share.system.domain.SRoom;
......@@ -110,4 +111,6 @@ public interface ISRoomService extends IService<SRoom>
List<SRoomVo> convertDoListToVoList(List<SRoom> roomList);
List<SRoom> roomNameByIds(List<Long> longs);
TableDataInfo pageList(SRoom sRoom);
}
......@@ -7,6 +7,9 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.core.page.PageDomain;
import share.common.core.page.TableDataInfo;
import share.common.core.page.TableSupport;
import share.common.enums.*;
import share.common.exception.base.BaseException;
import share.common.utils.DateUtils;
......@@ -81,11 +84,19 @@ public class SRoomServiceImpl extends ServiceImpl<SRoomMapper, SRoom> implements
return new ArrayList<>();
}
List<Long> storeIds = roomList.stream().map(SRoom::getStoreId).collect(Collectors.toList());
List<Long> roomIds = roomList.stream().map(SRoom::getId).collect(Collectors.toList());
List<Map> storeList = sStoreService.optionList(storeIds);
List<SRoomPack> list = roomPackService.list(new LambdaQueryWrapper<SRoomPack>().in(SRoomPack::getRoomId, roomIds));
Map<Long, List<Long>> listMap = list.stream().collect(Collectors.groupingBy(SRoomPack::getRoomId, Collectors.mapping(SRoomPack::getPackId, Collectors.toList())));
List<SPack> packList = packService.list(new LambdaQueryWrapper<SPack>().eq(SPack::getType, YesNoEnum.yes.getIndex()));
Map<Long, List<SPack>> packMap = new HashMap<>();
//循环listMap
for (Map.Entry<Long, List<Long>> entry : listMap.entrySet()) {
packMap.put(entry.getKey(), packList.stream().filter(o -> entry.getValue().contains(o.getId())).collect(Collectors.toList()));
}
roomList.forEach(o -> {
List<Long> roomId = roomPackService.selectPackListByRoomId(o.getId());
o.setPackIds(roomId.stream().map(String::valueOf).collect(Collectors.joining(",")));
o.setPackList(packService.selectPackListByIds(roomId));
o.setPackIds(CollectionUtils.isNotEmpty(listMap.get(o.getId())) ? listMap.get(o.getId()).stream().map(String::valueOf).collect(Collectors.joining(",")) : "");
o.setPackList(CollectionUtils.isNotEmpty(packMap.get(o.getId())) ? packMap.get(o.getId()) : new ArrayList<>());
storeList.stream().forEach(store -> {
if (o.getStoreId().compareTo(Long.parseLong(store.get("id").toString())) == 0) {
o.setStoreName(store.getOrDefault("name", "").toString());
......@@ -485,4 +496,41 @@ public class SRoomServiceImpl extends ServiceImpl<SRoomMapper, SRoom> implements
return this.list(queryWrapper);
}
@Override
public TableDataInfo pageList(SRoom sRoom) {
List<SRoom> roomList = baseMapper.selectSRoomList(sRoom);
TableDataInfo tableDataInfo = new TableDataInfo();
tableDataInfo.setTotal(roomList.size());
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
int start = (pageNum - 1) * pageSize;
int end = Math.min(start + pageSize, roomList.size());
List<SRoom> pagedList = roomList.subList(start, end);
List<Long> storeIds = pagedList.stream().map(SRoom::getStoreId).collect(Collectors.toList());
List<Long> roomIds = pagedList.stream().map(SRoom::getId).collect(Collectors.toList());
List<Map> storeList = sStoreService.optionList(storeIds);
List<SRoomPack> list = roomPackService.list(new LambdaQueryWrapper<SRoomPack>().in(SRoomPack::getRoomId, roomIds));
Map<Long, List<Long>> listMap = list.stream().collect(Collectors.groupingBy(SRoomPack::getRoomId, Collectors.mapping(SRoomPack::getPackId, Collectors.toList())));
List<SPack> packList = packService.list(new LambdaQueryWrapper<SPack>().eq(SPack::getType, YesNoEnum.yes.getIndex()));
Map<Long, List<SPack>> packMap = new HashMap<>();
//循环listMap
for (Map.Entry<Long, List<Long>> entry : listMap.entrySet()) {
packMap.put(entry.getKey(), packList.stream().filter(o -> entry.getValue().contains(o.getId())).collect(Collectors.toList()));
}
roomList.forEach(o -> {
o.setPackIds(CollectionUtils.isNotEmpty(listMap.get(o.getId())) ? listMap.get(o.getId()).stream().map(String::valueOf).collect(Collectors.joining(",")) : "");
o.setPackList(CollectionUtils.isNotEmpty(packMap.get(o.getId())) ? packMap.get(o.getId()) : new ArrayList<>());
storeList.stream().forEach(store -> {
if (o.getStoreId().compareTo(Long.parseLong(store.get("id").toString())) == 0) {
o.setStoreName(store.getOrDefault("name", "").toString());
}
});
});
tableDataInfo.setRows(pagedList);
tableDataInfo.setCode(200);
tableDataInfo.setMsg("查询成功");
return tableDataInfo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment