Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)

源码获取:博客首页 "资源" 里下载!

项目介绍

本项目分为管理员、医生、病人三种角色,
管理员的功能包含如下:
个人信息:个人资料、修改密码
系统管理:用户管理、角色管理、部门管理、菜单管理、字典管理
药物信息管理
居民健康信息
居民就诊历史
我的预约信息
居民医保信息

医生的功能包含如下:
个人信息:个人资料、修改密码
药物信息管理
居民健康信息
居民就诊历史
我的预约信息
居民医保信息

病人的功能包含如下:
个人信息:个人资料、修改密码
居民医保信息
居民健康信息
居民就诊历史

我的预约信息

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7或8.0版本;

6.是否Maven项目:是;

技术栈

1. 后端:SpringBoot+mybatis-plus

2. 前端:HTML+CSS+javascript+jQuery+bootstrap+ztree

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
管理员账号/密码:admin/111111
医生账号/密码:doctor/111111
病人账号/密码:doctor/111111

Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第1张图片

 Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第2张图片

 Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第3张图片

 Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第4张图片

 Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第5张图片

 Java项目:社区养老医疗综合服务系统(java+SpringBoot+bootstrap+HTML+mysql)_第6张图片

医生管理控制层:

/**
 * 医生管理控制层
 */

@Controller
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private OperaterLogService operaterLogService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private OrderReceivingService orderReceivingService;

    @Autowired
    private BedAllotService bedAllotService;

    /**
     * 跳转医生列表页面
     * @param model
     * @param doctor
     * @param pageBean
     * @return
     */
    @RequestMapping(value = "/list")
    public String list(Model model, Doctor doctor, PageBean pageBean) {
        model.addAttribute("title", "医生列表");
        if (doctor.getUser() != null) {
            model.addAttribute("name", doctor.getUser().getName());
        }
        model.addAttribute("pageBean", doctorService.findList(doctor, pageBean));
        return "admin/doctor/list";
    }

    /**
     * 医生添加页面
     * @param model
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(Model model) {

        model.addAttribute("departments", departmentService.findAllDepartment());
        return "admin/doctor/add";
    }

    /**
     * 医生添加提交
     * @param doctor
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result add(Doctor doctor) {

        CodeMsg validate = ValidateEntityUtil.validate(doctor);

        if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
            return Result.error(validate);
        }
        if(Objects.isNull(doctor.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(doctor.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }

        if (!StringUtil.emailFormat(doctor.getUser().getEmail())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        if (!StringUtil.isMobile(doctor.getUser().getMobile())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }

        Role role = roleService.find(Doctor.DOCTOR_ROLE_ID);
        String dNo = StringUtil.generateSn(Doctor.PATIENT_ROLE_DNO);

        int age = DateUtil.getAge(doctor.getUser().getBirthDay());
        if (age < 0) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
        }

        doctor.setDoctorDno(dNo);
        doctor.getUser().setPassword(dNo);
        doctor.getUser().setUsername(dNo);
        doctor.getUser().setRole(role);

        User user = doctor.getUser();
        user.setAge(age);

        User save = userService.save(user);
        if (userService.save(user) == null) {
            return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
        }
        operaterLogService.add("添加用户,用户名:" + user.getUsername());
        doctor.setUser(save);

        if (doctorService.save(doctor) == null) {
            return Result.error(CodeMsg.ADMIN_DOCTOR_ADD_EXIST);
        }
        return Result.success(true);
    }


    /**
     * 医生修改页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String edit(Model model, @RequestParam(name = "id") Long id) {
        model.addAttribute("doctor", doctorService.find(id));
        model.addAttribute("departments", departmentService.findAllDepartment());
        return "admin/doctor/edit";
    }


    /**
     * 医生修改提交
     * @param doctor
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public Result edit(Doctor doctor) {
        Doctor findDoctor = doctorService.find(doctor.getId());

        List doctors = doctorService.findByDoctorDno(findDoctor.getDoctorDno());

        if (doctors.size() > 1 || doctors.size() <= 0) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }

        if (doctors.get(0).getId() != doctor.getId()) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }
        if(Objects.isNull(doctor.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(doctor.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }
        if (!StringUtil.emailFormat(doctor.getUser().getEmail())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        if (!StringUtil.isMobile(doctor.getUser().getMobile())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }

        int age = DateUtil.getAge(doctor.getUser().getBirthDay());
        if (age < 0) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
        }

        findDoctor.setDepartment(doctor.getDepartment());
        findDoctor.setDescription(doctor.getDescription());
        findDoctor.setExperience(doctor.getExperience());

        User user = doctor.getUser();
        user.setAge(age);

        BeanUtils.copyProperties(user, findDoctor.getUser(), "id", "createTime", "updateTime", "password", "username", "role");

        userService.save(findDoctor.getUser());
        doctorService.save(findDoctor);

        return Result.success(true);
    }


    /**
     * 删除医生用户
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam(name = "id", required = true) Long id) {
        try {
            Doctor doctor = doctorService.find(id);
            doctorService.deleteById(id);
            userService.delete(doctor.getUser().getId());
        } catch (Exception e) {
            return Result.error(CodeMsg.ADMIN_DOCTOR_DELETE_ERROR);
        }
        operaterLogService.add("添加用户,用户ID:" + id);
        return Result.success(true);
    }

    /**
     * 修改个人出诊状态页面
     * @param model
     * @return
     */
    @RequestMapping(value = "/updateStatus", method = RequestMethod.GET)
    public String updateDoctorStatus(Model model) {
        Doctor doctor = doctorService.findByLoginDoctorUser();
        model.addAttribute("title","个人出诊信息修改");
        model.addAttribute("doctor", doctor);
        return "admin/doctor/visitingStatus";
    }

    /**
     * 提交修改个人出诊状态
     * @param doctor
     * @return
     */
    @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
    @ResponseBody
    public Result editStatus(Doctor doctor) {
        Doctor doc = doctorService.findByLoginDoctorUser();
        if(Objects.isNull(doctor.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(doctor.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }
        if (!StringUtil.isMobile(doctor.getUser().getMobile())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }
        if (!StringUtil.emailFormat(doctor.getUser().getEmail())) {
            return Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        User user = doc.getUser();
        user.setEmail(doctor.getUser().getEmail());
        user.setMobile(doctor.getUser().getMobile());
        user.setStatus(doctor.getStatus());
        doc.setStatus(doctor.getStatus());
        doc.setDescription(doctor.getDescription());
        doc.setExperience(doctor.getExperience());
        BeanUtils.copyProperties(user, doctor.getUser(), "id", "createTime", "updateTime", "password", "username", "role", "sex", "age", "birthday");
        doctorService.save(doc);
        return Result.success(true);
    }

    /**
     * 医生查询接单记录
     * @param model
     * @param pageBean
     * @return
     */
    @RequestMapping(value = "/orderRecord",method = RequestMethod.GET)
    public String doctorOrderRecords(Model model, PageBean pageBean) {
        //获取医生登录的信息
        Doctor loginDoctorUser = doctorService.findByLoginDoctorUser();
        model.addAttribute("title", "出诊信息");
        model.addAttribute("pageBean", orderReceivingService.findByDoctorId(pageBean,loginDoctorUser.getId()));
        return "admin/doctor/orderRecord";
    }

    /**
     * 查看自己科室所有医生信息
     * @param model
     * @param pageBean
     * @return
     */
    @RequestMapping(value = "/findByDepartment", method = RequestMethod.GET)
    public String AllDoctorByDepartment(Model model,PageBean pageBean) {
        Doctor loginDoctorUser = doctorService.findByLoginDoctorUser();
        model.addAttribute("title", "本科室所有医生列表");
        model.addAttribute("pageBean", doctorService.findAllByDepartment(pageBean, loginDoctorUser.getDepartment().getId()));
        return "admin/doctor/doctorInformation";
    }

    /**
     * 医生完成出诊订单
     * @param id
     * @return
     */
    @RequestMapping(value = "/orderRecord",method = RequestMethod.POST)
    @ResponseBody
    public ResultmodifyVisitStatus(Long id){
        boolean flag = doctorService.modifyVisitStatus(id);
        if (flag){
          return Result.success(true);
        }
        return Result.error(CodeMsg.ADMIN_DOCTOR_CANNOT_REPEATED);
    }

    /**
     * 管理员查看所有订单信息
     * @param model
     * @param orderReceiving
     * @param pageBean
     * @return
     */
    @RequestMapping(value="/allOrderInformation",method = RequestMethod.GET)
    public String findAll(Model model,OrderReceiving orderReceiving, PageBean pageBean){
        model.addAttribute("title","出诊信息");
        model.addAttribute("pageBean",orderReceivingService.findList(orderReceiving,pageBean));
        return "admin/doctor/allOrderInformation";
    }


    /**
     * 医生查询负责的住院信息
     */
    @RequestMapping(value="/bedAllot")
    public String bedAllotSelf(Model model,PageBean pageBean){
        Doctor loginDoctorUser = doctorService.findByLoginDoctorUser();
        Long doctorId = loginDoctorUser.getId();
        model.addAttribute("title","住院信息");
        model.addAttribute("pageBean",bedAllotService.findByDoctor(pageBean,doctorId));
        return "admin/doctor/bedAllot";
    }


}

病人信息管理控制层:

/**
 * 病人信息管理控制层
 */
@Controller
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private OperaterLogService operaterLogService;
    @Autowired
    private BedAllotService bedAllotService;


    /**
     * 病人登录展示病人个人的信息页面
     */
    @RequestMapping(value = "/self")
    public String patient(Model model){
        model.addAttribute("title", "病人个人信息");
        Patient loginPatientUser = patientService.findByLoginPatientUser();
        model.addAttribute("patient",loginPatientUser);
        return "admin/patient/self";
    }

    /**
     * 跳转病人列表页面
     * @param model
     * @param patient
     * @param pageBean
     * @return
     */
    @RequestMapping(value = "/list")
    public String list(Model model, Patient patient, PageBean pageBean) {
        model.addAttribute("title", "病人列表");
        if (patient.getUser() != null) {
            model.addAttribute("name", patient.getUser().getName());
        }
        model.addAttribute("pageBean", patientService.findList(patient, pageBean));
        return "admin/patient/list";
    }

    /**
     * 跳转病人添加页面
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add() {
        return "admin/patient/add";
    }

    /**
     * 病人添加
     * @param patient
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Result add(Patient patient){
        CodeMsg validate = ValidateEntityUtil.validate(patient);

        if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }
        if(Objects.isNull(patient.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(patient.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }
        if (!StringUtil.emailFormat(patient.getUser().getEmail())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        if (!StringUtil.isMobile(patient.getUser().getMobile())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }

        Role role = roleService.find(Patient.PATIENT_ROLE_ID);
        String pNo = StringUtil.generateSn(Patient.PATIENT_ROLE_PNO);

        int age = DateUtil.getAge(patient.getUser().getBirthDay());
        if (age < 0) {
            return   Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
        }

        patient.getUser().setAge(age);
        patient.setPatientPno(pNo);
        patient.getUser().setPassword(pNo);
        patient.getUser().setUsername(pNo);
        patient.getUser().setRole(role);
        User user = patient.getUser();

        User save = userService.save(user);
        if(userService.save(user) == null){
            return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
        }
        operaterLogService.add("添加用户,用户名:" + user.getUsername());
        patient.setUser(save);

        if (patientService.save(patient) == null) {
            return Result.error(CodeMsg.ADMIN_PATIENT_ADD_EXIST);
        }
        return Result.success(true);
    }

    /**
     * 跳转到修改病人页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value="/edit",method=RequestMethod.GET)
    public String edit(Model model,@RequestParam(name="id")Long id){
        model.addAttribute("patient", patientService.find(id));
        return "admin/patient/edit";
    }

    /**
     * 修改病人
     * @param patient
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public Result edit(Patient patient) {
        Patient findPatient = patientService.find(patient.getId());

        List patients = patientService.findByPatientPno(findPatient.getPatientPno());

        if (patients.size() > 1 || patients.size() <= 0) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }

        if (patients.get(0).getId() != patient.getId()) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }
        if(Objects.isNull(patient.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(patient.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }
        if (!StringUtil.emailFormat(patient.getUser().getEmail())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        if (!StringUtil.isMobile(patient.getUser().getMobile())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }

        int age = DateUtil.getAge(patient.getUser().getBirthDay());
        if (age < 0) {
            return   Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
        }

        User user = patient.getUser();
        user.setAge(age);

        BeanUtils.copyProperties(user,findPatient.getUser(), "id","createTime","updateTime","password","username","role");

        userService.save(findPatient.getUser());
        patientService.save(findPatient);

        return Result.success(true);
    }


    /**
     * 跳转到病人修改个人信息页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value="/editSelf",method=RequestMethod.GET)
    public String editSelf(Model model,@RequestParam(name="id")Long id){
        model.addAttribute("patient", patientService.find(id));
        return "admin/patient/editSelf";
    }

    /**
     * 病人修改个人信息
     * @param patient
     * @return
     */
    @RequestMapping(value = "/editSelf", method = RequestMethod.POST)
    @ResponseBody
    public Result editSelf(Patient patient){
        Patient findPatient = patientService.find(patient.getId());
        List patients = patientService.findByPatientPno(findPatient.getPatientPno());

        if (patients.size() > 1 || patients.size() <= 0) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }

        if (patients.get(0).getId() != patient.getId()) {
            return Result.error(CodeMsg.ADMIN_PATIENT_PNO_ERROR);
        }
        if(Objects.isNull(patient.getUser().getEmail())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_EMAIL);
        }
        if(Objects.isNull(patient.getUser().getMobile())){
            return Result.error(CodeMsg.ADMIN_PUBLIC_NO_ISEXIST_MOBILE);
        }
        if (!StringUtil.emailFormat(patient.getUser().getEmail())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_EMAIL);
        }
        if (!StringUtil.isMobile(patient.getUser().getMobile())){
            return   Result.error(CodeMsg.ADMIN_PUBLIC_MOBILE);
        }

        int age = DateUtil.getAge(patient.getUser().getBirthDay());
        if (age < 0) {
            return   Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
        }

        User user = patient.getUser();
        user.setAge(age);

        BeanUtils.copyProperties(user,findPatient.getUser(), "id","createTime","updateTime","password","username","role");

        userService.save(findPatient.getUser());
        patientService.save(findPatient);

        return Result.success(true);
    }

    /**
     * 删除病人用户
     * @param id
     * @return
     */
    @RequestMapping(value="/delete",method=RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam(name="id",required=true)Long id){
        try {
            Patient patient = patientService.find(id);
            patientService.deleteById(id);
            userService.delete(patient.getUser().getId());
        } catch (Exception e) {
            return Result.error(CodeMsg.ADMIN_UPATIENT_ERROR);
        }
        operaterLogService.add("添加病人用户,病人用户ID:" + id);
        return Result.success(true);
    }

    /**
     * 病人查询个人住院信息
     */
    @RequestMapping(value="/bedAllot")
    public String bedAllotSelf(Model model,PageBean pageBean){
        Patient loginPatientUser = patientService.findByLoginPatientUser();
        Long patientId = loginPatientUser.getId();
        model.addAttribute("title","住院信息");
        model.addAttribute("pageBean",bedAllotService.findByPatient(pageBean,patientId));
        return "admin/patient/bedAllot";
    }

}

