package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.DictionaryDataModel;
import com.lightinit.hsdataplatform.model.admin.TreeModel;
import com.lightinit.hsdataplatform.service.admin.IDictionaryMgrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author WangYao
 * @date 2018/6/3 11:44
 * @description 字典管理控制器
 */
@Controller
@RequestMapping("/admin/dictionary_mgr")
public class DictionaryMgrController {

    @Autowired
    private IDictionaryMgrService dictionaryMgrService;

    @RequestMapping(value = "index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("admin/dictionary_mgr/index");
        return modelAndView;
    }

    @RequestMapping(value = "tree_data.action")
    @ResponseBody
    public List<TreeModel> getTreeData(){
        return dictionaryMgrService.queryTreeData();
    }

    @RequestMapping(value = "edit.action")
    @ResponseBody
    public ResultState<Long> doEdit(DictionaryDataModel inputModel){
        ResultState<Long> resultState = dictionaryMgrService.addOrEdit(inputModel);
        return resultState;
    }

    @RequestMapping(value = "delete_dic_group.action/{id}")
    @ResponseBody
    public ResultState deleteDicGroup(@PathVariable long id){
        ResultState<Long> resultState = dictionaryMgrService.deleteDicGroup(id);
        return resultState;
    }

    @RequestMapping(value = "delete_dic.action/{id}")
    @ResponseBody
    public ResultState deleteDic(@PathVariable long id){
        ResultState<Long> resultState = dictionaryMgrService.deleteDic(id);
        return resultState;
    }
}
