package com.xhpc.general.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.general.domain.HelpEntity;
import com.xhpc.general.service.IXhpcHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帮助管理controller
 * program: ruoyi
 * User: HongYun
 * Date:2021-08-02 11
 */
@RestController
@RequestMapping("/help")
public class XhpcHelpController extends BaseController {

    @Autowired
    IXhpcHelpService iXhpcHelpService;

    @Log(title = "帮助-删除", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult deleteHelpItem(@RequestBody HelpEntity helpEntity){

        return iXhpcHelpService.deleteHelpItem(helpEntity.getHelpId());
    }

    @Log(title = "帮助-添加", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult insertHelpItem(@RequestBody HelpEntity helpEntity){

        return iXhpcHelpService.insertHelpItem(helpEntity.getTitle(),helpEntity.getContent(),helpEntity.getType());
    }

    @Log(title = "帮助-修改", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult updateHelpItem(@RequestBody HelpEntity helpEntity){

        return iXhpcHelpService.updateHelpItem(helpEntity.getHelpId(),helpEntity.getTitle(),helpEntity.getContent(),helpEntity.getType());
    }

    @GetMapping("/selectItems")
    public TableDataInfo selectHelpItems(String title, String createBy, Integer type){

        startPage();
        List<HelpEntity> list=iXhpcHelpService.selectHelpItems(title, createBy, type);
        return getDataTable(list);
    }



    @GetMapping("/selectItem")
    public AjaxResult selectHelpItem(@RequestParam Long helpId){

        return iXhpcHelpService.selectHelpItem(helpId);
    }


    @GetMapping(value = "/listTitles")
    public TableDataInfo listTitles(@RequestParam Integer type){

        startPage();
        return getDataTable(iXhpcHelpService.selectTitleId(type));

    }

    @GetMapping(value = "/showContent")
    public AjaxResult listDetails(@RequestParam Long helpId){

        return AjaxResult.success(iXhpcHelpService.selectDetails(helpId));
    }

}
