package com.ruoyi.system.controller;

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.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ActOperation1;
import com.ruoyi.system.domain.ActSuppliesHistorydata;
import com.ruoyi.system.domain.ActSuppliesImportCleaningAcc;
import com.ruoyi.system.model.HistorySaveDataModel;
import com.ruoyi.system.service.IActSuppliesHistorydataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  历史数据Controller
 *
 * @author dongjg
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/historydata")
public class ActSuppliesHistorydataController extends BaseController
{
    @Autowired
    private IActSuppliesHistorydataService actSuppliesHistorydataService;

    /**
     * 查询 历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActSuppliesHistorydata actSuppliesHistorydata)
    {
        startPage();
        List<ActSuppliesHistorydata> list = actSuppliesHistorydataService.selectActSuppliesHistorydataList(actSuppliesHistorydata);
        return getDataTable(list);
    }

    /**
     * 导出 历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:export')")
    @GetMapping("/export")
    public AjaxResult export(ActSuppliesHistorydata actSuppliesHistorydata)
    {
        List<ActSuppliesHistorydata> list = actSuppliesHistorydataService.selectActSuppliesHistorydataList(actSuppliesHistorydata);
        ExcelUtil<ActSuppliesHistorydata> util = new ExcelUtil<ActSuppliesHistorydata>(ActSuppliesHistorydata.class);
        return util.exportExcel(list, " 历史数据");
    }

    /**
     * 获取 历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(actSuppliesHistorydataService.selectActSuppliesHistorydataById(id));
    }

    /**
     * 新增 历史数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:add')")
    @PostMapping
    public AjaxResult add(@RequestBody List<ActSuppliesHistorydata> actSuppliesHistorydata)
    {
        return toAjax(actSuppliesHistorydataService.insertActSuppliesHistorydata(actSuppliesHistorydata));
    }

    /**
     * 修改 历史数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ActSuppliesHistorydata actSuppliesHistorydata)
    {
        return toAjax(actSuppliesHistorydataService.updateActSuppliesHistorydata(actSuppliesHistorydata));
    }

    /**
     * 删除 历史数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(actSuppliesHistorydataService.deleteActSuppliesHistorydataByIds(ids));
    }

    /**
     * 添加 通用or六矿历史数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsert')")
    @PostMapping("/addInsert")
    public AjaxResult addInsert(@RequestBody List<ActSuppliesHistorydata> actSuppliesHistorydata)
    {
        actSuppliesHistorydataService.addInsertActSuppliesHistorydata(actSuppliesHistorydata);
        return toAjax(1);
    }


    /**
     * 添加 通用凭证单历史数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsertAccount')")
    @PostMapping("/addInsertAccount")
    public AjaxResult addInsertAccount(@RequestBody List<ActSuppliesHistorydata> actSuppliesHistorydata)
    {
        System.out.println(actSuppliesHistorydata);
        actSuppliesHistorydataService.addInsertActSuppliesHistorydataAcc(actSuppliesHistorydata);
        return toAjax(1);
    }

    /**
     * 数据清洗 六矿生成表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsert1')")
    @PostMapping("/addInsert1")
    public AjaxResult addInsert1(@RequestBody List<ActOperation1> actOperation2s)
    {
        actSuppliesHistorydataService.addInsertImport(actOperation2s);
        return toAjax(1);
    }

    /**
     * 数据清洗 六矿导入表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsert2')")
    @PostMapping("/addInsert2")
    public AjaxResult addInsert2(@RequestBody List<ActOperation1> actOperation2s)
    {

        actSuppliesHistorydataService.addInsertImportss(actOperation2s);
        return toAjax(1);

    }

    /**
     * 数据清洗 凭证单六矿生成表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsertAccount1')")
    @PostMapping("/addInsertAccount1")
    public AjaxResult addInsertAccount1(@RequestBody List<ActOperation1> actOperation2s)
    {
        actSuppliesHistorydataService.addInsertImportAccpunt(actOperation2s);
        return toAjax(1);
    }

    /**
     * 数据清洗 凭证单六矿导入表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsertAccount2')")
    @PostMapping("/addInsertAccount2")
    public AjaxResult addInsertAccount2(@RequestBody List<ActOperation1> actOperation2s)
    {

        actSuppliesHistorydataService.addInsertImportssAccounts(actOperation2s);
        return toAjax(1);

    }

    /**
     * 数据清洗 通用生成表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsertConvert1')")
    @PostMapping("/addInsertConvert1")
    public AjaxResult addInsertConvert1(@RequestBody List<ActOperation1> actOperation2s)
    {

        actSuppliesHistorydataService.addInsertConvert1(actOperation2s);

        return toAjax(1);
    }

    /**
     * 数据清洗 通用导入表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:addInsertConvert2')")
    @PostMapping("/addInsertConvert2")
    public AjaxResult addInsertConvert2(@RequestBody List<ActOperation1> actOperation2s)
    {

        actSuppliesHistorydataService.addInsertConvert2(actOperation2s);

        return toAjax(1);
    }

    /**
     * 数据清洗 通用导入表数据
     */
    @PreAuthorize("@ss.hasPermi('system:historydata:selectActsuppliesCleaningCopyAcc')")
    @GetMapping("/selectActsuppliesCleaningCopyAcc/{id}")
    public TableDataInfo selectActsuppliesCleaningCopyAcc(@PathVariable("id") Long id)
    {
        List<ActSuppliesImportCleaningAcc> actSuppliesImportCleaningAccs = actSuppliesHistorydataService.selectActSuppliesCleaningCopyAcc(id);
        return getDataTable(actSuppliesImportCleaningAccs);
    }

    @PreAuthorize("@ss.hasPermi('system.historydata.save')")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody HistorySaveDataModel historySaveDataModel){
        actSuppliesHistorydataService.saveHistoryData(historySaveDataModel);
        return toAjax(1);
    }
    @PreAuthorize("@ss.hasPermi('system.historydata.selectData')")
    @GetMapping("/select/data")
    public TableDataInfo selectData(){
        return getDataTable(actSuppliesHistorydataService.selectNewData());
    }
    @PreAuthorize("@ss.hasPermi('system.historydata.selectContent')")
    @GetMapping("/selectbyid")
    public AjaxResult selectContent(@RequestParam("id") Integer id){
        return actSuppliesHistorydataService.selectContent(id);
    }
    @PreAuthorize("@ss.hasPermi('system.historydata.deleteById')")
    @GetMapping("/deletebyid")
    public AjaxResult deleteById(@RequestParam("id") Integer id){
        actSuppliesHistorydataService.deleteById(id);
        return toAjax(1);
    }
}

