开发微信打卡系统

This commit is contained in:
huangdeliang 2020-11-29 18:54:10 +08:00
parent b747473858
commit efc07c6b90
9 changed files with 205 additions and 90 deletions

View File

@ -790,22 +790,23 @@ create table sys_wx_user_info (
-- ---------------------------- -- ----------------------------
drop table if exists sys_wx_user_log; drop table if exists sys_wx_user_log;
create table sys_wx_user_log ( create table sys_wx_user_log (
openid varchar(100) not null default 'manual' comment '微信openid', id BIGINT(20) not null auto_increment comment 'id',
openid varchar(100) default 'manual' comment '微信openid',
appid varchar(100) comment '微信appid', appid varchar(100) comment '微信appid',
weight decimal(10,2) comment '体重', weight decimal(10,2) comment '体重',
phone varchar(30) comment '电话', phone varchar(30) comment '电话',
sleep_time datetime comment '睡觉时间', sleep_time varchar(10) comment '睡觉时间',
avatar_url varchar(255) comment '用户头像', avatar_url varchar(255) comment '用户头像',
wakeup_time datetime comment '起床时间', wakeup_time varchar(10) comment '起床时间',
sport char(1) comment '运动情况Y是 N否', sport char(1) comment '运动情况Y是 N否',
diet char(1) comment '饮食情况Y是 N否', diet char(1) comment '饮食情况Y是 N否',
insomnia char(1) comment '熬夜失眠Y是 N否', insomnia char(1) comment '熬夜失眠Y是 N否',
defecation char(1) comment '排便情况', defecation char(1) comment '排便情况',
water tinyint comment '饮水量', water bigint(20) comment '饮水量',
create_by varchar(64) default '' comment '创建者', create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间', create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者', update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间', update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注', remark varchar(500) default null comment '备注',
primary key (openid) primary key (id)
) engine=innodb comment = '微信用户记录'; ) engine=innodb comment = '微信用户记录';

View File

@ -1,25 +1,22 @@
package com.stdiet.web.controller.custom; package com.stdiet.web.controller.custom;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.stdiet.common.annotation.Log; import com.stdiet.common.annotation.Log;
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.enums.BusinessType;
import com.stdiet.custom.domain.SysWxUserInfo;
import com.stdiet.custom.service.ISysWxUserInfoService;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.common.core.page.TableDataInfo; import com.stdiet.common.core.page.TableDataInfo;
import com.stdiet.common.enums.BusinessType;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.custom.domain.SysOrder;
import com.stdiet.custom.domain.SysWxUserInfo;
import com.stdiet.custom.page.WxServeInfo;
import com.stdiet.custom.service.ISysOrderService;
import com.stdiet.custom.service.ISysWxUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 微信用户Controller * 微信用户Controller
@ -33,6 +30,9 @@ public class SysWxUserInfoController extends BaseController {
@Autowired @Autowired
private ISysWxUserInfoService sysWxUserInfoService; private ISysWxUserInfoService sysWxUserInfoService;
@Autowired
private ISysOrderService sysOrderService;
/** /**
* 查询微信用户列表 * 查询微信用户列表
*/ */
@ -95,17 +95,41 @@ public class SysWxUserInfoController extends BaseController {
return toAjax(sysWxUserInfoService.deleteSysWxUserInfoByIds(openids)); return toAjax(sysWxUserInfoService.deleteSysWxUserInfoByIds(openids));
} }
@PostMapping("/wx/adduser") @PostMapping("/wx/serveinfo")
public AjaxResult addUser(@RequestBody SysWxUserInfo sysWxUserInfo) { public AjaxResult addUser(@RequestBody SysWxUserInfo sysWxUserInfo) {
// 查询微信用户
SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid()); SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid());
int resultCode = 0; if (StringUtils.isNull(userInfo) && StringUtils.isEmpty(sysWxUserInfo.getPhone())
if (userInfo == null) { || StringUtils.isEmpty(userInfo.getPhone()) && StringUtils.isEmpty(sysWxUserInfo.getPhone())) {
resultCode = sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo); return AjaxResult.error(5001, "没有手机号");
}
// 插入/更新用户信息
if (StringUtils.isNull(userInfo)) {
sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo);
} else { } else {
if (StringUtils.isNotEmpty(userInfo.getPhone())) {
sysWxUserInfo.setPhone(userInfo.getPhone()); sysWxUserInfo.setPhone(userInfo.getPhone());
resultCode = sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo);
} }
return toAjax(resultCode); sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo);
}
// 查找订单记录
SysOrder querySysOrder = new SysOrder();
querySysOrder.setPhone(sysWxUserInfo.getPhone());
List<SysOrder> list = sysOrderService.selectSysOrderList(querySysOrder);
if (list.isEmpty()) {
return AjaxResult.error(5002, "没有订单信息");
}
WxServeInfo wxServeInfo = new WxServeInfo();
wxServeInfo.setServeStatus(list.get(0).getStatus());
wxServeInfo.setServeTime(list.get(0).getServeTime());
wxServeInfo.setStartTime(list.get(list.size() - 1).getStartTime());
wxServeInfo.setWeight(list.get(list.size() - 1).getWeight());
return AjaxResult.success(wxServeInfo);
} }
} }

