lyhzzz vor 9 Monaten
Ursprung
Commit
705864a2da

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

@@ -1,6 +1,8 @@
 package com.fdkankan.manage_jp.common;
 
 
+import com.fdkankan.common.constant.ErrorCode;
+
 public enum ResultCode  {
     SYSTEM_ERROR(500, "系统异常"),
 
@@ -49,6 +51,7 @@ public enum ResultCode  {
 
     SCENE_NOT_EXIST_E57(5030, "场景不存在e57文件"),
     SCENE_NOT_GPS(5031, "此场景无位置信息,无法在地图显示。"),
+    PLATFORM_NOT_EXIT(5032, "平台不存在。"),
 
 
     ;

+ 36 - 0
src/main/java/com/fdkankan/manage_jp/controller/PlatformController.java

@@ -0,0 +1,36 @@
+package com.fdkankan.manage_jp.controller;
+
+
+import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
+import com.fdkankan.manage_jp.common.Result;
+import com.fdkankan.manage_jp.service.IPlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@RestController
+@RequestMapping("/manage_jp/platform")
+public class PlatformController {
+
+    @Autowired
+    IPlatformService platformService;
+
+    @GetMapping("/listAll")
+    public Result listAll(){
+        return Result.success(platformService.list());
+    }
+
+}
+

+ 36 - 0
src/main/java/com/fdkankan/manage_jp/controller/UserPlatformController.java

@@ -0,0 +1,36 @@
+package com.fdkankan.manage_jp.controller;
+
+
+import com.fdkankan.manage_jp.common.Result;
+import com.fdkankan.manage_jp.service.IUserPlatformService;
+import com.fdkankan.manage_jp.vo.request.GivePlatformAuthParam;
+import com.fdkankan.manage_jp.vo.request.UserParam;
+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;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@RestController
+@RequestMapping("/manage_jp/userPlatform")
+public class UserPlatformController {
+
+    @Autowired
+    IUserPlatformService userPlatformService;
+
+    @PostMapping("/givePlatformAuth")
+    public Result givePlatformAuth(@RequestBody GivePlatformAuthParam param){
+        userPlatformService.givePlatformAuth(param);
+        return Result.success();
+    }
+}
+

+ 48 - 0
src/main/java/com/fdkankan/manage_jp/entity/Platform.java

@@ -0,0 +1,48 @@
+package com.fdkankan.manage_jp.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Getter
+@Setter
+@TableName("t_platform")
+public class Platform implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("name")
+    private String name;
+
+    @TableField("key")
+    private String key;
+
+    @TableField("rec_status")
+    @TableLogic(value = "A",delval = "I")
+    private String recStatus;
+
+    @TableField("create_time")
+    private Date createTime;
+
+    @TableField("update_time")
+    private Date updateTime;
+
+
+}

+ 51 - 0
src/main/java/com/fdkankan/manage_jp/entity/UserPlatform.java

@@ -0,0 +1,51 @@
+package com.fdkankan.manage_jp.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Getter
+@Setter
+@TableName("t_user_platform")
+public class UserPlatform implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("user_id")
+    private Integer userId;
+
+    @TableField("platform_key")
+    private String platformKey;
+
+    @TableField("create_time")
+    private Date createTime;
+
+    @TableField("update_time")
+    private Date updateTime;
+
+    @TableField("rec_status")
+    @TableLogic(value = "A",delval = "I")
+    private String recStatus;
+
+    @TableField("platform_id")
+    private Integer platformId;
+
+
+}

+ 1 - 1
src/main/java/com/fdkankan/manage_jp/generate/AutoGenerate.java

