package com.bonus.boot.manager.manager.controller;

import com.bonus.boot.manager.basic.entity.MapBean;
import com.bonus.boot.manager.basic.entity.PersonnelLibraryBean;
import com.bonus.boot.manager.basic.entity.PhyCombinBean;
import com.bonus.boot.manager.manager.annotation.LogAnnotation;
import com.bonus.boot.manager.manager.entity.R;
import com.bonus.boot.manager.manager.model.SysType;
import com.bonus.boot.manager.manager.model.SysUser;
import com.bonus.boot.manager.manager.service.TypeService;
import com.bonus.boot.manager.manager.service.UserService;
import com.bonus.boot.manager.manager.service.impl.TypeServiceImpl;
import com.bonus.boot.manager.manager.utils.AjaxRes;
import com.bonus.boot.manager.manager.utils.GlobalConst;
import com.bonus.boot.manager.physical.entity.CountImportBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private TypeServiceImpl typeServiceImpl;
    @Autowired
    private TypeService typeService;

    @LogAnnotation
    @PostMapping("getContent")
    @ApiOperation(value = "疾病类型管理-列表")
    public R getList(SysType o){
        List<SysType> list = typeServiceImpl.gettyMsgList(o);
        return list.size() > 0 ? R.okTable(list, list.size()):R.failTable("暂无数据");
    }

    @LogAnnotation
    @PostMapping("delById")
    @ApiOperation(value = "疾病类型管理-删除")
    public AjaxRes delById(SysType bean) {
        AjaxRes ar = new AjaxRes();
        int result  = typeService.delById(bean);
        if(result==1){
            ar.setSucceedMsg(GlobalConst.DATA_SUCCEED);
        }else {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    @LogAnnotation
    @RequestMapping(value = "addInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "疾病类型管理-新增")
    public AjaxRes addInfo(@RequestBody SysType bean){
        System.err.println("SysType===="+bean);
        AjaxRes ar = new AjaxRes();
        int cb = typeService.addInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
            if (cb == 3){
                ar.setFailMsg("阳性疾病类型已存在");
            }
        }
        return  ar;
    }

    @LogAnnotation
    @RequestMapping(value = "gettyMsgListOne", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "获取单独疾病类型")
    public AjaxRes gettyMsgListOne( SysType bean){
        System.err.println("SysType===="+bean);
        AjaxRes ar = new AjaxRes();
        SysType cb = typeService.gettyMsgListOne(bean);
        if(cb != null){
            ar.setSucceed(cb,GlobalConst.DATA_SUCCEED);
        }else{
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return  ar;
    }

    @RequestMapping(value = "updateInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "疾病类型管理-修改")
    public AjaxRes updateInfo(@RequestBody SysType bean){
        AjaxRes ar = new AjaxRes();
        int cb = typeService.updateInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            if (cb == 3){
                ar.setFailMsg("阳性疾病类型已存在");
            }else{
                ar.setFailMsg(GlobalConst.INIT_SUCCEED);
            }
        }
        return  ar;
    }

    @LogAnnotation
    @PostMapping("getStatisticalGroup")
    @ApiOperation(value = "异常指标情况统计-列表")
    public R getList(CountImportBean o){
        List<CountImportBean> list = typeServiceImpl.getStatisticalGroup(o);
        return list.size() > 0 ? R.okTable(list, list.size()):R.failTable("暂无数据");
    }

    @LogAnnotation
    @PostMapping("SexAnomalyIndexStatistics")
    @ApiOperation(value = "男、女异常指标统计-列表")
    public R getListSex(CountImportBean o){
        List<CountImportBean> list = typeServiceImpl.SexAnomalyIndexStatistics(o);
        return list.size() > 0 ? R.okTable(list, list.size()):R.failTable("暂无数据");
    }

    @LogAnnotation
    @PostMapping("getPositiveDisease")
    @ApiOperation(value = "获取阳性疾病--下拉框")
    public R getPositiveDisease(MapBean o){
        System.err.println("getPositiveDisease="+o);
        List<MapBean> list = typeServiceImpl.getPositiveDisease(o);
        return list.size() > 0 ? R.okTable(list, list.size()):R.failTable("暂无数据");
    }



}
