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 3333e7ca9..22340761d 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 @@ -173,39 +173,14 @@ public class WechatAppletController extends BaseController { * @return */ @GetMapping(value = "/getPunchLogs") - public AjaxResult getPunchLogs(SysWxUserLog sysWxUserLog) { - if (StringUtils.isEmpty(sysWxUserLog.getPhone()) && StringUtils.isEmpty(sysWxUserLog.getOpenid())) { - return AjaxResult.error(5001, "缺少参数"); - } - //查询是否下单 - SysCustomer param = new SysCustomer(); - param.setPhone(sysWxUserLog.getPhone()); - int orderCount = sysOrderService.getOrderCountByCustomer(param); - if (orderCount > 0) { - Map result = new HashMap<>(); - //今日是否已打卡 - boolean isPunch = false; - startPage(); - List list = sysWxUserLogService.getWxLogInfoList(sysWxUserLog); - if (list.size() > 0) { - WxLogInfo lastLog = list.get(0); - if (lastLog.getDate() != null && ChronoUnit.DAYS.between(DateUtils.stringToLocalDate(lastLog.getDate(), "yyyy-MM-dd"), LocalDate.now()) == 0) { - isPunch = true; - } - } + public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) { - /*for (WxLogInfo log : list) { - log.setId(AesUtils.encrypt(log.getId()+"", null)); - }*/ + startPage(); + List list = sysWxUserLogService.getWxLogInfoList(sysWxUserLog); + + + return getDataTable(list); - Collections.reverse(list); - TableDataInfo tableDataInfo = getDataTable(list); - result.put("isPunch", isPunch); - result.put("tableDataInfo", tableDataInfo); - return AjaxResult.success(result); - } else { - return AjaxResult.error(5002, "未查询到相关订单信息"); - } } /** @@ -232,19 +207,19 @@ 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("打卡失败"); - } +// 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("今日已打卡,不可重复打卡"); - } +// //查询今日是否已打卡 +// 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)); @@ -265,42 +240,14 @@ public class WechatAppletController extends BaseController { if (sysWxUserLog == null) { return AjaxResult.error("打卡记录不存在"); } - Map> imageUrlMap = new HashMap<>(); - List breakfastImagesUrlList = StringUtils.isNotEmpty(sysWxUserLog.getBreakfastImages()) ? Arrays.asList(sysWxUserLog.getBreakfastImages().split("\\|")) : new ArrayList<>(); - imageUrlMap.put(imageName[0], breakfastImagesUrlList); - List lunchImagesUrlList = StringUtils.isNotEmpty(sysWxUserLog.getLunchImages()) ? Arrays.asList(sysWxUserLog.getLunchImages().split("\\|")) : new ArrayList<>(); - imageUrlMap.put(imageName[1], lunchImagesUrlList); - - List dinnerImagesUrlList = StringUtils.isNotEmpty(sysWxUserLog.getDinnerImages()) ? Arrays.asList(sysWxUserLog.getDinnerImages().split("\\|")) : new ArrayList<>(); - imageUrlMap.put(imageName[2], dinnerImagesUrlList); - - List extraMealImagesUrlList = StringUtils.isNotEmpty(sysWxUserLog.getExtraMealImages()) ? Arrays.asList(sysWxUserLog.getExtraMealImages().split("\\|")) : new ArrayList<>(); - imageUrlMap.put(imageName[3], extraMealImagesUrlList); - - List bodyImagesUrlList = StringUtils.isNotEmpty(sysWxUserLog.getBodyImages()) ? Arrays.asList(sysWxUserLog.getBodyImages().split("\\|")) : new ArrayList<>(); - imageUrlMap.put(imageName[4], bodyImagesUrlList); - - //生成预览链接 - Map> downUrlList = AliyunOSSUtils.generatePresignedUrl(imageUrlMap); - - sysWxUserLog.setBreakfastImagesUrl(downUrlList.get(imageName[0])); - sysWxUserLog.setLunchImagesUrl(downUrlList.get(imageName[1])); - sysWxUserLog.setDinnerImagesUrl(downUrlList.get(imageName[2])); - sysWxUserLog.setExtraMealImagesUrl(downUrlList.get(imageName[3])); - sysWxUserLog.setBodyImagesUrl(downUrlList.get(imageName[4])); - - List allImagesList = new ArrayList<>(); List allUrlList = new ArrayList<>(); - - for (String key : imageName) { - if (!"bodyImages".equals(key)) { - allUrlList.addAll(downUrlList.get(key)); - allImagesList.addAll(imageUrlMap.get(key)); - } - } + allUrlList.addAll(sysWxUserLog.getBreakfastImagesUrl()); + allUrlList.addAll(sysWxUserLog.getLunchImagesUrl()); + allUrlList.addAll(sysWxUserLog.getDinnerImagesUrl()); + allUrlList.addAll(sysWxUserLog.getExtraMealImagesUrl()); sysWxUserLog.setAllImagesUrl(allUrlList); - sysWxUserLog.setAllImages(StringUtils.join(allImagesList, "|")); + sysWxUserLog.setAllImages(StringUtils.join(allUrlList, "|")); return AjaxResult.success(sysWxUserLog); } @@ -811,26 +758,27 @@ public class WechatAppletController extends BaseController { /** * 打卡社区点赞 + * * @return */ @PostMapping("/thumbsupPunch") public AjaxResult getCommunityPunch(@RequestBody SysPunchThumbsup sysPunchThumbsup) { - if(StringUtils.isEmpty(sysPunchThumbsup.getCusOpenid(),sysPunchThumbsup.getEncPunchId()) || sysPunchThumbsup.getThumbsupFlag() == null){ + if (StringUtils.isEmpty(sysPunchThumbsup.getCusOpenid(), sysPunchThumbsup.getEncPunchId()) || sysPunchThumbsup.getThumbsupFlag() == null) { return AjaxResult.error("缺少必要参数"); } sysPunchThumbsup.setPunchId(Long.parseLong(AesUtils.decrypt(sysPunchThumbsup.getEncPunchId()))); SysPunchThumbsup existPunchThumbsup = sysPunchThumbsupService.getThumbsupByPunchIdAndOpenid(sysPunchThumbsup); - if(existPunchThumbsup != null && sysPunchThumbsup.getThumbsupFlag()){ + if (existPunchThumbsup != null && sysPunchThumbsup.getThumbsupFlag()) { return AjaxResult.error("已点过暂,无法重复点赞"); } - if(existPunchThumbsup == null && !sysPunchThumbsup.getThumbsupFlag()){ + if (existPunchThumbsup == null && !sysPunchThumbsup.getThumbsupFlag()) { return AjaxResult.error("还未未点赞,无法取消点赞"); } int row = 0; - try{ + try { row = sysPunchThumbsup.getThumbsupFlag() ? sysPunchThumbsupService.insertSysPunchThumbsup(sysPunchThumbsup) : sysPunchThumbsupService.deleteThumbsupByPunchIdAndOpenid(sysPunchThumbsup); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } return toAjax(row); diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/page/WxLogInfo.java b/stdiet-custom/src/main/java/com/stdiet/custom/page/WxLogInfo.java index 19f763858..f16af162b 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/page/WxLogInfo.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/page/WxLogInfo.java @@ -1,20 +1,18 @@ package com.stdiet.custom.page; -import com.stdiet.common.annotation.Excel; -import com.stdiet.common.utils.DateUtils; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; -import java.io.Serializable; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Date; import java.util.List; -public class WxLogInfo implements Serializable { - private static final long serialVersionUID = 1L; - +@Data +public class WxLogInfo { private Long id; - private String date; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date date; private Long water; @@ -34,46 +32,72 @@ public class WxLogInfo implements Serializable { private String remark; - /** 情绪 */ + /** + * 情绪 + */ private String emotion; - /** 食谱之外的食物 */ + /** + * 食谱之外的食物 + */ private String slyEatFood; - /** 是否便秘(Y是 N否) */ + /** + * 是否便秘(Y是 N否) + */ private String constipation; - /** 食材描述 */ + /** + * 食材描述 + */ private String ingredientDescribe; //全部食材照片 private String allImages; - /** 早餐照片 */ - private String breakfastImages; + /** + * 早餐照片 + */ +// private String breakfastImages; - /** 午餐照片 */ - private String lunchImages; + /** + * 午餐照片 + */ +// private String lunchImages; - /** 午餐照片 */ - private String dinnerImages; + /** + * 午餐照片 + */ +// private String dinnerImages; - /** 加餐照片 */ - private String extraMealImages; + /** + * 加餐照片 + */ +// private String extraMealImages; - /** 体型对比照 */ - private String bodyImages; + /** + * 体型对比照 + */ +// private String bodyImages; - /** 服务建议 */ + /** + * 服务建议 + */ private String suggest; - /** 目标体重 */ + /** + * 目标体重 + */ private BigDecimal targetWeight; - /** 执行评分,五分制 */ + /** + * 执行评分,五分制 + */ private BigDecimal executionScore; - /** 点评 */ + /** + * 点评 + */ private String comment; private List allImagesUrl; @@ -88,266 +112,26 @@ public class WxLogInfo implements Serializable { private List bodyImagesUrl; - public String getDate() { - return date; - } + private String healthManifesto; - public String getDefecation() { - return defecation; - } - - public String getDiet() { - return diet; - } - - public String getSleepTime() { - return sleepTime; - } - - public Long getWater() { - return water; - } - - public String getInsomnia() { - return insomnia; - } - - public String getSport() { - return sport; - } - - public String getWakeupTime() { - return wakeupTime; - } - - public BigDecimal getWeight() { - return weight; - } - - public void setWeight(BigDecimal weight) { - this.weight = weight; - } - - public void setDate(Date date) { - this.date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date); + public void setDefecation(String defecation) { + this.defecation = defecation.equals("Y") ? "是" : "否"; } public void setDiet(String diet) { - this.diet = diet == "Y" ? "是" : "否"; - } - - public void setWater(Long water) { - this.water = water; - } - - public void setWakeupTime(String wakeupTime) { - this.wakeupTime = wakeupTime; - } - - public void setDefecation(String defecation) { - this.defecation = defecation == "Y" ? "是" : "否"; - } - - public void setSport(String sport) { - this.sport = sport == "Y" ? "是" : "否"; + this.diet = diet.equals("Y") ? "是" : "否"; } public void setInsomnia(String insomnia) { - this.insomnia = insomnia == "Y" ? "是" : "否"; + this.insomnia = insomnia.equals("Y") ? "是" : "否"; } - public void setSleepTime(String sleepTime) { - this.sleepTime = sleepTime; - } - - public String getEmotion() { - return emotion; - } - - public void setEmotion(String emotion) { - this.emotion = emotion; - } - - public String getSlyEatFood() { - return slyEatFood; - } - - public void setSlyEatFood(String slyEatFood) { - this.slyEatFood = slyEatFood; - } - - public String getConstipation() { - return constipation; + public void setSport(String sport) { + this.sport = sport.equals("Y") ? "是" : "否"; } public void setConstipation(String constipation) { - this.constipation = constipation == "Y" ? "是" : "否"; + this.constipation = constipation.equals("Y") ? "是" : "否"; } - public String getBreakfastImages() { - return breakfastImages; - } - - public void setBreakfastImages(String breakfastImages) { - this.breakfastImages = breakfastImages; - } - - public String getLunchImages() { - return lunchImages; - } - - public void setLunchImages(String lunchImages) { - this.lunchImages = lunchImages; - } - - public String getDinnerImages() { - return dinnerImages; - } - - public void setDinnerImages(String dinnerImages) { - this.dinnerImages = dinnerImages; - } - - public String getExtraMealImages() { - return extraMealImages; - } - - public void setExtraMealImages(String extraMealImages) { - this.extraMealImages = extraMealImages; - } - - public String getBodyImages() { - return bodyImages; - } - - public void setBodyImages(String bodyImages) { - this.bodyImages = bodyImages; - } - - public String getSuggest() { - return suggest; - } - - public void setSuggest(String suggest) { - this.suggest = suggest; - } - - public BigDecimal getTargetWeight() { - return targetWeight; - } - - public void setTargetWeight(BigDecimal targetWeight) { - this.targetWeight = targetWeight; - } - - public BigDecimal getExecutionScore() { - return executionScore; - } - - public void setExecutionScore(BigDecimal executionScore) { - this.executionScore = executionScore; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public List getBreakfastImagesUrl() { - return breakfastImagesUrl; - } - - public void setBreakfastImagesUrl(List breakfastImagesUrl) { - this.breakfastImagesUrl = breakfastImagesUrl; - } - - public List getLunchImagesUrl() { - return lunchImagesUrl; - } - - public void setLunchImagesUrl(List lunchImagesUrl) { - this.lunchImagesUrl = lunchImagesUrl; - } - - public List getDinnerImagesUrl() { - return dinnerImagesUrl; - } - - public void setDinnerImagesUrl(List dinnerImagesUrl) { - this.dinnerImagesUrl = dinnerImagesUrl; - } - - public List getExtraMealImagesUrl() { - return extraMealImagesUrl; - } - - public void setExtraMealImagesUrl(List extraMealImagesUrl) { - this.extraMealImagesUrl = extraMealImagesUrl; - } - - public List getBodyImagesUrl() { - return bodyImagesUrl; - } - - public void setBodyImagesUrl(List bodyImagesUrl) { - this.bodyImagesUrl = bodyImagesUrl; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getIngredientDescribe() { - return ingredientDescribe; - } - - public void setIngredientDescribe(String ingredientDescribe) { - this.ingredientDescribe = ingredientDescribe; - } - - public List getAllImagesUrl() { - return this.allImagesUrl; - } - - public void setAllImagesUrl(List allImagesUrl) { - this.allImagesUrl = allImagesUrl; - } - - public String getAllImages() { - return this.allImages; - } - - public void setAllImages(String allImages) { - this.allImages = allImages; - } - - @Override - public String toString() { - return "WxLogInfo{" + - "date='" + date + '\'' + - ", water='" + water + '\'' + - ", sleepTime='" + sleepTime + '\'' + - ", wakeupTime='" + wakeupTime + '\'' + - ", sport='" + sport + '\'' + - ", weight='" + weight + '\'' + - ", diet='" + diet + '\'' + - ", insomnia='" + insomnia + '\'' + - ", defecation='" + defecation + '\'' + - '}'; - } } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserLogServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserLogServiceImpl.java index 3100965e4..72a8a2e6e 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserLogServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysWxUserLogServiceImpl.java @@ -67,7 +67,6 @@ public class SysWxUserLogServiceImpl implements ISysWxUserLogService { */ @Override public int insertSysWxUserLog(SysWxUserLog sysWxUserLog) { - sysWxUserLog.setCreateTime(DateUtils.getNowDate()); return sysWxUserLogMapper.insertSysWxUserLog(sysWxUserLog); } @@ -79,7 +78,6 @@ public class SysWxUserLogServiceImpl implements ISysWxUserLogService { */ @Override public int updateSysWxUserLog(SysWxUserLog sysWxUserLog) { - sysWxUserLog.setUpdateTime(DateUtils.getNowDate()); return sysWxUserLogMapper.updateSysWxUserLog(sysWxUserLog); } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/ImagesHandler.java b/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/ImagesHandler.java new file mode 100644 index 000000000..d444ceb7d --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/typehandler/ImagesHandler.java @@ -0,0 +1,53 @@ +package com.stdiet.custom.typehandler; + +import com.google.api.client.repackaged.com.google.common.base.Joiner; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.common.utils.oss.AliyunOSSUtils; +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; +import java.util.ArrayList; +import java.util.List; + +@MappedTypes({List.class}) +@MappedJdbcTypes({JdbcType.VARCHAR}) +public class ImagesHandler extends BaseTypeHandler> { + + @Override + public void setNonNullParameter(PreparedStatement preparedStatement, int i, List strings, JdbcType jdbcType) throws SQLException { + String str = Joiner.on("\\|").skipNulls().join(strings); + preparedStatement.setString(i, str); + } + + @Override + public List getNullableResult(ResultSet resultSet, String s) throws SQLException { + return this.stringToList(resultSet.getString(s)); + } + + @Override + public List getNullableResult(ResultSet resultSet, int i) throws SQLException { + return this.stringToList(resultSet.getString(i)); + } + + @Override + public List getNullableResult(CallableStatement callableStatement, int i) throws SQLException { + return this.stringToList(callableStatement.getString(i)); + } + + private List stringToList(String string) { + List list = new ArrayList<>(); + if (StringUtils.isNotEmpty(string)) { + String[] urls = string.split("\\|"); + for (String url : urls) { + list.add(AliyunOSSUtils.generatePresignedUrl(url)); + } + } + return list; + } +} diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml index faed261e5..7ed3de323 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml @@ -5,7 +5,7 @@ - + @@ -25,22 +25,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -49,7 +49,7 @@ - + @@ -59,27 +59,32 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + select id,openid, weight, appid, phone, log_time, sleep_time, wakeup_time, sport, avatar_url, diet, insomnia, defecation, water, create_by, create_time, update_by, update_time, remark, - emotion,sly_eat_food,constipation,ingredient_describe,breakfast_images,lunch_images,dinner_images,extra_meal_images,body_images,suggest,execution_score,comment + emotion,sly_eat_food,constipation,ingredient_describe,breakfast_images,lunch_images,dinner_images,extra_meal_images,body_images,suggest,execution_score,comment,health_manifesto from sys_wx_user_log @@ -89,11 +94,14 @@ @@ -145,7 +159,7 @@ weight, appid, phone, - log_time, + log_time, sleep_time, wakeup_time, sport, @@ -155,9 +169,9 @@ defecation, water, create_by, - create_time, + create_time, update_by, - update_time, + update_time, remark, emotion, sly_eat_food, @@ -181,7 +195,7 @@ #{weight}, #{appid}, #{phone}, - #{logTime}, + now(), #{sleepTime}, #{wakeupTime}, #{sport}, @@ -191,9 +205,9 @@ #{defecation}, #{water}, #{createBy}, - #{createTime}, + now(), #{updateBy}, - #{updateTime}, + now(), #{remark}, #{emotion}, #{slyEatFood}, @@ -221,7 +235,6 @@ weight = #{weight}, appid = #{appid}, phone = #{phone}, - log_time = #{logTime}, sleep_time = #{sleepTime}, wakeup_time = #{wakeupTime}, sport = #{sport}, @@ -230,10 +243,8 @@ insomnia = #{insomnia}, defecation = #{defecation}, water = #{water}, - create_by = #{createBy}, - create_time = #{createTime}, update_by = #{updateBy}, - update_time = #{updateTime}, + update_time = now(), remark = #{remark}, emotion = #{emotion}, sly_eat_food = #{slyEatFood}, @@ -260,7 +271,7 @@ - update sys_wx_user_log set del_flag = 1 where id in + update sys_wx_user_log set del_flag = 1 where id in #{id} @@ -270,13 +281,13 @@ - select id from sys_wx_user_log where del_flag = 0 and to_days(log_time) = to_days(#{logTime}) and openid = #{openid} limit 1 @@ -299,11 +310,15 @@ @@ -319,8 +334,8 @@ - - + +