From 5535ae1ce0d4e08a51b6b31745a5c7f8b1af2dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=84=B1?= Date: Fri, 2 Aug 2019 01:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=9D=83=E9=99=90=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BssDeptController.java | 12 ++++- .../controller/BssEmployeeController.java | 51 ++++++++++++++++--- .../controller/BssPlatformController.java | 9 +++- .../business/validator/BssEmployeeValid.java | 7 ++- .../templates/business/employee/add.html | 14 +++-- .../templates/business/employee/detail.html | 6 +-- .../templates/business/employee/index.html | 6 +-- .../modules/business/domain/BssEmployee.java | 3 -- .../modules/business/domain/BssPlatform.java | 1 + .../repository/BssDeptRepository.java | 11 ++++ .../repository/BssEmployeeRepository.java | 3 +- .../business/service/BssDeptService.java | 5 ++ .../business/service/BssEmployeeService.java | 9 ++++ .../service/impl/BssDeptServiceImpl.java | 11 ++++ .../service/impl/BssEmployeeServiceImpl.java | 46 +++++++++++++++++ .../system/service/impl/UserServiceImpl.java | 24 +-------- 16 files changed, 160 insertions(+), 58 deletions(-) diff --git a/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java b/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java index 63c43c0..9063137 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java +++ b/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java @@ -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 example = Example.of(bssDept, matcher); Page list = bssDeptService.getPageList(example); diff --git a/admin/src/main/java/com/cwhelp/admin/business/controller/BssEmployeeController.java b/admin/src/main/java/com/cwhelp/admin/business/controller/BssEmployeeController.java index 0aad981..78586ce 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/controller/BssEmployeeController.java +++ b/admin/src/main/java/com/cwhelp/admin/business/controller/BssEmployeeController.java @@ -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 example = Example.of(bssEmployee, matcher); - Page list = bssEmployeeService.getPageList(example); + User user = ShiroUtil.getSubject(); + List bssDepts = null; + if (1 != user.getBssPlatform().getId()) { + bssDepts = bssDeptService.findBssDeptByBssPlatformAndId(user.getBssPlatform()); + } + Page 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 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 bssDepts = getBssDepts(user, bssPlatform); + model.addAttribute("bssDepts",bssDepts); model.addAttribute("bssEmployee", bssEmployee); return "/business/employee/add"; } + /** + * 获取当前用户下的部门 + * @param user + * @param bssPlatform + * @return + */ + private List getBssDepts(User user, BssPlatform bssPlatform) { + List bssDepts = null; + if (1 != user.getBssPlatform().getId()) { + bssDepts = bssDeptService.findBssDeptByBssPlatformAndId(bssPlatform); + } else { + bssDepts = bssDeptService.findAll(); + } + return bssDepts; + } + /** * 保存添加/修改的数据 * @param valid 验证对象 diff --git a/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java b/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java index f4ba1e3..2061584 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java +++ b/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java @@ -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 example = Example.of(bssPlatform, matcher); Page list = bssPlatformService.getPageList(example); diff --git a/admin/src/main/java/com/cwhelp/admin/business/validator/BssEmployeeValid.java b/admin/src/main/java/com/cwhelp/admin/business/validator/BssEmployeeValid.java index 4bf6b40..5d26fc8 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/validator/BssEmployeeValid.java +++ b/admin/src/main/java/com/cwhelp/admin/business/validator/BssEmployeeValid.java @@ -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; } \ No newline at end of file diff --git a/admin/src/main/resources/templates/business/employee/add.html b/admin/src/main/resources/templates/business/employee/add.html index 9a3feea..b40e134 100644 --- a/admin/src/main/resources/templates/business/employee/add.html +++ b/admin/src/main/resources/templates/business/employee/add.html @@ -15,7 +15,11 @@
- +
+ +
@@ -27,7 +31,7 @@
- +
@@ -42,12 +46,6 @@
-
- -
- -
-
diff --git a/admin/src/main/resources/templates/business/employee/detail.html b/admin/src/main/resources/templates/business/employee/detail.html index 1614865..f1a6a7b 100644 --- a/admin/src/main/resources/templates/business/employee/detail.html +++ b/admin/src/main/resources/templates/business/employee/detail.html @@ -32,12 +32,8 @@ 邮箱 - 员工状态 - - - 学历 - + 创建者 diff --git a/admin/src/main/resources/templates/business/employee/index.html b/admin/src/main/resources/templates/business/employee/index.html index a03fb93..2aa5ae0 100644 --- a/admin/src/main/resources/templates/business/employee/index.html +++ b/admin/src/main/resources/templates/business/employee/index.html @@ -44,6 +44,7 @@
启用
冻结
删除
+
授权
@@ -62,7 +63,6 @@ 手机号码 身份证号码 邮箱 - 员工状态 学历 创建时间 更新时间 @@ -80,8 +80,7 @@ 手机号码 身份证号码 邮箱 - 员工状态 - 学历 + 学历 创建时间 更新时间 数据状态 @@ -89,6 +88,7 @@ 编辑 详细 删除 + 授权 diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssEmployee.java b/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssEmployee.java index dbc47b4..7e4df02 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssEmployee.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssEmployee.java @@ -49,9 +49,6 @@ public class BssEmployee implements Serializable { private String card; // 邮箱 private String email; - // 员工状态 - @Column(name = "employee_status") - private String employeeStatus; // 学历 private String education; // 备注 diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java b/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java index 455c539..4e8293c 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java @@ -72,6 +72,7 @@ public class BssPlatform implements Serializable { @JoinColumn(name="update_by") @JsonIgnore private User updateBy; + // 数据状态 private Byte status = StatusEnum.OK.getCode(); } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssDeptRepository.java b/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssDeptRepository.java index 9d9d899..a6b7fcd 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssDeptRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssDeptRepository.java @@ -1,12 +1,23 @@ package com.cwhelp.modules.business.repository; import com.cwhelp.modules.business.domain.BssDept; +import com.cwhelp.modules.business.domain.BssPlatform; import com.cwhelp.modules.system.repository.BaseRepository; +import java.util.List; + /** * @author yan.y * @date 2019/07/29 */ public interface BssDeptRepository extends BaseRepository { + + + /** + * 根据平台ID查询业务部门 + * @param bssplatform + * @return + */ + List findByBssPlatformEquals(BssPlatform bssplatform); } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssEmployeeRepository.java b/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssEmployeeRepository.java index e8de8ea..fd0ff12 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssEmployeeRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/repository/BssEmployeeRepository.java @@ -2,11 +2,12 @@ package com.cwhelp.modules.business.repository; import com.cwhelp.modules.business.domain.BssEmployee; import com.cwhelp.modules.system.repository.BaseRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; /** * @author yan.y * @date 2019/07/31 */ -public interface BssEmployeeRepository extends BaseRepository { +public interface BssEmployeeRepository extends BaseRepository, JpaSpecificationExecutor { } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/service/BssDeptService.java b/modules/system/src/main/java/com/cwhelp/modules/business/service/BssDeptService.java index 6a3ce1a..0c4c3bb 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/service/BssDeptService.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/service/BssDeptService.java @@ -2,6 +2,7 @@ package com.cwhelp.modules.business.service; import com.cwhelp.common.enums.StatusEnum; import com.cwhelp.modules.business.domain.BssDept; +import com.cwhelp.modules.business.domain.BssPlatform; import org.springframework.data.domain.Example; import org.springframework.data.domain.Page; import org.springframework.transaction.annotation.Transactional; @@ -38,4 +39,8 @@ public interface BssDeptService { */ @Transactional Boolean updateStatus(StatusEnum statusEnum, List idList); + + List findBssDeptByBssPlatformAndId(BssPlatform bssplatform); + + List findAll(); } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/service/BssEmployeeService.java b/modules/system/src/main/java/com/cwhelp/modules/business/service/BssEmployeeService.java index b4ab88f..54981df 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/service/BssEmployeeService.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/service/BssEmployeeService.java @@ -1,6 +1,7 @@ package com.cwhelp.modules.business.service; import com.cwhelp.common.enums.StatusEnum; +import com.cwhelp.modules.business.domain.BssDept; import com.cwhelp.modules.business.domain.BssEmployee; import org.springframework.data.domain.Example; import org.springframework.data.domain.Page; @@ -22,6 +23,14 @@ public interface BssEmployeeService { */ Page getPageList(Example example); + /** + * 复杂查询sql + * @param depts + * @param bssEmployee + * @return + */ + Page getPageList(List depts,BssEmployee bssEmployee); + /** * 根据ID查询数据 * @param id 主键ID diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssDeptServiceImpl.java b/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssDeptServiceImpl.java index 97611ea..a4ba385 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssDeptServiceImpl.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssDeptServiceImpl.java @@ -3,6 +3,7 @@ package com.cwhelp.modules.business.service.impl; import com.cwhelp.common.data.PageSort; import com.cwhelp.common.enums.StatusEnum; import com.cwhelp.modules.business.domain.BssDept; +import com.cwhelp.modules.business.domain.BssPlatform; import com.cwhelp.modules.business.repository.BssDeptRepository; import com.cwhelp.modules.business.service.BssDeptService; import org.springframework.beans.factory.annotation.Autowired; @@ -63,4 +64,14 @@ public class BssDeptServiceImpl implements BssDeptService { public Boolean updateStatus(StatusEnum statusEnum, List idList) { return bssDeptRepository.updateStatus(statusEnum.getCode(), idList) > 0; } + + @Override + public List findBssDeptByBssPlatformAndId(BssPlatform bssplatform) { + return bssDeptRepository.findByBssPlatformEquals(bssplatform); + } + + @Override + public List findAll() { + return bssDeptRepository.findAll(); + } } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssEmployeeServiceImpl.java b/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssEmployeeServiceImpl.java index ce2f1e5..2b7ece0 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssEmployeeServiceImpl.java +++ b/modules/system/src/main/java/com/cwhelp/modules/business/service/impl/BssEmployeeServiceImpl.java @@ -2,16 +2,23 @@ package com.cwhelp.modules.business.service.impl; import com.cwhelp.common.data.PageSort; import com.cwhelp.common.enums.StatusEnum; +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.repository.BssEmployeeRepository; import com.cwhelp.modules.business.service.BssEmployeeService; +import com.cwhelp.modules.system.domain.Dept; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Example; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.persistence.criteria.*; +import java.util.ArrayList; import java.util.List; /** @@ -46,6 +53,45 @@ public class BssEmployeeServiceImpl implements BssEmployeeService { return bssEmployeeRepository.findAll(example, page); } + @Override + public Page getPageList(List depts, BssEmployee bssEmployee) { + // 创建分页对象 + PageRequest page = PageSort.pageRequest(Sort.Direction.ASC); + // 使用Specification复杂查询 + return bssEmployeeRepository.findAll(new Specification(){ + + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { + List preList = new ArrayList<>(); + if(null != depts && depts.size() > 0){ + + List deptIn = new ArrayList<>(); + depts.forEach(item -> deptIn.add(item.getId())); + + Join join = root.join("bssDept", JoinType.INNER); + CriteriaBuilder.In in = cb.in(join.get("id").as(Long.class)); + deptIn.forEach(in::value); + preList.add(in); + } + // 名称 + if(bssEmployee.getName() != null){ + preList.add(cb.like(root.get("name").as(String.class), "%" + bssEmployee.getName() + "%")); + } + // 号码 + if(bssEmployee.getPhoneNum() != null){ + preList.add(cb.like(root.get("phoneNum").as(String.class), "%" + bssEmployee.getPhoneNum() + "%")); + } + // 数据状态 + if(bssEmployee.getStatus() != null){ + preList.add(cb.equal(root.get("status").as(Byte.class), bssEmployee.getStatus())); + } + Predicate[] pres = new Predicate[preList.size()]; + return query.where(preList.toArray(pres)).getRestriction(); + } + + }, page); + } + /** * 保存数据 * @param bssEmployee 实体对象 diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/service/impl/UserServiceImpl.java b/modules/system/src/main/java/com/cwhelp/modules/system/service/impl/UserServiceImpl.java index 7da97e9..fca61f9 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/service/impl/UserServiceImpl.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/service/impl/UserServiceImpl.java @@ -82,15 +82,6 @@ public class UserServiceImpl implements UserService { @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { List preList = new ArrayList<>(); - if(user.getId() != null){ - preList.add(cb.equal(root.get("id").as(Long.class), user.getId())); - } - if(user.getUsername() != null){ - preList.add(cb.equal(root.get("username").as(String.class), user.getUsername())); - } - if(user.getNickname() != null){ - preList.add(cb.like(root.get("nickname").as(String.class), "%"+ user.getNickname() + "%")); - } if(user.getDept() != null){ // 联级查询部门 Dept dept = user.getDept(); @@ -105,20 +96,7 @@ public class UserServiceImpl implements UserService { preList.add(in); } // 1 为财务帮平台超级账号 - if (1 == user.getBssPlatform().getId()) { - // 查询所有平台的账号 - BssPlatform bssPlatform = user.getBssPlatform(); - List bssPlatformIn = new ArrayList<>(); - bssPlatformIn.add(bssPlatform.getId()); - List bssPlatforms = bssPlatformRepository.findAll(); - bssPlatforms.forEach(item -> bssPlatformIn.add(item.getId())); - - Join join = root.join("bssPlatform", JoinType.INNER); - CriteriaBuilder.In in = cb.in(join.get("id").as(Long.class)); - bssPlatformIn.forEach(in::value); - preList.add(in); - } else { - // 查询所有平台的账号 + if (1 != user.getBssPlatform().getId()) { BssPlatform bssPlatform = user.getBssPlatform(); Join join = root.join("bssPlatform", JoinType.INNER); Predicate eq = cb.equal(join.get("id").as(Long.class),bssPlatform.getId());