管道基础大数据平台系统开发-【后端】-Server
1
sws
2022-11-24 d5f776a44565fdd2306e95f1be602430f1336e90
1
已修改10个文件
165 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/DomainController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/MetaController.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/show/ExportController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/StringHelper.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/DomainMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/DownloadMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DomainService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DownloadService.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/DomainMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/DownloadMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/DomainController.java
@@ -6,6 +6,7 @@
import com.lf.server.entity.ctrl.TabEntity;
import com.lf.server.entity.data.DomainEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.StringHelper;
import com.lf.server.service.all.BaseQueryService;
import com.lf.server.service.data.DomainService;
import com.lf.server.service.sys.TokenService;
@@ -134,6 +135,27 @@
    }
    @SysLog()
    @ApiOperation(value = "根据表名查询值域名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ns", value = "名称空间", dataType = "String", paramType = "query", example = "bd"),
            @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "b_hy20w_s23")
    })
    @GetMapping(value = "/selectDomainNames")
    public ResponseMsg<List<String>> selectDomainNames(String ns, String tab) {
        try {
            if (StringHelper.isEmpty(ns) || StringHelper.isEmpty(tab)) {
                return fail("名称空间和表名不能为空", null);
            }
            List<String> list = domainService.selectDomainNames(ns, tab);
            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")
src/main/java/com/lf/server/controller/data/MetaController.java
@@ -8,6 +8,8 @@
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.Md5Helper;
import com.lf.server.helper.RsaHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.DownloadService;
@@ -223,6 +225,37 @@
    }
    @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 = "/selectPageCountForDownload")
    public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            int count = downloadService.selectCountForUser(ue.getCreateUser(), 3, name);
            if (count == 0) {
                return success(0, null);
            }
            List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "请求下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pwd", value = "密码", dataType = "String", paramType = "body", example = ""),
@@ -238,6 +271,12 @@
            if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) {
                return fail("请选择要下载的文件");
            }
            if (!downloadService.validatePwd(reqEntity)) {
                return fail("密码不符合要求");
            }
            String ids = StringHelper.join(reqEntity.getIds(), ",");
            return success(true);
        } catch (Exception ex) {
@@ -262,13 +301,16 @@
                return;
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid());
            if (null == de) {
                WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res);
                return;
            }
            if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), de.getPwd())) {
                WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "密码不正确", res);
            }
            UserEntity ue = tokenService.getCurrentUser(req);
            de.setDcount(de.getDcount() + 1);
            de.setDownloadUser(ue.getId());
            int rows = downloadService.update(de);
src/main/java/com/lf/server/controller/show/ExportController.java
@@ -59,11 +59,11 @@
                return fail("用户未登录", null);
            }
            int count = downloadService.selectCountForExport(ue.getCreateUser(), name);
            int count = downloadService.selectCountForUser(ue.getCreateUser(), 2, name);
            if (count == 0) {
                return success(0, null);
            }
            List<DownloadEntity> rs = downloadService.selectByPageForExport(ue.getCreateUser(), name, pageSize, pageSize * (pageIndex - 1));
            List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 2, name, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
