|
|
@@ -506,22 +506,46 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
@Override
|
|
|
public boolean bindVendorToUser(Long userUU, List<Vendor> vendors) {
|
|
|
if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
+ List<VendorDistribute> needSaveOrUpdateList = new ArrayList<>();
|
|
|
+ List<VendorDistribute> needDeleteList = new ArrayList<>();
|
|
|
for (Vendor vendor : vendors) {
|
|
|
- Distribute distribute = new Distribute();
|
|
|
+ VendorDistribute distribute = new VendorDistribute();
|
|
|
if (vendor.getDistribute()) {
|
|
|
List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(userUU, vendor.getId());
|
|
|
if (CollectionUtils.isEmpty(distributes)) {
|
|
|
distribute.setUserUU(userUU);
|
|
|
distribute.setVendorId(vendor.getId());
|
|
|
- distributeDao.save(distribute);
|
|
|
+ distribute.setDistribute(Constant.YES);
|
|
|
+ needSaveOrUpdateList.add(distribute);
|
|
|
+ } else {
|
|
|
+ distribute = distributes.get(0);
|
|
|
+ distribute.setDistribute(Constant.YES);
|
|
|
+ needSaveOrUpdateList.add(distribute);
|
|
|
}
|
|
|
} else {
|
|
|
- List<Distribute> distributes = distributeDao.findByUserUUAndVendorId(userUU, vendor.getId());
|
|
|
+ List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(userUU, vendor.getId());
|
|
|
if (!CollectionUtils.isEmpty(distributes)) {
|
|
|
- distributeDao.delete(distributes.get(0));
|
|
|
+ /*
|
|
|
+ * 判断分配和权限转移关系
|
|
|
+ * 1、只存在分配关系,取消分配直接删除
|
|
|
+ * 2、存在权限转移,将分配关系取消即可
|
|
|
+ */
|
|
|
+ distribute = distributes.get(0);
|
|
|
+ if (Constant.YES == distribute.getIsTransfer()) {
|
|
|
+ distribute.setDistribute(Constant.NO);
|
|
|
+ needSaveOrUpdateList.add(distribute);
|
|
|
+ } else {
|
|
|
+ needDeleteList.add(distribute);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (!CollectionUtil.isEmpty(needSaveOrUpdateList)) {
|
|
|
+ vendorDistributeDao.save(needSaveOrUpdateList);
|
|
|
+ }
|
|
|
+ if (!CollectionUtil.isEmpty(needDeleteList)) {
|
|
|
+ vendorDistributeDao.delete(needDeleteList);
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -543,22 +567,28 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
List<VendorDistribute> deleteList = new ArrayList<>();
|
|
|
if (null != u.getUserUU()) {
|
|
|
VendorDistribute distribute = new VendorDistribute();
|
|
|
- List<VendorDistribute> butes = vendorDistributeDao.findByUserUUAndVendorId(u.getUserUU(), vendors.get(0).getId());
|
|
|
- if (u.getDistribute()) {
|
|
|
- if (CollectionUtils.isEmpty(butes)) {
|
|
|
+ List<VendorDistribute> distributes = vendorDistributeDao.findByUserUUAndVendorId(u.getUserUU(), vendors.get(0).getId());
|
|
|
+ if (u.getTransfer()) {
|
|
|
+ if (CollectionUtils.isEmpty(distributes)) {
|
|
|
distribute.setUserUU(u.getUserUU());
|
|
|
distribute.setVendorId(vendors.get(0).getId());
|
|
|
distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
+ distribute.setIsTransfer(Constant.YES);
|
|
|
+ saveList.add(distribute);
|
|
|
+ } else {
|
|
|
+ distribute = distributes.get(0);
|
|
|
+ distribute.setLeaderUU(SystemSession.getUser().getUserUU());
|
|
|
+ distribute.setIsTransfer(Constant.YES);
|
|
|
saveList.add(distribute);
|
|
|
}
|
|
|
} else {
|
|
|
// 删除当前用户的权限子节点用户
|
|
|
- if (!CollectionUtils.isEmpty(butes)) {
|
|
|
+ if (!CollectionUtils.isEmpty(distributes)) {
|
|
|
// 当前用户
|
|
|
- deleteList.add(butes.get(0));
|
|
|
+ deleteList.add(distributes.get(0));
|
|
|
Long vendorId = vendors.get(0).getId();
|
|
|
Long userUU = u.getUserUU();
|
|
|
- if (null != butes.get(0).getIsTransfer() && 1 == butes.get(0).getIsTransfer()) {
|
|
|
+ if (null != distributes.get(0).getIsTransfer() && 1 == distributes.get(0).getIsTransfer()) {
|
|
|
deleteList = deleteChildrenDistributes(vendorId, userUU, deleteList);
|
|
|
}
|
|
|
// 防止出现作为参数的用户之间存在权限父子节点关系,导致重复查询,所以每次递归完成,执行一次删除
|
|
|
@@ -608,7 +638,9 @@ public class VendorsServiceImpl implements VendorService {
|
|
|
users.forEach(user -> {
|
|
|
distributes.forEach(distribute -> {
|
|
|
if (user.getUserUU().equals(distribute.getUserUU())) {
|
|
|
- user.setDistribute(true);
|
|
|
+ if (Constant.YES == distribute.getDistribute()) {
|
|
|
+ user.setDistribute(true);
|
|
|
+ }
|
|
|
if (null != distribute.getIsTransfer() && Constant.YES == distribute.getIsTransfer()) {
|
|
|
user.setTransfer(true);
|
|
|
}
|