package com.ruoyi.zongzhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zongzhi.domain.TcDataSourceTj;
import com.ruoyi.zongzhi.service.ITcDataSourceTjService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据来源统计Controller
 *
 * @author ruoyi
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/zongzhi/sourceTj")
@Api(tags = " 数据来源统计")
public class TcDataSourceTjController extends BaseController {
    @Resource
    private ITcDataSourceTjService tcDataSourceTjService;

    /**
     * 查询数据来源统计列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TcDataSourceTj tcDataSourceTj) {
        startPage();
        List<TcDataSourceTj> list = tcDataSourceTjService.selectTcDataSourceTjList(tcDataSourceTj);
        return getDataTable(list);
    }

    /**
     * 导出数据来源统计列表
     */
    @Log(title = "数据来源统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcDataSourceTj tcDataSourceTj) {
        List<TcDataSourceTj> list = tcDataSourceTjService.selectTcDataSourceTjList(tcDataSourceTj);
        ExcelUtil<TcDataSourceTj> util = new ExcelUtil<TcDataSourceTj>(TcDataSourceTj.class);
        util.exportExcel(response, list, "数据来源统计数据");
    }

    /**
     * 获取数据来源统计详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tcDataSourceTjService.selectTcDataSourceTjById(id));
    }

    /**
     * 新增数据来源统计
     */
    @Log(title = "数据来源统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcDataSourceTj tcDataSourceTj) {
        tcDataSourceTj.setIsStatus(true);
        return toAjax(tcDataSourceTjService.insertTcDataSourceTj(tcDataSourceTj));
    }

    /**
     * 修改数据来源统计
     */
    @Log(title = "数据来源统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcDataSourceTj tcDataSourceTj) {
        return toAjax(tcDataSourceTjService.updateTcDataSourceTj(tcDataSourceTj));
    }

    /**
     * 删除数据来源统计
     */
    @Log(title = "数据来源统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcDataSourceTjService.deleteTcDataSourceTjByIds(ids));
    }
}
