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

import com.bonus.boot.manager.basic.dao.HospitalDao;
import com.bonus.boot.manager.basic.dao.PhyCombinDao;
import com.bonus.boot.manager.basic.entity.PhyCombinBean;
import com.bonus.boot.manager.basic.service.HospitalService;
import com.bonus.boot.manager.basic.service.PhyCombinService;
import com.bonus.boot.manager.manager.annotation.LogAnnotation;
import com.bonus.boot.manager.manager.entity.R;
import com.bonus.boot.manager.manager.utils.AjaxRes;
import com.bonus.boot.manager.manager.utils.GlobalConst;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *体检项目管理表控制层
 * @author tqzhang
 * @Data 2023/6/1 11:30
 */
@RestController
@RequestMapping("physicalExaminationItems")
public class PhyCombinController {
    /**
     * 服务对象
     */
    @Resource
    private PhyCombinService service;

    @Resource
    private PhyCombinDao dao;

    @LogAnnotation
    @PostMapping("getMsgContent")
    @ApiOperation(value = "体检项目管理-列表")
    public R getList(PhyCombinBean o){
        List<PhyCombinBean> list = service.getList(o);
        return list.size() > 0 ? R.okTable(list, list.size()):R.failTable("暂无数据");
    }

    @RequestMapping(value = "addInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "体检项目管理-新增")
    public AjaxRes addInfo(@RequestBody PhyCombinBean bean){
        AjaxRes ar = new AjaxRes();
        int cb = service.addInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
            if (cb == 3){
                ar.setFailMsg("体检项目名称已存在");
            }
        }
        return  ar;
    }

    @RequestMapping(value = "updateInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "体检项目管理-修改")
    public AjaxRes updateInfo(@RequestBody PhyCombinBean bean){
        AjaxRes ar = new AjaxRes();
        int cb = service.updateInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            if (cb == 3){
                ar.setFailMsg("体检项目名称已存在");
            }
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
        }
        return  ar;
    }
    @RequestMapping(value = "getListById", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "体检项目管理-查询单个体检项目")
    public AjaxRes getListById(String id){
        AjaxRes ar = new AjaxRes();
        PhyCombinBean PhyCombinBean = service.getListById(id);
        Map<String, Object> map = new HashMap<>();
        if(PhyCombinBean !=null){
            map.put("PhyCombinBean",PhyCombinBean);
        }
        ar.setSucceed(map,GlobalConst.DATA_SUCCEED);
        return ar;
    }


    @LogAnnotation
    @PostMapping("delById")
    @ApiOperation(value = "体检项目管理-删除")
    public AjaxRes delById(PhyCombinBean bean) {
        AjaxRes ar = new AjaxRes();
        int result  = service.delById(bean);
        if(result==1){
            ar.setSucceedMsg(GlobalConst.DATA_SUCCEED);
        }else {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

}

