数据库
首页 > 数据库> > Java项目:健身房在线预约管理系统(java+SpringBoot+maven+mysql)

Java项目:健身房在线预约管理系统(java+SpringBoot+maven+mysql)

作者:互联网

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

系统分四个角色,管理员,职工、教练、前台用户 ,各角色功能如下:

管理员:系统管理(角色、权限、菜单等)、职工管理、健身会员管理、会员充值管理、健身项目管理、健身百科管理、健身器材管理、教练预约管理、反馈管理、活动管理、支付管理、会员请假管理、健身房信息管理、回访信息管理。

职工人员:职工管理、健身会员管理、会员充值管理、健身项目管理、健身百科管理、健身器材管理、教练预约管理、反馈管理、活动管理、支付管理、会员请假管理、健身房信息管理、回访信息管理。

教练:健身会员管理、健身项目管理、健身百科管理、健身器材管理、教练预约管理、反馈管理、会员请假管理、回访信息管理。

前台会员:登录、查看活动、查看健身项目、预定健身项目、健身器材查看、健身计划、查看健身百科、留言、举报、健身预约、个人中心(充值记录、预定记录、修改密码等)。

运行环境:windows/Linux均可、jdk1.8、mysql5.7、idea/eclipse均可。

特色功能:用户可以自助预约课程、支付宝沙箱支付等。

 

 

 

 

后台用户管理控制器:

/**
 * 后台用户管理控制器
 * @author yy
 *
 */
@RequestMapping("/admin/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<User> 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.findByType(Role.ADMIN_ROLE_TYPE_ADMIN));
		return "admin/user/add";
	}
	
	/**
	 * 用户添加表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> 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);
		}
		//到这说明一切符合条件,进行数据库新增
		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.findByType(Role.ADMIN_ROLE_TYPE_ADMIN));
		model.addAttribute("user", userService.find(id));
		return "admin/user/edit";
	}
	
	/**
	 * 编辑用户信息表单提交处理
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> 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);
		}
		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());
		//讲提交的用户信息指定字段复制到已存在的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<Boolean> 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);
	}
}

后台角色管理控制器:

/**
 * 后台角色管理控制器
 * @author yy
 *
 */
@RequestMapping("/admin/role")
@Controller
public class RoleController {

	
	private Logger log = LoggerFactory.getLogger(RoleController.class);
	
	@Autowired
	private MenuService menuService;
	
	@Autowired
	private OperaterLogService operaterLogService;
	
	@Autowired
	private RoleService roleService;
	
	/**
	 * 分页搜索角色列表
	 * @param model
	 * @param role
	 * @param pageBean
	 * @return
	 */
	@RequestMapping(value="/list")
	public String list(Model model,Role role,PageBean<Role> pageBean){
		model.addAttribute("title", "角色列表");
		model.addAttribute("name", role.getName());
		model.addAttribute("pageBean", roleService.findByName(role, pageBean));
		return "admin/role/list";
	}
	
	/**
	 * 角色添加页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		return "admin/role/add";
	}
	
	/**
	 * 角色添加表单提交处理
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(Role role){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(role);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(roleService.save(role) == null){
			return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
		}
		log.info("添加角色【"+role+"】");
		operaterLogService.add("添加角色【"+role.getName()+"】");
		return Result.success(true);
	}
	
	/**
	 * 角色编辑页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(@RequestParam(name="id",required=true)Long id,Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		Role role = roleService.find(id);
		model.addAttribute("role", role);
		model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
		return "admin/role/edit";
	}
	
	/**
	 * 角色修改表单提交处理
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit(Role role){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(role);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		Role existRole = roleService.find(role.getId());
		if(existRole == null){
			return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
		}
		existRole.setName(role.getName());
		existRole.setRemark(role.getRemark());
		existRole.setStatus(role.getStatus());
		existRole.setAuthorities(role.getAuthorities());
		existRole.setType(role.getType());
		if(roleService.save(existRole) == null){
			return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
		}
		log.info("编辑角色【"+role+"】");
		operaterLogService.add("编辑角色【"+role.getName()+"】");
		return Result.success(true);
	}
	
	/**
	 * 删除角色
	 * @param request
	 * @param id
	 * @return
	 */
	@RequestMapping(value="delete",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
		try {
			roleService.delete(id);
		} catch (Exception e) {
			// TODO: handle exception
			return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
		}
		log.info("编辑角色ID【"+id+"】");
		operaterLogService.add("删除角色ID【"+id+"】");
		return Result.success(true);
	}
}

系统控制器:

/**
 * 系统控制器
 * @author yy
 *
 */
