package com.xkrs.service.impl; import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.dao.GlobalConfigurationDao; import com.xkrs.model.entity.GlobalConfigurationEntity; import com.xkrs.service.GlobalConfigurationService; import com.xkrs.utils.LocalNullUtils; import org.apache.hc.core5.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Locale; import java.util.Optional; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @Service public class GlobalConfigurationServiceImpl implements GlobalConfigurationService { private final Locale locale = LocaleContextHolder.getLocale(); @Resource private GlobalConfigurationDao globalConfigurationDao; @Override public String insertGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) { final String key = LocalNullUtils.formatNullValue(globalConfiguration.getKey()); final String value = LocalNullUtils.formatNullValue(globalConfiguration.getValue()); final String remark = LocalNullUtils.formatNullValue(globalConfiguration.getRemark()); if (TextUtils.isEmpty(key)) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "key不可为空", locale); } Optional duplicatedOptional = globalConfigurationDao.findByKey(key); if (duplicatedOptional.isPresent()) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "key已存在", locale); } GlobalConfigurationEntity globalConfigurationEntity = new GlobalConfigurationEntity(); globalConfigurationEntity.setKey(key); globalConfigurationEntity.setValue(value); globalConfigurationEntity.setRemark(remark); globalConfigurationDao.save(globalConfigurationEntity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "新增成功", locale); } @Override public String deleteGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) { Long id = globalConfiguration.getId(); if (null == id) { return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "id不可为空", locale); } Optional targetOptional = globalConfigurationDao.findById(id); if (targetOptional.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "id不存在", locale); } globalConfigurationDao.deleteById(id); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功", locale); } @Override public String updateGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) { return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "新增成功", locale); } @Override public String queryGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) { return null; } }