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

import cn.com.victorysoft.business.sys.entity.*;
import cn.com.victorysoft.business.sys.param.UnitFieldBlockWellParam;
import cn.com.victorysoft.business.sys.param.UnitGroupWellParam;
import cn.com.victorysoft.business.sys.param.UnitWellParam;
import cn.com.victorysoft.business.sys.service.SysBaseService;
import com.github.pagehelper.PageInfo;
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.*;

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

@Api(tags = "基础数据查询")
@RestController
@RequestMapping("sys/base")
public class SysBaseController {

    @Resource
    private SysBaseService sysBaseService;

    @GetMapping("/unitTree")
    @ApiOperation("查询单位树形数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public SysUnitinfo unitTree(@RequestParam String unitcode){
        return sysBaseService.selectUnitTree(unitcode);
    }

    @GetMapping("/areaTree")
    @ApiOperation("查询管理区树形数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public SysUnitinfo areaTree(@RequestParam String unitcode){
        return sysBaseService.selectUnitTreeLevel3(unitcode);
    }

    @GetMapping("/areaList")
    @ApiOperation("查询管理区列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public List<SysUnitinfo> areaList(@RequestParam String unitcode){
        return sysBaseService.selectUnitListLevel3(unitcode);
    }

    @GetMapping("/unit/children")
    @ApiOperation("查询下级单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public List<SysUnitinfo> unitChildren(@RequestParam String unitcode){
        return sysBaseService.selectUnitChildren(unitcode);
    }

    @GetMapping("/waterWellList")
    @ApiOperation("查询单位/油田/区块的水井井号")
    public List<WellBasic> waterWellList(UnitFieldBlockWellParam param){
        return sysBaseService.selectWaterWellTop20(param);
    }

    @GetMapping("/fieldList")
    @ApiOperation("查询单位的油田")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public List<SysFieldinfo> fieldList(@RequestParam String unitcode){
        return sysBaseService.selectFieldList(unitcode);
    }

    @GetMapping("/blockList")
    @ApiOperation("查询单位（油田）的区块")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true),
            @ApiImplicitParam(name="fieldcode", value="油田代码", paramType="query", required=false)
    })
    public List<SysBlockinfo> blockList(@RequestParam String unitcode, @RequestParam(required = false) String fieldcode){
        return sysBaseService.selectBlockList(unitcode, fieldcode);
    }

    @GetMapping("/blockListTop20")
    @ApiOperation("查询单位的前20个区块")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true),
            @ApiImplicitParam(name="blockname", value="区块名称", paramType="query", required=false)
    })
    public List<SysBlockinfo> blockListTop20(@RequestParam String unitcode, @RequestParam(required = false) String blockname){
        return sysBaseService.selectBlockListTop20(unitcode, blockname);
    }

    @GetMapping("/noGroupWellList")
    @ApiOperation("井组-查询未划分井组的井号")
    @ApiImplicitParams({
            @ApiImplicitParam(name="unitcode", value="单位代码", paramType="query", required=true)
    })
    public List<WellBasic> noGroupWellList(String unitcode){
        return sysBaseService.selectNoGroupWellList(unitcode);
    }

    @GetMapping("/wellGroupList")
    @ApiOperation("井组-查询井组列表")
    public PageInfo<WellGroup> wellGroupList(UnitGroupWellParam param){
        return sysBaseService.selectWellGroupList(param);
    }

    @GetMapping("/wellGroup")
    @ApiOperation("井组-查询井组对象")
    public WellGroup wellGroup(String id){
        return sysBaseService.selectWellGroup(id);
    }

    @PostMapping("/wellGroup")
    @ApiOperation("井组-新增井组")
    public void insertWellGroup(@RequestBody WellGroup wellGroup){
        sysBaseService.insertWellGroup(wellGroup);
    }

    @PutMapping("/wellGroup")
    @ApiOperation("井组-更新井组")
    public void updateWellGroup(@RequestBody WellGroup wellGroup){
        sysBaseService.updateWellGroup(wellGroup);
    }

    @DeleteMapping("/wellGroup")
    @ApiOperation("井组-删除井组")
    public void deleteWellGroup(String id){
        sysBaseService.deleteWellGroup(id);
    }

    @GetMapping("/companyList")
    @ApiOperation("查询采油厂列表")
    public List<SysUnitinfo> companyList(){
        return sysBaseService.selectCompanyList();
    }
}
