parent
6e9ad77ec4
commit
da41a11e32
@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.other.crypto;
|
|
||||||
|
|
||||||
|
|
||||||
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.other.crypto
|
|
||||||
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2021-02-10 17:09:34
|
|
||||||
* @Description: 非对称加密
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
public class OtherCryptoAsymmetricModel extends ApiWrapper {
|
|
||||||
|
|
||||||
|
|
||||||
/** 加解密类别 */
|
|
||||||
@ApiModelProperty(value = "加解密类别")
|
|
||||||
@ExcelProperty(value = "加解密类别", order = 1)
|
|
||||||
@ExcelInfo
|
|
||||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_GENERAL})
|
|
||||||
@ValidationArgsLenMax(100)
|
|
||||||
private String cryptoType;
|
|
||||||
|
|
||||||
/** 公钥 */
|
|
||||||
@ApiModelProperty(value = "公钥")
|
|
||||||
@ExcelProperty(value = "公钥", order = 2)
|
|
||||||
@ExcelInfo
|
|
||||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
|
|
||||||
@ValidationArgsLenMax(2000)
|
|
||||||
private String publicKey;
|
|
||||||
|
|
||||||
/** 私钥 */
|
|
||||||
@ApiModelProperty(value = "私钥")
|
|
||||||
@ExcelProperty(value = "私钥", order = 3)
|
|
||||||
@ExcelInfo
|
|
||||||
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
|
|
||||||
@ValidationArgsLenMax(2000)
|
|
||||||
private String privateKey;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.other.crypto.entity;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.opsli.core.base.entity.BaseEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.modulars.system.other.crypto.entity
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2021-02-10 17:09:34
|
|
||||||
* @Description: 非对称加密
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
public class OtherCryptoAsymmetric extends BaseEntity {
|
|
||||||
|
|
||||||
/** 加解密类别 */
|
|
||||||
private String cryptoType;
|
|
||||||
|
|
||||||
/** 公钥 */
|
|
||||||
private String publicKey;
|
|
||||||
|
|
||||||
/** 私钥 */
|
|
||||||
private String privateKey;
|
|
||||||
|
|
||||||
|
|
||||||
// ========================================
|
|
||||||
|
|
||||||
|
|
||||||
/** 创建人 */
|
|
||||||
@JsonIgnore
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String createBy;
|
|
||||||
|
|
||||||
/** 创建时间 */
|
|
||||||
@JsonIgnore
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@TableField(exist = false)
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
/** 更新人 */
|
|
||||||
@JsonIgnore
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String updateBy;
|
|
||||||
|
|
||||||
/** 更新时间 */
|
|
||||||
@JsonIgnore
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@TableField(exist = false)
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
/** 乐观锁 版本 */
|
|
||||||
@JsonIgnore
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@TableField(exist = false)
|
|
||||||
private Integer version;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.other.crypto.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.other.crypto.entity.OtherCryptoAsymmetric;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.modulars.system.other.crypto.mapper
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2021-02-10 17:09:34
|
|
||||||
* @Description: 非对称加密 Mapper
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface OtherCryptoAsymmetricMapper extends BaseMapper<OtherCryptoAsymmetric> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
<?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.system.other.crypto.mapper.OtherCryptoAsymmetricMapper">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
|
@ -1,45 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.other.crypto.service;
|
|
||||||
|
|
||||||
|
|
||||||
import org.opsli.api.wrapper.system.other.crypto.OtherCryptoAsymmetricModel;
|
|
||||||
import org.opsli.common.enums.CryptoAsymmetricType;
|
|
||||||
import org.opsli.core.base.service.interfaces.CrudServiceInterface;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.opsli.modulars.system.other.crypto.entity.OtherCryptoAsymmetric;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.modulars.system.other.crypto.service
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2021-02-10 17:09:34
|
|
||||||
* @Description: 非对称加密 Service
|
|
||||||
*/
|
|
||||||
public interface IOtherCryptoAsymmetricService extends CrudServiceInterface<OtherCryptoAsymmetric, OtherCryptoAsymmetricModel> {
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 重置数据
|
|
||||||
* @param type 枚举
|
|
||||||
* @return OtherCryptoAsymmetricModel
|
|
||||||
*/
|
|
||||||
OtherCryptoAsymmetricModel reset(CryptoAsymmetricType type);
|
|
||||||
|
|
||||||
}
|
|
@ -1,192 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.other.crypto.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.other.crypto.OtherCryptoAsymmetricModel;
|
|
||||||
import org.opsli.common.constants.MyBatisConstants;
|
|
||||||
import org.opsli.common.enums.CryptoAsymmetricType;
|
|
||||||
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.CryptoAsymmetricUtil;
|
|
||||||
import org.opsli.modulars.system.SystemMsg;
|
|
||||||
import org.opsli.modulars.system.other.crypto.entity.OtherCryptoAsymmetric;
|
|
||||||
import org.opsli.modulars.system.other.crypto.mapper.OtherCryptoAsymmetricMapper;
|
|
||||||
import org.opsli.modulars.system.other.crypto.service.IOtherCryptoAsymmetricService;
|
|
||||||
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.system.other.crypto.service.impl
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2021-02-10 17:09:34
|
|
||||||
* @Description: 非对称加密 Service Impl
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class OtherCryptoAsymmetricServiceImpl extends CrudServiceImpl<OtherCryptoAsymmetricMapper, OtherCryptoAsymmetric, OtherCryptoAsymmetricModel>
|
|
||||||
implements IOtherCryptoAsymmetricService {
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private OtherCryptoAsymmetricMapper mapper;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public OtherCryptoAsymmetricModel insert(OtherCryptoAsymmetricModel model) {
|
|
||||||
if(model == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 唯一验证
|
|
||||||
Integer count = this.uniqueVerificationByCode(model);
|
|
||||||
if(count != null && count > 0){
|
|
||||||
// 重复
|
|
||||||
throw new ServiceException(SystemMsg.EXCEPTION_OTHER_CRYPTO_UNIQUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.insert(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public OtherCryptoAsymmetricModel update(OtherCryptoAsymmetricModel model) {
|
|
||||||
if(model == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 唯一验证
|
|
||||||
Integer count = this.uniqueVerificationByCode(model);
|
|
||||||
if(count != null && count > 0){
|
|
||||||
// 重复
|
|
||||||
throw new ServiceException(SystemMsg.EXCEPTION_OTHER_CRYPTO_UNIQUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.update(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean delete(String id) {
|
|
||||||
OtherCryptoAsymmetricModel 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<OtherCryptoAsymmetric> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.in(MyBatisConstants.FIELD_ID, Convert.toList(String.class, ids));
|
|
||||||
List<OtherCryptoAsymmetricModel> modelList = super.transformTs2Ms(
|
|
||||||
super.findList(queryWrapper)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 清除缓存
|
|
||||||
this.clearCache(modelList);
|
|
||||||
|
|
||||||
return super.deleteAll(ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 重置数据
|
|
||||||
* @param type 枚举
|
|
||||||
* @return OtherCryptoAsymmetricModel
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
@Override
|
|
||||||
public OtherCryptoAsymmetricModel reset(CryptoAsymmetricType type) {
|
|
||||||
if(type == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
QueryWrapper<OtherCryptoAsymmetric> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("crypto_type", type.getCode());
|
|
||||||
OtherCryptoAsymmetricModel model = super.transformT2M(
|
|
||||||
this.getOne(queryWrapper)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 删除当前数据 并清空缓存
|
|
||||||
this.delete(model);
|
|
||||||
// 重新获得缓存 如果当前库中没有该缓存 则自动创建
|
|
||||||
return CryptoAsymmetricUtil.getCryptoAsymmetric(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// =======================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 唯一验证
|
|
||||||
* @param model model
|
|
||||||
* @return Integer
|
|
||||||
*/
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Integer uniqueVerificationByCode(OtherCryptoAsymmetricModel model){
|
|
||||||
if(model == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
QueryWrapper<OtherCryptoAsymmetric> wrapper = new QueryWrapper<>();
|
|
||||||
wrapper.eq("crypto_type", model.getCryptoType());
|
|
||||||
|
|
||||||
// 重复校验排除自身
|
|
||||||
if(StringUtils.isNotEmpty(model.getId())){
|
|
||||||
wrapper.notIn(MyBatisConstants.FIELD_ID, model.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.count(wrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除缓存
|
|
||||||
* @param modelList
|
|
||||||
*/
|
|
||||||
private void clearCache(List<OtherCryptoAsymmetricModel> modelList){
|
|
||||||
// 清空缓存
|
|
||||||
if(CollUtil.isNotEmpty(modelList)){
|
|
||||||
int cacheCount = 0;
|
|
||||||
for (OtherCryptoAsymmetricModel model : modelList) {
|
|
||||||
cacheCount++;
|
|
||||||
boolean tmp = CryptoAsymmetricUtil.refresh(model);
|
|
||||||
if(tmp){
|
|
||||||
cacheCount--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 判断删除状态
|
|
||||||
if(cacheCount != 0){
|
|
||||||
// 删除缓存失败
|
|
||||||
throw new ServiceException(CoreMsg.CACHE_DEL_EXCEPTION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue