package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.KeyWord;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.HotWordListModel;
import com.lightinit.hsdataplatform.model.admin.HotWordModel;
import com.lightinit.hsdataplatform.model.admin.LoginUser;
import com.lightinit.hsdataplatform.service.admin.IHotWordService;
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 javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value="/admin/HotWord")
public class HotWordController extends BaseController {
    @Autowired
    private IHotWordService hotWordService;

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

    /**
     * 首页列表
     * @param
     * @param
     * @return
     */
    @RequestMapping(value="list.action")
    public ModelAndView list() {
        ModelAndView modelAndView = new ModelAndView("/admin/hotWord/list");

        List<HotWordListModel> outputModel = hotWordService.queryList();
        modelAndView.addObject("list", outputModel);
        return modelAndView;
    }
    @RequestMapping(value="add.action")
    @ResponseBody
    public ResultState add(HttpSession session, HotWordModel inputModel) {
        LoginUser loginUser = (LoginUser) session.getAttribute(LoginUser.SESSION_KEY_LOGIN_USER);
        inputModel.setCreatedBy(loginUser.getId());
        return hotWordService.add(inputModel);
    }

    @RequestMapping(value="del.action/{id}")
    @ResponseBody
    public ResultState del(@PathVariable Long id) {

        return hotWordService.del(id);
    }
    @RequestMapping(value="move.htm/{id}")
    @ResponseBody
    public ModelAndView move(@PathVariable Long id) {
        ModelAndView modelAndView = new ModelAndView("/admin/hotWord/move");
        KeyWord model = hotWordService.selectById(id);
        modelAndView.addObject("model", model);
        return modelAndView;
    }

    @RequestMapping(value="doMove.action")
    @ResponseBody
    public ResultState doMove(HotWordModel inputModel) {

        return hotWordService.doMove(inputModel);
    }



}
