Sfoglia il codice sorgente

网络泵wifi注册基础服务

Your Name 1 anno fa
parent
commit
f8716836a7

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 19 - 0
.idea/compiler.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <annotationProcessing>
+      <profile default="true" name="Default" enabled="true" />
+      <profile name="Maven default annotation processors profile" enabled="true">
+        <sourceOutputDir name="target/generated-sources/annotations" />
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+        <outputRelativeToContentRoot value="true" />
+        <module name="forward" />
+      </profile>
+    </annotationProcessing>
+  </component>
+  <component name="JavacSettings">
+    <option name="ADDITIONAL_OPTIONS_OVERRIDE">
+      <module name="forward" options="-parameters" />
+    </option>
+  </component>
+</project>

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+  </component>
+</project>

+ 20 - 0
.idea/jarRepositories.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RemoteRepositoriesConfiguration">
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="jboss.community" />
+      <option name="name" value="JBoss Community repository" />
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Central Repository" />
+      <option name="url" value="https://maven.aliyun.com/repository/public" />
+    </remote-repository>
+  </component>
+</project>

+ 12 - 0
.idea/misc.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 96 - 0
src/main/java/com/tuoren/forward/controller/UserConfigController.java

@@ -0,0 +1,96 @@
+package com.tuoren.forward.controller;
+
+import com.github.pagehelper.util.StringUtil;
+import com.tuoren.forward.constant.CommonConstant;
+import com.tuoren.forward.entity.UserConfig;
+import com.tuoren.forward.entity.req.IdReq;
+import com.tuoren.forward.service.UserConfigService;
+import com.tuoren.forward.util.Result;
+import com.tuoren.forward.util.ResultData;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+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.ResponseBody;
+
+
+/**
+ * @Author zzy
+ * @Data 2024/9/19
+ * @Version 1.0
+ * @Description XXX
+ */
+@Slf4j
+@Controller
+@RequestMapping("userConfig")
+@Tag(name="用户配置接口")
+public class UserConfigController {
+    @Autowired
+    UserConfigService userConfigService;
+
+    /**
+     * 根据id获取wifi配置信息
+     * @param req
+     * @return
+     */
+    @PostMapping("detailById")
+    @ResponseBody
+    @Operation(summary = "根据用户获取WIFI配置详情")
+    @Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+    public ResultData<UserConfig> detailById(@RequestBody IdReq req){
+        log.info("detailByUserId>>:{}",req);
+       return userConfigService.selectByUserId(req.getId());
+    }
+
+    /**
+     * 添加
+     * @param req
+     * @return
+     */
+    @PostMapping("add")
+    @ResponseBody
+    @Operation(summary = "添加用户配置表")
+    @Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+    public Result add(@RequestBody UserConfig req) throws  Exception{
+        log.info("addUserConfig>>:{}",req);
+        return userConfigService.add(req);
+    }
+
+    /**
+     * 根据id进行删除
+     * @param req
+     * @return
+     */
+    @PostMapping("delete")
+    @ResponseBody
+    @Operation(summary = "删除用户配置")
+    @Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+    public Result delete(@RequestBody IdReq req){
+        log.info("deleteUserConfig>>:{}",req);
+        return userConfigService.delete(req.getId());
+    }
+
+    /**
+     * 根据用户id进行修改
+     * @param req
+     * @return
+     */
+    @PostMapping("update")
+    @ResponseBody
+    @Operation(summary = "修改用户配置表")
+    @Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+    public Result edit(@RequestBody UserConfig req){
+        log.info("updateUserConfig>>:{}",req);
+        if(StringUtil.isEmpty(req.getId())) {
+            return Result.fail(CommonConstant.LACK_PARAM);
+        }
+        return userConfigService.edit(req);
+    }
+
+}

+ 13 - 7
src/main/java/com/tuoren/forward/entity/UserConfig.java

@@ -1,25 +1,31 @@
 package com.tuoren.forward.entity;
 
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.tuoren.forward.util.WifiListDeserializer;
 import io.swagger.v3.oas.annotations.media.Schema;
-import java.util.Date;
 import lombok.Data;
 
+import java.util.Date;
+
 @Data
 @Schema(description = "用户配置表")
 public class UserConfig {
+    @Schema(description = "用户ID")
     private String id;
 
-    @Schema(description = "用户id")
-    private String userId;
+    @Schema(description = "wifi信息:[{“name”:'tuoren1',“password”:'12345678'},{},{},...]")
+    @JsonDeserialize(using = WifiListDeserializer.class)
+    private String wifi;
 
-    @Schema(description = "wifi账号")
-    private String wifiName;
+    @Schema(description = "医院数据对接服务地址")
+    private String localAddress;
 
-    private String wifiPassword;
+    @Schema(description = "医院数据对接服务端口")
+    private Integer localPort;
 
     @Schema(description = "创建时间")
     private Date createtime;
 
     @Schema(description = "修改时间")
-    private String modifytime;
+    private Date modifytime;
 }

+ 1 - 1
src/main/java/com/tuoren/forward/entity/req/LoginReq.java