View File

@ -1,23 +1,23 @@
package com.stdiet.web.controller.custom; package com.stdiet.web.controller.custom;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.stdiet.common.annotation.Log; import com.stdiet.common.annotation.Log;
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.enums.BusinessType;
import com.stdiet.custom.domain.SysWxUserLog;
import com.stdiet.custom.service.ISysWxUserLogService;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.common.core.page.TableDataInfo; import com.stdiet.common.core.page.TableDataInfo;
import com.stdiet.common.enums.BusinessType;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.custom.domain.SysOrder;
import com.stdiet.custom.domain.SysWxUserInfo;
import com.stdiet.custom.domain.SysWxUserLog;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 微信用户记录Controller * 微信用户记录Controller
@ -27,18 +27,21 @@ import com.stdiet.common.core.page.TableDataInfo;
*/ */
@RestController @RestController
@RequestMapping("/custom/wxUserLog") @RequestMapping("/custom/wxUserLog")
public class SysWxUserLogController extends BaseController public class SysWxUserLogController extends BaseController {
{
@Autowired @Autowired
private ISysWxUserLogService sysWxUserLogService; private ISysWxUserLogService sysWxUserLogService;
@Autowired
private ISysWxUserInfoService sysWxUserInfoService;
private ISysOrderService sysOrderService;
/** /**
* 查询微信用户记录列表 * 查询微信用户记录列表
*/ */
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:list')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(SysWxUserLog sysWxUserLog) public TableDataInfo list(SysWxUserLog sysWxUserLog) {
{
startPage(); startPage();
List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(sysWxUserLog); List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(sysWxUserLog);
return getDataTable(list); return getDataTable(list);
@ -50,8 +53,7 @@ public class SysWxUserLogController extends BaseController
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:export')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:export')")
@Log(title = "微信用户记录", businessType = BusinessType.EXPORT) @Log(title = "微信用户记录", businessType = BusinessType.EXPORT)
@GetMapping("/export") @GetMapping("/export")
public AjaxResult export(SysWxUserLog sysWxUserLog) public AjaxResult export(SysWxUserLog sysWxUserLog) {
{
List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(sysWxUserLog); List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(sysWxUserLog);
ExcelUtil<SysWxUserLog> util = new ExcelUtil<SysWxUserLog>(SysWxUserLog.class); ExcelUtil<SysWxUserLog> util = new ExcelUtil<SysWxUserLog>(SysWxUserLog.class);
return util.exportExcel(list, "wxUserLog"); return util.exportExcel(list, "wxUserLog");
@ -62,8 +64,7 @@ public class SysWxUserLogController extends BaseController
*/ */
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:query')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:query')")
@GetMapping(value = "/{openid}") @GetMapping(value = "/{openid}")
public AjaxResult getInfo(@PathVariable("openid") String openid) public AjaxResult getInfo(@PathVariable("openid") String openid) {
{
return AjaxResult.success(sysWxUserLogService.selectSysWxUserLogById(openid)); return AjaxResult.success(sysWxUserLogService.selectSysWxUserLogById(openid));
} }
@ -73,8 +74,7 @@ public class SysWxUserLogController extends BaseController
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:add')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:add')")
@Log(title = "微信用户记录", businessType = BusinessType.INSERT) @Log(title = "微信用户记录", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody SysWxUserLog sysWxUserLog) public AjaxResult add(@RequestBody SysWxUserLog sysWxUserLog) {
{
return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog)); return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog));
} }
@ -84,8 +84,7 @@ public class SysWxUserLogController extends BaseController
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:edit')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:edit')")
@Log(title = "微信用户记录", businessType = BusinessType.UPDATE) @Log(title = "微信用户记录", businessType = BusinessType.UPDATE)
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody SysWxUserLog sysWxUserLog) public AjaxResult edit(@RequestBody SysWxUserLog sysWxUserLog) {
{
return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog)); return toAjax(sysWxUserLogService.updateSysWxUserLog(sysWxUserLog));
} }
@ -95,17 +94,28 @@ public class SysWxUserLogController extends BaseController
@PreAuthorize("@ss.hasPermi('custom:wxUserLog:remove')") @PreAuthorize("@ss.hasPermi('custom:wxUserLog:remove')")
@Log(title = "微信用户记录", businessType = BusinessType.DELETE) @Log(title = "微信用户记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{openids}") @DeleteMapping("/{openids}")
public AjaxResult remove(@PathVariable String[] openids) public AjaxResult remove(@PathVariable String[] openids) {
{
return toAjax(sysWxUserLogService.deleteSysWxUserLogByIds(openids)); return toAjax(sysWxUserLogService.deleteSysWxUserLogByIds(openids));
} }
@GetMapping(value = "/wx/logs/{openid}") @GetMapping(value = "/wx/logs/{openid}")
public TableDataInfo getLogInfo(@PathVariable("openid") String openid) public AjaxResult getLogs(@PathVariable String openId) {
{ SysWxUserLog querySysWxUserLog = new SysWxUserLog();
SysWxUserLog sysWxUserLog = new SysWxUserLog(); querySysWxUserLog.setOpenid(openId);
sysWxUserLog.setOpenid(openid); List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(querySysWxUserLog);
List<SysWxUserLog> list = sysWxUserLogService.selectSysWxUserLogList(sysWxUserLog); return AjaxResult.success(list);
return getDataTable(list); }
@PostMapping(value = "/wx/logs/add")
public AjaxResult addLog(@RequestBody SysWxUserLog sysWxUserLog) {
// 查询微信用户
SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid());
if(StringUtils.isNull(userInfo)) {
return AjaxResult.error(5003, "没有用户信息");
}
// 提取有用值
sysWxUserLog.setAvatarUrl(userInfo.getAvatarUrl());
sysWxUserLog.setPhone(userInfo.getPhone());
return add(sysWxUserLog);
} }
} }

