业务权限优化
This commit is contained in:
@@ -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;
|
||||
// 备注
|
||||
|
||||
@@ -72,6 +72,7 @@ public class BssPlatform implements Serializable {
|
||||
@JoinColumn(name="update_by")
|
||||
@JsonIgnore
|
||||
private User updateBy;
|
||||
|
||||
// 数据状态
|
||||
private Byte status = StatusEnum.OK.getCode();
|
||||
}
|
||||
+11
@@ -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<BssDept, Long> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据平台ID查询业务部门
|
||||
* @param bssplatform
|
||||
* @return
|
||||
*/
|
||||
List<BssDept> findByBssPlatformEquals(BssPlatform bssplatform);
|
||||
}
|
||||
+2
-1
@@ -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<BssEmployee, Long> {
|
||||
public interface BssEmployeeRepository extends BaseRepository<BssEmployee, Long>, JpaSpecificationExecutor<BssEmployee> {
|
||||
}
|
||||
@@ -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<Long> idList);
|
||||
|
||||
List<BssDept> findBssDeptByBssPlatformAndId(BssPlatform bssplatform);
|
||||
|
||||
List<BssDept> findAll();
|
||||
}
|
||||
+9
@@ -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<BssEmployee> getPageList(Example<BssEmployee> example);
|
||||
|
||||
/**
|
||||
* 复杂查询sql
|
||||
* @param depts
|
||||
* @param bssEmployee
|
||||
* @return
|
||||
*/
|
||||
Page<BssEmployee> getPageList(List<BssDept> depts,BssEmployee bssEmployee);
|
||||
|
||||
/**
|
||||
* 根据ID查询数据
|
||||
* @param id 主键ID
|
||||
|
||||
+11
@@ -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<Long> idList) {
|
||||
return bssDeptRepository.updateStatus(statusEnum.getCode(), idList) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BssDept> findBssDeptByBssPlatformAndId(BssPlatform bssplatform) {
|
||||
return bssDeptRepository.findByBssPlatformEquals(bssplatform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BssDept> findAll() {
|
||||
return bssDeptRepository.findAll();
|
||||
}
|
||||
}
|
||||
+46
@@ -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<BssEmployee> getPageList(List<BssDept> depts, BssEmployee bssEmployee) {
|
||||
// 创建分页对象
|
||||
PageRequest page = PageSort.pageRequest(Sort.Direction.ASC);
|
||||
// 使用Specification复杂查询
|
||||
return bssEmployeeRepository.findAll(new Specification<BssEmployee>(){
|
||||
|
||||
@Override
|
||||
public Predicate toPredicate(Root<BssEmployee> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
||||
List<Predicate> preList = new ArrayList<>();
|
||||
if(null != depts && depts.size() > 0){
|
||||
|
||||
List<Long> deptIn = new ArrayList<>();
|
||||
depts.forEach(item -> deptIn.add(item.getId()));
|
||||
|
||||
Join<BssEmployee, BssDept> join = root.join("bssDept", JoinType.INNER);
|
||||
CriteriaBuilder.In<Long> 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 实体对象
|
||||
|
||||
+1
-23
@@ -82,15 +82,6 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
||||
List<Predicate> 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<Long> bssPlatformIn = new ArrayList<>();
|
||||
bssPlatformIn.add(bssPlatform.getId());
|
||||
List<BssPlatform> bssPlatforms = bssPlatformRepository.findAll();
|
||||
bssPlatforms.forEach(item -> bssPlatformIn.add(item.getId()));
|
||||
|
||||
Join<User, BssPlatform> join = root.join("bssPlatform", JoinType.INNER);
|
||||
CriteriaBuilder.In<Long> 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<User, BssPlatform> join = root.join("bssPlatform", JoinType.INNER);
|
||||
Predicate eq = cb.equal(join.get("id").as(Long.class),bssPlatform.getId());
|
||||
|
||||
Reference in New Issue
Block a user