package com.yihu.jw.base.endpoint.dict;

import com.yihu.jw.base.service.dict.DictDiseaseService;
import com.yihu.jw.base.service.dict.DiseaseManageService;
import com.yihu.jw.entity.base.dict.DictDiseaseDO;
import com.yihu.jw.entity.base.dict.DiseaseManageDO;
import com.yihu.jw.restmodel.base.dict.DictDiseaseVO;
import com.yihu.jw.restmodel.web.*;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


/**
*
* 病种字典控制器
*
* @version
* <pre>
 * Author	Version		Date		Changes
 * Administrator 	1.0  		2018年09月05日 	Created
 *
 * </pre>
* @since 1.
*/
@RestController
@RequestMapping(value = BaseRequestMapping.DiseaseManage.PREFIX)
@Api(value = "疾病管理", description = "疾病管理", tags = {"疾病管理"})
public class DiseaseManageEndpoint extends EnvelopRestEndpoint {

@Autowired
private DiseaseManageService diseaseManageService;

@PostMapping(value = BaseRequestMapping.DiseaseManage.saveDisease)
@ApiOperation(value = "创建/新增")
public Envelop create (
    @ApiParam(name = "json_data", value = "Json数据", required = true)
    @RequestParam(value = "jsonData") String jsonData)  {
    try {
        DiseaseManageDO diseaseManageDO = diseaseManageService.saveDisease(jsonData);
        return success(diseaseManageDO);
    } catch (Exception e) {
        return failed(e.getMessage());
    }
    }

    @GetMapping(value = BaseRequestMapping.DiseaseManage.updateDiseaseStatus)
    @ApiOperation(value = "删除")
    public Envelop updateDiseaseStatus(
    @ApiParam(name = "id", value = "id", required = true)
    @RequestParam(value = "id") String id,
    @ApiParam(name = "isDel", value = "1正常0删除", required = false)
    @RequestParam(value = "isDel", required = false) String isDel,
    @ApiParam(name = "status", value = "1正常0弃用", required = false)
    @RequestParam(value = "status", required = false) String status) {

    return success(diseaseManageService.deleteById(id,isDel,status));
    }

    @GetMapping(value = BaseRequestMapping.DiseaseManage.findDiseaseList)
    @ApiOperation(value = "获取分页")
    public MixEnvelop page (
        @ApiParam(name = "orgCode", value = "医院code")
        @RequestParam(value = "orgCode", required = false) String orgCode,
        @ApiParam(name = "status", value = "状态")
        @RequestParam(value = "status", required = false) String status,
        @ApiParam(name = "name", value = "疾病名称")
        @RequestParam(value = "name", required = false) String name,
        @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
        @RequestParam(value = "page") int page,
        @ApiParam(name = "pageSize", value = "页码", required = true, defaultValue = "15")
        @RequestParam(value = "pageSize") int pageSize) throws Exception {
       return diseaseManageService.findList(orgCode,status,name,page,pageSize);
     }

     @GetMapping(value = BaseRequestMapping.DiseaseManage.findSingleDisease)
     @ApiOperation(value = "获取单条")
     public Envelop findSingleDisease (
         @ApiParam(name = "id", value = "id")
         @RequestParam(value = "id", required = false) String id) throws Exception {

    return success(diseaseManageService.findOneById(id));
   }

 }
