com.ruoyi.common.config.Global Java Examples

The following examples show how to use com.ruoyi.common.config.Global. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysProfileController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(SysUser user, @RequestParam("avatarfile") MultipartFile file) {
    try {
        if (!file.isEmpty()) {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            user.setAvatar(avatar);
            if (userService.updateUserInfo(user) > 0) {
                setSysUser(userService.selectUserById(user.getUserId()));
                return success();
            }
        }
        return error();
    } catch (Exception e) {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}
 
Example #2
Source File: CommonController.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 通用上传请求
 */
@PostMapping("/common/upload")
@ResponseBody
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
    try
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example #3
Source File: CommonController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@PostMapping("/common/upload")
@ResponseBody
@ApiOperation(value = "通用文件上传")
@ApiImplicitParams({
        @ApiImplicitParam(name = "fileName",value = "文件名",required = true),
        @ApiImplicitParam(name = "delete",value = "是否删除临时文件",required = true,dataType ="boolean")
})
public AjaxResult uploadFile(MultipartFile file){
    try
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + UPLOAD_PATH + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example #4
Source File: CommonController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@RequestMapping("common/download")
@ApiOperation(value = "通用下载文件")
@ApiImplicitParams({
        @ApiImplicitParam(name = "fileName",value = "文件名",required = true),
        @ApiImplicitParam(name = "delete",value = "是否删除临时文件",required = true,dataType ="boolean")
})
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
    String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf('_') + 1);
    try {
        if (!FileUtils.isValidFilename(fileName)){
            throw new BusinessException(String.format(" 文件名称(%s)非法,不允许下载。 ", fileName));
        }
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding(CharsetKit.UTF8);
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete) {
            FileUtils.deleteFile(filePath);
        }
    } catch (Exception e) {
        log.error("下载文件失败", e);
    }
}
 
Example #5
Source File: AddressUtils.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
public static String getRealAddressByIp(String ip) {
    String address = "XX XX" ;

    // 内网不查询
    if (IpUtils.internalIp(ip)) {
        return "内网IP" ;
    }
    if (Global.isAddressEnabled()) {
        String rspStr = HttpUtil.post(IP_URL, "ip=" + ip);
        if (StrUtil.isEmpty(rspStr)) {
            log.error("获取地理位置异常 {}" , ip);
            return address;
        }
        JSONObject obj;
        try {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        } catch (Exception e) {
            log.error("获取地理位置异常 {}" , ip);
        }
    }
    return address;
}
 
Example #6
Source File: CommonController.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 通用上传请求
 */
@PostMapping("/common/upload")
@ResponseBody
public AjaxResult uploadFile(MultipartFile file) throws Exception
{
    try
    {
        // 上传文件路径
        String filePath = Global.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, file);
        String url = serverConfig.getUrl() + UPLOAD_PATH + fileName;
        AjaxResult ajax = AjaxResult.success();
        ajax.put("fileName", fileName);
        ajax.put("url", url);
        return ajax;
    }
    catch (Exception e)
    {
        return AjaxResult.error(e.getMessage());
    }
}
 
