use of ruangong.root.bean.JsonBeanTemplate 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.JsonBeanTemplate in project RG by ADrWondertainment.
the class TemplateController method createOrUpdateTemplate.
@PostMapping
public Result createOrUpdateTemplate(@RequestBody String data, HttpServletRequest request) {
JSONObject entries = JSONUtil.parseObj(data);
String json = (String) entries.get("json");
if (json == null) {
throw new FrontException(ErrorCode.FRONT_DATA_IRREGULAR, "前端数据格式未按照规范");
}
try {
jsonBeanTemplate = JSONUtil.toBean(json, JsonBeanTemplate.class);
template = TemplateUtil.strToTemplate(json);
} catch (Exception e) {
throw new BackException(ErrorCode.UTIL_ERROR, "工具类出错");
}
String email = (String) request.getSession().getAttribute("email");
if (email == null) {
throw new BackException(ErrorCode.USER_ILLEGAL_ACCESS, "用户未登录");
}
Result result1 = userService.GetUserByEmail(email);
User user = (User) result1.getData();
template.setUid(user.getId());
jsonBeanTemplate.setUid(user.getId());
template.setData(JSONUtil.toJsonPrettyStr(jsonBeanTemplate));
result = templateService.createOrUpdateTemplateByBean(template, jsonBeanTemplate);
System.out.println(result);
return result;
}
use of ruangong.root.bean.JsonBeanTemplate 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