package org.jeecg.modules.dnc.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.dnc.entity.*; import org.jeecg.modules.dnc.exception.ExceptionCast; import org.jeecg.modules.dnc.mapper.ComponentInfoMapper; import org.jeecg.modules.dnc.mapper.PartsInfoMapper; import org.jeecg.modules.dnc.mapper.ProcessSpecVersionMapper; import org.jeecg.modules.dnc.mapper.ProductInfoMapper; import org.jeecg.modules.dnc.request.DocInfoQueryRequest; import org.jeecg.modules.dnc.request.TreeInfoRequest; import org.jeecg.modules.dnc.response.*; import org.jeecg.modules.dnc.service.*; import org.jeecg.modules.dnc.utils.ValidateUtil; import org.jeecg.modules.system.entity.MdcProduction; import org.jeecg.modules.system.entity.SysUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; @Service public class ProcessSpecVersionServiceImpl extends ServiceImpl implements IProcessSpecVersionService{ @Autowired private ProductInfoMapper productInfoMapper; @Autowired private ComponentInfoMapper componentInfoMapper; @Autowired private PartsInfoMapper processSpecVersionMapper; @Autowired private IPermissionStreamNewService permissionStreamNewService; @Autowired @Lazy private IProcessStreamService processStreamService; @Autowired private IProcessSpecVersionPermissionService processSpecVersionPermissionService; @Autowired private IProcessSpecVersionDepartmentService processSpecVersionDepartmentService; @Autowired private IProductMixService productMixService; @Autowired private IWorkStepService workStepService; @Autowired private IProductPermissionService productPermissionService; @Autowired @Lazy private IDocInfoService docInfoService; /** * 根据用户id获取授权的工艺规程版本表信息 * @param userId * @return */ @Override public List getByUserPerms(String userId){ if(!ValidateUtil.validateString(userId)) return Collections.emptyList(); return super.getBaseMapper().getByUserPerms(userId); } /** * 根据用户id获取授权的工艺规程版本表信息 * @param userId * @param queryParam 查询条件 * @return */ @Override public List getByUserPerms(String userId,String queryParam){ if(!ValidateUtil.validateString(userId)) return Collections.emptyList(); if(!ValidateUtil.validateString(queryParam)) return Collections.emptyList(); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); if(ValidateUtil.validateString(queryParam)) { queryWrapper.and(wrapper->wrapper.like(ProcessSpecVersion::getProcessSpecVersionName, queryParam) .or() .like(ProcessSpecVersion::getProcessSpecVersionName, queryParam)); } queryWrapper.orderByAsc(ProcessSpecVersion::getCreateTime); return super.list(queryWrapper); } /** * 新增工艺规程版本表信息 * @param ProcessSpecVersion * @return */ @Override public boolean addProcessSpecVersion(ProcessSpecVersion ProcessSpecVersion){ if(ProcessSpecVersion == null) ExceptionCast.cast(CommonCode.INVALID_PARAM); if(!ValidateUtil.validateString(ProcessSpecVersion.getProcessSpecVersionName())) ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_NONE); if(!ValidateUtil.validateString(ProcessSpecVersion.getProductId())) ExceptionCast.cast(PartsInfoCode.PARTS_PRODUCT_NONE); if(!ValidateUtil.validateString(ProcessSpecVersion.getComponentId())) ExceptionCast.cast(PartsInfoCode.PARTS_COMPONENT_NONE); if(!ValidateUtil.validateString(ProcessSpecVersion.getPartsId())) ExceptionCast.cast(ProcessInfoCode.PROCESS_PARTS_NONE); if(!ValidateUtil.validateString(ProcessSpecVersion.getProcessSpecVersionCode())) ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_CODE_NONE); ProcessSpecVersion en = getByCode(ProcessSpecVersion.getPartsId(),ProcessSpecVersion.getProcessSpecVersionCode()); if(en != null) ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_IS_EXIST); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); if(!ValidateUtil.validateString(userId)) ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); ProductInfo productInfo = productInfoMapper.selectById(ProcessSpecVersion.getProductId()); if(productInfo == null) ExceptionCast.cast(PartsInfoCode.PARTS_PRODUCT_NONE); ComponentInfo componentInfo = componentInfoMapper.selectById(ProcessSpecVersion.getComponentId()); if(componentInfo == null) ExceptionCast.cast(PartsInfoCode.PARTS_COMPONENT_NONE); PartsInfo processSpecVersion = processSpecVersionMapper.selectById(ProcessSpecVersion.getPartsId()); if(processSpecVersion == null) ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST); boolean b = super.save(ProcessSpecVersion); if(!b) ExceptionCast.cast(CommonCode.FAIL); //添加部门权限 List oldDepartPermList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(ProcessSpecVersion.getPartsId(),"3","1"); if(oldDepartPermList != null && !oldDepartPermList.isEmpty()) { List processSpecVersionDepartmentList = new ArrayList<>(); List permissionStreamList = new ArrayList<>(); oldDepartPermList.forEach(item -> { ProcessSpecVersionDepartment pd = new ProcessSpecVersionDepartment(); pd.setDepartId(item.getDepartId()); pd.setPsvId(ProcessSpecVersion.getId()); processSpecVersionDepartmentList.add(pd); PermissionStreamNew perm = new PermissionStreamNew(); perm.setDepartId(item.getDepartId()); perm.setBusinessId(ProcessSpecVersion.getId()); perm.setBusinessType("4"); permissionStreamList.add(perm); }); if(!processSpecVersionDepartmentList.isEmpty()) { b = processSpecVersionDepartmentService.saveBatch(processSpecVersionDepartmentList); if(!b) ExceptionCast.cast(CommonCode.FAIL); } if(!permissionStreamList.isEmpty()) { b = permissionStreamNewService.saveBatch(permissionStreamList); if(!b) ExceptionCast.cast(CommonCode.FAIL); } } //添加用户权限 b = productPermissionService.add(ProcessSpecVersion.getId(), userId,"4"); if (!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR); } //添加结构树 ProductMix productMix = new ProductMix(Long.parseLong(ProcessSpecVersion.getId()),Long.parseLong(ProcessSpecVersion.getPartsId()) ,ProcessSpecVersion.getProcessSpecVersionName(), ProcessSpecVersion.getProcessSpecVersionCode(),4,new Date()); productMixService.save(productMix); //添加用户权限 PermissionStreamNew stream = new PermissionStreamNew(); stream.setBusinessId(ProcessSpecVersion.getId()); stream.setBusinessType("4"); stream.setUserId(userId); return permissionStreamNewService.addPermissionStreamNew(stream); } /** * 编辑工艺规程版本表信息 * @param id * @param processSpecVersion * @return */ @Override public boolean editProcessSpecVersion(String id ,ProcessSpecVersion processSpecVersion){ if(!ValidateUtil.validateString(id) || processSpecVersion == null) ExceptionCast.cast(CommonCode.SUCCESS); LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = user.getId(); if(!ValidateUtil.validateString(userId)) ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST); ProcessSpecVersion en = super.getById(id); if(en == null) ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST); processSpecVersion.setId(id); processSpecVersion.setProductId(null); processSpecVersion.setComponentId(null); processSpecVersion.setPartsId(null); boolean b = super.updateById(processSpecVersion); //同步修改结构树 ProductMix productMix = productMixService.getById(Long.parseLong(id)); productMix.setName(processSpecVersion.getProcessSpecVersionName()); productMix.setCode(processSpecVersion.getProcessSpecVersionCode()); productMixService.updateById(productMix); if(!b) return false; ProcessSpecVersionPermission permission = processSpecVersionPermissionService.getByPsvIdAndUserId(id, userId); if(permission == null) { permission = new ProcessSpecVersionPermission(id,userId); b = processSpecVersionPermissionService.save(permission); if(!b) return false; } PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,"4"); if(stream == null) { stream = new PermissionStreamNew(); stream.setBusinessId(id); stream.setUserId(userId); return permissionStreamNewService.save(stream); } return b; } /** * 删除工艺规程版本表信息 * @param id * @return */ @Override public boolean deleteProcessSpecVersion(String id){ if(!ValidateUtil.validateString(id)) ExceptionCast.cast(CommonCode.INVALID_PARAM); ProcessSpecVersion processSpecVersion = super.getById(id); if(processSpecVersion == null) ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST); List processStreams = processStreamService.findBypsvId(id); if(processStreams!= null &&!processStreams.isEmpty()) ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_PROCESS_EXIST); boolean b = processSpecVersionPermissionService.deleteByPsvId(processSpecVersion.getId()); if(!b) ExceptionCast.cast(CommonCode.FAIL); b = processSpecVersionDepartmentService.deleteByPsvId(processSpecVersion.getId()); if(!b) ExceptionCast.cast(CommonCode.FAIL); b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(processSpecVersion.getId(),"4","0"); if(!b) ExceptionCast.cast(CommonCode.FAIL); b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(processSpecVersion.getId(),"4","1"); if(!b) ExceptionCast.cast(CommonCode.FAIL); b = productMixService.removeById(processSpecVersion.getId()); if (!b) ExceptionCast.cast(CommonCode.FAIL); return super.removeById(processSpecVersion.getId()); } @Override public ProcessSpecVersion getByCode(String partId,String processSpecVersionCode) { if(ValidateUtil.validateString(processSpecVersionCode)) { List list = super.lambdaQuery() .eq(ProcessSpecVersion::getPartsId, partId) .eq(ProcessSpecVersion::getProcessSpecVersionCode, processSpecVersionCode).list(); if(list == null || list.isEmpty()) return null; return list.get(0); } return null; } @Override public List getByPartsId(String partsId) { if(ValidateUtil.validateString(partsId)) { List list = super.lambdaQuery().eq(ProcessSpecVersion::getPartsId, partsId).list(); if(list == null || list.isEmpty()) return null; return list; } return null; } /** * 根据一组零件id获取 * @param partsIds * @return */ @Override public List getByPartsIds(List partsIds){ if(partsIds == null || partsIds.isEmpty()) return Collections.emptyList(); List list = super.lambdaQuery().in(ProcessSpecVersion::getPartsId, partsIds).list(); if(list == null || list.isEmpty()) return null; else return list; } /** * 分配用户权限 * @param processSpecVersion * @param userList * @return */ @Override public boolean assignAddUser(ProcessSpecVersion processSpecVersion, Collection userList){ if(processSpecVersion == null || userList == null || userList.isEmpty()) ExceptionCast.cast(CommonCode.INVALID_PARAM); List permissionList = new ArrayList<>(); List permissionStreamList = new ArrayList<>(); userList.forEach(item -> { ProcessSpecVersionPermission en = processSpecVersionPermissionService.getByPsvIdAndUserId(processSpecVersion.getId(), item.getId()); if(en == null) { en = new ProcessSpecVersionPermission(); en.setUserId(item.getId()); en.setPsvId(processSpecVersion.getId()); permissionList.add(en); } PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),"4"); if(stream == null) { stream = new PermissionStreamNew(); stream.setUserId(item.getId()); stream.setBusinessId(processSpecVersion.getId()); stream.setBusinessType("4"); permissionStreamList.add(stream); } }); if(!permissionList.isEmpty()) { boolean b = processSpecVersionPermissionService.saveBatch(permissionList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } if(!permissionStreamList.isEmpty()) { boolean b = permissionStreamNewService.saveBatch(permissionStreamList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } return true; } /** * 移除用户权限 * @param processSpecVersion * @param userList * @return */ @Override public boolean assignRemoveUser(ProcessSpecVersion processSpecVersion, Collection userList){ if(processSpecVersion == null || userList == null || userList.isEmpty()) ExceptionCast.cast(CommonCode.INVALID_PARAM); List permissionList = new ArrayList<>(); List permissionStreamList = new ArrayList<>(); userList.forEach(item -> { ProcessSpecVersionPermission en = processSpecVersionPermissionService.getByPsvIdAndUserId(processSpecVersion.getId(), item.getId()); if(en != null) { permissionList.add(en); } PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),"4"); if(stream != null) { permissionStreamList.add(stream); } }); //清空用户权限校验 if(!permissionList.isEmpty()) { boolean b = processSpecVersionPermissionService.removeByCollection(permissionList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } if(!permissionStreamList.isEmpty()) { boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } return true; } /** * 分配部门权限 * @param processSpecVersion * @param departmentList * @return */ @Override public boolean assignAddDepart(ProcessSpecVersion processSpecVersion, Collection departmentList){ if(processSpecVersion == null || departmentList == null || departmentList.isEmpty()) ExceptionCast.cast(CommonCode.INVALID_PARAM); List partsDepartments = new ArrayList<>(); List permissionStreamList = new ArrayList<>(); departmentList.forEach(item -> { ProcessSpecVersionDepartment en = processSpecVersionDepartmentService.getByProcessSpecVersionIdAndDepartId(processSpecVersion.getId(), item.getId()); if(en == null) { en = new ProcessSpecVersionDepartment(); en.setDepartId(item.getId()); en.setPsvId(processSpecVersion.getId()); partsDepartments.add(en); } PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(processSpecVersion.getId(), item.getId(),"4"); if(stream == null) { stream = new PermissionStreamNew(); stream.setDepartId(item.getId()); stream.setBusinessId(processSpecVersion.getId()); stream.setBusinessType("4"); permissionStreamList.add(stream); } }); if(!partsDepartments.isEmpty()) { boolean b = processSpecVersionDepartmentService.saveBatch(partsDepartments); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } if(!permissionStreamList.isEmpty()) { boolean b = permissionStreamNewService.saveBatch(permissionStreamList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } return true; } /** * 分配部门权限 * @param processSpecVersion * @param departmentList * @return */ @Override public boolean assignRemoveDepart(ProcessSpecVersion processSpecVersion, Collection departmentList){ if(processSpecVersion == null || departmentList == null || departmentList.isEmpty()) ExceptionCast.cast(CommonCode.INVALID_PARAM); List partsDepartments = new ArrayList<>(); List permissionStreamList = new ArrayList<>(); departmentList.forEach(item -> { ProcessSpecVersionDepartment en = processSpecVersionDepartmentService.getByProcessSpecVersionIdAndDepartId(processSpecVersion.getId(), item.getId()); if(en != null) { partsDepartments.add(en); } PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(processSpecVersion.getId(), item.getId(),"3"); if(stream != null) { permissionStreamList.add(stream); } }); if(!partsDepartments.isEmpty()) { boolean b = processSpecVersionDepartmentService.removeByCollection(partsDepartments); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } if(!permissionStreamList.isEmpty()) { boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList); if(!b) { ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR); } } return true; } /** * 根据工艺规程id查询,下级工序工步数量 * @param processSpecId * @return */ @Override public Result getProcessSpecVersionCount(String processSpecId){ List list = processStreamService.findBypsvId(processSpecId); List workStepList=workStepService.list(new LambdaQueryWrapper().eq(WorkStep::getPsvId,processSpecId)); return null; } /** * 通过零件号、材质等查询对应电子样板 * @param treeInfoRequest * @return */ @Override public List getByProcessSpecVersion(TreeInfoRequest treeInfoRequest){ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (treeInfoRequest.getProductIds() != null && !treeInfoRequest.getProductIds().isEmpty()) { queryWrapper.in(ProcessSpecVersion::getProductId, treeInfoRequest.getProductIds()); } if (treeInfoRequest.getComponentIds() != null && !treeInfoRequest.getComponentIds().isEmpty()) { queryWrapper.in(ProcessSpecVersion::getComponentId, treeInfoRequest.getComponentIds()); } if (treeInfoRequest.getPartsIds() != null && !treeInfoRequest.getPartsIds().isEmpty()) { queryWrapper.in(ProcessSpecVersion::getPartsId, treeInfoRequest.getPartsIds()); } if (treeInfoRequest.getAttributionType()==4){ queryWrapper.eq(StrUtil.isNotEmpty(treeInfoRequest.getAttributionId()),ProcessSpecVersion::getId,treeInfoRequest.getAttributionId()); } queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeName()),ProcessSpecVersion::getProcessSpecVersionName, treeInfoRequest.getTreeName()); queryWrapper.like(StrUtil.isNotEmpty(treeInfoRequest.getTreeCode()),ProcessSpecVersion::getProcessSpecVersionCode, treeInfoRequest.getTreeName()); queryWrapper.orderByDesc(ProcessSpecVersion::getCreateTime); List list = super.list(queryWrapper); if (list == null || list.isEmpty()){ return new ArrayList<>(); }else { String ids=list.stream().map(ProcessSpecVersion::getId).collect(Collectors.joining(",")); DocInfoQueryRequest docQuery = new DocInfoQueryRequest(); BeanUtil.copyProperties(treeInfoRequest,docQuery); docQuery.setAttributionIds(ids); docQuery.setDocClassCode("OTHER"); docQuery.setAttributionType(4); return docInfoService.findListByDocQuery(docQuery); } } }