后台用户管理控制器:

/**
 * 后台用户管理控制器
 * @author yy
 *
 */
@RequestMapping("/user")
@Controller
public class UserController {

	@Autowired
	private UserService userService;
	@Autowired
	private RoleService roleService;
	@Autowired
	private OperaterLogService operaterLogService;
	/**
	 * 用户列表页面
	 * @param model
	 * @param user
	 * @param pageBean
	 * @return
	 */
	@RequestMapping(value="/list")
	public String list(Model model,User user,PageBean pageBean){
		model.addAttribute("title", "用户列表");
		model.addAttribute("username", user.getUsername());
		model.addAttribute("pageBean", userService.findList(user, pageBean));
		return "admin/user/list";
	}
	
	/**
	 * 新增用户页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("roles", roleService.findSome());
		return "admin/user/add";
	}
	
	/**
	 * 用户添加表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result add(User user){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(user);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(user.getRole() == null || user.getRole().getId() == null){
			return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
		}
		//判断用户名是否存在
		if(userService.isExistUsername(user.getUsername(), 0l)){
			return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
		}

		int age = DateUtil.getAge(user.getBirthDay());
		if (age < 0) {
			return   Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
		}
		user.setAge(age);
		//到这说明一切符合条件,进行数据库新增
		if(userService.save(user) == null){
			return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
		}
		operaterLogService.add("添加用户,用户名:" + user.getUsername());
		return Result.success(true);
	}
	
	/**
	 * 用户编辑页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,@RequestParam(name="id",required=true)Long id){
		model.addAttribute("roles", roleService.findSome());
		model.addAttribute("user", userService.find(id));
		return "admin/user/edit";
	}
	
	/**
	 * 编辑用户信息表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result edit(User user){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(user);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(user.getRole() == null || user.getRole().getId() == null){
			return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY_EDIT);
		}
		if(user.getRole().getId() == Doctor.DOCTOR_ROLE_ID || user.getRole().getId() == Patient.PATIENT_ROLE_ID){
			return Result.error(CodeMsg.ADMIN_USER_ROLE_CANNOT_CHANGE);
		}
		if(user.getId() == null || user.getId().longValue() <= 0){
			return Result.error(CodeMsg.ADMIN_USE_NO_EXIST);
		}
		if(userService.isExistUsername(user.getUsername(), user.getId())){
			return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
		}
		//到这说明一切符合条件,进行数据库保存
		User findById = userService.find(user.getId());
		int age = DateUtil.getAge(user.getBirthDay());
		if (age < 0) {
			return   Result.error(CodeMsg.ADMIN_PUBLIC_AGE);
		}
		user.setAge(age);
		//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
		BeanUtils.copyProperties(user, findById, "id","createTime","updateTime");
		if(userService.save(findById) == null){
			return Result.error(CodeMsg.ADMIN_USE_EDIT_ERROR);
		}
		operaterLogService.add("编辑用户,用户名:" + user.getUsername());
		return Result.success(true);
	}
	
	/**
	 * 删除用户
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Result delete(@RequestParam(name="id",required=true)Long id){
		try {
			userService.delete(id);
		} catch (Exception e) {
			return Result.error(CodeMsg.ADMIN_USE_DELETE_ERROR);
		}
		operaterLogService.add("添加用户,用户ID:" + id);
		return Result.success(true);
	}
}

 源码获取:博客首页 "资源" 里下载!

你可能感兴趣的