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


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.BaseStateReqDTO;
import com.bc.exam.core.api.dto.PagingReqDTO;
import com.bc.exam.modules.dict.entity.SysDictData;
import com.bc.exam.modules.dict.entity.SysDictType;
import com.bc.exam.modules.dict.service.SysDictDataService;
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("/sys/api/dict/data")
public class SysDictDataController extends BaseController {
    @Resource
    private SysDictDataService baseService;

    /**
     * 分页查找
     * @param reqDTO 分页入参
     * @return 分页结果
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<SysDictData>> paging(@RequestBody PagingReqDTO<SysDictType> reqDTO) {
        //分页查询
        IPage<SysDictData> page = baseService.paging(reqDTO);
        return super.success(page);
    }

    /**
     * 保存或修改提交记录
     * @return
     */
    @ApiOperation(value = "保存或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody SysDictData reqDTO) {
        baseService.saveData(reqDTO);
        return success();
    }

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

    @ApiOperation(value = "修改状态")
    @PostMapping("/state")
    public ApiRest state(@RequestBody BaseStateReqDTO reqDTO) {
        QueryWrapper<SysDictData> wrapper = new QueryWrapper<>();
        wrapper.lambda().in(SysDictData::getId, reqDTO.getIds());
        SysDictData record = new SysDictData();
        record.setState(reqDTO.getState());
        baseService.update(record, wrapper);
        return super.success();
    }
}

