package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.model.admin.*;
import com.lightinit.hsdataplatform.service.admin.IResourceAllImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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;

@Controller
@RequestMapping("/admin/resourceAllImg")
public class ResourceAllImagesController {

    @Autowired
    private IResourceAllImagesService imagesService ;

    @RequestMapping(value = "allImage.htm")
    public ModelAndView allImage(){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/imageIndex");
        return modelAndView;
    }

    @RequestMapping(value = "allImageList.htm")
    public ModelAndView allImageList(){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/noImageIndex");
        return modelAndView;
    }

    @RequestMapping(value = "findAll.action")
    @ResponseBody
    public ResourceAllImgFreeParentModel findAll(ResourceAllImagesSearchModel inputModel){
        return imagesService.findAll(inputModel);
    }


    @RequestMapping(value = "findAllList.action")
    public ModelAndView findAllList(ResourceAllImagesSearchModel inputModel, @RequestParam(defaultValue = "1") int pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/noImageList");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        inputModel.setPage(pager);
        List<ResourceAllImagesListModel> outputModel = imagesService.findAllList(inputModel);
        pager.setTotal(imagesService.findAllListCount(inputModel));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }

    @RequestMapping(value = "theme.htm")
    public ModelAndView theme(String theme){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/themeImage");
        String removeStr = "主题" ;
        theme = theme.replace(removeStr,"").trim() ;
        modelAndView.addObject("theme",theme) ;
        return modelAndView;
    }

    @RequestMapping(value = "themeList.action")
    public ModelAndView themeList(ResourceNoImgThemeListModel inputModel,@RequestParam(defaultValue = "1") int pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/themeList");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        inputModel.setPage(pager);
        List<ResourceAllImagesListModel> outputModel = imagesService.findAllThemeList(inputModel);
        pager.setTotal(imagesService.findAllThemeListCount(inputModel));
        modelAndView.addObject("list", outputModel);
        modelAndView.addObject("pager", pager);
        return modelAndView;
    }

    @RequestMapping(value = "findThemesByName.action")
    @ResponseBody
    public ResourceAllImgFreeParentModel findThemesByName(String themeCode){
        return imagesService.findThemesByName(themeCode);
    }

    @RequestMapping(value = "property.htm")
    public ModelAndView property(String resourceId){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/propertyImage");
        String removeStr = "资源" ;
        resourceId = resourceId.replace(removeStr,"").trim() ;
        modelAndView.addObject("resourceId",resourceId) ;
        return modelAndView;
    }

    @RequestMapping(value = "findResourceById.action")
    @ResponseBody
    public ResourceAllImgFreeParentModel findResourceById(String resourceId){
        return imagesService.findResourceById(resourceId);
    }

    @RequestMapping(value = "resourceList.action")
    public ModelAndView resourceList(String resourceId){
        ModelAndView modelAndView = new ModelAndView("admin/resourceAllImg/resourceList");
        ResourceAllImagesListModel outputModel = imagesService.resourceList(resourceId);
        modelAndView.addObject("output", outputModel);
        return modelAndView;
    }

}

