package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.QuestionDTO;
import com.diagbot.dto.QuestionPageDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.QuestionInfo;
import com.diagbot.facade.QuestionFacade;
import com.diagbot.vo.DeleteQuestionVO;
import com.diagbot.vo.QuestionIdsVO;
import com.diagbot.vo.QuestionIndexVO;
import com.diagbot.vo.QuestionPageVO;
import com.diagbot.vo.QuestionSaveVO;
import com.diagbot.vo.QuestionSpecVO;
import com.diagbot.vo.QuestionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标签基础表 前端控制器
 * </p>
 *
 * @author zhoutg
 * @since 2018-11-23
 */
@RestController
@RequestMapping("/questionInfo")
@SuppressWarnings("unchecked")
@Api(value = "标签相关API——数据谨慎操作", tags = { "标签相关API——数据谨慎操作" })
public class QuestionInfoController {

    @Autowired
    QuestionFacade questionFacade;

    @ApiOperation(value = "标签新增或更新[by:zhoutg]",
            notes = "")
    @PostMapping("/saveOrUpdate")
    @SysLogger("saveOrUpdate")
    @Transactional
    public RespDTO<Boolean> saveOrUpdate(@RequestBody QuestionSaveVO questionSaveVO) {
        questionFacade.saveOrUpdate(questionSaveVO);
        return RespDTO.onSuc(true);
    }


    @ApiOperation(value = "标签列表[by:zhoutg]",
            notes = "")
    @PostMapping("/list")
    @SysLogger("list")
    public RespDTO<IPage<QuestionPageDTO>> list(@RequestBody QuestionPageVO questionPageVO) {
        IPage<QuestionPageDTO> data = questionFacade.getListFac(questionPageVO);
        return RespDTO.onSuc(data);
    }


    @ApiOperation(value = "标签检索[by:zhoutg]",
            notes = "")
    @PostMapping("/index")
    @SysLogger("index")
    public RespDTO<List<QuestionInfo>> index(@RequestBody QuestionIndexVO questionIndexVO) {
        List<QuestionInfo> data = questionFacade.indexFac(questionIndexVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "别名新增标签检索[by:rengb]",
            notes = "")
    @PostMapping("/indexRev")
    @SysLogger("indexRev")
    public RespDTO<List<QuestionInfo>> indexRev(@RequestBody QuestionIndexVO questionIndexVO) {
        List<QuestionInfo> data = questionFacade.indexRev(questionIndexVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "获取特殊标签（同伴|无）[by:zhoutg]",
            notes = "")
    @PostMapping("/getSpecial")
    @SysLogger("getSpecial")
    public RespDTO<List<QuestionInfo>> getSpecial(@RequestBody QuestionSpecVO questionSpecVO) {
        List<QuestionInfo> data = questionFacade.getSpecialFac(questionSpecVO);
        return RespDTO.onSuc(data);
    }


    @ApiOperation(value = "标签删除[by:zhoutg]",
            notes = "")
    @PostMapping("/delete")
    @SysLogger("delete")
    @Transactional
    public RespDTO<Boolean> delete(@RequestBody DeleteQuestionVO deleteQuestionVO) {
        questionFacade.deleteByIdsFac(deleteQuestionVO.getIds());
        return RespDTO.onSuc(true);
    }


    @ApiOperation(value = "根据参数返回标签内容[by:zhoutg]",
            notes = "id: questionId<br>" +
                    "sexType：性别，1：男，2：女<br>" +
                    "age：年龄")
    @PostMapping("/getById")
    public RespDTO<QuestionDTO> getById(@RequestBody QuestionVO questionVO) {
        QuestionDTO data = questionFacade.getById(questionVO);
        return RespDTO.onSuc(data);
    }


    @ApiOperation(value = "查询多个id返回标签内容[by:zhoutg]",
            notes = "ids: 多个questionId<br>" +
                    "sexType：性别，1：男，2：女<br>" +
                    "age：年龄")
    @PostMapping("/getByIds")
    public RespDTO<Map<Long, Object>> getByIds(@RequestBody QuestionIdsVO questionIdsVO) {
        Map<Long, Object> data = questionFacade.getByIds(questionIdsVO);
        return RespDTO.onSuc(data);
    }
}
