package com.ruoyi.cms.controller.app;


import com.ruoyi.cms.service.AppSkillService;
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.page.TableDataInfo;
import com.ruoyi.common.utils.SiteSecurityUtils;
import com.ruoyi.common.utils.StringUtils;
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("/app/appskill")
@Api(tags = "移动端:用户技能")
public class AppSkillController extends BaseController {
    @Autowired
    private AppSkillService appSkillService;

    /**
     * 列表
     */
    @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("新增技能信息")
    @PostMapping("/add")
    public AjaxResult save(@RequestBody AppSkill appSkill){
        if(StringUtils.isEmpty(appSkill.getName())){
            return AjaxResult.error("技能名称为空!");
        }
        if(StringUtils.isEmpty(appSkill.getLevels())){
            return AjaxResult.error("技能等级为空!");
        }
        if(appSkill.getUserId()==null){
            appSkill.setUserId(SiteSecurityUtils.getUserId());
        }
        return toAjax(appSkillService.insertAppskill(appSkill));
    }

    /**
     * 修改
     */
    @ApiOperation("修改技能详细信息")
    @PutMapping("/edit")
    public AjaxResult update(@RequestBody AppSkill appSkill){
        if(appSkill.getId()==null){
            return AjaxResult.error("技能id为空!");
        }
        if(StringUtils.isEmpty(appSkill.getName())){
            return AjaxResult.error("技能名称为空!");
        }
        if(StringUtils.isEmpty(appSkill.getLevels())){
            return AjaxResult.error("技能等级为空!");
        }
        if(appSkill.getUserId()==null){
            appSkill.setUserId(SiteSecurityUtils.getUserId());
        }
        return toAjax(appSkillService.updateAppskillById(appSkill));
    }

    /**
     * 删除
     */
    @ApiOperation("删除技能详细信息")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@ApiParam("主键id") @PathVariable Long id){
        if(id==null){
            return AjaxResult.error("参数id未传递!");
        }
        return toAjax(appSkillService.removeAppskillIds(new Long[]{id}));
    }

}
