代码相关示例

本文介绍了如何从InputStream读取文件并解析PEM密钥,使用RSA256进行JWT签名,以及在两个员工列表中找出差异并整理配置信息的过程。
摘要由CSDN通过智能技术生成
IOC依赖注入:
构造方法注入:

@Service
public class UserService {
    
    private final DepartmentService departmentSerivce;
 
    /**
     * 通过构造方法注入DepartmentService类
     */
    @Autowired
    public UserSerivce(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }
 
    public List<Department> list() {
        retern departmentService.list();
    }    
 
}

@Service
public class DepartmentService {
    
    private final UserService userSerivce;
 
    /**
     * 通过构造方法注入UserService类
     */
    @Autowired
    public DepartmentSerivce(UserService userSerivce) {
        this.userSerivce = userSerivce;
    }
}

set方法注入@Service
public class UserService {
    
    private DepartmentService departmentSerivce;
   
    @Autowired
    public void setDepartmentSerivce(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }
 
    public List<Department> list() {
        retern departmentService.list();
    }    
}
field(@Autowired)方法注入@Service
public class UserService {
    @Autowired
    private DepartmentService departmentSerivce;
 
    public List<Department> list() {
        retern departmentService.list();
    }    
}
使用懒加载方法解决@Service
public class UserService {
    
    private DepartmentService departmentSerivce;
 
    @Autowired
    public UserSerivce(@Lazy DepartmentService departmentService) {
        this.departmentService = departmentService;
    }
 
    public List<Department> list() {
        retern departmentService.list();
    }    
 
}
使用 @PostConstruct

@Service
public class UserService {
 
    @Autowired
    private DepartmentService departmentService;
 
    @PostConstruct
    public void init() {
        departmentService.setUserService(this);
    }
 
    public DepartmentService getDepartmentService() {
        return departmentService;
    }
}

@Service
public class DepartmentService {
 
    private UserService userService;
     
    private String message = "Hi!";
 
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
     
    public String getMessage() {
        return message;
    }
}

实现ApplicationContextAware and InitializingBean接口

@Service
public class UserService implements ApplicationContextAware, InitializingBean {
 
    private DepartmentService departmentService;
 
    private ApplicationContext context;
 
    public DepartmentService getDepartmentService() {
        return departmentService;
    }
 
    @Override
    public void afterPropertiesSet() throws Exception {
        circB = context.getBean(DepartmentService.class);
    }
 
    @Override
    public void setApplicationContext(final ApplicationContext ctx) throws BeansException {
        context = ctx;
    }
}

public class DepartmentService {
 
    private UserService userService;
 
    private String message = "Hi!";
 
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
 
    public String getMessage() {
        return message;
    }
}

pagehelper分页工具:
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.10</version>
</dependency>
PageHelper.startPage(pageNum,pageSize);
List<Tools> list = toolsMapper.findAll();
PageInfo<Tools> pageInfo = new PageInfo<Tools>(list);
return ServerResponse.createBySuccess("查询成功",pageInfo);


InputStream inputStream = this.getClass().getResourceAsStream("/feishuSecurityFile.txt");
File file = asFile(inputStream);

PEMParser pemParser = new PEMParser(new FileReader(file));
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
Object object = pemParser.readObject();
KeyPair kp = converter.getKeyPair((PEMKeyPair) object);
PrivateKey privateKey = kp.getPrivate();
SignatureAlgorithm algorithm = SignatureAlgorithm.RS256;
JwtBuilder jwtBuilder = Jwts.builder()
        .setHeader(header)
        .setClaims(claims)
        .signWith(algorithm, privateKey);
String assertion = jwtBuilder.compact();
public static List<UacEmployeeDto> getDifferEmpListByMap(List<UacEmployeeDto> listA, List<UacEmployeeDto> listB) {
    listA = listA.stream().filter(v-> StringUtils.isNotBlank(v.getCorpCode())).collect(Collectors.toList());
    listB = listB.stream().filter(v-> StringUtils.isNotBlank(v.getCorpCode())).collect(Collectors.toList());
    List<UacEmployeeDto> differList = new ArrayList<>();
    Map<UacEmployeeDto, Integer> map = new HashMap<>();
    for (UacEmployeeDto strA : listA) {
        map.put(strA, 1);
    }
    for (UacEmployeeDto strB : listB) {
        Integer value = map.get(strB);
        if (value != null) {
            map.put(strB, ++value);
            continue;
        }
        map.put(strB, 1);
    }

    for (Map.Entry<UacEmployeeDto, Integer> entry : map.entrySet()) {
        //获取不同元素集合
        if (entry.getValue() == 1) {
            if (!listA.contains(entry.getKey())){
                differList.add(entry.getKey());
            }
        }
    }

    return differList.stream()
            .collect(Collectors.collectingAndThen(Collectors.toCollection(
                    ()->new TreeSet<>(Comparator.comparing(o->o.getEmpNo()+";"+o.getStatus()+";"+o.getDeptId()+";"+o.getPosition()+";"+o.getOrgCode())))
                    , ArrayList::new));
}
List<UacConfigEmployeeDto> configEmployees = employeeConfigVos.stream().map(v->{
    UacConfigEmployeeDto configEmployeeDto = new UacConfigEmployeeDto();
    configEmployeeDto.setOpenFeishu(v.getOpenFeishu());
    configEmployeeDto.setUsername(v.getUsername());
    configEmployeeDto.setEmpName(v.getDisplayName());
    return configEmployeeDto;
}).collect(Collectors.toList());

update uac_emp_position_his as a 
join sap_emp_position as b on a.object_id_ = b.id_ 
set a.begin_date_ = b.begin_date_ ,a.end_date_ = b.end_date_ 
where a.source_= 'SAP' and a.begin_date_ is null and a.end_date_ is null and a.data_version_ = '202312041430';

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值