1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix TagRepository related class

This commit is contained in:
dengchao@xgtl 2020-04-17 10:34:08 +08:00
parent 3b039cce3c
commit 226171df3d
8 changed files with 318 additions and 339 deletions

View File

@ -19,24 +19,22 @@ package com.chatopera.cc.controller.api;
import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.controller.api.request.RestUtils;
import com.chatopera.cc.exception.CSKefuRestException;
import com.chatopera.cc.model.Tag;
import com.chatopera.cc.model.TagRelation;
import com.chatopera.cc.persistence.repository.TagRelationRepository;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.persistence.repository.UserRepository;
import com.chatopera.cc.util.Menu;
import com.chatopera.cc.util.json.GsonTools;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -51,26 +49,20 @@ import java.util.List;
*/
@RestController
@RequestMapping("/api/contacts/tags")
@RequiredArgsConstructor
public class ApiContactTagsController extends Handler {
private static final Logger logger = LoggerFactory.getLogger(ApiContactTagsController.class);
private static final String TAGTYPE_USER = "user";
@NonNull
private final TagRepository tagRes;
@Autowired
private TagRepository tagRes;
@Autowired
private TagRelationRepository tagRelationRes;
@Autowired
private UserRepository userRes;
@NonNull
private final TagRelationRepository tagRelationRes;
/**
* 获取联系人标签
*
* @param j
* @return
*/
private JsonObject fetch(JsonObject j) {
JsonObject resp = new JsonObject();
@ -78,7 +70,7 @@ public class ApiContactTagsController extends Handler {
String contactid = j.get("contactid").getAsString();
// 获取联系人所有标签
List<TagRelation> rels = tagRelationRes.findByUserid(contactid);
HashMap<String, String> tagged = new HashMap<String, String>();
HashMap<String, String> tagged = new HashMap<>();
for (TagRelation t : rels) {
tagged.put(t.getTagid(), t.getId());
@ -114,9 +106,6 @@ public class ApiContactTagsController extends Handler {
/**
* 创建联系人标签关系
*
* @param j
* @return
*/
private JsonObject create(JsonObject j) {
JsonObject resp = new JsonObject();
@ -135,9 +124,8 @@ public class ApiContactTagsController extends Handler {
final String tagId = j.get("tagId").getAsString();
final String contactid = j.get("contactid").getAsString();
Tag tag = tagRes.findOne(tagId);
if (tag == null) {
if (!tagRes.existsById(tagId)) {
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_2);
resp.addProperty(RestUtils.RESP_KEY_ERROR, "不存在该标签。");
return resp;
@ -161,9 +149,6 @@ public class ApiContactTagsController extends Handler {
/**
* 去掉标签
*
* @param j
* @return
*/
private JsonObject remove(JsonObject j) {
JsonObject resp = new JsonObject();
@ -173,14 +158,14 @@ public class ApiContactTagsController extends Handler {
return resp;
}
TagRelation t = tagRelationRes.findOne(j.get("xid").getAsString());
if (t == null) {
String tagId = j.get("xid").getAsString();
if (!tagRelationRes.existsById(tagId)) {
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_4);
resp.addProperty(RestUtils.RESP_KEY_ERROR, "该联系人没有打这个标签。");
return resp;
}
tagRelationRes.delete(t);
tagRelationRes.deleteById(tagId);
JsonObject data = new JsonObject();
data.addProperty("msg", "删除成功。");
resp.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_SUCC);
@ -191,8 +176,8 @@ public class ApiContactTagsController extends Handler {
@RequestMapping(method = RequestMethod.POST)
@Menu(type = "apps", subtype = "contacttags", access = true)
public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body) throws CSKefuRestException, GsonTools.JsonObjectExtensionConflictException {
final JsonObject j = (new JsonParser()).parse(body).getAsJsonObject();
public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body) {
final JsonObject j = JsonParser.parseString(body).getAsJsonObject();
logger.info("[contact tags] operations payload {}", j.toString());
JsonObject json = new JsonObject();
HttpHeaders headers = RestUtils.header();
@ -219,7 +204,7 @@ public class ApiContactTagsController extends Handler {
break;
}
}
return new ResponseEntity<String>(json.toString(), headers, HttpStatus.OK);
return new ResponseEntity<>(json.toString(), headers, HttpStatus.OK);
}
}

View File

@ -18,24 +18,23 @@ package com.chatopera.cc.controller.api;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.controller.api.request.RestUtils;
import com.chatopera.cc.exception.CSKefuRestException;
import com.chatopera.cc.model.Tag;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.util.Menu;
import com.chatopera.cc.util.json.GsonTools;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -49,18 +48,15 @@ import javax.servlet.http.HttpServletRequest;
*/
@RestController
@RequestMapping("/api/repo/tags")
@RequiredArgsConstructor
public class ApiTagsController extends Handler {
private static final Logger logger = LoggerFactory.getLogger(ApiTagsController.class);
@Autowired
private TagRepository tagRes;
@NonNull
private final TagRepository tagRes;
/**
* 获取标签
*
* @param j
* @param request
* @return
*/
private JsonObject fetch(final JsonObject j, final HttpServletRequest request) {
JsonObject resp = new JsonObject();
@ -97,17 +93,11 @@ public class ApiTagsController extends Handler {
/**
* 联系人标签
*
* @param request
* @param body
* @return
* @throws CSKefuRestException
* @throws GsonTools.JsonObjectExtensionConflictException
*/
@RequestMapping(method = RequestMethod.POST)
@Menu(type = "apps", subtype = "tags", access = true)
public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body) throws CSKefuRestException, GsonTools.JsonObjectExtensionConflictException {
final JsonObject j = (new JsonParser()).parse(body).getAsJsonObject();
public ResponseEntity<String> operations(HttpServletRequest request, @RequestBody final String body) {
final JsonObject j = JsonParser.parseString(body).getAsJsonObject();
logger.info("[contact tags] operations payload {}", j.toString());
JsonObject json = new JsonObject();
HttpHeaders headers = RestUtils.header();
@ -118,17 +108,14 @@ public class ApiTagsController extends Handler {
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_1);
json.addProperty(RestUtils.RESP_KEY_ERROR, "不合法的请求参数。");
} else {
switch (StringUtils.lowerCase(j.get("ops").getAsString())) {
case "fetch":
json = fetch(j, request);
break;
default:
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3);
json.addProperty(RestUtils.RESP_KEY_ERROR, "不支持的操作。");
break;
if ("fetch".equals(StringUtils.lowerCase(j.get("ops").getAsString()))) {
json = fetch(j, request);
} else {
json.addProperty(RestUtils.RESP_KEY_RC, RestUtils.RESP_RC_FAIL_3);
json.addProperty(RestUtils.RESP_KEY_ERROR, "不支持的操作。");
}
}
return new ResponseEntity<String>(json.toString(), headers, HttpStatus.OK);
return new ResponseEntity<>(json.toString(), headers, HttpStatus.OK);
}
}

View File

@ -1,59 +1,60 @@
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.controller.api;
import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.util.Menu;
import com.chatopera.cc.util.RestResult;
import com.chatopera.cc.util.RestResultType;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
* 标签功能
* 获取分类标签
*/
@RestController
@RequestMapping("/api/tags")
public class UkefuApiTagsController extends Handler {
@Autowired
private TagRepository tagRes;
/**
* 按照分类获取标签列表
* 按照分类获取标签列表Type 参数类型来自于 枚举可选值目前有三个 user workorders summary
* @param request
* @param type 类型
* @return
*/
@RequestMapping( method = RequestMethod.GET)
@Menu(type = "apps" , subtype = "tags" , access = true)
public ResponseEntity<RestResult> list(HttpServletRequest request , @Valid String type) {
return new ResponseEntity<>(new RestResult(RestResultType.OK, tagRes.findByOrgiAndTagtype(super.getOrgi(request) , !StringUtils.isBlank(type) ? type : MainContext.ModelType.USER.toString())), HttpStatus.OK);
}
}
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.controller.api;
import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.controller.Handler;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.util.Menu;
import com.chatopera.cc.util.RestResult;
import com.chatopera.cc.util.RestResultType;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
* 标签功能
* 获取分类标签
*/
@RestController
@RequestMapping("/api/tags")
@RequiredArgsConstructor
public class UkefuApiTagsController extends Handler {
@NonNull
private final TagRepository tagRes;
/**
* 按照分类获取标签列表
* 按照分类获取标签列表Type 参数类型来自于 枚举可选值目前有三个 user workorders summary
*
* @param type 类型
*/
@RequestMapping(method = RequestMethod.GET)
@Menu(type = "apps", subtype = "tags", access = true)
public ResponseEntity<RestResult> list(HttpServletRequest request, @Valid String type) {
return new ResponseEntity<>(new RestResult(RestResultType.OK, tagRes.findByOrgiAndTagtype(super.getOrgi(request), !StringUtils.isBlank(type) ? type : MainContext.ModelType.USER.toString())), HttpStatus.OK);
}
}

View File

@ -29,7 +29,8 @@ import com.chatopera.cc.persistence.repository.QualityRepository;
import com.chatopera.cc.persistence.repository.SessionConfigRepository;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.util.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@ -42,22 +43,23 @@ import java.util.List;
@Controller
@RequestMapping("/apps/quality")
@RequiredArgsConstructor
public class AgentQualityController extends Handler {
@Autowired
private ACDPolicyService acdPolicyService;
@NonNull
private final ACDPolicyService acdPolicyService;
@Autowired
private QualityRepository qualityRes;
@NonNull
private final QualityRepository qualityRes;
@Autowired
private SessionConfigRepository sessionConfigRes;
@NonNull
private final SessionConfigRepository sessionConfigRes;
@Autowired
private TagRepository tagRes;
@NonNull
private final TagRepository tagRes;
@Autowired
private Cache cache;
@NonNull
private final Cache cache;
@RequestMapping(value = "/index")
@Menu(type = "agent", subtype = "quality")
@ -71,13 +73,13 @@ public class AgentQualityController extends Handler {
@RequestMapping(value = "/save")
@Menu(type = "agent", subtype = "quality")
public ModelAndView save(ModelMap map, HttpServletRequest request, @Valid QualityRequest qualityArray) {
String orgi = super.getOrgi(request);
public ModelAndView save(HttpServletRequest request, @Valid QualityRequest qualityArray) {
String orgi = super.getOrgi(request);
if (qualityArray != null && qualityArray.getTitle() != null) {
List<Quality> qualityList = qualityRes.findByQualitytypeAndOrgi(MainContext.QualityType.CHAT.toString(), super.getOrgi(request));
qualityRes.delete(qualityList);
List<Quality> tempList = new ArrayList<Quality>();
qualityRes.deleteAll(qualityList);
List<Quality> tempList = new ArrayList<>();
for (int i = 0; i < qualityArray.getTitle().length; i++) {
Quality temp = new Quality();
temp.setName(qualityArray.getTitle()[i]);
@ -92,7 +94,7 @@ public class AgentQualityController extends Handler {
tempList.add(temp);
}
if (tempList.size() > 0) {
qualityRes.save(tempList);
qualityRes.saveAll(tempList);
}
SessionConfig config = acdPolicyService.initSessionConfig(super.getOrgi(request));
if (config != null) {
@ -106,12 +108,12 @@ public class AgentQualityController extends Handler {
cache.putSessionConfigByOrgi(config, orgi);
cache.deleteSessionConfigListByOrgi(orgi);
}
if (qualityArray != null && qualityArray.getTag() != null && qualityArray.getTag().length > 0) {
if (qualityArray.getTag() != null && qualityArray.getTag().length > 0) {
List<Tag> tagList = tagRes.findByOrgiAndTagtype(super.getOrgi(request), MainContext.TagType.QUALITY.toString());
if (tagList.size() > 0) {
tagRes.delete(tagList);
tagRes.deleteAll(tagList);
}
List<Tag> tagTempList = new ArrayList<Tag>();
List<Tag> tagTempList = new ArrayList<>();
for (String tag : qualityArray.getTag()) {
Tag temp = new Tag();
temp.setOrgi(super.getOrgi(request));
@ -122,7 +124,7 @@ public class AgentQualityController extends Handler {
tagTempList.add(temp);
}
if (tagTempList.size() > 0) {
tagRes.save(tagTempList);
tagRes.saveAll(tagTempList);
}
}
}

View File

@ -28,10 +28,11 @@ import com.chatopera.cc.persistence.repository.AttachmentRepository;
import com.chatopera.cc.persistence.repository.KbsTypeRepository;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.util.Menu;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@ -47,132 +48,134 @@ import java.util.Date;
@Controller
@RequestMapping({"/apps/kbs"})
@RequiredArgsConstructor
public class KbsController extends Handler {
@Autowired
private TagRepository tagRes;
@NonNull
private final TagRepository tagRes;
@Autowired
private KbsTypeRepository kbsTypeRes;
@NonNull
private final KbsTypeRepository kbsTypeRes;
@Autowired
private KbsTopicRepository kbsTopicRes;
@NonNull
private final KbsTopicRepository kbsTopicRes;
@Autowired
private AttachmentRepository attachementRes;
@NonNull
private final AttachmentRepository attachementRes;
@Value("${web.upload-path}")
private String path;
@Value("${web.upload-path}")
private String path;
@RequestMapping({"/index"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView index(ModelMap map, HttpServletRequest request) {
return request(super.createAppsTempletResponse("/apps/business/kbs/index"));
}
@RequestMapping({"/index"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView index() {
return request(super.createAppsTempletResponse("/apps/business/kbs/index"));
}
@RequestMapping({"/list"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView list(ModelMap map, HttpServletRequest request) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
return request(super.createAppsTempletResponse("/apps/business/kbs/list"));
}
@RequestMapping({"/list"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView list(ModelMap map, HttpServletRequest request) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
return request(super.createAppsTempletResponse("/apps/business/kbs/list"));
}
@RequestMapping({"/list/type"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView listtype(ModelMap map, HttpServletRequest request, @Valid String typeid) {
if (!StringUtils.isBlank(typeid) && !typeid.equals("0")) {
map.addAttribute("kbsType", kbsTypeRes.findByIdAndOrgi(typeid, super.getOrgi(request)));
}
return request(super.createRequestPageTempletResponse("/apps/business/kbs/typelist"));
}
@RequestMapping({"/list/type"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView listtype(ModelMap map, HttpServletRequest request, @Valid String typeid) {
if (!StringUtils.isBlank(typeid) && !typeid.equals("0")) {
map.addAttribute("kbsType", kbsTypeRes.findByIdAndOrgi(typeid, super.getOrgi(request)));
}
return request(super.createRequestPageTempletResponse("/apps/business/kbs/typelist"));
}
@RequestMapping({"/addtype"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView addtype(ModelMap map, HttpServletRequest request) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
return request(super.createRequestPageTempletResponse("/apps/business/kbs/addtype"));
}
@RequestMapping({"/addtype"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView addtype(ModelMap map, HttpServletRequest request) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
return request(super.createRequestPageTempletResponse("/apps/business/kbs/addtype"));
}
@RequestMapping("/type/save")
@Menu(type = "apps", subtype = "kbs")
public ModelAndView typesave(HttpServletRequest request, @Valid KbsType kbsType) {
int count = kbsTypeRes.countByOrgiAndNameAndParentid(super.getOrgi(request), kbsType.getName(), kbsType.getParentid());
if (count == 0) {
kbsType.setOrgi(super.getOrgi(request));
kbsType.setCreater(super.getUser(request).getId());
kbsType.setCreatetime(new Date());
kbsTypeRes.save(kbsType);
}
return request(super.createRequestPageTempletResponse("redirect:/apps/kbs/list.html"));
}
@RequestMapping("/type/save")
@Menu(type = "apps", subtype = "kbs")
public ModelAndView typesave(HttpServletRequest request, @Valid KbsType kbsType) {
int count = kbsTypeRes.countByOrgiAndNameAndParentid(super.getOrgi(request), kbsType.getName(), kbsType.getParentid());
if (count == 0) {
kbsType.setOrgi(super.getOrgi(request));
kbsType.setCreater(super.getUser(request).getId());
kbsType.setCreatetime(new Date());
kbsTypeRes.save(kbsType);
}
return request(super.createRequestPageTempletResponse("redirect:/apps/kbs/list.html"));
}
@RequestMapping({"/add"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String typeid) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
map.addAttribute("tags", tagRes.findByOrgiAndTagtype(super.getOrgi(request), MainContext.ModelType.KBS.toString()));
if (!StringUtils.isBlank(typeid) && !typeid.equals("0")) {
map.addAttribute("kbsType", kbsTypeRes.findByIdAndOrgi(typeid, super.getOrgi(request)));
}
return request(super.createRequestPageTempletResponse("/apps/business/kbs/add"));
}
@RequestMapping({"/add"})
@Menu(type = "apps", subtype = "kbs")
public ModelAndView add(ModelMap map, HttpServletRequest request, @Valid String typeid) {
map.addAttribute("kbsTypeResList", kbsTypeRes.findByOrgi(super.getOrgi(request)));
map.addAttribute("tags", tagRes.findByOrgiAndTagtype(super.getOrgi(request), MainContext.ModelType.KBS.toString()));
if (!StringUtils.isBlank(typeid) && !typeid.equals("0")) {
map.addAttribute("kbsType", kbsTypeRes.findByIdAndOrgi(typeid, super.getOrgi(request)));
}
return request(super.createRequestPageTempletResponse("/apps/business/kbs/add"));
}
@RequestMapping("/save")
@Menu(type = "topic", subtype = "save")
public ModelAndView save(HttpServletRequest request,
final @Valid KbsTopic topic,
@RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/apps/kbs/index.html"));
topic.setOrgi(super.getOrgi(request));
topic.setCreater(super.getUser(request).getId());
topic.setUsername(super.getUser(request).getUsername());
@RequestMapping("/save")
@Menu(type = "topic", subtype = "save")
public ModelAndView save(HttpServletRequest request,
final @Valid KbsTopic topic,
@RequestParam(value = "files", required = false) MultipartFile[] files) throws IOException {
ModelAndView view = request(super.createRequestPageTempletResponse("redirect:/apps/kbs/index.html"));
topic.setOrgi(super.getOrgi(request));
topic.setCreater(super.getUser(request).getId());
topic.setUsername(super.getUser(request).getUsername());
processAttachmentFile(files, topic, request, topic.getId(), topic.getId());
processAttachmentFile(files, topic, request, topic.getId(), topic.getId());
KbsType workOrderType = kbsTypeRes.findByIdAndOrgi(topic.getTptype(), super.getOrgi(request));
// 知识处理流程如果知识分类需要审批则触发知识流程
topic.setApproval(!workOrderType.isApproval());
kbsTopicRes.save(topic);
return view;
}
KbsType workOrderType = kbsTypeRes.findByIdAndOrgi(topic.getTptype(), super.getOrgi(request));
// 知识处理流程如果知识分类需要审批则触发知识流程
topic.setApproval(!workOrderType.isApproval());
kbsTopicRes.save(topic);
return view;
}
private void processAttachmentFile(MultipartFile[] files, KbsTopic topic, HttpServletRequest request, String dataid, String modelid) throws IOException {
if (files != null && files.length > 0) {
topic.setAttachment(""); //序列化 附件文件方便显示避免多一次查询 附件的操作
//保存附件
for (MultipartFile file : files) {
if (file.getSize() > 0) { //文件尺寸 限制 启动 配置中 设置 的最大值其他地方不做限制
String fileid = MainUtils.md5(file.getBytes()); //使用 文件的 MD5作为 ID避免重复上传大文件
if (!StringUtils.isBlank(fileid)) {
AttachmentFile attachmentFile = new AttachmentFile();
attachmentFile.setCreater(super.getUser(request).getId());
attachmentFile.setOrgi(super.getOrgi(request));
attachmentFile.setDataid(dataid);
attachmentFile.setModelid(modelid);
attachmentFile.setModel(MainContext.ModelType.WORKORDERS.toString());
attachmentFile.setFilelength((int) file.getSize());
if (file.getContentType() != null && file.getContentType().length() > 255) {
attachmentFile.setFiletype(file.getContentType().substring(0, 255));
} else {
attachmentFile.setFiletype(file.getContentType());
}
if (file.getOriginalFilename() != null && file.getOriginalFilename().length() > 255) {
attachmentFile.setTitle(file.getOriginalFilename().substring(0, 255));
} else {
attachmentFile.setTitle(file.getOriginalFilename());
}
if (!StringUtils.isBlank(attachmentFile.getFiletype()) && attachmentFile.getFiletype().indexOf("image") >= 0) {
attachmentFile.setImage(true);
}
attachmentFile.setFileid(fileid);
attachementRes.save(attachmentFile);
FileUtils.writeByteArrayToFile(new File(path, "app/kbs/" + fileid), file.getBytes());
}
}
}
private void processAttachmentFile(MultipartFile[] files, KbsTopic topic, HttpServletRequest request, String dataid, String modelid) throws IOException {
if (files != null && files.length > 0) {
topic.setAttachment(""); //序列化 附件文件方便显示避免多一次查询 附件的操作
//保存附件
for (MultipartFile file : files) {
if (file.getSize() > 0) { //文件尺寸 限制 启动 配置中 设置 的最大值其他地方不做限制
String fileid = MainUtils.md5(file.getBytes()); //使用 文件的 MD5作为 ID避免重复上传大文件
if (!StringUtils.isBlank(fileid)) {
AttachmentFile attachmentFile = new AttachmentFile();
attachmentFile.setCreater(super.getUser(request).getId());
attachmentFile.setOrgi(super.getOrgi(request));
attachmentFile.setDataid(dataid);
attachmentFile.setModelid(modelid);
attachmentFile.setModel(MainContext.ModelType.WORKORDERS.toString());
attachmentFile.setFilelength((int) file.getSize());
if (file.getContentType() != null && file.getContentType().length() > 255) {
attachmentFile.setFiletype(file.getContentType().substring(0, 255));
} else {
attachmentFile.setFiletype(file.getContentType());
}
if (file.getOriginalFilename() != null && file.getOriginalFilename().length() > 255) {
attachmentFile.setTitle(file.getOriginalFilename().substring(0, 255));
} else {
attachmentFile.setTitle(file.getOriginalFilename());
}
String filetype = attachmentFile.getFiletype();
if (!StringUtils.isBlank(filetype) && filetype.contains("image")) {
attachmentFile.setImage(true);
}
attachmentFile.setFileid(fileid);
attachementRes.save(attachmentFile);
FileUtils.writeByteArrayToFile(new File(path, "app/kbs/" + fileid), file.getBytes());
}
}
}
}
}
}
}
}

View File

@ -1,46 +1,48 @@
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.impl;
import com.chatopera.cc.model.Tag;
import com.chatopera.cc.persistence.interfaces.DataExchangeInterface;
import com.chatopera.cc.persistence.repository.TagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
@Service("servicedata")
public class ServiceDataExchangeImpl implements DataExchangeInterface {
@Autowired
private TagRepository tagRes ;
public String getDataByIdAndOrgi(String id, String orgi){
Tag tag = tagRes.findByOrgiAndId(orgi, id) ;
return tag!=null ? tag.getTag() : id;
}
@Override
public List<Serializable> getListDataByIdAndOrgi(String id , String creater, String orgi) {
return null ;
}
public void process(Object data , String orgi) {
}
}
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.impl;
import com.chatopera.cc.model.Tag;
import com.chatopera.cc.persistence.interfaces.DataExchangeInterface;
import com.chatopera.cc.persistence.repository.TagRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
@Service("servicedata")
@RequiredArgsConstructor
public class ServiceDataExchangeImpl implements DataExchangeInterface {
@NonNull
private final TagRepository tagRes;
public String getDataByIdAndOrgi(String id, String orgi) {
Tag tag = tagRes.findByOrgiAndId(orgi, id);
return tag != null ? tag.getTag() : id;
}
@Override
public List<Serializable> getListDataByIdAndOrgi(String id, String creater, String orgi) {
return null;
}
public void process(Object data, String orgi) {
}
}

View File

@ -1,20 +1,20 @@
package com.chatopera.cc.persistence.impl;
import com.chatopera.cc.model.Tag;
import com.chatopera.cc.model.User;
import com.chatopera.cc.persistence.interfaces.DataExchangeInterface;
import com.chatopera.cc.persistence.repository.TagRepository;
import com.chatopera.cc.persistence.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
@Service("tagdata")
@RequiredArgsConstructor
public class TagDataExchangeImpl implements DataExchangeInterface {
@Autowired
private TagRepository tagRes;
@NonNull
private final TagRepository tagRes;
public String getDataByIdAndOrgi(String id, String orgi) {
Tag tag = tagRes.findByOrgiAndId(orgi, id);

View File

@ -1,43 +1,42 @@
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface TagRepository extends JpaRepository<Tag, String>
{
Tag findByOrgiAndTag(String orgi, String tag);
Tag findByOrgiAndId(String orgi, String id);
@Query(value = "select t from Tag t where (:tagtype is null or t.tagtype = :tagtype) " +
"and t.orgi = :orgi")
Page<Tag> findByOrgiAndTagtype(@Param("orgi") String orgi, @Param("tagtype") String tagtype, Pageable paramPageable);
List<Tag> findByOrgi(String orgi);
List<Tag> findByOrgiAndTagtype(String orgi, String tagtype);
}
/*
* Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.chatopera.cc.persistence.repository;
import com.chatopera.cc.model.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface TagRepository extends JpaRepository<Tag, String> {
Tag findByOrgiAndTag(String orgi, String tag);
Tag findByOrgiAndId(String orgi, String id);
@Query(value = "select t from Tag t where (:tagtype is null or t.tagtype = :tagtype) " +
"and t.orgi = :orgi")
Page<Tag> findByOrgiAndTagtype(@Param("orgi") String orgi, @Param("tagtype") String tagtype, Pageable paramPageable);
List<Tag> findByOrgi(String orgi);
List<Tag> findByOrgiAndTagtype(String orgi, String tagtype);
}