| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/park") |
| | | @RequestMapping("ffzf/park") |
| | | @RequiredArgsConstructor |
| | | public class ParkController { |
| | | |
| | |
| | | List<Park> records = page1.getRecords(); |
| | | for (Park record : records) { |
| | | String num = redisTemplate.opsForValue().get("car_park_" + record.getId()); |
| | | record.setCarNum(Integer.parseInt(num)); |
| | | if(num != null){ |
| | | record.setCarNum(Integer.parseInt(num)); |
| | | }else { |
| | | record.setCarNum(0); |
| | | } |
| | | |
| | | } |
| | | page1.setRecords(records); |
| | | return R.ok(page1); |
| | |
| | | } |
| | | |
| | | @PostMapping("/getByUserId") |
| | | public Object getByUserId(Long userId) { |
| | | User byId = userService.getById(userId); |
| | | public Object getByUserId(String parkIds) { |
| | | List<Park> list = new ArrayList<>(); |
| | | if(byId == null){ |
| | | return R.failed("未查询到用户"); |
| | | }else { |
| | | String parkIds = byId.getParkIds(); |
| | | if(StringUtils.isBlank(parkIds)){ |
| | | return R.failed("该用户未管理停车场"); |
| | | } |
| | | List<Long> ids= Arrays.stream(parkIds.split(",")).map(s->Long.parseLong(s.trim())).collect(Collectors.toList()); |
| | | for (Long id : ids) { |
| | | Park byId1 = parkService.getById(id); |
| | | String num = redisTemplate.opsForValue().get("car_park_" + byId1.getId()); |
| | | byId1.setCarNum(Integer.parseInt(num)); |
| | | list.add(byId1); |
| | | } |
| | | return R.ok(list); |
| | | if(StringUtils.isBlank(parkIds)){ |
| | | return R.failed("该用户未管理停车场"); |
| | | } |
| | | List<Long> ids= Arrays.stream(parkIds.split(",")).map(s->Long.parseLong(s.trim())).collect(Collectors.toList()); |
| | | for (Long id : ids) { |
| | | Park byId1 = parkService.getById(id); |
| | | String num = redisTemplate.opsForValue().get("car_park_" + byId1.getId()); |
| | | byId1.setCarNum(Integer.parseInt(num)); |
| | | list.add(byId1); |
| | | } |
| | | return R.ok(list); |
| | | } |
| | | |
| | | @PostMapping("/getById") |
| | | public Object getById(Long parkId) { |
| | | Park byId = parkService.getById(parkId); |
| | |
| | | return R.failed("未查询到该停车场"); |
| | | }else { |
| | | String s = redisTemplate.opsForValue().get("car_park_" + parkId); |
| | | if(StringUtils.isBlank(s)){ |
| | | redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS); |
| | | s = "0"; |
| | | } |
| | | byId.setCarNum(Integer.parseInt(s)); |
| | | return R.ok(byId,"查询成功"); |
| | | } |