@@ -18,7 +18,7 @@ public class AutoGenerate {
         String path =System.getProperty("user.dir");
 
         generate(path,"manage_jp", getTables(new String[]{
-              "t_project_scene_gps"
+              "t_platform","t_user_platform"
         }));
 
 //        generate(path,"goods", getTables(new String[]{

+ 18 - 0
src/main/java/com/fdkankan/manage_jp/mapper/IPlatformMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.manage_jp.mapper;
+
+import com.fdkankan.manage_jp.entity.Platform;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Mapper
+public interface IPlatformMapper extends BaseMapper<Platform> {
+
+}

+ 18 - 0
src/main/java/com/fdkankan/manage_jp/mapper/IUserPlatformMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.manage_jp.mapper;
+
+import com.fdkankan.manage_jp.entity.UserPlatform;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Mapper
+public interface IUserPlatformMapper extends BaseMapper<UserPlatform> {
+
+}

+ 16 - 0
src/main/java/com/fdkankan/manage_jp/service/IPlatformService.java

@@ -0,0 +1,16 @@
+package com.fdkankan.manage_jp.service;
+
+import com.fdkankan.manage_jp.entity.Platform;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+public interface IPlatformService extends IService<Platform> {
+
+}

+ 18 - 0
src/main/java/com/fdkankan/manage_jp/service/IUserPlatformService.java

@@ -0,0 +1,18 @@
+package com.fdkankan.manage_jp.service;
+
+import com.fdkankan.manage_jp.entity.UserPlatform;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.manage_jp.vo.request.GivePlatformAuthParam;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+public interface IUserPlatformService extends IService<UserPlatform> {
+
+    void givePlatformAuth(GivePlatformAuthParam param);
+}

+ 20 - 0
src/main/java/com/fdkankan/manage_jp/service/impl/PlatformServiceImpl.java

@@ -0,0 +1,20 @@
+package com.fdkankan.manage_jp.service.impl;
+
+import com.fdkankan.manage_jp.entity.Platform;
+import com.fdkankan.manage_jp.mapper.IPlatformMapper;
+import com.fdkankan.manage_jp.service.IPlatformService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Service
+public class PlatformServiceImpl extends ServiceImpl<IPlatformMapper, Platform> implements IPlatformService {
+
+}

+ 75 - 0
src/main/java/com/fdkankan/manage_jp/service/impl/UserPlatformServiceImpl.java

@@ -0,0 +1,75 @@
+package com.fdkankan.manage_jp.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.manage_jp.common.ResultCode;
+import com.fdkankan.manage_jp.entity.Platform;
+import com.fdkankan.manage_jp.entity.UserPlatform;
+import com.fdkankan.manage_jp.exception.BusinessException;
+import com.fdkankan.manage_jp.mapper.IUserPlatformMapper;
+import com.fdkankan.manage_jp.service.IPlatformService;
+import com.fdkankan.manage_jp.service.IUserPlatformService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.manage_jp.vo.request.GivePlatformAuthParam;
+import com.fdkankan.manage_jp.vo.request.UserParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 
+ * @since 2024-11-19
+ */
+@Service
+public class UserPlatformServiceImpl extends ServiceImpl<IUserPlatformMapper, UserPlatform> implements IUserPlatformService {
+
+    @Autowired
+    IPlatformService platformService;
+    @Override
+    public void givePlatformAuth(GivePlatformAuthParam param) {
+        if(param.getUserId() == null ){
+            throw new BusinessException(ResultCode.PARAM_ERROR);
+        }
+        List<UserPlatform> userPlatforms = this.getByUserId(param.getUserId());
+        List<Integer> dbIds = userPlatforms.stream().map(UserPlatform::getPlatformId).collect(Collectors.toList());
+        List<Integer> addIds = param.getPlatformIds().stream().filter(e -> !dbIds.contains(e)).collect(Collectors.toList());
+        List<Integer> delIds = dbIds.stream().filter(e -> !param.getPlatformIds().contains(e)).collect(Collectors.toList());
+
+        this.saveByPlatformIds(param.getUserId(),addIds);
+        this.delByPlatformIds(param.getUserId(),delIds);
+
+    }
+
+    private void delByPlatformIds(Integer userId,List<Integer> delIds) {
+        LambdaQueryWrapper<UserPlatform> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(UserPlatform::getUserId,userId);
+        wrapper.in(UserPlatform::getPlatformId,delIds);
+        this.remove(wrapper);
+    }
+
+    private void saveByPlatformIds(Integer userId,List<Integer> addIds) {
+        for (Integer addId : addIds) {
+            Platform platform = platformService.getById(addId);
+            if(platform != null){
+                UserPlatform userPlatform = new UserPlatform();
+                userPlatform.setUserId(userId);
+                userPlatform.setPlatformKey(platform.getKey());
+                userPlatform.setPlatformId(platform.getId());
+                this.save(userPlatform);
+            }
+        }
+    }
+
+    private List<UserPlatform> getByUserId(Integer userId) {
+        LambdaQueryWrapper<UserPlatform> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(UserPlatform::getUserId,userId);
+        return this.list(wrapper);
+    }
+}

+ 12 - 0
src/main/java/com/fdkankan/manage_jp/vo/request/GivePlatformAuthParam.java

@@ -0,0 +1,12 @@
+package com.fdkankan.manage_jp.vo.request;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class GivePlatformAuthParam {
+    private Integer userId;
+    private List<Integer> platformIds = new ArrayList<>();
+}

+ 5 - 0
src/main/resources/mapper/manage_jp/PlatformMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fdkankan.manage_jp.mapper.IPlatformMapper">
+
+</mapper>

+ 5 - 0
src/main/resources/mapper/manage_jp/UserPlatformMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fdkankan.manage_jp.mapper.IUserPlatformMapper">
+
+</mapper>