package com.ruoyi.web.controller.front;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mingxue.domain.MxjbOperationManual;
import com.ruoyi.mingxue.service.IMxjbOperationManualService;
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;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "前端 操作视频")
@RestController
@RequestMapping("front/operationManual")
public class FrontOperationManualController extends BaseController {

    @Autowired
    private IMxjbOperationManualService operationManualService;

    @ApiOperation("01 获取操作视频/手册")
    @GetMapping(value = "getOperationManual")
    public AjaxResult getOperationManual(@ApiParam("知识点") @RequestParam String nameType) {
        MxjbOperationManual res = operationManualService.selectMxjbOperationManualByNameType(nameType);
        if(null==res){
            return AjaxResult.success(new ArrayList<MxjbOperationManual>());
        }

        SysUser user= SecurityUtils.getLoginUser().getUser();
        MxjbOperationManual query = new MxjbOperationManual().setId(res.getId())
                .setSource(user.getUserType())
                .setRoleIds(String.valueOf(user.getCurrentRoleId()));
        List<MxjbOperationManual> list = operationManualService.selectMxjbOperationManualAndChildren(query);
        //处理成tree
        List<MxjbOperationManual> resultList = operationManualService.buildTree(list);

        return AjaxResult.success(resultList);
    }
}
