管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-09 1ae0244127bbcccbd655b86f18b55346df2ba4c8
1
已添加5个文件
611 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/sys/ReportController.java 253 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/sys/ReportEntity.java 115 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/sys/ReportMapper.java 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/ReportService.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/ReportMapper.xml 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/sys/ReportController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,253 @@
package com.lf.server.controller.sys;
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.ReportEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.sys.ReportService;
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("/report")
public class ReportController extends BaseController {
    @Autowired
    ReportService reportService;
    @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 = reportService.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<ReportEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<ReportEntity> rs = reportService.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<ReportEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = reportService.selectCount(name);
            if (count == 0) {
                return success(0, null);
            }
            List<ReportEntity> rs = reportService.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<ReportEntity>> selectAll() {
        try {
            List<ReportEntity> list = reportService.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<ReportEntity> selectById(int id) {
        try {
            ReportEntity entity = reportService.selectById(id);
            return success(entity);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "ReportEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody ReportEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
            int count = reportService.insert(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "ReportEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<ReportEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (ReportEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = reportService.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 = reportService.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 = reportService.deletes(ids);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "ReportEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody ReportEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
            int count = reportService.update(entity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "ReportEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<ReportEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (ReportEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = reportService.updates(list);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
}
src/main/java/com/lf/server/entity/sys/ReportEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,115 @@
package com.lf.server.entity.sys;
import java.io.Serializable;
import java.sql.Timestamp;
/**
 * æŠ¥å‘Šæ¨¡æ¿
 * @author WWW
 */
public class ReportEntity implements Serializable {
    private static final long serialVersionUID = -976039118587988992L;
    private int id;
    private String name;
    private String type;
    private String path;
    private String code;
    private int createUser;
    private Timestamp createTime;
    private int updateUser;
    private Timestamp updateTime;
    private String bak;
    public ReportEntity() {
    }
    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 getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getPath() {
        return path;
    }
    public void setPath(String path) {
        this.path = path;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    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 getBak() {
        return bak;
    }
    public void setBak(String bak) {
        this.bak = bak;
    }
}
src/main/java/com/lf/server/mapper/sys/ReportMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,96 @@
package com.lf.server.mapper.sys;
import com.lf.server.entity.sys.ReportEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
 * æŠ¥å‘Šæ¨¡æ¿
 * @author WWW
 */
@Mapper
@Repository
public interface ReportMapper {
    /**
     * æŸ¥è¯¢è®°å½•æ•°
     *
     * @param name åç§°
     * @return è®°å½•æ•°
     */
    public Integer selectCount(String name);
    /**
     * åˆ†é¡µæŸ¥è¯¢
     *
     * @param name   åç§°
     * @param limit  è®°å½•æ•°
     * @param offset åç§»é‡
     * @return åˆ—表
     */
    public List<ReportEntity> selectByPage(String name, Integer limit, Integer offset);
    /**
     * æŸ¥è¯¢æ‰€æœ‰
     *
     * @return
     */
    public List<ReportEntity> selectAll();
    /**
     * æ ¹æ®ID查询
     *
     * @param id
     * @return
     */
    public ReportEntity selectById(int id);
    /**
     * æ’入一条
     *
     * @param entity
     * @return
     */
    public Integer insert(ReportEntity entity);
    /**
     * æ’入多条
     *
     * @param list
     * @return
     */
    public Integer inserts(List<ReportEntity> list);
    /**
     * åˆ é™¤ä¸€æ¡
     *
     * @param id
     * @return
     */
    public Integer delete(int id);
    /**
     * åˆ é™¤å¤šæ¡
     *
     * @param ids
     * @return
     */
    public Integer deletes(List<Integer> ids);
    /**
     * æ›´æ–°ä¸€æ¡
     *
     * @param entity
     * @return
     */
    public Integer update(ReportEntity entity);
    /**
     * æ›´æ–°å¤šæ¡
     *
     * @param list
     * @return
     */
    public Integer updates(List<ReportEntity> list);
}
src/main/java/com/lf/server/service/sys/ReportService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,73 @@
package com.lf.server.service.sys;
import com.lf.server.entity.sys.ReportEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.sys.ReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * æŠ¥å‘Šæ¨¡æ¿
 * @author WWW
 */
@Service
public class ReportService implements ReportMapper {
    @Autowired
    ReportMapper reportMapper;
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeStr(name);
        return reportMapper.selectCount(name);
    }
    @Override
    public List<ReportEntity> selectByPage(String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        return reportMapper.selectByPage(name, limit, offset);
    }
    @Override
    public List<ReportEntity> selectAll() {
        return reportMapper.selectAll();
    }
    @Override
    public ReportEntity selectById(int id) {
        return reportMapper.selectById(id);
    }
    @Override
    public Integer insert(ReportEntity entity) {
        return reportMapper.insert(entity);
    }
    @Override
    public Integer inserts(List<ReportEntity> list) {
        return reportMapper.inserts(list);
    }
    @Override
    public Integer delete(int id) {
        return reportMapper.delete(id);
    }
    @Override
    public Integer deletes(List<Integer> ids) {
        return reportMapper.deletes(ids);
    }
    @Override
    public Integer update(ReportEntity entity) {
        return reportMapper.update(entity);
    }
    @Override
    public Integer updates(List<ReportEntity> list) {
        return reportMapper.updates(list);
    }
}
src/main/resources/mapper/sys/ReportMapper.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.ReportMapper">
    <select id="selectCount" resultType="java.lang.Integer">
        select count(*) from lf.sys_report
        <where>
            <if test="name != null">
                name like #{name}
            </if>
        </where>
    </select>
    <select id="selectByPage" resultType="com.lf.server.entity.sys.ReportEntity">
        select * from lf.sys_report
        <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.ReportEntity">
        select * from lf.sys_report order by id;
    </select>
    <select id="selectById" resultType="com.lf.server.entity.sys.ReportEntity">
        select * from lf.sys_report where id = #{id}
    </select>
    <insert id="insert" parameterType="com.lf.server.entity.sys.ReportEntity">
        insert into lf.sys_report
        (name,type,path,code,create_user,create_time,bak)
        values
        (#{name},#{type},#{path},#{code},#{createUser},now(),#{bak})
    </insert>
    <insert id="inserts">
        insert into lf.sys_report
        (name,type,path,code,create_user,create_time,bak)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.name},#{item.type},#{item.path},#{item.code},#{item.createUser},now(),#{item.bak})
        </foreach>
    </insert>
    <delete id="delete">
        delete from lf.sys_report where id = #{id}
    </delete>
    <delete id="deletes">
        delete from lf.sys_report where id in
        <foreach item="id" collection="ids" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="update">
        update lf.sys_report
        set name=#{name},type=#{type},path=#{path},code=#{code},update_user=#{updateUser},update_time=now(),bak=#{bak}
        where id=#{id}
    </update>
    <update id="updates">
        <foreach collection="list" item="item" index="index" separator=";">
            update lf.sys_report
            <set>
                name=#{item.name},type=#{item.type},path=#{item.path},code=#{item.code},update_user=#{item.updateUser},update_time=now(),bak=#{item.bak}
            </set>
            where id = #{item.id}
        </foreach>
    </update>
</mapper>