package com.xjrsoft.module.student.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.common.constant.GlobalConstant;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.student.dto.AddPbCseSpecplanDto;
import com.xjrsoft.module.student.dto.UpdatePbCseSpecplanDto;
import cn.dev33.satoken.annotation.SaCheckPermission;

import com.xjrsoft.module.student.dto.PbCseSpecplanPageDto;
import com.xjrsoft.module.student.entity.PbCseSpecplan;
import com.xjrsoft.module.student.service.IPbCseSpecplanService;
import com.xjrsoft.module.student.vo.PbCseSpecplanPageVo;

import com.xjrsoft.module.student.vo.PbCseSpecplanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* @title: 
* @Author szs
* @Date: 2024-04-03
* @Version 1.0
*/
@RestController
@RequestMapping("/student" + "/pbCseSpecplan")
@Api(value = "/student"  + "/pbCseSpecplan",tags = "代码")
@AllArgsConstructor
public class PbCseSpecplanController {


    private final IPbCseSpecplanService pbCseSpecplanService;

    @GetMapping(value = "/page")
    @ApiOperation(value="列表(分页)")
    @SaCheckPermission("pbcsespecplan:detail")
    public RT<PageOutput<PbCseSpecplanPageVo>> page(@Valid PbCseSpecplanPageDto dto){

        LambdaQueryWrapper<PbCseSpecplan> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                    //.orderByDesc(PbCseSpecplan::getId)
                .select(PbCseSpecplan.class,x -> VoToColumnUtil.fieldsToColumns(PbCseSpecplanPageVo.class).contains(x.getProperty()));
        IPage<PbCseSpecplan> page = pbCseSpecplanService.page(ConventPage.getPage(dto), queryWrapper);
        PageOutput<PbCseSpecplanPageVo> pageOutput = ConventPage.getPageOutput(page, PbCseSpecplanPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询信息")
    @SaCheckPermission("pbcsespecplan:detail")
    public RT<PbCseSpecplanVo> info(@RequestParam Long id){
        PbCseSpecplan pbCseSpecplan = pbCseSpecplanService.getById(id);
        if (pbCseSpecplan == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(BeanUtil.toBean(pbCseSpecplan, PbCseSpecplanVo.class));
    }


    @PostMapping
    @ApiOperation(value = "新增")
    @SaCheckPermission("pbcsespecplan:add")
    public RT<Boolean> add(@Valid @RequestBody AddPbCseSpecplanDto dto){
        PbCseSpecplan pbCseSpecplan = BeanUtil.toBean(dto, PbCseSpecplan.class);
        boolean isSuccess = pbCseSpecplanService.save(pbCseSpecplan);
    return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    @SaCheckPermission("pbcsespecplan:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdatePbCseSpecplanDto dto){

        PbCseSpecplan pbCseSpecplan = BeanUtil.toBean(dto, PbCseSpecplan.class);
        return RT.ok(pbCseSpecplanService.updateById(pbCseSpecplan));

    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @SaCheckPermission("pbcsespecplan:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(pbCseSpecplanService.removeBatchByIds(ids));

    }

}