package com.alfred.bus.controller; import com.alfred.bus.domain.Car; import com.alfred.bus.service.CarService; import com.alfred.bus.vo.CarVo; import com.alfred.sys.constant.SysConstant; import com.alfred.sys.utils.AppFileUtils; import com.alfred.sys.utils.DataGridView; import com.alfred.sys.utils.ResultObj; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Date; @RestController @RequestMapping("car") public class CarController { @Autowired private CarService carService; /** * 加载车辆列表返回DataGridView * @param carVo * @return */ @RequestMapping("loadAllCar") public DataGridView loadAllCar(CarVo carVo){ return this.carService.queryAllCar(carVo); } /** * 添加一个车辆 * @param carVo * @return */ @RequestMapping("addCar") public ResultObj addCar(CarVo carVo){ try{ carVo.setCreatetime(new Date()); //如果不是默认图片就去掉图片的_temp的后缀 if(!carVo.getCarimg().equals(SysConstant.DEFAULT_CAR_IMG)){ String filePath = AppFileUtils.updateFileName(carVo.getCarimg(), SysConstant.FILE_UPLOAD_TEMP); carVo.setCarimg(filePath); } this.carService.addCar(carVo); return ResultObj.ADD_SUCCESS; }catch (Exception e){ e.printStackTrace(); return ResultObj.ADD_ERROR; } } /** * 修改一个车辆 * @param carVo * @return */ @RequestMapping("updateCar") public ResultObj updateCar(CarVo carVo){ try{ String carimg = carVo.getCarimg(); if (carimg.endsWith(SysConstant.FILE_UPLOAD_TEMP)) { String filePath =AppFileUtils.updateFileName(carVo.getCarimg(), SysConstant.FILE_UPLOAD_TEMP); carVo.setCarimg(filePath); //把原来的删除 Car car = this.carService.queryCarByCarNumber(carVo.getCarnumber()); AppFileUtils.removeFileByPath(car.getCarimg()); } this.carService.updateCar(carVo); return ResultObj.UPDATE_SUCCESS; }catch (Exception e){ e.printStackTrace(); return ResultObj.UPDATE_ERROR; } } /** * 删除一个车辆 * @param carVo * @return */ @RequestMapping("deleteCar") public ResultObj deleteCar(CarVo carVo){ try { this.carService.deleteCar(carVo.getCarnumber()); return ResultObj.DELETE_SUCCESS; }catch (Exception e){ e.printStackTrace(); return ResultObj.DELETE_ERROR; } } /** * 批量删除车辆 * @param carVo * @return */ @RequestMapping("deleteBatchCar") public ResultObj deleteBatchCar(CarVo carVo){ try{ this.carService.deleteBatchCar(carVo.getIds()); return ResultObj.DELETE_SUCCESS; }catch (Exception e){ e.printStackTrace(); return ResultObj.DELETE_ERROR; } } }

小松哥11 LV3
2024年10月24日
wuying8208 LV15
2024年10月23日
微信网友_6917967074955264 LV2
2024年3月30日
微信网友_6900009262157824 LV1
2024年3月9日
WBelong LV8
2023年12月25日
dzlwindy LV8
2023年12月18日
angel_yy LV2
2023年8月11日
homework333 LV1
2023年7月10日
sunshinemenfolk LV4
2023年7月5日
GJQ123 LV4
2023年6月5日

niuwa666
4月3日
暂无贡献等级
ryadmin123 LV2
2月11日
Mhgfhjyrf LV3
2024年12月9日
zolscy LV24
2024年11月28日
微笑刺客 LV21
2024年11月22日
小松哥11 LV3
2024年10月24日
wuying8208 LV15
2024年10月23日
3339790961
2024年9月6日
暂无贡献等级
yyhrhv LV8
2024年9月3日
terryang LV19
2024年9月2日