|
|
@@ -5,7 +5,6 @@ import com.uas.platform.b2b.dao.DistributeDao;
|
|
|
import com.uas.platform.b2b.dao.EnterpriseDao;
|
|
|
import com.uas.platform.b2b.dao.RoleDao;
|
|
|
import com.uas.platform.b2b.dao.UserBaseInfoDao;
|
|
|
-import com.uas.platform.b2b.dao.UserDao;
|
|
|
import com.uas.platform.b2b.dao.VendorContactDao;
|
|
|
import com.uas.platform.b2b.dao.VendorDao;
|
|
|
import com.uas.platform.b2b.dao.VendorDistributeDao;
|
|
|
@@ -48,6 +47,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
|
|
@@ -594,27 +594,38 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
Vendor vendor = vendorDao.findOne(id);
|
|
|
if (!CollectionUtils.isEmpty(users)) {
|
|
|
List<VendorDistribute> saveList = new ArrayList<>();
|
|
|
- for (UserBaseInfo u : users) {
|
|
|
- if (null != u.getUserUU()) {
|
|
|
+ for (UserBaseInfo user : users) {
|
|
|
+ if (null != user.getUserUU()) {
|
|
|
VendorDistribute distribute = new VendorDistribute();
|
|
|
- List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(u.getUserUU(), vendor.getId());
|
|
|
+ List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(user.getUserUU(), vendor.getId());
|
|
|
List<VendorDistribute> transferDistributes = vendorDistributeDao.findByVendorIdAndIsTransfer(id, Constant.YES);
|
|
|
- if (u.isTransfer()) {
|
|
|
+ /*
|
|
|
+ * 根据前端传入的用户绑定信息进行相关判断
|
|
|
+ * 1、 用户分配供应商
|
|
|
+ * a. 不存在绑定记录,新增
|
|
|
+ * b. 存在绑定状态,根据转移是否是当前用户和已分配关系判断
|
|
|
+ * 转移用户不是当前用户设置为当前用,不是已分配状态设置为已分配状态
|
|
|
+ */
|
|
|
+ Long currentUserUU = SystemSession.getUser().getUserUU();
|
|
|
+ if (user.isTransfer()) {
|
|
|
if (CollectionUtils.isEmpty(distributes)) {
|
|
|
- distribute.setUserUU(u.getUserUU());
|
|
|
+ distribute.setUserUU(user.getUserUU());
|
|
|
distribute.setVendorId(vendor.getId());
|
|
|
- distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
+ distribute.setLeaderUU(currentUserUU);
|
|
|
distribute.setIsTransfer(Constant.YES);
|
|
|
saveList.add(distribute);
|
|
|
} else {
|
|
|
distribute = distributes.get(0);
|
|
|
- distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
- distribute.setIsTransfer(Constant.YES);
|
|
|
- saveList.add(distribute);
|
|
|
+ boolean isNotTransfer = null == distribute.getDistribute() || Constant.NO == distribute.getDistribute();
|
|
|
+ if (!Objects.equals(distribute.getLeaderUU(), currentUserUU) || isNotTransfer) {
|
|
|
+ distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
+ distribute.setIsTransfer(Constant.YES);
|
|
|
+ saveList.add(distribute);
|
|
|
+ }
|
|
|
}
|
|
|
// 进行权限转移时判断该用户是否是当前用户,如果不是,去掉当前用户的转移状态
|
|
|
- if (!Objects.equals(u.getUserUU(), SystemSession.getUser().getUserUU())) {
|
|
|
- List<VendorDistribute> currentDistributes = vendorDistributeDao.findByUserUUAndVendorId(SystemSession.getUser().getUserUU(), vendor.getId());
|
|
|
+ if (!Objects.equals(user.getUserUU(), SystemSession.getUser().getUserUU())) {
|
|
|
+ List<VendorDistribute> currentDistributes = vendorDistributeDao.findByUserUUAndVendorId(currentUserUU, vendor.getId());
|
|
|
if (!CollectionUtil.isEmpty(currentDistributes)) {
|
|
|
distribute = currentDistributes.get(0);
|
|
|
distribute.setIsTransfer(Constant.NO);
|
|
|
@@ -622,16 +633,16 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
}
|
|
|
}
|
|
|
// 删除该企业以前转移的用户
|
|
|
- if (!CollectionUtil.isEmpty(transferDistributes) && !Objects.equals(u.getUserUU(), transferDistributes.get(0).getUserUU())) {
|
|
|
+ if (!CollectionUtil.isEmpty(transferDistributes) && !Objects.equals(user.getUserUU(), transferDistributes.get(0).getUserUU())) {
|
|
|
distribute = transferDistributes.get(0);
|
|
|
distribute.setIsTransfer(Constant.NO);
|
|
|
saveList.add(distribute);
|
|
|
}
|
|
|
} else {
|
|
|
- // 删除当前用户的权限子节点用户
|
|
|
+ // 更新分配用户
|
|
|
if (!CollectionUtils.isEmpty(distributes)) {
|
|
|
distribute = distributes.get(0);
|
|
|
- distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
+ distribute.setLeaderUU(currentUserUU);
|
|
|
distribute.setIsTransfer(Constant.NO);
|
|
|
saveList.add(distribute);
|
|
|
}
|
|
|
@@ -655,19 +666,13 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
*/
|
|
|
private void checkAuthority(Long vendId) throws IllegalAccessException {
|
|
|
User user = SystemSession.getUser();
|
|
|
- List<String> roles = new ArrayList<>();
|
|
|
- roles.add(Role.ROLE_ADMIN);
|
|
|
+ List<String> roles = Collections.singletonList(Role.ROLE_ADMIN);
|
|
|
// 查询是否是管理员
|
|
|
Integer count = roleDao.countByEnUUAndUserUU(user.getEnterprise().getUu(), user.getUserUU(), roles);
|
|
|
if (count == 0) {
|
|
|
// 查询是否被转移权限
|
|
|
List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(user.getUserUU(), vendId);
|
|
|
- if (!CollectionUtil.isEmpty(distributes)) {
|
|
|
- VendorDistribute distribute = distributes.get(0);
|
|
|
- if (Constant.NO == distribute.getIsTransfer()) {
|
|
|
- throw new IllegalAccessException("当前用户没有分配或转移的权限");
|
|
|
- }
|
|
|
- } else {
|
|
|
+ if (CollectionUtils.isEmpty(distributes) || Constant.NO == distributes.get(0).getIsTransfer()) {
|
|
|
throw new IllegalAccessException("当前用户没有分配或转移的权限");
|
|
|
}
|
|
|
}
|