管道基础大数据平台系统开发-【后端】-Server
1
Surpriseplus
2022-09-28 37f3afebbec6b60aacc1d87363f59f5d1aa5fe68
1
已添加4个文件
已修改1个文件
375 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/TokenController.java 192 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/data/ResEntity.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/TokenMapper.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/TokenService.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/TokenMapper.xml 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/TokenController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,192 @@
package com.lf.server.controller.data;
import com.lf.server.controller.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.data.DictEntity;
import com.lf.server.entity.data.TokenEntity;
import com.lf.server.service.data.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * ä»¤ç‰Œè¡¨
 * @author  sws
 * @date 2022-09-28
 */
@Api(tags = "令牌管理")
@RestController
@RequestMapping("/token")
public class TokenController extends BaseController {
   @Autowired
   TokenService tokenService;
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", required = false, example = "sys_token")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String token) {
        try {
            int count = tokenService.selectCount(token);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = "sys_token"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPage")
    public ResponseMsg<List<TokenEntity>> selectByPage(String token, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<TokenEntity> rs = tokenService.selectByPage(token, pageSize, pageSize * (pageIndex - 1));
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @ApiOperation(value = "分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = "sys_token"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectByPageAndCount")
    public ResponseMsg<List<TokenEntity>> selectByPageAndCount(String token, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = tokenService.selectCount(token);
            if (count == 0) {
                return success(0, null);
            }
            List<TokenEntity> rs = tokenService.selectByPage(token, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @ApiOperation(value = "插入字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tokenEntity", value = "字典实体类", dataType = "com.lf.server.entity.data.TokenEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertToken", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertToken(TokenEntity tokenEntity) {
        try {
            int count = tokenService.insertToken(tokenEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "插入多条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tokenEntity", value = "字典实体类集合", dataType = "List<TokenEntity>", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertTokens", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertTokens(@RequestBody List<TokenEntity> tokenEntity) {
        try {
            int count = tokenService.insertTokens(tokenEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "删除一条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/deleteToken")
    public ResponseMsg<Integer> deleteToken(int id) {
        try {
            int count = tokenService.deleteToken(id);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "删除多条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "字典ID集合", dataType = "List<Integer>", paramType = "query", example = "1,2")
    })
    @GetMapping(value = "/deleteTokens")
    public ResponseMsg<Integer> deleteTokens(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = tokenService.deleteTokens(ids);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "更新一条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tokenEntity", value = "字典ID集合", dataType = "TokenEntity", paramType = "body", example = "")
    })
    @ResponseBody
    @PostMapping(value = "/updateToken", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateToken(TokenEntity tokenEntity) {
        try {
            int count = tokenService.updateToken(tokenEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @ApiOperation(value = "根据ID查询字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectToken")
    public ResponseMsg<TokenEntity> selectToken(int id) {
        try {
            TokenEntity tokenEntity = tokenService.selectToken(id);
            return success(tokenEntity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @ApiOperation(value = "查询所有字典")
    @GetMapping(value = "/selectTokenAll")
    public ResponseMsg<List<TokenEntity>> selectTokenAll() {
        try {
            List<TokenEntity> list = tokenService.selectTokenAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
}
src/main/java/com/lf/server/entity/data/ResEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,10 @@
package com.lf.server.entity.data;
import java.io.Serializable;
/**
 * @author user
 */
public class ResEntity implements Serializable {
}
src/main/java/com/lf/server/mapper/data/TokenMapper.java
@@ -2,6 +2,7 @@
import com.lf.server.entity.data.DictEntity;
import com.lf.server.entity.data.TokenEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -19,36 +20,34 @@
    /**
     * æ ¹æ®è¡¨åæŸ¥è¯¢è®°å½•æ•°
     *
     * @param tab è¡¨å
     * @param token è¡¨å
     * @return è®°å½•æ•°
     */
    public Integer selectCount(String tab);
    public Integer selectCount(String token);
    /**
     * æ ¹æ®è¡¨ååˆ†é¡µæŸ¥è¯¢
     *
     * @param tab    è¡¨å
     * @param token    è¡¨å
     * @param limit  è®°å½•表
     * @param offset åç§»é‡
     * @return åˆ—表
     */
    public List<DictEntity> selectByPage(String tab, Integer limit, Integer offset);
    public List<TokenEntity> selectByPage(String token, Integer limit, Integer offset);
    /**
     * æ·»åŠ æ•°æ®
     *
     * @param dictEntity
     * @param tokenEntity
     * @return
     */
    public Integer insertDict(DictEntity dictEntity);
    public Integer insertToken(TokenEntity tokenEntity);
    /**
     * æ‰¹é‡æ·»åŠ 
     *
     * @param dictEntity
     * @param tokenEntity
     * @return
     */
    public Integer insertDicts(List<DictEntity> dictEntity);
    public Integer insertTokens(List<TokenEntity> tokenEntity);
    /**
     * åˆªé™¤æ•°æ®
@@ -56,7 +55,7 @@
     * @param id
     * @return
     */
    public Integer deleteDict(int id);
    public Integer deleteToken(int id);
    /**
     * æ‰¹é‡åˆ é™¤
@@ -64,30 +63,27 @@
     * @param ids
     * @return
     */
    public Integer deleteDicts(List<Integer> ids);
    public Integer deleteTokens(List<Integer> ids);
    /**
     * ä¿®æ”¹æ•°æ®
     *
     * @param dictEntity
     * @param tokenEntity
     * @return
     */
    public Integer updateDict(DictEntity dictEntity);
    public Integer updateToken(TokenEntity tokenEntity);
    /**
     * æŸ¥è¯¢å•条数据
     *
     * @param id
     * @return
     */
    public DictEntity selectDict(int id);
    public TokenEntity selectToken(int id);
    /**
     * æŸ¥è¯¢å…¨éƒ¨æ•°æ®
     *
     * @return
     */
    public List<DictEntity> selectDictAll();
    public List<TokenEntity> selectTokenAll();
src/main/java/com/lf/server/service/data/TokenService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,66 @@
package com.lf.server.service.data;
import com.lf.server.entity.data.TokenEntity;
import com.lf.server.mapper.data.TokenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * ä»¤ç‰Œè¡¨
 * @author sws
 * @date 2022-09-28
 */
@Service
public class TokenService implements TokenMapper {
    @Autowired
    TokenMapper tokenMapper;
    @Override
    public Integer selectCount(String token) {
        return tokenMapper.selectCount(token);
    }
    @Override
    public List<TokenEntity> selectByPage(String token, Integer limit, Integer offset) {
        return tokenMapper.selectByPage(token,limit,offset);
    }
    @Override
    public Integer insertToken(TokenEntity tokenEntity) {
        return tokenMapper.insertToken(tokenEntity);
    }
    @Override
    public Integer insertTokens(List<TokenEntity> tokenEntity) {
        return tokenMapper.insertTokens(tokenEntity);
    }
    @Override
    public Integer deleteToken(int id) {
        return tokenMapper.deleteToken(id);
    }
    @Override
    public Integer deleteTokens(List<Integer> ids) {
        return tokenMapper.deleteTokens(ids);
    }
    @Override
    public Integer updateToken(TokenEntity tokenEntity) {
        return tokenMapper.updateToken(tokenEntity);
    }
    @Override
    public TokenEntity selectToken(int id) {
        return tokenMapper.selectToken(id);
    }
    @Override
    public List<TokenEntity> selectTokenAll() {
        return tokenMapper.selectTokenAll();
    }
}
src/main/resources/mapper/data/TokenMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
<?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.lf.server.mapper.data.TokenMapper">
    <resultMap id="resultMap" type="com.lf.server.entity.data.TokenEntity">
        <id property="id" column="id"></id>
        <result property="createUser" column="create_user"></result>
        <result property="createTime" column="create_time"></result>
        <result property="updateUser" column="update_user"></result>
        <result property="updateTime" column="update_time"></result>
    </resultMap>
    <!-- ç»Ÿè®¡è¡Œæ•° -->
    <select id="selectCount" resultType="java.lang.Integer" parameterType="java.lang.String">
        select count(*) from lf.sys_token
        <where>
            <if test="token != null">
                token = #{token}
            </if>
        </where>
    </select>
    <!-- åˆ†é¡µæŸ¥è¯¢ -->
    <select id="selectByPage" resultMap="resultMap" resultType="com.lf.server.entity.data.TokenEntity">
        select * from lf.sys_token
        <where>
            <if test="token != null">
                token = #{token}
            </if>
        </where>
        order by id
        limit #{limit} offset #{offset}
    </select>
    <select id="selectTokenAll" resultMap="resultMap" resultType="com.lf.server.entity.data.TokenEntity">
        select * from lf.sys_token
    </select>
    <select id="selectToken" resultMap="resultMap" resultType="com.lf.server.entity.data.TokenEntity">
        select * from lf.sys_token where id = #{id}
    </select>
    <insert id="insertToken"  parameterType="com.lf.server.entity.data.TokenEntity">
       insert into lf.sys_token
       (token,duration,expire,type,ip,create_user,create_time)
       values
       (#{token},#{duration},#{expire},#{type},#{ip},#{createUser},now())
    </insert>
    <insert id="insertTokens"   >
       insert into lf.sys_token
        (token,duration,expire,type,ip,create_user,create_time)
       values
        <foreach collection="list"   item="item" index="index" separator=","  >
            (#{item.token},#{item.duration},#{item.expire},#{item.type},#{item.ip},#{item.createUser} now())
        </foreach>
    </insert>
    <delete id="deleteToken"  >
        delete from lf.sys_token where id = #{id}
    </delete>
    <delete id="deleteTokens"  >
        delete from lf.sys_token where id in
        <foreach item="ids" collection="list" index="index" open="("
                 separator="," close=")">
            #{ids}
        </foreach>
    </delete>
    <update id="updateToken">
    update lf.sys_token set token=#{token},duration=#{duration},expire=#{expire},type=#{type},ip=#{ip},update_user=#{updateUser},update_time=now() where id=#{id}
    </update>
</mapper>