package com.bonus.gs.sub.evaluate.evaluate.controller;

import com.bonus.gs.sub.evaluate.evaluate.beans.EvaluateBean;
import com.bonus.gs.sub.evaluate.evaluate.beans.EvaluatePersonBean;
import com.bonus.gs.sub.evaluate.evaluate.beans.OrganizationalBean;
import com.bonus.gs.sub.evaluate.evaluate.dao.OrganizationalDao;
import com.bonus.gs.sub.evaluate.evaluate.service.OrganizationalService;
import com.bonus.gs.sub.evaluate.manager.controller.BaseController;
import com.bonus.gs.sub.evaluate.manager.utils.AjaxRes;
import com.bonus.gs.sub.evaluate.manager.utils.GlobalConst;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 *
 * 外包单位组织架构控制层
 * @author 黑子
 */
@Api(tags = "外包单位组织架")
@Controller
@RequestMapping("/organizational")
public class OrganizationalController extends BaseController<EvaluateBean> {


    @Resource
    private OrganizationalService service;

    @Resource
    private OrganizationalDao dao;
    /**
     * 树拆线呢
     * @param bean
     * @return
     */
    @RequestMapping(value = "/getTreeList", method = RequestMethod.GET)
    @ResponseBody
    public AjaxRes getTreeList(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<OrganizationalBean> list = service.getTreeList(bean);
            ar.setSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }
    @RequestMapping(value = "/getEvaluatePersonList", method = RequestMethod.GET)
    @ResponseBody
    public AjaxRes getEvaluatePersonList(EvaluatePersonBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<EvaluatePersonBean> list = dao.getEvaluatePersonList(bean);
            ar.setListSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }


    /**
     * 项目下拉选
     * @param bean
     * @return
     */
    @RequestMapping(value = "getDeptSelected", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getDeptSelected(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<OrganizationalBean> list = service.getDeptSelected(bean);
            ar.setListSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }


    /**
     * 负责人下拉选
     * @param bean
     * @return
     */
    @RequestMapping(value = "getLeaderSelect", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getLeaderSelect(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<OrganizationalBean> list = dao.getLeaderSelect(bean);
            ar.setSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }
    /**
     * 外包商下拉选
     * @param bean
     * @return
     */
    @RequestMapping(value = "getOutSourceSelected", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getOutSourceSelected(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<OrganizationalBean> list = service.getOutSourceSelected(bean);
            ar.setSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }


    /**
     * 新增人员下拉选(isAdd==1）
     * 修改 不传
     * @param bean
     * @return
     */
    @RequestMapping(value = "getAddUserSelected", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getAddUserSelected(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            List<OrganizationalBean> list = service.getAddUserSelected(bean);
            ar.setSucceed(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    /**
     * 新增数据接口
     * 修改 不传
     * @param bean
     * @return
     */
    @RequestMapping(value = "addData", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes addData(@RequestBody OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
             ar = service.addData(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }
    @RequestMapping(value = "addDept", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes addDept(@RequestBody OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
             ar = service.addDept(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }



    /**
     * 更换班组长
     * 更换班组长
     * @param bean
     * @return
     */
    @RequestMapping(value = "updateLeader", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes updateLeader(@RequestBody OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            ar = service.updateLeader(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }


    /**
     * 查询详情
     * @param bean
     * @return
     */
    @RequestMapping(value = "getDataDetails", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getDataDetails(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            ar = service.getDataDetails(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }
    /**
     * 退场
     * @param bean
     * @return
     */
    @RequestMapping(value = "userOutData", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes userOutData(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            ar = service.userOutData(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    @RequestMapping(value = "userOutDataFail", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes userOutDataFail(OrganizationalBean bean) {
        AjaxRes ar = getAjaxRes();
        try {
            ar = service.userOutDataFail(bean);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }



}
