package com.openhis.web.check.controller;

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

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

@RestController
@Slf4j
@RequestMapping("/check/part")
public class CheckPartController {
    @Resource
    private ICheckPartAppService checkPartAppService;

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

    /*
    * 条件搜索检查部位
    * @Param
    * */
    @GetMapping("/search")
    public R<?> searchCheckPartList(@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(checkPartAppService.searchCheckPartList(pageNo,pageSize,checkType,name,packageName));
    }

    /*
     * 新增检查部位
     * @Param
     */
    @PostMapping("/add")
    public R<?> addCheckPart(@RequestBody CheckPart checkPart){
        return R.ok(checkPartAppService.addCheckPart(checkPart));
    }

    /*
     * 删除检查部位
     * @Param code代码
     */
    @DeleteMapping("/delete/{checkPartId}")
    public R<?> deleteCheckPart(@PathVariable Integer checkPartId){
        return R.ok(checkPartAppService.removeCheckPart(checkPartId));
    }

    /*
     * 更新检查部位
     * @Param
     */
    @PutMapping("/update")
    public R<?> updateCheckPart(@RequestBody CheckPart checkPart){
        return R.ok(checkPartAppService.updateCheckPart(checkPart));
    }

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