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;
}
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;
}
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;
}
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;
}
Aggregations