src/main/java/com/lf/server/helper/StringHelper.java
@@ -4,6 +4,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -162,4 +163,29 @@
    public static boolean checkPwdValid(String pwd) {
        return Pattern.matches(StaticData.PWD_REG, pwd);
    }
    /**
     * 连接List集合
     * @param list 整数集合
     * @param join 连接字符
     * @return
     */
    public static String join(List<Integer> list, String join) {
        if (null == list || list.isEmpty()) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (Integer i : list) {
            if (null != i) {
                sb.append(i.toString() + join);
            }
        }
        if (sb.length() > 0 && sb.lastIndexOf(join) == sb.length() - 1) {
            sb.deleteCharAt(sb.length() -1 );
        }
        return sb.toString();
    }
}
src/main/java/com/lf/server/mapper/data/DomainMapper.java
@@ -53,11 +53,21 @@
    /**
     * 查询值域表集合
     *
     * @return
     */
    public List<TabEntity> selectDomainTabs();
    /**
     * 根据表名查询值域名称
     *
     * @param ns  名称空间
     * @param tab 表名
     * @return 值域名称集合
     */
    public List<String> selectDomainNames(String ns, String tab);
    /**
     * 插入一条
     *
     * @param entity
src/main/java/com/lf/server/mapper/data/DownloadMapper.java
@@ -35,21 +35,23 @@
     * 根据用户ID查询记录数(在线制图)
     *
     * @param createUser 用户ID
     * @param type       类别
     * @param name       名称
     * @return 记录数
     */
    public Integer selectCountForExport(Integer createUser, String name);
    public Integer selectCountForUser(Integer createUser, Integer type, String name);
    /**
     * 根据用户ID分页查询(在线制图)
     *
     * @param createUser 用户ID
     * @param type       类别
     * @param name       名称
     * @param limit      记录表
     * @param offset     偏移量
     * @return 列表
     */
    public List<DownloadEntity> selectByPageForExport(Integer createUser, String name, Integer limit, Integer offset);
    public List<DownloadEntity> selectByPageForUser(Integer createUser, Integer type, String name, Integer limit, Integer offset);
    /**
     * 查询所有
src/main/java/com/lf/server/service/data/DomainService.java
@@ -48,6 +48,11 @@
    }
    @Override
    public List<String> selectDomainNames(String ns, String tab) {
        return domainMapper.selectDomainNames(ns, tab);
    }
    @Override
    public Integer insert(DomainEntity entity) {
        return domainMapper.insert(entity);
    }
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -1,9 +1,13 @@
package com.lf.server.service.data;
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.helper.PathHelper;
import com.lf.server.helper.RsaHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.data.DownloadMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -22,6 +26,8 @@
    @Autowired
    DownloadMapper downloadMapper;
    private final static Log log = LogFactory.getLog(DownloadService.class);
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeStr(name);
@@ -37,17 +43,17 @@
    }
    @Override
    public Integer selectCountForExport(Integer createUser, String name) {
    public Integer selectCountForUser(Integer createUser, Integer type, String name) {
        name = StringHelper.getLikeStr(name);
        return downloadMapper.selectCountForExport(createUser, name);
        return downloadMapper.selectCountForUser(createUser, type, name);
    }
    @Override
    public List<DownloadEntity> selectByPageForExport(Integer createUser, String name, Integer limit, Integer offset) {
    public List<DownloadEntity> selectByPageForUser(Integer createUser, Integer type, String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        return downloadMapper.selectByPageForExport(createUser, name, limit, offset);
        return downloadMapper.selectByPageForUser(createUser, type, name, limit, offset);
    }
    @Override
@@ -104,4 +110,26 @@
    public String getDownloadFilePath(DownloadEntity de) {
        return pathHelper.getConfig().getDownloadPath() + File.separator + de.getUrl();
    }
    /**
     * 校验密码有效性
     *
     * @param reqEntity 请求下载实体类
     * @return 是/否有效
     */
    public boolean validatePwd(DownloadReqEntity reqEntity) {
        try {
            String pwd = RsaHelper.decrypt(reqEntity.getPwd());
            if (StringHelper.isEmpty(pwd) || !StringHelper.checkPwdValid(pwd)) {
                return false;
            }
            reqEntity.setPwd(pwd);
            return true;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return false;
        }
    }
}
src/main/resources/mapper/data/DomainMapper.xml
@@ -37,6 +37,10 @@
        select distinct ns,tab,tab_desc,tableType from lf.sys_dict where domain_na is not null order by ns,tab
    </select>
    <select id="selectDomainNames" resultType="java.lang.String">
        select domain_na from lf.sys_dict where ns = #{ns} and tab = #{tab} and domain_na is not null group by domain_na
    </select>
    <insert id="insert" parameterType="com.lf.server.entity.data.DomainEntity">
       insert into lf.sys_domain
       (dom_desc,dom_name,dom_code,code_desc,level,orderid,bsm,create_user,create_time,bak)
src/main/resources/mapper/data/DownloadMapper.xml
@@ -21,20 +21,20 @@
        limit #{limit} offset #{offset}
    </select>
    <select id="selectCountForExport" resultType="java.lang.Integer">
    <select id="selectCountForUser" resultType="java.lang.Integer">
        select count(*) from lf.sys_download
        <where>
            create_user = #{createUser} and type = 2
            create_user = #{createUser} and type = #{type}
            <if test="name != null">
                and name like #{name}
            </if>
        </where>
    </select>
    <select id="selectByPageForExport" resultType="com.lf.server.entity.data.DownloadEntity">
    <select id="selectByPageForUser" resultType="com.lf.server.entity.data.DownloadEntity">
        select * from lf.sys_download
        <where>
            create_user = #{createUser} and type = 2
            create_user = #{createUser} and type = #{type}
            <if test="name != null">
                and name like #{name}
            </if>