@@ -15,7 +15,7 @@ public class LoginReq {
     
     @Schema(description = "验证码")
     private String captchaCode;
-    
+
     @Schema(description = "验证码键值")
     private String captchaKey;
     

+ 2 - 0
src/main/java/com/tuoren/forward/mapper/UserConfigMapper.java

@@ -14,4 +14,6 @@ public interface UserConfigMapper {
     int updateByPrimaryKeySelective(UserConfig row);
 
     int updateByPrimaryKey(UserConfig row);
+
+
 }

+ 79 - 0
src/main/java/com/tuoren/forward/service/UserConfigService.java

@@ -0,0 +1,79 @@
+package com.tuoren.forward.service;
+
+import com.tuoren.forward.constant.CommonConstant;
+import com.tuoren.forward.entity.UserConfig;
+import com.tuoren.forward.mapper.UserConfigMapper;
+import com.tuoren.forward.util.AccessTokenUtil;
+import com.tuoren.forward.util.Result;
+import com.tuoren.forward.util.ResultData;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+
+/**
+ * @Author zzy
+ * @Data 2024/9/19
+ * @Version 1.0
+ * @Description XXX
+ */
+@Service
+public class UserConfigService {
+    @Autowired
+    UserConfigMapper userConfigMapper;
+
+    public ResultData<UserConfig> selectByUserId(String id) {
+        UserConfig userConfig = userConfigMapper.selectByPrimaryKey(id);
+        return ResultData.success(userConfig);
+    }
+
+    public Result add(UserConfig req) {
+
+        String userId = AccessTokenUtil.getUserId();
+        Date date = new Date();
+        req.setId(userId);
+        req.setCreatetime(date);
+        userConfigMapper.insert(req);
+        return Result.success();
+    }
+//public ResultData<UserConfig> add(UserConfigAddReq req) {
+//
+//    UserConfig userConfig = new UserConfig();
+//    BeanUtils.copyProperties(req, userConfig);
+//    String userId = AccessTokenUtil.getUserId();
+//    if (StringUtils.isEmpty(req.getId())){
+//        req.setId(userId);
+//    }else {
+//        UserConfig config = userConfigMapper.selectByPrimaryKey(req.getId());
+//        if (config != null){
+//            return ResultData.failNull("用户id存在");
+//        }
+//    }
+//   UserConfig existUserConfig = userConfigMapper.selectOneOr(userConfig.getWifi(),userConfig.getLocalAddress(),userConfig.getLocalPort());
+//    if (existUserConfig == null){
+//        userConfig.setCreatetime(new Date());
+//        userConfigMapper.insertSelective(userConfig);
+//    }
+//    return ResultData.success(userConfig);
+//}
+
+    public Result delete(String id) {
+        if (StringUtils.isEmpty(id)){
+            return ResultData.fail(CommonConstant.LACK_PARAM);
+        }
+        userConfigMapper.deleteByPrimaryKey(id);
+        return Result.success();
+
+    }
+
+    public Result edit(UserConfig req) {
+        Date date = new Date();
+        req.setModifytime(date);
+        userConfigMapper.updateByPrimaryKeySelective(req);
+        return Result.success();
+
+    }
+
+
+}

+ 41 - 0
src/main/java/com/tuoren/forward/util/WifiListDeserializer.java

@@ -0,0 +1,41 @@
+package com.tuoren.forward.util;
+
+import com.fasterxml.jackson.core.JacksonException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * @Author zzy
+ * @Data 2024/9/19
+ * @Version 1.0
+ * @Description XXX
+ */
+public class WifiListDeserializer extends JsonDeserializer<String>{
+    @Override
+    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
+        ObjectMapper mapper = (ObjectMapper) p.getCodec();
+        JsonNode node = mapper.readTree(p);
+
+        StringBuilder wifiStringBuilder = new StringBuilder();
+
+        if (node.isArray()) {
+            for (Iterator<JsonNode> it = node.elements(); it.hasNext(); ) {
+                JsonNode wifiNode = it.next();
+                String name = wifiNode.get("name").asText();
+                String password = wifiNode.get("password").asText();
+                wifiStringBuilder.append("{\"name\":\"").append(name).append("\",\"password\":\"").append(password).append("\"}");
+                if (it.hasNext()) {
+                    wifiStringBuilder.append(",");
+                }
+            }
+        }
+
+        return "[" + wifiStringBuilder.toString() + "]";
+    }
+}

+ 40 - 33
src/main/resources/mapper/UserConfigMapper.xml

@@ -3,14 +3,14 @@
 <mapper namespace="com.tuoren.forward.mapper.UserConfigMapper">
   <resultMap id="BaseResultMap" type="com.tuoren.forward.entity.UserConfig">
     <id column="id" jdbcType="VARCHAR" property="id" />
-    <result column="user_id" jdbcType="VARCHAR" property="userId" />
-    <result column="wifi_name" jdbcType="VARCHAR" property="wifiName" />
-    <result column="wifi_password" jdbcType="VARCHAR" property="wifiPassword" />
+    <result column="wifi" jdbcType="VARCHAR" property="wifi" />
+    <result column="local_address" jdbcType="VARCHAR" property="localAddress" />
+    <result column="local_port" jdbcType="INTEGER" property="localPort" />
     <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
