“djh”
2024-11-11 8458e64aab474c0fc2f49ae4ff22fb11ce5cf6e2
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExCourseServiceImpl.java
@@ -10,6 +10,7 @@
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.common.utils.StringUtils;
import com.gkhy.exam.system.domain.ExCourse;
import com.gkhy.exam.system.mapper.ExCourseChapterMapper;
import com.gkhy.exam.system.mapper.ExCourseMapper;
@@ -76,8 +77,9 @@
        checkUserAllowed(course);
        if(SecurityUtils.getLoginUser().getUser().getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
            course.setState(ApproveStatusEnum.APPROVED.getCode());
            course.setPrivatize(PrivatizeEnum.PUBLIC.getCode());
        }else{
            course.setState(ApproveStatusEnum.APPROVING.getCode());
            course.setState(ApproveStatusEnum.TEMPORARY.getCode());
        }
        int row =baseMapper.insert(course);
        if(row<1){
@@ -111,8 +113,11 @@
            throw new ApiException("没有权限操作其他企业课程");
        }
        if(course.getId()!=null){
            if(course.getState().equals(ApproveStatusEnum.APPROVING.getCode())){
                throw new ApiException("课程待审批状态不能再操作");
            }
            if(course.getState().equals(ApproveStatusEnum.APPROVED.getCode())){
                throw new ApiException("已审批的课程不能再修改");
                throw new ApiException("已审批的课程不能再操作");
            }
        }
    }
@@ -138,8 +143,9 @@
    @Override
    public boolean checkNameUnique(ExCourse course) {
        SysUser user=SecurityUtils.getLoginUser().getUser();
        Long courseId=course.getId()==null?-1L:course.getId();
        ExCourse cou= baseMapper.checkNameUnique(course.getName());
        ExCourse cou= baseMapper.checkNameUnique(course.getName(),user.getCompanyId());
        if(cou!=null&&cou.getId().longValue()!=courseId.longValue()){
            return UserConstant.NOT_UNIQUE;
        }
@@ -148,12 +154,36 @@
    @Override
    public int doApprove(ExCourse course) {
        ExCourse existCourse=baseMapper.selectById(course.getId());
        checkUserAllowed(existCourse);
        SysUser currentUser= SecurityUtils.getLoginUser().getUser();
        ExCourse dbCourse=getById(course.getId());
        if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
            if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){
                throw new ApiException("没有权限操作");
            }
            if(!currentUser.getCompanyId().equals(dbCourse.getCompanyId())){
                throw new ApiException("没有权限操作其他企业课程");
            }
            if(dbCourse.getState().equals(ApproveStatusEnum.APPROVED.getCode())){
                throw new ApiException("已审批的课程不能再操作");
            }
        }
        if(StringUtils.isBlank(course.getMessage())){
            course.setMessage("");
        }
        int row=baseMapper.updateById(course);
        if(row<1){
            throw new ApiException("审批失败");
        }
        return row;
    }
    @Override
    public int changeStatus(ExCourse course) {
        if(course.getId()==null||course.getStatus()==null){
            throw new ApiException("参数传参缺失");
        }
        ExCourse entity=new ExCourse().setId(course.getId()).setStatus(course.getStatus());
        entity.setUpdateBy(SecurityUtils.getUsername());
        return baseMapper.updateById(entity);
    }
}