Esempio n. 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();
  }
Esempio n. 2
0
 /**
  * get all car info.
  *
  * @return
  */
 @RequestMapping("/car/getAllCars.do")
 @ResponseBody
 public String getAllCars() {
   Result result = new Result();
   List<Car> cars = carService.getAllCars();
   result.setSuccess(true);
   result.putObject("total", cars.size());
   result.putObject("cars", cars);
   return result.toJsonString();
 }
Esempio n. 3
0
 /**
  * delete car by id.
  *
  * @param carId
  * @return
  */
 @RequestMapping("/v/w/car/deleteCarById.do")
 @ResponseBody
 public String deleteCar(String carId) {
   Result result = new Result();
   if (!Regex.regex(Regex.sint, carId)) {
     return result.setErrorMsg("类型不正确").toJsonString();
   }
   boolean flag = carService.deleteCarById(Integer.valueOf(carId));
   result.setSuccess(flag);
   result.setMsg(flag ? "删除成功" : "删除失败");
   return result.toJsonString();
 }
Esempio n. 4
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();
  }
Esempio n. 5
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();
  }