From e7d76b9a37f16eff7f93657307144679addaf018 Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Mon, 26 Jul 2021 18:37:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=89=93=E5=8D=A1=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/WechatAppletController.java | 155 +++++++----------- .../dto/response/CommunityPunchReponse.java | 14 +- .../mapper/custom/SysWxUserLogMapper.xml | 29 ++-- 3 files changed, 79 insertions(+), 119 deletions(-) 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 22340761d..ee7b125d0 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 @@ -26,7 +26,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 微信小程序统一Controller @@ -134,37 +137,37 @@ public class WechatAppletController extends BaseController { * @param sysWxUserInfo * @return */ - @PostMapping("/synchroCustomerInfo") - public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) { - if (StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())) { - return AjaxResult.error("手机号为空"); - } - //根据手机号查询返回用户加密ID - SysCustomer customer = sysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone()); - //加密ID - String customerEncId = null; - if (customer != null) { - sysWxUserInfo.setCusId(customer.getId()); - customerEncId = AesUtils.encrypt(customer.getId() + "", null); - } - // 查询微信用户 - SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); - if (userInfo != null) { - //更新数据 - sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); - } else { - sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); - } - Map result = new HashMap<>(); - result.put("customerId", customerEncId); - //查询未读消息数量 - SysMessageNotice messageParam = new SysMessageNotice(); - messageParam.setReadType(0); - messageParam.setMessageCustomer(customer != null ? customer.getId() : 0); - int unReadNoticeTotal = sysMessageNoticeService.getCustomerMessageCount(messageParam); - result.put("unReadNoticeTotal", unReadNoticeTotal); - return AjaxResult.success(result); - } +// @PostMapping("/synchroCustomerInfo") +// public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) { +// if (StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())) { +// return AjaxResult.error("手机号为空"); +// } +// //根据手机号查询返回用户加密ID +// SysCustomer customer = sysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone()); +// //加密ID +// String customerEncId = null; +// if (customer != null) { +// sysWxUserInfo.setCusId(customer.getId()); +// customerEncId = AesUtils.encrypt(customer.getId() + "", null); +// } +// // 查询微信用户 +// SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); +// if (userInfo != null) { +// //更新数据 +// sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); +// } else { +// sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); +// } +// Map result = new HashMap<>(); +// result.put("customerId", customerEncId); +// //查询未读消息数量 +// SysMessageNotice messageParam = new SysMessageNotice(); +// messageParam.setReadType(0); +// messageParam.setMessageCustomer(customer != null ? customer.getId() : 0); +// int unReadNoticeTotal = sysMessageNoticeService.getCustomerMessageCount(messageParam); +// result.put("unReadNoticeTotal", unReadNoticeTotal); +// return AjaxResult.success(result); +// } /** * 微信小程序获取客户打卡记录 @@ -174,28 +177,9 @@ public class WechatAppletController extends BaseController { */ @GetMapping(value = "/getPunchLogs") public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) { - - startPage(); +// startPage(); List list = sysWxUserLogService.getWxLogInfoList(sysWxUserLog); - - return getDataTable(list); - - } - - /** - * 今日是否打卡 - * - * @param openid - * @return - */ - @GetMapping(value = "/checkNowPunchLog/{openid}") - public AjaxResult checkNowPunchLog(@PathVariable String openid) { - SysWxUserLog sysWxUserLog = new SysWxUserLog(); - sysWxUserLog.setOpenid(openid); - sysWxUserLog.setLogTime(new Date()); - int count = StringUtils.isEmpty(openid) ? 0 : sysWxUserLogService.checkWxLogInfoCount(sysWxUserLog); - return AjaxResult.success(count); } /** @@ -206,51 +190,36 @@ public class WechatAppletController extends BaseController { */ @PostMapping(value = "/addPunchLog") public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) { - // 查询微信用户 -// SysWxUserInfo userInfo = StringUtils.isEmpty(sysWxUserLog.getOpenid()) ? null : sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid()); -// if (userInfo == null || StringUtils.isEmpty(userInfo.getPhone())) { -// return AjaxResult.error("打卡失败"); -// } if (sysWxUserLog.getId() == null) { -// //查询今日是否已打卡 -// if (sysWxUserLog.getLogTime() == null) { -// sysWxUserLog.setLogTime(new Date()); -// } -// int count = sysWxUserLogService.checkWxLogInfoCount(sysWxUserLog); -// if (count > 0) { -// return AjaxResult.error("今日已打卡,不可重复打卡"); -// } return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog)); - } else { - return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); } - + return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); } /** * 获取微信用户记录详细信息 */ - @GetMapping(value = "/getPunchLogDetail/{id}") - public AjaxResult getPunchLogDetail(@PathVariable("id") String id) { - WxLogInfo sysWxUserLog = null; - //根据ID查询 - SysWxUserLog param = new SysWxUserLog(); - param.setId(Long.parseLong(id)); - sysWxUserLog = sysWxUserLogService.getWxLogInfoDetailById(param); - if (sysWxUserLog == null) { - return AjaxResult.error("打卡记录不存在"); - } - - List allUrlList = new ArrayList<>(); - allUrlList.addAll(sysWxUserLog.getBreakfastImagesUrl()); - allUrlList.addAll(sysWxUserLog.getLunchImagesUrl()); - allUrlList.addAll(sysWxUserLog.getDinnerImagesUrl()); - allUrlList.addAll(sysWxUserLog.getExtraMealImagesUrl()); - sysWxUserLog.setAllImagesUrl(allUrlList); - sysWxUserLog.setAllImages(StringUtils.join(allUrlList, "|")); - - return AjaxResult.success(sysWxUserLog); - } +// @GetMapping(value = "/getPunchLogDetail/{id}") +// public AjaxResult getPunchLogDetail(@PathVariable("id") String id) { +// WxLogInfo sysWxUserLog = null; +// //根据ID查询 +// SysWxUserLog param = new SysWxUserLog(); +// param.setId(Long.parseLong(id)); +// sysWxUserLog = sysWxUserLogService.getWxLogInfoDetailById(param); +// if (sysWxUserLog == null) { +// return AjaxResult.error("打卡记录不存在"); +// } +// +// List allUrlList = new ArrayList<>(); +// allUrlList.addAll(sysWxUserLog.getBreakfastImagesUrl()); +// allUrlList.addAll(sysWxUserLog.getLunchImagesUrl()); +// allUrlList.addAll(sysWxUserLog.getDinnerImagesUrl()); +// allUrlList.addAll(sysWxUserLog.getExtraMealImagesUrl()); +// sysWxUserLog.setAllImagesUrl(allUrlList); +// sysWxUserLog.setAllImages(StringUtils.join(allUrlList, "|")); +// +// return AjaxResult.success(sysWxUserLog); +// } /** * 处理返回值的ID加密 @@ -456,7 +425,7 @@ public class WechatAppletController extends BaseController { sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); //先根据cusId查询是否已经绑定过微信用户 SysWxUserInfo cusIdWxUserInfo = sysWxUserInfoService.selectSysWxUserInfoByCusId(sysCustomer.getId()); - if(cusIdWxUserInfo != null && !sysWxUserInfo.getOpenid().equals(curWxUserInfo.getOpenid())){ + if (cusIdWxUserInfo != null && !sysWxUserInfo.getOpenid().equals(curWxUserInfo.getOpenid())) { //解绑之前记录 sysWxUserInfoService.removeCusIdByOpenId(curWxUserInfo.getOpenid()); } @@ -472,7 +441,7 @@ public class WechatAppletController extends BaseController { curWxUserInfo = sysWxUserInfo; } - // 更新时间超过7天,重新登录获取最新信息 + // 更新时间超过21天,重新登录获取最新信息 if (StringUtils.isEmpty(curWxUserInfo.getAvatarUrl()) || ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(curWxUserInfo.getUpdateTime()), LocalDate.now()) >= 21) { return AjaxResult.error(5001, "信息缺失或者过期需要重新登录"); } @@ -749,8 +718,8 @@ public class WechatAppletController extends BaseController { if (list != null && list.size() > 0) { for (CommunityPunchReponse comm : list) { comm.setId(AesUtils.encrypt(comm.getId())); - comm.setCusId(AesUtils.encrypt(comm.getCusId())); - comm.setThumbsupNum(comm.getThumbsupOpenid() != null ? comm.getThumbsupOpenid().size() : 0); +// comm.setCusId(AesUtils.encrypt(comm.getCusId())); +// comm.setThumbsupNum(comm.getThumbsupOpenid() != null ? comm.getThumbsupOpenid().size() : 0); } } return getDataTable(list); diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/CommunityPunchReponse.java b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/CommunityPunchReponse.java index 1853d7f0c..59e5d2ce9 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/CommunityPunchReponse.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/dto/response/CommunityPunchReponse.java @@ -22,11 +22,6 @@ public class CommunityPunchReponse { */ private String openid; - /** - * 客户ID - */ - private String cusId; - /** * 昵称 */ @@ -43,11 +38,6 @@ public class CommunityPunchReponse { @JsonFormat(pattern = "yyyy-MM-dd") private Date logTime; - /** - * 当天打卡体重 - */ - private BigDecimal weight; - /** * 营养师评论 */ @@ -66,10 +56,10 @@ public class CommunityPunchReponse { /** * 近期打卡体重信息 logTime: 打卡日期 weight: 体重 */ - private List> recentWeight; + private List> weightData; /** * 点赞的openid */ - private List> thumbsupOpenid; + private List> thumbsupUser; } diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml index 7ed3de323..4ebd06b96 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml @@ -336,7 +336,6 @@ - @@ -345,31 +344,33 @@ - + - + - + From e54b05b833a597d38990c7193443fb288b829320 Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Tue, 27 Jul 2021 20:29:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=89=93=E5=8D=A1=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/WechatAppletController.java | 43 +++++++++---------- .../custom/domain/SysPunchThumbsup.java | 2 + .../typehandler/EncryptedIdHandler.java | 41 ++++++++++++++++++ .../mapper/custom/SysPunchThumbsupMapper.xml | 8 ++-- .../mapper/custom/SysWxUserLogMapper.xml | 29 +++++++++---- 5 files changed, 89 insertions(+), 34 deletions(-) create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/typehandler/EncryptedIdHandler.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 index ee7b125d0..381eb20eb 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 @@ -715,13 +715,13 @@ public class WechatAppletController extends BaseController { public TableDataInfo getCommunityPunch() { startPage(); List list = sysWxUserLogService.getCommunityPunch(new SysWxUserLog()); - if (list != null && list.size() > 0) { - for (CommunityPunchReponse comm : list) { - comm.setId(AesUtils.encrypt(comm.getId())); +// if (list != null && list.size() > 0) { +// for (CommunityPunchReponse comm : list) { +// comm.setId(AesUtils.encrypt(comm.getId())); // comm.setCusId(AesUtils.encrypt(comm.getCusId())); // comm.setThumbsupNum(comm.getThumbsupOpenid() != null ? comm.getThumbsupOpenid().size() : 0); - } - } +// } +// } return getDataTable(list); } @@ -732,25 +732,24 @@ public class WechatAppletController extends BaseController { */ @PostMapping("/thumbsupPunch") public AjaxResult getCommunityPunch(@RequestBody SysPunchThumbsup sysPunchThumbsup) { - if (StringUtils.isEmpty(sysPunchThumbsup.getCusOpenid(), sysPunchThumbsup.getEncPunchId()) || sysPunchThumbsup.getThumbsupFlag() == null) { - return AjaxResult.error("缺少必要参数"); + int rows = 0; + if (StringUtils.isEmpty(sysPunchThumbsup.getEncId())) { + // 点赞 + sysPunchThumbsup.setPunchId(Long.parseLong(AesUtils.decrypt(sysPunchThumbsup.getEncPunchId()))); + rows = sysPunchThumbsupService.insertSysPunchThumbsup(sysPunchThumbsup); + if (rows > 0) { + Map resultData = new HashMap<>(); + resultData.put("id", AesUtils.encrypt(String.valueOf(sysPunchThumbsup.getId()))); + resultData.put("openid", sysPunchThumbsup.getCusOpenid()); + resultData.put("punchId", sysPunchThumbsup.getEncPunchId()); + return AjaxResult.success(resultData); + } + } else { + // 取消点赞 + rows = sysPunchThumbsupService.deleteSysPunchThumbsupById(Long.parseLong(AesUtils.decrypt(sysPunchThumbsup.getEncId()))); } - sysPunchThumbsup.setPunchId(Long.parseLong(AesUtils.decrypt(sysPunchThumbsup.getEncPunchId()))); - SysPunchThumbsup existPunchThumbsup = sysPunchThumbsupService.getThumbsupByPunchIdAndOpenid(sysPunchThumbsup); - if (existPunchThumbsup != null && sysPunchThumbsup.getThumbsupFlag()) { - return AjaxResult.error("已点过暂,无法重复点赞"); - } - if (existPunchThumbsup == null && !sysPunchThumbsup.getThumbsupFlag()) { - return AjaxResult.error("还未未点赞,无法取消点赞"); - } - int row = 0; - try { - row = sysPunchThumbsup.getThumbsupFlag() ? sysPunchThumbsupService.insertSysPunchThumbsup(sysPunchThumbsup) : sysPunchThumbsupService.deleteThumbsupByPunchIdAndOpenid(sysPunchThumbsup); - } catch (Exception e) { - e.printStackTrace(); - } - return toAjax(row); + return toAjax(rows); } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysPunchThumbsup.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysPunchThumbsup.java index 7b1ccb17c..f44f7eadb 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysPunchThumbsup.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysPunchThumbsup.java @@ -18,6 +18,8 @@ public class SysPunchThumbsup extends BaseEntity /** $column.columnComment */ private Long id; + private String encId; + /** 打卡记录ID */ @Excel(name = "打卡记录ID") private Long punchId; diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/EncryptedIdHandler.java b/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/EncryptedIdHandler.java new file mode 100644 index 000000000..7cef65489 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/EncryptedIdHandler.java @@ -0,0 +1,41 @@ +package com.stdiet.custom.typehandler; + +import com.stdiet.common.utils.sign.AesUtils; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +@MappedTypes({String.class}) +@MappedJdbcTypes({JdbcType.BIGINT}) +public class EncryptedIdHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement preparedStatement, int i, String encrypedId, JdbcType jdbcType) throws SQLException { + preparedStatement.setLong(i, Long.parseLong(AesUtils.decrypt(encrypedId))); + } + + @Override + public String getNullableResult(ResultSet resultSet, String s) throws SQLException { + return this.encryptedString(resultSet.getLong(s)); + } + + @Override + public String getNullableResult(ResultSet resultSet, int i) throws SQLException { + return this.encryptedString(resultSet.getLong(i)); + } + + @Override + public String getNullableResult(CallableStatement callableStatement, int i) throws SQLException { + return this.encryptedString(callableStatement.getLong(i)); + } + + private String encryptedString(Long id) { + return AesUtils.encrypt(String.valueOf(id)); + } +} diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysPunchThumbsupMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysPunchThumbsupMapper.xml index c9fd4a5e9..c2f0ea3e7 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysPunchThumbsupMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysPunchThumbsupMapper.xml @@ -31,15 +31,15 @@ punch_id, cus_openid, - create_time, - update_time, + create_time, + update_time, del_flag, #{punchId}, #{cusOpenid}, - #{createTime}, - #{updateTime}, + now(), + now(), #{delFlag}, diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml index 4ebd06b96..7562a6bbf 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml @@ -334,15 +334,15 @@ - + - + @@ -359,18 +359,31 @@ - + select id, cus_openid from sys_punch_thumbsup where punch_id = #{id} and del_flag = 0 + + +