|
|
@@ -0,0 +1,51 @@
|
|
|
+package com.usoftchina.saas.ui.service;
|
|
|
+
|
|
|
+import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
+import com.usoftchina.saas.ui.po.Config;
|
|
|
+import com.usoftchina.saas.ui.repository.CustomizeRepository;
|
|
|
+import com.usoftchina.saas.utils.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: guq
|
|
|
+ * @create: 2018-12-26 16:07
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class CustomizeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomizeRepository customizeRepository;
|
|
|
+
|
|
|
+ @Cacheable(value = "customizeConfig", key = "#name")
|
|
|
+ public List<Config> getConfig(String name) {
|
|
|
+ if (StringUtils.isEmpty(name)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ return customizeRepository.findByNameAndCompanyId(name, companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @CacheEvict(value = "customizeConfig", key = "#config.name")
|
|
|
+ public void save(Config config) {
|
|
|
+ if (!StringUtils.isEmpty(config)) {
|
|
|
+ customizeRepository.deleteConfigByNameAndPositionAndCompanyId(config.getName(), config.getPosition(),
|
|
|
+ BaseContextHolder.getCompanyId());
|
|
|
+ config.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ config.setCreateTime(new Date());
|
|
|
+ customizeRepository.save(config);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @CacheEvict(value = "customizeConfig", key = "#name")
|
|
|
+ public void delete(String name) {
|
|
|
+ if (!StringUtils.isEmpty(name)) {
|
|
|
+ customizeRepository.deleteConfigByNameAndCompanyId(name, BaseContextHolder.getCompanyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|