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

import com.bonus.gs.sub.evaluate.evaluate.beans.OrganizationalBean;
import com.bonus.gs.sub.evaluate.evaluate.beans.SetTemplateBean;
import com.bonus.gs.sub.evaluate.evaluate.beans.TeamEvaluateBean;
import com.bonus.gs.sub.evaluate.evaluate.dao.SetTemplateDao;
import com.bonus.gs.sub.evaluate.evaluate.service.EvaluateService;
import com.bonus.gs.sub.evaluate.evaluate.service.SetTemplateService;
import com.bonus.gs.sub.evaluate.manager.utils.AjaxRes;
import com.bonus.gs.sub.evaluate.manager.utils.GlobalConst;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

/**
 * @ClassName: SetTemplateController
 * @author: tqzhang
 * @Date: 2024/12/18 15:07
 * @version: 1.0
 * @description: 模板配置
 */
@Controller
@RequestMapping("/setTemplate/")
public class SetTemplateController {

    @Resource
    private SetTemplateService service;

    @Resource
    private SetTemplateDao dao;

    @GetMapping("getTemplateList")
    @ResponseBody
    public AjaxRes getTemplateList(SetTemplateBean o){
        AjaxRes ar = new AjaxRes();
        List<SetTemplateBean> list = service.getTemplateList(o);
        ar.setListSucceed(list);
        return ar;
    }

    @RequestMapping(value = "changeEnable", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes changeEnable(SetTemplateBean o){
        AjaxRes ar = new AjaxRes();
        Integer i = service.changeEnable(o);
        if (i > 0){
            ar.setRes(GlobalConst.SUCCEED);
            ar.setResMsg("启用成功");
            return ar;
        }else {
            ar.setRes(GlobalConst.FAIL);
            ar.setFailMsg("启用失败");
            return ar;
        }
    }

    @RequestMapping("deleteTemplateById")
    @ResponseBody
    public AjaxRes deleteTemplateById(String id) {
        AjaxRes ar = new AjaxRes();
        try {
            int result = dao.deleteTemplateById(id);
            if(result > 0) {
                ar.setRes(GlobalConst.SUCCEED);
                ar.setResMsg("删除成功");
            }else {
                ar.setFailMsg(GlobalConst.DATA_FAIL);
                ar.setResMsg("删除失败,请联系系统管理员");
            }

        }catch(Exception e) {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    @RequestMapping("addTemplate")
    @ResponseBody
    public AjaxRes addTemplate(SetTemplateBean o) {
        AjaxRes ar = new AjaxRes();
        try {
            ar = service.addTemplate(o);
        }catch(Exception e) {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }

    @RequestMapping(value = "getResponsibleDepartmentSelect", method = RequestMethod.POST)
    @ResponseBody
    public AjaxRes getResponsibleDepartmentSelect(SetTemplateBean bean) {
        AjaxRes ar = new AjaxRes();
        try {
            List<SetTemplateBean> list = dao.getResponsibleDepartmentSelect(bean);
            ar.setSucceed(list);
        } catch (Exception e) {
            ar.setFailMsg(GlobalConst.DATA_FAIL);
        }
        return ar;
    }
}
