SystemDictService.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.yihu.wlyy.service.system;
  2. import com.yihu.wlyy.entity.dict.SystemDict;
  3. import com.yihu.wlyy.repository.dict.SystemDictDao;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.data.redis.core.StringRedisTemplate;
  7. import org.springframework.stereotype.Service;
  8. import java.util.List;
  9. /**
  10. * Created by Administrator on 2016/8/13.
  11. */
  12. @Service
  13. public class SystemDictService {
  14. @Autowired
  15. private SystemDictDao systemDictDao;
  16. @Autowired
  17. private StringRedisTemplate redisTemplate;
  18. public List<SystemDict> getDictByDictName(String name) {
  19. return systemDictDao.findByDictName(name);
  20. }
  21. private String dictName = "SYSTEM_PARAMS";
  22. public String getDictValueNoRedis(String dictName, String code) {
  23. String re = systemDictDao.findByDictNameAndCode(dictName, code);
  24. return re;
  25. }
  26. /**
  27. * 字典转译
  28. *
  29. * @param dictName
  30. * @param code
  31. * @return
  32. */
  33. public String getDictValue(String dictName, String code) {
  34. String re = "";
  35. try {
  36. if (!StringUtils.isEmpty(code)) {
  37. //判断该字典redis是否存在
  38. String exit = redisTemplate.opsForValue().get("systemDict:" + dictName);
  39. if (!StringUtils.isEmpty(exit)) {
  40. re = redisTemplate.opsForValue().get("systemDict:" + dictName + ":" + code);
  41. } else {
  42. List<SystemDict> list = systemDictDao.findByDictName(dictName);
  43. if (list != null && list.size() > 0) {
  44. redisTemplate.opsForValue().set("systemDict:" + dictName, "1");
  45. for (SystemDict item : list) {
  46. redisTemplate.opsForValue().set("systemDict:" + dictName + ":" + item.getCode(), item.getValue());
  47. if (code.equals(item.getCode())) {
  48. re = item.getValue();
  49. }
  50. }
  51. }
  52. }
  53. }
  54. } catch (Exception ex) {
  55. ex.printStackTrace();
  56. re = systemDictDao.findByDictNameAndCode(dictName, code);
  57. }
  58. return re;
  59. }
  60. /************************************** 其他参数 ****************************************/
  61. /**
  62. * http_log是否记录成功消息
  63. *
  64. * @return
  65. */
  66. public Boolean getSaveSuccessLog() {
  67. try {
  68. String re = systemDictDao.findByDictNameAndCode(dictName, "SAVE_SUCCESS_LOG");
  69. if ("1".equals(re)) {
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. } catch (Exception ex) {
  75. ex.printStackTrace();
  76. return false;
  77. }
  78. }
  79. }