|
|
@@ -0,0 +1,93 @@
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.entity.AuthorizeRtk;
|
|
|
+import com.fdkankan.manage.entity.RtkDevice;
|
|
|
+import com.fdkankan.manage.entity.SysUser;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.mapper.IAuthorizeRtkMapper;
|
|
|
+import com.fdkankan.manage.service.IAuthorizeRtkService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.service.IRtkDeviceService;
|
|
|
+import com.fdkankan.manage.service.ISysUserService;
|
|
|
+import com.fdkankan.manage.util.DateUtils;
|
|
|
+import com.fdkankan.manage.vo.request.AuthorizeRtkParam;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2025-03-24
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AuthorizeRtkServiceImpl extends ServiceImpl<IAuthorizeRtkMapper, AuthorizeRtk> implements IAuthorizeRtkService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IRtkDeviceService rtkDeviceService;
|
|
|
+ @Autowired
|
|
|
+ ISysUserService sysUserService;
|
|
|
+ @Override
|
|
|
+ public void addAuth(AuthorizeRtk authorizeRtk) {
|
|
|
+ if(StringUtils.isBlank(authorizeRtk.getRtkCode()) ||authorizeRtk.getValidStartTime() == null || authorizeRtk.getValidEndTime() == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(authorizeRtk.getRtkCode());
|
|
|
+ if(rtkDevice == null || rtkDevice.getUseStatus() ==1){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
|
|
|
+ }
|
|
|
+ if(rtkDevice.getValidStartTime() != null || rtkDevice.getValidEndTime() != null){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TIME_ERROR);
|
|
|
+ }
|
|
|
+ if(authorizeRtk.getValidEndTime().before(authorizeRtk.getValidStartTime())){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TIME_ERROR2);
|
|
|
+ }
|
|
|
+
|
|
|
+ String startTime = DateUtils.getStartTime(authorizeRtk.getValidStartTime());
|
|
|
+ String endTime = DateUtils.getEndTime(authorizeRtk.getValidEndTime());
|
|
|
+ rtkDeviceService.updateValidTime(rtkDevice.getId(),startTime,endTime);
|
|
|
+
|
|
|
+ authorizeRtk.setValidStartTime(DateUtil.parse(startTime));
|
|
|
+ authorizeRtk.setValidEndTime(DateUtil.parse(endTime));
|
|
|
+ authorizeRtk.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
|
|
|
+ this.save(authorizeRtk);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(AuthorizeRtkParam param) {
|
|
|
+ if(StringUtils.isBlank(param.getRktCode())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<AuthorizeRtk> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(AuthorizeRtk::getRtkCode,param.getRktCode());
|
|
|
+ wrapper.orderByDesc(AuthorizeRtk::getId);
|
|
|
+ Page<AuthorizeRtk> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
+ Set<Long> sysIds = page.getRecords().stream().map(AuthorizeRtk::getSysUserId).collect(Collectors.toSet());
|
|
|
+ HashMap<Long, SysUser> userMap = sysUserService.getByIds(sysIds);
|
|
|
+ for (AuthorizeRtk record : page.getRecords()) {
|
|
|
+ SysUser sysUser = userMap.get(record.getSysUserId());
|
|
|
+ if(sysUser != null){
|
|
|
+ record.setSysUserName(sysUser.getNickName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+}
|