View File

@ -12,7 +12,7 @@ import com.stdiet.common.core.domain.BaseEntity;
* 微信用户记录对象 sys_wx_user_log * 微信用户记录对象 sys_wx_user_log
* *
* @author wonder * @author wonder
* @date 2020-11-28 * @date 2020-11-29
*/ */
public class SysWxUserLog extends BaseEntity public class SysWxUserLog extends BaseEntity
{ {
@ -34,34 +34,32 @@ public class SysWxUserLog extends BaseEntity
private String phone; private String phone;
/** 睡觉时间 */ /** 睡觉时间 */
@JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "睡觉时间")
@Excel(name = "睡觉时间", width = 30, dateFormat = "yyyy-MM-dd") private String sleepTime;
private Date sleepTime;
/** 起床时间 */ /** 起床时间 */
@JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "起床时间")
@Excel(name = "起床时间", width = 30, dateFormat = "yyyy-MM-dd") private String wakeupTime;
private Date wakeupTime;
/** 运动情况 */ /** 运动情况Y是 N否 */
@Excel(name = "运动情况") @Excel(name = "运动情况", readConverterExp = "Y=是,N=否")
private Long sport; private String sport;
/** 用户头像 */ /** 用户头像 */
@Excel(name = "用户头像") @Excel(name = "用户头像")
private String avatarUrl; private String avatarUrl;
/** 饮食情况 */ /** 饮食情况Y是 N否 */
@Excel(name = "饮食情况") @Excel(name = "饮食情况", readConverterExp = "Y=是,N=否")
private Long diet; private String diet;
/** 熬夜失眠Y是 N否 */ /** 熬夜失眠Y是 N否 */
@Excel(name = "熬夜失眠", readConverterExp = "Y=是,N=否") @Excel(name = "熬夜失眠", readConverterExp = "Y=是,N=否")
private String insomnia; private String insomnia;
/** 排便情况 */ /** 排便情况Y是 N否 */
@Excel(name = "排便情况") @Excel(name = "排便情况", readConverterExp = "Y=是,N=否")
private Long defecation; private String defecation;
/** 饮水量 */ /** 饮水量 */
@Excel(name = "饮水量") @Excel(name = "饮水量")
@ -103,30 +101,30 @@ public class SysWxUserLog extends BaseEntity
{ {
return phone; return phone;
} }
public void setSleepTime(Date sleepTime) public void setSleepTime(String sleepTime)
{ {
this.sleepTime = sleepTime; this.sleepTime = sleepTime;
} }
public Date getSleepTime() public String getSleepTime()
{ {
return sleepTime; return sleepTime;
} }
public void setWakeupTime(Date wakeupTime) public void setWakeupTime(String wakeupTime)
{ {
this.wakeupTime = wakeupTime; this.wakeupTime = wakeupTime;
} }
public Date getWakeupTime() public String getWakeupTime()
{ {
return wakeupTime; return wakeupTime;
} }
public void setSport(Long sport) public void setSport(String sport)
{ {
this.sport = sport; this.sport = sport;
} }
public Long getSport() public String getSport()
{ {
return sport; return sport;
} }
@ -139,12 +137,12 @@ public class SysWxUserLog extends BaseEntity
{ {
return avatarUrl; return avatarUrl;
} }
public void setDiet(Long diet) public void setDiet(String diet)
{ {
this.diet = diet; this.diet = diet;
} }
public Long getDiet() public String getDiet()
{ {
return diet; return diet;
} }
@ -157,12 +155,12 @@ public class SysWxUserLog extends BaseEntity
{ {
return insomnia; return insomnia;
} }
public void setDefecation(Long defecation) public void setDefecation(String defecation)
{ {
this.defecation = defecation; this.defecation = defecation;
} }
public Long getDefecation() public String getDefecation()
{ {
return defecation; return defecation;
} }

