package com.goldenwater.web.controller.portal;

import com.goldenwater.slgc.entity.portal.Djxx;
import com.goldenwater.slgc.service.portal.IDjxxService;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.enums.BusinessType;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@RestController
@Validated
@RequestMapping("/portal/djxx")
public class DjxxController extends BaseController {
    @Autowired
    private IDjxxService djxxService;

    @GetMapping("/list")
    public TableDataInfo list(Djxx djxx) {
        startPage();
        List<Djxx> list = djxxService.selectList(djxx);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(djxxService.selectById(id));
    }

    @Log(title = "党建信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Djxx djxx) {
        return toAjax(djxxService.insert(djxx));
    }

    @Log(title = "党建信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Djxx djxx) {
        return toAjax(djxxService.update(djxx));
    }

    @Log(title = "党建信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(djxxService.deleteByIds(ids));
    }
}
