ConfigServiceImpl.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.kym.service.impl;
  2. import cn.hutool.json.JSONUtil;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.github.pagehelper.PageHelper;
  5. import com.github.yulichang.base.MPJBaseServiceImpl;
  6. import com.kym.common.utils.CommUtil;
  7. import com.kym.common.utils.ConfigUtil;
  8. import com.kym.entity.Config;
  9. import com.kym.entity.common.PageBean;
  10. import com.kym.entity.queryParams.ConfigQueryParam;
  11. import com.kym.mapper.ConfigMapper;
  12. import com.kym.service.ConfigService;
  13. import com.kym.service.cache.PubSubService;
  14. import jakarta.annotation.PostConstruct;
  15. import jakarta.annotation.Resource;
  16. import org.springframework.stereotype.Service;
  17. import java.util.Map;
  18. /**
  19. * 配置表业务类
  20. *
  21. * @author yaop
  22. * @date 2025-06-15T19:17:14.374702500
  23. */
  24. @Service("configService")
  25. public class ConfigServiceImpl extends MPJBaseServiceImpl<ConfigMapper, Config> implements ConfigService {
  26. @Resource
  27. private PubSubService pubSubService;
  28. @Override
  29. public Number add(Config config) {
  30. // config.setCompanyId(1)
  31. config.setDelete(false);
  32. var rows = save(config);
  33. if(rows){
  34. pubSubService.publish(PubSubService.CHANNEL,
  35. JSONUtil.toJsonStr(
  36. Map.of("node", ConfigUtil.getNode(), "config", config)
  37. ));
  38. }
  39. return config.getId();
  40. }
  41. @Override
  42. public void modify(Config config) {
  43. UpdateWrapper<Config> updateWrapper = new UpdateWrapper<>();
  44. updateWrapper.set("config_value", config.getConfigValue());
  45. updateWrapper.set("remark", config.getRemark());
  46. updateWrapper.set("value_type", config.getValueType());
  47. updateWrapper.eq("config_key", config.getConfigKey());
  48. update(updateWrapper);
  49. pubSubService.publish(PubSubService.CHANNEL,
  50. JSONUtil.toJsonStr(
  51. Map.of("node", ConfigUtil.getNode(), "config", config)
  52. ));
  53. log.debug( JSONUtil.toJsonStr(
  54. Map.of("node", ConfigUtil.getNode(), "config", config)
  55. ));
  56. }
  57. @Override
  58. public PageBean<Config> list(ConfigQueryParam query) {
  59. PageHelper.startPage(query.getPageNum(), query.getPageSize());
  60. var list = lambdaQuery()
  61. .like(CommUtil.isNotEmptyAndNull(query.getKey()), Config::getConfigKey, query.getKey())
  62. .like(CommUtil.isNotEmptyAndNull(query.getValue()), Config::getConfigValue, query.getValue())
  63. .like(CommUtil.isNotEmptyAndNull(query.getValueType()), Config::getValueType, query.getValueType())
  64. .like(CommUtil.isNotEmptyAndNull(query.getRemark()), Config::getRemark, query.getRemark())
  65. .like(CommUtil.isNotEmptyAndNull(query.getDelete()), Config::isDelete, query.getDelete())
  66. .list();
  67. return new PageBean<>(list);
  68. }
  69. @Override
  70. public Config detail(long id) {
  71. return getById(id);
  72. }
  73. @Override
  74. public void remove(long id) {
  75. Config cfg = getById(id);
  76. cfg.setDelete(true);
  77. UpdateWrapper<Config> updateWrapper = new UpdateWrapper<>();
  78. updateWrapper.set("is_delete", false);
  79. updateWrapper.eq("id", id);
  80. update(updateWrapper);
  81. pubSubService.publish(PubSubService.CHANNEL,
  82. JSONUtil.toJsonStr(
  83. Map.of("node", ConfigUtil.getNode(), "config", cfg)
  84. ));
  85. }
  86. @PostConstruct
  87. @Override
  88. public void initConfig() {
  89. var list = lambdaQuery().list();
  90. ConfigUtil.initConfig(list);
  91. }
  92. @Override
  93. public void status(Config config) {
  94. UpdateWrapper<Config> updateWrapper = new UpdateWrapper<>();
  95. updateWrapper.set("is_delete", config.isDelete());
  96. updateWrapper.eq("id", config.getId());
  97. update(updateWrapper);
  98. pubSubService.publish(PubSubService.CHANNEL,
  99. JSONUtil.toJsonStr(
  100. Map.of("node", ConfigUtil.getNode(), "config", config)
  101. ));
  102. }
  103. }