package com.yihu.hos.standard.controller;

import com.yihu.hos.standard.model.standard.resultModel.StandardParamResultModel;
import com.yihu.hos.standard.service.standard.StandardService;
import com.yihu.hos.web.framework.constant.SqlConstants;
import com.yihu.hos.web.framework.model.DetailModelResult;
import com.yihu.hos.web.framework.model.DictionaryResult;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("StandardController")
@RequestMapping("/standardCenter")
//@Api(protocols = "https", value = "StandardController", description = "标准管理", tags = {"标准"})
public class StandardController extends BaseController {
    @Resource(name = StandardService.BEAN_ID)
    private StandardService standardService;

    /**
     * 查询集成标准首页信息（get）
     * @param condition
     * @return
     * @throws Exception
     */
    @RequestMapping("/searchStandard")
    @ApiOperation(value = "获取标准树列表", response = DetailModelResult.class, responseContainer = "List", notes = "获取标准列表")
    public DetailModelResult searchStandard(
            @ApiParam(name = "condition", value = "查询条件name：厂商、标准、标准版本名称，标准类别type：0为集成标准，1为应用标准")
            @RequestParam(value = "condition", required = false) String condition) {
        return standardService.getDetailModelResult(condition);
    }

    /**
     * 获取集成标准系统参数
     * @return
     * @throws Exception
     */
    @RequestMapping("/getSysParamList")
    @ApiOperation(value = "获取集成标准系统参数", response = StandardParamResultModel.class, notes = "获取集成标准系统参数")
    public StandardParamResultModel getSysParamList() {
        StandardParamResultModel standardParamResultModel = standardService.getStandardParam(SqlConstants.STANDARD);
        return standardParamResultModel;
    }


    /**
     * 根据标准ID获取集成标准信息（get）
     * @param standardId
     * @return
     * @throws Exception
     */
    @RequestMapping("/getForStandardId")
    @ApiOperation(value = "获取标准", response = Result.class, produces = "application/json", notes = "获取标准")
    public Result getForStandardId(
            @ApiParam(name = "standardId", value = "标准ID")
            @RequestParam(value = "standardId") Integer standardId){
        return standardService.get(standardId);
    }

    /**
     * 修改标准信息（PUT）
     * @param standard
     * @return
     * @throws Exception
     */
    @RequestMapping("/updateStandard")
    @ApiOperation(value = "修改标准", response = Result.class, produces = "application/json", notes = "修改标准")
    public Result modify(
            @ApiParam(name = "standard", value = "标准基本信息")
            @RequestParam(value = "standard") String standard) {
        return standardService.update(standard);
    }

    /**
     * 新增标准信息（POST）
     * @param standard
     * @return
     * @throws Exception
     */
    @RequestMapping("/addStandard")
    @ApiOperation(value = "保存标准", response = Result.class, produces = "application/json", notes = "保存标准")
    public Result add(
            @ApiParam(name = "standard", value = "标准基本信息")
            @RequestParam(value = "standard") String standard) {
        return standardService.add(standard);
    }

    /**
     * 删除标准信息（DELETE）
     * @param  standardId
     * @return
     * @throws Exception
     */
    @RequestMapping("/deleteStandard")
    @ApiOperation(value = "删除标准", response = Result.class, produces = "application/json", notes = "删除标准")
    public Result delete(
            @ApiParam(name = "standardId", value = "标准ID")
            @RequestParam(value = "standardId") Integer standardId) {
        return standardService.delete(standardId);
    }

    /**
     * 获取平台标准名称/应用标准名称列表
     * @param condition
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getStandards")
    @ApiOperation(value = "获取标准列表", response = DictionaryResult.class, produces = "application/json", notes = "获取标准列表")
    public DictionaryResult getStandardList(
            @ApiParam(name = "condition", value = "Must be Json,其中type为区分集成与应用标准")
            @RequestParam(value = "condition", required = false) String condition,
            @ApiParam(name = "order", value = "Must be Json")
            @RequestParam(value = "order", required = false) String order,
            @ApiParam(name = "rows", value = "Limit the size of result set. Must be an integer")
            @RequestParam(value = "rows", required = false) Integer rows,
            @ApiParam(name = "page", value = "Start position of result set. Must be an integer")
            @RequestParam(value = "page", required = false) Integer page) {
        DictionaryResult dictionaryResult = standardService.getDictionaryResult(condition, order, rows, page);
        return dictionaryResult;
    }
}
