package com.tofly.feesapi.bmgl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tofly.feesapi.bmgl.entity.BmSj;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.bmgl.entity.dto.BmSjFilter;
import com.tofly.feesapi.bmgl.entity.dto.BmSjInsert;
import com.tofly.feesapi.bmgl.entity.dto.BmSjUpdate;
import com.tofly.feesapi.bmgl.entity.vo.BmSjSelect;
import com.tofly.feesapi.bmgl.entity.vo.BmSjView;
import com.tofly.feesapi.bmgl.entity.vo.BmSjlsSelect;
import com.tofly.feesapi.bmgl.entity.vo.BmSjlsView;
import com.tofly.feesapi.bmgl.mapper.BmSjMapper;
import com.tofly.feesapi.bmgl.service.BmSjService;
import com.tofly.feesapi.bmgl.service.IBmSjlsService;
import com.tofly.feesapi.common.core.dto.PageDto;
import com.tofly.feesapi.common.core.vo.PageResult;
import com.tofly.feesapi.common.model.CollectionData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/bmgl/bmsj")
@Api(tags = "编码-水价管理")
public class BmSjController {

    @Autowired
    private BmSjService bmSjService;
    @Autowired
    private IBmSjlsService bmSjlsService;

    @GetMapping("/list")
    @ApiOperation(value = "水价管理列表list")
    public ResultRespone<CollectionData<List<BmSj>>> getbmsjList() {
        List<BmSj> bmSjs = bmSjService.selectListMap();
        return ResultRespone.success(new CollectionData(bmSjs, bmSjs.size()));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "新增水价")
    @PostMapping
    public ResultRespone<Boolean> save(@RequestBody BmSjInsert insert) {
        return ResultRespone.success(bmSjService.save(insert));
    }

    @ApiOperationSupport(order = 3)
    @GetMapping("/{code}")
    @ApiOperation(value = "查看水价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "水价编码", required = true, dataType = "String", example = "1")
    })
    public ResultRespone<BmSjView> getById(@PathVariable("code") String code) {
        return ResultRespone.success(bmSjService.getViewById(code));
    }

    @ApiOperationSupport(order = 4)
    @GetMapping("")
    @ApiOperation(value = "查询水价")
    public ResultRespone<CollectionData<BmSjSelect>> getList(@ModelAttribute BmSjFilter filter) {
        List<BmSjSelect> list = bmSjService.getList(filter);
        return ResultRespone.success(new CollectionData<>(list, list.size()));
    }


    @ApiOperationSupport(order = 5)
    @GetMapping("/page")
    @ApiOperation(value = "查询水价（分页）")
    public ResultRespone<PageResult<BmSjSelect>> getPage(@ModelAttribute PageDto pageDto, @ModelAttribute BmSjFilter filter) {
                return ResultRespone.success(bmSjService.getPage(pageDto, filter));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "修改水价")
    @PutMapping
    public ResultRespone<Boolean> update(@RequestBody BmSjUpdate update) {
        return ResultRespone.success(bmSjService.update(update));
    }

//    @ApiOperationSupport(order = 8)
//    @ApiOperation(value = "删除")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "水价编码", required = true, example = "1")
//    })
//    @DeleteMapping("/{code}")
//    public ResultRespone<Boolean> delById(@PathVariable String code,
//                                          ) {
//        return ResultRespone.success(bmSjService.delById(code));
//    }
//
//    @ApiOperationSupport(order = 9)
//    @ApiOperation(value = "批量删除")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "codes", value = "水价编码，多个以逗号隔开", required = true, example = "1,2,3,4")
//    })
//    @DeleteMapping("/delByIds")
//    public ResultRespone<Boolean> delByIds(@RequestParam String codes,
//                                           ) {
//        return ResultRespone.success(bmSjService.delByIds(Arrays.asList(codes.split(","))));
//    }


    @ApiOperationSupport(order = 13)
    @GetMapping("/{code}/bmsjls")
    @ApiOperation(value = "查询水价历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "水价编码", required = true, dataType = "String", example = "1")
    })
    public ResultRespone<PageResult<BmSjlsSelect>> getBmsjlsPage(@PathVariable("code") String code,
                                                                 @ModelAttribute PageDto pageDto) {
        return ResultRespone.success(bmSjlsService.getPage(pageDto, code));
    }

    @ApiOperationSupport(order = 14)
    @GetMapping("/bmsjls/{id}")
    @ApiOperation(value = "查看水价历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "水价编码历史ID", required = true, dataType = "String", example = "0451c679bb259efba7a4a9f3f47e592e")
    })
    public ResultRespone<BmSjlsView> getBmsjlById(@PathVariable("id") String id) {
        return ResultRespone.success(bmSjlsService.getViewById(id));
    }
}