View File

@ -0,0 +1,9 @@
package com.stdiet.custom.page;
import java.io.Serializable;
public class WxCurUserLogInfo implements Serializable {
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,67 @@
package com.stdiet.custom.page;
import com.stdiet.common.utils.DateUtils;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
public class WxServeInfo implements Serializable {
private static final long serialVersionUID = 1L;
private String serveTime;
private String serveStatus;
private String startTime;
private String weight;
public String getServeTime() {
return serveTime;
}
public void setServeTime(String serveTime) {
this.serveTime = serveTime;
}
public String getServeStatus() {
return serveStatus;
}
public void setServeStatus(String serveStatus) {
if (serveStatus.equals("0")) {
this.serveStatus = "进行中";
} else if (serveStatus.equals("1")) {
this.serveStatus = "暂停";
} else if (serveStatus.equals("")) {
this.serveStatus = "已完成";
}
}
public String getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startTime);
}
public String getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight.toString() + "kg";
}
@Override
public String toString() {
return "WxServeInfo{" +
"serveTime='" + serveTime + '\'' +
", serveStatus='" + serveStatus + '\'' +
", startTime='" + startTime + '\'' +
", weight='" + weight + '\'' +
'}';
}
}

View File

@ -58,4 +58,6 @@ public interface ISysWxUserInfoService
* @return 结果 * @return 结果
*/ */
public int deleteSysWxUserInfoById(String openid); public int deleteSysWxUserInfoById(String openid);
} }

View File

@ -34,6 +34,7 @@
<if test="appid != null and appid != ''"> and appid = #{appid}</if> <if test="appid != null and appid != ''"> and appid = #{appid}</if>
<if test="phone != null and phone != ''"> and phone = #{phone}</if> <if test="phone != null and phone != ''"> and phone = #{phone}</if>
</where> </where>
order by create_time asc
</select> </select>
<select id="selectSysWxUserLogById" parameterType="String" resultMap="SysWxUserLogResult"> <select id="selectSysWxUserLogById" parameterType="String" resultMap="SysWxUserLogResult">

View File

@ -585,6 +585,9 @@
], ],
phone: [ phone: [
{required: true, message: "手机号不能为空", trigger: "blur"} {required: true, message: "手机号不能为空", trigger: "blur"}
],
startTime: [
{required: true, message: "开始时间不能为空", trigger: "blur"}
] ]
// payTypeId: [ // payTypeId: [
// {required: true, message: "", trigger: "blur"} // {required: true, message: "", trigger: "blur"}