package com.yida.data.device.telephone.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.telephone.EduTelephoneMsg;
import com.yida.data.device.telephone.service.EduTelephoneMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 亲情电话-留言 Controller
 *
 * @author zhanghaijun
 * @date 2021-08-10 17:31:56
 */
@Api(tags = "亲情电话-留言")
@Slf4j
@Validated
@RestController
@RequestMapping("/telephone/msg")
@RequiredArgsConstructor
public class EduTelephoneMsgController {

    private final EduTelephoneMsgService eduTelephoneMsgService;

    @ApiOperation("查询留言列表")
    @GetMapping("/listMsg")
    public ResultBean<List<EduTelephoneMsg>> listMsg(@RequestParam @ApiParam("卡Id") Long cardId) {
        return ResultBean.buildSuccess(eduTelephoneMsgService.list(Wrappers.lambdaQuery(new EduTelephoneMsg())
                .eq(EduTelephoneMsg::getCardId, cardId).orderByDesc(EduTelephoneMsg::getCreateDate)));
    }


    @ApiOperation("新增留言")
    @PostMapping("/saveMsg")
    public ResultBean saveMsg(@RequestBody EduTelephoneMsg eduTelephoneMsg) {
        eduTelephoneMsgService.save(eduTelephoneMsg);
        return ResultBean.buildSuccess();
    }
}
