package com.jojubanking.boot.module.system.controller.admin.reserve8;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.text.ParseException;
import java.util.*;
import java.io.IOException;

import com.jojubanking.boot.framework.common.pojo.PageResult;
import com.jojubanking.boot.framework.common.pojo.CommonResult;
import static com.jojubanking.boot.framework.common.pojo.CommonResult.success;

import com.jojubanking.boot.framework.excel.core.util.ExcelUtils;

import com.jojubanking.boot.framework.operatelog.core.annotations.OperateLog;
import static com.jojubanking.boot.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.jojubanking.boot.module.system.controller.admin.reserve8.vo.*;
import com.jojubanking.boot.module.system.dal.dataobject.reserve8.Reserve8DO;
import com.jojubanking.boot.module.system.convert.reserve8.Reserve8Convert;
import com.jojubanking.boot.module.system.service.reserve8.Reserve8Service;

@Api(tags = "管理后台 - 预约挂号")
@RestController
@RequestMapping("/system/reserve8")
@Validated
public class Reserve8Controller {

    @Resource
    private Reserve8Service reserve8Service;

    @PostMapping("/create")
    @ApiOperation("创建预约挂号")
    @PreAuthorize("@ss.hasPermission('system:reserve8:create')")
    public CommonResult<Integer> createReserve8(@Valid @RequestBody Reserve8CreateReqVO createReqVO) {
        return success(reserve8Service.createReserve8(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新预约挂号")
    @PreAuthorize("@ss.hasPermission('system:reserve8:update')")
    public CommonResult<Boolean> updateReserve8(@Valid @RequestBody Reserve8UpdateReqVO updateReqVO) {
        reserve8Service.updateReserve8(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除预约挂号")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('system:reserve8:delete')")
    public CommonResult<Boolean> deleteReserve8(@RequestParam("id") Integer id) {
        reserve8Service.deleteReserve8(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得预约挂号")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('system:reserve8:query')")
    public CommonResult<Reserve8RespVO> getReserve8(@RequestParam("id") Integer id) {
        Reserve8DO reserve8 = reserve8Service.getReserve8(id);
        return success(Reserve8Convert.INSTANCE.convert(reserve8));
    }

    @GetMapping("/list")
    @ApiOperation("获得预约挂号列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('system:reserve8:query')")
    public CommonResult<List<Reserve8RespVO>> getReserve8List(@RequestParam("ids") Collection<Integer> ids) {
        List<Reserve8DO> list = reserve8Service.getReserve8List(ids);
        return success(Reserve8Convert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得预约挂号分页")
    @PreAuthorize("@ss.hasPermission('system:reserve8:query')")
    public CommonResult<PageResult<Reserve8RespVO>> getReserve8Page(@Valid Reserve8PageReqVO pageVO) throws ParseException {
        PageResult<Reserve8DO> pageResult = reserve8Service.getReserve8Page(pageVO);
        return success(Reserve8Convert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出预约挂号 Excel")
    @PreAuthorize("@ss.hasPermission('system:reserve8:export')")
    @OperateLog(type = EXPORT)
    public void exportReserve8Excel(@Valid Reserve8ExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<Reserve8DO> list = reserve8Service.getReserve8List(exportReqVO);
        // 导出 Excel
        List<Reserve8ExcelVO> datas = Reserve8Convert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "预约挂号.xls", "数据", Reserve8ExcelVO.class, datas);
    }

}