Example #7
Source File: CommonController.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
    try
    {
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example #8
Source File: GenUtils.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 获取模板信息
 * 
 * @return 模板列表
 */
public static VelocityContext getVelocityContext(TableInfo table,String _packageName)
{
    // java对象数据传递到模板文件vm
    VelocityContext velocityContext = new VelocityContext();
    String packageName = _packageName==null?Global.getPackageName():_packageName;
    velocityContext.put("tableName", table.getTableName());
    velocityContext.put("tableComment", replaceKeyword(table.getTableComment()));
    velocityContext.put("primaryKey", table.getPrimaryKey());
    velocityContext.put("className", table.getClassName());
    velocityContext.put("classname", table.getClassname());
    velocityContext.put("moduleName", getModuleName(packageName));
    velocityContext.put("columns", table.getColumns());
    velocityContext.put("basePackage", getBasePackage(packageName));
    velocityContext.put("package", packageName);
    velocityContext.put("author", Convert.toStr(Global.getAuthor(),"cxlh"));
    velocityContext.put("datetime", DateUtils.getDate());

    velocityContext.put("module", StrUtil.isEmpty(table.getModule())?getModuleName(packageName):table.getModule());
    velocityContext.put("uri",table.getUri());
    velocityContext.put("dir",table.getBaseDir());
    velocityContext.put("tmpl",table.getWebTempleName());
    return velocityContext;
}
 
Example #9
Source File: GenUtils.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 表名转换成Java类名
 */
public static String tableToJava(String tableName)
{
    String autoRemovePre = Global.getAutoRemovePre();
    String tablePrefix = Global.getTablePrefix();
    //多种前缀
    if(tablePrefix.indexOf(",")>0){
        String[] prefixes = StrUtil.splitToArray(tablePrefix,',');
        for(String _prefix : prefixes){
            if(!StrUtil.isEmpty(_prefix)){
                tableName = tableName.replaceFirst(_prefix, "");
            }
        }
    }else {
        if (Constants.AUTO_REOMVE_PRE.equals(autoRemovePre) && StringUtils.isNotEmpty(tablePrefix)) {
            tableName = tableName.replaceFirst(tablePrefix, "");
        }
    }
    return StringUtils.convertToCamelCase(tableName);
}
 
Example #10
Source File: GenUtils.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取模板信息
 *
 * @return 模板列表
 */
public static VelocityContext getVelocityContext(TableInfo table) {
    // java对象数据传递到模板文件vm
    VelocityContext velocityContext = new VelocityContext();
    String packageName = Global.getPackageName();
    velocityContext.put("tableName" , table.getTableName());
    velocityContext.put("tableComment" , replaceKeyword(table.getTableComment()));
    velocityContext.put("primaryKey" , table.getPrimaryKey());
    velocityContext.put("className" , table.getClassName());
    velocityContext.put("classname" , table.getClassname());
    velocityContext.put("moduleName" , getModuleName(packageName));
    velocityContext.put("columns" , table.getColumns());
    velocityContext.put("basePackage" , getBasePackage(packageName));
    velocityContext.put("package" , packageName);
    velocityContext.put("author" , Global.getAuthor());
    velocityContext.put("datetime" , DateUtil.today());
    return velocityContext;
}
 
Example #11
Source File: SysProfileController.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file)
{
    SysUser currentUser = getSysUser();
    try
    {
        if (!file.isEmpty())
        {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            currentUser.setAvatar(avatar);
            if (userService.updateUserInfo(currentUser) > 0)
            {
                setSysUser(userService.selectUserById(currentUser.getUserId()));
                return success();
            }
        }
        return error();
    }
    catch (Exception e)
    {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}
 
Example #12
Source File: SysIndexController.java    From ruoyiplus with MIT License 5 votes vote down vote up
@GetMapping("/index")
public String index(ModelMap mmap)
{
    // 取身份信息
    SysUser user = getSysUser();
    // 根据用户id取出菜单
    List<SysMenu> menus = menuService.selectMenusByUser(user);
    mmap.put("menus", menus);
    mmap.put("user", user);
    mmap.put("copyrightYear", Global.getCopyrightYear());
    return "index";
}
 
Example #13
Source File: SwaggerConfig.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 添加摘要信息
 */
private ApiInfo apiInfo()
{
    // 用ApiInfoBuilder进行定制
    return new ApiInfoBuilder()
            .title("标题:若依管理系统_接口文档")
            .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
            .contact(new Contact(Global.getName(), null, null))
            .version("版本号:" + Global.getVersion())
            .build();
}
 
Example #14
Source File: GenServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 根据表信息生成代码
 * @param zip 生成后的压缩包
 * @param tableName 表名
 */
private void generatorCode(ZipOutputStream zip, String tableName) {
    // 查询表信息
    TableInfo table = genMapper.selectTableByName(tableName);
    // 查询列信息
    List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
    // 表名转换成Java属性名
    String className = GenUtils.tableToJava(table.getTableName());
    table.setClassName(className);
    table.setClassname(StrUtil.lowerFirst(className));
    // 列信息
    table.setColumns(GenUtils.transColums(columns));
    // 设置主键
    table.setPrimaryKey(table.getColumnsLast());

    VelocityInitializer.initVelocity();

    String packageName = Global.getPackageName();
    String moduleName = GenUtils.getModuleName(packageName);

    VelocityContext context = GenUtils.getVelocityContext(table);

    // 获取模板列表
    List<String> templates = GenUtils.getTemplates();
    for (String template : templates) {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, CharsetKit.UTF8);
        tpl.merge(context, sw);
        try {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(Objects.requireNonNull(GenUtils.getFileName(template, table, moduleName))));
            IOUtils.write(sw.toString(), zip, CharsetKit.UTF8);
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        } catch (IOException e) {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}
 
Example #15
Source File: GenUtils.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 表名转换成Java类名
 */
public static String tableToJava(String tableName) {
    if (Constants.AUTO_REOMVE_PRE.equals(Global.getAutoRemovePre())) {
        tableName = tableName.substring(tableName.indexOf('_') + 1);
    }
    if (StrUtil.isNotEmpty(Global.getTablePrefix())) {
        tableName = tableName.replace(Global.getTablePrefix(), "");
    }
    return StrUtil.upperFirst(StrUtil.toUnderlineCase(tableName));
}
 
Example #16
Source File: GenUtils.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
private static String getProjectPath() {
    String packageName = Global.getPackageName();
    StringBuilder projectPath = new StringBuilder();
    projectPath.append("main/java/");
    projectPath.append(packageName.replace("." , "/"));
    projectPath.append("/");
    return projectPath.toString();
}
 
Example #17
Source File: ResourcesConfig.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    // 文件上传路径
    registry.addResourceHandler("/profile/**").addResourceLocations("file:" + Global.getProfile());

    // swagger配置
    registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
 
Example #18
Source File: ExcelUtil.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取下载路径
 *
 * @param filename 文件名称
 */
private String getAbsoluteFile(String filename) {
    String downloadPath = Global.getDownloadPath() + filename;
    File desc = new File(downloadPath);
    if (!desc.getParentFile().exists()) {
        boolean mkdirs = desc.getParentFile().mkdirs();
        if(mkdirs){
            log.error("获取路径失败");
        }
    }
    return downloadPath;
}
 
Example #19
Source File: SysIndexController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 系统首页
 *
 * @param mmap ModelMap
 * @return
 */
@GetMapping("/index")
public String index(ModelMap mmap,SysUser sysUser) {
    // 根据用户id取出菜单
    List<SysMenu> menus = menuService.selectMenusByUser(sysUser);
    mmap.put("menus", menus);
    mmap.put("user", sysUser);
    mmap.put("copyrightYear", Global.getCopyrightYear());
    mmap.put("demoEnabled", Global.isDemoEnabled());
    return "index";
}
 
Example #20
Source File: SwaggerConfig.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 添加摘要信息
 */
private ApiInfo apiInfo() {
    // 用ApiInfoBuilder进行定制
    return new ApiInfoBuilder()
            .title("标题:若依管理系统_接口文档")
            .description("更多内容请关注:https://github.com/lerry903/RuoYi")
            .contact(new Contact(Global.getName(), "https://github.com/lerry903/RuoYi", "[email protected]"))
            .version("版本号:" + Global.getVersion())
            .build();
}
 
Example #21
Source File: SwaggerConfig.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 添加摘要信息
 */
private ApiInfo apiInfo()
{
    // 用ApiInfoBuilder进行定制
    return new ApiInfoBuilder()
            // 设置标题
            .title("标题:若依管理系统_接口文档")
            // 描述
            .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
            // 作者信息
            .contact(new Contact(Global.getName(), null, null))
            // 版本
            .version("版本号:" + Global.getVersion())
            .build();
}
 
Example #22
Source File: AddressUtils.java    From supplierShop with MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = "XX XX";

    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (Global.isAddressEnabled())
    {
        String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
        if (StringUtils.isEmpty(rspStr))
        {
            log.error("获取地理位置异常 {}", ip);
            return address;
        }
        JSONObject obj;
        try
        {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        }
        catch (Exception e)
        {
            log.error("获取地理位置异常 {}", ip);
        }
    }
    return address;
}
 
