package com.miaxis.app.controller.hospital;


import com.miaxis.app.hospital.domain.HospitalInfo;
import com.miaxis.app.hospital.service.IHospitalInfoService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【体检医院】Controller
 *
 * @author miaxis
 * @date 2021-01-11
 */
@RestController
@RequestMapping(Constants.OPEN_PREFIX+"/hospital/info")
@Api(tags={"【app-体检医院】"})
public class HospitalInfoController extends BaseController{
    @Autowired
    private IHospitalInfoService hospitalInfoService;

    /**
     * 查询体检医院列表
     */
    //@PreAuthorize("@ss.hasPermi('hospital:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询体检医院列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<HospitalInfo> list(@ModelAttribute HospitalInfo hospitalInfo){
        startPage();
        List<HospitalInfo> list = hospitalInfoService.selectHospitalInfoList(hospitalInfo);
        return toResponsePageInfo(list);
    }

    /**
     * 导出体检医院列表
     */
   // @PreAuthorize("@ss.hasPermi('hospital:info:export')")
    @Log(title = "体检医院", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出体检医院列表Excel")
    public Response<String> export(@ModelAttribute HospitalInfo hospitalInfo){
        List<HospitalInfo> list = hospitalInfoService.selectHospitalInfoList(hospitalInfo);
        ExcelUtil<HospitalInfo> util = new ExcelUtil<HospitalInfo>(HospitalInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取体检医院详细信息
     */
    //@PreAuthorize("@ss.hasPermi('hospital:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取体检医院详细信息")
    public Response<HospitalInfo> getInfo(
            @ApiParam(name = "id", value = "体检医院参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(hospitalInfoService.selectHospitalInfoById(id));
    }

    /**
     * 新增体检医院
     */
    //@PreAuthorize("@ss.hasPermi('hospital:info:add')")
    @Log(title = "体检医院", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增体检医院")
    public Response<Integer> add(@RequestBody HospitalInfo hospitalInfo){
        return toResponse(hospitalInfoService.insertHospitalInfo(hospitalInfo));
    }

    /**
     * 修改体检医院
     */
    //@PreAuthorize("@ss.hasPermi('hospital:info:edit')")
    @Log(title = "体检医院", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改体检医院")
    public Response<Integer> edit(@RequestBody HospitalInfo hospitalInfo){
        return toResponse(hospitalInfoService.updateHospitalInfo(hospitalInfo));
    }

    /**
     * 删除体检医院
     */
    //@PreAuthorize("@ss.hasPermi('hospital:info:remove')")
    @Log(title = "体检医院", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除体检医院")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "体检医院ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(hospitalInfoService.deleteHospitalInfoByIds(ids));
    }
}
