|
@@ -6,7 +6,6 @@ import cn.com.ty.lift.system.faq.service.FaqService;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -18,73 +17,50 @@ import java.util.List;
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wang-hai-cheng
|
|
|
- * @since 2019-11-21
|
|
|
+ * @since 2019-12-05
|
|
|
*/
|
|
|
@Transactional
|
|
|
@Service
|
|
|
-@AllArgsConstructor
|
|
|
public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqService {
|
|
|
|
|
|
- public RestResponse addOne(String title, String description) {
|
|
|
- Faq faq = new Faq();
|
|
|
- faq.setContent(title).setType(1).setParentId(0L).setDescription(description);
|
|
|
- faq.setSerial(this.count(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", 0)) + 1);
|
|
|
- if (this.save(faq)) {
|
|
|
- return RestResponse.ok(null, "1", "新增一级分类成功");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "新增一级分类失败");
|
|
|
- }
|
|
|
- }
|
|
|
+ public RestResponse getFaqs(Faq faq) {
|
|
|
+ boolean typeFlag = faq.getId() != null;
|
|
|
+ boolean parentIdFlag = faq.getId() != null;
|
|
|
|
|
|
- public RestResponse addChild(Long parentId, String title, String description) {
|
|
|
- Faq faq = new Faq();
|
|
|
- faq.setContent(title).setType(1).setParentId(parentId).setDescription(description);
|
|
|
- faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 1).eq("parent_id", parentId)).size() + 1);
|
|
|
- if (this.save(faq)) {
|
|
|
- return RestResponse.ok(null, "1", "新增子分类成功");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "新增子分类失败");
|
|
|
+ List<Faq> faqs = this.list(new QueryWrapper<Faq>()
|
|
|
+ .eq(typeFlag, "type", faq.getType()).eq(parentIdFlag, "parent_id", faq.getParentId())
|
|
|
+ .orderByAsc("serial"));
|
|
|
+ if (faqs.isEmpty()) {
|
|
|
+ return RestResponse.ok(null, "9", "无数据");
|
|
|
}
|
|
|
+ return RestResponse.ok(faqs, "1", "查询成功");
|
|
|
}
|
|
|
|
|
|
- public RestResponse addQuestion(Long parentId, String title, String description) {
|
|
|
- Faq faq = new Faq();
|
|
|
- faq.setContent(title).setType(2).setParentId(parentId).setDescription(description);
|
|
|
- faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 2).eq("parent_id", parentId)).size() + 1);
|
|
|
- if (this.save(faq)) {
|
|
|
- return RestResponse.ok(null, "1", "新增问题成功");
|
|
|
+ /**
|
|
|
+ * @description 新增分类或问题或答案
|
|
|
+ * @date 2019/12/5 11:01
|
|
|
+ */
|
|
|
+ public RestResponse add(Faq faq) {
|
|
|
+ List<Faq> faqs = this.list(new QueryWrapper<Faq>()
|
|
|
+ .select("id", "serial")
|
|
|
+ .eq("type", faq.getType()).eq("parent_id", faq.getParentId())
|
|
|
+ .orderByDesc("serial"));
|
|
|
+ if (faqs.isEmpty()) {
|
|
|
+ faq.setSerial(1);
|
|
|
} else {
|
|
|
- return RestResponse.ok(null, "0", "新增问题失败");
|
|
|
+ faq.setSerial(faqs.get(0).getSerial() + 1);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- public RestResponse addAnswer(Long parentId, String content, String description) {
|
|
|
- Faq faq = new Faq();
|
|
|
- faq.setContent(content).setType(3).setParentId(parentId).setDescription(description);
|
|
|
- faq.setSerial(this.list(new QueryWrapper<Faq>().eq("type", 3).eq("parent_id", parentId)).size() + 1);
|
|
|
if (this.save(faq)) {
|
|
|
- return RestResponse.ok(null, "1", "新增答案成功");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "新增答案失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public RestResponse up(Long id, String title, String description) {
|
|
|
- Faq byId = this.getById(id);
|
|
|
- byId.setContent(title).setDescription(description);
|
|
|
- if (this.updateById(byId)) {
|
|
|
- return RestResponse.ok(null, "1", "更新成功");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "更新失败");
|
|
|
+ return RestResponse.ok(null, "1", "新增成功");
|
|
|
}
|
|
|
+ return RestResponse.ok(null, "0", "新增失败");
|
|
|
}
|
|
|
|
|
|
public RestResponse delete(Long id) {
|
|
|
if (deleteAll(id)) {
|
|
|
return RestResponse.ok(null, "1", "删除成功");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "删除失败");
|
|
|
}
|
|
|
+ return RestResponse.ok(null, "0", "删除失败");
|
|
|
}
|
|
|
|
|
|
//递归删除id及它下面所有分类,问答
|
|
@@ -112,39 +88,59 @@ public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqSe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public RestResponse up(Long id) {
|
|
|
- Faq up = this.getById(id);
|
|
|
- if (up != null) {
|
|
|
- if (up.getSerial() > 1) {
|
|
|
- Faq one = this.getOne(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial() - 1));
|
|
|
- one.setSerial(one.getSerial() + 1);
|
|
|
- up.setSerial(up.getSerial() - 1);
|
|
|
- this.updateById(one);
|
|
|
- this.updateById(up);
|
|
|
- return RestResponse.ok(null, "1", "上移一位");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "已经到顶了");
|
|
|
- }
|
|
|
- } else {
|
|
|
+ //type 1上移 0下移
|
|
|
+ public RestResponse serial(Long id, Integer type) {
|
|
|
+ Faq byId = this.getById(id);
|
|
|
+ if (byId == null) {
|
|
|
return RestResponse.ok(null, "0", "此id不存在");
|
|
|
}
|
|
|
- }
|
|
|
+ List<Faq> faqs;
|
|
|
+ if (type == 1) {
|
|
|
+ faqs = this.list(new QueryWrapper<Faq>().eq("type", byId.getType()).eq("parent_id", byId.getParentId()).orderByDesc("serial"));
|
|
|
+ } else {
|
|
|
+ faqs = this.list(new QueryWrapper<Faq>().eq("type", byId.getType()).eq("parent_id", byId.getParentId()).orderByAsc(("serial")));
|
|
|
+ }
|
|
|
|
|
|
- public RestResponse down(Long id) {
|
|
|
- Faq up = this.getById(id);
|
|
|
- if (up != null) {
|
|
|
- if (this.count(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial())) > up.getSerial()) {
|
|
|
- Faq one = this.getOne(new QueryWrapper<Faq>().eq("type", up.getType()).eq("parent_id", up.getParentId()).eq("serial", up.getSerial() + 1));
|
|
|
- one.setSerial(one.getSerial() - 1);
|
|
|
- up.setSerial(one.getSerial() + 1);
|
|
|
- this.updateById(one);
|
|
|
- this.updateById(up);
|
|
|
- return RestResponse.ok(null, "1", "下移一位");
|
|
|
- } else {
|
|
|
- return RestResponse.ok(null, "0", "已经到顶了");
|
|
|
+ if (faqs.isEmpty()) {
|
|
|
+ byId.setSerial(1);
|
|
|
+ this.updateById(byId);
|
|
|
+ return RestResponse.ok(null, "1", "移动成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ Faq faq;
|
|
|
+ int i;
|
|
|
+ if (type == 1) {
|
|
|
+ for (i = 0; i < faqs.size(); i++) {
|
|
|
+ if (faqs.get(i).getSerial() < byId.getSerial()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- return RestResponse.ok(null, "0", "此id不存在");
|
|
|
+ for (i = 0; i < faqs.size(); i++) {
|
|
|
+ if (faqs.get(i).getSerial() > byId.getSerial()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ if (i==faqs.size()) {
|
|
|
+ return RestResponse.ok(null, "1", "移动成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ faq = faqs.get(i);
|
|
|
+
|
|
|
+
|
|
|
+ if (byId.getId().equals(faq.getId())) {
|
|
|
+ return RestResponse.ok(null, "1", "移动成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer serial = faq.getSerial();
|
|
|
+ faq.setSerial(byId.getSerial());
|
|
|
+ byId.setSerial(serial);
|
|
|
+
|
|
|
+ this.updateById(faq);
|
|
|
+ this.updateById(byId);
|
|
|
+
|
|
|
+ return RestResponse.ok(null, "1", "移动成功");
|
|
|
}
|
|
|
}
|