package com.openhis.web.check.controller;

import com.core.common.core.domain.R;
import com.openhis.check.domain.CheckMethod;
import com.openhis.web.check.appservice.ICheckMethodAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


@RestController
@Slf4j
@RequestMapping("/check/method")
public class CheckMethodController {
    @Resource
    private ICheckMethodAppService checkMethodAppService;

    /*
     * 获取检查方法
     * @Param    此处参数注释有问题，完全是按照需求给的图来注释的
     */
    @GetMapping("/list")
    public R<?> getCheckMethodList(){
        return R.ok(checkMethodAppService.getCheckMethodList());
    }

    /*
    * 条件查询检查方法
    * @Para
    * */
    @GetMapping("/search")
    public R<?> searchCheckMethodList(
            @RequestParam(required = false) Integer pageNo,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String checkType,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String packageName) {
        return R.ok(checkMethodAppService.searchCheckMethodList(pageNo,pageSize,checkType,name,packageName));
    }

    /*
     * 新增检查方法
     * @Param
     */
    @PostMapping("/add")
    public R<?> addCheckMethod(@RequestBody CheckMethod checkMethod){
        return R.ok(checkMethodAppService.addCheckMethod(checkMethod));
    }

    /*
     * 删除检查方法
     * @Param code代码
     */
    @DeleteMapping("/delete/{checkMethodId}")
    public R<?> deleteCheckMethod(@PathVariable Integer checkMethodId){
        return R.ok(checkMethodAppService.removeCheckMethod(checkMethodId));
    }

    /*
     * 更新检查方法
     * @Param
     */
    @PutMapping("/update")
    public R<?> updateCheckMethod(@RequestBody CheckMethod checkMethod){
        return R.ok(checkMethodAppService.updateCheckMethod(checkMethod));
    }

    /*
     * 导出检查方法列表
     * @Param
     */
    @GetMapping("/export")
    public void exportCheckMethod(
            @RequestParam(required = false) String checkType,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String packageName,
            HttpServletResponse response) {
        checkMethodAppService.exportCheckMethod(checkType, name, packageName, response);
    }
}
