package com.bc.exam.modules.liuyan.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bc.exam.core.api.ApiRest;
import com.bc.exam.core.api.controller.BaseController;
import com.bc.exam.core.api.dto.BaseIdsReqDTO;
import com.bc.exam.core.api.dto.PagingReqDTO;
import com.bc.exam.modules.liuyan.entity.TLiuyan;
import com.bc.exam.modules.liuyan.service.TLiuyanService;
import com.bc.exam.modules.user.UserUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description 描述:留言信息表 前端控制器
 * @Author A贾宇婷034244310
 * @Date 20260615
 */
@RestController
@RequestMapping("/liuyan/lygl")
public class TLiuyanController extends BaseController {

    @Resource
    TLiuyanService tLiuyanService;


    /**
     * 留言分页查找
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<TLiuyan>> paging(@RequestBody PagingReqDTO<TLiuyan> reqDTO) {
        //分页查询并转换
        IPage<TLiuyan> page = tLiuyanService.paging(reqDTO);
        return super.success(page);
    }


    /**
     * 公告表添加或修改
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "留言表添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody TLiuyan reqDTO) {
        reqDTO.setUserid(UserUtils.getUserId());
        tLiuyanService.saveOrUpdate(reqDTO);
        return super.success();
    }

    /**
     * 批量删除
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "批量删除")
    @PostMapping("delete")
    public ApiRest edit(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        tLiuyanService.removeByIds(reqDTO.getIds());
        return super.success();
    }
}

