管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-13 4d4b5bdb44811c0aa47d85666dbc8c2a02d76221
1
已添加5个文件
681 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/PublishController.java 253 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/data/PublishEntity.java 185 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/PublishMapper.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/PublishService.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/show/PublishMapper.xml 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/PublishController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,253 @@
package com.lf.server.controller.data;
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.data.PublishEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.data.PublishService;
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.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * æ•°æ®å‘布
 * @author WWW
 */
@Api(tags = "运维管理\\数据发布")
@RestController
@RequestMapping("/publish")
public class PublishController extends BaseController {
    @Autowired
    PublishService publishService;
    @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 = publishService.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<PublishEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @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 = "/selectByPageAndCount")
    public ResponseMsg<List<PublishEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = publishService.selectCount(name);
            if (count == 0) {
                return success(0, null);
            }
            List<PublishEntity> rs = publishService.selectByPage(name, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/selectAll")
    public ResponseMsg<List<PublishEntity>> selectAll() {
        try {
            List<PublishEntity> list = publishService.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<PublishEntity> selectById(int id) {
        try {
            PublishEntity entity = publishService.selectById(id);
            return success(entity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PublishEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody PublishEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
            int count = publishService.insert(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "PublishEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<PublishEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (PublishEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = publishService.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 = publishService.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 = publishService.deletes(ids);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PublishEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody PublishEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
            int count = publishService.update(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "PublishEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<PublishEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (PublishEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = publishService.updates(list);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
}
src/main/java/com/lf/server/entity/data/PublishEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,185 @@
package com.lf.server.entity.data;
import java.io.Serializable;
import java.sql.Timestamp;
/**
 * æ•°æ®å‘布
 * @author WWW
 */
public class PublishEntity implements Serializable {
    private static final long serialVersionUID = -386130556178340032L;
    private int id;
    private String name;
    private String url;
    private String path;
    private String type;
    private int status;
    private String dirid;
    private String depid;
    private int min;
    private int max;
    private String json;
    private int createUser;
    private Timestamp createTime;
    private int updateUser;
    private Timestamp updateTime;
    private String geom;
    private String bak;
    public PublishEntity() {
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getPath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    public String getDirid() {
        return dirid;
    }
    public void setDirid(String dirid) {
        this.dirid = dirid;
    }
    public String getDepid() {
        return depid;
    }
    public void setDepid(String depid) {
        this.depid = depid;
    }
    public int getMin() {
        return min;
    }
    public void setMin(int min) {
        this.min = min;
    }
    public int getMax() {
        return max;
    }
    public void setMax(int max) {
        this.max = max;
    }
    public String getJson() {
        return json;
    }
    public void setJson(String json) {
        this.json = json;
    }
    public int getCreateUser() {
        return createUser;
    }
    public void setCreateUser(int createUser) {
        this.createUser = createUser;
    }
    public Timestamp getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }
    public int getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(int updateUser) {
        this.updateUser = updateUser;
    }
    public Timestamp getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }
    public String getGeom() {
        return geom;
    }
    public void setGeom(String geom) {
        this.geom = geom;
    }
    public String getBak() {
        return bak;
    }
    public void setBak(String bak) {
        this.bak = bak;
    }
}
src/main/java/com/lf/server/mapper/data/PublishMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,96 @@
package com.lf.server.mapper.data;
import com.lf.server.entity.data.PublishEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
 * æ•°æ®å‘布
 * @author WWW
 */
@Mapper
@Repository
public interface PublishMapper {
    /**
     * æŸ¥è¯¢è®°å½•æ•°
     *
     * @param name åç§°
     * @return è®°å½•æ•°
     */
    public Integer selectCount(String name);
    /**
     * åˆ†é¡µæŸ¥è¯¢
     *
     * @param name   åç§°
     * @param limit  è®°å½•æ•°
     * @param offset åç§»é‡
     * @return åˆ—表
     */
    public List<PublishEntity> selectByPage(String name, Integer limit, Integer offset);
    /**
     * æŸ¥è¯¢æ‰€æœ‰
     *
     * @return
     */
    public List<PublishEntity> selectAll();
    /**
     * æ ¹æ®ID查询
     *
     * @param id
     * @return
     */
    public PublishEntity selectById(int id);
    /**
     * æ’入一条
     *
     * @param entity
     * @return
     */
    public Integer insert(PublishEntity entity);
    /**
     * æ’入多条
     *
     * @param list
     * @return
     */
    public Integer inserts(List<PublishEntity> list);
    /**
     * åˆ é™¤ä¸€æ¡
     *
     * @param id
     * @return
     */
    public Integer delete(int id);
    /**
     * åˆ é™¤å¤šæ¡
     *
     * @param ids
     * @return
     */
    public Integer deletes(List<Integer> ids);
    /**
     * æ›´æ–°ä¸€æ¡
     *
     * @param entity
     * @return
     */
    public Integer update(PublishEntity entity);
    /**
     * æ›´æ–°å¤šæ¡
     *
     * @param list
     * @return
     */
    public Integer updates(List<PublishEntity> list);
}
src/main/java/com/lf/server/service/data/PublishService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
package com.lf.server.service.data;
import com.lf.server.entity.data.PublishEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.data.PublishMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * æ•°æ®å‘布
 * @author WWW
 */
@Service
public class PublishService implements PublishMapper {
    @Autowired
    PublishMapper publishMapper;
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeStr(name);
        return publishMapper.selectCount(name);
    }
    @Override
    public List<PublishEntity> selectByPage(String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        return publishMapper.selectByPage(name, limit, offset);
    }
    @Override
    public List<PublishEntity> selectAll() {
        return publishMapper.selectAll();
    }
    @Override
    public PublishEntity selectById(int id) {
        return publishMapper.selectById(id);
    }
    @Override
    public Integer insert(PublishEntity entity) {
        return publishMapper.insert(entity);
    }
    @Override
    public Integer inserts(List<PublishEntity> list) {
        return publishMapper.inserts(list);
    }
    @Override
    public Integer delete(int id) {
        return publishMapper.delete(id);
    }
    @Override
    public Integer deletes(List<Integer> ids) {
        return publishMapper.deletes(ids);
    }
    @Override
    public Integer update(PublishEntity entity) {
        return publishMapper.update(entity);
    }
    @Override
    public Integer updates(List<PublishEntity> list) {
        return publishMapper.updates(list);
    }
}
src/main/resources/mapper/show/PublishMapper.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.data.PublishMapper">
    <select id="selectCount" resultType="java.lang.Integer">
        select count(*) from lf.sys_publish
        <where>
            <if test="name != null">
                name like #{name}
            </if>
        </where>
    </select>
    <select id="selectByPage" resultType="com.lf.server.entity.data.PublishEntity">
        select * from lf.sys_publish
        <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.data.PublishEntity">
        select * from lf.sys_publish order by id;
    </select>
    <select id="selectById" resultType="com.lf.server.entity.data.PublishEntity">
        select * from lf.sys_publish where id = #{id}
    </select>
    <insert id="insert" parameterType="com.lf.server.entity.data.PublishEntity">
        insert into lf.sys_publish
        (name,url,path,type,status,dirid,depid,min,max,json,create_user,create_time,geom,bak)
        values
        (#{name},#{url},#{path},#{type},#{status},#{dirid},#{depid},#{min},#{max},#{json},#{createUser},now(),#{geom},#{bak})
    </insert>
    <insert id="inserts">
        insert into lf.sys_publish
        (name,url,path,type,status,dirid,depid,min,max,json,create_user,create_time,geom,bak)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.name},#{item.url},#{item.path},#{item.type},#{item.status},#{item.dirid},#{item.depid},#{item.min},#{item.max},#{item.json},#{item.createUser},now(),#{item.geom},#{item.bak})
        </foreach>
    </insert>
    <delete id="delete">
        delete from lf.sys_publish where id = #{id}
    </delete>
    <delete id="deletes">
        delete from lf.sys_publish where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="update">
        update lf.sys_publish
        set name=#{name},url=#{url},path=#{path},type=#{type},status=#{status},dirid=#{dirid},depid=#{depid},min=#{min},max=#{max},json=#{json},update_user=#{updateUser},update_time=now(),geom=#{geom},bak=#{bak}
        where id=#{id}
    </update>
    <update id="updates">
        <foreach collection="list" item="item" index="index" separator=";">
            update lf.sys_publish
            <set>
                name=#{item.name},url=#{item.url},path=#{item.path},type=#{item.type},status=#{item.status},dirid=#{item.dirid},depid=#{item.depid},min=#{item.min},max=#{item.max},json=#{item.json},update_user=#{item.updateUser},update_time=now(),geom=#{item.geom},bak=#{item.bak}
            </set>
            where id = #{item.id}
        </foreach>
    </update>
</mapper>