package com.diagbot.web;


import java.util.ArrayList;
import java.util.List;

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.RestController;

import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.VersionDetailDTO;
import com.diagbot.facade.VersionDetailFacade;
import com.diagbot.vo.VersionDetailIdVO;
import com.diagbot.vo.VersionDetailVO;
import com.diagbot.vo.VersionInfoAndDetailIdVO;
import com.diagbot.vo.VersionInfoIdVO;

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

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

    @Autowired
    VersionDetailFacade versionDetailFacade;

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

        boolean res = versionDetailFacade.updateVersionDetail(versionDetailVO);

        return RespDTO.onSuc(res);
    }

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

        boolean res = versionDetailFacade.cancelVersionDetail(versionDetailIdVO);

        return RespDTO.onSuc(res);
    }

    @ApiOperation(value = "增加版本详情信息[by:wangfeng]", notes = "增加版本详情信息")
    @PostMapping("/addVersionDetails")
    @SysLogger("addVersionDetails")
    @Transactional
    public RespDTO<Boolean> addVersionDetails(@Valid @RequestBody VersionInfoAndDetailIdVO versionInfoAndDetailIdVO) {

        boolean res = versionDetailFacade.addVersionDetail(versionInfoAndDetailIdVO);

        return RespDTO.onSuc(res);
    }
    @ApiOperation(value = "根据版本id获取版本详情信息[by:wangfeng]", notes = "根据版本id获取版本详情信息")
    @PostMapping("/getDetailById")
    @SysLogger("getDetailById")
    @Transactional
    public RespDTO<List<VersionDetailDTO>> getDetailById(@Valid @RequestBody VersionInfoIdVO versionInfoIdVO)  {
    	List<Long> ids = new ArrayList<>();
    	ids.add(versionInfoIdVO.getId());
    	List<VersionDetailDTO> data = versionDetailFacade.getByIds(ids);

        return RespDTO.onSuc(data);
    }
}
