package com.yihu.hos.standard.controller;

import com.yihu.hos.standard.service.adapter.AdapterDictEntryService;
import com.yihu.hos.web.framework.model.DetailModelResult;
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;

/**
 * Created by LLH on 2016/1/6.
 */
@RestController("AdapterDictEntryController")
@RequestMapping("/adapterCenter")
//@Api(protocols = "https", value = "AdapterDictEntryController", description = "适配字典项管理", tags = {"适配字典项"})
public class AdapterDictEntryController extends BaseController {

    @Resource(name = AdapterDictEntryService.BEAN_ID)
    private AdapterDictEntryService dictentryService;
    /**
     * 查询字典项列表信息（get）
     * @param adapterVersion
     * @param condition
     * @param order
     * @param rows
     * @param page
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/searchDictEntryList")
    @ApiOperation(value = "获取字典项列表", response = DetailModelResult.class, produces = "application/json", notes = "获取字典项列表")
    public DetailModelResult getDictEntryList(
            @ApiParam(name = "adapterVersion", value = "适配版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "condition", value = "查询条件")
            @RequestParam(value = "condition", required = false) String condition,
            @ApiParam(name = "order", value = "Order param,Must be json.ascending:asc,descending:desc")
            @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) throws Exception{
        return dictentryService.getDetailResult(adapterVersion, condition, order, rows, page);
    }

    @RequestMapping(value = "/getForDictEntryId")
    @ApiOperation(value = "获取字典项", response = Result.class, produces = "application/json", notes = "获取字典项")
    public Result get(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntryId", value = "字典项ID")
            @RequestParam(value = "dictEntryId") Integer dictentryId) {
        return dictentryService.get(adapterVersion, dictentryId);
    }

    @RequestMapping(value = "/updateDictEntry")
    @ApiOperation(value = "修改字典项", response = Result.class, produces = "application/json", notes = "修改字典项")
    public Result updateDictEntry(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntry", value = "字典项")
            @RequestParam(value = "dictEntry") String dictEntry) {
        return dictentryService.modify(adapterVersion, dictEntry);
    }

    @RequestMapping(value = "/addDictEntry")
    @ApiOperation(value = "保存字典项", response = Result.class, produces = "application/json", notes = "保存字典项")
    public Result add(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntry", value = "字典项")
            @RequestParam(value = "dictEntry") String dictEntry) {
        return dictentryService.add(adapterVersion, dictEntry);
    }

    @RequestMapping("/updateDictEntrys")
    @ApiOperation(value = "保存字典项", response = DetailModelResult.class, produces = "application/json", notes = "保存数据元")
    public DetailModelResult updateDictEntrys(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "list", value = "字典项列表")
            @RequestParam(value = "list") String list) {
        return dictentryService.updateDictEntrys(adapterVersion, list);
    }

    @RequestMapping("/delDictEntry")
    @ApiOperation(value = "删除字典项", response = Result.class, produces = "application/json", notes = "删除字典项,若字典项表为空管理字典清掉")
    public Result delete(
            @ApiParam(name = "adapterVersion", value = "标准版本号")
            @RequestParam(value = "adapterVersion") String adapterVersion,
            @ApiParam(name = "dictEntryId", value = "字典项ID")
            @RequestParam(value = "dictEntryId") Integer dictEntryId,
            @ApiParam(name = "stdDictId", value = "标准字典ID")
            @RequestParam(value = "stdDictId") Integer stdDictId,
            @ApiParam(name = "adapterDictId", value = "适配字典ID")
            @RequestParam(value = "adapterDictId") Integer adapterDictId) {
        return dictentryService.deleteMultiple(adapterVersion, dictEntryId, stdDictId, adapterDictId);
    }
}
