AuthorizeInstallServiceImpl.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. wrapper.orderByDesc(AuthorizeInstall::getCreateTime);
  56. Page<AuthorizeInstall> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  57. Set<Long> sysIds = page.getRecords().stream().map(AuthorizeInstall::getSysUserId).collect(Collectors.toSet());
  58. HashMap<Long, SysUser> userMap = sysUserService.getByIds(sysIds);
  59. for (AuthorizeInstall record : page.getRecords()) {
  60. if(userMap.get(record.getSysUserId())!=null){
  61. record.setSysUserName(userMap.get(record.getSysUserId()).getNickName());
  62. }
  63. }
  64. return PageInfo.PageInfo(page);
  65. }
  66. @Override
  67. public AuthorizeInstall addOrUpdate(AuthorizeInstall param) {
  68. param.setSysUserId(Long.valueOf((String) StpUtil.getLoginId()));
  69. if(param.getId() == null){
  70. //获取机器UUID,机器名称
  71. MachineRegDto machineRegDto = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().ParseMachineCode(param.getMachineCode());
  72. if(machineRegDto == null){
  73. throw new BusinessException(ResultCode.READ_MACHINE_CODE_ERROR);
  74. }
  75. param.setMachineUuid( machineRegDto.getUuid());
  76. try {
  77. String authorizeKey = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().GenRegeditCode(param.getMachineCode());
  78. if(StringUtils.isBlank(authorizeKey)){
  79. throw new BusinessException(ResultCode.GET_MACHINE_CODE_ERROR);
  80. }
  81. param.setAuthorizeKey(authorizeKey);
  82. }catch (Exception e){
  83. throw new BusinessException(ResultCode.GET_MACHINE_CODE_ERROR);
  84. }
  85. }
  86. this.saveOrUpdate(param);
  87. return param;
  88. }
  89. @Override
  90. public AuthorizeInstall checkMachineCode(String machineCode) {
  91. LambdaQueryWrapper<AuthorizeInstall> wrapper = new LambdaQueryWrapper<>();
  92. wrapper.eq(AuthorizeInstall::getMachineCode,machineCode);
  93. List<AuthorizeInstall> list = this.list(wrapper);
  94. if(list!=null && list.size() >0){
  95. return list.get(0);
  96. }
  97. MachineRegDto machineRegDto = null;
  98. try {
  99. machineRegDto = RegCodeUtil.builder().env(CacheUtil.laserRegEnv).build().ParseMachineCode(machineCode);
  100. }catch (Exception e){
  101. throw new BusinessException(ResultCode.MACHINE_CODE_ERROR);
  102. }
  103. if(machineRegDto == null){
  104. throw new BusinessException(ResultCode.READ_MACHINE_CODE_ERROR);
  105. }
  106. String uuid = machineRegDto.getUuid();
  107. LambdaQueryWrapper<AuthorizeInstall> wrapper2 = new LambdaQueryWrapper<>();
  108. wrapper2.eq(AuthorizeInstall::getMachineUuid,uuid);
  109. List<AuthorizeInstall> list2 = this.list(wrapper2);
  110. if(list2!=null && list2.size() >0){
  111. return list2.get(0);
  112. }
  113. return null;
  114. }
  115. }