package com.ylx.web.controller.massage;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.annotation.Log;
import com.ylx.common.core.controller.BaseController;
import com.ylx.common.core.domain.R;
import com.ylx.common.enums.BusinessType;
import com.ylx.common.utils.StringUtils;

import com.ylx.massage.domain.TComment;

import com.ylx.massage.service.TCommentService;
import com.ylx.order.service.TOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 评论 前端控制器
 */

@RestController
@Api(tags = {"评论"})
@RequestMapping("api/comment/v1")
public class TCommentController extends BaseController {
    @Resource
    private TCommentService commentService;

    @Resource
    private TOrderService orderService;



    /**
     * 后台管理新增评论
     * @param comment
     * @return R
     */
    @ApiOperation("后台管理新增评论")
    @RequestMapping(value = "black/add", method = RequestMethod.POST)
    public R blackAdd(@RequestBody TComment comment) {
        return R.ok(commentService.save(comment));

    }

    /**
     * 查询评论（用户端）
     * @param cJsid
     * @return List<TComment>
     */
    @ApiOperation("查询评论")
    @ApiImplicitParam(name = "cJsid", value = "技师id", required = true, dataType = "String", paramType = "query", dataTypeClass = String.class)
    @RequestMapping(value = "wx/select", method = RequestMethod.POST)
    public List<TComment> wxSelect(@RequestParam String cJsid) {
        QueryWrapper<TComment> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(TComment::getcJsid, cJsid);
        wrapper.lambda().orderByDesc(TComment::getdTime);
        return commentService.list(wrapper);
    }

    /**
     * 分页查询评论（后台管理系统）
     *
     * @param page
     * @param comment
     * @return Page<TComment>
     */
    @ApiOperation("分页查询评论")
    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public Page<TComment> select(Page<TComment> page, TComment comment) {
        LambdaQueryWrapper<TComment> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
        objectLambdaQueryWrapper.like(StringUtils.isNotBlank(comment.getName()), TComment::getName, comment.getName()).
                orderByDesc(TComment::getdTime);
        return commentService.page(page, objectLambdaQueryWrapper);
    }

    @PostMapping("delete")
    @ApiOperation("删除数据")
    @Log(title = "评论删除数据", businessType = BusinessType.DELETE)
    public R delete(@RequestBody List<String> idList) {
        return R.ok(this.commentService.removeByIds(idList));
    }
}
