package com.inspect.guideline.controller;

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.guideline.domain.PatrolGuidelineRule;
import com.inspect.guideline.service.IPatrolGuidelineRuleService;

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

import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/guideline_rule"})
public class PatrolGuidelineRuleController extends BaseController {
    private final IPatrolGuidelineRuleService patrolGuidelineRuleService;

    public PatrolGuidelineRuleController(IPatrolGuidelineRuleService patrolGuidelineRuleService) {
        this.patrolGuidelineRuleService = patrolGuidelineRuleService;
    }

    @GetMapping({"/list"})
    public TableDataInfo list(PatrolGuidelineRule patrolGuidelineRule) {
        this.startPage();
        List<PatrolGuidelineRule> list = this.patrolGuidelineRuleService.selectPatrolGuidelineRuleList(patrolGuidelineRule);
        return this.getDataTable(list);
    }

    @Log(
            title = "664导则细则",
            businessType = BizType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, PatrolGuidelineRule patrolGuidelineRule) {
        List<PatrolGuidelineRule> list = this.patrolGuidelineRuleService.selectPatrolGuidelineRuleList(patrolGuidelineRule);
        ExcelUtil<PatrolGuidelineRule> util = new ExcelUtil<>(PatrolGuidelineRule.class);
        util.exportExcel(response, list, "664导则细则数据");
    }

    @GetMapping({"/{guidelineRuleId}"})
    public AjaxResult getInfo(@PathVariable("guidelineRuleId") Long guidelineRuleId) {
        return AjaxResult.success(this.patrolGuidelineRuleService.selectPatrolGuidelineRuleByGuidelineRuleId(guidelineRuleId));
    }

    @Log(
            title = "664导则细则",
            businessType = BizType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody PatrolGuidelineRule patrolGuidelineRule) {
        return this.toAjax(this.patrolGuidelineRuleService.insertPatrolGuidelineRule(patrolGuidelineRule));
    }

    @Log(
            title = "664导则细则",
            businessType = BizType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody PatrolGuidelineRule patrolGuidelineRule) {
        return this.toAjax(this.patrolGuidelineRuleService.updatePatrolGuidelineRule(patrolGuidelineRule));
    }

    @Log(
            title = "664导则细则",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{guidelineRuleIds}"})
    public AjaxResult remove(@PathVariable Long[] guidelineRuleIds) {
        return this.toAjax(this.patrolGuidelineRuleService.deletePatrolGuidelineRuleByGuidelineRuleIds(guidelineRuleIds));
    }
}
