Search in sources :

Example 1 with Template

use of ruangong.root.bean.Template 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 2 with Template

use of ruangong.root.bean.Template in project RG by ADrWondertainment.

the class TemplateServiceImpl method createOrUpdateTemplateByBean.

@Override
public Result createOrUpdateTemplateByBean(Template template, JsonBeanTemplate jsonBeanTemplate) {
    JSONObject data = JSONUtil.parseObj(template.getData());
    String type = jsonBeanTemplate.getType();
    if (!(type.equals("0") || type.equals("1"))) {
        throw new FrontException(ErrorCode.TEMPLATE_DATA_NULL, "模板名称和内容不能为空捏~");
    // ResultUtil.quickSet(
    // result,
    // ErrorCode.TEMPLATE_DATA_NULL,
    // "模板名称和内容不能为空捏~",
    // null
    // );
    // return result;
    }
    QueryWrapper<Template> queryWrapper = Wrappers.query();
    queryWrapper.eq("name", template.getName());
    Template uniqueCheck = templateMapper.selectOne(queryWrapper);
    if (uniqueCheck != null) {
        throw new FrontException(ErrorCode.TEMPLATE_NAME_DUPLICATED, "模板重名了捏,请重新起一个名字~");
    // ResultUtil.quickSet(
    // result,
    // ErrorCode.TEMPLATE_NAME_DUPLICATED,
    // "模板重名了捏,请重新起一个名字~",
    // null
    // );
    // return result;
    }
    boolean isUpdated = saveOrUpdate(template);
    if (!isUpdated) {
        throw new BackException(ErrorCode.TEMPLATE_INSERT_FAILURE, "添加或者修改失败了捏,请稍后再试~");
    // ResultUtil.quickSet(
    // result,
    // ErrorCode.TEMPLATE_INSERT_FAILURE,
    // "添加或者修改失败了捏,请稍后再试~",
    // null
    // );
    // return result;
    }
    ResultUtil.quickSet(result, ErrorCode.TEMPLATE_INSERT_SUCCESS, "模板添加/修改成功了捏~", JSONUtil.toJsonPrettyStr(JSONUtil.createObj().putOnce("isSuccess", true)));
    return result;
}
Also used : JSONObject(cn.hutool.json.JSONObject) FrontException(ruangong.root.exception.FrontException) BackException(ruangong.root.exception.BackException) JsonBeanTemplate(ruangong.root.bean.JsonBeanTemplate) Template(ruangong.root.bean.Template)

Example 3 with Template

use of ruangong.root.bean.Template in project RG by ADrWondertainment.

the class TemplateServiceImpl method getTemplateById.

@Override
public Result getTemplateById(Integer id) {
    QueryWrapper<Template> query = Wrappers.query();
    query.eq("id", id);
    Template template = templateMapper.selectOne(query);
    if (template == null) {
        throw new BackException(ErrorCode.TEMPLATE_SELECT_FAILURE, "没有对应id的模板");
    }
    ResultUtil.quickSet(result, ErrorCode.ALL_SET, "获取成功", JSONUtil.toJsonPrettyStr(template));
    return result;
}
Also used : BackException(ruangong.root.exception.BackException) JsonBeanTemplate(ruangong.root.bean.JsonBeanTemplate) Template(ruangong.root.bean.Template)

Example 4 with Template

use of ruangong.root.bean.Template in project RG by ADrWondertainment.

the class TemplateUtil method jsonBeanToTemplate.

public static Template jsonBeanToTemplate(JsonBeanTemplate jsonBeanTemplate) {
    Template template = new Template();
    template.setUid(jsonBeanTemplate.getUid());
    template.setDescription(jsonBeanTemplate.getDescription());
    template.setName(jsonBeanTemplate.getName());
    template.setTime(new Date());
    template.setData(JSONUtil.toJsonPrettyStr(jsonBeanTemplate));
    template.setLength(jsonBeanTemplate.getContentLength());
    return template;
}
Also used : Date(java.util.Date) JsonBeanTemplate(ruangong.root.bean.JsonBeanTemplate) Template(ruangong.root.bean.Template)

Aggregations

JsonBeanTemplate (ruangong.root.bean.JsonBeanTemplate)4 Template (ruangong.root.bean.Template)4 BackException (ruangong.root.exception.BackException)3 JSONArray (cn.hutool.json.JSONArray)1 JSONObject (cn.hutool.json.JSONObject)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TemplateTransfer (ruangong.root.bean.TemplateTransfer)1 FrontException (ruangong.root.exception.FrontException)1