yusm 1 개월 전
부모
커밋
d0e1a4810b

+ 55 - 6
fhKeeper/formulahousekeeper/course-manager/src/main/java/com/management/platform/controller/CourseTypeController.java

@@ -1,16 +1,21 @@
 package com.management.platform.controller;
 package com.management.platform.controller;
 
 
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.CourseInfo;
 import com.management.platform.entity.CourseInfo;
 import com.management.platform.entity.CourseType;
 import com.management.platform.entity.CourseType;
+import com.management.platform.entity.dto.CourseInfoDto;
+import com.management.platform.service.CourseInfoService;
 import com.management.platform.service.CourseTypeService;
 import com.management.platform.service.CourseTypeService;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.HttpRespMsg;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -26,21 +31,65 @@ public class CourseTypeController {
     @Resource
     @Resource
     private CourseTypeService courseTypeService;
     private CourseTypeService courseTypeService;
 
 
+    @Resource
+    private CourseInfoService courseInfoService;
     /**
     /**
-     * 保存或新增
+     * 保存或修改
      * @param courseType
      * @param courseType
-     * @param request
      * @return
      * @return
      */
      */
     @RequestMapping(value="/saveOrUpdate")
     @RequestMapping(value="/saveOrUpdate")
-    public HttpRespMsg saveOrUpdate(CourseType courseType, HttpServletRequest request) {
+    public HttpRespMsg saveOrUpdate(CourseType courseType) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         HttpRespMsg httpRespMsg = new HttpRespMsg();
-//        if (courseType.getId() == null) {
-//
-//        }
+        if(StringUtils.isEmpty(courseType.getTypeName())){
+            httpRespMsg.setError("类型名称不能为空!");
+            return httpRespMsg;
+        }
+        if (courseType.getId() == null) {
+            int count = courseTypeService.count(new QueryWrapper<CourseType>().eq("type_name", courseType.getTypeName()));
+            if(count > 0){
+                httpRespMsg.setError("类型名称重复!");
+                return httpRespMsg;
+            }
+        }else {
+            int count = courseTypeService.count(new QueryWrapper<CourseType>()
+                    .eq("type_name", courseType.getTypeName())
+                    .ne("id", courseType.getId()));
+            if(count > 0){
+                httpRespMsg.setError("类型名称重复!");
+                return httpRespMsg;
+            }
+        }
+        courseTypeService.saveOrUpdate(courseType);
         return httpRespMsg;
         return httpRespMsg;
 
 
     }
     }
 
 
+    /**
+     * 删除类型
+     * @param id
+     * @return
+     */
+    @RequestMapping(value="/delete")
+    public HttpRespMsg delete(Integer id) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        int count = courseInfoService.count(new QueryWrapper<CourseInfo>().eq("course_type_id", id));
+        if(count > 0){
+            httpRespMsg.setError("有课程类型为当前类型,不能删除!");
+            return httpRespMsg;
+        }else {
+            courseTypeService.removeById(id);
+            return httpRespMsg;
+        }
+    }
+
+    @RequestMapping(value="/typeList")
+    public HttpRespMsg typeList() {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        List<CourseType> courseTypeList = courseTypeService.list();
+        httpRespMsg.setData(courseTypeList);
+        return httpRespMsg;
+    }
+
 }
 }