DictController.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.yihu.figure.controller.system;
  2. import com.yihu.figure.controller.BaseController;
  3. import com.yihu.figure.model.dict.SystemDict;
  4. import com.yihu.figure.service.dict.SystemDictService;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import io.swagger.annotations.ApiParam;
  8. import org.json.JSONArray;
  9. import org.json.JSONObject;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.http.MediaType;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.util.List;
  17. /**
  18. * Created by chenweida on 2017/3/14.
  19. */
  20. @RestController
  21. @RequestMapping(value = "/dict", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  22. @Api(description = "系统字典")
  23. public class DictController extends BaseController {
  24. @Autowired
  25. private SystemDictService systemDictService;
  26. /**
  27. * 根据字典code获取字典内容
  28. *
  29. * @return
  30. */
  31. @ApiOperation(value = "根据字典code获取字典内容")
  32. @RequestMapping(value = "getDictByDictName", method = RequestMethod.GET)
  33. public String getDictByDictName(
  34. @ApiParam(name = "name", value = "字典名称", required = true) @RequestParam(value = "name", required = true) String name) {
  35. try {
  36. List<SystemDict> systemDicts = systemDictService.getDictByDictName(name);
  37. JSONArray ja=new JSONArray();
  38. systemDicts.stream().forEach( dict->{
  39. JSONObject jo=new JSONObject();
  40. jo.put("code",dict.getCode());
  41. jo.put("value",dict.getValue());
  42. ja.put(jo);
  43. });
  44. return write(10000,"成功","dict",ja);
  45. } catch (Exception e) {
  46. e.printStackTrace();
  47. return error(-1, e.getMessage());
  48. }
  49. }
  50. }