package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.DeptInfoDTO;
import com.diagbot.dto.GetDeptInfoDTO;
import com.diagbot.dto.GetQuestionInfoDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.facade.DeptInfoFacade;
import com.diagbot.facade.QuestionFacade;
import com.diagbot.facade.QuestionUsualFacade;
import com.diagbot.vo.DeleteQuestionUsualVO;
import com.diagbot.vo.GetDeptInfoVO;
import com.diagbot.vo.GetQuestionInfoVO;
import com.diagbot.vo.GetQuestionUsualByDeptVO;
import com.diagbot.vo.QuestionUsualVO;
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 javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 常用标签表 前端控制器
 * </p>
 *
 * @author wangyu
 * @since 2018-12-03
 */
@RestController
@RequestMapping("/questionUsual")
@SuppressWarnings("unchecked")
@Api(value = "常用标签维护相关API", tags = { "常用标签维护相关API" })
public class QuestionUsualController {

    @Autowired
    private QuestionUsualFacade questionUsualFacade;
    @Autowired
    private DeptInfoFacade deptInfoFacade;
    @Autowired
    private QuestionFacade questionFacade;

    @ApiOperation(value = "常用标签维护——添加和修改[by:wangyu]",
            notes = "deptId: 科室id,必填<br>" +
                    "questionName: 症状名称，必填")
    @PostMapping("/addQuestionUsual")
    @SysLogger("addQuestionUsual")
    @Transactional
    public RespDTO<Boolean> addQuestionUsual(@Valid @RequestBody QuestionUsualVO questionUsualVO) {
        Boolean data = questionUsualFacade.addQuestionUsual(questionUsualVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "常用标签维护——删除[by:wangyu]",
            notes = "deptId: 科室id,必填<br>" +
                    "type: 标签类型,必填<br>")
    @PostMapping("/deleteQuestionUsual")
    @SysLogger("deleteQuestionUsual")
    @Transactional
    public RespDTO<Boolean> deleteQuestionUsual(@Valid @RequestBody DeleteQuestionUsualVO deleteQuestionUsualVO) {
        Boolean data = questionUsualFacade.deleteQuestionUsualByDeptId(deleteQuestionUsualVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "常用标签维护——获取科室名称[by:wangyu]",
            notes = "")
    @PostMapping("/getDeptName")
    @SysLogger("getDeptName")
    public RespDTO<List<DeptInfoDTO>> getDeptName() {
        List<DeptInfoDTO> data = deptInfoFacade.getAllDeptInfo();
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "常用标签维护——获取标签信息[by:wangyu]",
            notes = "tagName: 标签名称，非必填<br>" +
                    "deptId: 科室id，如果是添加不用填，如果是修改页面必填<br>" +
                    "noIds: 需要去掉的标签id，非必填<br>" +
                    "type: 归属类型，必填")
    @PostMapping("/getQuestionInfo")
    @SysLogger("getQuestionInfo")
    public RespDTO<List<GetQuestionInfoDTO>> getQuestionInfo(@Valid @RequestBody GetQuestionInfoVO getQuestionInfoVO) {
        List<GetQuestionInfoDTO> data = questionFacade.getQuestiongInfosByName(getQuestionInfoVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "常用标签维护——根据科室获取常用标签信息(修改和详情用)[by:wangyu]",
            notes = "deptId: 科室id,必填<br>")
    @PostMapping("/getQuestionUsualByDept")
    @SysLogger("getQuestionUsualByDept")
    public RespDTO<List<GetQuestionInfoDTO>> getQuestionUsualByDept(@Valid @RequestBody GetQuestionUsualByDeptVO getQuestionUsualByDeptVO) {
        List<GetQuestionInfoDTO> data = questionFacade.getQuestionUsualByDept(getQuestionUsualByDeptVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "常用标签维护——获取科室信息(常见症状维护系统页面查询)[by:wangyu]",
            notes = "name: 科室名称<br>")
    @PostMapping("/getDeptInfos")
    @SysLogger("getDeptInfos")
    public RespDTO<IPage<GetDeptInfoDTO>> getDeptInfos(@Valid @RequestBody GetDeptInfoVO getDeptInfoVO) {
        IPage<GetDeptInfoDTO> data = questionUsualFacade.getDeptInfos(getDeptInfoVO);
        return RespDTO.onSuc(data);
    }
}
