提交 4f2d5918 作者: yanxin

增加专题跨环境同步相关接口

上级 4138b031
package com.zzsn.event.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* 专题数据同步配置类
*/
@Data
@Component
@RefreshScope
@ConfigurationProperties(SubjectSyncConfig.PREFIX)
public class SubjectSyncConfig {
public static final String PREFIX = "subject.sync";
private List<Config> configs= new ArrayList<>();
@Data
public static class Config {
//环境名称
private String name;
//环境编码
private String code;
//访问地址
private String domain;
//鉴权地址
private String loginUrl;
//专题列表查询地址
private String subjectListUrl;
//查询接口地址
private String findDataUrl;
//用户名
private String username;
//密码
private String password;
}
@Data
public static class ConfigVo {
//环境名称
private String name;
//环境编码
private String code;
}
}
package com.zzsn.event.controller;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzsn.event.config.SubjectSyncConfig;
import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result;
import com.zzsn.event.entity.*;
import com.zzsn.event.service.*;
import com.zzsn.event.util.encryption.AesEncryptUtil;
import com.zzsn.event.vo.SubjectKeywordsMap;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Description: 平台间专题数据同步
* @Author: yanxin
* @Date: 2023-06-12
* @Version: V1.0
*/
@Api(tags = "平台间专题数据同步")
@RestController
@RequestMapping("/sync")
@Slf4j
public class SubjectSyncController {
@Autowired
private SubjectSyncConfig syncConfig;
/**
* 专题直接关联部分begin
*/
@Autowired
private SubjectService subjectService;
@Autowired
private SubjectKeywordsService subjectKeywordsService;
@Autowired
private ISubjectKeywordsMapService subjectKeywordsMapService;
@Autowired
private ISubjectModelMapService subjectModelMapService;
@Autowired
private ISubjectSearchEnginesMapService subjectSearchEnginesMapService;
/**专题直接关联部分end*/
/**
* 专题分类部分begin
*/
@Autowired
private ISubjectTypeMapService subjectTypeMapService;
@Autowired
private ISubjectTypeService subjectTypeService;
/**专题分类部分end*/
/**
* 信息源以及信息源组部分begin
*/
@Autowired
private IInfoSourceService infoSourceService;
@Autowired
private ISubjectInfoSourceMapService subjectInfoSourceMapService;
@Autowired
private InfoSourceGroupService infoSourceGroupService;
@Autowired
private IInfoSourceGroupMapService infoSourceGroupMapService;
@Autowired
private IGroupTypeService groupTypeService;
@Autowired
private IGroupTypeMapService groupTypeMapService;
/**信息源以及信息源组部分end*/
@GetMapping(value = "/getConfigs")
public Result<?> getConfigs() {
List<SubjectSyncConfig.ConfigVo> configVos = JSONArray.parseArray(JSONArray.toJSONString(syncConfig.getConfigs()), SubjectSyncConfig.ConfigVo.class);
return Result.OK(configVos);
}
@GetMapping(value = "/getProjectTreeList")
public Object getProjectTreeList(@RequestParam(name="code") String code) throws Exception {
Optional<SubjectSyncConfig.Config> first = syncConfig.getConfigs().stream().filter(config -> code.equals(config.getCode())).findFirst();
if(!first.isPresent()){
return Result.FAIL("未找到对应配置");
}
SubjectSyncConfig.Config config = first.get();
//获取登陆token
String post = HttpUtil.get(config.getDomain() + config.getLoginUrl()+"?username="+ AesEncryptUtil.encrypt(config.getUsername())+"&password="+AesEncryptUtil.encrypt(config.getPassword()));
String token = JSON.parseObject(post).getString("result");
//查询专题配置
HttpHeaders headers = new HttpHeaders();
headers.add(Constants.HEADER_KEY, token);
String body = HttpRequest.get(config.getDomain() + config.getSubjectListUrl()).header(headers).execute().body();
return JSONObject.parseObject(body);
}
/**
* 接收专题信息并更新本地库
* @param subjectId
* @return
*/
@GetMapping(value = "/findSubjectData")
public Result<?> findSubjectData(@RequestParam(name="subjectId") String subjectId) {
SubjectAboutTable aboutTable = new SubjectAboutTable();
//专题直接关联部分
Subject subject = subjectService.getById(subjectId);
if(subject == null){
return Result.FAIL("专题不存在");
}
aboutTable.getSubject().add(subject);
aboutTable.getSubjectKeywords().addAll(subjectKeywordsService.list(Wrappers.lambdaQuery(SubjectKeywords.class).eq(SubjectKeywords::getSubjectId,subjectId)));
aboutTable.getSubjectKeywordsMap().addAll(subjectKeywordsMapService.list(Wrappers.lambdaQuery(SubjectKeywordsMap.class).eq(SubjectKeywordsMap::getSubjectId,subjectId)));
aboutTable.getSubjectModelMap().addAll(subjectModelMapService.list(Wrappers.lambdaQuery(SubjectModelMap.class).eq(SubjectModelMap::getSubjectId,subjectId)));
aboutTable.getSubjectSearchEnginesMap().addAll(subjectSearchEnginesMapService.list(Wrappers.lambdaQuery(SubjectSearchEnginesMap.class).eq(SubjectSearchEnginesMap::getSubjectId,subjectId)));
//专题分类部分
aboutTable.getSubjectTypeMap().addAll(subjectTypeMapService.list(Wrappers.lambdaQuery(SubjectTypeMap.class).eq(SubjectTypeMap::getSubjectId,subjectId)));
if(aboutTable.getSubjectTypeMap().size()>0){
List<String> typeIds = aboutTable.getSubjectTypeMap().stream().map(SubjectTypeMap::getTypeId).collect(Collectors.toList());
while (true){
Iterator<String> iterator = typeIds.iterator();
while (iterator.hasNext()){
String next = iterator.next();
if(StringUtils.isEmpty(next) || "0".equals(next)){
iterator.remove();
}
}
if(typeIds.size()<=0){
break;
}
List<SubjectType> list = subjectTypeService.list(Wrappers.lambdaQuery(SubjectType.class).in(SubjectType::getId, typeIds));
typeIds = list.stream().map(SubjectType::getPid).collect(Collectors.toList());
aboutTable.getSubjectType().addAll(list);
}
}
//信息源以及信息源组部分begin
aboutTable.getSubjectInfoSourceMap().addAll(subjectInfoSourceMapService.list(Wrappers.lambdaQuery(SubjectInfoSourceMap.class).eq(SubjectInfoSourceMap::getSubjectId,subjectId).eq(SubjectInfoSourceMap::getType,2)));
List<String> groupIds = aboutTable.getSubjectInfoSourceMap().stream().map(SubjectInfoSourceMap::getSourceId).collect(Collectors.toList());
if(groupIds.size()>0){
aboutTable.getInfoSourceGroup().addAll(infoSourceGroupService.list(Wrappers.lambdaQuery(InfoSourceGroup.class).in(InfoSourceGroup::getId,groupIds)));
aboutTable.getInfoSourceGroupMap().addAll(infoSourceGroupMapService.list(Wrappers.lambdaQuery(InfoSourceGroupMap.class).in(InfoSourceGroupMap::getGroupId,groupIds)));
List<String> sourceIds = aboutTable.getInfoSourceGroupMap().stream().map(InfoSourceGroupMap::getSourceId).collect(Collectors.toList());
aboutTable.getInfoSource().addAll(infoSourceService.list(Wrappers.lambdaQuery(InfoSource.class).in(InfoSource::getId,sourceIds)));
aboutTable.getGroupTypeMap().addAll(groupTypeMapService.list(Wrappers.lambdaQuery(GroupTypeMap.class).in(GroupTypeMap::getGroupId,groupIds)));
if(aboutTable.getGroupTypeMap().size()>0){
List<String> typeIds = aboutTable.getGroupTypeMap().stream().map(GroupTypeMap::getTypeId).collect(Collectors.toList());
while (true){
Iterator<String> iterator = typeIds.iterator();
while (iterator.hasNext()){
String next = iterator.next();
if(StringUtils.isEmpty(next) || "0".equals(next)){
iterator.remove();
}
}
if(typeIds.size()<=0){
break;
}
List<GroupType> list = groupTypeService.list(Wrappers.lambdaQuery(GroupType.class).in(GroupType::getId, typeIds));
typeIds = list.stream().map(GroupType::getPid).collect(Collectors.toList());
aboutTable.getGroupType().addAll(list);
}
}
}
return Result.OK(aboutTable);
}
/**
* 查询并更新本地专题信息
*
* @return
*/
@GetMapping(value = "/findAndSyncSubjectData")
public Result<?> findAndSyncSubjectData(@RequestParam(name="code") String code,
@RequestParam(name="subjectId") String subjectId,
@RequestParam(name="environment",defaultValue = "") String environment) {
try {
Optional<SubjectSyncConfig.Config> first = syncConfig.getConfigs().stream().filter(config -> code.equals(config.getCode())).findFirst();
if(!first.isPresent()){
return Result.FAIL("未找到对应配置");
}
SubjectSyncConfig.Config config = first.get();
//获取登陆token
String post = HttpUtil.get(config.getDomain() + config.getLoginUrl()+"?username="+ AesEncryptUtil.encrypt(config.getUsername())+"&password="+AesEncryptUtil.encrypt(config.getPassword()));
String token = JSON.parseObject(post).getString("result");
//查询专题配置
HttpHeaders headers = new HttpHeaders();
headers.add(Constants.HEADER_KEY, token);
String body = HttpRequest.get(config.getDomain() + config.getFindDataUrl() + "?subjectId=" + subjectId).header(headers).execute().body();
if(JSON.parseObject(body).getInteger("code") != 200){
log.error("专题:{}信息查询失败:{}",subjectId,body);
return Result.FAIL("专题信息查询失败");
}
SubjectAboutTable aboutTable = JSON.parseObject(JSON.parseObject(body).getString("result"),SubjectAboutTable.class);
if(aboutTable.getSubject()!=null && aboutTable.getSubject().size()>0){
//同步后默认专题为未启用状态
Subject subject = aboutTable.getSubject().get(0);
subject.setStatus(0);
subject.setEnvironment(environment);
subjectService.saveOrUpdateBatch(aboutTable.getSubject());
}
if(aboutTable.getSubjectKeywords()!=null && aboutTable.getSubjectKeywords().size()>0){
subjectKeywordsService.saveOrUpdateBatch(aboutTable.getSubjectKeywords());
}
if(aboutTable.getSubjectKeywordsMap()!=null && aboutTable.getSubjectKeywordsMap().size()>0){
subjectKeywordsMapService.saveOrUpdateBatch(aboutTable.getSubjectKeywordsMap());
}
if(aboutTable.getSubjectModelMap()!=null && aboutTable.getSubjectModelMap().size()>0){
subjectModelMapService.saveOrUpdateBatch(aboutTable.getSubjectModelMap());
}
if(aboutTable.getSubjectSearchEnginesMap()!=null && aboutTable.getSubjectSearchEnginesMap().size()>0){
subjectSearchEnginesMapService.saveOrUpdateBatch(aboutTable.getSubjectSearchEnginesMap());
}
if(aboutTable.getSubjectTypeMap()!=null && aboutTable.getSubjectTypeMap().size()>0){
subjectTypeMapService.saveOrUpdateBatch(aboutTable.getSubjectTypeMap());
}
if(aboutTable.getSubjectType()!=null && aboutTable.getSubjectType().size()>0){
subjectTypeService.saveOrUpdateBatch(aboutTable.getSubjectType());
}
if(aboutTable.getInfoSource()!=null && aboutTable.getInfoSource().size()>0){
infoSourceService.saveOrUpdateBatch(aboutTable.getInfoSource());
}
if(aboutTable.getSubjectInfoSourceMap()!=null && aboutTable.getSubjectInfoSourceMap().size()>0){
subjectInfoSourceMapService.saveOrUpdateBatch(aboutTable.getSubjectInfoSourceMap());
}
if(aboutTable.getInfoSourceGroup()!=null && aboutTable.getInfoSourceGroup().size()>0){
infoSourceGroupService.saveOrUpdateBatch(aboutTable.getInfoSourceGroup());
}
if(aboutTable.getInfoSourceGroupMap()!=null && aboutTable.getInfoSourceGroupMap().size()>0){
infoSourceGroupMapService.saveOrUpdateBatch(aboutTable.getInfoSourceGroupMap());
}
if(aboutTable.getGroupType()!=null && aboutTable.getGroupType().size()>0){
groupTypeService.saveOrUpdateBatch(aboutTable.getGroupType());
}
if(aboutTable.getGroupTypeMap()!=null && aboutTable.getGroupTypeMap().size()>0){
groupTypeMapService.saveOrUpdateBatch(aboutTable.getGroupTypeMap());
}
}catch (Exception e){
log.error("专题:{}同步失败,e:{}",subjectId,e);
return Result.FAIL("专题同步失败");
}
return Result.OK();
}
}
package com.zzsn.event.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 信息源组类别
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Data
@TableName("group_type")
@ApiModel(value="group_type对象", description="信息源组类别")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GroupType implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private String id;
/**类别名称*/
@Excel(name = "类别名称", width = 15)
@ApiModelProperty(value = "类别名称")
private String typeName;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
/**父级节点*/
@Excel(name = "父级节点", width = 15)
@ApiModelProperty(value = "父级节点")
private String pid;
/**是否有子节点*/
@Excel(name = "是否有子节点", width = 15, dicCode = "yn")
@ApiModelProperty(value = "是否有子节点")
private String hasChild;
/**
* 状态(1启用 0不启用)
*/
private Integer status;
/**所属客户*/
@ApiModelProperty(value = "所属客户")
private String customerId;
}
package com.zzsn.event.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 信息源组-类别关联表
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Data
@TableName("group_type_map")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="group_type_map对象", description="信息源组-类别关联表")
public class GroupTypeMap implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private String id;
/**信息源组id*/
@Excel(name = "信息源组id", width = 15)
@ApiModelProperty(value = "信息源组id")
private String groupId;
/**类别id*/
@Excel(name = "类别id", width = 15)
@ApiModelProperty(value = "类别id")
private String typeId;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
}
package com.zzsn.event.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
@Data
@TableName("info_source_group_map")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="info_source_group_map对象", description="信息源组和信息源关联表")
public class InfoSourceGroupMap implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private String id;
/**信息源组id*/
@Excel(name = "信息源组id", width = 15)
@ApiModelProperty(value = "信息源组id")
private String groupId;
/**信息源id*/
@Excel(name = "信息源id", width = 15)
@ApiModelProperty(value = "信息源id")
private String sourceId;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
}
package com.zzsn.event.entity;
import com.zzsn.event.vo.SubjectKeywordsMap;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @Description: 专题相关表(数据同步使用)
* @Author: yanxin
* @Date: 2023-06-12
* @Version: V1.0
*/
@Data
public class SubjectAboutTable implements Serializable {
private static final long serialVersionUID = 1L;
/**专题直接关联部分begin*/
private List<Subject> subject = new ArrayList<>();
private List<SubjectKeywords> subjectKeywords = new ArrayList<>();
private List<SubjectKeywordsMap> subjectKeywordsMap = new ArrayList<>();
private List<SubjectModelMap> subjectModelMap = new ArrayList<>();
private List<SubjectSearchEnginesMap> subjectSearchEnginesMap = new ArrayList<>();
/**专题直接关联部分end*/
/**专题分类部分begin*/
private List<SubjectTypeMap> subjectTypeMap = new ArrayList<>();
private List<SubjectType> subjectType = new ArrayList<>();
/**专题分类部分end*/
/**信息源以及信息源组部分begin*/
private List<InfoSource> infoSource = new ArrayList<>();
private List<SubjectInfoSourceMap> subjectInfoSourceMap = new ArrayList<>();
private List<InfoSourceGroup> infoSourceGroup = new ArrayList<>();
private List<InfoSourceGroupMap> infoSourceGroupMap = new ArrayList<>();
private List<GroupType> groupType = new ArrayList<>();
private List<GroupTypeMap> groupTypeMap = new ArrayList<>();
/**信息源以及信息源组部分end*/
}
package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.GroupTypeMap;
import org.apache.ibatis.annotations.Mapper;
/**
* @Description: 信息源组-类别关联表
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Mapper
public interface GroupTypeMapMapper extends BaseMapper<GroupTypeMap> {
}
package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.GroupType;
import org.apache.ibatis.annotations.Mapper;
/**
* @Description: 信息源组类别
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Mapper
public interface GroupTypeMapper extends BaseMapper<GroupType> {
}
package com.zzsn.event.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.event.entity.InfoSourceGroupMap;
import org.apache.ibatis.annotations.Mapper;
/**
* @author 张宗涵
* @date 2024/5/22
*/
@Mapper
public interface InfoSourceGroupMapMapper extends BaseMapper<InfoSourceGroupMap> {
}
<?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="com.zzsn.event.mapper.GroupTypeMapMapper">
</mapper>
\ No newline at end of file
<?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="com.zzsn.event.mapper.GroupTypeMapper">
</mapper>
<?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="com.zzsn.event.mapper.InfoSourceGroupMapMapper">
</mapper>
\ No newline at end of file
package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.GroupTypeMap;
/**
* @Description: 信息源组-类别关联表
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
public interface IGroupTypeMapService extends IService<GroupTypeMap> {
}
package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.GroupType;
/**
* @Description: 信息源组类别
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
public interface IGroupTypeService extends IService<GroupType> {
}
package com.zzsn.event.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.event.entity.InfoSourceGroupMap;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
public interface IInfoSourceGroupMapService extends IService<InfoSourceGroupMap> {
}
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.GroupTypeMap;
import com.zzsn.event.mapper.GroupTypeMapMapper;
import com.zzsn.event.service.IGroupTypeMapService;
import org.springframework.stereotype.Service;
/**
* @Description: 信息源组-类别关联表
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Service
public class GroupTypeMapServiceImpl extends ServiceImpl<GroupTypeMapMapper, GroupTypeMap> implements IGroupTypeMapService {
}
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.GroupType;
import com.zzsn.event.mapper.GroupTypeMapper;
import com.zzsn.event.service.IGroupTypeService;
import org.springframework.stereotype.Service;
/**
* @Description: 信息源组类别
* @Author: jeecg-boot
* @Date: 2021-11-25
* @Version: V1.0
*/
@Service
public class GroupTypeServiceImpl extends ServiceImpl<GroupTypeMapper, GroupType> implements IGroupTypeService {
}
package com.zzsn.event.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.event.entity.InfoSourceGroupMap;
import com.zzsn.event.mapper.InfoSourceGroupMapMapper;
import com.zzsn.event.service.IInfoSourceGroupMapService;
import org.springframework.stereotype.Service;
/**
* @Description: 信息源组和信息源关联表
* @Author: jeecg-boot
* @Date: 2021-11-24
* @Version: V1.0
*/
@Service
public class InfoSourceGroupMapServiceImpl extends ServiceImpl<InfoSourceGroupMapMapper, InfoSourceGroupMap> implements IInfoSourceGroupMapService {
}
package com.zzsn.event.util.encryption;
import org.springframework.util.Base64Utils;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* AES 加密
*/
public class AesEncryptUtil {
//使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同!
private static String KEY = EncryptedString.key;
private static String IV = EncryptedString.iv;
/**
* 加密方法
* @param data 要加密的数据
* @param key 加密key
* @param iv 加密iv
* @return 加密的结果
* @throws Exception
*/
public static String encrypt(String data, String key, String iv) throws Exception {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");//"算法/模式/补码方式"NoPadding PkcsPadding
int blockSize = cipher.getBlockSize();
byte[] dataBytes = data.getBytes();
int plaintextLength = dataBytes.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength];
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
byte[] encrypted = cipher.doFinal(plaintext);
return Base64Utils.encodeToString(encrypted);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 解密方法
* @param data 要解密的数据
* @param key 解密key
* @param iv 解密iv
* @return 解密的结果
*/
public static String desEncrypt(String data, String key, String iv) {
try {
byte[] encrypted1 = Base64Utils.decodeFromString(data);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
byte[] original = cipher.doFinal(encrypted1);
return new String(original);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 使用默认的key和iv加密
* @param data
* @return
* @throws Exception
*/
public static String encrypt(String data) throws Exception {
return encrypt(data, KEY, IV);
}
/**
* 使用默认的key和iv解密
* @param data
* @return
*/
public static String desEncrypt(String data) {
return desEncrypt(data, KEY, IV);
}
// /**
// * 测试
// */
// public static void main(String args[]) throws Exception {
// String test1 = "sa";
// String test =new String(test1.getBytes(),"UTF-8");
// String data = null;
// String key = KEY;
// String iv = IV;
// // /g2wzfqvMOeazgtsUVbq1kmJawROa6mcRAzwG1/GeJ4=
// data = encrypt(test, key, iv);
// System.out.println("数据:"+test);
// System.out.println("加密:"+data);
// String jiemi =desEncrypt(data, key, iv).trim();
// System.out.println("解密:"+jiemi);
// }
}
package com.zzsn.event.util.encryption;
import lombok.Data;
@Data
public class EncryptedString {
public static String key = "1234567890adbcde";//长度为16个字符
public static String iv = "1234567890hjlkew";//长度为16个字符
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论