| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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") |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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 = ""), |
| | |
| | | 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) { |
| | |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 查询值域表集合 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<TabEntity> selectDomainTabs(); |
| | | |
| | | /** |
| | | * 根据表名查询值域名称 |
| | | * |
| | | * @param ns 名称空间 |
| | | * @param tab 表名 |
| | | * @return 值域名称集合 |
| | | */ |
| | | public List<String> selectDomainNames(String ns, String tab); |
| | | |
| | | /** |
| | | * 插入一条 |
| | | * |
| | | * @param entity |
| | |
| | | * 根据用户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); |
| | | |
| | | /** |
| | | * 查询所有 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectDomainNames(String ns, String tab) { |
| | | return domainMapper.selectDomainNames(ns, tab); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(DomainEntity entity) { |
| | | return domainMapper.insert(entity); |
| | | } |
| | |
| | | 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; |
| | | |
| | |
| | | @Autowired |
| | | DownloadMapper downloadMapper; |
| | | |
| | | private final static Log log = LogFactory.getLog(DownloadService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(String name) { |
| | | name = StringHelper.getLikeStr(name); |
| | |
| | | } |
| | | |
| | | @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 |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) |
| | |
| | | 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> |