package com.jiayue.insu.inclientqn.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.insu.common.core.util.R;
import com.jiayue.insu.inclientqn.entity.Station;
import com.jiayue.insu.inclientqn.service.StationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * StationController
 *
 * @author yh
 * @date 2022-03-18 15:48:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/station")
public class StationController {

    private final StationService stationService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param station station
     * @return
     */

    @GetMapping("/page")
    public R getPage(Page page, Station station) {
        LambdaQueryWrapper<Station> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if(station.getStationCode()!=null){
            lambdaQueryWrapper.eq(Station::getStationCode,station.getStationCode());
        }

        if(station.getName()!=null){
            lambdaQueryWrapper.like(Station::getName,station.getName());
        }
        return R.ok(stationService.page(page, lambdaQueryWrapper));
    }

    @GetMapping("/all")
    public R getAll() {
        return R.ok(stationService.list());
    }



    /**
     * 新增station
     *
     * @param station station
     * @return R
     */

    @PostMapping
    public R save(@RequestBody Station station) {
        return R.ok(stationService.save(station));
    }

    /**
     * 修改equipmentAttribute
     *
     * @param station station
     * @return R
     */

    @PutMapping
    public R updateById(@RequestBody Station station) {
        return R.ok(stationService.updateById(station));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return R.ok(stationService.removeById(id));
    }


}
