Search in sources :

Example 1 with BackException

use of ruangong.root.exception.BackException in project RG by ADrWondertainment.

the class PageUtil method getPageInfo.

/*
        {
            "pageNum":1,
            "size":5
        }

     */
public static HashMap<String, Integer> getPageInfo(JSONObject jsonObject, HttpServletRequest httpServletRequest, UserService userService) {
    String email = (String) httpServletRequest.getSession().getAttribute("email");
    if (email == null) {
        throw new BackException(ErrorCode.USER_ILLEGAL_ACCESS, "用户未登录");
    }
    Result result = userService.GetUserByEmail(email);
    User user = (User) result.getData();
    Integer id = user.getId();
    Integer pageNum = (Integer) jsonObject.get("pageNum");
    Integer size = (Integer) jsonObject.get("size");
    HashMap<String, Integer> map = new HashMap<>();
    map.put("id", id);
    map.put("pageIndex", pageNum);
    map.put("sizePerPage", size);
    return map;
}
Also used : User(ruangong.root.bean.User) BackException(ruangong.root.exception.BackException) HashMap(java.util.HashMap) Result(ruangong.root.bean.Result)

Example 2 with BackException

use of ruangong.root.exception.BackException in project RG by ADrWondertainment.

the class AnswerServiceImpl method getAnswersByUserID.

@Override
public Result getAnswersByUserID(Integer id, Integer pageNum, Integer size) {
    IPage<Answer> page = new Page(pageNum, size);
    QueryWrapper<Answer> query = Wrappers.query();
    query.eq("uid", id);
    IPage<Answer> answerIPage = answerMapper.selectPage(page, query);
    if (answerIPage == null) {
        throw new BackException(ErrorCode.TEMPLATE_SELECT_FAILURE, "分页数据查询失败");
    }
    List<Answer> records = answerIPage.getRecords();
    JSONArray jsonArray = JSONUtil.parseArray(records);
    System.out.println(JSONUtil.toJsonPrettyStr(jsonArray));
    ResultUtil.quickSet(result, ErrorCode.ALL_SET, "查询成功", JSONUtil.toJsonPrettyStr(jsonArray));
    return result;
}
Also used : BackException(ruangong.root.exception.BackException) JSONArray(cn.hutool.json.JSONArray) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 3 with BackException

use of ruangong.root.exception.BackException in project RG by ADrWondertainment.

the class SheetServiceImpl method getSheetsInPages.

@Override
public Result getSheetsInPages(Integer id, Integer pageIndex, Integer sizePerPage) {
    IPage<Sheet> page = new Page(pageIndex, sizePerPage);
    QueryWrapper<Sheet> query = Wrappers.query();
    query.eq("uid", id);
    IPage<Sheet> sheetIPage = sheetMapper.selectPage(page, query);
    if (sheetIPage == null) {
        throw new BackException(ErrorCode.SHEET_SELECT_FAILURE, "分页数据查询失败");
    }
    JSONArray jsonArray = JSONUtil.parseArray(sheetIPage.getRecords());
    ResultUtil.quickSet(result, ErrorCode.ALL_SET, "查询成功", JSONUtil.toJsonPrettyStr(jsonArray));
    return result;
}
Also used : BackException(ruangong.root.exception.BackException) JSONArray(cn.hutool.json.JSONArray) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 4 with BackException

use of ruangong.root.exception.BackException in project RG by ADrWondertainment.

the class TemplateServiceImpl method getTemplatesInPages.

@Override
public Result getTemplatesInPages(Integer id, Integer pageNum, Integer size) {
    IPage<Template> page = new Page(pageNum, size);
    QueryWrapper<Template> query = Wrappers.query();
    query.eq("uid", id);
    IPage<Template> templateIPage = templateMapper.selectPage(page, query);
    if (templateIPage == null) {
        throw new BackException(ErrorCode.TEMPLATE_SELECT_FAILURE, "分页数据查询失败");
    }
    List<Template> records = templateIPage.getRecords();
    List<TemplateTransfer> transfers = new ArrayList<>();
    for (Template t : records) {
        TemplateTransfer temp = new TemplateTransfer();
        temp.setId(t.getId());
        temp.setUid(t.getUid());
        temp.setName(t.getName());
        temp.setTime(t.getTime());
        temp.setLength(t.getLength());
        temp.setDescription(t.getDescription());
        temp.setData(JSONUtil.parseObj(t.getData()));
        transfers.add(temp);
    }
    JSONArray jsonArray = JSONUtil.parseArray(transfers);
    ResultUtil.quickSet(result, ErrorCode.ALL_SET, "查询成功", JSONUtil.toJsonPrettyStr(jsonArray));
    return result;
}
Also used : BackException(ruangong.root.exception.BackException) TemplateTransfer(ruangong.root.bean.TemplateTransfer) ArrayList(java.util.ArrayList) JSONArray(cn.hutool.json.JSONArray) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) JsonBeanTemplate(ruangong.root.bean.JsonBeanTemplate) Template(ruangong.root.bean.Template)

Example 5 with BackException

use of ruangong.root.exception.BackException in project RG by ADrWondertainment.

the class UserServiceImpl method GetUserByEmail.

@Override
public Result GetUserByEmail(String email) {
    QueryWrapper<User> wrapper = new QueryWrapper<>();
    wrapper.eq("email", email);
    User user_result = userMapper.selectOne(wrapper);
    if (user_result == null) {
        throw new BackException(ErrorCode.USER_NAME_UNFINDED, "该用户不存在");
    }
    // if (user_result == null) {
    // ResultUtil.quickSet(
    // result,
    // ErrorCode.USER_NAME_UNFINDED,
    // "该用户不存在",
    // null
    // );
    // return result;
    // }
    ResultUtil.quickSet(result, ErrorCode.SUCCESS, "查询成功", user_result);
    return result;
}
Also used : User(ruangong.root.bean.User) BackException(ruangong.root.exception.BackException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Aggregations

BackException (ruangong.root.exception.BackException)11 JSONArray (cn.hutool.json.JSONArray)4 JsonBeanTemplate (ruangong.root.bean.JsonBeanTemplate)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 Template (ruangong.root.bean.Template)3 User (ruangong.root.bean.User)3 FrontException (ruangong.root.exception.FrontException)3 JSONObject (cn.hutool.json.JSONObject)2 Result (ruangong.root.bean.Result)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpSession (javax.servlet.http.HttpSession)1 TemplateTransfer (ruangong.root.bean.TemplateTransfer)1