package com.diagbot.web;

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

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.GetRetrievalsByTagDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.RetrievalExcelImDTO;
import com.diagbot.dto.RetrievalListDTO;
import com.diagbot.facade.RetrievalFacade;
import com.diagbot.vo.AddTagRetrievalVO;
import com.diagbot.vo.DelRetrievalsByQuesIdVO;
import com.diagbot.vo.GetRetrievalsByTagVO;
import com.diagbot.vo.RetrievalListVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 同义词检索表 前端控制器
 * </p>
 *
 * @author rgb
 * @since 2018--12
 */
@RestController
@RequestMapping("/retrieval")
@SuppressWarnings("unchecked")
@Api(value = "同义词维护相关API", tags = { "同义词维护相关API" })
public class RetrievalController {

    @Autowired
    private RetrievalFacade retrievalFacade;

    @ApiOperation(value = "根据标签获取同义词[by:rengb]")
    @PostMapping("/getRetrievalsByTag")
    @SysLogger("getRetrievalsByTag")
    public RespDTO<Map<Integer, List<GetRetrievalsByTagDTO>>> getRetrievalsByTag(@Valid @RequestBody GetRetrievalsByTagVO getRetrievalsByTagVO) {
        return RespDTO.onSuc(retrievalFacade.getRetrievalsByTag(getRetrievalsByTagVO));
    }

    @ApiOperation(value = "根据标签id删除标签的同义词[by:rengb]")
    @PostMapping("/delRetrievalsByQuesId")
    @SysLogger("delRetrievalsByQuesId")
    @Transactional
    public RespDTO<Boolean> delRetrievalsByQuesId(@Valid @RequestBody DelRetrievalsByQuesIdVO delRetrievalsByQuesIdVO) {
        return RespDTO.onSuc(retrievalFacade.delRetrievalsByQuesId(delRetrievalsByQuesIdVO));
    }

    @ApiOperation(value = "添加或者编辑标签同义词[by:rengb]")
    @PostMapping("/addTagRetrieval")
    @SysLogger("addTagRetrieval")
    @Transactional
    public RespDTO<Boolean> addTagRetrieval(@Valid @RequestBody AddTagRetrievalVO addTagRetrievalVO) {
        return RespDTO.onSuc(retrievalFacade.addTagRetrieval(addTagRetrievalVO));
    }

    @ApiOperation(value = "获取标签同义词列表[by:rengb]")
	@PostMapping("/retrievalList")
	@SysLogger("retrievalList")
	public RespDTO<IPage<RetrievalListDTO>> retrievalList(@RequestBody RetrievalListVO retrievalListVO) {
    	IPage<RetrievalListDTO> ipage = retrievalFacade.retrievalList(retrievalListVO);
		return RespDTO.onSuc(ipage);
	}
    
    @ApiOperation(value = "同义词excel文件导入[by:rengb]")
    @PostMapping("/retrievalExcelIm")
    @Transactional
    public RespDTO<RetrievalExcelImDTO> retrievalExcelIm(@RequestParam("uploadfile") MultipartFile file,HttpServletRequest request) {
        return RespDTO.onSuc(retrievalFacade.retrievalExcelIm(file));
    }
    

}
