package com.jwipc.sys.controller.pc;

import com.jwipc.sys.dto.OrgAddOrEditDTO;
import com.jwipc.sys.logic.OrgLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Controller
@RequestMapping(MODULE_ROOT + "/org")
@RequiredArgsConstructor
public class OrgPageController {
    private final OrgLogic orgLogic;

    @GetMapping("orgTree")
    public String orgTree() {
        return MODULE_ROOT + "/org/tree";
    }

    @GetMapping("userOrgAdd")
    public String userRoleAdd(Model model, Long userId) {
        model.addAttribute("userId", userId);
        return MODULE_ROOT + "/org/user_org_add";
    }

    @GetMapping("index")
    public String index() {
        return MODULE_ROOT + "/org/index";
    }

    @GetMapping("addOrEdit")
    public String addOrEdit(Long id, Long parentId, Model model) {
        model.addAttribute("id", id);

        model.addAttribute("parentId", parentId);
        OrgAddOrEditDTO addOrEditDTO = orgLogic.getForEdit(id, parentId);
        model.addAttribute("org", addOrEditDTO);
        return MODULE_ROOT + "/org/add_edit";
    }
}
