package cn.com.victorysoft.business.sys.controller;

import cn.com.victorysoft.business.constant.DataType;
import cn.com.victorysoft.business.sys.entity.*;
import cn.com.victorysoft.business.sys.service.SysDictService;
import cn.com.victorysoft.business.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "附录查询")
@RestController
@RequestMapping("sys/dict")
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @GetMapping("/lastRange")
    @ApiOperation("查询上一时间范围")
    @ApiImplicitParams({
            @ApiImplicitParam(name="dataType", value="数据类型", paramType="query", required=true)
    })
    public DateRange getLastRange(@RequestParam String dataType){
        // 日度返回今天
        if (dataType.equals(DataType.daily.name())) {
            return DateUtils.getThisDaily();
        }else {
            return DateUtils.getLastRange(DataType.valueOf(dataType));
        }
    }

    @GetMapping("/dataType")
    @ApiOperation("查询数据类型")
    public List<SysDataType> dataType(){
        return sysDictService.queryDataType();
    }

    @GetMapping("")
    @ApiOperation("查询字典数据")
    public List<SysFlag> query(@RequestParam String categoryCode){
        return sysDictService.queryDict(categoryCode);
    }

    @GetMapping("/wellType")
    @ApiOperation("井型附录")
    public List<WellType> selectWellType() {
        return sysDictService.selectWellType();
    }

    @GetMapping("/rodDevicePump")
    @ApiOperation("泵附录")
    public List<RodDevicePump> selectRodDevicePump() {
        return sysDictService.selectRodDevicePump();
    }

    @GetMapping("/rodDeviceRod")
    @ApiOperation("油杆附录")
    public List<RodDeviceRod> selectRodDeviceRod() {
        return sysDictService.selectRodDeviceRod();
    }

    @GetMapping("/rodDeviceSucker")
    @ApiOperation("抽油机附录")
    public List<RodDeviceSucker> selectRodDeviceSucker() {
        return sysDictService.selectRodDeviceSucker();
    }

    @GetMapping("/rodDeviceTube")
    @ApiOperation("油管附录")
    public List<RodDeviceTube> selectRodDeviceTube() {
        return sysDictService.selectRodDeviceTube();
    }
}
