文章目录
- 一.需求分析
- 二.数据模型
- 三.服务端
- 1.Api接口
- 1)查询课程营销信息
- 2)更新课程营销信息
- 2.Dao
- 3.Service
- 4.Controller
- 四.前端
- 1.Api 方法
- 2.编写 course_marketinfo.vue
- 1)template
- 2)数据对象
- 3)保存方法
- 4)在mounted钩子方法中查询课程营销信息及数据字典信息
一.需求分析
课程营销信息包括课程价格、课程有效期等信息。
二.数据模型
课程营销信息使用course_market表存储。
数据模型如下:
文件位置:xcEduService01\xc-framework-model\src\main\java\com\xuecheng\framework\domain\course\CourseMarket.java
package com.xuecheng.framework.domain.course;import lombok.Data;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;@Data
@ToString
@Entity
@Table(name="course_market")
@GenericGenerator(name = "jpa-assigned", strategy = "assigned")
public class CourseMarket implements Serializable {private static final long serialVersionUID = -916357110051689486L;@Id@GeneratedValue(generator = "jpa-assigned")@Column(length = 32)private String id;private String charge;private String valid;private String qq;private Float price;private Float price_old;
// private Date expires;@Column(name = "start_time")private Date startTime;@Column(name = "end_time")private Date endTime;}
三.服务端
1.Api接口
文件位置:xcEduService01\xc-service-api\src\main\java\com\xuecheng\api\course\CourseControllerApi.java
1)查询课程营销信息
@ApiOperation("获取课程营销信息")
public CourseMarket getCourseMarketById(String courseId);
2)更新课程营销信息
@ApiOperation("更新课程营销信息")
public ResponseResult updateCourseMarket(String id,CourseMarket courseMarket);
2.Dao
文件位置:xcEduService01\xc-service-manage-course\src\main\java\com\xuecheng\manage_course\dao\CourseMarketRepository.java
public interface CourseMarketRepository extends JpaRepository<CourseMarket, String> {
}
3.Service
文件位置:xcEduService01\xc-service-manage-course\src\main\java\com\xuecheng\manage_course\service\CourseService.java
public CourseMarket getCourseMarketById(String courseid) {Optional<CourseMarket> optional = courseMarketRepository.findById(courseId);if(!optional.isPresent()){return optional.get();} return null;
}@public CourseMarket updateCourseMarket(String id, CourseMarket courseMarket) {CourseMarket one = this.getCourseMarketById(id);if(one!=null){one.setCharge(courseMarket.getCharge());one.setStartTime(courseMarket.getStartTime());//课程有效期,开始时间one.setEndTime(courseMarket.getEndTime());//课程有效期,结束时间one.setPrice(courseMarket.getPrice());one.setQq(courseMarket.getQq());one.setValid(courseMarket.getValid());courseMarketRepository.save(one);}else{//添加课程营销信息one = new CourseMarket();BeanUtils.copyProperties(courseMarket, one);//设置课程idone.setId(id);courseMarketRepository.save(one);} return one;
}
4.Controller
文件位置:xcEduService01\xc-service-manage-course\src\main\java\com\xuecheng\manage_course\controller\CourseController.java
@Override
@PostMapping("/coursemarket/update/{id}")
public ResponseResult updateCourseMarket(@PathVariable("id") String id, @RequestBody CourseMarket courseMarket) {CourseMarket courseMarket_u = courseService.updateCourseMarket(id, courseMarket);if(courseMarket_u!=null){return new ResponseResult(CommonCode.SUCCESS);}else{return new ResponseResult(CommonCode.FAIL);}
} @Override
@GetMapping("/coursemarket/get/{courseId}")
public CourseMarket getCourseMarketById(@PathVariable("courseId") String courseId) {return courseService.getCourseMarketById(courseId);
}
四.前端
1.Api 方法
文件位置:xc-ui-pc-teach\src\module\course\api\course.js
//获取课程营销信息
export const getCourseMarketById = id => {return http.requestQuickGet(apiUrl+'/course/coursemarket/get/'+id)
} // 更新课程营销信息
export const updateCourseMarket =(id,courseMarket) => {return http.requestPost(apiUrl+'/course/coursemarket/update/'+id,courseMarket)
}
2.编写 course_marketinfo.vue
文件位置:xc-ui-pc-teach\src\module\course\page\course_manage\course_marketinfo.vue
1)template
<template><div><el-form :model="courseForm" label-width="80px" :rules="courseRules" ref="courseForm"><el-form-item label="课程名称" prop="name"><el-input v-model="courseForm.name" auto-complete="off" ></el-input></el-form-item><el-form-item label="适用人群" prop="users"><el-input type="textarea" v-model="courseForm.users" auto-complete="off" ></el-input></el-form-item><el-form-item label="课程分类" prop="categoryActive"><el-cascaderexpand-trigger="hover":options="categoryList"v-model="categoryActive":props="props"></el-cascader></el-form-item><el-form-item label="课程等级" prop="grade"><b v-for="grade in gradeList"><el-radio v-model="courseForm.grade" :label="grade.sdId" >{{grade.sdName}}</el-radio> </b></el-form-item><el-form-item label="学习模式" prop="studymodel"><b v-for="studymodel_v in studymodelList"><el-radio v-model="courseForm.studymodel" :label="studymodel_v.sdId" >{{studymodel_v.sdName}}</el-radio> </b></el-form-item><el-form-item label="课程介绍" prop="description"><el-input type="textarea" v-model="courseForm.description" ></el-input></el-form-item></el-form><div slot="footer" class="dialog-footer"><el-button type="primary" @click.native="save" :loading="editLoading">提交</el-button></div></div>
</template>
2)数据对象
data() {return {dotype:'',courseid:'',studymodelList:[],gradeList:[],editLoading: false,props: {value: 'id',label:'label',children:'children'},categoryList: [],categoryActive:[],courseForm: {id:'',name: '',users: '',grade:'',studymodel:'',mt:'',st:'',description: ''},courseRules: {name: [{required: true, message: '请输入课程名称', trigger: 'blur'}],category: [{required: true, message: '请选择课程分类', trigger: 'blur'}],grade: [{required: true, message: '请选择课程等级', trigger: 'blur'}],studymodel: [{required: true, message: '请选择学习模式', trigger: 'blur'}]}}},
3)保存方法
methods: {save () {//修改课程this.$refs.courseForm.validate((valid) => {if (valid) {this.$confirm('确认提交吗?', '提示', {}).then(() => {this.editLoading = true;let mt = this.categoryActive[0];let st = this.categoryActive[1];this.courseForm.mt = mt;this.courseForm.st = st;let id = this.courseForm.idcourseApi.updateCoursebase(id,this.courseForm).then((res) => {this.editLoading = false;if(res.success){this.$message({message: '提交成功',type: 'success'});}else{if(res.message){this.$message.error(res.message);}else{this.$message.error('提交失败');}}});});}});}},
4)在mounted钩子方法中查询课程营销信息及数据字典信息
mounted(){//查询数据字典字典systemApi.sys_getDictionary('201').then((res) => {
// console.log(res);this.studymodelList = res.dvalue;});systemApi.sys_getDictionary('200').then((res) => {this.gradeList = res.dvalue;});//取课程分类courseApi.category_findlist({}).then((res) => {this.categoryList = res.children;});//查询课程信息//课程idthis.courseid = this.$route.params.courseid;courseApi.getCoursebaseById(this.courseid).then((res) => {
// console.log(res);this.courseForm = res;//课程分类显示,需要两级分类this.categoryActive.push(this.courseForm.mt);this.categoryActive.push(this.courseForm.st);});}