package com.lxzn.nc.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.lxzn.auth.JwtUtil;
|
import com.lxzn.framework.domain.nc.*;
|
import com.lxzn.framework.domain.nc.ext.ComponentExt;
|
import com.lxzn.framework.domain.nc.response.ComponentInfoCode;
|
import com.lxzn.framework.domain.nc.response.PartsInfoCode;
|
import com.lxzn.framework.domain.nc.response.ProductInfoCode;
|
import com.lxzn.framework.domain.ucenter.Department;
|
import com.lxzn.framework.domain.ucenter.User;
|
import com.lxzn.framework.domain.ucenter.ext.UserDepartExt;
|
import com.lxzn.framework.domain.ucenter.response.UcenterCode;
|
import com.lxzn.framework.exception.ExceptionCast;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.model.response.CommonGenericTree;
|
import com.lxzn.framework.utils.UserIdUtil;
|
import com.lxzn.framework.utils.ValidateUtil;
|
import com.lxzn.nc.dao.ProductInfoMapper;
|
import com.lxzn.nc.service.*;
|
import com.lxzn.nc.service.support.ProductTreeWrapper;
|
import com.lxzn.ucenter.service.IDepartmentService;
|
import com.lxzn.ucenter.service.IUserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.Collection;
|
import java.util.Collections;
|
import java.util.List;
|
|
@Service
|
public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper,ProductInfo> implements IProductInfoService {
|
@Autowired
|
private IComponentInfoService componentInfoService;
|
@Autowired
|
private IPartsInfoService partsInfoService;
|
@Autowired
|
private IProductPermissionService productPermissionService;
|
@Autowired
|
private IProductDepartmentService productDepartmentService;
|
@Autowired
|
private IPermissionStreamService permissionStreamService;
|
@Autowired
|
private IComponentDepartmentService componentDepartmentService;
|
@Autowired
|
private IComponentPermissionService componentPermissionService;
|
@Autowired
|
private IPartsDepartmentService partsDepartmentService;
|
@Autowired
|
private IPartsPermissionService partsPermissionService;
|
@Autowired
|
private IDepartmentService departmentService;
|
@Autowired
|
private IUserService userService;
|
@Autowired
|
private IProcessStreamService processStreamService;
|
@Autowired
|
private IDocInfoService docInfoService;
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean addProductInfo(ProductInfo productInfo) {
|
if(productInfo == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(!ValidateUtil.validateString(productInfo.getProductName()))
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NAME_NONE);
|
if(!ValidateUtil.validateString(productInfo.getProductNo())) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NO_NONE);
|
}
|
ProductInfo en = getByProductNo(productInfo.getProductNo());
|
if(en != null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_IS_EXIST);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
productInfo.setProductStatus(1);
|
boolean b = super.save(productInfo);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
|
}
|
ProductPermission permission = new ProductPermission();
|
permission.setProductId(productInfo.getProductId());
|
permission.setUserId(userId);
|
b = productPermissionService.save(permission);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
|
}
|
PermissionStream stream = new PermissionStream();
|
stream.setProductId(productInfo.getProductId());
|
stream.setUserId(userId);
|
return permissionStreamService.save(stream);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean editProductInfo(String id ,ProductInfo productInfo) {
|
if(!ValidateUtil.validateString(id) || productInfo == null)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
ProductInfo en = super.getById(id);
|
if(en == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
productInfo.setProductId(id);
|
productInfo.setProductStatus(null);
|
boolean b = super.updateById(productInfo);
|
if(!b)
|
return false;
|
ProductPermission permission = productPermissionService.getByProductIdAndUserId(id, userId);
|
if(permission == null) {
|
permission = new ProductPermission();
|
permission.setProductId(id);
|
permission.setUserId(userId);
|
b = productPermissionService.save(permission);
|
if(!b) {
|
return false;
|
}
|
}
|
PermissionStream stream = permissionStreamService.getByProductIdAndUserId(id, userId);
|
if(stream == null) {
|
stream = new PermissionStream();
|
stream.setProductId(id);
|
stream.setUserId(userId);
|
return permissionStreamService.save(stream);
|
}
|
return b;
|
}
|
|
@Override
|
public List<CommonGenericTree> loadProductTree(String userId) {
|
if (UserIdUtil.selectUserIdAdmin().equals(userId)) {
|
List<ProductInfo> productInfoList = super.list();
|
if(productInfoList == null || productInfoList.isEmpty())
|
return Collections.emptyList();
|
//bug
|
//List<ComponentExt> componentInfoList = componentInfoService.getByListComp();
|
List<ComponentExt> componentInfoList = componentInfoService.getByListCompAll();
|
if(componentInfoList == null)
|
componentInfoList = Collections.emptyList();
|
List<PartsInfo> partsInfos = partsInfoService.list();
|
if(partsInfos == null)
|
partsInfos = Collections.emptyList();
|
return ProductTreeWrapper.loadTree(productInfoList, componentInfoList, partsInfos);
|
}
|
List<ProductInfo> productInfoList = getByUserPerms(userId);
|
if(productInfoList == null || productInfoList.isEmpty())
|
return Collections.emptyList();
|
List<ComponentExt> componentInfoList = componentInfoService.getByUserPermsAs(userId);
|
if(componentInfoList == null)
|
componentInfoList = Collections.emptyList();
|
List<PartsInfo> partsInfos = partsInfoService.getByUserPerms(userId);
|
if(partsInfos == null)
|
partsInfos = Collections.emptyList();
|
return ProductTreeWrapper.loadTree(productInfoList, componentInfoList, partsInfos);
|
}
|
|
@Override
|
public List<ProductInfo> getByUserPerms(String userId) {
|
if(!ValidateUtil.validateString(userId))
|
return Collections.emptyList();
|
return super.getBaseMapper().getByUserPerms(userId);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteProductInfo(String id) {
|
if(!ValidateUtil.validateString(id))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
ProductInfo productInfo = super.getById(id);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
//验证产品下是否有部件
|
List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
|
if(componentInfoList != null && !componentInfoList.isEmpty()) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_COMPONENT_EXIST);
|
}
|
//验证产品下是否有零件
|
List<PartsInfo> partsInfoList = partsInfoService.getByProductId(productInfo.getProductId());
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_PARTS_EXIST);
|
}
|
List<ProcessStream> processStreams = processStreamService.findByProductId(id);
|
if(processStreams != null && !processStreams.isEmpty())
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_PROCESS_EXIST);
|
boolean b = productPermissionService.deleteByProductId(id);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
b = productDepartmentService.deleteByProductId(id);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
b = permissionStreamService.deleteUserPermsByProductId(id);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
b = permissionStreamService.deleteDepartPermsByProductId(id);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
b = docInfoService.deleteByProductId(id);
|
if(!b)
|
ExceptionCast.cast(CommonCode.FAIL);
|
return super.removeById(id);
|
}
|
|
@Override
|
public boolean checkProductPerm(Integer nodeType, String paramId) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
|
if(nodeType == 1) {
|
ProductInfo productInfo = super.getById(paramId);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
PermissionStream permission = permissionStreamService.getByProductIdAndUserId(paramId, userId);
|
if(permission == null)
|
return false;
|
return true;
|
}else if(nodeType == 2) {
|
ComponentInfo componentInfo = componentInfoService.getById(paramId);
|
if(componentInfo == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
|
PermissionStream permission = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), paramId, userId);
|
if(permission == null)
|
return false;
|
return true;
|
}else if(nodeType == 3) {
|
PartsInfo partsInfo = partsInfoService.getById(paramId);
|
if(partsInfo == null)
|
ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
|
PermissionStream permission = permissionStreamService.getByPartsIdAndUserId(partsInfo.getProductId(), partsInfo.getComponentId(), paramId, userId);
|
if(permission == null)
|
return false;
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
public List<UserDepartExt> getUserPermsList(Integer nodeType, String paramId) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
|
return null;
|
if(nodeType == 1) {
|
return productPermissionService.getUserPermsByProductId(paramId);
|
}else if(nodeType == 2) {
|
return componentPermissionService.getUserPermsByComponentId(paramId);
|
}else if(nodeType == 3) {
|
return partsPermissionService.getUserPermsByProductId(paramId);
|
}else {
|
return null;
|
}
|
}
|
|
@Override
|
public List<User> getUserNonPermsList(Integer nodeType, String paramId) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
|
return null;
|
if(nodeType == 1) {
|
return productPermissionService.getUserNonPermsByProductId(paramId);
|
}else if(nodeType == 2) {
|
return componentPermissionService.getUserNonPermsByComponentId(paramId);
|
}else if(nodeType == 3) {
|
return partsPermissionService.getUserNonPermsByProductId(paramId);
|
}else {
|
return null;
|
}
|
}
|
|
@Override
|
public List<Department> getDepartPermsList(Integer nodeType, String paramId) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
|
return null;
|
if(nodeType == 1) {
|
return productDepartmentService.getDepartPermsByProductId(paramId);
|
}else if(nodeType == 2) {
|
return componentDepartmentService.getDepartPermsByComponentId(paramId);
|
}else if(nodeType == 3) {
|
return partsDepartmentService.getDepartPermsByPartsId(paramId);
|
}else {
|
return null;
|
}
|
}
|
|
@Override
|
public List<Department> getDepartNonPermsList(Integer nodeType, String paramId) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
|
return null;
|
if(nodeType == 1) {
|
return productDepartmentService.getDepartNonPermsByProductId(paramId);
|
}else if(nodeType == 2) {
|
return componentDepartmentService.getDepartNonPermsByComponentId(paramId);
|
}else if(nodeType == 3) {
|
return partsDepartmentService.getDepartNonPermsByProductId(paramId);
|
}else {
|
return null;
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignAddUser(Integer nodeType, String paramId, Integer relativeFlag, String[] userIds) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId) ||
|
!ValidateUtil.validateInteger(relativeFlag))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(userIds == null || userIds.length < 1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
|
List<String> ids = new ArrayList<>(userIds.length);
|
Collections.addAll(ids, userIds);
|
Collection<User> userList = userService.listByIds(ids);
|
if(userList == null || userList.isEmpty() || userList.size() != userIds.length)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(nodeType == 3) {
|
//处理零件
|
PartsInfo partsInfo = partsInfoService.getById(paramId);
|
if(partsInfo == null)
|
ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
|
boolean b = checkProductPerm(3, partsInfo.getPartsId());
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
return partsInfoService.assignAddUser(partsInfo, userList);
|
}else if(nodeType == 1) {
|
//处理产品
|
ProductInfo productInfo = super.getById(paramId);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
boolean b1 = checkProductPerm(1, productInfo.getProductId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = this.assignAddUser(productInfo, userList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
//处理产品 下的部件
|
List<String> componentIds = new ArrayList<>();
|
List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
|
if(componentInfoList != null && !componentInfoList.isEmpty()) {
|
componentInfoList.forEach(item -> {
|
componentIds.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignAddUser(item, userList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
|
//处理产品 下的零件
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productInfo.getProductId(), componentIds);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignAddUser(item, userList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
}
|
return true;
|
}else if(nodeType == 2) {
|
ComponentInfo componentInfo = componentInfoService.getById(paramId);
|
if(componentInfo == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
|
boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = componentInfoService.assignAddUser(componentInfo, userList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
List<String> componentIdList = new ArrayList<>();
|
componentIdList.add(componentInfo.getComponentId());
|
List<ComponentInfo> childrenList = componentInfoService.getByParentId(componentInfo.getComponentId());
|
if(childrenList != null && !childrenList.isEmpty()) {
|
childrenList.forEach(item -> {
|
componentIdList.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignAddUser(item, userList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(componentInfo.getProductId(), componentIdList);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignAddUser(item, userList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
}
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignRemoveUser(Integer nodeType, String paramId, Integer relativeFlag, String[] userIds) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId) ||
|
!ValidateUtil.validateInteger(relativeFlag))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(userIds == null || userIds.length < 1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
|
List<String> ids = new ArrayList<>(userIds.length);
|
Collections.addAll(ids, userIds);
|
Collection<User> userList = userService.listByIds(ids);
|
if(userList == null || userList.isEmpty() || userList.size() != userIds.length)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(nodeType == 3) {
|
//处理零件
|
PartsInfo partsInfo = partsInfoService.getById(paramId);
|
if(partsInfo == null)
|
ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
|
boolean b = checkProductPerm(3, partsInfo.getPartsId());
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
return partsInfoService.assignRemoveUser(partsInfo, userList);
|
}else if(nodeType == 1) {
|
//处理产品
|
ProductInfo productInfo = super.getById(paramId);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
boolean b1 = checkProductPerm(1, productInfo.getProductId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = this.assignRemoveUser(productInfo, userList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
//处理产品 下的部件
|
List<String> componentIds = new ArrayList<>();
|
List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
|
if(componentInfoList != null && !componentInfoList.isEmpty()) {
|
componentInfoList.forEach(item -> {
|
componentIds.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignRemoveUser(item, userList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
|
//处理产品 下的零件
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productInfo.getProductId(), componentIds);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignRemoveUser(item, userList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
}
|
return true;
|
}else if(nodeType == 2) {
|
ComponentInfo componentInfo = componentInfoService.getById(paramId);
|
if(componentInfo == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
|
boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = componentInfoService.assignRemoveUser(componentInfo, userList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
List<String> componentIdList = new ArrayList<>();
|
componentIdList.add(componentInfo.getComponentId());
|
List<ComponentInfo> childrenList = componentInfoService.getByParentId(componentInfo.getComponentId());
|
if(childrenList != null && !childrenList.isEmpty()) {
|
childrenList.forEach(item -> {
|
componentIdList.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignRemoveUser(item, userList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(componentInfo.getProductId(), componentIdList);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignRemoveUser(item, userList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
}
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignAddDepartment(Integer nodeType, String paramId, Integer relativeFlag, String[] departmentIds) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId) ||
|
!ValidateUtil.validateInteger(relativeFlag))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(departmentIds == null || departmentIds.length < 1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
|
List<String> ids = new ArrayList<>(departmentIds.length);
|
Collections.addAll(ids, departmentIds);
|
Collection<Department> departList = departmentService.listByIds(ids);
|
if(departList == null || departList.isEmpty() || departList.size() != departmentIds.length)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(nodeType == 3) {
|
//处理零件
|
PartsInfo partsInfo = partsInfoService.getById(paramId);
|
if(partsInfo == null)
|
ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
|
boolean b = checkProductPerm(3, partsInfo.getPartsId());
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
return partsInfoService.assignAddDepart(partsInfo, departList);
|
}else if(nodeType == 1) {
|
//处理产品
|
ProductInfo productInfo = super.getById(paramId);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
boolean b1 = checkProductPerm(1, productInfo.getProductId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = this.assignAddDepartment(productInfo, departList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
//处理产品 下的部件
|
List<String> componentIds = new ArrayList<>();
|
List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
|
if(componentInfoList != null && !componentInfoList.isEmpty()) {
|
componentInfoList.forEach(item -> {
|
componentIds.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignAddDepart(item, departList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
|
//处理产品 下的零件
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productInfo.getProductId(), componentIds);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignAddDepart(item, departList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
}
|
return true;
|
}else if(nodeType == 2) {
|
ComponentInfo componentInfo = componentInfoService.getById(paramId);
|
if(componentInfo == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
|
boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = componentInfoService.assignAddDepart(componentInfo, departList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
List<String> componentIdList = new ArrayList<>();
|
componentIdList.add(componentInfo.getComponentId());
|
List<ComponentInfo> childrenList = componentInfoService.getByParentId(componentInfo.getComponentId());
|
if(childrenList != null && !childrenList.isEmpty()) {
|
childrenList.forEach(item -> {
|
componentIdList.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignAddDepart(item, departList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(componentInfo.getProductId(), componentIdList);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignAddDepart(item, departList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
}
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignRemoveDepartment(Integer nodeType, String paramId, Integer relativeFlag, String[] departmentIds) {
|
if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId) ||
|
!ValidateUtil.validateInteger(relativeFlag))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(departmentIds == null || departmentIds.length < 1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
|
List<String> ids = new ArrayList<>(departmentIds.length);
|
Collections.addAll(ids, departmentIds);
|
Collection<Department> departList = departmentService.listByIds(ids);
|
if(departList == null || departList.isEmpty() || departList.size() != departmentIds.length)
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
if(nodeType == 3) {
|
//处理零件
|
PartsInfo partsInfo = partsInfoService.getById(paramId);
|
if(partsInfo == null)
|
ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
|
boolean b = checkProductPerm(3, partsInfo.getPartsId());
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
return partsInfoService.assignRemoveDepart(partsInfo, departList);
|
}else if(nodeType == 1) {
|
//处理产品
|
ProductInfo productInfo = super.getById(paramId);
|
if(productInfo == null)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
|
boolean b1 = checkProductPerm(1, productInfo.getProductId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = this.assignRemoveDepartment(productInfo, departList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
//处理产品 下的部件
|
List<String> componentIds = new ArrayList<>();
|
List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
|
if(componentInfoList != null && !componentInfoList.isEmpty()) {
|
componentInfoList.forEach(item -> {
|
componentIds.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignRemoveDepart(item, departList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
|
//处理产品 下的零件
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productInfo.getProductId(), componentIds);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignRemoveDepart(item, departList);
|
if(!b)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
});
|
}
|
}
|
return true;
|
}else if(nodeType == 2) {
|
ComponentInfo componentInfo = componentInfoService.getById(paramId);
|
if(componentInfo == null)
|
ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
|
boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
b1 = componentInfoService.assignRemoveDepart(componentInfo, departList);
|
if(!b1)
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
if(relativeFlag == 1) {
|
List<String> componentIdList = new ArrayList<>();
|
componentIdList.add(componentInfo.getComponentId());
|
List<ComponentInfo> childrenList = componentInfoService.getByParentId(componentInfo.getComponentId());
|
if(childrenList != null && !childrenList.isEmpty()) {
|
childrenList.forEach(item -> {
|
componentIdList.add(item.getComponentId());
|
boolean b = checkProductPerm(2, item.getComponentId());
|
if(b) {
|
b = componentInfoService.assignRemoveDepart(item, departList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
|
List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(componentInfo.getProductId(), componentIdList);
|
if(partsInfoList != null && !partsInfoList.isEmpty()) {
|
partsInfoList.forEach(item -> {
|
boolean b = checkProductPerm(3, item.getPartsId());
|
if(b) {
|
b = partsInfoService.assignRemoveDepart(item, departList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
});
|
}
|
}
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignAddUser(ProductInfo productInfo, Collection<User> userList) {
|
if(productInfo == null || userList == null || userList.isEmpty())
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
List<ProductPermission> permissionList = new ArrayList<>();
|
List<PermissionStream> permissionStreamList = new ArrayList<>();
|
userList.forEach(item -> {
|
ProductPermission en = productPermissionService.getByProductIdAndUserId(productInfo.getProductId(), item.getUserId());
|
if(en == null) {
|
en = new ProductPermission();
|
en.setUserId(item.getUserId());
|
en.setProductId(productInfo.getProductId());
|
permissionList.add(en);
|
}
|
PermissionStream stream = permissionStreamService.getByProductIdAndUserId(productInfo.getProductId(), item.getUserId());
|
if(stream == null) {
|
stream = new PermissionStream();
|
stream.setUserId(item.getUserId());
|
stream.setProductId(productInfo.getProductId());
|
permissionStreamList.add(stream);
|
}
|
});
|
if(!permissionList.isEmpty()) {
|
boolean b = productPermissionService.saveBatch(permissionList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
if(!permissionStreamList.isEmpty()) {
|
boolean b = permissionStreamService.saveBatch(permissionStreamList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignRemoveUser(ProductInfo productInfo, Collection<User> userList) {
|
if(productInfo == null || userList == null || userList.isEmpty())
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
List<ProductPermission> permissionList = new ArrayList<>();
|
List<PermissionStream> permissionStreamList = new ArrayList<>();
|
userList.forEach(item -> {
|
ProductPermission en = productPermissionService.getByProductIdAndUserId(productInfo.getProductId(), item.getUserId());
|
if(en != null) {
|
permissionList.add(en);
|
}
|
PermissionStream stream = permissionStreamService.getByProductIdAndUserId(productInfo.getProductId(), item.getUserId());
|
if(stream != null) {
|
permissionStreamList.add(stream);
|
}
|
});
|
//移除用户权限清空校验
|
List<ProductPermission> existList = productPermissionService.getByProductId(productInfo.getProductId());
|
if(existList.size() <= permissionList.size())
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_NONE);
|
if(!permissionList.isEmpty()) {
|
boolean b = productPermissionService.removeByCollection(permissionList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
if(!permissionStreamList.isEmpty()) {
|
boolean b = permissionStreamService.removeByCollection(permissionStreamList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignAddDepartment(ProductInfo productInfo, Collection<Department> departmentList) {
|
if(productInfo == null || departmentList == null || departmentList.isEmpty())
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
List<ProductDepartment> productDepartmentList = new ArrayList<>();
|
List<PermissionStream> permissionStreamList = new ArrayList<>();
|
departmentList.forEach(item -> {
|
ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
|
if(en == null) {
|
en = new ProductDepartment();
|
en.setDepartId(item.getDepartId());
|
en.setProductId(productInfo.getProductId());
|
productDepartmentList.add(en);
|
}
|
PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
|
if(stream == null) {
|
stream = new PermissionStream();
|
stream.setDepartId(item.getDepartId());
|
stream.setProductId(productInfo.getProductId());
|
permissionStreamList.add(stream);
|
}
|
});
|
if(!productDepartmentList.isEmpty()) {
|
boolean b = productDepartmentService.saveBatch(productDepartmentList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
if(!permissionStreamList.isEmpty()) {
|
boolean b = permissionStreamService.saveBatch(permissionStreamList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
return true;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean assignRemoveDepartment(ProductInfo productInfo, Collection<Department> departmentList) {
|
if(productInfo == null || departmentList == null || departmentList.isEmpty())
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
List<ProductDepartment> productDepartmentList = new ArrayList<>();
|
List<PermissionStream> permissionStreamList = new ArrayList<>();
|
departmentList.forEach(item -> {
|
ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
|
if(en != null) {
|
productDepartmentList.add(en);
|
}
|
PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
|
if(stream != null) {
|
permissionStreamList.add(stream);
|
}
|
});
|
if(!productDepartmentList.isEmpty()) {
|
boolean b = productDepartmentService.removeByCollection(productDepartmentList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
if(!permissionStreamList.isEmpty()) {
|
boolean b = permissionStreamService.removeByCollection(permissionStreamList);
|
if(!b) {
|
ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
|
}
|
}
|
return true;
|
}
|
|
@Override
|
public List<String> getDepartIdsByParams(Integer nodeType, String paramId) {
|
List<String> departIds = new ArrayList<>();
|
if(nodeType == 2) {
|
ComponentInfo en = componentInfoService.getById(paramId);
|
if(en == null)
|
return null;
|
List<PermissionStream> permissionStreamList = permissionStreamService.getByComponentId(en.getProductId(), en.getComponentId());
|
if(permissionStreamList == null || permissionStreamList.isEmpty())
|
return null;
|
permissionStreamList.forEach(item -> {
|
departIds.add(item.getDepartId());
|
});
|
}else if(nodeType == 3) {
|
PartsInfo en = partsInfoService.getById(paramId);
|
if(en == null)
|
return null;
|
List<PermissionStream> permissionStreamList = permissionStreamService.getByPartsId(en.getProductId(), en.getComponentId(), en.getPartsId());
|
if(permissionStreamList == null || permissionStreamList.isEmpty())
|
return null;
|
permissionStreamList.forEach(item -> {
|
departIds.add(item.getDepartId());
|
});
|
}else {
|
return null;
|
}
|
return departIds;
|
}
|
|
@Override
|
public ProductInfo getByProductNo(String productNo) {
|
if(ValidateUtil.validateString(productNo)) {
|
List<ProductInfo> list = super.lambdaQuery().eq(ProductInfo::getProductNo, productNo).list();
|
if(list == null || list.isEmpty())
|
return null;
|
return list.get(0);
|
}
|
return null;
|
}
|
}
|