package com.gxwebsoft.hjm.controller;

import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.hjm.service.HjmGpsLogService;
import com.gxwebsoft.hjm.entity.HjmGpsLog;
import com.gxwebsoft.hjm.param.HjmGpsLogParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.system.entity.User;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 黄家明_gps轨迹控制器
 *
 * @author 科技小王子
 * @since 2025-06-11 12:03:50
 */
@Tag(name = "黄家明_gps轨迹管理")
@RestController
@RequestMapping("/api/hjm/hjm-gps-log")
public class HjmGpsLogController extends BaseController {
    @Resource
    private HjmGpsLogService hjmGpsLogService;

    @Operation(summary = "分页查询黄家明_gps轨迹")
    @GetMapping("/page")
    public ApiResult<PageResult<HjmGpsLog>> page(HjmGpsLogParam param) {
        // 使用关联查询
        return success(hjmGpsLogService.pageRel(param));
    }

    @Operation(summary = "查询全部黄家明_gps轨迹")
    @GetMapping()
    public ApiResult<List<HjmGpsLog>> list(HjmGpsLogParam param) {
        // 使用关联查询
        return success(hjmGpsLogService.listRel(param));
    }

    @Operation(summary = "根据id查询黄家明_gps轨迹")
    @GetMapping("/{id}")
    public ApiResult<HjmGpsLog> get(@PathVariable("id") Integer id) {
        // 使用关联查询
        return success(hjmGpsLogService.getByIdRel(id));
    }

    @Operation(summary = "添加黄家明_gps轨迹")
    @PostMapping()
    public ApiResult<?> save(@RequestBody HjmGpsLog hjmGpsLog) {
        if (hjmGpsLogService.save(hjmGpsLog)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmGpsLog:update')")
    @OperationLog
    @Operation(summary = "修改黄家明_gps轨迹")
    @PutMapping()
    public ApiResult<?> update(@RequestBody HjmGpsLog hjmGpsLog) {
        if (hjmGpsLogService.updateById(hjmGpsLog)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmGpsLog:remove')")
    @OperationLog
    @Operation(summary = "删除黄家明_gps轨迹")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (hjmGpsLogService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmGpsLog:save')")
    @OperationLog
    @Operation(summary = "批量添加黄家明_gps轨迹")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<HjmGpsLog> list) {
        if (hjmGpsLogService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmGpsLog:update')")
    @OperationLog
    @Operation(summary = "批量修改黄家明_gps轨迹")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<HjmGpsLog> batchParam) {
        if (batchParam.update(hjmGpsLogService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('hjm:hjmGpsLog:remove')")
    @OperationLog
    @Operation(summary = "批量删除黄家明_gps轨迹")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (hjmGpsLogService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    // 分析车辆是否逆行

}
