package com.goldenwater.web.controller.hzz;

import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.hzz.domain.ArticleDTO;
import com.goldenwater.hzz.domain.FileWsnDTO;
import com.goldenwater.hzz.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hzz/rule")
public class RuleController extends BaseController {
    @Autowired
    private RuleService service;

    @GetMapping("/list")
    public AjaxResult list(@RequestParam(defaultValue = "") String adCode, @RequestParam(required = false) String ruleType) {
        return success(service.getRuleMessage(adCode, ruleType));
    }

    @GetMapping("/file/list")
    public TableDataInfo fileList(@RequestParam(defaultValue = "") String types, @RequestParam(required = false) String fileName, @RequestParam(required = false) String fileType, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        return getDataTable(service.getWsnList(types, fileName, fileType, startTime, endTime, pageNum, pageSize));
    }

    @PostMapping("/file")
    public AjaxResult addFile(@RequestBody FileWsnDTO p) {
        return toAjax(service.insertWsn(p));
    }

    @PutMapping("/file")
    public AjaxResult editFile(@RequestBody FileWsnDTO p) {
        return toAjax(service.updateWsn(p));
    }

    @DeleteMapping("/file/{guid}")
    public AjaxResult delFile(@PathVariable String guid) {
        return toAjax(service.deleteWsn(guid));
    }

    @GetMapping("/article/list")
    public TableDataInfo articleList(@RequestParam(required = false) String title, @RequestParam(required = false) String type, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        return getDataTable(service.getArticleList(title, type, startTime, endTime, pageNum, pageSize));
    }

    @GetMapping("/article/top5")
    public AjaxResult articleTop5(@RequestParam(defaultValue = "0") String type) {
        return success(service.getArticleTop5(type));
    }

    @PostMapping("/article")
    public AjaxResult addArticle(@RequestBody ArticleDTO p) {
        return toAjax(service.addArticle(p));
    }

    @PutMapping("/article")
    public AjaxResult editArticle(@RequestBody ArticleDTO p) {
        return toAjax(service.updateArticle(p));
    }

    @DeleteMapping("/article/{guid}")
    public AjaxResult delArticle(@PathVariable String guid) {
        return toAjax(service.deleteArticle(guid));
    }
}
