package com.lightinit.hsdataplatformresdir.controller.admin;

import com.lightinit.hsdataplatformresdir.entity.BaseExample;
import com.lightinit.hsdataplatformresdir.model.admin.ResourceAllImagesListModel;
import com.lightinit.hsdataplatformresdir.model.admin.ResourceAllImagesSearchModel;
import com.lightinit.hsdataplatformresdir.model.admin.ResourceAllImgFreeParentModel;
import com.lightinit.hsdataplatformresdir.model.admin.ResourceNoImgThemeListModel;
import com.lightinit.hsdataplatformresdir.service.admin.IResourceBasicsImagesService;
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/resourceBasicsImg")
public class ResourceBasicsImgController {

    @Autowired
    private IResourceBasicsImagesService imagesService ;

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

    @RequestMapping(value = "allImageList.htm")
    public ModelAndView allImageList(){
        ModelAndView modelAndView = new ModelAndView("admin/resourceBasicsImg/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/resourceBasicsImg/noImageList");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        inputModel.setPage(pager);
        List<ResourceAllImagesListModel> outputModel = imagesService.findBasicsAllList(inputModel);
        pager.setTotal(imagesService.findBasicsAllListCount(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/resourceBasicsImg/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/resourceBasicsImg/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/resourceBasicsImg/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/resourceBasicsImg/resourceList");
        ResourceAllImagesListModel outputModel = imagesService.resourceList(resourceId);
        modelAndView.addObject("output", outputModel);
        return modelAndView;
    }

}

