diff --git a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/controller/ReportController.java b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/controller/ReportController.java index fcc53c4..430a1f0 100644 --- a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/controller/ReportController.java +++ b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/controller/ReportController.java @@ -13,8 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; +import java.util.List; @Controller @RequestMapping("/access/report") @@ -26,12 +25,21 @@ public class ReportController { @Autowired private ReportServiceImpl reportService; + /** + * 体温上报 + * + * @param id + * @param address + * @param timestamp + * @param temperature + * @return + */ @PostMapping("/submit") @ResponseBody - public Res getCodeInfo(@RequestParam("userId") Integer id, - @RequestParam("address") String address, - @RequestParam("timestamp") Long timestamp, - @RequestParam("temperature") Integer temperature) { + public Res submit(@RequestParam("userId") Integer id, + @RequestParam("address") String address, + @RequestParam("timestamp") Long timestamp, + @RequestParam("temperature") Integer temperature) { User user = userService.getUserById(id); if (user == null) { return Res.error("用户不存在"); @@ -53,4 +61,37 @@ public class ReportController { return Res.success(); } + + /** + * 获取用户填报信息 + * + * @param userId + * @return + */ + @PostMapping("/getRecordList") + @ResponseBody + public Res getRecordList(@RequestParam("userId") Integer userId) { + User user = userService.getUserById(userId); + if (user == null) { + return Res.error("用户不存在"); + } + List records = reportService.getRecordListByUserId(user.getId()); + return Res.success(records); + } + /** + * 获取最近一次用户填报信息 + * + * @param userId + * @return + */ + @PostMapping("/getLatestRecord") + @ResponseBody + public Res getLatestRecord(@RequestParam("userId") Integer userId) { + User user = userService.getUserById(userId); + if (user == null) { + return Res.error("用户不存在"); + } + Report records = reportService.getLatestRecordByUserId(user.getId()); + return Res.success(records); + } } diff --git a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/dao/ReportDao.java b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/dao/ReportDao.java index ba82cf2..5192ba3 100644 --- a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/dao/ReportDao.java +++ b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/dao/ReportDao.java @@ -4,8 +4,14 @@ import com.cxyxiaomo.epp.common.pojo.Report; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; +import java.util.List; + @Mapper @Repository public interface ReportDao { Integer insert(Report report); + + List getReportListByUserId(Integer userId); + + Report getLatestReportByUserId(Integer userId); } diff --git a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportService.java b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportService.java index 485fe4d..091df03 100644 --- a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportService.java +++ b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportService.java @@ -2,6 +2,13 @@ package com.cxyxiaomo.epp.access.service; import com.cxyxiaomo.epp.common.pojo.Report; +import java.util.List; + public interface ReportService { + void addRecord(Report report); + + List getRecordListByUserId(Integer userId); + + Report getLatestRecordByUserId(Integer userId); } diff --git a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportServiceImpl.java b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportServiceImpl.java index 2a537e0..e3aa527 100644 --- a/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportServiceImpl.java +++ b/backend/microservice-provider-access-8002/src/main/java/com/cxyxiaomo/epp/access/service/ReportServiceImpl.java @@ -5,6 +5,8 @@ import com.cxyxiaomo.epp.common.pojo.Report; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service public class ReportServiceImpl implements ReportService { @@ -15,4 +17,12 @@ public class ReportServiceImpl implements ReportService { public void addRecord(Report report) { reportDao.insert(report); } + + public List getRecordListByUserId(Integer userId) { + return reportDao.getReportListByUserId(userId); + } + + public Report getLatestRecordByUserId(Integer userId) { + return reportDao.getLatestReportByUserId(userId); + } } diff --git a/backend/microservice-provider-access-8002/src/main/resources/mybatis/mapper/ReportDao.xml b/backend/microservice-provider-access-8002/src/main/resources/mybatis/mapper/ReportDao.xml index c33d241..3d97654 100644 --- a/backend/microservice-provider-access-8002/src/main/resources/mybatis/mapper/ReportDao.xml +++ b/backend/microservice-provider-access-8002/src/main/resources/mybatis/mapper/ReportDao.xml @@ -7,4 +7,15 @@ INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`) VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature}) + + diff --git a/miniprogram/src/app.config.js b/miniprogram/src/app.config.js index 2371342..bc98dae 100644 --- a/miniprogram/src/app.config.js +++ b/miniprogram/src/app.config.js @@ -8,6 +8,7 @@ export default defineAppConfig({ */ 'pages/residents/code', // 进出码 'pages/residents/report', // 体温上报 + 'pages/residents/reportHistory', // 体温上报-历史上报 /** * 扫码跳转 diff --git a/miniprogram/src/pages/residents/report.vue b/miniprogram/src/pages/residents/report.vue index 7423865..99f4b82 100644 --- a/miniprogram/src/pages/residents/report.vue +++ b/miniprogram/src/pages/residents/report.vue @@ -41,61 +41,67 @@ @@ -116,17 +122,69 @@ export default { time: '', timestamp: '', temperature: 0, - } + }, + // 是否填报过 + isFilled: true, + filledMsg: "", } }, onShow() { console.log('onShow') this.userInfo = Taro.getStorageSync("userInfo") + console.log("this.userInfo", this.userInfo) + this.formData.userId = this.userInfo.id this.formData.userRealname = this.userInfo.realname this.updateTime(); this.timeInterval = setInterval(this.updateTime, 1000); + + // 获取用户当日是否填报过 + Taro.showLoading({ title: '加载中' }) + var that = this; + Taro.request({ + url: `${this.baseUrl}/access/report/getLatestRecord`, + method: "POST", + header: { + "Content-Type": "application/x-www-form-urlencoded" //用于post + }, + data: { + userId: this.userInfo.id + }, + success: function (d) { + Taro.hideLoading() + let result = d.data + console.log("result", result) + if (result.success) { + console.log("result.data", result.data); + if (result.data == null || new Date(result.data.time) < new Date(new Date().toISOString().substring(0, 10))) { + // 如果没有填报记录,或者填报记录不是今天,那么说明没有填报过 + that.isFilled = false + } else { + // 有今日记录,说明已经填报过 + that.isFilled = true + that.filledMsg = "您已完成今日体温填报" + } + } else { + Taro.showToast({ + title: "加载填报信息失败", + icon: 'error', + duration: 2000 + }) + } + }, + fail: function () { + Taro.hideLoading() + Taro.showToast({ + title: "请求失败", + icon: 'error', + duration: 2000 + }) + }, + complete: function () { + Taro.hideNavigationBarLoading(); + } + }) }, onHide() { @@ -173,9 +231,16 @@ export default { }) Taro.hideLoading() }, + // 体温上报 提交按钮 report() { console.log("点击提交", "this.formData", this.formData) - + if (!this.formData.address) { + Taro.showToast({ + title: "请获取当前位置", + icon: 'error' + }) + return; + } Taro.showLoading({ title: '加载中' }) var that = this; Taro.request({ @@ -192,6 +257,9 @@ export default { Taro.hideLoading() let result = d.data; if (result.success) { + // 填报完成 + that.isFilled = true + that.filledMsg = "您已完成今日体温填报" console.log("result.data", result.data); Taro.showToast({ title: "填报成功", @@ -226,6 +294,12 @@ export default { that.debugMode && console.log("end complete") } }) + }, + // 历史填报 + myreport() { + Taro.navigateTo({ + url: "/pages/residents/reportHistory" + }) } } } diff --git a/miniprogram/src/pages/residents/reportHistory.config.js b/miniprogram/src/pages/residents/reportHistory.config.js new file mode 100644 index 0000000..8a1b27d --- /dev/null +++ b/miniprogram/src/pages/residents/reportHistory.config.js @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '体温上报 - 历史记录', +}) diff --git a/miniprogram/src/pages/residents/reportHistory.vue b/miniprogram/src/pages/residents/reportHistory.vue new file mode 100644 index 0000000..54fb4a1 --- /dev/null +++ b/miniprogram/src/pages/residents/reportHistory.vue @@ -0,0 +1,131 @@ + + + + +