package com.ho.business.controller;

import com.ho.business.entity.PageConfig;
import com.ho.business.service.PageConfigService;
import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.annotation.TokenIgnore;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;

/**
 * @author gyan
 * @desc: TODO
 * @DateTime: 2023/8/8 14:30
 */
@RestController
@RequestMapping(ContextConstant.BUSINESS + "config")
@Api(tags = "页面字段配置")
@Slf4j
public class PageConfigController {
    @Autowired
    private PageConfigService pageConfigService;

    //新增
    @PostMapping("add")
    @ApiOperation(value = "新增页面字段数据配置")
    @LogAnnotation(title = "页面字段配置", action = "新增页面字段数据配置")
    public DataResult add(@RequestBody List<PageConfig> configList) {
        int i = pageConfigService.addBatch(configList);
        return DataResult.success();
    }

    //查询
    @PostMapping("selectAll")
    @ApiOperation(value = "查询")
    public DataResult<List<PageConfig>> pageModelType(@RequestBody PageConfig vo){
        List<PageConfig> configList = pageConfigService.selectPage(vo);
        return DataResult.success(configList);
    }

    /**
     * 删除接口（支持批量）
     *
     * @param ids
     * @return
     */
    @PostMapping("delete")
    @ApiOperation(value = "删除页面字段数据配置")
    @LogAnnotation(title = "页面字段配置", action = "删除页面字段数据配置")
    @TokenIgnore
    public DataResult delete(@RequestBody List<Integer> ids) {
         pageConfigService.delete(ids);
        return DataResult.success();
    }


}
