diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceQuestionController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceQuestionController.java index c80f1b488..4f7cf6fb7 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceQuestionController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysServiceQuestionController.java @@ -2,11 +2,15 @@ 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.SysServicesQuestion; import com.stdiet.custom.service.ISysServicesQuestionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("/services/question") public class SysServiceQuestionController extends BaseController { @@ -14,18 +18,38 @@ public class SysServiceQuestionController extends BaseController { @Autowired private ISysServicesQuestionService sysServicesQuestionService; - @PostMapping("/list") - public AjaxResult list(@RequestBody SysServicesQuestion sysServicesQuestion) { - return AjaxResult.success(sysServicesQuestionService.selectSysServicesQuestionByUserIdAndRole(sysServicesQuestion)); + @GetMapping("/list") + public TableDataInfo list(SysServicesQuestion sysServicesQuestion) { + startPage(); + return getDataTable(sysServicesQuestionService.selectSysServicesQuestionByUserIdAndRole(sysServicesQuestion)); } - @PutMapping("/updateStatus") - public AjaxResult status(@RequestBody SysServicesQuestion sysServicesQuestion) { - return toAjax(sysServicesQuestionService.updateSysServicesQuestionStatus(sysServicesQuestion)); - } +// @PutMapping("/update/status") +// public AjaxResult status(@RequestBody SysServicesQuestion sysServicesQuestion) { +// return toAjax(sysServicesQuestionService.updateSysServicesQuestionStatus(sysServicesQuestion)); +// } @PostMapping("/reply") public AjaxResult reply(@RequestBody SysServicesQuestion servicesQuestion) { - return toAjax(sysServicesQuestionService.inserSysServicesQuestionReply(servicesQuestion)); + int row = sysServicesQuestionService.inserSysServicesQuestionReply(servicesQuestion); + if (row > 0) { + // 更新customer未读,id不能有值 + servicesQuestion.setRead(0); + sysServicesQuestionService.updateSysServicesQuestionStatus(servicesQuestion); + } + return toAjax(row); + } + + @GetMapping("/detail") + public AjaxResult detail(@RequestParam String queId, @RequestParam Long id) { + List questions = sysServicesQuestionService.selectSysServicesQuestionSessionByQueId(queId); + if (StringUtils.isNotNull(questions)) { + // 更新问题对应角色的状态 + SysServicesQuestion servicesQuestion = new SysServicesQuestion(); + servicesQuestion.setRead(1); + servicesQuestion.setId(id); + sysServicesQuestionService.updateSysServicesQuestionStatus(servicesQuestion); + } + 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 4509f2940..5c7cb85e2 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 @@ -593,7 +593,7 @@ public class WechatAppletController extends BaseController { } @GetMapping("/services/list") - public AjaxResult fetchServiceQuestion(@RequestParam String customerId, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { + public TableDataInfo fetchServiceQuestion(@RequestParam String customerId, @RequestParam Integer pageNum, @RequestParam Integer pageSize) { startPage(); Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L; @@ -602,11 +602,12 @@ public class WechatAppletController extends BaseController { servicesQuestion.setRole("customer"); servicesQuestion.setUserId(cusId); - return AjaxResult.success(iSysServicesQuestionService.selectSysServicesQuestionByUserIdAndRole(servicesQuestion)); + return getDataTable(iSysServicesQuestionService.selectSysServicesQuestionByUserIdAndRole(servicesQuestion)); } /** * 客户添加问题 + * * @param servicesQuestion * @param customerId * @return @@ -614,42 +615,69 @@ public class WechatAppletController extends BaseController { @PostMapping("/services/post") public AjaxResult postServiceQuestion(@RequestBody SysServicesQuestion servicesQuestion, @RequestParam String customerId) { Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L; - if(cusId == 0L) { + if (cusId == 0L) { return toAjax(0); } servicesQuestion.setCusId(cusId); - return toAjax(iSysServicesQuestionService.insertSysServicesQuestion(servicesQuestion)); - } - @GetMapping("/services/reply") - public AjaxResult serviceQuestionReply(@RequestParam String queId) { - return AjaxResult.success(iSysServicesQuestionService.selectSysServicesQuestionSessionByQueId(queId)); + return AjaxResult.success(iSysServicesQuestionService.insertSysServicesQuestion(servicesQuestion)); } /** - * 设置已读 - * @param id + * 回答问题 + * + * @param servicesQuestion + * @param customerId * @return */ - @GetMapping("/services/post/update") - public AjaxResult updateServiceQuestion(@RequestParam Long id) { - SysServicesQuestion servicesQuestion = new SysServicesQuestion(); - servicesQuestion.setRead(1); - servicesQuestion.setId(id); - - return toAjax(iSysServicesQuestionService.updateSysServicesQuestionStatus(servicesQuestion)); - } - @PostMapping("/services/post/reply") public AjaxResult replyServiceQuestion(@RequestBody SysServicesQuestion servicesQuestion, @RequestParam String customerId) { Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L; - + if (cusId == 0L) { + return toAjax(0); + } servicesQuestion.setRole("customer"); servicesQuestion.setUserId(cusId); - return toAjax(iSysServicesQuestionService.inserSysServicesQuestionReply(servicesQuestion)); + int row = iSysServicesQuestionService.inserSysServicesQuestionReply(servicesQuestion); + if (row > 0) { + // 更新三个觉得未读,id不能有值 + servicesQuestion.setRead(0); + iSysServicesQuestionService.updateSysServicesQuestionStatus(servicesQuestion); + } + + return toAjax(row); } + /** + * 获取问题详情 + * + * @param id + * @return + */ + @GetMapping("/services/detail") + public AjaxResult serviceQuestionDetail(@RequestParam String queId, @RequestParam Long id) { + List questions = iSysServicesQuestionService.selectSysServicesQuestionSessionByQueId(queId); + if (StringUtils.isNotNull(questions)) { + SysServicesQuestion status = new SysServicesQuestion(); + status.setId(id); + status.setRead(1); + iSysServicesQuestionService.updateSysServicesQuestionStatus(status); + } + return AjaxResult.success(questions); + } + + +// @GetMapping("/services/post/update") +// public AjaxResult updateServiceQuestion(@RequestParam Long id) { +// SysServicesQuestion servicesQuestion = new SysServicesQuestion(); +// servicesQuestion.setRead(1); +// servicesQuestion.setId(id); +// +// return toAjax(iSysServicesQuestionService.updateSysServicesQuestionStatus(servicesQuestion)); +// } + + } diff --git a/stdiet-common/src/main/java/com/stdiet/common/core/controller/BaseController.java b/stdiet-common/src/main/java/com/stdiet/common/core/controller/BaseController.java index 3b1cc8d45..250614f38 100644 --- a/stdiet-common/src/main/java/com/stdiet/common/core/controller/BaseController.java +++ b/stdiet-common/src/main/java/com/stdiet/common/core/controller/BaseController.java @@ -1,12 +1,5 @@ package com.stdiet.common.core.controller; -import java.beans.PropertyEditorSupport; -import java.util.Date; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.stdiet.common.constant.HttpStatus; @@ -17,28 +10,33 @@ import com.stdiet.common.core.page.TableSupport; import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.StringUtils; import com.stdiet.common.utils.sql.SqlUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; + +import java.beans.PropertyEditorSupport; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; /** * web层通用数据处理 - * + * * @author stdiet */ -public class BaseController -{ +public class BaseController { protected final Logger logger = LoggerFactory.getLogger(BaseController.class); /** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder - public void initBinder(WebDataBinder binder) - { + public void initBinder(WebDataBinder binder) { // Date 类型转换 - binder.registerCustomEditor(Date.class, new PropertyEditorSupport() - { + binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override - public void setAsText(String text) - { + public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); @@ -47,13 +45,11 @@ public class BaseController /** * 设置请求分页数据 */ - protected void startPage() - { + protected void startPage() { PageDomain pageDomain = TableSupport.buildPageRequest(); Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); - if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) - { + if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) { String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); PageHelper.startPage(pageNum, pageSize, orderBy); } @@ -62,33 +58,37 @@ public class BaseController /** * 响应请求分页数据 */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - protected TableDataInfo getDataTable(List list) - { + @SuppressWarnings({"rawtypes", "unchecked"}) + protected TableDataInfo getDataTable(List list) { + + PageDomain pageDomain = TableSupport.buildPageRequest(); + Integer pageNum = pageDomain.getPageNum(); + Integer pageSize = pageDomain.getPageSize(); + + long total = new PageInfo(list).getTotal(); + TableDataInfo rspData = new TableDataInfo(); rspData.setCode(HttpStatus.SUCCESS); rspData.setMsg("查询成功"); - rspData.setRows(list); - rspData.setTotal(new PageInfo(list).getTotal()); + rspData.setRows(total > pageSize * (pageNum - 1) ? list : new ArrayList<>()); + rspData.setTotal(total); return rspData; } /** * 响应返回结果 - * + * * @param rows 影响行数 * @return 操作结果 */ - protected AjaxResult toAjax(int rows) - { + protected AjaxResult toAjax(int rows) { return rows > 0 ? AjaxResult.success() : AjaxResult.error(); } /** * 页面跳转 */ - public String redirect(String url) - { + public String redirect(String url) { return StringUtils.format("redirect:{}", url); } } 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 new file mode 100644 index 000000000..c21645535 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysServicesTopic.java @@ -0,0 +1,73 @@ +package com.stdiet.custom.domain; + +import com.alibaba.fastjson.JSONArray; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class SysServicesTopic { + /** + * + */ + Long id; + + /** + * 问题id + */ + String topicId; + + /** + * 问题类型 + */ + Integer topicType; + + /** + * 角色 + */ + Long uid; + + Long fromUid; + + Long toUid; + + /** + * 问题内容 + */ + String content; + + /** + * 图片地址 + */ + JSONArray img; + + /** + * 创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + Date createTime; + + /** + * 0-未读 1-已读 + */ + Integer read; + + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + Date updateTime; + + /** + * 角色 + */ + String role; + + // 非持久化字段 + /** + * 角色名字 + */ + String name; + +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesQuestionService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesQuestionService.java index 329f94e21..f671b9268 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesQuestionService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysServicesQuestionService.java @@ -8,7 +8,7 @@ public interface ISysServicesQuestionService { List selectSysServicesQuestionByUserIdAndRole(SysServicesQuestion servicesQuestion); - int insertSysServicesQuestion(SysServicesQuestion servicesQuestion); + SysServicesQuestion insertSysServicesQuestion(SysServicesQuestion servicesQuestion); int updateSysServicesQuestionStatus(SysServicesQuestion sysServicesQuestion); diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesQuestionServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesQuestionServiceImp.java index 1c9691014..fbaca72b1 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesQuestionServiceImp.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysServicesQuestionServiceImp.java @@ -1,5 +1,6 @@ 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.SysServicesQuestion; @@ -26,9 +27,11 @@ public class SysServicesQuestionServiceImp implements ISysServicesQuestionServic } @Override - public int insertSysServicesQuestion(SysServicesQuestion servicesQuestion) { + public SysServicesQuestion insertSysServicesQuestion(SysServicesQuestion servicesQuestion) { // 生成uuid servicesQuestion.setQueId(UUID.randomUUID().toString().replaceAll("-", "")); + servicesQuestion.setRead(1); + servicesQuestion.setCreateTime(DateUtils.getNowDate()); servicesQuestionMapper.insertSysServicesQuestion(servicesQuestion); @@ -45,25 +48,31 @@ public class SysServicesQuestionServiceImp implements ISysServicesQuestionServic SysServicesQuestion dieticianStatus = new SysServicesQuestion(); dieticianStatus.setUserId(customer.getMainDietitian()); dieticianStatus.setRole("dietician"); - customerStatus.setRead(0); + dieticianStatus.setRead(0); dieticianStatus.setQueId(servicesQuestion.getQueId()); statusList.add(dieticianStatus); SysServicesQuestion afterSaleStatus = new SysServicesQuestion(); afterSaleStatus.setUserId(customer.getAfterDietitian()); afterSaleStatus.setRole("after_sale"); - customerStatus.setRead(0); + afterSaleStatus.setRead(0); afterSaleStatus.setQueId(servicesQuestion.getQueId()); statusList.add(afterSaleStatus); SysServicesQuestion dieticianAssistantStatus = new SysServicesQuestion(); dieticianAssistantStatus.setUserId(customer.getAssistantDietitian()); dieticianAssistantStatus.setRole("dietician_assistant"); - customerStatus.setRead(0); + dieticianAssistantStatus.setRead(0); dieticianAssistantStatus.setQueId(servicesQuestion.getQueId()); + statusList.add(dieticianAssistantStatus); - return servicesQuestionMapper.insertSysServicesQuestionStatus(statusList); + servicesQuestionMapper.insertSysServicesQuestionStatus(statusList); + + servicesQuestion.setId(customerStatus.getId()); + servicesQuestion.setCusId(null); + + return servicesQuestion; } diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysServicesQuestionMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysServicesQuestionMapper.xml index e45c1da94..964e6d196 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysServicesQuestionMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysServicesQuestionMapper.xml @@ -48,7 +48,7 @@ ) AS user USING(user_id) - ORDER BY type ASC, update_time DESC + ORDER BY `read` ASC, update_time DESC + SELECT * FROM ( + SELECT * FROM sys_services_topic_status WHERE role = #{role} AND uid = #{uid} + ) AS status + LEFT JOIN sys_services_question USING(topic_id) + + + LEFT JOIN ( + SELECT name, id AS uid FROM sys_customer WHERE id = #{uid} + ) AS customer USING(uid) + + + LEFT JOIN ( + SELECT name, user_id AS uid, nick_name AS name FROM sys_user WHERE user_id = #{uid} + ) AS user USING(uid) + + + ORDER BY `read` ASC, update_time DESC + + + + + + + + + insert into sys_services_question + + que_id, + cus_id, + content, + type, + create_time, + img, + + + #{queId}, + #{cusId}, + #{content}, + #{type}, + #{createTime}, + + #{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 + + (#{status.queId}, #{status.userId}, #{status.role}, #{status.read}, now(), now()) + + + + + + update sys_services_question_status + + `read` = #{read}, + update_time = now(), + + + + + id = ${id} + + + + role != #{role} and + + + role = 'customer' and + + que_id = #{queId} + + + + + + + + insert into sys_services_question_session + + que_id, + user_id, + content, + `read`, + role, + img, + create_time, + update_time, + + + + #{queId}, + #{userId}, + #{content}, + #{read}, + #{role}, + + #{img, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler}, + + now(), + now(), + + + + + \ No newline at end of file