目录
一.目标概述
本次项目实施的目的是完成工作日志功能。对于工作日志,我和另外一位同学进行分工,我负责后端接口功能和数据库的设计和编写,他负责前端界面的编写,最后一起前后端交互,从而实现工作日志功能。
二.数据库设计
工作日志设计增删改查,但是是因为是个人的工作记录,因此采用单表进行操作。
三.功能代码
1.工作日志的查询和展示
@RequestMapping("/findLogTime")
public JsonResult<Object> findLogTime(@RequestBody Map<String,String> map){
String userid = map.get("userid");
List<WorkLogTime> workLogTimeList = workLogService.findLogTime(userid);
JsonResult<Object> jsonResult = new JsonResult<Object>("200", (Object) workLogTimeList,"获取工作日志成功");
//System.out.println(jsonResult);
return jsonResult;
}
2.工作日志的添加
@RequestMapping("/createLogTime")
public JsonResult<Object> createLogTime(@RequestBody Map<String,String> map){
if (!map.containsKey("userid") || map.get("userid").equals("") || map.get("userid") == null){
return new JsonResult<Object>("400","缺少userid");
}
if (!map.containsKey("title") || map.get("title").equals("") || map.get("title") == null){
return new JsonResult<Object>("400","缺少title");
}
if (!map.containsKey("details") || map.get("details").equals("") || map.get("details") == null){
return new JsonResult<Object>("400","缺少details");
}
String userid = map.get("userid");
String title = map.get("title");
String details = map.get("details");
Date date = new Date(System.currentTimeMillis());
WorkLogTime workLogTime = new WorkLogTime(userid,title,details,date);
int res = workLogService.createLogTime(workLogTime);
if (res == ResCondition.workLog_success){
JsonResult<Object> jsonResult = new JsonResult<Object>("200",(Object) workLogTime,"创建日志成功");
return jsonResult;
}
else {
JsonResult<Object> jsonResult = new JsonResult<Object>("400",(Object) workLogTime,"创建日志失败");
return jsonResult;
}
}
3.工作日志的修改
@RequestMapping("/updateLogTime")
public JsonResult<Object> updateLogTime(@RequestBody Map<String,String> map){
if (!map.containsKey("id") || map.get("id").equals("") || map.get("id") == null){
return new JsonResult<Object>("400","缺少id");
}
if (!map.containsKey("title") || map.get("title").equals("") || map.get("title") == null){
return new JsonResult<Object>("400","缺少title");
}
if (!map.containsKey("details") || map.get("details").equals("") || map.get("details") == null){
return new JsonResult<Object>("400","缺少details");
}
int workLogTimeId = Integer.parseInt(map.get("id"));
String title = map.get("title");
String details = map.get("details");
WorkLogTime workLogTime = new WorkLogTime(workLogTimeId,title,details);
int res = workLogService.updateLogTime(workLogTime);
if (res == ResCondition.workLog_success){
JsonResult<Object> jsonResult = new JsonResult<Object>("200",(Object) workLogTime,"修改日志成功");
return jsonResult;
}
else {
JsonResult<Object> jsonResult = new JsonResult<Object>("400",(Object) workLogTime,"修改日志失败");
return jsonResult;
}
}
4.工作日志的删除
@RequestMapping("/deleteLogTime")
public JsonResult<Object> deleteLogTime(@RequestBody Map<String,String> map){
if (!map.containsKey("id") || map.get("id").equals("") || map.get("id") == null){
return new JsonResult<Object>("400","缺少id");
}
int workLogTimeId = Integer.parseInt(map.get("id"));
int res = workLogService.deleteLogTime(workLogTimeId);
if (res == ResCondition.workLog_success){
JsonResult<Object> jsonResult = new JsonResult<Object>("200",(Object) workLogTimeId,"删除日志成功");
return jsonResult;
}
else {
JsonResult<Object> jsonResult = new JsonResult<Object>("400",(Object) workLogTimeId,"删除日志失败");
return jsonResult;
}
}
三.前后端联调后界面展示
四.总结
通过本次对工作日志的编写,我们完成了工作日志的基本功能,知道了前后端成员之间协作的过程和方法,后续,我们继续进行问卷功能的编写。