public ResultEntity addExercise(Exercise exercise) { ResultEntity resultEntity = new ResultEntity(); if (exercise != null) { resultEntity.setData(ExerciseApi.insert(exercise)); if (resultEntity.getData() != null) { if (exercise.exerciseType <= 3) { setTotalScore(exercise.chapterId, "preview"); } else { setTotalScore(exercise.chapterId, "review"); } resultEntity.setState(1); resultEntity.setMessage("创建习题成功!"); } else { resultEntity.setMessage("创建习题失败!"); resultEntity.setState(0); } } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }
public ResultEntity alterExercise(Exercise exercise) { ResultEntity resultEntity = new ResultEntity(); if (exercise != null) { //fragile Exercise exercise1 = ExerciseApi.findByExerciseId(exercise.exerciseId); if (exercise1 != null) { resultEntity.setData(ExerciseApi.insert(exercise)); resultEntity.setState(1); resultEntity.setMessage("习题修改成功!"); } else { resultEntity.setMessage("未找到对应习题!"); resultEntity.setState(0); } } else { resultEntity.setMessage("传入参数为空!"); resultEntity.setState(0); } return(resultEntity); }