package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.IntroducePageDTO;
import com.diagbot.dto.QuestionShortDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.IntroduceInfo;
import com.diagbot.facade.IntroduceInfoFacade;
import com.diagbot.vo.IdVO;
import com.diagbot.vo.IntroducePageVO;
import com.diagbot.vo.IntroduceVO;
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 springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 提示信息 前端控制器
 * </p>
 *
 * @author zhaops
 * @since 2018-11-16
 */
@RestController
@RequestMapping("/introduceInfo")
@SuppressWarnings("unchecked")
@Api(value = "提示信息维护相关API", tags = { "提示信息维护相关API" })
public class IntroduceInfoController {

    @Autowired
    IntroduceInfoFacade introduceInfoFacade;

    @ApiOperation(value = "保存提示信息[by:zhaops]",
            notes = "id: 修改时带id,新增时为空<br>" +
                    "name: 名称，必填<br>" +
                    "remark：备注<br>" +
                    "detailVOList:提示信息明细列表<br>" +
                    "title：提示信息标题<br>" +
                    "content：提示信息<br>" +
                    "text：提示信息-纯文本<br>" +
                    "orderNo：排序号<br>" +
                    "position：显示位置<br>")
    @PostMapping("/saveIntroduce")
    @SysLogger("saveIntroduce")
    @Transactional
    public RespDTO<Boolean> saveIntroduce(@RequestBody @Valid IntroduceVO introduceVO) {
        Boolean data = introduceInfoFacade.saveIntroduce(introduceVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "单条删除提示信息[by:zhaops]",
            notes = "id: id,必填")
    @PostMapping("/deleteRecord")
    @SysLogger("deleteRecord")
    @Transactional
    public RespDTO<Boolean> deleteRecord(@RequestBody IdVO idVO) {
        Boolean data = introduceInfoFacade.deleteRecord(idVO.getId());
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "批量删除提示信息[by:zhaops]",
            notes = "ids: ids,必填")
    @PostMapping("/deleteRecords")
    @SysLogger("deleteRecords")
    @Transactional
    public RespDTO<Boolean> deleteRecords(@RequestBody List<IdVO> ids) {
        Boolean data = introduceInfoFacade.deleteRecords(ids);
        return RespDTO.onSuc(data);
    }

    /**
     * 分页查询提示信息，可带条件
     *
     * @param introducePageVO
     * @return
     */
    @ApiOperation(value = "分页查询提示信息，可带条件[by:zhaops]",
            notes = "current:页码，必填<br>" +
                    "size:每页显示条数，必填<br>" +
                    "name:提示信息名称<br>" +
                    "tagName:标签名称<br>")
    @PostMapping("/getIntroducePage")
    @SysLogger("getIntroducePage")
    public RespDTO getIntroducePage(@RequestBody IntroducePageVO introducePageVO) {
        IPage<IntroducePageDTO> infoIPage = introduceInfoFacade.getIntroducePageByMap(introducePageVO);
        return RespDTO.onSuc(infoIPage);
    }

    /**
     * 带条件查询
     *
     * @param map
     * @return
     */
    @ApiOperation(value = "带条件查询提示信息[by:zhaops]",
            notes = "map:查询条件（=），key为数据库字段名<br>")
    @PostMapping("/getByMap")
    @SysLogger("getByMap")
    @ApiIgnore
    public RespDTO<IntroduceInfo> getByMap(@RequestBody Map<String, Object> map) {
        List<IntroduceInfo> data = introduceInfoFacade.getByMap(map);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "根据id获取提示信息[by:zhaops]",
            notes = "id:id，必填<br>")
    @PostMapping("/getIntroduceById")
    @SysLogger("getIntroduceById")
    public RespDTO<IntroducePageDTO> getIntroduceById(@RequestBody IdVO idVO) {
        IntroducePageDTO data = introduceInfoFacade.getIntroduceById(idVO.getId());
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "获取未关联标签列表-新增提示信息时[by:zhaops]")
    @PostMapping("/getAllQuestionList")
    @SysLogger("getAllQuestionList")
    public RespDTO<QuestionShortDTO> getUnRelatedQuestionList() {
        List<QuestionShortDTO> data = introduceInfoFacade.getAllQuestionList();
        return RespDTO.onSuc(data);
    }
}