Browse Source

rtk管理1.2.0

lyhzzz 1 year ago
parent
commit
bd313bca84

+ 3 - 0
src/main/java/com/fdkankan/manage/common/ResultCode.java

@@ -98,6 +98,9 @@ public enum ResultCode  {
     RTK_SN_CODE_NOT_AC(50077, "板卡SN码未激活"),
     SGRTK_SN_EXIST(50078, "深光插件sn已存在"),
 
+    RTK_ACCOUNT_NOT_EXIT(50079, "rtk账号库存不足"),
+
+
     ;
 
     private Integer code;

+ 29 - 1
src/main/java/com/fdkankan/manage/controller/RtkAccountController.java

@@ -1,6 +1,14 @@
 package com.fdkankan.manage.controller;
 
 
+import com.fdkankan.manage.common.ResultData;
+import com.fdkankan.manage.entity.RtkAccount;
+import com.fdkankan.manage.entity.RtkInfo;
+import com.fdkankan.manage.service.IRtkAccountService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
@@ -14,8 +22,28 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2024-07-22
  */
 @RestController
-@RequestMapping("/manage/rtkAccount")
+@RequestMapping("/service/manage/rtkAccount")
 public class RtkAccountController {
 
+    @Autowired
+    IRtkAccountService rtkAccountService;
+
+
+    @PostMapping("/list")
+    public ResultData list(@RequestBody RtkInfoParam param){
+        return ResultData.ok(rtkAccountService.pageList(param));
+    }
+
+    @PostMapping("/saveOrEdit")
+    public ResultData saveOrEdit(@RequestBody RtkAccount param){
+        rtkAccountService.saveOrEditEntity(param);
+        return ResultData.ok();
+    }
+
+    @PostMapping("/del")
+    public ResultData del(@RequestBody RtkAccount param){
+        rtkAccountService.del(param);
+        return ResultData.ok();
+    }
 }
 

+ 29 - 1
src/main/java/com/fdkankan/manage/controller/RtkDeviceController.java

@@ -1,6 +1,15 @@
 package com.fdkankan.manage.controller;
 
 
+import com.fdkankan.manage.common.ResultData;
+import com.fdkankan.manage.entity.RtkAccount;
+import com.fdkankan.manage.entity.RtkDevice;
+import com.fdkankan.manage.entity.RtkInfo;
+import com.fdkankan.manage.service.IRtkDeviceService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
@@ -14,8 +23,27 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2024-07-22
  */
 @RestController
-@RequestMapping("/manage/rtkDevice")
+@RequestMapping("/service/manage/rtkDevice")
 public class RtkDeviceController {
 
+    @Autowired
+    IRtkDeviceService rtkDeviceService;
+
+    @PostMapping("/list")
+    public ResultData list(@RequestBody RtkInfoParam param){
+        return ResultData.ok(rtkDeviceService.pageList(param));
+    }
+
+    @PostMapping("/saveOrEdit")
+    public ResultData saveOrEdit(@RequestBody RtkDevice rtkDevice){
+        rtkDeviceService.saveOrEditEntity(rtkDevice);
+        return ResultData.ok();
+    }
+
+    @PostMapping("/del")
+    public ResultData del(@RequestBody RtkDevice rtkDevice){
+        rtkDeviceService.del(rtkDevice);
+        return ResultData.ok();
+    }
 }
 

+ 1 - 3
src/main/java/com/fdkankan/manage/controller/RtkInfoController.java

@@ -23,9 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
 import java.util.Objects;
 
 /**
- * 经销商申请管理
- * @author 
- * @since 2022-09-21
+ * rtk 1.1.0  ,1.2.0版本废弃
  */
 @RestController
 @RequestMapping("/service/manage/rtkInfo")

+ 17 - 1
src/main/java/com/fdkankan/manage/controller/RtkUseLogController.java

@@ -1,6 +1,13 @@
 package com.fdkankan.manage.controller;
 
 
+import com.fdkankan.common.util.SecurityUtil;
+import com.fdkankan.manage.common.ResultData;
+import com.fdkankan.manage.service.IRtkUseLogService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
@@ -14,8 +21,17 @@ import org.springframework.web.bind.annotation.RestController;
  * @since 2024-07-22
  */
 @RestController
-@RequestMapping("/manage/rtkUseLog")
+@RequestMapping("/service/manage/rtkUseLog")
 public class RtkUseLogController {
 
+    @Autowired
+    IRtkUseLogService rtkUseLogService;
+
+    @PostMapping("/list")
+    public ResultData list(@RequestBody RtkInfoParam param){
+        return ResultData.ok(rtkUseLogService.pageList(param));
+    }
+
+
 }
 

+ 9 - 2
src/main/java/com/fdkankan/manage/entity/RtkAccount.java

@@ -72,10 +72,17 @@ public class RtkAccount implements Serializable {
     private Date updateTime;
 
     @TableField("create_user_id")
-    private Integer createUserId;
+    private Long createUserId;
 
     @TableField("update_user_id")
-    private Integer updateUserId;
+    private Long updateUserId;
 
+    @TableField("del_user_id")
+    private Long delUserId;
+
+    @TableField(exist = false)
+    private String createUserName;
+    @TableField(exist = false)
+    private String createNickName;
 
 }

+ 11 - 4
src/main/java/com/fdkankan/manage/entity/RtkDevice.java

@@ -37,8 +37,8 @@ public class RtkDevice implements Serializable {
     @TableField("sg_rtk_sn")
     private String sgRtkSn;
 
-    @TableField("type")
-    private Integer type;
+    @TableField("rtk_type")
+    private Integer rtkType;
 
     @TableField("rec_status")
     @TableLogic(value = "A",delval = "I")
@@ -51,10 +51,17 @@ public class RtkDevice implements Serializable {
     private Date updateTime;
 
     @TableField("create_user_id")
-    private Integer createUserId;
+    private Long createUserId;
 
     @TableField("update_user_id")
-    private Integer updateUserId;
+    private Long updateUserId;
 
+    @TableField("del_user_id")
+    private Long delUserId;
+
+    @TableField(exist = false)
+    private String createUserName;
+    @TableField(exist = false)
+    private String createNickName;
 
 }

+ 3 - 0
src/main/java/com/fdkankan/manage/entity/RtkUseLog.java

@@ -31,6 +31,9 @@ public class RtkUseLog implements Serializable {
     @TableField("rtk_sn_code")
     private String rtkSnCode;
 
+    @TableField("rtk_account_id")
+    private Integer rtkAccountId;
+
     @TableField("user_name")
     private String userName;
 

+ 23 - 5
src/main/java/com/fdkankan/manage/inner/controller/InnerController.java

@@ -86,10 +86,10 @@ public class InnerController extends BaseController {
     IRtkUseLogService rtkUseLogService;
 
     /**
-     *
+     * 相机开启rtk获取账号
      */
     @GetMapping("/info/{rtkSnCode}")
-    public ResultData info(@PathVariable String rtkSnCode){
+    public synchronized ResultData info(@PathVariable String rtkSnCode){
         if(StringUtils.isBlank(rtkSnCode)){
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
@@ -99,14 +99,32 @@ public class InnerController extends BaseController {
         }
         RtkInfo rtkInfo = new RtkInfo();
         rtkInfo.setRtkSnCode(rtkSnCode);
-        rtkInfo.setRtkType(rtkDevice.getType());
+        rtkInfo.setRtkType(rtkDevice.getRtkType());
         //rtkDevice.getType() = 0板卡自带账号信息,无需关联
-        if(rtkDevice.getType() != 0){
+        Integer rtkAccountId = null;
+        if(rtkDevice.getRtkType() != 0){
             RtkAccount rtkAccount = rtkAccountService.getOneNotUseAccount(rtkSnCode);
+            rtkAccountId = rtkAccount.getId();
             BeanUtils.copyProperties(rtkAccount,rtkInfo);
         }
         String clientIP = ServletUtil.getClientIP(request);
-        rtkUseLogService.saveLog(rtkInfo,clientIP);
+        rtkUseLogService.saveLog(rtkInfo,clientIP,rtkAccountId);
         return ResultData.ok(rtkInfo);
     }
+
+    /**
+     * 相机关闭rtk,回收账号
+     */
+    @GetMapping("/stop/{rtkSnCode}")
+    public ResultData stop(@PathVariable String rtkSnCode){
+        if(StringUtils.isBlank(rtkSnCode)){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode);
+        if(rtkDevice == null){
+            throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
+        }
+        rtkAccountService.stop(rtkSnCode);
+        return ResultData.ok();
+    }
 }

+ 10 - 0
src/main/java/com/fdkankan/manage/service/IRtkAccountService.java

@@ -2,6 +2,7 @@ package com.fdkankan.manage.service;
 
 import com.fdkankan.manage.entity.RtkAccount;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
 
 /**
  * <p>
@@ -17,4 +18,13 @@ public interface IRtkAccountService extends IService<RtkAccount> {
 
     void updateAccountStatus(Integer id, int status);
 
+    void stop(String rtkSnCode);
+
+    Object pageList(RtkInfoParam param);
+
+    void saveOrEditEntity(RtkAccount param);
+
+    void del(RtkAccount param);
+
+    RtkAccount getByUserName(String userName);
 }

+ 12 - 0
src/main/java/com/fdkankan/manage/service/IRtkDeviceService.java

@@ -1,7 +1,9 @@
 package com.fdkankan.manage.service;
 
+import com.fdkankan.manage.entity.RtkAccount;
 import com.fdkankan.manage.entity.RtkDevice;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
 
 /**
  * <p>
@@ -14,4 +16,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IRtkDeviceService extends IService<RtkDevice> {
 
     RtkDevice getByRtkSnCode(String rtkSnCode);
+
+    Object pageList(RtkInfoParam param);
+
+    void saveOrEditEntity(RtkDevice rtkDevice);
+
+    void del(RtkDevice rtkDevice);
+
+    RtkDevice getSgRtkSn(String sgRtkSn);
+
+    RtkDevice getByCameraSn(String cameraSnCode);
 }

+ 6 - 1
src/main/java/com/fdkankan/manage/service/IRtkUseLogService.java

@@ -3,6 +3,7 @@ package com.fdkankan.manage.service;
 import com.fdkankan.manage.entity.RtkInfo;
 import com.fdkankan.manage.entity.RtkUseLog;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
 
 /**
  * <p>
@@ -14,5 +15,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IRtkUseLogService extends IService<RtkUseLog> {
 
-    void saveLog(RtkInfo rtkInfo, String clientIP);
+    void saveLog(RtkInfo rtkInfo, String clientIP,Integer rtkAccountId);
+
+    RtkUseLog getByRtkSn(String rtkSnCode);
+
+    Object pageList(RtkInfoParam param);
 }

+ 120 - 9
src/main/java/com/fdkankan/manage/service/impl/RtkAccountServiceImpl.java

@@ -1,19 +1,25 @@
 package com.fdkankan.manage.service.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fdkankan.dingtalk.DingTalkSendUtils;
+import com.fdkankan.manage.common.PageInfo;
 import com.fdkankan.manage.common.ResultCode;
-import com.fdkankan.manage.entity.RtkAccount;
-import com.fdkankan.manage.entity.RtkInfo;
+import com.fdkankan.manage.entity.*;
 import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.mapper.IRtkAccountMapper;
 import com.fdkankan.manage.service.IRtkAccountService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage.service.IRtkUseLogService;
+import com.fdkankan.manage.service.ISysUserService;
 import com.fdkankan.manage.util.SendMailUtils;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
 import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -25,6 +31,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -41,29 +48,45 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
 
     @Autowired
     RedisUtil redisUtil;
+    @Autowired
+    IRtkUseLogService rtkUseLogService;
+    @Autowired
+    ISysUserService sysUserService;
 
     @Override
     public RtkAccount getOneNotUseAccount(String rtkSnCode) {
         String redisKey = "4dkankan:rtk:snCode:"+rtkSnCode;
         if(redisUtil.hasKey(redisKey)){
             String jsonStr = redisUtil.get(redisKey);
-            redisUtil.expire(redisKey,60);
+            redisUtil.expire(redisKey,8 * 60 * 60);
             return JSONObject.parseObject(jsonStr, RtkAccount.class);
         }
 
         LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
         wrapper.in(RtkAccount::getStatus,0,1);
-        wrapper.orderByAsc(RtkAccount::getId);
+        wrapper.orderByAsc(RtkAccount::getUpdateTime);
         List<RtkAccount> list = this.list(wrapper);
         if(list == null || list.isEmpty()){
             //账号库存不足,钉钉通知
             sendDingDingMsg(0);
-            throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
+            throw new BusinessException(ResultCode.RTK_ACCOUNT_NOT_EXIT);
         }
-        RtkAccount rtkAccount = list.get(0);
-        updateAccountStatus(rtkAccount.getId(),2);
-        redisUtil.set(redisKey,JSONObject.toJSONString(rtkAccount),60);
         modelThreshold(list.size() -1);
+
+        RtkAccount rtkAccount = null;
+        RtkUseLog rtkUseLog = rtkUseLogService.getByRtkSn(rtkSnCode);
+        if(rtkUseLog != null && rtkUseLog.getRtkAccountId() != null){
+            RtkAccount rtkAccount2 = this.getById(rtkUseLog.getRtkAccountId());
+            if(rtkAccount2 != null && rtkAccount2.getStatus() == 1){
+                rtkAccount = rtkAccount2;
+            }
+        }
+        if(rtkAccount == null){
+            rtkAccount = list.get(0);
+        }
+
+        updateAccountStatus(rtkAccount.getId(),2);
+        redisUtil.set(redisKey,JSONObject.toJSONString(rtkAccount),8 * 60 * 60);
         return rtkAccount;
     }
 
@@ -75,7 +98,22 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
         this.update(wrapper1);
     }
 
-    private void modelThreshold( int size) {
+    @Override
+    public void stop(String rtkSnCode) {
+        String redisKey = "4dkankan:rtk:snCode:"+rtkSnCode;
+        if(redisUtil.hasKey(redisKey)){
+            String jsonStr = redisUtil.get(redisKey);
+            RtkAccount rtkAccount = JSONObject.parseObject(jsonStr, RtkAccount.class);
+            updateAccountStatus(rtkAccount.getId(),1);
+            redisUtil.del(redisKey);
+        }
+    }
+
+    private void modelThreshold(int size) {
+        if(size == 0){
+            sendDingDingMsg(size);
+            return;
+        }
         BigDecimal totalCount = new BigDecimal(this.count());
         BigDecimal dbCount = new BigDecimal(size);
 
@@ -87,6 +125,9 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
     }
 
 
+    /**
+     *
+     */
     @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60)
     public void checkAccount() {
         HashMap<String,RtkAccount> map = new HashMap<>();
@@ -134,4 +175,74 @@ public class RtkAccountServiceImpl extends ServiceImpl<IRtkAccountMapper, RtkAcc
             log.info("发送钉钉消息失败:{}",e);
         }
     }
+
+
+    @Override
+    public Object pageList(RtkInfoParam param) {
+        LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
+        if(StringUtils.isNotBlank(param.getUserName())){
+            wrapper.like(RtkAccount::getUserName,param.getUserName());
+        }
+        if(StringUtils.isNotBlank(param.getStartTime())&& StringUtils.isNotBlank(param.getEndTime()) ) {
+            wrapper.between(RtkAccount::getCreateTime,param.getStartTime(),param.getEndTime());
+        }
+        wrapper.orderByDesc(RtkAccount::getCreateTime);
+        wrapper.orderByDesc(RtkAccount::getId);
+        Page<RtkAccount> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
+        Set<Long> createUserIds = page.getRecords().stream().map(RtkAccount::getCreateUserId).collect(Collectors.toSet());
+        HashMap<Long, SysUser> byIds = sysUserService.getByIds(createUserIds);
+
+        for (RtkAccount record : page.getRecords()) {
+            SysUser sysUser = byIds.get(record.getCreateUserId());
+            if(sysUser != null){
+                record.setCreateUserName(sysUser.getUserName());
+                record.setCreateNickName(sysUser.getNickName());
+            }
+        }
+        return PageInfo.PageInfo(page);
+    }
+
+    @Override
+    public void saveOrEditEntity(RtkAccount param) {
+        if(StringUtils.isBlank(param.getUserName()) || param.getPassword() == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        RtkAccount rtkAccount = this.getByUserName(param.getUserName());
+        if(rtkAccount != null && param.getId() == null){
+            throw new BusinessException(ResultCode.RTK_SN_EXIST);
+        }
+        if(rtkAccount != null && !param.getId().equals(rtkAccount.getId())){
+            throw new BusinessException(ResultCode.RTK_SN_EXIST);
+        }
+        if(param.getId()== null){
+            param.setCreateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
+        }
+        if(param.getId()!= null){
+            param.setUpdateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
+        }
+
+        this.saveOrUpdate(param);
+    }
+
+    @Override
+    public void del(RtkAccount param) {
+        if(param.getId() == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        RtkAccount rtkAccount = this.getById(param.getId());
+        if(rtkAccount != null){
+            LambdaUpdateWrapper<RtkAccount> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(RtkAccount::getId,param.getId());
+            wrapper.set(RtkAccount::getDelUserId,Long.valueOf(StpUtil.getLoginId().toString()));
+            wrapper.set(RtkAccount::getRecStatus,"I");
+            this.update(wrapper);
+        }
+    }
+
+    @Override
+    public RtkAccount getByUserName(String userName) {
+        LambdaQueryWrapper<RtkAccount> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(RtkAccount::getUserName,userName);
+        return this.getOne(wrapper);
+    }
 }

+ 122 - 0
src/main/java/com/fdkankan/manage/service/impl/RtkDeviceServiceImpl.java

@@ -1,13 +1,30 @@
 package com.fdkankan.manage.service.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fdkankan.manage.common.PageInfo;
+import com.fdkankan.manage.common.ResultCode;
+import com.fdkankan.manage.entity.RtkAccount;
 import com.fdkankan.manage.entity.RtkDevice;
+import com.fdkankan.manage.entity.RtkInfo;
+import com.fdkankan.manage.entity.SysUser;
+import com.fdkankan.manage.exception.BusinessException;
 import com.fdkankan.manage.mapper.IRtkDeviceMapper;
 import com.fdkankan.manage.service.IRtkDeviceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage.service.ISysUserService;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+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>
@@ -20,6 +37,8 @@ import java.util.List;
 @Service
 public class RtkDeviceServiceImpl extends ServiceImpl<IRtkDeviceMapper, RtkDevice> implements IRtkDeviceService {
 
+    @Autowired
+    ISysUserService sysUserService;
     @Override
     public RtkDevice getByRtkSnCode(String rtkSnCode) {
         LambdaQueryWrapper<RtkDevice> wrapper = new LambdaQueryWrapper<>();
@@ -30,4 +49,107 @@ public class RtkDeviceServiceImpl extends ServiceImpl<IRtkDeviceMapper, RtkDevic
         }
         return list.get(0);
     }
+
+    @Override
+    public Object pageList(RtkInfoParam param) {
+        LambdaQueryWrapper<RtkDevice> wrapper = new LambdaQueryWrapper<>();
+        if(StringUtils.isNotBlank(param.getRtkSnCode())){
+            wrapper.like(RtkDevice::getRtkSnCode,param.getRtkSnCode());
+        }
+        if(StringUtils.isNotBlank(param.getCameraSnCode())){
+            wrapper.like(RtkDevice::getCameraSnCode,param.getCameraSnCode());
+        }
+        if(StringUtils.isNotBlank(param.getSgRtkSn())){
+            wrapper.like(RtkDevice::getSgRtkSn,param.getSgRtkSn());
+        }
+        if(StringUtils.isNotBlank(param.getStartTime())&& StringUtils.isNotBlank(param.getEndTime()) ) {
+            wrapper.between(RtkDevice::getCreateTime,param.getStartTime(),param.getEndTime());
+        }
+        wrapper.orderByDesc(RtkDevice::getCreateTime);
+        wrapper.orderByDesc(RtkDevice::getId);
+        Page<RtkDevice> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
+        Set<Long> createUserIds = page.getRecords().stream().map(RtkDevice::getCreateUserId).collect(Collectors.toSet());
+        HashMap<Long, SysUser> byIds = sysUserService.getByIds(createUserIds);
+
+        for (RtkDevice record : page.getRecords()) {
+            SysUser sysUser = byIds.get(record.getCreateUserId());
+            if(sysUser != null){
+                record.setCreateUserName(sysUser.getUserName());
+                record.setCreateNickName(sysUser.getNickName());
+            }
+        }
+        return PageInfo.PageInfo(page);
+    }
+
+    @Override
+    public void saveOrEditEntity(RtkDevice param) {
+        if(StringUtils.isBlank(param.getRtkSnCode()) || param.getRtkType() == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        RtkDevice rtkDevice = this.getByRtkSnCode(param.getRtkSnCode());
+        if(rtkDevice != null && param.getId() == null){
+            throw new BusinessException(ResultCode.RTK_SN_EXIST);
+        }
+        if(rtkDevice != null && !param.getId().equals(rtkDevice.getId())){
+            throw new BusinessException(ResultCode.RTK_SN_EXIST);
+        }
+        RtkDevice  rtkDevice2 = null;
+        if(StringUtils.isNotBlank(param.getSgRtkSn())){
+            rtkDevice2 = this.getSgRtkSn(param.getSgRtkSn());
+        }
+        if(rtkDevice2 != null && param.getId() == null){
+            throw new BusinessException(ResultCode.SGRTK_SN_EXIST);
+        }
+        if(rtkDevice2 != null && !param.getId().equals(rtkDevice2.getId())){
+            throw new BusinessException(ResultCode.SGRTK_SN_EXIST);
+        }
+        RtkDevice  rtkDevice3 = null;
+        if(StringUtils.isNotBlank(param.getCameraSnCode())){
+            rtkDevice3 = this.getByCameraSn(param.getCameraSnCode());
+        }
+        if(rtkDevice3 != null && param.getId() == null){
+            throw new BusinessException(ResultCode.CAMERA_SN_EXIST);
+        }
+        if(rtkDevice3 != null && !param.getId().equals(rtkDevice3.getId())){
+            throw new BusinessException(ResultCode.CAMERA_SN_EXIST);
+        }
+        if(param.getId()== null){
+            param.setCreateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
+        }
+        if(param.getId()!= null){
+            param.setUpdateUserId(Long.valueOf(StpUtil.getLoginId().toString()));
+        }
+        this.saveOrUpdate(param);
+    }
+
+    @Override
+    public void del(RtkDevice param) {
+        if(param.getId() == null){
+            throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
+        }
+        RtkDevice rtkDevice = this.getById(param.getId());
+        if(rtkDevice != null){
+            LambdaUpdateWrapper<RtkDevice> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(RtkDevice::getId,param.getId());
+            wrapper.set(RtkDevice::getDelUserId,Long.valueOf(StpUtil.getLoginId().toString()));
+            wrapper.set(RtkDevice::getRecStatus,"I");
+            this.update(wrapper);
+        }
+
+    }
+
+
+    @Override
+    public RtkDevice getSgRtkSn(String sgRtkSn) {
+        LambdaQueryWrapper<RtkDevice> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(RtkDevice::getSgRtkSn,sgRtkSn);
+        return this.getOne(wrapper);
+    }
+
+    @Override
+    public RtkDevice getByCameraSn(String cameraSnCode) {
+        LambdaQueryWrapper<RtkDevice> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(RtkDevice::getCameraSnCode,cameraSnCode);
+        return this.getOne(wrapper);
+    }
 }

+ 43 - 1
src/main/java/com/fdkankan/manage/service/impl/RtkUseLogServiceImpl.java

@@ -1,13 +1,24 @@
 package com.fdkankan.manage.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fdkankan.manage.common.PageInfo;
 import com.fdkankan.manage.entity.RtkInfo;
 import com.fdkankan.manage.entity.RtkUseLog;
+import com.fdkankan.manage.entity.SysUser;
 import com.fdkankan.manage.mapper.IRtkUseLogMapper;
 import com.fdkankan.manage.service.IRtkUseLogService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage.vo.request.RtkInfoParam;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  *  服务实现类
@@ -20,7 +31,7 @@ import org.springframework.stereotype.Service;
 public class RtkUseLogServiceImpl extends ServiceImpl<IRtkUseLogMapper, RtkUseLog> implements IRtkUseLogService {
 
     @Override
-    public void saveLog(RtkInfo rtkInfo, String clientIP) {
+    public void saveLog(RtkInfo rtkInfo, String clientIP,Integer rtkAccountId) {
         RtkUseLog rtkUseLog = new RtkUseLog();
         BeanUtils.copyProperties(rtkInfo,rtkUseLog);
         rtkUseLog.setId(null);
@@ -28,6 +39,37 @@ public class RtkUseLogServiceImpl extends ServiceImpl<IRtkUseLogMapper, RtkUseLo
         rtkUseLog.setUpdateTime(null);
         rtkUseLog.setVisitIp(clientIP);
         rtkUseLog.setType(rtkInfo.getRtkType());
+        rtkUseLog.setRtkAccountId(rtkAccountId);
         this.save(rtkUseLog);
     }
+
+    @Override
+    public RtkUseLog getByRtkSn(String rtkSnCode) {
+        LambdaQueryWrapper<RtkUseLog> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(RtkUseLog::getRtkSnCode,rtkSnCode);
+        wrapper.orderByDesc(RtkUseLog::getId);
+        List<RtkUseLog> list = this.list(wrapper);
+        if(list != null && !list.isEmpty()){
+            return list.get(0);
+        }
+        return null;
+    }
+
+    @Override
+    public Object pageList(RtkInfoParam param) {
+        LambdaQueryWrapper<RtkUseLog> wrapper = new LambdaQueryWrapper<>();
+        if(StringUtils.isNotBlank(param.getRtkSnCode())){
+            wrapper.like(RtkUseLog::getRtkSnCode,param.getRtkSnCode());
+        }
+        if(StringUtils.isNotBlank(param.getUserName())){
+            wrapper.like(RtkUseLog::getUserName,param.getUserName());
+        }
+        if(StringUtils.isNotBlank(param.getStartTime())&& StringUtils.isNotBlank(param.getEndTime()) ) {
+            wrapper.between(RtkUseLog::getCreateTime,param.getStartTime(),param.getEndTime());
+        }
+        wrapper.orderByDesc(RtkUseLog::getCreateTime);
+        wrapper.orderByDesc(RtkUseLog::getId);
+        Page<RtkUseLog> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
+        return PageInfo.PageInfo(page);
+    }
 }