use of com.orion.ops.entity.domain.MachineEnvDO in project orion-ops by lijiahangmax.
the class MachineEnvServiceImpl method updateEnv.
@Override
public Integer updateEnv(MachineEnvRequest request) {
// 查询
Long id = request.getId();
MachineEnvDO before = machineEnvDAO.selectById(id);
Valid.notNull(before, MessageConst.ENV_ABSENT);
return SpringHolder.getBean(MachineEnvService.class).updateEnv(before, request);
}
use of com.orion.ops.entity.domain.MachineEnvDO in project orion-ops by lijiahangmax.
the class MachineEnvServiceImpl method deleteEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public Integer deleteEnv(List<Long> idList) {
int effect = 0;
for (Long id : idList) {
// 获取元数据
MachineEnvDO env = machineEnvDAO.selectById(id);
Valid.notNull(env, MessageConst.ENV_ABSENT);
String key = env.getAttrKey();
Valid.isTrue(MachineEnvAttr.of(key) == null, "{} " + MessageConst.FORBID_DELETE, key);
// 删除
effect += machineEnvDAO.deleteById(id);
// 插入历史值
historyValueService.addHistory(id, HistoryValueType.MACHINE_ENV, HistoryOperator.DELETE, env.getAttrValue(), null);
}
// 设置日志参数
EventParamsHolder.addParam(EventKeys.ID_LIST, idList);
EventParamsHolder.addParam(EventKeys.COUNT, effect);
return effect;
}
use of com.orion.ops.entity.domain.MachineEnvDO in project orion-ops by lijiahangmax.
the class MachineEnvServiceImpl method getEnvDetail.
@Override
public MachineEnvVO getEnvDetail(Long id) {
MachineEnvDO env = machineEnvDAO.selectById(id);
Valid.notNull(env, MessageConst.UNKNOWN_DATA);
return Converts.to(env, MachineEnvVO.class);
}
use of com.orion.ops.entity.domain.MachineEnvDO in project orion-ops by lijiahangmax.
the class MachineEnvServiceImpl method updateEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateEnv(MachineEnvDO before, MachineEnvRequest request) {
// 检查是否修改了值
Long id = before.getId();
String beforeValue = before.getAttrValue();
String afterValue = request.getValue();
if (Const.IS_DELETED.equals(before.getDeleted())) {
// 设置新增历史值
historyValueService.addHistory(id, HistoryValueType.MACHINE_ENV, HistoryOperator.ADD, null, afterValue);
// 恢复
machineEnvDAO.setDeleted(id, Const.NOT_DELETED);
} else if (afterValue != null && !afterValue.equals(beforeValue)) {
// 检查是否修改了值 增加历史值
historyValueService.addHistory(id, HistoryValueType.MACHINE_ENV, HistoryOperator.UPDATE, beforeValue, afterValue);
}
// 修改
MachineEnvDO update = new MachineEnvDO();
update.setId(id);
update.setAttrValue(afterValue);
update.setDescription(request.getDescription());
update.setUpdateTime(new Date());
return machineEnvDAO.updateById(update);
}
use of com.orion.ops.entity.domain.MachineEnvDO in project orion-ops by lijiahangmax.
the class MachineEnvServiceImpl method syncMachineEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public void syncMachineEnv(MachineEnvRequest request) {
Long id = request.getId();
Long machineId = request.getMachineId();
List<Long> targetMachineIdList = request.getTargetMachineIdList();
// 获取self
MachineEnvService self = SpringHolder.getBean(MachineEnvService.class);
List<MachineEnvDO> envList;
if (Const.N_N_L_1.equals(id)) {
// 全量同步
LambdaQueryWrapper<MachineEnvDO> wrapper = new LambdaQueryWrapper<MachineEnvDO>().eq(MachineEnvDO::getMachineId, machineId).orderByAsc(MachineEnvDO::getUpdateTime);
envList = machineEnvDAO.selectList(wrapper);
} else {
// 查询数据
MachineEnvDO env = machineEnvDAO.selectById(id);
Valid.notNull(env, MessageConst.UNKNOWN_DATA);
envList = Lists.singleton(env);
}
// 同步
for (Long targetMachineId : targetMachineIdList) {
for (MachineEnvDO syncEnv : envList) {
MachineEnvRequest addRequest = new MachineEnvRequest();
addRequest.setMachineId(targetMachineId);
addRequest.setKey(syncEnv.getAttrKey());
addRequest.setValue(syncEnv.getAttrValue());
addRequest.setDescription(syncEnv.getDescription());
self.addEnv(addRequest);
}
}
// 设置日志参数
EventParamsHolder.addParams(request);
EventParamsHolder.addParam(EventKeys.ENV_COUNT, envList.size());
EventParamsHolder.addParam(EventKeys.MACHINE_COUNT, targetMachineIdList.size());
}
Aggregations