微信小程序消息通知

This commit is contained in:
liuchengqian 2022-08-31 08:55:48 +08:00
parent 1d7b2d0e8e
commit 9e68345a31
5 changed files with 207 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.xkrs.dao;
import com.xkrs.model.entity.GlobalConfigurationEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public interface GlobalConfigurationDao extends JpaRepository<GlobalConfigurationEntity, Long>, JpaSpecificationExecutor<GlobalConfigurationEntity> {
Optional<GlobalConfigurationEntity> findByKey(String key);
}

View File

@ -0,0 +1,80 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* 全局配置表
*/
@Entity
@Table(name = "global_configuration")
public class GlobalConfigurationEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_configuration_seq_gen")
@SequenceGenerator(name = "global_configuration_seq_gen", sequenceName = "global_configuration_id_seq", allocationSize = 1)
private Long id;
/**
* 全局配置项的键
*/
private String key;
/**
* 全局配置项的值
*/
private String value;
/**
* 备注信息
*/
private String remark;
public GlobalConfigurationEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "GlobalConfigurationEntity{" +
"id=" + id +
", key='" + key + '\'' +
", value='" + value + '\'' +
", remark='" + remark + '\'' +
'}';
}
}

View File

@ -0,0 +1,27 @@
package com.xkrs.service;
import com.xkrs.model.entity.GlobalConfigurationEntity;
public interface GlobalConfigurationService {
/**
* 新增全局配置
*/
String insertGlobalConfiguration(GlobalConfigurationEntity globalConfiguration);
/**
* 删除全局配置
*/
String deleteGlobalConfiguration(GlobalConfigurationEntity globalConfiguration);
/**
* 修改全局配置
*/
String updateGlobalConfiguration(GlobalConfigurationEntity globalConfiguration);
/**
* 查询全局配置
*/
String queryGlobalConfiguration(GlobalConfigurationEntity globalConfiguration);
}

View File

@ -0,0 +1,69 @@
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<GlobalConfigurationEntity> 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<GlobalConfigurationEntity> 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;
}
}

View File

@ -0,0 +1,16 @@
package com.xkrs.utils;
public class LocalNullUtils {
private LocalNullUtils() {
}
public static String formatNullValue(String value) {
return formatNullValue(value, "");
}
public static String formatNullValue(String value, String defaultValue) {
return null == value ? defaultValue : value;
}
}