|
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
+import com.qmth.boot.core.security.service.EncryptService;
|
|
|
+import com.qmth.boot.core.security.service.impl.DefaultEncryptService;
|
|
|
import com.qmth.ops.biz.dao.PropertyItemDao;
|
|
|
import com.qmth.ops.biz.domain.*;
|
|
|
import com.qmth.ops.biz.utils.PropertyFileUtil;
|
|
@@ -31,6 +33,8 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
|
|
|
|
|
|
private static final String APP_CODE_KEY = "com.qmth.solar.app-code";
|
|
|
|
|
|
+ private static final String MODULE_CODE_KEY = "com.qmth.solar.module-code";
|
|
|
+
|
|
|
@Resource
|
|
|
private EnvService envService;
|
|
|
|
|
@@ -217,10 +221,12 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
|
|
|
.eq(PropertyItem::getKey, key));
|
|
|
}
|
|
|
|
|
|
- public List<PropertyItem> mergePropertyList(String appCode, Version version, Long moduleId, Long envId) {
|
|
|
- List<PropertyItem> list = listBaseline(version.getId(), moduleId);
|
|
|
+ public List<PropertyItem> mergePropertyList(String appCode, Version version, Module module, Long envId,
|
|
|
+ boolean encrypt) {
|
|
|
+ EncryptService encryptService = new DefaultEncryptService(() -> appCode);
|
|
|
+ List<PropertyItem> list = listBaseline(version.getId(), module.getId());
|
|
|
//获取环境定义配置项
|
|
|
- Map<String, PropertyItem> itemMap = listPropertyItem(version.getId(), moduleId, envId).stream()
|
|
|
+ Map<String, PropertyItem> itemMap = listPropertyItem(version.getId(), module.getId(), envId).stream()
|
|
|
.collect(Collectors.toMap(PropertyItem::getKey, Function.identity()));
|
|
|
//遍历基线
|
|
|
for (PropertyItem item : list) {
|
|
@@ -239,13 +245,17 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
|
|
|
if (!itemMap.isEmpty()) {
|
|
|
list.addAll(itemMap.values());
|
|
|
}
|
|
|
- //强制增加appCode与appVersion配置项,自动根据当前app和version填充
|
|
|
+ //强制增加appCode,moduleCode,appVersion配置项,自动根据当前app,module,version填充
|
|
|
boolean hasCode = false;
|
|
|
+ boolean hasModule = false;
|
|
|
boolean hasVersion = false;
|
|
|
for (PropertyItem item : list) {
|
|
|
if (item.getKey().equals(APP_CODE_KEY)) {
|
|
|
item.setValue(appCode);
|
|
|
hasCode = true;
|
|
|
+ } else if (item.getKey().equals(MODULE_CODE_KEY)) {
|
|
|
+ item.setValue(module.getCode());
|
|
|
+ hasModule = true;
|
|
|
} else if (item.getKey().equals(APP_VERSION_KEY)) {
|
|
|
item.setValue(version.getName());
|
|
|
hasVersion = true;
|
|
@@ -257,12 +267,26 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
|
|
|
item.setValue(appCode);
|
|
|
list.add(item);
|
|
|
}
|
|
|
+ if (!hasModule) {
|
|
|
+ PropertyItem item = new PropertyItem();
|
|
|
+ item.setKey(MODULE_CODE_KEY);
|
|
|
+ item.setValue(module.getCode());
|
|
|
+ list.add(item);
|
|
|
+ }
|
|
|
if (!hasVersion) {
|
|
|
PropertyItem item = new PropertyItem();
|
|
|
item.setKey(APP_VERSION_KEY);
|
|
|
item.setValue(version.getName());
|
|
|
list.add(item);
|
|
|
}
|
|
|
+ //对敏感配置值进行加密处理
|
|
|
+ if (encrypt) {
|
|
|
+ for (PropertyItem item : list) {
|
|
|
+ if (item.containSecret()) {
|
|
|
+ item.setValue("ENC(" + encryptService.encrypt(item.getValue()) + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
list.sort(Comparator.comparing(PropertyItem::getKey));
|
|
|
return list;
|
|
|
}
|