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

import com.bonus.boot.manager.health.entity.PmBaseCareerLimit;
import com.bonus.boot.manager.health.service.CareerdisposService;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 体检人数配置后台
 * lzh
 */
@RestController
@RequestMapping("/Careerdispos")
public class CareerdisposController {
    @Autowired
    private CareerdisposService CareerService;
    @LogAnnotation
    @PostMapping("getMsgContent")
    @ApiOperation(value = "用户管理-列表")
    public R getList(PmBaseCareerLimit o){
        List<PmBaseCareerLimit> list = CareerService.getMsgList(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 PmBaseCareerLimit bean) throws Exception {
        AjaxRes ar = new AjaxRes();
        int cb = CareerService.addInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
        }
        return  ar;
    }

    @RequestMapping(value = "updateInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "体检管理-预约人数配置修改")
    public AjaxRes updateInfo(@RequestBody PmBaseCareerLimit bean) throws Exception {
        AjaxRes ar = new AjaxRes();
        int cb = CareerService.updateInfo(bean);
        ar.setFailMsg(GlobalConst.DATA_FAIL);
        if(cb>0){
            ar.setFailMsg(GlobalConst.INIT_SUCCEED);
        }
        return  ar;
    }

    @LogAnnotation
    @PostMapping("delById")
    @ApiOperation(value = "体检管理-预约人数配置删除")
    public AjaxRes delById(PmBaseCareerLimit bean) {
        AjaxRes ar = new AjaxRes();
        int result  = CareerService.delById(bean);
        if(result==1){
            ar.setSucceedMsg(GlobalConst.DATA_SUCCEED);
        }else {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    @RequestMapping(value = "getListById", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "体检人员库-查询人员信息")
    public AjaxRes getListById(String id){
        AjaxRes ar = new AjaxRes();
        PmBaseCareerLimit PmBaseCareerLimit = CareerService.getListById(id);
        Map<String, Object> map = new HashMap<>();
        if(PmBaseCareerLimit !=null){
            map.put("PmBaseCareerLimit",PmBaseCareerLimit);
        }
        ar.setSucceed(map,GlobalConst.DATA_SUCCEED);
        return ar;
    }

}
