package com.diagbot.web;

import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.VersionWrapperDTO;
import com.diagbot.facade.VersionInfoFacade;
import com.diagbot.vo.VersionInfoAllVO;
import com.diagbot.vo.VersionInfoIdVO;
import com.diagbot.vo.VersionInfoVO;
import com.diagbot.vo.VersionWrapperNameVO;
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;

/**
 * @author wangfeng
 * @Description: 版本信息(关于) 前端控制器
 * @date 2018年12月4日 上午10:57:49
 */
@RestController
@RequestMapping("/versionInfo")
@Api(value = "版本信息(关于)API[by:wangfeng]", tags = { "WF——版本信息(关于)API" })
@SuppressWarnings("unchecked")
public class VersionInfoController {

    @Autowired
    VersionInfoFacade versionInfoFacade;

    @ApiOperation(value = "获取版本信息[by:wangfeng]", notes = "获取版本信息")
    @PostMapping("/getVersionInfoAlls")
    @SysLogger("getVersionInfoAlls")
    @Transactional
    public RespDTO<List<VersionWrapperDTO>> getVersionInfoAlls(@RequestBody VersionWrapperNameVO versionWrapperNameVO) {

        List<VersionWrapperDTO> data = versionInfoFacade.getVersionInfoAll(versionWrapperNameVO, versionWrapperNameVO.getName());

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "保存版本信息[by:wangfeng]", notes = "保存版本信息")
    @PostMapping("/saveVersionInfoAlls")
    @SysLogger("saveVersionInfoAlls")
    @Transactional
    public RespDTO<Boolean> saveVersionInfoAlls(@Valid @RequestBody VersionInfoVO versionInfoVO) {

        boolean res = versionInfoFacade.saveVersionInfoAll(versionInfoVO);

        return RespDTO.onSuc(res);
    }

    @ApiOperation(value = "更新版本信息[by:wangfeng]", notes = "更新版本信息")
    @PostMapping("/updateVersionInfoAlls")
    @SysLogger("updateVersionInfoAlls")
    @Transactional
    public RespDTO<Boolean> updateVersionInfoAlls(@Valid @RequestBody VersionInfoAllVO versionInfoVO) {

        boolean res = versionInfoFacade.updateVersionInfoAll(versionInfoVO);

        return RespDTO.onSuc(res);
    }

    @ApiOperation(value = "删除版本信息[by:wangfeng]", notes = "删除版本信息")
    @PostMapping("/cancelVersionInfoAlls")
    @SysLogger("cancelVersionInfoAlls")
    @Transactional
    public RespDTO<Boolean> cancelVersionInfoAlls(@Valid @RequestBody VersionInfoIdVO versionInfoVO) {

        boolean res = versionInfoFacade.cancelVersionInfoAll(versionInfoVO);

        return RespDTO.onSuc(res);
    }
}
