From 1d66f7334a5432539dfb106363c4b11c8b2742a2 Mon Sep 17 00:00:00 2001 From: xiezhijun <15270898033@163.com> Date: Mon, 22 Mar 2021 15:51:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=89=93=E5=8D=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/WechatAppletController.java | 160 ++++++++++++++++++ .../stdiet/custom/mapper/SysOrderMapper.java | 8 + .../custom/service/ISysOrderService.java | 9 + .../service/impl/SysOrderServiceImpl.java | 10 ++ .../mapper/custom/SysOrderMapper.xml | 12 ++ .../mapper/custom/SysWxUserLogMapper.xml | 2 +- 6 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java 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 new file mode 100644 index 000000000..afa4fc614 --- /dev/null +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java @@ -0,0 +1,160 @@ +package com.stdiet.web.controller.custom; + +import com.itextpdf.io.util.DateTimeUtil; +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.common.utils.oss.AliyunOSSUtils; +import com.stdiet.common.utils.sign.AesUtils; +import com.stdiet.custom.domain.*; +import com.stdiet.custom.dto.response.CustomerCaseResponse; +import com.stdiet.custom.page.WxLogInfo; +import com.stdiet.custom.service.ISysCustomerCaseService; +import com.stdiet.custom.service.ISysOrderService; +import com.stdiet.custom.service.ISysWxUserInfoService; +import com.stdiet.custom.service.ISysWxUserLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * 微信小程序统一Controller + */ +@RestController +@RequestMapping("/wx/applet") +public class WechatAppletController extends BaseController { + + + @Autowired + private ISysCustomerCaseService sysCustomerCaseService; + + @Autowired + private ISysWxUserLogService sysWxUserLogService; + + @Autowired + private ISysWxUserInfoService sysWxUserInfoService; + + @Autowired + private ISysOrderService sysOrderService; + + /** + * 查询微信小程序中展示的客户案例 + */ + @GetMapping("/caseList") + public TableDataInfo caseList(SysCustomerCase sysCustomerCase) + { + startPage(); + sysCustomerCase.setKeywordArray(StringUtils.isNotEmpty(sysCustomerCase.getKeyword()) ? sysCustomerCase.getKeyword().split(",") : null); + List list = sysCustomerCaseService.getWxCustomerCaseList(sysCustomerCase); + //处理ID加密 + dealIdEnc(list); + return getDataTable(list); + } + + /** + * 查询客户案例文件列表 + */ + @GetMapping("/getFileByCaseId") + public AjaxResult getFileByCaseId(@RequestParam("caseId")String caseId) + { + Long id = StringUtils.isNotEmpty(caseId) ? Long.parseLong(AesUtils.decrypt(caseId, null)) : null; + CustomerCaseResponse customerCaseResponse = new CustomerCaseResponse(); + customerCaseResponse.setId(caseId); + if(id != null){ + List list = sysCustomerCaseService.getFileListByCaseId(id); + List fileUrl = new ArrayList<>(); + for (SysCustomerCaseFile caseFile : list) { + fileUrl.add(caseFile.getFileUrl()); + } + List downUrlList = AliyunOSSUtils.generatePresignedUrl(fileUrl); + customerCaseResponse.setFileList(downUrlList); + }else{ + customerCaseResponse.setFileList(new ArrayList<>()); + } + return AjaxResult.success(customerCaseResponse); + } + + /** + * 同步客户信息,返回订单数量 + * @param sysWxUserInfo + * @return + */ + @PostMapping("/synchroCustomerInfo") + public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) { + if(StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())){ + return AjaxResult.error("手机号为空"); + } + // 查询微信用户 + SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); + if(userInfo != null){ + //更新数据 + sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); + }else{ + sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); + } + //查询是否下单 + SysCustomer param = new SysCustomer(); + param.setPhone(sysWxUserInfo.getPhone()); + int orderCount = sysOrderService.getOrderCountByCustomer(param); + //返回订单数量 + return AjaxResult.success(orderCount); + } + + /** + * 微信小程序获取客户打卡记录 + * @param sysWxUserLog + * @return + */ + @GetMapping(value = "/getPunchLogs") + public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) { + startPage(); + List list = sysWxUserLogService.selectWxLogInfoList(sysWxUserLog); + return getDataTable(list); + } + + /** + * 今日是否打卡 + * @param openid + * @return + */ + @GetMapping(value = "/checkNowPunchLog/{openid}") + public AjaxResult checkNowPunchLog(@PathVariable String openid) { + int count = StringUtils.isEmpty(openid) ? 0 : sysWxUserLogService.checkWxLogInfoCount(openid); + return AjaxResult.success(count); + } + + /** + * 微信小程序打卡 + * @param sysWxUserLog + * @return + */ + @PostMapping(value = "/addPunchLog") + public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) { + // 查询微信用户 + SysWxUserInfo userInfo = StringUtils.isEmpty(sysWxUserLog.getOpenid()) ? null : sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid()); + if (userInfo == null) { + return AjaxResult.error("不存在客户"); + } + //查询今日是否已打卡 + int count = sysWxUserLogService.checkWxLogInfoCount(sysWxUserLog.getOpenid()); + if(count > 0){ + return AjaxResult.error("今日已打卡,不可重复打卡"); + } + sysWxUserLog.setLogTime(DateTimeUtil.getCurrentTimeDate()); + return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog)); + } + + /** + * 处理返回值的ID加密 + * @param list + * @return + */ + private void dealIdEnc(List list){ + for (CustomerCaseResponse cus : list) { + cus.setId(AesUtils.encrypt(cus.getId()+"", null)); + } + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java index e23a0259e..8662f4b91 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysOrderMapper.java @@ -5,6 +5,7 @@ import java.util.List; import com.stdiet.custom.domain.SysCommision; import com.stdiet.custom.domain.SysCommissionDayDetail; +import com.stdiet.custom.domain.SysCustomer; import com.stdiet.custom.domain.SysOrder; import com.stdiet.custom.dto.request.SysOrderCommision; import org.apache.ibatis.annotations.Param; @@ -77,4 +78,11 @@ public interface SysOrderMapper * @return */ List selectSimpleOrderMessage(SysCommision sysCommision); + + /** + * 查询客户订单数量 + * @param sysCustomer + * @return + */ + int getOrderCountByCustomer(SysCustomer sysCustomer); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java index e641dcb76..8daa51afe 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysOrderService.java @@ -3,6 +3,8 @@ package com.stdiet.custom.service; import java.math.BigDecimal; import java.util.Date; import java.util.List; + +import com.stdiet.custom.domain.SysCustomer; import com.stdiet.custom.domain.SysOrder; /** @@ -75,4 +77,11 @@ public interface ISysOrderService * @return */ int updateOrderServerEndDate(Long orderId, boolean updatePlan); + + /** + * 查询客户订单数量 + * @param sysCustomer + * @return + */ + int getOrderCountByCustomer(SysCustomer sysCustomer); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java index c822e243c..27c17c8e9 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysOrderServiceImpl.java @@ -4,6 +4,7 @@ import com.stdiet.common.annotation.Excel; import com.stdiet.common.utils.DateUtils; import com.stdiet.common.utils.SecurityUtils; import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysCustomer; import com.stdiet.custom.domain.SysOrder; import com.stdiet.custom.mapper.SysOrderMapper; import com.stdiet.custom.service.ISysCommissionDayService; @@ -326,4 +327,13 @@ public class SysOrderServiceImpl implements ISysOrderService { //删除食谱计划 sysRecipesPlanService.delRecipesPlanByOrderId(orderIds); } + + /** + * 查询客户订单数量 + * @param sysCustomer + * @return + */ + public int getOrderCountByCustomer(SysCustomer sysCustomer){ + return sysOrderMapper.getOrderCountByCustomer(sysCustomer); + } } \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml index dbe0d15f2..dff79ab11 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysOrderMapper.xml @@ -408,4 +408,16 @@ order by o.order_time desc + + + \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml index e14a6e8f8..a47b57d33 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml @@ -78,7 +78,7 @@ - order by log_time asc + order by log_time desc