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

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.mzjf.vo.*;
import com.jojubanking.boot.module.system.dal.dataobject.mzjf.MzjfDO;
import com.jojubanking.boot.module.system.convert.mzjf.MzjfConvert;
import com.jojubanking.boot.module.system.service.mzjf.MzjfService;

@Api(tags = "管理后台 - 门诊缴费")
@RestController
@RequestMapping("/system/mzjf")
@Validated
public class MzjfController {

    @Resource
    private MzjfService mzjfService;

    @PostMapping("/create")
    @ApiOperation("创建门诊缴费")
    @PreAuthorize("@ss.hasPermission('system:mzjf:create')")
    public CommonResult<Integer> createMzjf(@Valid @RequestBody MzjfCreateReqVO createReqVO) {
        return success(mzjfService.createMzjf(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新门诊缴费")
    @PreAuthorize("@ss.hasPermission('system:mzjf:update')")
    public CommonResult<Boolean> updateMzjf(@Valid @RequestBody MzjfUpdateReqVO updateReqVO) {
        mzjfService.updateMzjf(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除门诊缴费")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('system:mzjf:delete')")
    public CommonResult<Boolean> deleteMzjf(@RequestParam("id") Integer id) {
        mzjfService.deleteMzjf(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得门诊缴费")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('system:mzjf:query')")
    public CommonResult<MzjfRespVO> getMzjf(@RequestParam("id") Integer id) {
        MzjfDO mzjf = mzjfService.getMzjf(id);
        return success(MzjfConvert.INSTANCE.convert(mzjf));
    }

    @GetMapping("/list")
    @ApiOperation("获得门诊缴费列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('system:mzjf:query')")
    public CommonResult<List<MzjfRespVO>> getMzjfList(@RequestParam("ids") Collection<Integer> ids) {
        List<MzjfDO> list = mzjfService.getMzjfList(ids);
        return success(MzjfConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得门诊缴费分页")
    @PreAuthorize("@ss.hasPermission('system:mzjf:query')")
    public CommonResult<PageResult<MzjfRespVO>> getMzjfPage(@Valid MzjfPageReqVO pageVO) throws ParseException {
        PageResult<MzjfDO> pageResult = mzjfService.getMzjfPage(pageVO);
        return success(MzjfConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出门诊缴费 Excel")
    @PreAuthorize("@ss.hasPermission('system:mzjf:export')")
    @OperateLog(type = EXPORT)
    public void exportMzjfExcel(@Valid MzjfExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<MzjfDO> list = mzjfService.getMzjfList(exportReqVO);
        // 导出 Excel
        List<MzjfExcelVO> datas = MzjfConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "门诊缴费.xls", "数据", MzjfExcelVO.class, datas);
    }

}
