package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.DataCollection;
import com.cool.bang.modules.business.service.IDataCollectionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 数据集合
 *
 * @author PeiZhi Guo
 * @version 1.0.0
 * 2024-10-31 17:05
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "collection/v1")
public class DataCollectionController extends BaseController {

    private IDataCollectionService dataCollectionService;

    @Autowired
    public DataCollectionController(IDataCollectionService dataCollectionService) {
        this.dataCollectionService = dataCollectionService;
    }

    @GetMapping
    public ResultTable main(PageDomain pageDomain, DataCollection param) {
        param.setDelFlag(1);
        PageInfo<DataCollection> clfDataCollectionPage = dataCollectionService.page(pageDomain, param);
        return pageTable(clfDataCollectionPage.getList(), clfDataCollectionPage.getTotal());
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Long id) {
        return success(dataCollectionService.queryById(id));
    }

    @PostMapping
    public Result add(@RequestBody DataCollection dataCollection) {
        dataCollection.insertConfigure();
        return decide(dataCollectionService.save(dataCollection));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody DataCollection dataCollection) {
        return decide(dataCollectionService.update(dataCollection));
    }

    @DeleteMapping("{id}")
    public Result remove(@PathVariable Integer id) {
        return decide(dataCollectionService.removeById(id));
    }

}
