admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVipConfigServiceImpl.java
@@ -1,101 +1,109 @@
package com.yeshi.fanli.service.impl.user.vip;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.user.vip.UserVipConfigMapper;
import com.yeshi.fanli.entity.bus.user.vip.UserVipConfig;
import com.yeshi.fanli.exception.user.vip.UserVipConfigException;
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class UserVipConfigServiceImpl implements UserVipConfigService {
   @Resource
   private UserVipConfigMapper userVipConfigMapper;
   @Override
   public UserVipConfig getByKey(String key) {
      return userVipConfigMapper.getByKey(key, new Date());
   }
   @Override
   @Cacheable(value = "vipconfigCache", key = "'getValueByKey-' + #key")
   public String getValueByKey(String key) {
      UserVipConfig config = userVipConfigMapper.getByKey(key, new Date());
      if (config != null) {
         return config.getValue();
      }
      return null;
   }
   @Override
   public UserVipConfig getByKey(String key, Date date) {
      if (date == null)
         return getByKey(key);
      return userVipConfigMapper.getByKey(key, date);
   }
   @Override
   public String getValueByKey(String key, Date date) {
      if (date == null)
         return getValueByKey(key);
      UserVipConfig config = userVipConfigMapper.getByKey(key, date);
      if (config != null) {
         return config.getValue();
      }
      return null;
   }
   @Override
   public List<UserVipConfig> query(int page, int pageSize, String key) {
      return userVipConfigMapper.query((page - 1) * pageSize, pageSize, key);
   }
   @Override
   public long count(String key) {
      return userVipConfigMapper.count(key);
   }
   @Override
   public void save(UserVipConfig record) throws UserVipConfigException {
      String name = record.getName();
      if (StringUtil.isNullOrEmpty(name))
         throw new UserVipConfigException(1, "名称不能为空");
      if (StringUtil.isNullOrEmpty(record.getValue()))
         throw new UserVipConfigException(1, "值不能为空");
      if (StringUtil.isNullOrEmpty(record.getKey()))
         throw new UserVipConfigException(1, "标识不能为空");
      record.setUpdateTime(new Date());
      if (record.getId() == null) {
         record.setCreateTime(new Date());
         userVipConfigMapper.insert(record);
      } else {
         UserVipConfig resultObj = userVipConfigMapper.selectByPrimaryKey(record.getId());
         if (resultObj == null)
            throw new UserVipConfigException(1, "修改内容已不存在");
         record.setCreateTime(resultObj.getCreateTime());
         userVipConfigMapper.updateByPrimaryKey(record);
      }
   }
   @Override
   public void delete(List<Long> idsList) {
      if (idsList != null)
         for (Long id : idsList)
            userVipConfigMapper.deleteByPrimaryKey(id);
   }
}
package com.yeshi.fanli.service.impl.user.vip;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.user.vip.UserVipConfigMapper;
import com.yeshi.fanli.entity.bus.user.vip.UserVipConfig;
import com.yeshi.fanli.exception.user.vip.UserVipConfigException;
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
import com.yeshi.fanli.util.StringUtil;
@Service
public class UserVipConfigServiceImpl implements UserVipConfigService {
   @Resource
   private UserVipConfigMapper userVipConfigMapper;
   @Override
   public UserVipConfig getByKey(String key) {
      return userVipConfigMapper.getByKey(key, new Date());
   }
   @Override
   @Cacheable(value = "vipconfigCache", key = "'getValueByKey-' + #key")
   public String getValueByKey(String key) {
      UserVipConfig config = userVipConfigMapper.getByKey(key, new Date());
      if (config != null) {
         return config.getValue();
      }
      return null;
   }
   @Override
   public UserVipConfig getByKey(String key, Date date) {
      if (date == null)
         return getByKey(key);
      return userVipConfigMapper.getByKey(key, date);
   }
   @Override
   public String getValueByKey(String key, Date date) {
      if (date == null)
         return getValueByKey(key);
      UserVipConfig config = userVipConfigMapper.getByKey(key, date);
      if (config != null) {
         return config.getValue();
      }
      return null;
   }
   @Override
   public List<UserVipConfig> query(int page, int pageSize, String key) {
      return userVipConfigMapper.query((page - 1) * pageSize, pageSize, key);
   }
   @Override
   public long count(String key) {
      return userVipConfigMapper.count(key);
   }
   @Override
   public void save(UserVipConfig record) throws UserVipConfigException {
      String name = record.getName();
      if (StringUtil.isNullOrEmpty(name))
         throw new UserVipConfigException(1, "名称不能为空");
      if (StringUtil.isNullOrEmpty(record.getValue()))
         throw new UserVipConfigException(1, "值不能为空");
      if (StringUtil.isNullOrEmpty(record.getKey()))
         throw new UserVipConfigException(1, "标识不能为空");
      String remark = record.getRemark();
      if ("null".equalsIgnoreCase(remark)) {
         record.setRemark("");
      }
      record.setUpdateTime(new Date());
      if (record.getId() == null) {
         record.setStartTime(new Date());
         record.setCreateTime(new Date());
         userVipConfigMapper.insert(record);
      } else {
         UserVipConfig resultObj = userVipConfigMapper.selectByPrimaryKey(record.getId());
         if (resultObj == null)
            throw new UserVipConfigException(1, "修改内容已不存在");
         record.setCreateTime(resultObj.getCreateTime());
         userVipConfigMapper.updateByPrimaryKey(record);
      }
   }
   @Override
   public void delete(List<Long> idsList) {
      if (idsList != null)
         for (Long id : idsList)
            userVipConfigMapper.deleteByPrimaryKey(id);
   }
}