管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-12-23 8a373a66936407266e860a19c0d44c406baae7cc
1
已添加2个文件
已修改8个文件
534 ■■■■ 文件已修改
data/db_tab.sql 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/config/InitConfig.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/DownlogController.java 224 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/BaseEntity.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/sys/DownlogEntity.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/all/GeomBaseMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/sys/DownlogMapper.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DataLoaderService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/DownlogService.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/DownlogMapper.xml 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_tab.sql
@@ -1017,7 +1017,7 @@
----------------------------------------------------------------------------------------------------- 29.下载日志表
-- drop table if exists lf.sys_downlog;
create table lf.sys_downlog (
    id serial8,
    id serial primary key,
    downid integer default 0,
    name varchar(50),
    type smallint default 1,
@@ -1027,20 +1027,7 @@
    create_time timestamp(6) without time zone default now(),
    update_user integer,
    update_time timestamp(6) without time zone
) partition by range(create_time);
create table lf.sys_downlog_2022 partition of lf.sys_downlog for values from ('2022-01-01') to ('2023-01-01');
create index index_sys_downlog_2022_create_time on lf.sys_downlog_2022 (create_time);
create table lf.sys_downlog_2023 partition of lf.sys_downlog for values from ('2023-01-01') to ('2024-01-01');
create index index_sys_downlog_2023_create_time on lf.sys_downlog_2023 (create_time);
create table lf.sys_downlog_2024 partition of lf.sys_downlog for values from ('2024-01-01') to ('2025-01-01');
create index index_sys_downlog_2024_create_time on lf.sys_downlog_2024 (create_time);
create table lf.sys_downlog_2025 partition of lf.sys_downlog for values from ('2025-01-01') to ('2026-01-01');
create index index_sys_downlog_2025_create_time on lf.sys_downlog_2025 (create_time);
create table lf.sys_downlog_2026 partition of lf.sys_downlog for values from ('2026-01-01') to ('2027-01-01');
create index index_sys_downlog_2026_create_time on lf.sys_downlog_2026 (create_time);
create table lf.sys_downlog_2027 partition of lf.sys_downlog for values from ('2027-01-01') to ('2028-01-01');
create index index_sys_downlog_2027_create_time on lf.sys_downlog_2027 (create_time);
);
comment on table lf.sys_downlog is '下载日志表';
comment on column lf.sys_downlog.id is '主键id';
comment on column lf.sys_downlog.name is '名称';
src/main/java/com/lf/server/config/InitConfig.java
@@ -96,11 +96,11 @@
    private void testBatchUpdate() {
        DlgagnpEntity d1 = new DlgagnpEntity();
        d1.setGid(56L);
        d1.setGid(56);
        d1.setGb("10");
        d1.setName("a01");
        DlgagnpEntity d2 = new DlgagnpEntity();
        d2.setGid(57L);
        d2.setGid(57);
        d2.setGb("20");
        d2.setName("a02");
src/main/java/com/lf/server/controller/sys/DownlogController.java
@@ -1,24 +1,20 @@
package com.lf.server.controller.sys;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.DownlogEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.sys.DownlogMapper;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.sys.DownlogService;
import com.lf.server.service.sys.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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@@ -30,7 +26,48 @@
@RequestMapping("/downlog")
public class DownlogController extends BaseController {
    @Autowired
    DownlogMapper downlogMapper;
    DownlogService downlogService;
    @Autowired
    TokenService tokenService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false, example = "")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String name) {
        try {
            int count = downlogService.selectCount(name);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", example = ""),
            @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<DownlogEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<DownlogEntity> rs = downlogService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "分页查询并返回记录数")
@@ -46,18 +83,171 @@
                return fail("每页页数或分页数小于1", null);
            }
            QueryWrapper wrapper = new QueryWrapper();
            if (!StringHelper.isEmpty(name)) {
                wrapper.like("name", name);
            int count = downlogService.selectCount(name);
            if (count == 0) {
                return success(0, null);
            }
            Page<DownlogEntity> page = new Page<>(pageIndex, pageSize);
            page.addOrder(OrderItem.asc("id"));
            IPage<DownlogEntity> paged = downlogMapper.selectPage(page, wrapper);
            List<DownlogEntity> rs = downlogService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            return success(paged.getTotal(), paged.getRecords());
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/selectAll")
    public ResponseMsg<List<DownlogEntity>> selectAll() {
        try {
            List<DownlogEntity> list = downlogService.selectAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectById")
    public ResponseMsg<DownlogEntity> selectById(int id) {
        try {
            DownlogEntity entity = downlogService.selectById(id);
            return success(entity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "DownlogEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody DownlogEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
            int count = downlogService.insert(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "DownlogEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<DownlogEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (DownlogEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = downlogService.inserts(list);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "删除一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/delete")
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = downlogService.delete(id);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "删除多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2")
    })
    @GetMapping(value = "/deletes")
    public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = downlogService.deletes(ids);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "DownlogEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody DownlogEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
            int count = downlogService.update(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "DownlogEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<DownlogEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (DownlogEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = downlogService.updates(list);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
}
src/main/java/com/lf/server/entity/all/BaseEntity.java
@@ -14,7 +14,7 @@
 */
public class BaseEntity implements Serializable {
    @TableId(type = IdType.AUTO)
    private Long gid;
    private Integer gid;
    private String eventid;
@@ -50,11 +50,11 @@
    public BaseEntity() {
    }
    public Long getGid() {
    public Integer getGid() {
        return gid;
    }
    public void setGid(Long gid) {
    public void setGid(Integer gid) {
        this.gid = gid;
    }
src/main/java/com/lf/server/entity/sys/DownlogEntity.java
@@ -1,12 +1,5 @@
package com.lf.server.entity.sys;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
@@ -14,52 +7,47 @@
 * ä¸‹è½½æ—¥å¿—
 * @author WWW
 */
@Data
@AllArgsConstructor
@TableName("lf.sys_downlog")
public class DownlogEntity implements Serializable {
    private static final long serialVersionUID = 2791055269920047470L;
    private static final long serialVersionUID = -295796504381949312L;
    @TableId(type = IdType.AUTO)
    private Integer id;
    private int id;
    private Integer downid;
    private int downid;
    private String name;
    private Integer type;
    private int type;
    private double sizes;
    private String ip;
    private Integer createUser;
    private int createUser;
    private Timestamp createTime;
    private Integer updateUser;
    private int updateUser;
    private Timestamp updateTime;
    @TableField(value = "fn_uname(create_user)")
    private String createName;
    public DownlogEntity() {
    }
    public Integer getId() {
    public int getId() {
        return id;
    }
    public void setId(Integer id) {
    public void setId(int id) {
        this.id = id;
    }
    public Integer getDownid() {
    public int getDownid() {
        return downid;
    }
    public void setDownid(Integer downid) {
    public void setDownid(int downid) {
        this.downid = downid;
    }
@@ -71,11 +59,11 @@
        this.name = name;
    }
    public Integer getType() {
    public int getType() {
        return type;
    }
    public void setType(Integer type) {
    public void setType(int type) {
        this.type = type;
    }
@@ -95,11 +83,11 @@
        this.ip = ip;
    }
    public Integer getCreateUser() {
    public int getCreateUser() {
        return createUser;
    }
    public void setCreateUser(Integer createUser) {
    public void setCreateUser(int createUser) {
        this.createUser = createUser;
    }
@@ -111,11 +99,11 @@
        this.createTime = createTime;
    }
    public Integer getUpdateUser() {
    public int getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(Integer updateUser) {
    public void setUpdateUser(int updateUser) {
        this.updateUser = updateUser;
    }
src/main/java/com/lf/server/mapper/all/GeomBaseMapper.java
@@ -47,5 +47,5 @@
     * @return å½±å“è¡Œæ•°
     */
    @Update("update ${tab} set geom = ST_GeomFromText('${wkt}') where gid = #{gid}")
    public Integer updateGeom(@Param("tab") String tab, @Param("gid") Long gid, @Param("wkt") String wkt);
    public Integer updateGeom(@Param("tab") String tab, @Param("gid") Integer gid, @Param("wkt") String wkt);
}
src/main/java/com/lf/server/mapper/sys/DownlogMapper.java
@@ -1,9 +1,10 @@
package com.lf.server.mapper.sys;
import com.lf.server.entity.sys.DownlogEntity;
import com.lf.server.mapper.all.BasicMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
 * ä¸‹è½½æ—¥å¿—
@@ -11,6 +12,85 @@
 */
@Mapper
@Repository
public interface DownlogMapper extends BasicMapper<DownlogEntity> {
    //
public interface DownlogMapper {
    /**
     * æŸ¥è¯¢è®°å½•æ•°
     *
     * @param name åç§°
     * @return è®°å½•æ•°
     */
    public Integer selectCount(String name);
    /**
     * åˆ†é¡µæŸ¥è¯¢
     *
     * @param name   åç§°
     * @param limit  è®°å½•æ•°
     * @param offset åç§»é‡
     * @return åˆ—表
     */
    public List<DownlogEntity> selectByPage(String name, Integer limit, Integer offset);
    /**
     * æŸ¥è¯¢æ‰€æœ‰
     *
     * @return
     */
    public List<DownlogEntity> selectAll();
    /**
     * æ ¹æ®ID查询
     *
     * @param id
     * @return
     */
    public DownlogEntity selectById(int id);
    /**
     * æ’入一条
     *
     * @param entity
     * @return
     */
    public Integer insert(DownlogEntity entity);
    /**
     * æ’入多条
     *
     * @param list
     * @return
     */
    public Integer inserts(List<DownlogEntity> list);
    /**
     * åˆ é™¤ä¸€æ¡
     *
     * @param id
     * @return
     */
    public Integer delete(int id);
    /**
     * åˆ é™¤å¤šæ¡
     *
     * @param ids
     * @return
     */
    public Integer deletes(List<Integer> ids);
    /**
     * æ›´æ–°ä¸€æ¡
     *
     * @param entity
     * @return
     */
    public Integer update(DownlogEntity entity);
    /**
     * æ›´æ–°å¤šæ¡
     *
     * @param list
     * @return
     */
    public Integer updates(List<DownlogEntity> list);
}
src/main/java/com/lf/server/service/data/DataLoaderService.java
@@ -423,7 +423,7 @@
                double y = (double) yField.get(t);
                BaseEntity baseEntity = (BaseEntity) t;
                Long gid = baseEntity.getGid();
                Integer gid = baseEntity.getGid();
                String wkt = String.format("POINT(%f %f)", x, y);
                geomBaseMapper.updateGeom(tabName, gid, wkt);
@@ -482,7 +482,7 @@
            String tabName = BaseQueryService.getTabName(geomBaseMapper);
            for (T t : list) {
                BaseEntity baseEntity = (BaseEntity) t;
                Long gid = baseEntity.getGid();
                Integer gid = baseEntity.getGid();
                Field gField = t.getClass().getDeclaredField("geom");
                gField.setAccessible(true);
src/main/java/com/lf/server/service/sys/DownlogService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
package com.lf.server.service.sys;
import com.lf.server.entity.sys.DownlogEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.sys.DownlogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * ä¸‹è½½æ—¥å¿—
 * @author WWW
 */
@Service
public class DownlogService implements DownlogMapper {
    @Autowired
    DownlogMapper downlogMapper;
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeStr(name);
        return downlogMapper.selectCount(name);
    }
    @Override
    public List<DownlogEntity> selectByPage(String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        return downlogMapper.selectByPage(name, limit, offset);
    }
    @Override
    public List<DownlogEntity> selectAll() {
        return downlogMapper.selectAll();
    }
    @Override
    public DownlogEntity selectById(int id) {
        return downlogMapper.selectById(id);
    }
    @Override
    public Integer insert(DownlogEntity entity) {
        return downlogMapper.insert(entity);
    }
    @Override
    public Integer inserts(List<DownlogEntity> list) {
        return downlogMapper.inserts(list);
    }
    @Override
    public Integer delete(int id) {
        return downlogMapper.delete(id);
    }
    @Override
    public Integer deletes(List<Integer> ids) {
        return downlogMapper.deletes(ids);
    }
    @Override
    public Integer update(DownlogEntity entity) {
        return downlogMapper.update(entity);
    }
    @Override
    public Integer updates(List<DownlogEntity> list) {
        return downlogMapper.updates(list);
    }
}
src/main/resources/mapper/sys/DownlogMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
<?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.sys.DownlogMapper">
    <select id="selectCount" resultType="java.lang.Integer">
        select count(*) from lf.sys_downlog
        <where>
            <if test="name != null">
                name like #{name}
            </if>
        </where>
    </select>
    <select id="selectByPage" resultType="com.lf.server.entity.sys.DownlogEntity">
        select * from lf.sys_downlog
        <where>
            <if test="name != null">
                name like #{name}
            </if>
        </where>
        order by id
        limit #{limit} offset #{offset}
    </select>
    <select id="selectAll" resultType="com.lf.server.entity.sys.DownlogEntity">
        select * from lf.sys_downlog order by id;
    </select>
    <select id="selectById" resultType="com.lf.server.entity.sys.DownlogEntity">
        select * from lf.sys_downlog where id = #{id}
    </select>
    <insert id="insert" parameterType="com.lf.server.entity.sys.DownlogEntity">
       insert into lf.sys_downlog
       (downid,name,type,sizes,ip,create_user,create_time)
       values
       (#{downid},#{name},#{type},#{sizes},#{ip},#{createUser},now())
    </insert>
    <insert id="inserts">
        insert into lf.sys_downlog
        (downid,name,type,sizes,ip,create_user,create_time)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.downid},#{item.name},#{item.type},#{item.sizes},#{item.ip},#{item.createUser},now())
        </foreach>
    </insert>
    <delete id="delete">
        delete from lf.sys_downlog where id = #{id}
    </delete>
    <delete id="deletes">
        delete from lf.sys_downlog where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="update">
        update lf.sys_downlog
        set downid=#{downid},name=#{name},type=#{type},sizes=#{sizes},ip=#{ip},update_user=#{updateUser},update_time=now()
        where id=#{id}
    </update>
    <update id="updates">
        <foreach collection="list" item="item" index="index" separator=";">
            update lf.sys_downlog
            <set>
                downid=#{item.downid},name=#{item.name},type=#{item.type},sizes=#{item.sizes},ip=#{item.ip},update_user=#{item.updateUser},update_time=now()
            </set>
            where id = #{item.id}
        </foreach>
    </update>
</mapper>