package ink.wgink.service.department.controller.route;

import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.interfaces.dictionary.IDictionaryCheckService;
import ink.wgink.util.ResourceUtil;
import ink.wgink.util.request.StaticResourceRequestUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DepartmentRouteController
 * @Description: 组织部门
 * @Author: wanggeng
 * @Date: 2021/1/29 2:53 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.ROUTE_TAGS_PREFIX + "组织部门接口")
@Controller
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/department")
public class DepartmentRouteController {

    @Autowired(required = false)
    private IDictionaryCheckService dictionaryCheckService;

    @GetMapping("save")
    public ModelAndView save() {
        ModelAndView mv = new ModelAndView("department/save");
        mv.addObject("hasArea", dictionaryCheckService == null ? false : true);
        return mv;
    }

    @GetMapping("save-merge")
    public ModelAndView saveMerge() {
        return new ModelAndView("department/save-merge");
    }

    @GetMapping("save-split")
    public ModelAndView saveSplit() {
        return new ModelAndView("department/save-split");
    }

    @GetMapping("update")
    public ModelAndView update() {
        ModelAndView mv = new ModelAndView("department/update");
        mv.addObject("hasArea", dictionaryCheckService == null ? false : true);
        return mv;
    }

    @GetMapping("update-split")
    public ModelAndView updateSplit() {
        return new ModelAndView("department/update-split");
    }

    @GetMapping("get")
    public ModelAndView get() {
        return new ModelAndView("department/get");
    }

    @GetMapping("get-merge")
    public ModelAndView getMerge() {
        return new ModelAndView("department/get-merge");
    }

    @GetMapping("list")
    public ModelAndView list() {
        return new ModelAndView("department/list");
    }

    @GetMapping("list-split")
    public ModelAndView listSplit() {
        return new ModelAndView("department/list-split");
    }

    @GetMapping("list-tree")
    public ModelAndView listTree() {
        return new ModelAndView("department/list-tree");
    }

    @GetMapping("list-tree-select")
    public ModelAndView listTreeSelect() {
        return new ModelAndView("department/list-tree-select");
    }

    @GetMapping("list-tree-check")
    public ModelAndView listTreeCheck() {
        return new ModelAndView("department/list-tree-check");
    }

    @GetMapping("list-tree-user")
    public ModelAndView listTreeUser() {
        return new ModelAndView("department/list-tree-user");
    }

    @GetMapping("upload/upload-excel")
    public ModelAndView uploadExcel() {
        return new ModelAndView("department/upload/upload-excel");
    }

    @GetMapping("upload/upload-excel-template")
    public void excelTemplate(HttpServletResponse response) throws IOException {
        InputStream inputStream = ResourceUtil.getJarResourceInputStream("templates/department/upload/upload-excel-template.xls");
        StaticResourceRequestUtil.download(response, inputStream, "导入模板.xls");
    }

}
