diff --git a/ruoyi_edu/src/main/java/com/ruoyi/edu/controller/EduClazzController.java b/ruoyi_edu/src/main/java/com/ruoyi/edu/controller/EduClazzController.java index 2b34130..f3ce7fa 100644 --- a/ruoyi_edu/src/main/java/com/ruoyi/edu/controller/EduClazzController.java +++ b/ruoyi_edu/src/main/java/com/ruoyi/edu/controller/EduClazzController.java @@ -1,6 +1,8 @@ package com.ruoyi.edu.controller; import java.util.List; + +import com.ruoyi.common.core.domain.entity.SysUser; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -124,4 +126,15 @@ public class EduClazzController extends BaseController { return toAjax(eduClazzService.deleteEduClazzByIds(ids)); } + + @Log(title = "班级管理", businessType = BusinessType.UPDATE) + @RequiresPermissions("edu:clazz:edit") + @PostMapping("/changeStatus") + @ResponseBody + public AjaxResult changeStatus(EduClazz clazz) + { + eduClazzService.checkClazzAllowed(clazz); + eduClazzService.checkClazzDataScope(clazz.getId()); + return toAjax(eduClazzService.changeStatus(clazz)); + } } diff --git a/ruoyi_edu/src/main/java/com/ruoyi/edu/domain/EduClazz.java b/ruoyi_edu/src/main/java/com/ruoyi/edu/domain/EduClazz.java index 6a43ff6..d924030 100644 --- a/ruoyi_edu/src/main/java/com/ruoyi/edu/domain/EduClazz.java +++ b/ruoyi_edu/src/main/java/com/ruoyi/edu/domain/EduClazz.java @@ -27,7 +27,7 @@ public class EduClazz extends BaseEntity private String clazzCount; /** 状态 */ - @Excel(name = "状态") + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String visible; public void setId(Long id) @@ -67,6 +67,16 @@ public class EduClazz extends BaseEntity return visible; } + public boolean isAdmin() + { + return isAdmin(this.id); + } + + public static boolean isAdmin(Long id) + { + return id != null && 1L == id; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi_edu/src/main/java/com/ruoyi/edu/service/IEduClazzService.java b/ruoyi_edu/src/main/java/com/ruoyi/edu/service/IEduClazzService.java index ba40b50..3bb2302 100644 --- a/ruoyi_edu/src/main/java/com/ruoyi/edu/service/IEduClazzService.java +++ b/ruoyi_edu/src/main/java/com/ruoyi/edu/service/IEduClazzService.java @@ -58,4 +58,10 @@ public interface IEduClazzService * @return 结果 */ public int deleteEduClazzById(Long id); + + void checkClazzAllowed(EduClazz clazz); + + void checkClazzDataScope(Long id); + + int changeStatus(EduClazz clazz); } diff --git a/ruoyi_edu/src/main/java/com/ruoyi/edu/service/impl/EduClazzServiceImpl.java b/ruoyi_edu/src/main/java/com/ruoyi/edu/service/impl/EduClazzServiceImpl.java index 776e555..7829e8c 100644 --- a/ruoyi_edu/src/main/java/com/ruoyi/edu/service/impl/EduClazzServiceImpl.java +++ b/ruoyi_edu/src/main/java/com/ruoyi/edu/service/impl/EduClazzServiceImpl.java @@ -1,6 +1,12 @@ package com.ruoyi.edu.service.impl; import java.util.List; + +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.spring.SpringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.edu.mapper.EduClazzMapper; @@ -91,4 +97,33 @@ public class EduClazzServiceImpl implements IEduClazzService { return eduClazzMapper.deleteEduClazzById(id); } + + @Override + public void checkClazzAllowed(EduClazz clazz) { + if (StringUtils.isNotNull(clazz.getId()) && clazz.isAdmin()) + { + throw new ServiceException("不允许操作超级管理员用户"); + } + } + + @Override + public void checkClazzDataScope(Long id) { + + if (!EduClazz.isAdmin(ShiroUtils.getUserId())) + { + EduClazz clazz = new EduClazz(); + clazz.setId(id); + List clazzs = SpringUtils.getAopProxy(this).selectEduClazzList(clazz); + if (StringUtils.isEmpty(clazzs)) + { + throw new ServiceException("没有权限访问用户数据!"); + } + } + } + + + @Override + public int changeStatus(EduClazz clazz) { + return eduClazzMapper.updateEduClazz(clazz); + } } diff --git a/ruoyi_edu/src/main/resources/templates/edu/clazz/add.html b/ruoyi_edu/src/main/resources/templates/edu/clazz/add.html index a780745..cd611ea 100644 --- a/ruoyi_edu/src/main/resources/templates/edu/clazz/add.html +++ b/ruoyi_edu/src/main/resources/templates/edu/clazz/add.html @@ -21,7 +21,11 @@
- + +
@@ -35,7 +39,11 @@ function submitHandler() { if ($.validate.form()) { - $.operate.save(prefix + "/add", $('#form-clazz-add').serialize()); + var data = $("#form-clazz-add").serializeArray(); + var visible=$("input[id='visible']").is(':checked') == true ? 0 : 1; + console.log(visible); + data.push({"name": "visible", "value": visible}); + $.operate.save(prefix + "/add", data); } } diff --git a/ruoyi_edu/src/main/resources/templates/edu/clazz/clazz.html b/ruoyi_edu/src/main/resources/templates/edu/clazz/clazz.html index 13c9107..7fa1bc6 100644 --- a/ruoyi_edu/src/main/resources/templates/edu/clazz/clazz.html +++ b/ruoyi_edu/src/main/resources/templates/edu/clazz/clazz.html @@ -19,8 +19,12 @@
  • - - + + + 班级状态:
  •  搜索 @@ -81,8 +85,13 @@ title: '班级人数' }, { + visible: editFlag == 'hidden' ? false : true, field: 'visible', - title: '状态' + title: '状态', + align: 'center', + formatter: function (value, row, index) { + return statusTools(row); + } }, { title: '操作', @@ -97,6 +106,30 @@ }; $.table.init(options); }); + + + /* 用户状态显示 */ + function statusTools(row) { + if (row.visible == 1) { + return ' '; + } else { + return ' '; + } + } + + /* 用户管理-停用 */ + function disable(id) { + $.modal.confirm("确认要停用用户吗?", function() { + $.operate.post(prefix + "/changeStatus", { "id": id, "visible": 1 }); + }) + } + + /* 用户管理启用 */ + function enable(id) { + $.modal.confirm("确认要启用用户吗?", function() { + $.operate.post(prefix + "/changeStatus", { "id": id, "visible": 0 }); + }) + } \ No newline at end of file