Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / zhz / CarManagerController.java
package com.newfiber.api.pc.controller.zhz;

import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.*;
import com.newfiber.api.pc.dto.CarSearchDTO;
import com.newfiber.api.pc.model.entity.CarManager;
import com.newfiber.api.pc.model.vo.ReturnGisCarLocationDataVo;
import com.newfiber.api.pc.service.CarManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @description: TODO
 * @author: 张鸿志
 * @date: 2021/2/2 10:10
 * @version: v1.0
 */
@RestController
@RequestMapping("/car")
@Api(value = "CarManagerController",tags = "车辆管理控制层")
public class CarManagerController {

    @Autowired
    private CarManagerService carManagerService;


    @PostMapping("/save")
    @ApiOperation("新增或修改车辆数据")
    @SysLog(actionType = "2",value = "新增或修改车辆数据")
    public ResultObj addCar(@RequestBody CarManager carManager){
        if(!StringUtils.isEmpty(carManager)){
            //看是够是修改
            if(!StringUtils.isEmpty(carManager.getCarId())){
                //根据主键查询
                CarManager carById = carManagerService.selectById(carManager.getCarId());
                if(StringUtils.isEmpty(carById)){
                    throw  new CustomException(500,"要修改的数据不存在");
                }
                carManagerService.updateById(carManager);
            }else{
                //新增
                carManagerService.insert(carManager);
            }

            return ResultObj.ok();
        }
        throw new CustomException(ResultCode.PARAM_NULL);
    }


    @PostMapping("/delete")
    @ApiOperation("删除车辆信息")
    @SysLog(actionType = "3",value = "删除车辆信息")
    public ResultObj deleteCar(@RequestParam("carId")Integer carId){
        if(StringUtils.isEmpty(carId)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        boolean delete = carManagerService.deleteById(carId);
        if(!delete) {
            return ResultObj.error("删除失败");
        }
        return ResultObj.ok();
    }


    @PostMapping("/selectListPage")
    @ApiOperation("分页查询车辆信息")
    @SysLog(actionType = "4",value = "分页查询车辆信息")
    public ResultObj<PageResultObject<CarManager>> selectList(@RequestBody PageRequestObject<CarSearchDTO> pageRequestObject){
        return new ResultObj<PageResultObject<CarManager>>(ResultCode.OK,carManagerService.selectListPage(pageRequestObject));
    }

    @PostMapping("/select")
    @ApiOperation("查询所有空闲车辆信息")
    @SysLog(actionType = "4",value = "查询所有空闲车辆信息")
    public ResultObj<List<CarManager>> selectAll(){
        return new ResultObj<>(ResultCode.OK,carManagerService.select());
    }



    @PostMapping("/locations")
    @ApiOperation("查询所有正在运输的车辆的位置信息")
    @SysLog(actionType = "4",value = "查询所有正在运输的车辆的位置信息")
    public ResultObj<List<ReturnGisCarLocationDataVo>> allCarLocations(){
        return new ResultObj<>(ResultCode.OK,carManagerService.allCarLocations());
    }

}