fire_point/src/main/java/com/xkrs/service/impl/GlobalConfigServiceImpl.java
liuchengqian 6a6302ff43 普通用户和VIP用户区别对待:
1、普通用户不能查看历史火情,VIP可以。
2、普通用户不能导航,VIP可以。
3、普通用户不能接收短信通知,VIP可以。
2022-06-17 15:43:48 +08:00

112 lines
4.7 KiB
Java

package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.GlobalConfigDao;
import com.xkrs.dao.GlobalConfigDictDao;
import com.xkrs.model.entity.GlobalConfigDictEntity;
import com.xkrs.model.entity.GlobalConfigEntity;
import com.xkrs.model.qo.GlobalConfigDictQo;
import com.xkrs.service.GlobalConfigService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.util.*;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class GlobalConfigServiceImpl implements GlobalConfigService {
private final Locale locale = LocaleContextHolder.getLocale();
@Resource
private GlobalConfigDao globalConfigDao;
@Resource
private GlobalConfigDictDao globalConfigDictDao;
@Override
public String selectGlobalConfigDict() {
List<GlobalConfigDictEntity> globalConfigDictList = globalConfigDictDao.findAll(Sort.by(Sort.Direction.ASC, "id"));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, globalConfigDictList, locale);
}
@Override
public Long selectGlobalConfigValue(Long code) {
try {
Optional<GlobalConfigEntity> existsGlobalConfigOptional = globalConfigDao.findByCode(code);
if (existsGlobalConfigOptional.isEmpty()) {
return 0L;
}
return existsGlobalConfigOptional.get().getValue();
} catch (Exception e) {
e.printStackTrace();
}
return 0L;
}
@Override
public String selectGlobalConfig(Long code) {
Specification<GlobalConfigEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
//查询条件集合
List<Predicate> predicateList = new ArrayList<>();
if (code != null) {
predicateList.add(criteriaBuilder.equal(root.get("code").as(Long.class), code));
}
Predicate[] predicateArray = new Predicate[predicateList.size()];
return criteriaBuilder.and(predicateList.toArray(predicateArray));
};
List<GlobalConfigEntity> globalConfigList = globalConfigDao.findAll(specification, Sort.by(Sort.Direction.ASC, "id"));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, globalConfigList, locale);
}
@Override
public String globalConfig(Map<Long, Long> globalConfigMap) {
if (globalConfigMap == null || globalConfigMap.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "配置失败", locale);
}
for (Map.Entry<Long, Long> entry : globalConfigMap.entrySet()) {
Long code = entry.getKey();
Long value = entry.getValue();
if (code == null || value == null) {
continue;
}
Optional<GlobalConfigEntity> existsGlobalConfigOptional = globalConfigDao.findByCode(code);
if (existsGlobalConfigOptional.isEmpty()) {
GlobalConfigEntity globalConfigEntity = new GlobalConfigEntity();
globalConfigEntity.setCode(code);
globalConfigEntity.setValue(value);
globalConfigDao.save(globalConfigEntity);
} else {
GlobalConfigEntity existsGlobalConfig = existsGlobalConfigOptional.get();
existsGlobalConfig.setCode(code);
existsGlobalConfig.setValue(value);
globalConfigDao.save(existsGlobalConfig);
}
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
@Override
public String globalConfigDict(GlobalConfigDictQo globalConfigDictQo) {
Long code = globalConfigDictQo.getCode();
String name = globalConfigDictQo.getName();
String remark = globalConfigDictQo.getRemark();
Optional<GlobalConfigDictEntity> existsGlobalConfigDictOptional = globalConfigDictDao.findByCode(code);
if (existsGlobalConfigDictOptional.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "配置失败", locale);
}
GlobalConfigDictEntity globalConfigDictEntity = new GlobalConfigDictEntity();
globalConfigDictEntity.setCode(code);
globalConfigDictEntity.setName(name);
globalConfigDictEntity.setRemark(remark);
globalConfigDictDao.save(globalConfigDictEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "配置成功", locale);
}
}