业务权限优化

This commit is contained in:
易焱
2019-08-02 01:08:21 +08:00
parent 8740a34a4a
commit 5535ae1ce0
16 changed files with 160 additions and 58 deletions
@@ -6,10 +6,12 @@ import com.cwhelp.common.utils.EntityBeanUtil;
import com.cwhelp.common.utils.ResultVoUtil;
import com.cwhelp.common.utils.StatusUtil;
import com.cwhelp.common.vo.ResultVo;
import com.cwhelp.component.shiro.ShiroUtil;
import com.cwhelp.modules.business.domain.BssDept;
import com.cwhelp.modules.business.domain.BssPlatform;
import com.cwhelp.modules.business.service.BssDeptService;
import com.cwhelp.modules.business.service.BssPlatformService;
import com.cwhelp.modules.system.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -46,9 +48,15 @@ public class BssDeptController {
// 创建匹配器,进行动态查询匹配
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("name", match -> match.contains())
.withMatcher("bssPlatform.name",match -> match.contains());
.withMatcher("name", match -> match.contains());
User user = ShiroUtil.getSubject();
if (1 != user.getBssPlatform().getId()) {
matcher.withMatcher("bssPlatform.id",match -> match.contains());
BssPlatform bssPlatform = new BssPlatform();
bssPlatform.setId(user.getBssPlatform().getId());
bssDept.setBssPlatform(bssPlatform);
}
// 获取数据列表
Example<BssDept> example = Example.of(bssDept, matcher);
Page<BssDept> list = bssDeptService.getPageList(example);
@@ -7,8 +7,14 @@ import com.cwhelp.common.utils.EntityBeanUtil;
import com.cwhelp.common.utils.ResultVoUtil;
import com.cwhelp.common.utils.StatusUtil;
import com.cwhelp.common.vo.ResultVo;
import com.cwhelp.component.shiro.ShiroUtil;
import com.cwhelp.modules.business.domain.BssDept;
import com.cwhelp.modules.business.domain.BssEmployee;
import com.cwhelp.modules.business.domain.BssPlatform;
import com.cwhelp.modules.business.service.BssDeptService;
import com.cwhelp.modules.business.service.BssEmployeeService;
import com.cwhelp.modules.system.domain.User;
import com.cwhelp.modules.system.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
@@ -32,6 +38,12 @@ public class BssEmployeeController {
@Autowired
private BssEmployeeService bssEmployeeService;
@Autowired
private BssDeptService bssDeptService;
@Autowired
private UserService userService;
/**
* 列表页面
*/
@@ -39,13 +51,12 @@ public class BssEmployeeController {
@RequiresPermissions("bss:employee:index")
public String index(Model model, BssEmployee bssEmployee) {
// 创建匹配器,进行动态查询匹配
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("name", match -> match.contains());
// 获取数据列表
Example<BssEmployee> example = Example.of(bssEmployee, matcher);
Page<BssEmployee> list = bssEmployeeService.getPageList(example);
User user = ShiroUtil.getSubject();
List<BssDept> bssDepts = null;
if (1 != user.getBssPlatform().getId()) {
bssDepts = bssDeptService.findBssDeptByBssPlatformAndId(user.getBssPlatform());
}
Page<BssEmployee> list = bssEmployeeService.getPageList(bssDepts,bssEmployee);
// 封装数据
model.addAttribute("list", list.getContent());
@@ -58,7 +69,11 @@ public class BssEmployeeController {
*/
@GetMapping("/add")
@RequiresPermissions("bss:employee:add")
public String toAdd() {
public String toAdd(Model model) {
User user = ShiroUtil.getSubject();
BssPlatform bssPlatform = userService.getById(user.getId()).getBssPlatform();
List<BssDept> bssDepts = getBssDepts(user, bssPlatform);
model.addAttribute("bssDepts",bssDepts);
return "/business/employee/add";
}
@@ -68,10 +83,30 @@ public class BssEmployeeController {
@GetMapping("/edit/{id}")
@RequiresPermissions("bss:employee:edit")
public String toEdit(@PathVariable("id") BssEmployee bssEmployee, Model model) {
User user = ShiroUtil.getSubject();
BssPlatform bssPlatform = userService.getById(user.getId()).getBssPlatform();
List<BssDept> bssDepts = getBssDepts(user, bssPlatform);
model.addAttribute("bssDepts",bssDepts);
model.addAttribute("bssEmployee", bssEmployee);
return "/business/employee/add";
}
/**
* 获取当前用户下的部门
* @param user
* @param bssPlatform
* @return
*/
private List<BssDept> getBssDepts(User user, BssPlatform bssPlatform) {
List<BssDept> bssDepts = null;
if (1 != user.getBssPlatform().getId()) {
bssDepts = bssDeptService.findBssDeptByBssPlatformAndId(bssPlatform);
} else {
bssDepts = bssDeptService.findAll();
}
return bssDepts;
}
/**
* 保存添加/修改的数据
* @param valid 验证对象
@@ -7,9 +7,11 @@ import com.cwhelp.common.utils.EntityBeanUtil;
import com.cwhelp.common.utils.ResultVoUtil;
import com.cwhelp.common.utils.StatusUtil;
import com.cwhelp.common.vo.ResultVo;
import com.cwhelp.component.shiro.ShiroUtil;
import com.cwhelp.modules.business.domain.BssPlatform;
import com.cwhelp.modules.business.service.BssPlatformService;
import com.cwhelp.modules.system.domain.Dept;
import com.cwhelp.modules.system.domain.User;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,7 +50,12 @@ public class BssPlatformController {
.withMatcher("name", match -> match.contains())
.withMatcher("contact", match -> match.contains())
.withMatcher("email", match -> match.contains());
User user = ShiroUtil.getSubject();
// 判定当前用户的 所属平台 1为系统平台
if (1 != user.getBssPlatform().getId()) {
matcher.withMatcher("id",match -> match.contains());
bssPlatform.setId(user.getBssPlatform().getId());
}
// 获取数据列表
Example<BssPlatform> example = Example.of(bssPlatform, matcher);
Page<BssPlatform> list = bssPlatformService.getPageList(example);
@@ -1,5 +1,6 @@
package com.cwhelp.admin.business.validator;
import com.cwhelp.modules.business.domain.BssDept;
import lombok.Data;
import javax.validation.constraints.Email;
@@ -17,20 +18,18 @@ public class BssEmployeeValid implements Serializable {
@NotEmpty(message = "名称不能为空")
private String name;
@NotNull(message = "部门不能为空")
private Long dept_id;
private BssDept bssDept;
@NotEmpty(message = "职位不能为空")
private String position;
@NotEmpty(message = "手机号码不能为空")
@Pattern(regexp = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$", message = "手机号码格式不正确")
private String phone_num;
private String phoneNum;
@NotEmpty(message = "身份证号码不能为空")
@Pattern(regexp = "(^(\\d{14}|\\d{17})(\\d|[xX])$)?", message = "身份证号码错误")
private String card;
@NotEmpty(message = "邮箱不能为空")
@Email(message = "邮箱格式不正确")
private String email;
@NotEmpty(message = "员工状态不能为空")
private String employee_status;
@NotEmpty(message = "学历不能为空")
private String education;
}
@@ -15,7 +15,11 @@
<div class="layui-form-item">
<label class="layui-form-label required">部门</label>
<div class="layui-input-inline">
<input class="layui-input" type="text" name="dept_id" placeholder="请输入部门" th:value="${bssEmployee?.dept_id}">
<div class="layui-input-inline">
<select name="bssDept" mo-selected="${dept?.bssPlatform?.id}" mo-empty="" lay-verify="bssDept">
<option th:each="bssDept,userStat:${bssDepts}" th:value="${bssDept.id}" th:text="${bssDept.name}" th:selected="${bssDept.id == bssEmployee?.bssDept?.id}"></option>
</select>
</div>
</div>
</div>
<div class="layui-form-item">
@@ -27,7 +31,7 @@
<div class="layui-form-item">
<label class="layui-form-label required">手机号码</label>
<div class="layui-input-inline">
<input class="layui-input" type="text" name="phone_num" placeholder="请输入手机号码" th:value="${bssEmployee?.phone_num}">
<input class="layui-input" type="text" name="phoneNum" placeholder="请输入手机号码" th:value="${bssEmployee?.phoneNum}">
</div>
</div>
<div class="layui-form-item">
@@ -42,12 +46,6 @@
<input class="layui-input" type="text" name="email" placeholder="请输入邮箱" th:value="${bssEmployee?.email}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">员工状态</label>
<div class="layui-input-inline">
<select name="employeeStatus" mo:dict="EMPLOYEE_TYPE" mo-selected="${bssEmployee?.employeeStatus}" mo-empty="" lay-verify="employeeStatus"></select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">学历</label>
<div class="layui-input-inline">
@@ -32,12 +32,8 @@
<tr>
<th>邮箱</th>
<td th:text="${bssEmployee.email}"></td>
<th>员工状态</th>
<td th:text="${#dicts.keyValue('EMPLOYEE_TYPE', bssEmployee.employeeStatus)}"></td>
</tr>
<tr>
<th>学历</th>
<td th:text="${#dicts.keyValue('EDUCATION', bssEmployee.education)}" colspan="3"></td>
<td th:text="${#dicts.keyValue('EDUCATION', bssEmployee.education)}"></td>
</tr>
<tr>
<th>创建者</th>
@@ -44,6 +44,7 @@
<dd><a class="ajax-status" th:href="@{/bss/employee/status/ok}">启用</a></dd>
<dd><a class="ajax-status" th:href="@{/bss/employee/status/freezed}">冻结</a></dd>
<dd><a class="ajax-status" th:href="@{/bss/employee/status/delete}">删除</a></dd>
<dd><a class="ajax-status" th:href="@{/bss/employee/role}">授权</a></dd>
</dl>
</div>
</div>
@@ -62,7 +63,6 @@
<th>手机号码</th>
<th>身份证号码</th>
<th>邮箱</th>
<th>员工状态</th>
<th>学历</th>
<th>创建时间</th>
<th>更新时间</th>
@@ -80,8 +80,7 @@
<td th:text="${item.phoneNum}">手机号码</td>
<td th:text="${item.card}">身份证号码</td>
<td th:text="${item.email}">邮箱</td>
<td th:text="${#dicts.keyValue('EMPLOYEE_TYPE', item.type)}">员工状态</td>
<td th:text="${#dicts.keyValue('EDUCATION', item.type)}">学历</td>
<td th:text="${#dicts.keyValue('EDUCATION', item.education)}">学历</td>
<td th:text="${#dates.format(item.createDate, 'yyyy-MM-dd HH:mm:ss')}">创建时间</td>
<td th:text="${#dates.format(item.updateDate, 'yyyy-MM-dd HH:mm:ss')}">更新时间</td>
<td th:text="${#dicts.dataStatus(item.status)}">数据状态</td>
@@ -89,6 +88,7 @@
<a class="open-popup" data-title="编辑员工" th:attr="data-url=@{'/bss/employee/edit/'+${item.id}}" data-size="auto" href="#">编辑</a>
<a class="open-popup" data-title="详细信息" th:attr="data-url=@{'/bss/employee/detail/'+${item.id}}" data-size="800,600" href="#">详细</a>
<a class="ajax-get" data-msg="您是否确认删除" th:href="@{/bss/employee/status/delete(ids=${item.id})}">删除</a>
<a class="open-popup" th:href="@{/bss/employee/role}">授权</a>
</td>
</tr>
</tbody>