parent
918326632c
commit
4f8d0f7fb4
@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.opsli.api.wrapper.system.options;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.opsli.api.base.warpper.ApiWrapper;
|
||||||
|
import org.opsli.common.annotation.validation.ValidationArgs;
|
||||||
|
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
|
||||||
|
import org.opsli.common.enums.ValiArgsType;
|
||||||
|
import org.opsli.plugins.excel.annotation.ExcelInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
|
||||||
|
* @BelongsPackage: org.opsli.api.wrapper.sys.options
|
||||||
|
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2021-02-07 18:24:38
|
||||||
|
* @Description: 系统参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class OptionsModel extends ApiWrapper {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 参数编号 */
|
||||||
|
@ApiModelProperty(value = "参数编号")
|
||||||
|
@ExcelProperty(value = "参数编号", order = 1)
|
||||||
|
@ExcelInfo
|
||||||
|
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL})
|
||||||
|
@ValidationArgsLenMax(100)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private String optionCode;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 参数名称 */
|
||||||
|
@ApiModelProperty(value = "参数名称")
|
||||||
|
@ExcelProperty(value = "参数名称", order = 2)
|
||||||
|
@ExcelInfo
|
||||||
|
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL_WITH_CHINESE})
|
||||||
|
@ValidationArgsLenMax(200)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private String optionName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 参数值 */
|
||||||
|
@ApiModelProperty(value = "参数值")
|
||||||
|
@ExcelProperty(value = "参数值", order = 3)
|
||||||
|
@ExcelInfo
|
||||||
|
@ValidationArgsLenMax(500)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private String optionValue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.cache.pushsub.handler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.opsli.common.constants.CacheConstants;
|
||||||
|
import org.opsli.core.cache.local.CacheUtil;
|
||||||
|
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||||
|
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.plugins.cache.EhCachePlugin;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.core.cache.pushsub.handler
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2020-09-15 16:24
|
||||||
|
* @Description: 系统参数消息处理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class OptionHandler implements RedisPushSubHandler{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EhCachePlugin ehCachePlugin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PushSubType getType() {
|
||||||
|
return PushSubType.OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handler(JSONObject msgJson) {
|
||||||
|
// 系统参数刷新
|
||||||
|
this.optionHandler(msgJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户数据处理
|
||||||
|
* @param msgJson
|
||||||
|
*/
|
||||||
|
private void optionHandler(JSONObject msgJson){
|
||||||
|
JSONObject data = msgJson.getJSONObject(MsgArgsType.OPTION_MODEL_DATA.toString());
|
||||||
|
// 数据为空则不执行
|
||||||
|
if(data == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得参数编号
|
||||||
|
String optionCode = (String) msgJson.get(MsgArgsType.OPTION_CODE.toString());
|
||||||
|
if(StringUtils.isEmpty(optionCode)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String cacheKey = CacheUtil.handleKey(OptionsUtil.PREFIX_CODE + optionCode);
|
||||||
|
|
||||||
|
// 先删除
|
||||||
|
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.cache.pushsub.msgs;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.opsli.api.wrapper.system.menu.MenuModel;
|
||||||
|
import org.opsli.api.wrapper.system.options.OptionsModel;
|
||||||
|
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
|
||||||
|
import org.opsli.core.cache.pushsub.enums.PushSubType;
|
||||||
|
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
|
||||||
|
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.core.cache.pushsub.msgs
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2020-09-15 16:50
|
||||||
|
* @Description: 参数消息
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public final class OptionMsgFactory extends BaseSubMessage{
|
||||||
|
|
||||||
|
/** 通道 */
|
||||||
|
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
|
||||||
|
|
||||||
|
private OptionMsgFactory(){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建消息 - 参数
|
||||||
|
*/
|
||||||
|
public static BaseSubMessage createOptionMsg(OptionsModel optionsModel){
|
||||||
|
BaseSubMessage baseSubMessage = new BaseSubMessage();
|
||||||
|
// 数据
|
||||||
|
JSONObject jsonObj = new JSONObject();
|
||||||
|
jsonObj.put(MsgArgsType.OPTION_CODE.toString(), optionsModel.getOptionCode());
|
||||||
|
jsonObj.put(MsgArgsType.OPTION_MODEL_DATA.toString(), optionsModel);
|
||||||
|
|
||||||
|
// 参数
|
||||||
|
baseSubMessage.build(CHANNEL,PushSubType.OPTION.toString(),jsonObj);
|
||||||
|
return baseSubMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,180 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.opsli.api.base.result.ResultVo;
|
||||||
|
import org.opsli.api.web.system.menu.MenuApi;
|
||||||
|
import org.opsli.api.web.system.options.OptionsApi;
|
||||||
|
import org.opsli.api.wrapper.system.menu.MenuModel;
|
||||||
|
import org.opsli.api.wrapper.system.options.OptionsModel;
|
||||||
|
import org.opsli.core.cache.local.CacheUtil;
|
||||||
|
import org.opsli.core.cache.pushsub.msgs.MenuMsgFactory;
|
||||||
|
import org.opsli.core.cache.pushsub.msgs.OptionMsgFactory;
|
||||||
|
import org.opsli.core.msg.CoreMsg;
|
||||||
|
import org.opsli.plugins.redis.RedisPlugin;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.core.utils
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2020-09-19 20:03
|
||||||
|
* @Description: 参数工具类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Order(UTIL_ORDER)
|
||||||
|
@Component
|
||||||
|
@Lazy(false)
|
||||||
|
public class OptionsUtil {
|
||||||
|
|
||||||
|
/** 前缀 */
|
||||||
|
public static final String PREFIX_CODE = "options:code:";
|
||||||
|
|
||||||
|
|
||||||
|
/** Redis插件 */
|
||||||
|
private static RedisPlugin redisPlugin;
|
||||||
|
|
||||||
|
/** 参数 Api */
|
||||||
|
private static OptionsApi optionsApi;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 optionCode 获得参数
|
||||||
|
* @param optionCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static OptionsModel getOptionByCode(String optionCode){
|
||||||
|
// 缓存Key
|
||||||
|
String cacheKey = PREFIX_CODE + optionCode;
|
||||||
|
|
||||||
|
// 先从缓存里拿
|
||||||
|
OptionsModel model = CacheUtil.getTimed(OptionsModel.class, cacheKey);
|
||||||
|
if (model != null){
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拿不到 --------
|
||||||
|
// 防止缓存穿透判断
|
||||||
|
boolean hasNilFlag = CacheUtil.hasNilFlag(cacheKey);
|
||||||
|
if(hasNilFlag){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 分布式加锁
|
||||||
|
if(!DistributedLockUtil.lock(cacheKey)){
|
||||||
|
// 无法申领分布式锁
|
||||||
|
log.error(CoreMsg.REDIS_EXCEPTION_LOCK.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
|
||||||
|
model = CacheUtil.getTimed(OptionsModel.class, cacheKey);
|
||||||
|
if (model != null){
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询数据库
|
||||||
|
ResultVo<OptionsModel> resultVo = optionsApi.getByCode(optionCode);
|
||||||
|
if(resultVo.isSuccess()){
|
||||||
|
model = resultVo.getData();
|
||||||
|
// 存入缓存
|
||||||
|
CacheUtil.put(cacheKey, model);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}finally {
|
||||||
|
// 释放锁
|
||||||
|
DistributedLockUtil.unlock(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(model == null){
|
||||||
|
// 设置空变量 用于防止穿透判断
|
||||||
|
CacheUtil.putNilFlag(cacheKey);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ============== 刷新缓存 ==============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新参数 - 删就完了
|
||||||
|
* @param option
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean refreshOption(OptionsModel option){
|
||||||
|
if(option == null || StringUtils.isEmpty(option.getOptionCode())){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计数器
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
OptionsModel model = CacheUtil.getTimed(OptionsModel.class, PREFIX_CODE + option.getOptionCode());
|
||||||
|
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + option.getOptionCode());
|
||||||
|
|
||||||
|
// 只要不为空 则执行刷新
|
||||||
|
if (hasNilFlag){
|
||||||
|
count++;
|
||||||
|
// 清除空拦截
|
||||||
|
boolean tmp = CacheUtil.delNilFlag(PREFIX_CODE + option.getOptionCode());
|
||||||
|
if(tmp){
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(model != null){
|
||||||
|
count++;
|
||||||
|
// 先删除
|
||||||
|
boolean tmp = CacheUtil.del(PREFIX_CODE + option.getOptionCode());
|
||||||
|
if(tmp){
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送通知消息
|
||||||
|
redisPlugin.sendMessage(
|
||||||
|
OptionMsgFactory.createOptionMsg(option)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setRedisPlugin(RedisPlugin redisPlugin) {
|
||||||
|
OptionsUtil.redisPlugin = redisPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setOptionsApi(OptionsApi optionsApi) {
|
||||||
|
OptionsUtil.optionsApi = optionsApi;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.opsli.modulars.system.options.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.opsli.core.base.entity.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.modulars.sys.options.entity
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2021-02-07 18:24:38
|
||||||
|
* @Description: 系统参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class SysOptions extends BaseEntity {
|
||||||
|
|
||||||
|
/** 参数编号 */
|
||||||
|
private String optionCode;
|
||||||
|
|
||||||
|
/** 参数名称 */
|
||||||
|
private String optionName;
|
||||||
|
|
||||||
|
/** 参数值 */
|
||||||
|
private String optionValue;
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.opsli.modulars.system.options.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import org.opsli.modulars.system.options.entity.SysOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
|
||||||
|
* @BelongsPackage: org.opsli.modulars.sys.options.mapper
|
||||||
|
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2021-02-07 18:24:38
|
||||||
|
* @Description: 系统参数 Mapper
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysOptionsMapper extends BaseMapper<SysOptions> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.opsli.modulars.sys.options.mapper.SysOptionsMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.opsli.modulars.system.options.service;
|
||||||
|
|
||||||
|
|
||||||
|
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import org.opsli.modulars.system.options.entity.SysOptions;
|
||||||
|
import org.opsli.api.wrapper.system.options.OptionsModel;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
|
||||||
|
* @BelongsPackage: org.opsli.modulars.sys.options.service
|
||||||
|
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2021-02-07 18:24:38
|
||||||
|
* @Description: 系统参数 Service
|
||||||
|
*/
|
||||||
|
public interface ISysOptionsService extends CrudServiceInterface<SysOptions, OptionsModel> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,172 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.opsli.modulars.system.options.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.opsli.api.wrapper.system.options.OptionsModel;
|
||||||
|
import org.opsli.common.constants.MyBatisConstants;
|
||||||
|
import org.opsli.common.exception.ServiceException;
|
||||||
|
import org.opsli.core.base.service.impl.CrudServiceImpl;
|
||||||
|
import org.opsli.core.msg.CoreMsg;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
import org.opsli.modulars.system.SystemMsg;
|
||||||
|
import org.opsli.modulars.system.options.entity.SysOptions;
|
||||||
|
import org.opsli.modulars.system.options.mapper.SysOptionsMapper;
|
||||||
|
import org.opsli.modulars.system.options.service.ISysOptionsService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
|
||||||
|
* @BelongsPackage: org.opsli.modulars.sys.options.service.impl
|
||||||
|
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2021-02-07 18:24:38
|
||||||
|
* @Description: 系统参数 Service Impl
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SysOptionsServiceImpl extends CrudServiceImpl<SysOptionsMapper, SysOptions, OptionsModel>
|
||||||
|
implements ISysOptionsService {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private SysOptionsMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public OptionsModel insert(OptionsModel model) {
|
||||||
|
if(model == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 唯一验证
|
||||||
|
Integer count = this.uniqueVerificationByCode(model);
|
||||||
|
if(count != null && count > 0){
|
||||||
|
// 重复
|
||||||
|
throw new ServiceException(SystemMsg.EXCEPTION_OPTIONS_UNIQUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.insert(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Override
|
||||||
|
public OptionsModel update(OptionsModel model) {
|
||||||
|
if(model == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 唯一验证
|
||||||
|
Integer count = this.uniqueVerificationByCode(model);
|
||||||
|
if(count != null && count > 0){
|
||||||
|
// 重复
|
||||||
|
throw new ServiceException(SystemMsg.EXCEPTION_OPTIONS_UNIQUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
model = super.update(model);
|
||||||
|
if(model != null){
|
||||||
|
// 清除缓存
|
||||||
|
this.clearCache(Collections.singletonList(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean delete(String id) {
|
||||||
|
OptionsModel model = super.get(id);
|
||||||
|
boolean ret = super.delete(id);
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
// 清除缓存
|
||||||
|
this.clearCache(Collections.singletonList(model));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteAll(String[] ids) {
|
||||||
|
QueryWrapper<SysOptions> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids));
|
||||||
|
List<OptionsModel> modelList = super.transformTs2Ms(
|
||||||
|
super.findList(queryWrapper)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 清除缓存
|
||||||
|
this.clearCache(modelList);
|
||||||
|
|
||||||
|
return super.deleteAll(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一验证
|
||||||
|
* @param model model
|
||||||
|
* @return Integer
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Integer uniqueVerificationByCode(OptionsModel model){
|
||||||
|
if(model == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
QueryWrapper<SysOptions> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("option_code", model.getOptionCode());
|
||||||
|
|
||||||
|
// 重复校验排除自身
|
||||||
|
if(StringUtils.isNotEmpty(model.getId())){
|
||||||
|
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.count(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除缓存
|
||||||
|
* @param optionList
|
||||||
|
*/
|
||||||
|
private void clearCache(List<OptionsModel> optionList){
|
||||||
|
// 清空缓存
|
||||||
|
if(CollUtil.isNotEmpty(optionList)){
|
||||||
|
int cacheCount = 0;
|
||||||
|
for (OptionsModel model : optionList) {
|
||||||
|
cacheCount++;
|
||||||
|
boolean tmp = OptionsUtil.refreshOption(model);
|
||||||
|
if(tmp){
|
||||||
|
cacheCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 判断删除状态
|
||||||
|
if(cacheCount != 0){
|
||||||
|
// 删除缓存失败
|
||||||
|
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue