package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.dictionary.*;
import com.lightinit.hsdataplatform.entity.Activity;
import com.lightinit.hsdataplatform.entity.ActivityWithBLOBs;
import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.entity.Roadshow;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.ActivitySearchModel;
import com.lightinit.hsdataplatform.model.admin.RoadShowSearchModel;
import com.lightinit.hsdataplatform.service.admin.IActivityMgrService;
import com.lightinit.hsdataplatform.service.admin.IRoadShowMgrService;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * 路演管理
 */
@Controller
@RequestMapping("/admin/roadshow_mgr")
public class RoadShowMgrController {

    @Autowired
    private IRoadShowMgrService roadShowMgrService;

    @RequestMapping(value = "index.htm")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("admin/roadshow_mgr/index");
        modelAndView.addObject("dicRoadShowStage", DicRoadShowStage.getInstacne().getDicMap());
        modelAndView.addObject("dicRoadShowState", DicRoadShowState.getInstacne().getDicMap());
        modelAndView.addObject("dicRoadShowTrade", DicRoadShowTrade.getInstacne().getDicMap());
        return modelAndView;
    }


    @RequestMapping(value = "list.action")
    public ModelAndView list(RoadShowSearchModel inputModel, @RequestParam(defaultValue = "1") int pageNo) {
        ModelAndView modelAndView = new ModelAndView("admin/roadshow_mgr/list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<Roadshow> outputModel = roadShowMgrService.queryList(inputModel, pager);
        pager.setTotal(roadShowMgrService.queryCount(inputModel));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }

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

    @RequestMapping(value = "detail.htm")
    public ModelAndView detail(@RequestParam("id") long id) {
        ModelAndView modelAndView = new ModelAndView("admin/roadshow_mgr/detail");
        Map<String, Object> map = roadShowMgrService.queryOne(id);
        modelAndView.addObject("busiModel", map.get("roadshowWithBLOBs"));
        modelAndView.addObject("auditor", map.get("auditor"));
        return modelAndView;
    }
}
