Example #1
0
  @RequestMapping("/car/getCarsByDegreeId.do")
  @ResponseBody
  public String getCarsByDegreeId(Integer DegreeId) {
    Result result = new Result();
    // System.out.println("execute this");
    if (DegreeId == null) {
      result.setSuccess(false);
      result.setMsg("获取车辆信息时候,DegreeId参数不能为空!");
    } else {
      List<Car> cars = carService.getCarsByDegreeId(DegreeId);
      // System.out.println("cars size is "+cars.size());
      if (cars == null) {
        result.setSuccess(false);
        result.setMsg("没有车辆信息!");
        System.out.println("cars is NULLL");
      } else {
        System.out.println("cars is not null!!!!!,cars size is " + cars.size());
        for (Car car : cars) {
          List<CarImage> carImages = carImageSerive.getCarImages(car.getId());
          if (!carImages.isEmpty()) {
            car.setCarImageUrl(carImages.get(0).getAddress());
          }
        }

        result.setSuccess(true);
        result.setMsg("查询成功!");
        result.putObject("cars", cars);
      }
    }
    return result.toJsonString();
  }
Example #2
0
  /**
   * get all car info.
   *
   * @return
   */
  @RequestMapping("/car/getAllCarsForFlexi.do")
  @ResponseBody
  public String getAllCarsForFlexi() {
    List<Car> cars = carService.getAllCars();

    for (Car car : cars) {
      CarDegree cardegree = carDegreeService.selectById(Integer.valueOf(car.getCarDegreeId()));
      if (cardegree != null) {
        car.setCarDegreeName(cardegree.getName());
      }
      List<CarImage> carImages = carImageSerive.getCarImages(car.getId());
      if (!carImages.isEmpty()) {
        car.setCarImageUrl(carImages.get(0).getAddress());
      }
    }
    FlexiGridJson flexigrid = new FlexiGridJson(1, cars.size(), cars);
    return flexigrid.toJson();
  }
Example #3
0
  /**
   * add new car.
   *
   * @param car
   * @return
   */
  @RequestMapping("/v/w/car/addCar.do")
  @ResponseBody
  public String addNewCar(HttpServletRequest request, Car car, MultipartFile file) {

    Result result = UploadFileController.uploadFile(request, "car", file);
    if (!result.getSuccess()) {
      return result.toJsonString();
    }
    boolean flag = carService.addCar(car);
    result.setSuccess(flag);
    result.setMsg(flag ? "创建成功" : "创建失败");

    if (result.getSuccess()) {
      CarImage carImage = new CarImage();
      carImage.setCarID(car.getId());
      carImage.setAddress(result.getDatas().get("filePath").toString());
      carImage.setName(car.getName());
      flag = carImageSerive.addCarImage(carImage);
    }

    return result.toJsonString();
  }