|
@@ -1,182 +0,0 @@
|
|
|
-package cn.rankin.productservice.controller;
|
|
|
-
|
|
|
-import cn.rankin.common.utils.api.model.BaseCode;
|
|
|
-import cn.rankin.common.utils.api.model.APIResult;
|
|
|
-import cn.rankin.data.api.product.dto.CourseDTO;
|
|
|
-import cn.rankin.data.api.product.dto.CourseSubRelationDTO;
|
|
|
-import cn.rankin.common.utils.dto.search.SearchDTO;
|
|
|
-import cn.rankin.common.utils.api.page.Page;
|
|
|
-import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
|
-import cn.rankin.data.api.product.entity.Course;
|
|
|
-import cn.rankin.data.api.product.entity.Support;
|
|
|
-import cn.rankin.productservice.code.ProductServiceAPICode;
|
|
|
-import cn.rankin.productservice.proxy.CourseServiceProxy;
|
|
|
-import cn.rankin.productservice.service.*;
|
|
|
-import cn.rankin.data.api.product.vo.CourseSubItemVo;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@RestController
|
|
|
-@RequestMapping(value = "course")
|
|
|
-public class CourseController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CourseService courseService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CourseServiceProxy courseServiceProxy;
|
|
|
-
|
|
|
- @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
- public APIResult<Page<Course>> search(SearchDTO searchDTO) {
|
|
|
- Course course = new Course();
|
|
|
-
|
|
|
- String code = searchDTO.getCode();
|
|
|
- if (!StringUtils.isEmpty(code)) {
|
|
|
- course.setCode("%" + code + "%");
|
|
|
- }
|
|
|
-
|
|
|
- String name = searchDTO.getName();
|
|
|
- if (!StringUtils.isEmpty(name)) {
|
|
|
- course.setName("%" + name + "%");
|
|
|
- }
|
|
|
-
|
|
|
- course.setStatus(searchDTO.getStatus());
|
|
|
-
|
|
|
- LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
|
|
|
- sort.put("gmtModified", BaseOrderEnum.DESC);
|
|
|
-
|
|
|
- return courseService.search(course, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
|
|
|
- }
|
|
|
-
|
|
|
- // 创建资源
|
|
|
- @Transactional
|
|
|
- @RequestMapping(method = RequestMethod.POST)
|
|
|
- public APIResult<Course> create(@RequestBody CourseDTO courseDTO) {
|
|
|
- String code = courseDTO.getCode();
|
|
|
- if (StringUtils.isEmpty(code)) {
|
|
|
- return APIResult.error(ProductServiceAPICode.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- if (courseService.exists(code)) {
|
|
|
- return APIResult.error(ProductServiceAPICode.ALREADY_EXISTS);
|
|
|
- }
|
|
|
-
|
|
|
- APIResult<Course> result = courseService.create(courseDTO);
|
|
|
- if (!result.getSuccess()) {
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- Course course = result.getData();
|
|
|
- String courseId = result.getData().getId();
|
|
|
-
|
|
|
- // 更新二级关系
|
|
|
- List<CourseSubRelationDTO> subRelationList = courseDTO.getSubItemList();
|
|
|
- if (subRelationList != null) {
|
|
|
- APIResult<List<CourseSubItemVo>> subResult = courseServiceProxy.updateSubRelation(courseId, subRelationList);
|
|
|
- if (!subResult.getSuccess()) {
|
|
|
- // 显示回滚
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return APIResult.error(new BaseCode(subResult.getCode(), subResult.getMessage()));
|
|
|
- }
|
|
|
- course.setSubItemList(subResult.getData());
|
|
|
- }
|
|
|
-
|
|
|
- // 更新周边关系
|
|
|
- List<String> supportIdList = courseDTO.getSupportList();
|
|
|
- if (supportIdList != null) {
|
|
|
- APIResult<List<Support>> supportResult = courseServiceProxy.updateSupportRelation(courseId, supportIdList);
|
|
|
- if (!supportResult.getSuccess()) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return APIResult.error(new BaseCode(supportResult.getCode(), supportResult.getMessage()));
|
|
|
- }
|
|
|
- course.setSupportList(supportResult.getData());
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- // 修改资源
|
|
|
- @Transactional
|
|
|
- @RequestMapping(method = RequestMethod.PUT)
|
|
|
- public APIResult<Course> update(@RequestBody CourseDTO courseDTO) {
|
|
|
- if (courseDTO.getId() == null) {
|
|
|
- return APIResult.error(ProductServiceAPICode.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- APIResult<Course> result = courseService.update(courseDTO);
|
|
|
- if (!result.getSuccess()) {
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- Course course = result.getData();
|
|
|
- String courseId = result.getData().getId();
|
|
|
-
|
|
|
-
|
|
|
- // 更新二级关系
|
|
|
- List<CourseSubRelationDTO> subRelationList = courseDTO.getSubItemList();
|
|
|
- if (subRelationList != null) {
|
|
|
- APIResult<List<CourseSubItemVo>> subResult = courseServiceProxy.updateSubRelation(courseId, subRelationList);
|
|
|
- if (!subResult.getSuccess()) {
|
|
|
- // 显示回滚
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return APIResult.error(new BaseCode(subResult.getCode(), subResult.getMessage()));
|
|
|
- }
|
|
|
- course.setSubItemList(subResult.getData());
|
|
|
- }
|
|
|
-
|
|
|
- // 更新周边关系
|
|
|
- List<String> supportIdList = courseDTO.getSupportList();
|
|
|
- if (supportIdList != null) {
|
|
|
- APIResult<List<Support>> supportResult = courseServiceProxy.updateSupportRelation(courseId, supportIdList);
|
|
|
- if (!supportResult.getSuccess()) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return APIResult.error(new BaseCode(supportResult.getCode(), supportResult.getMessage()));
|
|
|
- }
|
|
|
- course.setSupportList(supportResult.getData());
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- // 删除
|
|
|
- @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
|
|
- public APIResult delete(@PathVariable("id") String id) {
|
|
|
- if (StringUtils.isEmpty(id)) {
|
|
|
- return APIResult.error(ProductServiceAPICode.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- APIResult<List<Item>> itemResult = itemService.findAllBySubId(id);
|
|
|
- if (itemResult.getData() == null || itemResult.getData().size() == 0) {
|
|
|
- return courseService.delete(id);
|
|
|
- }
|
|
|
-
|
|
|
- APIResult<List<Item>> result = APIResult.error(APICode.CAN_NOT_DEL);
|
|
|
- result.setData(itemResult.getData());
|
|
|
-
|
|
|
- return result;
|
|
|
-
|
|
|
-*/
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
|
|
- public APIResult<Course> getCourse(@PathVariable("id") String id) {
|
|
|
- if (StringUtils.isEmpty(id)) {
|
|
|
- return APIResult.error(ProductServiceAPICode.PARAMETER_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- Course result = courseServiceProxy.getCourse(id);
|
|
|
-
|
|
|
- return APIResult.ok(result);
|
|
|
- }
|
|
|
-}
|