-    <result column="modifytime" jdbcType="VARCHAR" property="modifytime" />
+    <result column="modifytime" jdbcType="TIMESTAMP" property="modifytime" />
   </resultMap>
   <sql id="Base_Column_List">
-    id, user_id, wifi_name, wifi_password, createtime, modifytime
+    id, wifi, local_address, local_port, createtime, modifytime
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
     select 
@@ -23,11 +23,11 @@
     where id = #{id,jdbcType=VARCHAR}
   </delete>
   <insert id="insert" parameterType="com.tuoren.forward.entity.UserConfig">
-    insert into user_config (id, user_id, wifi_name, 
-      wifi_password, createtime, modifytime
+    insert into user_config (id, wifi, local_address, 
+      local_port, createtime, modifytime
       )
-    values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{wifiName,jdbcType=VARCHAR}, 
-      #{wifiPassword,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=VARCHAR}
+    values (#{id,jdbcType=VARCHAR}, #{wifi,jdbcType=VARCHAR}, #{localAddress,jdbcType=VARCHAR}, 
+      #{localPort,jdbcType=INTEGER}, #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=TIMESTAMP}
       )
   </insert>
   <insert id="insertSelective" parameterType="com.tuoren.forward.entity.UserConfig">
@@ -36,14 +36,14 @@
       <if test="id != null">
         id,
       </if>
-      <if test="userId != null">
-        user_id,
+      <if test="wifi != null">
+        wifi,
       </if>
-      <if test="wifiName != null">
-        wifi_name,
+      <if test="localAddress != null">
+        local_address,
       </if>
-      <if test="wifiPassword != null">
-        wifi_password,
+      <if test="localPort != null">
+        local_port,
       </if>
       <if test="createtime != null">
         createtime,
@@ -56,51 +56,58 @@
       <if test="id != null">
         #{id,jdbcType=VARCHAR},
       </if>
-      <if test="userId != null">
-        #{userId,jdbcType=VARCHAR},
+      <if test="wifi != null">
+        #{wifi,jdbcType=VARCHAR},
       </if>
-      <if test="wifiName != null">
-        #{wifiName,jdbcType=VARCHAR},
+      <if test="localAddress != null">
+        #{localAddress,jdbcType=VARCHAR},
       </if>
-      <if test="wifiPassword != null">
-        #{wifiPassword,jdbcType=VARCHAR},
+      <if test="localPort != null">
+        #{localPort,jdbcType=INTEGER},
       </if>
       <if test="createtime != null">
         #{createtime,jdbcType=TIMESTAMP},
       </if>
       <if test="modifytime != null">
-        #{modifytime,jdbcType=VARCHAR},
+        #{modifytime,jdbcType=TIMESTAMP},
       </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.tuoren.forward.entity.UserConfig">
     update user_config
     <set>
-      <if test="userId != null">
-        user_id = #{userId,jdbcType=VARCHAR},
+      <if test="wifi != null">
+        wifi = #{wifi,jdbcType=VARCHAR},
       </if>
-      <if test="wifiName != null">
-        wifi_name = #{wifiName,jdbcType=VARCHAR},
+      <if test="localAddress != null">
+        local_address = #{localAddress,jdbcType=VARCHAR},
       </if>
-      <if test="wifiPassword != null">
-        wifi_password = #{wifiPassword,jdbcType=VARCHAR},
+      <if test="localPort != null">
+        local_port = #{localPort,jdbcType=INTEGER},
       </if>
       <if test="createtime != null">
         createtime = #{createtime,jdbcType=TIMESTAMP},
       </if>
       <if test="modifytime != null">
-        modifytime = #{modifytime,jdbcType=VARCHAR},
+        modifytime = #{modifytime,jdbcType=TIMESTAMP},
       </if>
     </set>
     where id = #{id,jdbcType=VARCHAR}
   </update>
   <update id="updateByPrimaryKey" parameterType="com.tuoren.forward.entity.UserConfig">
     update user_config
-    set user_id = #{userId,jdbcType=VARCHAR},
-      wifi_name = #{wifiName,jdbcType=VARCHAR},
-      wifi_password = #{wifiPassword,jdbcType=VARCHAR},
+    set wifi = #{wifi,jdbcType=VARCHAR},
+      local_address = #{localAddress,jdbcType=VARCHAR},
+      local_port = #{localPort,jdbcType=INTEGER},
       createtime = #{createtime,jdbcType=TIMESTAMP},
-      modifytime = #{modifytime,jdbcType=VARCHAR}
+      modifytime = #{modifytime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=VARCHAR}
   </update>
+
+  <select id="selectOneOr" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from user_config
+    where wifi = #{wifi,jdbcType=VARCHAR} or  local_address = #{localAddress,jdbcType=VARCHAR} or local_port = #{localPort,jdbcType=INTEGER}, limit 1
+    </select>
 </mapper>