package com.ruoyi.interfaces.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.interfaces.core.page.Page;
import com.ruoyi.interfaces.core.page.PageParam;
import com.ruoyi.interfaces.core.page.PageUtils;
import com.ruoyi.interfaces.domain.PtConsult;
import com.ruoyi.interfaces.service.PtConsultService;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author
 * @date 2022-1-20
 */
@RestController
@RequestMapping("/pt/consult")
public class PtConsultController extends BaseController {

    private final PtConsultService ptConsultService;

    public PtConsultController(PtConsultService ptConsultService) {
        this.ptConsultService = ptConsultService;
    }

    @ApiOperation("添加用户咨询")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public AjaxResult insert(@RequestBody PtConsult ptConsult) {
        ptConsult.setUserId(String.valueOf(getUserId()));
        return AjaxResult.success(ptConsultService.save(ptConsult));
    }

    @ApiOperation("回复用户咨询")
    @RequestMapping(value = "/reply", method = RequestMethod.POST)
    public AjaxResult reply(@RequestBody PtConsult ptConsult) {
        ptConsult.setReplyUserId(String.valueOf(getUserId()));
        ptConsult.setRplytm(new Date());
        return AjaxResult.success(ptConsultService.update(ptConsult));
    }

    @ApiOperation("根据ID删除用户咨询")
    @GetMapping(value = "delete/{id}")
    public AjaxResult delete(@PathVariable String id) {
        int ret = ptConsultService.delete(id);
        return AjaxResult.success();
    }

    @ApiOperation("根据ID获取用户咨询（单表）")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public AjaxResult get(@PathVariable String id) {
        PtConsult ptConsult = ptConsultService.get(id);
        return AjaxResult.success(ptConsult);
    }

    @ApiOperation("用户咨询(分页)")
    @PostMapping("pageList")
    public Page pageList(@RequestBody PageParam<PtConsult> pageParam) {
        return PageUtils.convert(ptConsultService.findPageInfo(pageParam));
    }

}
