package com.diagbot.web;


import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.IntroduceDetail;
import com.diagbot.facade.IntroduceDetailFacade;
import com.diagbot.vo.IdVO;
import com.diagbot.vo.IntroduceDetailSingleVO;
import com.diagbot.vo.IntroduceIdVO;
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;

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

    @ApiOperation(value = "获取提示信息明细信息[by:zhaops]",
            notes = "introduceId: 提示信息id,必填")
    @PostMapping("/getByIntroduceId")
    @SysLogger("getByIntroduceId")
    public RespDTO<List<IntroduceDetail>> getByIntroduceId(@RequestBody IntroduceIdVO introduceIdVO) {
        List<IntroduceDetail> data = introduceDetailFacade.getByIntroduceId(introduceIdVO.getIntroduceId());
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "获取单条提示信息明细[by:zhaops]",
            notes = "id: 提示信息明细id,必填")
    @PostMapping("/getById")
    @SysLogger("getById")
    public RespDTO<IntroduceDetail> getById(@RequestBody IdVO idVO) {
        IntroduceDetail data = introduceDetailFacade.getRecordById(idVO.getId());
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "保存单条明细信息[by:zhaops]",
            notes = "introdueId: 提示信息id,必填<br>" +
                    "id: 提示信息明细id<br>" +
                    "title：提示信息标题<br>" +
                    "content：提示信息<br>" +
                    "text：提示信息-纯文本<br>" +
                    "orderNo：排序号<br>" +
                    "position：显示位置<br>")
    @PostMapping("/saveRecord")
    @SysLogger("saveRecord")
    public RespDTO<Boolean> saveRecord(@RequestBody IntroduceDetailSingleVO introduceDetailSingleVO) {
        Boolean data = introduceDetailFacade.saveRecord(introduceDetailSingleVO);
        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 = introduceDetailFacade.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> idVOList) {
        Boolean data = introduceDetailFacade.deleteRecords(idVOList);
        return RespDTO.onSuc(data);
    }
}