| @@ -26,7 +26,10 @@ import org.springframework.web.multipart.MultipartFile; | |||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import java.time.LocalDate; | import java.time.LocalDate; | ||||||
| import java.time.temporal.ChronoUnit; | 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 |  * 微信小程序统一Controller | ||||||
| @@ -134,37 +137,37 @@ public class WechatAppletController extends BaseController { | |||||||
|      * @param sysWxUserInfo |      * @param sysWxUserInfo | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @PostMapping("/synchroCustomerInfo") | //    @PostMapping("/synchroCustomerInfo") | ||||||
|     public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) { | //    public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) { | ||||||
|         if (StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())) { | //        if (StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())) { | ||||||
|             return AjaxResult.error("手机号为空"); | //            return AjaxResult.error("手机号为空"); | ||||||
|         } | //        } | ||||||
|         //根据手机号查询返回用户加密ID | //        //根据手机号查询返回用户加密ID | ||||||
|         SysCustomer customer = sysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone()); | //        SysCustomer customer = sysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone()); | ||||||
|         //加密ID | //        //加密ID | ||||||
|         String customerEncId = null; | //        String customerEncId = null; | ||||||
|         if (customer != null) { | //        if (customer != null) { | ||||||
|             sysWxUserInfo.setCusId(customer.getId()); | //            sysWxUserInfo.setCusId(customer.getId()); | ||||||
|             customerEncId = AesUtils.encrypt(customer.getId() + "", null); | //            customerEncId = AesUtils.encrypt(customer.getId() + "", null); | ||||||
|         } | //        } | ||||||
|         // 查询微信用户 | //        // 查询微信用户 | ||||||
|         SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); | //        SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); | ||||||
|         if (userInfo != null) { | //        if (userInfo != null) { | ||||||
|             //更新数据 | //            //更新数据 | ||||||
|             sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); | //            sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo); | ||||||
|         } else { | //        } else { | ||||||
|             sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); | //            sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); | ||||||
|         } | //        } | ||||||
|         Map<String, Object> result = new HashMap<>(); | //        Map<String, Object> result = new HashMap<>(); | ||||||
|         result.put("customerId", customerEncId); | //        result.put("customerId", customerEncId); | ||||||
|         //查询未读消息数量 | //        //查询未读消息数量 | ||||||
|         SysMessageNotice messageParam = new SysMessageNotice(); | //        SysMessageNotice messageParam = new SysMessageNotice(); | ||||||
|         messageParam.setReadType(0); | //        messageParam.setReadType(0); | ||||||
|         messageParam.setMessageCustomer(customer != null ? customer.getId() : 0); | //        messageParam.setMessageCustomer(customer != null ? customer.getId() : 0); | ||||||
|         int unReadNoticeTotal = sysMessageNoticeService.getCustomerMessageCount(messageParam); | //        int unReadNoticeTotal = sysMessageNoticeService.getCustomerMessageCount(messageParam); | ||||||
|         result.put("unReadNoticeTotal", unReadNoticeTotal); | //        result.put("unReadNoticeTotal", unReadNoticeTotal); | ||||||
|         return AjaxResult.success(result); | //        return AjaxResult.success(result); | ||||||
|     } | //    } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 微信小程序获取客户打卡记录 |      * 微信小程序获取客户打卡记录 | ||||||
| @@ -174,28 +177,9 @@ public class WechatAppletController extends BaseController { | |||||||
|      */ |      */ | ||||||
|     @GetMapping(value = "/getPunchLogs") |     @GetMapping(value = "/getPunchLogs") | ||||||
|     public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) { |     public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) { | ||||||
|  | //        startPage(); | ||||||
|         startPage(); |  | ||||||
|         List<WxLogInfo> list = sysWxUserLogService.getWxLogInfoList(sysWxUserLog); |         List<WxLogInfo> list = sysWxUserLogService.getWxLogInfoList(sysWxUserLog); | ||||||
|  |  | ||||||
|  |  | ||||||
|         return getDataTable(list); |         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") |     @PostMapping(value = "/addPunchLog") | ||||||
|     public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) { |     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.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)); |             return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog)); | ||||||
|         } else { |  | ||||||
|             return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); |  | ||||||
|         } |         } | ||||||
|  |         return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获取微信用户记录详细信息 |      * 获取微信用户记录详细信息 | ||||||
|      */ |      */ | ||||||
|     @GetMapping(value = "/getPunchLogDetail/{id}") | //    @GetMapping(value = "/getPunchLogDetail/{id}") | ||||||
|     public AjaxResult getPunchLogDetail(@PathVariable("id") String id) { | //    public AjaxResult getPunchLogDetail(@PathVariable("id") String id) { | ||||||
|         WxLogInfo sysWxUserLog = null; | //        WxLogInfo sysWxUserLog = null; | ||||||
|         //根据ID查询 | //        //根据ID查询 | ||||||
|         SysWxUserLog param = new SysWxUserLog(); | //        SysWxUserLog param = new SysWxUserLog(); | ||||||
|         param.setId(Long.parseLong(id)); | //        param.setId(Long.parseLong(id)); | ||||||
|         sysWxUserLog = sysWxUserLogService.getWxLogInfoDetailById(param); | //        sysWxUserLog = sysWxUserLogService.getWxLogInfoDetailById(param); | ||||||
|         if (sysWxUserLog == null) { | //        if (sysWxUserLog == null) { | ||||||
|             return AjaxResult.error("打卡记录不存在"); | //            return AjaxResult.error("打卡记录不存在"); | ||||||
|         } | //        } | ||||||
|  | // | ||||||
|         List<String> allUrlList = new ArrayList<>(); | //        List<String> allUrlList = new ArrayList<>(); | ||||||
|         allUrlList.addAll(sysWxUserLog.getBreakfastImagesUrl()); | //        allUrlList.addAll(sysWxUserLog.getBreakfastImagesUrl()); | ||||||
|         allUrlList.addAll(sysWxUserLog.getLunchImagesUrl()); | //        allUrlList.addAll(sysWxUserLog.getLunchImagesUrl()); | ||||||
|         allUrlList.addAll(sysWxUserLog.getDinnerImagesUrl()); | //        allUrlList.addAll(sysWxUserLog.getDinnerImagesUrl()); | ||||||
|         allUrlList.addAll(sysWxUserLog.getExtraMealImagesUrl()); | //        allUrlList.addAll(sysWxUserLog.getExtraMealImagesUrl()); | ||||||
|         sysWxUserLog.setAllImagesUrl(allUrlList); | //        sysWxUserLog.setAllImagesUrl(allUrlList); | ||||||
|         sysWxUserLog.setAllImages(StringUtils.join(allUrlList, "|")); | //        sysWxUserLog.setAllImages(StringUtils.join(allUrlList, "|")); | ||||||
|  | // | ||||||
|         return AjaxResult.success(sysWxUserLog); | //        return AjaxResult.success(sysWxUserLog); | ||||||
|     } | //    } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 处理返回值的ID加密 |      * 处理返回值的ID加密 | ||||||
| @@ -456,7 +425,7 @@ public class WechatAppletController extends BaseController { | |||||||
|             sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); |             sysWxUserInfo.setUpdateTime(DateUtils.getNowDate()); | ||||||
|             //先根据cusId查询是否已经绑定过微信用户 |             //先根据cusId查询是否已经绑定过微信用户 | ||||||
|             SysWxUserInfo cusIdWxUserInfo = sysWxUserInfoService.selectSysWxUserInfoByCusId(sysCustomer.getId()); |             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()); |                 sysWxUserInfoService.removeCusIdByOpenId(curWxUserInfo.getOpenid()); | ||||||
|             } |             } | ||||||
| @@ -472,7 +441,7 @@ public class WechatAppletController extends BaseController { | |||||||
|             curWxUserInfo = sysWxUserInfo; |             curWxUserInfo = sysWxUserInfo; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // 更新时间超过7天,重新登录获取最新信息 |         // 更新时间超过21天,重新登录获取最新信息 | ||||||
|         if (StringUtils.isEmpty(curWxUserInfo.getAvatarUrl()) || ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(curWxUserInfo.getUpdateTime()), LocalDate.now()) >= 21) { |         if (StringUtils.isEmpty(curWxUserInfo.getAvatarUrl()) || ChronoUnit.DAYS.between(DateUtils.dateToLocalDate(curWxUserInfo.getUpdateTime()), LocalDate.now()) >= 21) { | ||||||
|             return AjaxResult.error(5001, "信息缺失或者过期需要重新登录"); |             return AjaxResult.error(5001, "信息缺失或者过期需要重新登录"); | ||||||
|         } |         } | ||||||
| @@ -749,8 +718,8 @@ public class WechatAppletController extends BaseController { | |||||||
|         if (list != null && list.size() > 0) { |         if (list != null && list.size() > 0) { | ||||||
|             for (CommunityPunchReponse comm : list) { |             for (CommunityPunchReponse comm : list) { | ||||||
|                 comm.setId(AesUtils.encrypt(comm.getId())); |                 comm.setId(AesUtils.encrypt(comm.getId())); | ||||||
|                 comm.setCusId(AesUtils.encrypt(comm.getCusId())); | //                comm.setCusId(AesUtils.encrypt(comm.getCusId())); | ||||||
|                 comm.setThumbsupNum(comm.getThumbsupOpenid() != null ? comm.getThumbsupOpenid().size() : 0); | //                comm.setThumbsupNum(comm.getThumbsupOpenid() != null ? comm.getThumbsupOpenid().size() : 0); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return getDataTable(list); |         return getDataTable(list); | ||||||
|   | |||||||
| @@ -22,11 +22,6 @@ public class CommunityPunchReponse { | |||||||
|      */ |      */ | ||||||
|     private String openid; |     private String openid; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 客户ID |  | ||||||
|      */ |  | ||||||
|     private String cusId; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 昵称 |      * 昵称 | ||||||
|      */ |      */ | ||||||
| @@ -43,11 +38,6 @@ public class CommunityPunchReponse { | |||||||
|     @JsonFormat(pattern = "yyyy-MM-dd") |     @JsonFormat(pattern = "yyyy-MM-dd") | ||||||
|     private Date logTime; |     private Date logTime; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 当天打卡体重 |  | ||||||
|      */ |  | ||||||
|     private BigDecimal weight; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 营养师评论 |      * 营养师评论 | ||||||
|      */ |      */ | ||||||
| @@ -66,10 +56,10 @@ public class CommunityPunchReponse { | |||||||
|     /** |     /** | ||||||
|      * 近期打卡体重信息  logTime: 打卡日期  weight: 体重 |      * 近期打卡体重信息  logTime: 打卡日期  weight: 体重 | ||||||
|      */ |      */ | ||||||
|     private List<Map<String,Object>> recentWeight; |     private List<Map<String,Object>> weightData; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 点赞的openid |      * 点赞的openid | ||||||
|      */ |      */ | ||||||
|     private List<Map<String,Object>> thumbsupOpenid; |     private List<Map<String,Object>> thumbsupUser; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -336,7 +336,6 @@ | |||||||
|     <resultMap id="punchReponseMap" type="com.stdiet.custom.dto.response.CommunityPunchReponse"> |     <resultMap id="punchReponseMap" type="com.stdiet.custom.dto.response.CommunityPunchReponse"> | ||||||
|         <result property="id" column="id"/> |         <result property="id" column="id"/> | ||||||
|         <result property="openid" column="openid"/> |         <result property="openid" column="openid"/> | ||||||
|         <result property="cusId" column="cus_id"/> |  | ||||||
|         <result property="nickName" column="nick_name"/> |         <result property="nickName" column="nick_name"/> | ||||||
|         <result property="avatarUrl" column="avatar_url"/> |         <result property="avatarUrl" column="avatar_url"/> | ||||||
|         <result property="logTime" column="log_time"/> |         <result property="logTime" column="log_time"/> | ||||||
| @@ -345,31 +344,33 @@ | |||||||
|         <result property="thumbsupNum" column="thumbsup_num"/> |         <result property="thumbsupNum" column="thumbsup_num"/> | ||||||
|         <result property="healthManifesto" column="health_manifesto"/> |         <result property="healthManifesto" column="health_manifesto"/> | ||||||
|         <!-- 查询最近五天体重 --> |         <!-- 查询最近五天体重 --> | ||||||
|         <association property="recentWeight" column="{cusId=cus_id,logTime=log_time}" select="getRecentWeight"/> |         <association property="weightData" column="{id=openid}" select="getRecentWeight"/> | ||||||
|         <!-- 查询点赞的openid --> |         <!-- 查询点赞的openid --> | ||||||
|         <association property="thumbsupOpenid" column="id" select="getPunchThumbsupList"/> |         <association property="thumbsupUser" column="id" select="getPunchThumbsupList"/> | ||||||
|     </resultMap> |     </resultMap> | ||||||
|  |  | ||||||
|     <!--  查询打卡社区内容  --> |     <!--  查询打卡社区内容  --> | ||||||
|     <select id="getCommunityPunch" resultMap="punchReponseMap" parameterType="SysWxUserLog"> |     <select id="getCommunityPunch" resultMap="punchReponseMap" parameterType="SysWxUserLog"> | ||||||
|          select wxlog.id,wxinfo.openid,wxinfo.cus_id,wxinfo.nick_name,wxinfo.avatar_url,wxlog.log_time,wxlog.weight,wxlog.comment,wxlog.thumbsup_num,wxlog.health_manifesto from sys_wx_user_log wxlog |          SELECT * FROM | ||||||
|          left join sys_wx_user_info wxinfo on wxinfo.openid  = wxlog.openid |         (SELECT id, openid, `comment`, health_manifesto, log_time FROM sys_wx_user_log WHERE TO_DAYS(log_time) = TO_DAYS(NOW()) AND del_flag = 0) AS wxlog | ||||||
|          where wxlog.del_flag = 0 |         LEFT JOIN (SELECT openid, nick_name, avatar_url FROM sys_wx_user_info) AS wxinfo | ||||||
|          order by wxlog.log_time desc |         USING(openid) | ||||||
|  |         ORDER BY log_time DESC | ||||||
|     </select> |     </select> | ||||||
|  |  | ||||||
|     <!-- 查询打卡社区中点赞的openid --> |     <!-- 查询打卡社区中点赞的openid --> | ||||||
|     <select id="getPunchThumbsupList" parameterType="Long" resultType="Map"> |     <select id="getPunchThumbsupList" parameterType="Long" resultType="Map"> | ||||||
|         select cus_openid as openid from sys_punch_thumbsup |         select * from | ||||||
|         where punch_id = #{id} and del_flag = 0 |         (select cus_openid as openid, DATE_FORMAT(create_time,'%Y-%m-%d %H:%i') as `time` from sys_punch_thumbsup where punch_id = #{id} and del_flag = 0 order by create_time asc) as tu | ||||||
|  |         left join (SELECT openid, nick_name as nickName, avatar_url as avatarUrl FROM sys_wx_user_info) AS wxinfo | ||||||
|  |         using(openid) | ||||||
|     </select> |     </select> | ||||||
|  |  | ||||||
|     <!-- 查询最近一周的打卡体重 --> |     <!-- 查询所有打卡体重 --> | ||||||
|     <select id="getRecentWeight" resultType="Map"> |     <select id="getRecentWeight" resultType="Map"> | ||||||
|         select DATE_FORMAT(wxlog.log_time,'%Y-%m-%d') as logTime,wxlog.weight as weight from sys_wx_user_log wxlog |         select DATE_FORMAT(log_time,'%Y-%m-%d') as name, weight as `value` from sys_wx_user_log | ||||||
|         left join sys_wx_user_info wxinfo on wxinfo.openid  = wxlog.openid |         where del_flag = 0 and openid = #{id} | ||||||
|         where wxlog.del_flag = 0 and wxinfo.cus_id = #{cusId} and #{logTime} >= wxlog.log_time |         order by log_time asc | ||||||
|         order by wxlog.log_time desc limit 7 |  | ||||||
|     </select> |     </select> | ||||||
|  |  | ||||||
|     <!-- 根据客户ID查询总共打卡次数 --> |     <!-- 根据客户ID查询总共打卡次数 --> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user