kongdeqiang
2023-06-05 a41b28d983f46f90a41ff7d2aa47179541c1be99
src/main/java/com/boying/controller/ParkController.java
@@ -24,7 +24,7 @@
import java.util.stream.Collectors;
@RestController
@RequestMapping("/park")
@RequestMapping("ffzf/park")
@RequiredArgsConstructor
public class ParkController {
@@ -39,7 +39,12 @@
        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);
@@ -89,26 +94,21 @@
    }
    @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);
@@ -116,6 +116,10 @@
            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,"查询成功");
        }