AuthorizeInstallServiceImpl.java 5.7 KB

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