package com.fuint.module.backendApi.controller;

import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.VersionDto;
import com.fuint.common.dto.VersionDto;
import com.fuint.common.util.TokenUtil;
import com.fuint.common.vo.VersionVo;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.PageResult;
import com.fuint.framework.web.ResponseObject;
import com.fuint.common.Constants;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.VersionService;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtVersion;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 版本控制表管理类controller
 *
 * Created by pzg
 * CopyRight https://www.fuint.cn
 */
@Api(tags="管理端-版本控制表相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/version")
public class BackendVersionController extends BaseController {

    /**
     * 版本控制表服务接口
     */
    private VersionService versionService;

    /**
     * 版本控制表列表查询
     *
     * @param  request HttpServletRequest对象
     * @return 版本控制表列表
     */
    @ApiOperation(value = "版本控制表列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('version:list')")
    public ResponseObject list(HttpServletRequest request, VersionDto versionDto) throws BusinessCheckException {

        PageResult<VersionVo> result = versionService.queryVersionPageList(versionDto);

        return getSuccessResult(result);
    }
    /**
     * 更新版本控制表状态
     *
     * @return
     */
    @ApiOperation(value = "更新版本控制表状态")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('version:edit')")
    public ResponseObject updateStatus(HttpServletRequest request, @RequestBody VersionDto versionDto) throws BusinessCheckException {

        versionService.updateVersion(versionDto);

        return getSuccessResult(true);
    }

    /**
     * 保存版本控制表
     *
     * @param request HttpServletRequest对象
     * @return
     */
    @ApiOperation(value = "保存版本控制表")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('version:add')")
    public ResponseObject saveHandler(HttpServletRequest request, @RequestBody VersionDto versionDto) throws BusinessCheckException {

        versionService.addVersion(versionDto);

        return getSuccessResult(true);
    }

    /**
     * 获取版本控制表详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取版本控制表详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('version:list')")
    public ResponseObject info(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {

        VersionVo result = versionService.queryVersionById(id);

        return getSuccessResult(result);
    }
    /**
     *"删除版本控制表
     *
     * @param request HttpServletRequest对象
     * @return
     */
    @ApiOperation(value = "删除版本控制表")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('version:update')")
    public ResponseObject deleteVersionById(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {

        versionService.deleteVersionById(id);

        return getSuccessResult(true);
    }
}
