package com.ningdatech.kqapi.admin.controller;

import com.ningdatech.basic.model.IdVo;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.kqapi.admin.manage.AdminMatterManage;
import com.ningdatech.kqapi.admin.model.req.MatterListReq;
import com.ningdatech.kqapi.admin.model.vo.MatterDetailDTO;
import com.ningdatech.kqapi.admin.model.vo.MatterListVO;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * MatterController
 * </p>
 *
 * @author WendyYang
 * @since 16:10 2024/4/20
 */
@Api(tags = "事项管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/matter")
public class MatterController {

    private final AdminMatterManage matterManage;

    @DeleteMapping("/del")
    @ApiOperation("删除事项")
    @WebLog("删除事项")
    public void del(@RequestBody IdVo<Long> id) {
        matterManage.del(id);
    }

    @GetMapping("/page")
    @ApiOperation("事项列表")
    @WebLog("事项列表")
    public PageVo<MatterListVO> pageMatter(MatterListReq req) {
        return matterManage.pageMatter(req);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("事项详情")
    @WebLog("事项详情")
    public MatterDetailDTO detail(@PathVariable Long id) {
        return matterManage.detail(id);
    }

    @PostMapping("/save")
    @ApiOperation("事项保存或修改")
    @WebLog("事项保存或修改")
    public void saveOrUpdate(@RequestBody MatterDetailDTO req) {
        matterManage.saveOrUpdate(req);
    }

    @PostMapping("/importMatter")
    @WebLog("导入服务事项")
    @ApiOperation("导入服务事项")
    public void importMatter(@RequestParam("file") MultipartFile file,
                             @RequestParam("matterType") Integer matterType) {
        matterManage.importMatter(file, matterType);
    }

    @GetMapping("/downloadMatterImportTemplate/{matterType}")
    @WebLog("下载政策服务事项配置模板")
    @ApiOperation("下载政策服务事项配置模板")
    public void downloadMatterImportTemplate(HttpServletResponse response, @PathVariable Integer matterType) {
        matterManage.downloadMatterImportTemplate(response, matterType);
    }

}
