Search in sources :

Example 46 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class CaptchaController method getCode.

/**
 * 生成验证码
 */
@GetMapping("/captchaImage")
public AjaxResult getCode(HttpServletResponse response) throws IOException {
    AjaxResult ajax = AjaxResult.success();
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    ajax.put("captchaOnOff", captchaOnOff);
    if (!captchaOnOff) {
        return ajax;
    }
    // 保存验证码信息
    String uuid = IdUtils.simpleUUID();
    String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
    String capStr = null, code = null;
    BufferedImage image = null;
    // 生成验证码
    String captchaType = RuoYiConfig.getCaptchaType();
    if ("math".equals(captchaType)) {
        String capText = captchaProducerMath.createText();
        capStr = capText.substring(0, capText.lastIndexOf("@"));
        code = capText.substring(capText.lastIndexOf("@") + 1);
        image = captchaProducerMath.createImage(capStr);
    } else if ("char".equals(captchaType)) {
        capStr = code = captchaProducer.createText();
        image = captchaProducer.createImage(capStr);
    }
    redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
    // 转换流信息写出
    FastByteArrayOutputStream os = new FastByteArrayOutputStream();
    try {
        ImageIO.write(image, "jpg", os);
    } catch (IOException e) {
        return AjaxResult.error(e.getMessage());
    }
    ajax.put("uuid", uuid);
    ajax.put("img", Base64.encode(os.toByteArray()));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) FastByteArrayOutputStream(org.springframework.util.FastByteArrayOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 47 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class CacheController method getInfo.

@PreAuthorize("@ss.hasPermi('monitor:cache:list')")
@GetMapping()
public AjaxResult getInfo() throws Exception {
    Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info());
    Properties commandStats = (Properties) redisTemplate.execute((RedisCallback<Object>) connection -> connection.info("commandstats"));
    Object dbSize = redisTemplate.execute((RedisCallback<Object>) connection -> connection.dbSize());
    Map<String, Object> result = new HashMap<>(3);
    result.put("info", info);
    result.put("dbSize", dbSize);
    List<Map<String, String>> pieList = new ArrayList<>();
    commandStats.stringPropertyNames().forEach(key -> {
        Map<String, String> data = new HashMap<>(2);
        String property = commandStats.getProperty(key);
        data.put("name", StringUtils.removeStart(key, "cmdstat_"));
        data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
        pieList.add(data);
    });
    result.put("commandStats", pieList);
    return AjaxResult.success(result);
}
Also used : Properties(java.util.Properties) RedisCallback(org.springframework.data.redis.core.RedisCallback) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) RestController(org.springframework.web.bind.annotation.RestController) AjaxResult(com.ruoyi.common.core.domain.AjaxResult) ArrayList(java.util.ArrayList) List(java.util.List) StringUtils(com.ruoyi.common.utils.StringUtils) Map(java.util.Map) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) GetMapping(org.springframework.web.bind.annotation.GetMapping) HashMap(java.util.HashMap) RedisCallback(org.springframework.data.redis.core.RedisCallback) ArrayList(java.util.ArrayList) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class SysDeptController method roleDeptTreeselect.

/**
 * 加载对应角色部门列表树
 */
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
    List<SysDept> depts = deptService.selectDeptList(new SysDept());
    AjaxResult ajax = AjaxResult.success();
    ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
    ajax.put("depts", deptService.buildDeptTreeSelect(depts));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysDept(com.ruoyi.common.core.domain.entity.SysDept) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 49 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project RuoYi-Vue by yangzongzhuan.

the class SysLoginController method login.

/**
 * 登录方法
 *
 * @param loginBody 登录信息
 * @return 结果
 */
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) {
    AjaxResult ajax = AjaxResult.success();
    // 生成令牌
    String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid());
    ajax.put(Constants.TOKEN, token);
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 50 with AjaxResult

use of com.ruoyi.common.core.domain.AjaxResult in project hocassian-media-matrix by hokaso.

the class SysDeptController method roleDeptTreeselect.

/**
 * 加载对应角色部门列表树
 */
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
    List<SysDept> depts = deptService.selectDeptList(new SysDept());
    AjaxResult ajax = AjaxResult.success();
    ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
    ajax.put("depts", deptService.buildDeptTreeSelect(depts));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysDept(com.ruoyi.common.core.domain.entity.SysDept) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AjaxResult (com.ruoyi.common.core.domain.AjaxResult)55 GetMapping (org.springframework.web.bind.annotation.GetMapping)25 PostMapping (org.springframework.web.bind.annotation.PostMapping)16 SysUser (com.ruoyi.common.core.domain.entity.SysUser)12 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)10 Log (com.ruoyi.common.annotation.Log)8 StringUtils (com.ruoyi.common.utils.StringUtils)7 List (java.util.List)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 RestController (org.springframework.web.bind.annotation.RestController)7 MultipartFile (org.springframework.web.multipart.MultipartFile)7 SysUser (com.ruoyi.system.domain.SysUser)6 UserConstants (com.ruoyi.common.constant.UserConstants)5 BaseController (com.ruoyi.common.core.controller.BaseController)5 SysRole (com.ruoyi.common.core.domain.entity.SysRole)5 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)5 BusinessType (com.ruoyi.common.enums.BusinessType)5 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)5