package com.zpy.yy.controller;
import com.zpy.yy.base.BaseConfig;
import com.zpy.yy.base.BaseController;
import com.zpy.yy.bean.*;
import com.zpy.yy.service.*;
import com.zpy.yy.util.AjaxCode;
import com.zpy.yy.util.AjaxModel;
import com.zpy.yy.util.PageInfo;
import com.zpy.yy.util.TextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
@Controller
@RequestMapping("/suffererApi")
public class SuffererApiController extends BaseController {
@Autowired
ISuffererService iSuffererService;
@Autowired
IAppTokenService iAppTokenService;
@Autowired
IBloodSugarLogService iBloodSugarLogService;
@Autowired
IQuestionService iQuestionService;
@Autowired
IQuestionAndAnswerService iQuestionAndAnswerService;
/**
* 患者注册
*
* @param phone
* @param password
* @return
*/
@RequestMapping("/suffererRegister")
@ResponseBody
public AjaxModel suffererRegister(String phone, String password) {
System.out.println("phone=" + phone);
System.out.println("password=" + password);
AjaxModel model = new AjaxModel();
if (iSuffererService.phoneExist(phone)) {
model.setCode(AjaxCode.ACCOUNT_ALREADY_EXIST);
return model;
}
Sufferer sufferer = new Sufferer();
sufferer.setPhone(phone);
sufferer.setPassword(password);
if (iSuffererService.addSuffer(sufferer)) {
model.setCode(AjaxCode.OK);
return model;
}
model.setCode(AjaxCode.ERROR);
return model;
}
/**
* 患者登录
*
* @param phone
* @param password
* @return
*/
@RequestMapping("/suffererLogin")
@ResponseBody
public AjaxModel suffererLogin(String phone, String password) {
System.out.println("phone=" + phone);
System.out.println("password=" + password);
AjaxModel model = new AjaxModel();
if (!iSuffererService.phoneExist(phone)) {
model.setCode(AjaxCode.ACCOUNT_ALREADY_NOT_EXIST);
return model;
}
Sufferer sufferer = iSuffererService.getSuffererByPassword(phone, password);
if (sufferer == null) {
model.setCode(AjaxCode.LOGIN_ERROR);
return model;
}
Map map = new HashMap();
System.out.println("sufferer.getId()=" + sufferer.getId());
AppToken appToken = iAppTokenService.findAppTokenByUserId(sufferer.getId(), BaseConfig.ROLE_TYPE_FOR_SUFFERER);
System.out.println(appToken);
map.put("appToken", appToken);
model.setData(map);
model.setCode(AjaxCode.OK);
return model;
}
/**
* 获取患者信息
*
* @param token
* @return
*/
@RequestMapping("/getSuffererInfo")
@ResponseBody
public AjaxModel getSuffererInfo(String token) {
AjaxModel model = new AjaxModel();
if (TextUtil.isEmpty(token)) {
model.setCode(AjaxCode.TOKEN_IS_NULL);
return model;
}
AppToken appToken = iAppTokenService.findAppTokenByToken(token);
if (appToken == null) {
model.setCode(AjaxCode.ACCOUNT_IS_REPLACED);
return model;
}
Integer userId = appToken.getUserId();
Sufferer sufferer = iSuffererService.findSufferById(userId);
Map map = new HashMap();
map.put("sufferer", sufferer);
model.setCode(AjaxCode.OK);
model.setData(map);
return model;
}
/**
* 更换头像
* @param token
* @param photo
* @return
*/
@RequestMapping("/uploadMyPhoto")
@ResponseBody
public AjaxModel uploadMyPhoto(String token, String photo) {
AjaxModel model = new AjaxModel();
if (TextUtil.isEmpty(token)) {
model.setCode(AjaxCode.TOKEN_IS_NULL);
return model;
}
if (TextUtil.isEmpty(photo)) {
model.setCode(AjaxCode.PHOTO_IS_NULL);
return model;
}
AppToken appToken = iAppTokenService.findAppTokenByToken(token);
Integer userId = appToken.getUserId();
Sufferer sufferer = iSuffererService.findSufferById(userId);
if (sufferer == null) {
model.setCode(AjaxCode.ACCOUNT_ALREADY_NOT_EXIST);
return model;
}
sufferer.setPhoto(photo);
iSuffererService.updateSuffer(sufferer);
model.setCode(AjaxCode.OK);
return model;
}
/**
* 更新患者资料
*
* @param name
* @param sex
* @param birthday
* @param sufferDate
* @return
*/
@RequestMapping("/updateSuffererInfo")
@ResponseBody
public AjaxModel updateSuffererInfo(String token, String name, String sex, String birthday, String sufferDate) {
AjaxModel model = new AjaxModel();
if (TextUtil.isEmpty(token)) {
model.setCode(AjaxCode.TOKEN_IS_NULL);
return model;
}
AppToken appToken = iAppTokenService.findAppTokenByToken(token);
if (appToken == null) {
model.setCode(AjaxCode.ACCOUNT_IS_REPLACED);
return model;
}
Integer userId = appToken.getUserId();
Sufferer sufferer = iSuffererService.findSufferById(userId);
if (sufferer == null) {
model.setCode(AjaxCode.GET_ACCOUNT_ERR);
return model;
}
if (!TextUtil.isEmpty(name)) {
sufferer.setName(name);
}
if (!TextUtil.isEmpty(sex)) {
if ("男".equals(sex)) {
sufferer.setSex(0);
} else {
sufferer.setSex(1);
}
}
if (!TextUtil.isEmpty(birthday)) {
Date date = TextUtil.str2Date(birthday);
sufferer.setBirthday(date);
}
if (!TextUtil.isEmpty(sufferDate)) {
Date date = TextUtil.str2Date(sufferDate);
sufferer.setSufferedDate(date);
}
iSuffererService.updateSuffer(sufferer);
model.setCode(AjaxCode.OK);
return model;
}
/**
* 患者添加当天的血糖记录
*
* @param token
* @param sugar_content
* @return
*/
@RequestMapping("/addBloodSugarLog")
@ResponseBody
public AjaxModel addBloodSugarLog(String token, String sugar_content) {
AjaxModel model = new AjaxModel();
//通过token查找用户
AppToken appToken = iAppTokenService.findAppTokenByToken(token);
if (appToken == null) {
model.setCode(AjaxCode.GET_ACCOUNT_ERR);
return model;
}
Integer user_id = appToken.getUserId();
Sufferer sufferer = iSuffererService.findSufferById(user_id);
if (sufferer == null) {
model.setCode(AjaxCode.ACCOUNT_ALREADY_NOT_EXIST);
return model;
}
//判断今天是否已经添加血糖记录
BloodSugarLog bloodSugarLog = iBloodSugarLogService.findBloodSugarLogByDateAndSuffererId(new Date(), user_id);
if (bloodSugarLog != null) {
model.setCode(AjaxCode.CURRENT_BLOOD_SUGAR_LOG_EXIST);
return model;
}
//开始添加
bloodSugarLog = new BloodSugarLog();
bloodSugarLog.setSuffererId(user_id);
Double sugar_content_d = Double.parseDouble(sugar_content);
bloodSugarLog.setSugarContent(sugar_content_d);
if (iBloodSugarLogService.addBloodSugarLog(bloodSugarLog)) {
bloodSugarLog = iBloodSugarLogService.findBloodSugarLogById(11);
System.out.print(bloodSugarLog);
model.setCode(AjaxCode.OK);
return model;
}
model.setCode(AjaxCode.ERROR);
return model
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能正常的情况下才上传的,请放心下载使用。 2、适用人群:主要针对计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、数学、电子信息等)的同学或企业员工下载使用,具有较高的学习借鉴价值。 3、不仅适合小白学习实战练习,也可作为大作业、课程设计、毕设项目、初期项目立项演示等,欢迎下载,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
糖尿病管理系统服务端完整源码+说明.zip (386个子文件)
DoctorApiController.class 9KB
DoctorApiController.class 9KB
SuffererApiController.class 8KB
SuffererApiController.class 8KB
QuestionApiController.class 7KB
QuestionApiController.class 7KB
TextUtil.class 6KB
TextUtil.class 6KB
DoctorPatientApiController.class 5KB
DoctorPatientApiController.class 5KB
DoctorServiceImpl.class 4KB
DoctorServiceImpl.class 4KB
QiniuApiController.class 4KB
QiniuApiController.class 4KB
SuffererServiceImpl.class 4KB
SuffererServiceImpl.class 4KB
IndexApiController.class 4KB
IndexApiController.class 4KB
Doctor.class 3KB
Doctor.class 3KB
OpinionApiController.class 3KB
OpinionApiController.class 3KB
DoctorPatientServiceImpl.class 3KB
DoctorPatientServiceImpl.class 3KB
AjaxCode.class 3KB
AjaxCode.class 3KB
HealthInfoApiController.class 3KB
HealthInfoApiController.class 3KB
QuestionServiceImpl.class 3KB
QuestionServiceImpl.class 3KB
QuestionAndAnswerServiceImpl.class 3KB
QuestionAndAnswerServiceImpl.class 3KB
Sufferer.class 3KB
Sufferer.class 3KB
AppTests.class 2KB
HealthInfoServiceImpl.class 2KB
HealthInfoServiceImpl.class 2KB
AnswerServiceImpl.class 2KB
AnswerServiceImpl.class 2KB
BloodSugarLog.class 2KB
BloodSugarLog.class 2KB
AppToken.class 2KB
AppToken.class 2KB
BaseDateFormat.class 2KB
BaseDateFormat.class 2KB
AdminApiController.class 2KB
AdminApiController.class 2KB
Question.class 2KB
Question.class 2KB
HealthInfo.class 2KB
HealthInfo.class 2KB
BloodSugarLogServiceImpl.class 2KB
BloodSugarLogServiceImpl.class 2KB
AppTokenServiceImpl.class 2KB
AppTokenServiceImpl.class 2KB
Answer.class 2KB
Answer.class 2KB
Opinion.class 2KB
Opinion.class 2KB
QuestionAndAnswer.class 2KB
QuestionAndAnswer.class 2KB
DoctorPatient.class 2KB
DoctorPatient.class 2KB
OpinionServiceImpl.class 1KB
OpinionServiceImpl.class 1KB
PageInfo.class 1KB
PageInfo.class 1KB
AjaxModel.class 1KB
AjaxModel.class 1KB
BaseController.class 900B
BaseController.class 900B
IDoctorService.class 897B
IDoctorService.class 897B
DoctorPatientDao.class 820B
DoctorPatientDao.class 820B
IDoctorPatientService.class 774B
IDoctorPatientService.class 774B
DoctorDao.class 760B
DoctorDao.class 760B
IQuestionService.class 755B
IQuestionService.class 755B
IQuestionAndAnswerService.class 748B
IQuestionAndAnswerService.class 748B
ISuffererService.class 734B
ISuffererService.class 734B
AppTokenDao.class 648B
AppTokenDao.class 648B
QuestionAndAnswerDao.class 610B
QuestionAndAnswerDao.class 610B
IndexController.class 606B
IndexController.class 606B
QuestionDao.class 604B
QuestionDao.class 604B
BloodSugarLogDao.class 602B
BloodSugarLogDao.class 602B
IHealthInfoService.class 533B
IHealthInfoService.class 533B
IAnswerService.class 531B
IAnswerService.class 531B
SuffererDao.class 525B
共 386 条
- 1
- 2
- 3
- 4
资源评论
龙年行大运
- 粉丝: 1266
- 资源: 3865
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功