package com.inspect.metadata.threshold.controller;

import com.inspect.metadata.threshold.domain.BasedataThresholdModification;
import com.inspect.metadata.threshold.service.IBasedataThresholdModificationService;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
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;

@RestController
@RequestMapping({"/threshold"})
public class BasedataThresholdModificationController extends BaseController {
    @Resource
    private IBasedataThresholdModificationService basedataThresholdModificationService;

    @RequiresPermissions({"basedata:threshold:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataThresholdModification basedataThresholdModification) {
        this.startPage();
        List<BasedataThresholdModification> list = this.basedataThresholdModificationService.selectBasedataThresholdModificationList(basedataThresholdModification);
        return this.getDataTable(list);
    }

    @RequiresPermissions({"basedata:threshold:export"})
    @Log(
            title = "算法阈值修改记录",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataThresholdModification basedataThresholdModification) {
        List<BasedataThresholdModification> list = this.basedataThresholdModificationService.selectBasedataThresholdModificationList(basedataThresholdModification);
        ExcelUtil<BasedataThresholdModification> util = new ExcelUtil<>(BasedataThresholdModification.class);
        util.exportExcel(response, list, "算法阈值修改记录数据");
    }

    @RequiresPermissions({"basedata:threshold:query"})
    @GetMapping({"/{lineId}"})
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId) {
        return AjaxResult.success(this.basedataThresholdModificationService.selectBasedataThresholdModificationByLineId(lineId));
    }

    @RequiresPermissions({"basedata:threshold:add"})
    @Log(
            title = "算法阈值修改记录",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody BasedataThresholdModification basedataThresholdModification) {
        return this.toAjax(this.basedataThresholdModificationService.insertBasedataThresholdModification(basedataThresholdModification));
    }

    @RequiresPermissions({"basedata:threshold:edit"})
    @Log(
            title = "算法阈值修改记录",
            businessType = BizType.UPDATE
    )
    @PutMapping
    public AjaxResult edit(@RequestBody BasedataThresholdModification basedataThresholdModification) {
        return this.toAjax(this.basedataThresholdModificationService.updateBasedataThresholdModification(basedataThresholdModification));
    }

    @RequiresPermissions({"basedata:threshold:remove"})
    @Log(
            title = "算法阈值修改记录",
            businessType = BizType.DELETE
    )
    @DeleteMapping({"/{lineIds}"})
    public AjaxResult remove(@PathVariable Long[] lineIds) {
        return this.toAjax(this.basedataThresholdModificationService.deleteBasedataThresholdModificationByLineIds(lineIds));
    }
}
