| | |
| | | import cn.exrick.xboot.core.common.vo.PageVo; |
| | | import cn.exrick.xboot.core.common.vo.Result; |
| | | import cn.exrick.xboot.your.entity.Area; |
| | | import cn.exrick.xboot.your.entity.Car; |
| | | import cn.exrick.xboot.your.service.IAreaService; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | @RequestMapping(value = "/getAll", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取全部数据") |
| | | public Result<List<Area>> getAll() { |
| | | |
| | | QueryWrapper<Area> wrapper = new QueryWrapper<>(); |
| | | wrapper.orderByAsc("name"); |
| | | List<Area> list = iAreaService.list(); |
| | | return new ResultUtil<List<Area>>().setData(list); |
| | | } |
| | |
| | | @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST) |
| | | @ApiOperation(value = "编辑或更新数据") |
| | | public Result<Area> saveOrUpdate(Area area) { |
| | | QueryWrapper<Area> wrapper = new QueryWrapper<>(); |
| | | if (StrUtil.isNotEmpty(area.getCarId())){ |
| | | wrapper.eq("car_id",area.getCarId()); |
| | | Area area1 = iAreaService.getOne(wrapper); |
| | | if (area1 != null && !area.getId().equals(area1.getId())){ |
| | | return new ResultUtil<Area>().setErrorMsg("该车辆已被其它片区绑定,请先解绑"); |
| | | } |
| | | } |
| | | |
| | | if (iAreaService.saveOrUpdate(area)) { |
| | | return new ResultUtil<Area>().setData(area); |
| | | } |