package com.boman.gen.controller;


import com.boman.common.core.utils.SecurityUtils;
import com.boman.common.core.web.controller.BaseController;
import com.boman.domain.dto.AjaxResult;
import com.boman.common.core.web.page.TableDataInfo;
import com.boman.domain.GenTableRelation;
import com.boman.gen.service.IGenTableRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**关联关系表
 * @author tjf
 * @Date: 2021/03/25/16:02
 */
@RequestMapping("/genTableRelation")
@RestController
public class GenTableRelationController extends BaseController {
    @Autowired
    private IGenTableRelationService genTableRelationService;


    /**
     * 查询关联关系表列表
     */
    @GetMapping("/list")
    public TableDataInfo genTableRelationList(GenTableRelation genTableRelation) {
        startPage();
        List<GenTableRelation> list = genTableRelationService.selectGenTableRelationList(genTableRelation);
        return getDataTable(list);
    }

    /**
     * 根据关联关系表编号获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return AjaxResult.success(genTableRelationService.selectGenTableRelationById(id));
    }

    /**
     * 新增关联关系表
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody GenTableRelation genTableRelation)
    {

        genTableRelation.setCreateBy(SecurityUtils.getUsername());
        return toAjax(genTableRelationService.insertGenTableRelation(genTableRelation));
    }

    /**
     * 修改关联关系表
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody GenTableRelation genTableRelation)
    {

        genTableRelation.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(genTableRelationService.updateGenTableRelation(genTableRelation));
    }

    /**
     * 删除关联关系表
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(genTableRelationService.deleteGenTableRelation(ids));
    }

}