@RequestMapping("/system")
@Controller
public class SystemController {

	@Autowired
	private OperaterLogService operaterLogService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private DatabaseBakService databaseBakService;

	@Autowired
	private ItemService itemService;

	@Autowired
	private PeopleService peopleService;
	@Autowired
	private OrderAuthService orderAuthService;
	@Autowired
	private StaffService staffService;

/*	@Value("${show.tips.text}")
	private String showTipsText;
	@Value("${show.tips.url.text}")
	private String showTipsUrlText;
	@Value("${show.tips.btn.text}")
	private String showTipsBtnText;
	@Value("${show.tips.url}")
	private String showTipsUtl;*/
	
	private Logger log = LoggerFactory.getLogger(SystemController.class);
	
	/**
	 * 登录页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login(Model model){
		return "admin/system/login";
	}
	
	/**
	 * 用户登录提交表单处理方法
	 * @param request
	 * @param user
	 * @param cpacha
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> login(HttpServletRequest request,User user,String cpacha){
		if(user == null){
			return Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(user);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		//表示实体信息合法,开始验证验证码是否为空
		if(StringUtils.isEmpty(cpacha)){
			return Result.error(CodeMsg.CPACHA_EMPTY);
		}
		//说明验证码不为空,从session里获取验证码
		Object attribute = request.getSession().getAttribute("admin_login");
		if(attribute == null){
			return Result.error(CodeMsg.SESSION_EXPIRED);
		}
		//表示session未失效,进一步判断用户填写的验证码是否正确
		if(!cpacha.equalsIgnoreCase(attribute.toString())){
			return Result.error(CodeMsg.CPACHA_ERROR);
		}
		//表示验证码正确,开始查询数据库,检验密码是否正确
		User findByUsername = userService.findByUsername(user.getUsername());
		//判断是否为空
		if(findByUsername == null){
			return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
		}
		//表示用户存在,进一步对比密码是否正确
		if(!findByUsername.getPassword().equals(user.getPassword())){
			return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
		}
		//表示密码正确,接下来判断用户状态是否可用
		if(findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE){
			return Result.error(CodeMsg.ADMIN_USER_UNABLE);
		}
		//检查用户所属角色状态是否可用
		if(findByUsername.getRole() == null || findByUsername.getRole().getStatus() == Role.ADMIN_ROLE_STATUS_UNABLE){
			return Result.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);
		}
		//检查用户所属角色的权限是否存在
		if(findByUsername.getRole().getAuthorities() == null || findByUsername.getRole().getAuthorities().size() == 0){
			return Result.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);
		}
		//检查一切符合,可以登录,将用户信息存放至session
		request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, findByUsername);
		//销毁session中的验证码
		request.getSession().setAttribute("admin_login", null);
		//将登陆记录写入日志库
		operaterLogService.add("用户【"+user.getUsername()+"】于【" + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd HH:mm:ss") + "】登录系统!");
		log.info("用户成功登录,user = " + findByUsername);
		return Result.success(true);
	}
	
	/**
	 * 登录成功后的系统主页
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/index")
	public String index(Model model){
		model.addAttribute("operatorLogs", operaterLogService.findLastestLog(10));
		model.addAttribute("userTotal", userService.total());
		model.addAttribute("operatorLogTotal", operaterLogService.total());
		model.addAttribute("databaseBackupTotal", databaseBakService.total());
		model.addAttribute("itemCount", itemService.count());
		model.addAttribute("peopleCount", peopleService.count());
		model.addAttribute("workerCount", staffService.countByType(Staff.WORKER));
		model.addAttribute("coachCount", staffService.countByType(Staff.COACH));
		model.addAttribute("onlineUserTotal", SessionListener.onlineUserCount);
		return "admin/system/index";
	}
	
	/**
	 * 注销登录
	 * @return
	 */
	@RequestMapping(value="/logout")
	public String logout(){
		User loginedUser = SessionUtil.getLoginedUser();
		if(loginedUser != null){
			SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, null);
		}
		return "redirect:login";
	}
	
	/**
	 * 无权限提示页面
	 * @return
	 */
	@RequestMapping(value="/no_right")
	public String noRight(){
		return "admin/system/no_right";
	}
	
	/**
	 * 修改用户个人信息
	 * @return
	 */
	@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)
	public String updateUserInfo(){
		return "admin/system/update_userinfo";
	}
	
	/**
	 * 修改个人信息保存
	 * @param user
	 * @return
	 */
	@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)
	public String updateUserInfo(User user){
		User loginedUser = SessionUtil.getLoginedUser();
		loginedUser.setEmail(user.getEmail());
		loginedUser.setMobile(user.getMobile());
		loginedUser.setHeadPic(user.getHeadPic());
		//首先保存到数据库
		userService.save(loginedUser);
		//更新session里的值
		SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
		return "redirect:update_userinfo";
	}
	
	/**
	 * 修改密码页面
	 * @return
	 */
	@RequestMapping(value="/update_pwd",method=RequestMethod.GET)
	public String updatePwd(){
		return "admin/system/update_pwd";
	}
	
	/**
	 * 修改密码表单提交
	 * @param oldPwd
	 * @param newPwd
	 * @return
	 */
	@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> updatePwd(@RequestParam(name="oldPwd",required=true)String oldPwd,
			@RequestParam(name="newPwd",required=true)String newPwd
			){
		User loginedUser = SessionUtil.getLoginedUser();
		if(!loginedUser.getPassword().equals(oldPwd)){
			return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
		}
		if(StringUtils.isEmpty(newPwd)){
			return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
		}
		if (newPwd.length() < 4){
			return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_LENGTH);
		}
		loginedUser.setPassword(newPwd);
		//保存数据库
		userService.save(loginedUser);
		//更新session
		SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
		return Result.success(true);
	}
	
	/**
	 * 日志管理列表
	 * @param model
	 * @param operaterLog
	 * @param pageBean
	 * @return
	 */
	@RequestMapping(value="/operator_log_list")
	public String operatorLogList(Model model,OperaterLog operaterLog,PageBean<OperaterLog> pageBean){
		model.addAttribute("pageBean", operaterLogService.findList(operaterLog, pageBean));
		model.addAttribute("operator", operaterLog.getOperator());
		model.addAttribute("title", "日志列表");
		return "admin/system/operator_log_list";
	}
	
	/**
	 * 删除操作日志,可删除多个
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(String ids){
		if(!StringUtils.isEmpty(ids)){
			String[] splitIds = ids.split(",");
			for(String id : splitIds){
				operaterLogService.delete(Long.valueOf(id));
			}
		}
		return Result.success(true);
	}
	/**
	 * 清空整个日志
	 * @return
	 */
	@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> deleteAll(){
		operaterLogService.deleteAll();
		return Result.success(true);
	}
}

