From e5def38565ead311ccdd250f3ecb38912a4af03a Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 27 May 2021 16:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/SysServiceTopicController.java | 54 +++++ .../custom/WechatAppletController.java | 20 ++ .../custom/domain/SysServicesTopic.java | 21 +- .../custom/mapper/SysServicesTopicMapper.java | 22 ++ .../service/ISysServicesTopicService.java | 21 ++ .../impl/SysServicesTopicServiceImp.java | 121 +++++++++++ .../mapper/custom/SysServicesTopicMapper.xml | 188 +++++++++++++----- .../config/properties/DruidProperties.java | 3 + 8 files changed, 397 insertions(+), 53 deletions(-) create mode 100644 stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceTopicController.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysServicesTopicMapper.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesTopicService.java create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesTopicServiceImp.java diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceTopicController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceTopicController.java new file mode 100644 index 000000000..45b74e292 --- /dev/null +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceTopicController.java @@ -0,0 +1,54 @@ +package com.stdiet.web.controller.custom; + +import com.stdiet.common.core.controller.BaseController; +import com.stdiet.common.core.domain.AjaxResult; +import com.stdiet.common.core.page.TableDataInfo; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysServicesTopic; +import com.stdiet.custom.service.ISysServicesTopicService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/services/topic") +public class SysServiceTopicController extends BaseController { + + @Autowired + private ISysServicesTopicService servicesTopicService; + + @GetMapping("/list") + public TableDataInfo list(SysServicesTopic topic) { + startPage(); + return getDataTable(servicesTopicService.selectSysServicesTopicByUserIdAndRole(topic)); + } + +// @PutMapping("/update/status") +// public AjaxResult status(@RequestBody SysServicesQuestion sysServicesQuestion) { +// return toAjax(sysServicesQuestionService.updateSysServicesQuestionStatus(sysServicesQuestion)); +// } + + @PostMapping("/reply") + public AjaxResult reply(@RequestBody SysServicesTopic topic) { + return AjaxResult.success(servicesTopicService.inserSysServicesTopicReply(topic)); + } + + @PostMapping("/comment") + public AjaxResult comment(@RequestBody SysServicesTopic topic) { + return AjaxResult.success(servicesTopicService.inserSysServicesTopicComment(topic)); + } + + @GetMapping("/detail") + public AjaxResult detail(@RequestParam String topicId, @RequestParam String id) { + List questions = servicesTopicService.selectSysServicesTopicSessionByTopicId(topicId); + if (StringUtils.isNotNull(questions)) { + // 更新问题对应角色的状态 + SysServicesTopic status = new SysServicesTopic(); + status.setRead(1); + status.setId(id); + servicesTopicService.updateSysServicesTopicStatus(status); + } + return AjaxResult.success(questions); + } +} diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java index 5c7cb85e2..f012f7582 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java @@ -70,6 +70,8 @@ public class WechatAppletController extends BaseController { private IWechatAppletService iWechatAppletService; @Autowired private ISysServicesQuestionService iSysServicesQuestionService; + @Autowired + private ISysServicesTopicService iSysServicesTopicService; /** * 查询微信小程序中展示的客户案例 @@ -605,6 +607,24 @@ public class WechatAppletController extends BaseController { return getDataTable(iSysServicesQuestionService.selectSysServicesQuestionByUserIdAndRole(servicesQuestion)); } + /** + * 客户添加问题 + * + * @param topic + * @param customerId + * @return + */ + @PostMapping("/services/topic/post") + public AjaxResult postServiceTopic(@RequestBody SysServicesTopic topic, @RequestParam String customerId) { + Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L; + if (cusId == 0L) { + return toAjax(0); + } + topic.setUid(cusId); + + return AjaxResult.success(iSysServicesTopicService.insertSysServicesTopic(topic)); + } + /** * 客户添加问题 * diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysServicesTopic.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysServicesTopic.java index c21645535..d76cf691a 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysServicesTopic.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysServicesTopic.java @@ -2,16 +2,19 @@ package com.stdiet.custom.domain; import com.alibaba.fastjson.JSONArray; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import java.util.Date; +import java.util.List; @Data +@JsonInclude(JsonInclude.Include.NON_NULL) public class SysServicesTopic { /** * */ - Long id; + String id; /** * 问题id @@ -23,6 +26,12 @@ public class SysServicesTopic { */ Integer topicType; + String commentId; + + String replyId; + + Integer replyType; + /** * 角色 */ @@ -64,10 +73,20 @@ public class SysServicesTopic { */ String role; + String fromRole; + + String toRole; + // 非持久化字段 /** * 角色名字 */ + String fromName; + String toName; String name; + List comments; + + List replys; + } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysServicesTopicMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysServicesTopicMapper.java new file mode 100644 index 000000000..29ecaadaa --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysServicesTopicMapper.java @@ -0,0 +1,22 @@ +package com.stdiet.custom.mapper; + +import com.stdiet.custom.domain.SysServicesQuestion; +import com.stdiet.custom.domain.SysServicesTopic; + +import java.util.List; + +public interface SysServicesTopicMapper { + List selectSysServicesTopicByUserIdAndRole(SysServicesTopic topic); + + int insertSysServicesTopic(SysServicesTopic topic); + + int insertSysServicesTopicStatus(List topics); + + int updateSysServicesTopicStatus(SysServicesTopic topic); + + int inserSysServicesTopicComment(SysServicesTopic topic); + + int inserSysServicesTopicReply(SysServicesTopic topic); + + List selectSysServicesTopicSessionByTopicId(String topicId); +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesTopicService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesTopicService.java new file mode 100644 index 000000000..dedfe3873 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesTopicService.java @@ -0,0 +1,21 @@ +package com.stdiet.custom.service; + +import com.stdiet.custom.domain.SysServicesQuestion; +import com.stdiet.custom.domain.SysServicesTopic; + +import java.util.List; + +public interface ISysServicesTopicService { + + List selectSysServicesTopicByUserIdAndRole(SysServicesTopic topic); + + SysServicesTopic insertSysServicesTopic(SysServicesTopic topic); + + int updateSysServicesTopicStatus(SysServicesTopic topic); + + SysServicesTopic inserSysServicesTopicReply(SysServicesTopic topic); + + SysServicesTopic inserSysServicesTopicComment(SysServicesTopic topic); + + List selectSysServicesTopicSessionByTopicId(String topicId); +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesTopicServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesTopicServiceImp.java new file mode 100644 index 000000000..a66a0b3dd --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesTopicServiceImp.java @@ -0,0 +1,121 @@ +package com.stdiet.custom.service.impl; + +import com.stdiet.common.utils.DateUtils; +import com.stdiet.common.utils.uuid.UUID; +import com.stdiet.custom.domain.SysCustomer; +import com.stdiet.custom.domain.SysServicesTopic; +import com.stdiet.custom.mapper.SysCustomerMapper; +import com.stdiet.custom.mapper.SysServicesTopicMapper; +import com.stdiet.custom.service.ISysServicesTopicService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class SysServicesTopicServiceImp implements ISysServicesTopicService { + @Autowired + SysServicesTopicMapper servicesTopicMapper; + + @Autowired + SysCustomerMapper sysCustomerMapper; + + @Override + public List selectSysServicesTopicByUserIdAndRole(SysServicesTopic topic) { + return servicesTopicMapper.selectSysServicesTopicByUserIdAndRole(topic); + } + + + @Override + public SysServicesTopic insertSysServicesTopic(SysServicesTopic topic) { + // 生成uuid + topic.setTopicId(UUID.randomUUID().toString().replaceAll("-", "")); + topic.setRead(1); + topic.setCreateTime(DateUtils.getNowDate()); + + servicesTopicMapper.insertSysServicesTopic(topic); + + SysCustomer customer = sysCustomerMapper.selectSysCustomerById(topic.getUid()); + + List statusList = new ArrayList<>(); + + SysServicesTopic customerStatus = new SysServicesTopic(); + customerStatus.setUid(customer.getId()); + customerStatus.setRole("customer"); + customerStatus.setRead(1); + customerStatus.setTopicId(topic.getTopicId()); + statusList.add(customerStatus); + + SysServicesTopic dieticianStatus = new SysServicesTopic(); + dieticianStatus.setUid(customer.getMainDietitian()); + dieticianStatus.setRole("dietician"); + dieticianStatus.setRead(0); + dieticianStatus.setTopicId(topic.getTopicId()); + statusList.add(dieticianStatus); + + SysServicesTopic afterSaleStatus = new SysServicesTopic(); + afterSaleStatus.setUid(customer.getAfterDietitian()); + afterSaleStatus.setRole("after_sale"); + afterSaleStatus.setRead(0); + afterSaleStatus.setTopicId(topic.getTopicId()); + statusList.add(afterSaleStatus); + + SysServicesTopic dieticianAssistantStatus = new SysServicesTopic(); + dieticianAssistantStatus.setUid(customer.getAssistantDietitian()); + dieticianAssistantStatus.setRole("dietician_assistant"); + dieticianAssistantStatus.setRead(0); + dieticianAssistantStatus.setTopicId(topic.getTopicId()); + statusList.add(dieticianAssistantStatus); + + servicesTopicMapper.insertSysServicesTopicStatus(statusList); + + topic.setId(customerStatus.getId()); + topic.setUid(null); + + return topic; + } + + @Override + public int updateSysServicesTopicStatus(SysServicesTopic topic) { + return servicesTopicMapper.updateSysServicesTopicStatus(topic); + } + + + @Override + public SysServicesTopic inserSysServicesTopicReply(SysServicesTopic topic) { + String uuid = java.util.UUID.randomUUID().toString().replace("-", ""); + topic.setId(uuid); + int row = servicesTopicMapper.inserSysServicesTopicReply(topic); + if (row > 0) { + // 设置未读 + SysServicesTopic status = new SysServicesTopic(); + status.setRead(0); + status.setTopicId(topic.getTopicId()); + status.setRole(topic.getRole()); + servicesTopicMapper.updateSysServicesTopicStatus(status); + } + return topic; + } + + @Override + public SysServicesTopic inserSysServicesTopicComment(SysServicesTopic topic) { + String uuid = java.util.UUID.randomUUID().toString().replace("-", ""); + topic.setId(uuid); + int row = servicesTopicMapper.inserSysServicesTopicComment(topic); + if (row > 0) { + // 设置未读 + SysServicesTopic status = new SysServicesTopic(); + status.setRead(0); + status.setTopicId(topic.getTopicId()); + status.setRole(topic.getRole()); + servicesTopicMapper.updateSysServicesTopicStatus(status); + } + return topic; + } + + @Override + public List selectSysServicesTopicSessionByTopicId(String topicId) { + return servicesTopicMapper.selectSysServicesTopicSessionByTopicId(topicId); + } +} diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysServicesTopicMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysServicesTopicMapper.xml index 160b5b90b..d309926c4 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysServicesTopicMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysServicesTopicMapper.xml @@ -9,7 +9,6 @@ - @@ -17,91 +16,140 @@ - - - - - - - - - - select que_id, cus_id as user_id, 'customer' as role, content, img, create_time from sys_services_question where que_id = #{queId} - union select que_id, user_id, role, content, img, create_time from sys_services_question_session where que_id = #{queId} - order by create_time asc + select topic_id, uid, 'customer' as role, content, img, create_time from sys_services_topic where topic_id = #{topicId} + + + + + + + + - - insert into sys_services_question + + insert into sys_services_topic - que_id, - cus_id, + topic_id, + uid, content, - type, + topic_type, create_time, img, - #{queId}, - #{cusId}, + #{topicId}, + #{uid}, #{content}, - #{type}, + #{topicType}, #{createTime}, - #{img, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}, + #{img, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}, - - insert into sys_services_question_status (que_id, user_id, role, `read`, create_time, update_time) values + insert into sys_services_topic_status (topic_id, uid, role, `read`, create_time, update_time) values - (#{status.queId}, #{status.userId}, #{status.role}, #{status.read}, now(), now()) + (#{status.topicId}, #{status.uid}, #{status.role}, #{status.read}, now(), now()) - - update sys_services_question_status + + update sys_services_topic_status `read` = #{read}, update_time = now(), @@ -118,37 +166,73 @@ role = 'customer' and - que_id = #{queId} + topic_id = #{topicId} - - insert into sys_services_question_session + + insert into sys_services_topic_comment - que_id, - user_id, + id, + topic_id, + from_uid, + from_role, + to_uid, + to_role, content, - `read`, - role, img, - create_time, - update_time, - + create_time, - #{queId}, - #{userId}, + #{id}, + #{topicId}, + #{fromUid}, + #{fromRole}, + #{toUid}, + #{toRole}, #{content}, - #{read}, - #{role}, #{img, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}, - now(), - now(), + now(), + + + + + + insert into sys_services_topic_reply + + id, + comment_id, + reply_id, + reply_type, + content, + from_uid, + to_uid, + img, + from_role, + to_role, + create_time, + + + + #{id}, + #{commentId}, + #{replyId}, + #{replyType}, + #{content}, + #{fromUid}, + #{toUid}, + + #{img, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}, + + #{fromRole}, + #{toRole}, + now(), diff --git a/stdiet-framework/src/main/java/com/stdiet/framework/config/properties/DruidProperties.java b/stdiet-framework/src/main/java/com/stdiet/framework/config/properties/DruidProperties.java index 73e8004d3..cbe94f040 100644 --- a/stdiet-framework/src/main/java/com/stdiet/framework/config/properties/DruidProperties.java +++ b/stdiet-framework/src/main/java/com/stdiet/framework/config/properties/DruidProperties.java @@ -72,6 +72,9 @@ public class DruidProperties datasource.setTestOnBorrow(testOnBorrow); /** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ datasource.setTestOnReturn(testOnReturn); + + datasource.setRemoveAbandoned(true); + datasource.setRemoveAbandonedTimeout(180); return datasource; } }