| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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<ConfigMapper, Config> 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<Config> 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<Config> 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<Config> 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<Config> 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)
- ));
- }
- }
|