Example #23
Source File: ExcelUtil.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 获取下载路径
 * 
 * @param filename 文件名称
 */
public String getAbsoluteFile(String filename)
{
    String downloadPath = Global.getDownloadPath() + filename;
    File desc = new File(downloadPath);
    if (!desc.getParentFile().exists())
    {
        desc.getParentFile().mkdirs();
    }
    return downloadPath;
}
 
Example #24
Source File: CommonController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    try
    {
        if (!FileUtils.isValidFilename(fileName))
        {
            throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
        }
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example #25
Source File: SysIndexController.java    From supplierShop with MIT License 5 votes vote down vote up
@GetMapping("/index")
public String index(ModelMap mmap)
{
    // 取身份信息
    SysUser user = ShiroUtils.getSysUser();
    // 根据用户id取出菜单
    List<SysMenu> menus = menuService.selectMenusByUser(user);
    mmap.put("menus", menus);
    mmap.put("user", user);
    mmap.put("copyrightYear", Global.getCopyrightYear());
    mmap.put("demoEnabled", Global.isDemoEnabled());
    return "index";
}
 
Example #26
Source File: SysProfileController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file)
{
    SysUser currentUser = ShiroUtils.getSysUser();
    try
    {
        if (!file.isEmpty())
        {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            currentUser.setAvatar(avatar);
            if (userService.updateUserInfo(currentUser) > 0)
            {
                ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
                return success();
            }
        }
        return error();
    }
    catch (Exception e)
    {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}
 
Example #27
Source File: GenServiceImpl.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 生成代码
 */
private void generatorCode(TableInfo table, ZipOutputStream zip) {
    // 设置主键
    table.setPrimaryKey(table.getColumnsLast());
    VelocityInitializer.initVelocity();
    String packageName = Global.getPackageName();
    String moduleName = GenUtils.getModuleName(packageName);

    VelocityContext context = GenUtils.getVelocityContext(table);

    // 获取模板列表
    List<String> templates = GenUtils.getTemplates();
    for (String template : templates) {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        try {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(GenUtils.getFileName(template, table, moduleName)));
            IOUtils.write(sw.toString(), zip, Constants.UTF8);
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        } catch (IOException e) {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}
 
Example #28
Source File: GenUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
public static String getProjectPath()
{
    String packageName = Global.getPackageName();
    StringBuffer projectPath = new StringBuffer();
    projectPath.append("main/java/");
    projectPath.append(packageName.replace(".", "/"));
    projectPath.append("/");
    return projectPath.toString();
}
 
Example #29
Source File: ResourcesConfig.java    From ruoyiplus with MIT License 5 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
    /** 文件上传路径 */
    registry.addResourceHandler("/profile/**").addResourceLocations("file:" + Global.getProfile());

    /** swagger配置 */
    registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
 
Example #30
Source File: AddressUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = "XX XX";

    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (Global.isAddressEnabled())
    {
        String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
        if (StringUtils.isEmpty(rspStr))
        {
            log.error("获取地理位置异常 {}", ip);
            return address;
        }
        JSONObject obj;
        try
        {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        }
        catch (Exception e)
        {
            log.error("获取地理位置异常 {}", ip);
        }
    }
    return address;
}