package com.zcloud.primeport.web;


import com.zcloud.primeport.api.EVehicleArrivalDepartureInfoServiceI;
import com.zcloud.primeport.dto.EVehicleArrivalDepartureInfoAddCmd;
import com.zcloud.primeport.dto.EVehicleArrivalDepartureInfoPageQry;
import com.zcloud.primeport.dto.EVehicleArrivalDepartureInfoUpdateCmd;
import com.zcloud.primeport.dto.clientobject.EVehicleArrivalDepartureInfoCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * web-adapter
 *
 * @Author dearLin
 * @Date 2026-05-27 17:45:43
 */
@Api(tags = "一级口门车辆数据接入")
@RequestMapping("/${application.gateway}/eVehicleArrivalDepartureInfo")
@RestController
@AllArgsConstructor
public class EVehicleArrivalDepartureInfoController {
    private final EVehicleArrivalDepartureInfoServiceI eVehicleArrivalDepartureInfoService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<EVehicleArrivalDepartureInfoCO> add(@Validated @RequestBody EVehicleArrivalDepartureInfoAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return eVehicleArrivalDepartureInfoService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<EVehicleArrivalDepartureInfoCO> page(@RequestBody EVehicleArrivalDepartureInfoPageQry qry) {
        return eVehicleArrivalDepartureInfoService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<EVehicleArrivalDepartureInfoCO> listAll() {
        return MultiResponse.of(new ArrayList<EVehicleArrivalDepartureInfoCO>());
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<EVehicleArrivalDepartureInfoCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(eVehicleArrivalDepartureInfoService.queryById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable("id") Long id) {
        eVehicleArrivalDepartureInfoService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam("ids") String ids) {
        List<Long> idsList = Arrays.stream(ids.split(","))
                .map(Long::valueOf)
                .collect(Collectors.toList());
        eVehicleArrivalDepartureInfoService.removeBatch(idsList);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody EVehicleArrivalDepartureInfoUpdateCmd eVehicleArrivalDepartureInfoUpdateCmd) {
        eVehicleArrivalDepartureInfoService.edit(eVehicleArrivalDepartureInfoUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

