package com.ruoyi.cms.controller.cms;


import com.ruoyi.cms.service.AppSkillService;
import com.ruoyi.cms.service.IAppUserService;
import com.ruoyi.cms.util.RoleUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.AppSkill;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
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.*;

import java.util.List;


/**
 * 用户技能信息
 *
 * @author 
 * @email 
 * @date 2025-10-21 12:22:09
 */
@RestController
@RequestMapping("/cms/appskill")
@Api(tags = "后台:用户技能")
public class CmsSkillController extends BaseController {
    @Autowired
    private AppSkillService appSkillService;
    @Autowired
    private IAppUserService appUserService;

    /**
     * 列表
     */
    @ApiOperation("获取技能列表")
    @GetMapping("/list")
    public TableDataInfo list(AppSkill appSkill){
        startPage();
        List<AppSkill> list=appSkillService.getList(appSkill);
        return getDataTable(list);
    }


    /**
     * 信息
     */
    @ApiOperation("获取技能详情")
    @GetMapping(value = "/{id}")
    public AjaxResult info(@PathVariable("id") Long id){
        return success(appSkillService.getAppskillById(id));
    }

    /**
     * 保存
     */
    @ApiOperation("新增技能")
    @Log(title = "技能", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult save(@RequestBody AppSkill appSkill){
        if(SecurityUtils.isLogin()){
            AppUser appUser=appUserService.selectAppuserByIdcard(RoleUtils.getCurrentUseridCard());
            if(appUser==null){
                return AjaxResult.error("未传递userId!");
            }
            appSkill.setUserId(appUser.getUserId());
        }else {
            return AjaxResult.error("未登录!");
        }
        return toAjax(appSkillService.insertAppskill(appSkill));
    }

    /**
     * 修改
     */
    @ApiOperation("修改技能")
    @Log(title = "技能", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult update(@RequestBody AppSkill appSkill){
        if (appSkill.getId()==null){
            return AjaxResult.error("参数id未传递!");
        }
        return toAjax(appSkillService.updateAppskillById(appSkill));
    }

    /**
     * 删除
     */
    @Log(title = "删除技能", businessType = BusinessType.DELETE)
    @ApiOperation("技能")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@ApiParam("主键ids") @PathVariable Long[] ids){
        if(ids==null){
            return AjaxResult.error("参数ids未传递!");
        }
        return toAjax(appSkillService.removeAppskillIds(ids));
    }

}
