package cn.com.ty.lift.ud.expertComment.controller;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.common.DelReq;
import cn.com.ty.lift.ud.expertComment.mapper.entity.ExpertCommentEntity;
import cn.com.ty.lift.ud.expertComment.service.IExpertCommentService;
import cn.com.xwy.boot.web.dto.RestResponse;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.ty.lift.ud.expertComment.controller.query.ExpertCommentQuery;

import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 诊单评论  API
 * 
 * @author Xson
 * @date 2020-05-06
 */
@Api(tags = "诊单评论  API - 小陶")
@RestController
@RequestMapping("/api/expertComments")
public class ExpertCommentController extends BaseController<ExpertCommentEntity,ExpertCommentQuery> {

    private final Logger log = LoggerFactory.getLogger(ExpertCommentController.class);
    
    private @Autowired
    IExpertCommentService expertCommentService;

    @Override
    protected IService<ExpertCommentEntity> getService() {
        return expertCommentService;
    }

    /**
     * 重写条件查询的方法
     * @param request
     * @return
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/query-page")
    @Override
    public RestResponse getCondition(@RequestBody ExpertCommentQuery request) {
        if(request.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return expertCommentService.selectByExample(request);
        }
    }

    @ApiOperation(value = "批量显示")
    @PostMapping("/useBath")
    public RestResponse useBath(@RequestBody DelReq ids) {
        expertCommentService.updateByIds(ids.getIds(), 0);
        return RestResponse.success(null, "显示成功");
    }

    @ApiOperation(value = "批量屏蔽")
    @PostMapping("/noUseBath")
    public RestResponse noUseBath(@RequestBody DelReq ids) {
        expertCommentService.updateByIds(ids.getIds(), 1);
        return RestResponse.success(null, "屏蔽成功");
    }

    /**
     * 获取专家评论-分页
     * @param request
     * @return
     */
    @ApiOperation(value = "获取专家评论")
    @PostMapping("/query-expert")
    public RestResponse getExpertComment(@RequestBody ExpertCommentQuery request) {
        if(request.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return expertCommentService.getExpertComment(request);
        }
    }

    /**
     * 重写新增的方法
     * @param entity
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "新增")
    @Override
    public RestResponse create(@RequestBody ExpertCommentEntity entity) {
        if(null == entity.getLifeCaseId()){
            return RestResponse.fail( "诊单不能为空");
        }
        if(null == entity.getExpertId()){
            return RestResponse.fail( "专家不能为空");
        }
        if(null == entity.getAttitude()){
            return RestResponse.fail( "服务态度不能为空");
        }
        if(null == entity.getResponseSpeed()){
            return RestResponse.fail( "回复速度不能为空");
        }
        if(null == entity.getTech()){
            return RestResponse.fail( "技术服务不能为空");
        }
        if(null == entity.getUserId()){
            return RestResponse.fail( "评论人不能为空");
        }
        return expertCommentService.saveComment(entity);

    }


}