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

import com.yihu.jw.hospital.dict.service.WlyyHospitalSysDictService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = BaseRequestMapping.DictDisease.PREFIX)
@Api(value = "Sys字典管理", description = "Sys字典管理", tags = {"wlyy基础服务 - Sys字典管理"})
public class WlyyHospitalSysDictEndpoint extends EnvelopRestEndpoint {
    private static Logger logger = LoggerFactory.getLogger(WlyyHospitalSysDictEndpoint.class);
    @Autowired
    private WlyyHospitalSysDictService wlyyHospitalSysDictService;
    @ApiOperation("查询字典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.findDict)
    public MixEnvelop findDict(@ApiParam(name = "name", value = "name", required = false)
                                @RequestParam(value = "name", required = false)String name,
                                @ApiParam(name = "modelName", value = "modelName", required = false)
                                @RequestParam(value = "modelName", required = false)String modelName,
                                @ApiParam(name = "code", value = "code", required = false)
                                @RequestParam(value = "code", required = false)String code,
                                @ApiParam(name = "value", value = "value", required = false)
                                @RequestParam(value = "value", required = false)String value,
                                @ApiParam(name = "page", value = "page", required = false)
                                @RequestParam(value = "page", required = false) Integer page,
                                @ApiParam(name = "pageSize", value = "pageSize", required = false)
                                @RequestParam(value = "pageSize", required = false)Integer pageSize){

        return wlyyHospitalSysDictService.findDictsByNameCode(modelName,name,code,value,page,pageSize);
    }
    @ApiOperation("删除字典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.delDict)
    public Envelop delDict(@ApiParam(name = "id", value = "id", required = true)
                           @RequestParam(value = "id", required = true)String id){

        return success(wlyyHospitalSysDictService.deleteDictById(id));
    }
    @ApiOperation("新增/修改字典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.createOrUpdateDict)
    public Envelop createOrUpdateDict(@ApiParam(name = "json", value = "id", required = true)
                                      @RequestParam(value = "json", required = true)String json) throws Exception{

        return success(wlyyHospitalSysDictService.updateOrCreateDict(json));
    }

    @ApiOperation("查单条")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.findOneDict)
    public Envelop findOneDict(@ApiParam(name = "id", value = "id", required = true)
                                      @RequestParam(value = "id", required = true)String id) throws Exception{

        return success(wlyyHospitalSysDictService.findOne(id));
    }
    @ApiOperation("查字典模块")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.findModelDict)
    public MixEnvelop findModelDict(@ApiParam(name = "modelName", value = "modelName", required = false)
                               @RequestParam(value = "modelName", required = false)String modelName,
                                    @ApiParam(name = "dictName", value = "dictName", required = false)
            @RequestParam(value = "dictName", required = false)String dictName,
                                    @ApiParam(name = "page", value = "page", required = false)
                                         @RequestParam(value = "page", required = false) Integer page,
                                    @ApiParam(name = "pageSize", value = "pageSize", required = false)
                                         @RequestParam(value = "pageSize", required = false)Integer pageSize) throws Exception{

        return wlyyHospitalSysDictService.findModel(modelName,dictName,page,pageSize);
    }


    @ApiOperation("批量修改字典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.updateDictGroup)
    public Envelop updateDictGroup(@ApiParam(name = "json", value = "", required = true)
                                      @RequestParam(value = "json", required = true)String json) {

        try {
            return wlyyHospitalSysDictService.updateByModelName(json);
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }

    @ApiOperation("批量删除字典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.delDictGroup)
    public Envelop delDictGroup(@ApiParam(name = "preDictName", value = "", required = true)
                                   @RequestParam(value = "preDictName", required = true)String preDictName) throws Exception{

        return wlyyHospitalSysDictService.deleteByModelName(preDictName);
    }
    @ApiOperation("上移推荐医生")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.upDoctorDict)
    public Envelop upDoctorDict(@ApiParam(name = "id", value = "", required = true)
                                @RequestParam(value = "id", required = true)String id){

        try {
           return success(wlyyHospitalSysDictService.upDoctor(id));
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @ApiOperation("下移推荐医生")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.downDoctorDict)
    public Envelop downDoctorDict(@ApiParam(name = "id", value = "", required = true)
                                @RequestParam(value = "id", required = true)String id){

        try {
            return success(wlyyHospitalSysDictService.downDoctor(id));
        } catch (Exception e) {
            return failed(e.getMessage());
        }
    }
    @ApiOperation("插入推荐医生顺序")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.insertSortDoctorDict)
    public Envelop insertSortDoctorDict(@ApiParam(name = "id", value = "", required = true)
                                @RequestParam(value = "id", required = true)String id,
                                        @ApiParam(name = "sort", value = "", required = true)
                                        @RequestParam(value = "sort", required = true)Integer sort) throws Exception{
        wlyyHospitalSysDictService.insertSort(id,sort);
        return success("操作成功");
    }

    @ApiOperation("保存推荐医生词典")
    @PostMapping(value= BaseHospitalRequestMapping.PatientNoLogin.saveSortDoctorDict)
    public Envelop saveSortDoctorDict(@ApiParam(name = "json", value = "", required = true)
                                        @RequestParam(value = "json", required = true)String json
                                        ) {

        try {
            wlyyHospitalSysDictService.saveDictDoctor(json);
            return success("操作成功");
        } catch (Exception e) {
            return failed(e.getMessage());
        }

    }

    @ApiOperation("查询推荐医生词典")
    @GetMapping(value= BaseHospitalRequestMapping.PatientNoLogin.findSortDoctorDict)
    public MixEnvelop findSortDoctorDict(@ApiParam(name = "orgCode", value = "", required = false)
                                      @RequestParam(value = "orgCode", required = false)String orgCode,
                                      @ApiParam(name = "del", value = "", required = false)
                                      @RequestParam(value = "del", required = false)String del,
                                      @ApiParam(name = "doctorName", value = "", required = false)
                                          @RequestParam(value = "doctorName", required = false)String doctorName,
                                      @ApiParam(name = "page", value = "", required = false)
                                          @RequestParam(value = "page", required = false)Integer page,
                                      @ApiParam(name = "pageSize", value = "", required = false)
                                          @RequestParam(value = "pageSize", required = false)Integer pageSize) {

        return  wlyyHospitalSysDictService.findSortDoctors(orgCode,del,doctorName,page,pageSize);
    }


}
