| | |
| | | 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; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @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 = "/getAllAreas", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取所有区域数据") |
| | | public Result<List<String>> getAllAreas(){ |
| | | QueryWrapper<Area> wrapper = new QueryWrapper<>(); |
| | | wrapper.orderByAsc("name"); |
| | | List<String> names = new ArrayList<>(); |
| | | List<Area> list = iAreaService.list(); |
| | | for (Area area:list ) { |
| | | String name = area.getName(); |
| | | /* int wz = name.indexOf("0"); |
| | | if(wz>0){ |
| | | name = name.substring(0,wz); |
| | | }*/ |
| | | |
| | | name = name |
| | | .replace("01车","") |
| | | .replace("02车","") |
| | | .replace("03车","") |
| | | .replace("04车","") |
| | | .replace("05车","") |
| | | .replace("06车","") |
| | | .replace("07车","") |
| | | .replace("08车","") |
| | | .replace("09车","") |
| | | .replace("10车","") |
| | | .replace("11车","") |
| | | .replace("12车","") |
| | | .replace("13车","") |
| | | .replace("14车","") |
| | | .replace("15车",""); |
| | | name = name |
| | | .replace("01","") |
| | | .replace("02","") |
| | | .replace("03","") |
| | | .replace("04","") |
| | | .replace("05","") |
| | | .replace("06","") |
| | | .replace("07","") |
| | | .replace("08","") |
| | | .replace("09","") |
| | | .replace("10","") |
| | | .replace("11","") |
| | | .replace("12","") |
| | | .replace("13","") |
| | | .replace("14","") |
| | | .replace("15",""); |
| | | if(!names.contains(name)){ |
| | | names.add(name); |
| | | } |
| | | } |
| | | return new ResultUtil<List<String>>().setData(names); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getByPage", method = RequestMethod.GET) |
| | | @ApiOperation(value = "分页获取") |
| | | public Result<IPage<Area>> getByPage(String areaId,PageVo page) { |
| | | public Result<IPage<Area>> getByPage(String name,PageVo page) { |
| | | QueryWrapper<Area> wrapper = new QueryWrapper<>(); |
| | | if (!StrUtil.isEmpty(areaId)) |
| | | wrapper.eq("area_id",areaId); |
| | | if (!StrUtil.isEmpty(name)) |
| | | wrapper.like("a.name",name); |
| | | IPage<Area> data = iAreaService.page2(PageUtil.initMpPage(page),wrapper); |
| | | return new ResultUtil<IPage<Area>>().setData(data); |
| | | } |
| | |
| | | @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); |
| | | } |