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

import com.bonus.boot.manager.basic.dao.PackageTypeDao;
import com.bonus.boot.manager.basic.entity.BaseTypePackageBean;
import com.bonus.boot.manager.basic.service.PackageTypeService;
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;

/**
 * 包名称：com.bonus.boot.manager.basic.controller
 * 类名称：PackageTypeController
 * 类描述：套餐管理
 * 创建人：@author tqzhang
 * 创建时间：2023年05月31日 15:16
 */

@RestController
@RequestMapping("packageType")
public class PackageTypeController {

    @Resource
    private PackageTypeService service;

    @Resource
    private PackageTypeDao daoDao;

    @LogAnnotation
    @PostMapping("getMsgContent")
    @ApiOperation(value = "套餐管理-列表")
    public R getList(BaseTypePackageBean o){
        List<BaseTypePackageBean> 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 BaseTypePackageBean 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 BaseTypePackageBean bean){
        AjaxRes ar = new AjaxRes();
        int cb = service.updateInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
            if (cb == 3){
                ar.setFailMsg("套餐名称已存在");
            }
        }
        return  ar;
    }
    @RequestMapping(value = "getListById", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "套餐管理-查询单个医院")
    public AjaxRes getListById(String id){
        AjaxRes ar = new AjaxRes();
        BaseTypePackageBean BaseTypePackageBean = service.getListById(id);
        Map<String, Object> map = new HashMap<>();
        if(BaseTypePackageBean !=null){
            map.put("BaseTypePackageBean",BaseTypePackageBean);
        }
        ar.setSucceed(map,GlobalConst.DATA_SUCCEED);
        return ar;
    }


    @LogAnnotation
    @PostMapping("delById")
    @ApiOperation(value = "套餐管理-删除")
    public AjaxRes delById(BaseTypePackageBean 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;
    }
}
