第三课主要是健康管理员端后台接口开发,主要功能有健康管理员对基本信息(姓名、性别、年龄、手机)的操作、用户和健康管理员转账的功能。
AccountController.java
// 标记controller,返回json数据
@RestController
public class AccountController {
// 自动注入service
@Autowired
private AccountService accountService;
/**
* 转账
* @param transferDetail
* @return
*/
@PostMapping("transfer")
public ResultObject add(@RequestBody TransferDetail transferDetail) {
String status = accountService.transfer(transferDetail);
ResultObject resultObject = new ResultObject(200, status, null);
return resultObject;
}
}
DoctorController.java
// 标记controller,返回json数据,URL前缀:/doctor
@RestController
@RequestMapping("doctor")
public class DoctorController {
// 自动注入service
@Autowired
private DoctorService doctorService;
/**
* 创建健康管理员
* @param doctor
* @return
*/
@PostMapping("add")
public ResultObject add(@RequestBody Doctor doctor) {
int modifyId = doctorService.insertDoctor(doctor);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 删除健康管理员
* @param id
* @return
*/
@DeleteMapping("delete")
public ResultObject delete(@RequestParam int id) {
int modifyId = doctorService.deleteDoctor(id);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 更新健康管理员
* @param doctor
* @return
*/
@PutMapping("modify")
public ResultObject modify(@RequestBody Doctor doctor) {
int modifyId = doctorService.updateDoctor(doctor);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 查询健康管理员
* @param id
* @return
*/
@GetMapping("find")
public ResultObject find(@RequestParam int id) {
Doctor doctor = doctorService.selectDoctor(id);
Map<String, Doctor> map = new HashMap<>();
map.put("doctor", doctor);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
}
UserController.java
// 标记controller,返回json数据,URL前缀:/user
@RestController
@RequestMapping("user")
public class UserController {
// 自动注入service
@Autowired
private UserService userService;
/**
* 创建用户
* @param user
* @return
*/
@PostMapping("add")
public ResultObject add(@RequestBody User user) {
int modifyId = userService.insertUser(user);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 删除用户
* @param id
* @return
*/
@DeleteMapping("delete")
public ResultObject delete(@RequestParam int id) {
int modifyId = userService.deleteUser(id);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 更新用户
* @param user
* @return
*/
@PutMapping("modify")
public ResultObject modify(@RequestBody User user) {
int modifyId = userService.updateUser(user);
Map<String, Integer> map = new HashMap<>();
map.put("modifyId", modifyId);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
/**
* 查询用户
* @param id
* @return
*/
@GetMapping("find")
public ResultObject find(@RequestParam int id) {
User user = userService.selectUser(id);
Map<String, User> map = new HashMap<>();
map.put("user", user);
ResultObject resultObject = new ResultObject(200, "success", map);
return resultObject;
}
}