package com.inspect.metadata.station.controller;

import com.inspect.metadata.station.domain.BasedataStation;
import com.inspect.metadata.station.service.IBasedataStationService;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/station"})
public class BasedataStationController extends BaseController {
    @Resource
    private IBasedataStationService basedataStationService;

    @RequiresPermissions({"basedata:station:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataStation basedataStation) {
        this.startPage();
        List<BasedataStation> list = this.basedataStationService.selectBasedataStationList(basedataStation);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata:station:export"})
    @Log(
            title = "场站信息",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataStation basedataStation) {
        List<BasedataStation> list = this.basedataStationService.selectBasedataStationList(basedataStation);
        ExcelUtil<BasedataStation> util = new ExcelUtil<>(BasedataStation.class);
        util.exportExcel(response, list, "场站信息数据");
    }

    @RequiresPermissions({"basedata:station:query"})
    @GetMapping({"/{stationId}"})
    public AjaxResult getInfo(@PathVariable("stationId") String stationId) {
        return AjaxResult.success(this.basedataStationService.selectBasedataStationByStationId(stationId));
    }

    @RequiresPermissions({"basedata:station:add"})
    @Log(
            title = "场站信息",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataStation basedataStation) {
        return this.toAjax(this.basedataStationService.insertBasedataStation(basedataStation));
    }

    @RequiresPermissions({"basedata:station:edit"})
    @Log(
            title = "场站信息",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataStation basedataStation) {
        return this.toAjax(this.basedataStationService.updateBasedataStation(basedataStation));
    }

    @RequiresPermissions({"basedata:station:remove"})
    @Log(
            title = "场站信息",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{stationIds}"})
    public AjaxResult remove(@PathVariable String[] stationIds) {
        return this.toAjax(this.basedataStationService.deleteBasedataStationByStationIds(stationIds));
    }

    @RequiresPermissions({"basedata:station:query"})
    @Log(
            title = "场站信息",
            businessType = BizType.OTHER
    )
    @GetMapping({"/getStationType/{patrolpointId}"})
    public AjaxResult getStationTypeBypatrolpointId(@PathVariable("patrolpointId") String patrolPointId) {
        return AjaxResult.success(this.basedataStationService.getStationTypeByPatrolPointId(patrolPointId));
    }

    @RequiresPermissions({"basedata:station:query"})
    @Log(
            title = "场站信息",
            businessType = BizType.OTHER
    )
    @GetMapping({"/getStationNameList"})
    public AjaxResult getStationNameList() {
        return AjaxResult.success(this.basedataStationService.getStationNameList());
    }
}
