package com.yihu.jw.base.endpoint.menu;

import com.yihu.jw.base.service.article.KnowledgeArticleService;
import com.yihu.jw.base.service.menu.BaseMenuManageService;
import com.yihu.jw.entity.hospital.article.KnowledgeArticleDictDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = BaseRequestMapping.MenuNologin.PREFIX)
@Api(value = "首页菜单管理免登录接口", description = "首页菜单管理免登录接口", tags = {"基础服务 - 首页菜单管理免登录接口"})
public class BaseMenuNoLoginEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private BaseMenuManageService menuService;
    @Autowired
    private KnowledgeArticleService knowledgeArticleService;
    @GetMapping(value = BaseRequestMapping.MenuNologin.findAllMenu)
    @ApiOperation(value = "查询首页列表")
    public Envelop findMenuShowByKey(
            @ApiParam(name = "parentId", value = "parentId", required = false)
            @RequestParam(value = "parentId",required = false) String parentId,
            @ApiParam(name = "name", value = "name", required = false)
            @RequestParam(value = "name",required = false) String name) {
        try {
            return success(menuService.findMenuShow());
        }catch (Exception e){
            return failedException(e);
        }
    }

    @GetMapping(value = BaseRequestMapping.MenuNologin.findMenuByParentId)
    @ApiOperation(value = "查询二级菜单")
    public Envelop findMenuByParentId(
            @ApiParam(name = "parentId", value = "parentId", required = false)
            @RequestParam(value = "parentId",required = false) String parentId,
            @ApiParam(name = "status", value = "status", required = false)
            @RequestParam(value = "status",required = false) Integer status) {
        try {
            return success(menuService.findByParentId(parentId,status));
        }catch (Exception e){
            return failedException(e);
        }
    }
    @GetMapping(value = BaseRequestMapping.MenuNologin.findArticleByMenuId)
    @ApiOperation(value = "查询文章")
    public Envelop findArticleByMenuid(
            @ApiParam(name = "menuId", value = "menuId", required = false)
            @RequestParam(value = "menuId",required = true) String menuId,
            @ApiParam(name = "page", value = "page", required = false)
            @RequestParam(value = "page",required = true) Integer page,
            @ApiParam(name = "pageSize", value = "pageSize", required = false)
            @RequestParam(value = "pageSize",required = true) Integer pageSize) {
        try {
            return success(menuService.findArticleByMenuId(menuId,page,pageSize));
        }catch (Exception e){
            return failedException(e);
        }
    }
    @GetMapping(value = BaseRequestMapping.MenuNologin.queryById)
    @ApiOperation(value = "根据id查询文章")
    public Envelop queryByCode(
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id", required = true)String id) throws Exception{
        try {
            KnowledgeArticleDictDO articleDO = knowledgeArticleService.retrieve(id);
            return success(articleDO);
        }catch (Exception e){
            return failedException(e);
        }
    }

}
