|
@@ -3,20 +3,31 @@ package com.redxun.knowledge.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.redxun.common.base.db.BaseDao;
|
|
|
import com.redxun.common.base.db.BaseService;
|
|
|
+import com.redxun.common.model.JPaasUser;
|
|
|
import com.redxun.common.tool.IdGenerator;
|
|
|
import com.redxun.common.service.impl.SuperServiceImpl;
|
|
|
+import com.redxun.common.tool.StringUtils;
|
|
|
+import com.redxun.common.utils.ExceptionUtil;
|
|
|
+import com.redxun.common.utils.SysUserUtil;
|
|
|
import com.redxun.knowledge.entity.dao.KnowledgeLabel;
|
|
|
import com.redxun.knowledge.mapper.KnowledgeLabelMapper;
|
|
|
+import freemarker.template.ObjectWrapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
/**
|
|
|
-* [业务--知识标签表]业务服务类
|
|
|
-*/
|
|
|
+ * [业务--知识标签表]业务服务类
|
|
|
+ */
|
|
|
@Service
|
|
|
public class KnowledgeLabelServiceImpl extends SuperServiceImpl<KnowledgeLabelMapper, KnowledgeLabel> implements BaseService<KnowledgeLabel> {
|
|
|
|
|
@@ -28,4 +39,48 @@ public class KnowledgeLabelServiceImpl extends SuperServiceImpl<KnowledgeLabelMa
|
|
|
return knowledgeLabelMapper;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增/修改标签数据
|
|
|
+ *
|
|
|
+ * @param id 标签ID
|
|
|
+ * @param name 标签名称
|
|
|
+ * @param sort 标签排序
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public KnowledgeLabel saveOrUpdateTags(String id, String name, Integer sort) {
|
|
|
+ KnowledgeLabel knowledgeLabel = new KnowledgeLabel();
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ knowledgeLabel.setPkId(IdGenerator.getIdStr());
|
|
|
+ knowledgeLabel.setCreateBy(queryLoginUser());
|
|
|
+ knowledgeLabel.setCreateTime(new Date());
|
|
|
+ } else {
|
|
|
+ knowledgeLabel.setPkId(id);
|
|
|
+ knowledgeLabel.setUpdateBy(queryLoginUser());
|
|
|
+ knowledgeLabel.setCreateTime(new Date());
|
|
|
+ }
|
|
|
+ knowledgeLabel.setName(name);
|
|
|
+ knowledgeLabel.setSort(sort);
|
|
|
+ // 更新sort
|
|
|
+ knowledgeLabelMapper.adjustSort(sort);
|
|
|
+ if (saveOrUpdate(knowledgeLabel)) {
|
|
|
+ return knowledgeLabelMapper.selectById(knowledgeLabel.getPkId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String queryLoginUser() {
|
|
|
+ String loginUserId = null;
|
|
|
+ try {
|
|
|
+ JPaasUser jPaasUser = SysUserUtil.getLoginUser();
|
|
|
+ if (jPaasUser == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ loginUserId = jPaasUser.getUserId();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(ExceptionUtil.getExceptionMessage(e));
|
|
|
+ }
|
|
|
+ return loginUserId;
|
|
|
+ }
|
|
|
}
|