package com.yihu.wlyy.web.common.system;

import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2016/8/13.
 */

@Controller
@RequestMapping(value = "/common")
@Api(description = "系统字典")
public class SystemDictController extends BaseController {
    @Autowired
    private SystemDictService systemDictService;

    /**
     * 根據dictname查找DictName
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDictByDictName")
    public String getDictByDictName(String name){
        try {
            List<SystemDict> list=systemDictService.getDictByDictName(name);
            JSONArray ja=new JSONArray();
            for (SystemDict systemDict:list){
                JSONObject jo=new JSONObject();
                jo.put("code",systemDict.getCode());
                jo.put("value",systemDict.getValue());
                ja.put(jo);
            }
            return write(200,"查询成功","list",ja);
        } catch (Exception e) {
            error(e);
            return error(-1, "验证码检查失败！");
        }
    }
}
