package com.kym.service.impl; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.github.pagehelper.PageHelper; import com.github.yulichang.base.MPJBaseServiceImpl; import com.kym.common.utils.CommUtil; import com.kym.common.utils.ConfigUtil; import com.kym.entity.Config; import com.kym.entity.common.PageBean; import com.kym.entity.queryParams.ConfigQueryParam; import com.kym.mapper.ConfigMapper; import com.kym.service.ConfigService; import com.kym.service.cache.PubSubService; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import java.util.Map; /** * 配置表业务类 * * @author yaop * @date 2025-06-15T19:17:14.374702500 */ @Service("configService") public class ConfigServiceImpl extends MPJBaseServiceImpl implements ConfigService { @Resource private PubSubService pubSubService; @Override public Number add(Config config) { // config.setCompanyId(1) config.setDelete(false); var rows = save(config); if(rows){ pubSubService.publish(PubSubService.CHANNEL, JSONUtil.toJsonStr( Map.of("node", ConfigUtil.getNode(), "config", config) )); } return config.getId(); } @Override public void modify(Config config) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.set("config_value", config.getConfigValue()); updateWrapper.set("remark", config.getRemark()); updateWrapper.set("value_type", config.getValueType()); updateWrapper.eq("config_key", config.getConfigKey()); update(updateWrapper); pubSubService.publish(PubSubService.CHANNEL, JSONUtil.toJsonStr( Map.of("node", ConfigUtil.getNode(), "config", config) )); log.debug( JSONUtil.toJsonStr( Map.of("node", ConfigUtil.getNode(), "config", config) )); } @Override public PageBean list(ConfigQueryParam query) { PageHelper.startPage(query.getPageNum(), query.getPageSize()); var list = lambdaQuery() .like(CommUtil.isNotEmptyAndNull(query.getKey()), Config::getConfigKey, query.getKey()) .like(CommUtil.isNotEmptyAndNull(query.getValue()), Config::getConfigValue, query.getValue()) .like(CommUtil.isNotEmptyAndNull(query.getValueType()), Config::getValueType, query.getValueType()) .like(CommUtil.isNotEmptyAndNull(query.getRemark()), Config::getRemark, query.getRemark()) .like(CommUtil.isNotEmptyAndNull(query.getDelete()), Config::isDelete, query.getDelete()) .list(); return new PageBean<>(list); } @Override public Config detail(long id) { return getById(id); } @Override public void remove(long id) { Config cfg = getById(id); cfg.setDelete(true); UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.set("is_delete", false); updateWrapper.eq("id", id); update(updateWrapper); pubSubService.publish(PubSubService.CHANNEL, JSONUtil.toJsonStr( Map.of("node", ConfigUtil.getNode(), "config", cfg) )); } @PostConstruct @Override public void initConfig() { var list = lambdaQuery().list(); ConfigUtil.initConfig(list); } @Override public void status(Config config) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.set("is_delete", config.isDelete()); updateWrapper.eq("id", config.getId()); update(updateWrapper); pubSubService.publish(PubSubService.CHANNEL, JSONUtil.toJsonStr( Map.of("node", ConfigUtil.getNode(), "config", config) )); } }