微信打卡接口优化
This commit is contained in:
parent
23bdf241e4
commit
7952bdb03e
@ -2,7 +2,11 @@ package com.stdiet.web.controller;
|
|||||||
|
|
||||||
import com.stdiet.common.config.AliyunOSSConfig;
|
import com.stdiet.common.config.AliyunOSSConfig;
|
||||||
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
||||||
|
import com.stdiet.custom.domain.SysWxUserInfo;
|
||||||
|
import com.stdiet.custom.domain.SysWxUserLog;
|
||||||
import com.stdiet.custom.mapper.SysCustomerPhysicalSignsMapper;
|
import com.stdiet.custom.mapper.SysCustomerPhysicalSignsMapper;
|
||||||
|
import com.stdiet.custom.mapper.SysWxUserInfoMapper;
|
||||||
|
import com.stdiet.custom.mapper.SysWxUserLogMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
@ -10,18 +14,36 @@ import org.springframework.core.annotation.Order;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Order(value = 1)
|
@Order(value = 1)
|
||||||
public class MyApplicationRunner implements ApplicationRunner {
|
public class MyApplicationRunner implements ApplicationRunner {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysCustomerPhysicalSignsMapper sysCustomerPhysicalSignsMapper;
|
private SysWxUserLogMapper sysWxUserLogMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysWxUserInfoMapper sysWxUserInfoMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
System.out.println("项目启动调用方法");
|
/*System.out.println("项目启动调用方法");
|
||||||
// String path = AliyunOSSUtils.uploadFileInputSteam(AliyunOSSConfig.casePrefix,"ceshi.png",new File("D:\\ceshi.png"));
|
List<String> phoneList = sysWxUserLogMapper.getAllSysWxUserLogPhone();
|
||||||
// System.out.println(path);
|
SysWxUserLog sysWxUserLog = new SysWxUserLog();
|
||||||
|
if(phoneList.size() > 0){
|
||||||
|
for (String phone : phoneList) {
|
||||||
|
System.out.println(phone);
|
||||||
|
SysWxUserInfo sysWxUserInfo = new SysWxUserInfo();
|
||||||
|
sysWxUserInfo.setPhone(phone);
|
||||||
|
List<SysWxUserInfo> list = sysWxUserInfoMapper.selectSysWxUserInfoList(sysWxUserInfo);
|
||||||
|
if(list != null && list.size() > 0){
|
||||||
|
sysWxUserLog.setOpenid(list.get(0).getOpenid());
|
||||||
|
sysWxUserLog.setPhone(phone);
|
||||||
|
sysWxUserLogMapper.updateSysWxUserLog(sysWxUserLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.itextpdf.io.util.DateTimeUtil;
|
|||||||
import com.stdiet.common.core.controller.BaseController;
|
import com.stdiet.common.core.controller.BaseController;
|
||||||
import com.stdiet.common.core.domain.AjaxResult;
|
import com.stdiet.common.core.domain.AjaxResult;
|
||||||
import com.stdiet.common.core.page.TableDataInfo;
|
import com.stdiet.common.core.page.TableDataInfo;
|
||||||
|
import com.stdiet.common.utils.DateUtils;
|
||||||
import com.stdiet.common.utils.StringUtils;
|
import com.stdiet.common.utils.StringUtils;
|
||||||
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
import com.stdiet.common.utils.oss.AliyunOSSUtils;
|
||||||
import com.stdiet.common.utils.sign.AesUtils;
|
import com.stdiet.common.utils.sign.AesUtils;
|
||||||
@ -17,8 +18,9 @@ import com.stdiet.custom.service.ISysWxUserLogService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信小程序统一Controller
|
* 微信小程序统一Controller
|
||||||
@ -95,12 +97,7 @@ public class WechatAppletController extends BaseController {
|
|||||||
}else{
|
}else{
|
||||||
sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo);
|
sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo);
|
||||||
}
|
}
|
||||||
//查询是否下单
|
return AjaxResult.success();
|
||||||
SysCustomer param = new SysCustomer();
|
|
||||||
param.setPhone(sysWxUserInfo.getPhone());
|
|
||||||
int orderCount = sysOrderService.getOrderCountByCustomer(param);
|
|
||||||
//返回订单数量
|
|
||||||
return AjaxResult.success(orderCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,10 +106,34 @@ public class WechatAppletController extends BaseController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/getPunchLogs")
|
@GetMapping(value = "/getPunchLogs")
|
||||||
public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) {
|
public AjaxResult getPunchLogs(SysWxUserLog sysWxUserLog) {
|
||||||
startPage();
|
if(StringUtils.isEmpty(sysWxUserLog.getPhone()) && StringUtils.isEmpty(sysWxUserLog.getOpenid())){
|
||||||
List<WxLogInfo> list = sysWxUserLogService.selectWxLogInfoList(sysWxUserLog);
|
return AjaxResult.error(5001, "缺少参数");
|
||||||
return getDataTable(list);
|
}
|
||||||
|
//查询是否下单
|
||||||
|
SysCustomer param = new SysCustomer();
|
||||||
|
param.setPhone(sysWxUserLog.getPhone());
|
||||||
|
int orderCount = sysOrderService.getOrderCountByCustomer(param);
|
||||||
|
if(orderCount > 0){
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
//今日是否已打卡
|
||||||
|
boolean isPunch = false;
|
||||||
|
startPage();
|
||||||
|
List<WxLogInfo> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.reverse(list);
|
||||||
|
TableDataInfo tableDataInfo = getDataTable(list);
|
||||||
|
result.put("isPunch", isPunch);
|
||||||
|
result.put("tableDataInfo", tableDataInfo);
|
||||||
|
return AjaxResult.success(result);
|
||||||
|
}else{
|
||||||
|
return AjaxResult.error(5002, "未查询到相关订单信息");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +156,7 @@ public class WechatAppletController extends BaseController {
|
|||||||
public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) {
|
public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) {
|
||||||
// 查询微信用户
|
// 查询微信用户
|
||||||
SysWxUserInfo userInfo = StringUtils.isEmpty(sysWxUserLog.getOpenid()) ? null : sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid());
|
SysWxUserInfo userInfo = StringUtils.isEmpty(sysWxUserLog.getOpenid()) ? null : sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid());
|
||||||
if (userInfo == null) {
|
if (userInfo == null || StringUtils.isEmpty(userInfo.getPhone())) {
|
||||||
return AjaxResult.error("不存在客户");
|
return AjaxResult.error("不存在客户");
|
||||||
}
|
}
|
||||||
//查询今日是否已打卡
|
//查询今日是否已打卡
|
||||||
|
@ -66,4 +66,10 @@ public interface SysWxUserLogMapper
|
|||||||
|
|
||||||
public int checkWxLogInfoCount(String openid);
|
public int checkWxLogInfoCount(String openid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据openid和手机号查询打卡记录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<WxLogInfo> getWxLogInfoList(SysWxUserLog sysWxUserLog);
|
||||||
|
|
||||||
}
|
}
|
@ -65,4 +65,10 @@ public interface ISysWxUserLogService
|
|||||||
public int deleteSysWxUserLogById(String openid);
|
public int deleteSysWxUserLogById(String openid);
|
||||||
|
|
||||||
public int checkWxLogInfoCount(String openid);
|
public int checkWxLogInfoCount(String openid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据openid和手机号查询打卡记录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<WxLogInfo> getWxLogInfoList(SysWxUserLog sysWxUserLog);
|
||||||
}
|
}
|
@ -100,5 +100,12 @@ public class SysWxUserLogServiceImpl implements ISysWxUserLogService {
|
|||||||
return sysWxUserLogMapper.checkWxLogInfoCount(openid);
|
return sysWxUserLogMapper.checkWxLogInfoCount(openid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据openid和手机号查询打卡记录
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<WxLogInfo> getWxLogInfoList(SysWxUserLog sysWxUserLog){
|
||||||
|
return sysWxUserLogMapper.getWxLogInfoList(sysWxUserLog);
|
||||||
|
}
|
||||||
}
|
}
|
@ -133,6 +133,7 @@
|
|||||||
<update id="updateSysWxUserLog" parameterType="SysWxUserLog">
|
<update id="updateSysWxUserLog" parameterType="SysWxUserLog">
|
||||||
update sys_wx_user_log
|
update sys_wx_user_log
|
||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="openid != null">openid = #{openid},</if>
|
||||||
<if test="weight != null">weight = #{weight},</if>
|
<if test="weight != null">weight = #{weight},</if>
|
||||||
<if test="appid != null">appid = #{appid},</if>
|
<if test="appid != null">appid = #{appid},</if>
|
||||||
<if test="phone != null">phone = #{phone},</if>
|
<if test="phone != null">phone = #{phone},</if>
|
||||||
@ -151,7 +152,7 @@
|
|||||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
<if test="remark != null">remark = #{remark},</if>
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where openid = #{openid}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteSysWxUserLogById" parameterType="String">
|
<delete id="deleteSysWxUserLogById" parameterType="String">
|
||||||
@ -165,4 +166,11 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<!-- 根据openid或手机号查询对应打卡记录 -->
|
||||||
|
<select id="getWxLogInfoList" parameterType="SysWxUserLog" resultMap="WxLogInfo">
|
||||||
|
SELECT wxlog.weight,wxlog.log_time,wxlog.sleep_time, wxlog.wakeup_time,wxlog.defecation, wxlog.water, wxlog.sport FROM sys_wx_user_log wxlog left join sys_wx_user_info wxinfo on wxinfo.openid = wxlog.openid
|
||||||
|
where wxinfo.openid = #{openid} or wxinfo.phone = #{phone}
|
||||||
|
order by wxlog.log_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user