New file |
| | |
| | | package cn.exrick.xboot.your.controller; |
| | | |
| | | import cn.exrick.xboot.core.common.utils.PageUtil; |
| | | import cn.exrick.xboot.core.common.utils.ResultUtil; |
| | | import cn.exrick.xboot.core.common.vo.PageVo; |
| | | import cn.exrick.xboot.core.common.vo.Result; |
| | | import cn.exrick.xboot.your.entity.Alarm; |
| | | import cn.exrick.xboot.your.service.IAlarmService; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author zhangzeli |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @Api(tags = "报警记录管理接口") |
| | | @RequestMapping("/xboot/alarm") |
| | | @Transactional |
| | | public class AlarmController { |
| | | |
| | | @Autowired |
| | | private IAlarmService iAlarmService; |
| | | |
| | | @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) |
| | | @ApiOperation(value = "通过id获取") |
| | | public Result<Alarm> get(@PathVariable String id) { |
| | | |
| | | Alarm alarm = iAlarmService.getById(id); |
| | | return new ResultUtil<Alarm>().setData(alarm); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getAll", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取全部数据") |
| | | public Result<List<Alarm>> getAll(String carId) { |
| | | |
| | | QueryWrapper<Alarm> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("flag",0); |
| | | queryWrapper.eq("car_id",carId); |
| | | List<Alarm> list = iAlarmService.list(queryWrapper); |
| | | |
| | | for(Alarm a:list){ |
| | | a.setFlag(1); |
| | | iAlarmService.saveOrUpdate(a); |
| | | } |
| | | return new ResultUtil<List<Alarm>>().setData(list); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getByPage", method = RequestMethod.GET) |
| | | @ApiOperation(value = "分页获取") |
| | | public Result<IPage<Alarm>> getByPage(PageVo page) { |
| | | |
| | | IPage<Alarm> data = iAlarmService.page(PageUtil.initMpPage(page)); |
| | | return new ResultUtil<IPage<Alarm>>().setData(data); |
| | | } |
| | | |
| | | @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST) |
| | | @ApiOperation(value = "编辑或更新数据") |
| | | public Result<Alarm> saveOrUpdate(Alarm alarm) { |
| | | |
| | | if (iAlarmService.saveOrUpdate(alarm)) { |
| | | return new ResultUtil<Alarm>().setData(alarm); |
| | | } |
| | | return new ResultUtil<Alarm>().setErrorMsg("操作失败"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/delByIds", method = RequestMethod.POST) |
| | | @ApiOperation(value = "批量通过id删除") |
| | | public Result<Object> delAllByIds(@RequestParam String[] ids) { |
| | | |
| | | for (String id : ids) { |
| | | iAlarmService.removeById(id); |
| | | } |
| | | return ResultUtil.success("批量通过id删除数据成功"); |
| | | } |
| | | } |