package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.model.admin.ResourceAllImagesListModel;
import com.lightinit.hsdataplatform.model.admin.ResourceAllImagesSearchModel;
import com.lightinit.hsdataplatform.model.admin.ResourceAllImgFreeParentModel;
import com.lightinit.hsdataplatform.model.admin.ResourceNoImgThemeListModel;
import com.lightinit.hsdataplatform.service.admin.IResourceShareImagesService;
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/resourceShareImg")
public class ResourceShareImgController {

    @Autowired
    private IResourceShareImagesService imagesService ;

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

    @RequestMapping(value = "allImageList.htm")
    public ModelAndView allImageList(){
        ModelAndView modelAndView = new ModelAndView("admin/resourceShareImg/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/resourceShareImg/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/resourceShareImg/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/resourceShareImg/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 shareType){
        return imagesService.findThemesByName(shareType);
    }

    @RequestMapping(value = "property.htm")
    public ModelAndView property(String resourceId){
        ModelAndView modelAndView = new ModelAndView("admin/resourceShareImg/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/resourceShareImg/resourceList");
        ResourceAllImagesListModel outputModel = imagesService.resourceList(resourceId);
        modelAndView.addObject("output", outputModel);
        return modelAndView;
    }

}