会员管理控制层:

@RequestMapping("/admin/people")
@Controller
public class PeopleController {

    @Autowired
    private PeopleService peopleService;

    @Autowired
    private OperaterLogService operaterLogService;

    @Autowired
    private PlanService planService;


    @RequestMapping("/list")
    public String list(PageBean<People> pageBean, People people, Model model){
        model.addAttribute("title","会员列表");
        model.addAttribute("mobile",people.getMobile());
        model.addAttribute("pageBean",peopleService.findAllByLikeMobile(pageBean,people));
        return "admin/people/list";
    }

    /**
     * 进入保存页面
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.GET)
    public String add(){
        return "admin/people/add";
    }

    /**
     * 表单验证进行保存
     * @param people
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> add(People people){
        //进行实体校验
        CodeMsg validate = ValidateEntityUtil.validate(people);
        if (validate.getCode() != CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }

        //校验该会员信息是否录入
        if (peopleService.isExistMobile(people.getMobile(),0L)){
            return Result.error(CodeMsg.ADMIN_MOBILE_EXIST);
        }

        people.setPassword("123456");

        //计算BMI
        DecimalFormat df=new DecimalFormat("0.0");
        String format = df.format((float)people.getWeight() / ((float)people.getStature()/100 * (float)people.getStature()/100));
        people.setBmi(Double.valueOf(format));

        //计算体脂率
        if (StaticConstants.SEX_UNKONW.equals(people.getSex())){
            people.setBodyFat(0.00);
        }

        if (StaticConstants.SEX_WOMAN.equals(people.getSex())){
            BigDecimal bigDecimalWaistline = new BigDecimal(people.getWaistline());

            BigDecimal bigDecimalWeight = new BigDecimal(people.getWeight());

            //计算参数a
            BigDecimal a = bigDecimalWaistline.multiply(new BigDecimal("0.74"));
            //计算参数b
            BigDecimal b = bigDecimalWeight.multiply(new BigDecimal("0.082")).add(new BigDecimal("34.89"));

            //计算参数体脂
            BigDecimal bodyFat = a.subtract(b).divide(bigDecimalWeight,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));


            people.setBodyFat(Double.valueOf(String.valueOf(bodyFat)));
        }

        if(StaticConstants.SEX_MAN.equals(people.getSex())){
            BigDecimal bigDecimalWaistline = new BigDecimal(people.getWaistline());

            BigDecimal bigDecimalWeight = new BigDecimal(people.getWeight());

            //计算参数a
            BigDecimal a = bigDecimalWaistline.multiply(new BigDecimal("0.74"));
            //计算参数b
            BigDecimal b = bigDecimalWeight.multiply(new BigDecimal("0.082")).add(new BigDecimal("44.74"));

            //计算参数体脂
            BigDecimal bodyFat = a.subtract(b).divide(bigDecimalWeight,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));

            people.setBodyFat(Double.valueOf(String.valueOf(bodyFat)));
        }

        //一切符合进行保存
         if (peopleService.save(people) == null) {
             return Result.error(CodeMsg.ADMIN_PEOPLE_ADD_ERROR);
        }

        //保存完成进行日志记录
        operaterLogService.add("添加健身会员,健身会员id:" + people.getId());

        return Result.success(true);
    }

    /**
     * 进入编辑页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public String edit(Model model,Long id){
        model.addAttribute("people",peopleService.find(id));
        return "admin/people/edit";
    }

    /**
     * 表单验证进行编辑
     * @param people
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public Result<Boolean> edit(People people){
        //进行实体校验
        CodeMsg validate = ValidateEntityUtil.validate(people);
        if (validate.getCode() != CodeMsg.SUCCESS.getCode()){
            return Result.error(validate);
        }

        //校验该会员信息是否录入
        if (peopleService.isExistMobile(people.getMobile(),people.getId())){
            return Result.error(CodeMsg.ADMIN_MOBILE_EXIST);
        }

        //计算体脂率
        if (StaticConstants.SEX_UNKONW.equals(people.getSex())){
            people.setBodyFat(0.00);
        }

        if (StaticConstants.SEX_WOMAN.equals(people.getSex())){
            BigDecimal bigDecimalWaistline = new BigDecimal(people.getWaistline());

            BigDecimal bigDecimalWeight = new BigDecimal(people.getWeight());

            //计算参数a
            BigDecimal a = bigDecimalWaistline.multiply(new BigDecimal("0.74"));
            //计算参数b
            BigDecimal b = bigDecimalWeight.multiply(new BigDecimal("0.082")).add(new BigDecimal("34.89"));

            //计算参数体脂
            BigDecimal bodyFat = a.subtract(b).divide(bigDecimalWeight,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));


            people.setBodyFat(Double.valueOf(String.valueOf(bodyFat)));
        }

        if(StaticConstants.SEX_MAN.equals(people.getSex())){
            BigDecimal bigDecimalWaistline = new BigDecimal(people.getWaistline());

            BigDecimal bigDecimalWeight = new BigDecimal(people.getWeight());

            //计算参数a
            BigDecimal a = bigDecimalWaistline.multiply(new BigDecimal("0.74"));
            //计算参数b
            BigDecimal b = bigDecimalWeight.multiply(new BigDecimal("0.082")).add(new BigDecimal("44.74"));

            //计算参数体脂
            BigDecimal bodyFat = a.subtract(b).divide(bigDecimalWeight,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));

            people.setBodyFat(Double.valueOf(String.valueOf(bodyFat)));
        }


        //计算BMI
        DecimalFormat df=new DecimalFormat("0.0");
        String format = df.format((float)people.getWeight() / ((float)people.getStature()/100 * (float)people.getStature()/100));
        people.setBmi(Double.valueOf(format));;


        People people1 = peopleService.find(people.getId());
        people.setPassword(people1.getPassword());
        people.setMemberExpirationTime(people1.getMemberExpirationTime());

        //一切符合进行编辑
        if (peopleService.save(people) == null){
            return Result.error(CodeMsg.ADMIN_PEOPLE_EDIT_ERROR);
        }

        //保存完成进行日志记录
        operaterLogService.add("编辑健身会员,健身会员id:" + people.getId());
        return Result.success(true);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public Result<Boolean> delete(Long id){
        try {
            peopleService.delete(id);
        }catch (Exception e){
            return Result.error(CodeMsg.ADMIN_PEOPLE_DELETE_ERROR);
        }
        operaterLogService.add("删除健身会员,健身会员id:" +id);
        return Result.success(true);
    }


    /**
     * 进入查看会员计划页面
     * @param model
     * @return
     */
    @RequestMapping("/plan")
    public String plan(@RequestParam("id") Long id,Model model){
        model.addAttribute("plans",planService.findAllByPeopleIdOrderByCreateTimeDesc(id));
        return "admin/people/planList";
    }

}

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

标签:return,BigDecimal,people,maven,CodeMsg,Result,mysql,Java,model
来源: https://blog.csdn.net/yuyecsdn/article/details/122318464