AuthorizeInstallServiceImpl.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.fdkankan.manage.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.manage.common.CacheUtil;
  6. import com.fdkankan.manage.common.PageInfo;
  7. import com.fdkankan.manage.common.ResultCode;
  8. import com.fdkankan.manage.entity.AuthorizeInstall;
  9. import com.fdkankan.manage.entity.SysUser;
  10. import com.fdkankan.manage.exception.BusinessException;
  11. import com.fdkankan.manage.mapper.IAuthorizeInstallMapper;
  12. import com.fdkankan.manage.service.IAuthorizeInstallService;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import com.fdkankan.manage.service.ISysUserService;
  15. import com.fdkankan.manage.vo.request.AuthorizeParam;
  16. import com.fdkankan.reg.RegCodeUtil;
  17. import com.fdkankan.reg.dto.MachineRegDto;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Set;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2023-07-07
  32. */
  33. @Service
  34. public class AuthorizeInstallServiceImpl extends ServiceImpl<IAuthorizeInstallMapper, AuthorizeInstall> implements IAuthorizeInstallService {
  35. @Autowired
  36. ISysUserService sysUserService;
  37. @Override
  38. public Object pageList(AuthorizeParam param) {
  39. LambdaQueryWrapper<AuthorizeInstall> wrapper = new LambdaQueryWrapper<>();
  40. if(StringUtils.isNotBlank(param.getCustomerName())){
  41. wrapper.like(AuthorizeInstall::getCustomerName,param.getCustomerName());
  42. }
  43. if(param.getCustomerType() != null){
  44. wrapper.eq(AuthorizeInstall::getCustomerType,param.getCustomerType());
  45. }
  46. if(param.getUseType() != null){
  47. wrapper.eq(AuthorizeInstall::getUseType,param.getUseType());
  48. }
  49. if(StringUtils.isNotBlank(param.getAuthorizeKey())){
  50. wrapper.like(AuthorizeInstall::getAuthorizeKey,param.getAuthorizeKey());
  51. }
  52. if(StringUtils.isNotBlank(param.getMachineUuid())){
  53. wrapper.like(AuthorizeInstall::getMachineUuid,param.getMachineUuid());
  54. }
  55. if(StringUtils.isNotBlank(param.getMachineCode())){
  56. wrapper.like(AuthorizeInstall::getMachineCode,param.getMachineCode());
  57. }
  58. wrapper.orderByDesc(AuthorizeInstall::getCreateTime);
  59. Page<AuthorizeInstall> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  60. Set<Long> sysIds = page.getRecords().stream().map(AuthorizeInstall::getSysUserId).collect(Collectors.toSet());
  61. HashMap<Long, SysUser> userMap = sysUserService.getByIds(sysIds);
  62. for (AuthorizeInstall record : page.getRecords()) {
  63. if(userMap.get(record.getSysUserId())!=null){
  64. record.setSysUserName(userMap.get(record.getSysUserId()).getNickName());
  65. }
  66. }
  67. return PageInfo.PageInfo(page);
  68. }
  69. @Override
  70. public AuthorizeInstall addOrUpdate(AuthorizeInstall param) {
  71. param.setSysUserId(Long.valueOf((String) StpUtil.getLoginId()));
  72. if(param.getId() == null){
  73. //获取机器UUID,机器名称
  74. MachineRegDto machineRegDto = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().ParseMachineCode(param.getMachineCode());
  75. if(machineRegDto == null){
  76. throw new BusinessException(ResultCode.READ_MACHINE_CODE_ERROR);
  77. }
  78. param.setMachineUuid( machineRegDto.getUuid());
  79. try {
  80. String authorizeKey = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().GenRegeditCode(param.getMachineCode());
  81. if(StringUtils.isBlank(authorizeKey)){
  82. throw new BusinessException(ResultCode.GET_MACHINE_CODE_ERROR);
  83. }
  84. param.setAuthorizeKey(authorizeKey);
  85. }catch (Exception e){
  86. throw new BusinessException(ResultCode.GET_MACHINE_CODE_ERROR);
  87. }
  88. }
  89. this.saveOrUpdate(param);
  90. return param;
  91. }
  92. @Override
  93. public AuthorizeInstall checkMachineCode(String machineCode) {
  94. LambdaQueryWrapper<AuthorizeInstall> wrapper = new LambdaQueryWrapper<>();
  95. wrapper.eq(AuthorizeInstall::getMachineCode,machineCode);
  96. List<AuthorizeInstall> list = this.list(wrapper);
  97. if(list!=null && list.size() >0){
  98. return list.get(0);
  99. }
  100. MachineRegDto machineRegDto = null;
  101. try {
  102. machineRegDto = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().ParseMachineCode(machineCode);
  103. }catch (Exception e){
  104. throw new BusinessException(ResultCode.MACHINE_CODE_ERROR);
  105. }
  106. if(machineRegDto == null){
  107. throw new BusinessException(ResultCode.READ_MACHINE_CODE_ERROR);
  108. }
  109. String uuid = machineRegDto.getUuid();
  110. LambdaQueryWrapper<AuthorizeInstall> wrapper2 = new LambdaQueryWrapper<>();
  111. wrapper2.eq(AuthorizeInstall::getMachineUuid,uuid);
  112. List<AuthorizeInstall> list2 = this.list(wrapper2);
  113. if(list2!=null && list2.size() >0){
  114. return list2.get(0);
  115. }
  116. return null;
  117. }
  118. }