zhangherong
2025-06-25 2fb6c67b2c0c72195eef6fe5f7904d739b46e2c0
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessSpecVersionServiceImpl.java
@@ -1,17 +1,22 @@
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.conditions.query.QueryWrapper;
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.constant.DocAttributionTypeEnum;
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;
@@ -21,10 +26,8 @@
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ProcessSpecVersionServiceImpl extends ServiceImpl<ProcessSpecVersionMapper, ProcessSpecVersion> implements IProcessSpecVersionService{
@@ -33,7 +36,7 @@
    @Autowired
    private ComponentInfoMapper componentInfoMapper;
    @Autowired
    private PartsInfoMapper processSpecVersionMapper;
    private PartsInfoMapper partsInfoMapper;
    @Autowired
    private IPermissionStreamNewService permissionStreamNewService;
    @Autowired
@@ -44,7 +47,14 @@
    @Autowired
    private IProcessSpecVersionDepartmentService processSpecVersionDepartmentService;
    @Autowired
    private IProductMixService productMixService;
    @Autowired
    private IWorkStepService workStepService;
    @Autowired
    private IProductPermissionService productPermissionService;
    @Autowired
    @Lazy
    private IDocInfoService docInfoService;
    /**
     * 根据用户id获取授权的工艺规程版本表信息
     * @param userId
@@ -81,56 +91,65 @@
    /**
     * 新增工艺规程版本表信息
     * @param ProcessSpecVersion
     * @param processSpecVersion
     * @return
     */
    @Override
    public boolean addProcessSpecVersion(ProcessSpecVersion ProcessSpecVersion){
        if(ProcessSpecVersion == null)
    public boolean addProcessSpecVersion(ProcessSpecVersion processSpecVersion){
        if(processSpecVersion == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(ProcessSpecVersion.getProcessSpecVersionName()))
            ExceptionCast.cast(PartsInfoCode.PARTS_NAME_NONE);
        if(!ValidateUtil.validateString(ProcessSpecVersion.getProductId()))
        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()))
        if(!ValidateUtil.validateString(processSpecVersion.getComponentId()))
            ExceptionCast.cast(PartsInfoCode.PARTS_COMPONENT_NONE);
        if(!ValidateUtil.validateString(ProcessSpecVersion.getPartsId()))
        if(!ValidateUtil.validateString(processSpecVersion.getPartsId()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_PARTS_NONE);
        if(!ValidateUtil.validateString(ProcessSpecVersion.getProcessSpecVersionCode()))
        if(!ValidateUtil.validateString(processSpecVersion.getProcessSpecVersionCode()))
            ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_CODE_NONE);
        ProcessSpecVersion en = getByCode(ProcessSpecVersion.getProcessSpecVersionCode());
        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());
        ProductInfo productInfo = productInfoMapper.selectById(processSpecVersion.getProductId());
        if(productInfo == null)
            ExceptionCast.cast(PartsInfoCode.PARTS_PRODUCT_NONE);
        ComponentInfo componentInfo = componentInfoMapper.selectById(ProcessSpecVersion.getComponentId());
        ComponentInfo componentInfo = componentInfoMapper.selectById(processSpecVersion.getComponentId());
        if(componentInfo == null)
            ExceptionCast.cast(PartsInfoCode.PARTS_COMPONENT_NONE);
        PartsInfo processSpecVersion = processSpecVersionMapper.selectById(ProcessSpecVersion.getPartsId());
        if(processSpecVersion == null)
        PartsInfo partsInfo = partsInfoMapper.selectById(processSpecVersion.getPartsId());
        if(partsInfo == null)
            ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
        boolean b = super.save(ProcessSpecVersion);
        //相同零件号下面版本号不能重复
        List<ProcessSpecVersion> list = super.list(new LambdaQueryWrapper<ProcessSpecVersion>().eq(ProcessSpecVersion::getPartsId,partsInfo.getPartsId()));
        if (list != null && list.size() > 0) {
            list.forEach(processSpecVersion1 -> {
                if (processSpecVersion1.getProcessSpecVersionCode().equals(processSpecVersion.getProcessSpecVersionCode())) {
                    ExceptionCast.cast(PartsInfoCode.PROCESSSPECVERSION_IS_EXIST);
                }
            });
        }
        boolean b = super.save(processSpecVersion);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //添加部门权限
        List<PermissionStreamNew> oldDepartPermList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(ProcessSpecVersion.getPartsId(),"3","1");
        List<PermissionStreamNew> oldDepartPermList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(processSpecVersion.getPartsId(), DocAttributionTypeEnum.PARTS.getCode().toString(),"1");
        if(oldDepartPermList != null && !oldDepartPermList.isEmpty()) {
            List<ProcessSpecVersionDepartment> processSpecVersionDepartmentList = new ArrayList<>();
            List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
            oldDepartPermList.forEach(item -> {
                ProcessSpecVersionDepartment pd = new ProcessSpecVersionDepartment();
                pd.setDepartId(item.getDepartId());
                pd.setPsvId(ProcessSpecVersion.getId());
                pd.setPsvId(processSpecVersion.getId());
                processSpecVersionDepartmentList.add(pd);
                PermissionStreamNew perm = new PermissionStreamNew();
                perm.setDepartId(item.getDepartId());
                perm.setBusinessId(ProcessSpecVersion.getId());
                perm.setBusinessType("4");
                perm.setBusinessId(processSpecVersion.getId());
                perm.setBusinessType(DocAttributionTypeEnum.OPERATION.getCode().toString());
                permissionStreamList.add(perm);
            });
            if(!processSpecVersionDepartmentList.isEmpty()) {
@@ -145,16 +164,21 @@
            }
        }
        //添加用户权限
        b = productPermissionService.add(ProcessSpecVersion.getId(), userId,"4");
        b = productPermissionService.add(processSpecVersion.getId(), userId,DocAttributionTypeEnum.OPERATION.getCode().toString());
        if (!b) {
            ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
        }
        //添加结构树
        ProductMix productMix = new ProductMix(Long.parseLong(processSpecVersion.getId()),Long.parseLong(processSpecVersion.getPartsId())
                ,processSpecVersion.getProcessSpecVersionName(),
                processSpecVersion.getProcessSpecVersionCode(),DocAttributionTypeEnum.OPERATION.getCode(),new Date());
        productMixService.save(productMix);
        //添加用户权限
        PermissionStreamNew stream = new PermissionStreamNew();
        stream.setBusinessId(ProcessSpecVersion.getId());
        stream.setBusinessType("4");
        stream.setBusinessId(processSpecVersion.getId());
        stream.setBusinessType(DocAttributionTypeEnum.OPERATION.getCode().toString());
        stream.setUserId(userId);
        return permissionStreamNewService.save(stream);
        return permissionStreamNewService.addPermissionStreamNew(stream);
    }
    /**
@@ -179,6 +203,11 @@
        processSpecVersion.setComponentId(null);
        processSpecVersion.setPartsId(null);
        boolean b = super.updateById(processSpecVersion);
        //同步修改结构树
        ProductMix productMix = productMixService.getById(Long.parseLong(id));
        productMix.setTreeName(processSpecVersion.getProcessSpecVersionName());
        productMix.setTreeCode(processSpecVersion.getProcessSpecVersionCode());
        productMixService.updateById(productMix);
        if(!b)
            return false;
        ProcessSpecVersionPermission permission = processSpecVersionPermissionService.getByPsvIdAndUserId(id, userId);
@@ -188,7 +217,7 @@
            if(!b)
                return false;
        }
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,"4");
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,DocAttributionTypeEnum.OPERATION.getCode().toString());
        if(stream == null) {
            stream = new PermissionStreamNew();
            stream.setBusinessId(id);
@@ -212,26 +241,31 @@
            ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
        List<ProcessStream> processStreams = processStreamService.findBypsvId(id);
        if(processStreams!= null &&!processStreams.isEmpty())
            ExceptionCast.cast(PartsInfoCode.PARTS_PROCESS_EXIST);
            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");
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(processSpecVersion.getId(),DocAttributionTypeEnum.OPERATION.getCode().toString(),"0");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(processSpecVersion.getId(),"4","1");
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(processSpecVersion.getId(),DocAttributionTypeEnum.OPERATION.getCode().toString(),"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 processSpecVersionCode) {
    public ProcessSpecVersion getByCode(String partId,String processSpecVersionCode) {
        if(ValidateUtil.validateString(processSpecVersionCode)) {
            List<ProcessSpecVersion> list = super.lambdaQuery().eq(ProcessSpecVersion::getProcessSpecVersionCode, processSpecVersionCode).list();
            List<ProcessSpecVersion> list = super.lambdaQuery()
                    .eq(ProcessSpecVersion::getPartsId, partId)
                    .eq(ProcessSpecVersion::getProcessSpecVersionCode, processSpecVersionCode).list();
            if(list == null || list.isEmpty())
                return null;
            return list.get(0);
@@ -287,12 +321,12 @@
                en.setPsvId(processSpecVersion.getId());
                permissionList.add(en);
            }
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),"4");
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),DocAttributionTypeEnum.OPERATION.getCode().toString());
            if(stream == null) {
                stream = new PermissionStreamNew();
                stream.setUserId(item.getId());
                stream.setBusinessId(processSpecVersion.getId());
                stream.setBusinessType("4");
                stream.setBusinessType(DocAttributionTypeEnum.OPERATION.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -329,7 +363,7 @@
            if(en != null) {
                permissionList.add(en);
            }
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),"4");
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(processSpecVersion.getId(), item.getId(),DocAttributionTypeEnum.OPERATION.getCode().toString());
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -369,12 +403,12 @@
                en.setPsvId(processSpecVersion.getId());
                partsDepartments.add(en);
            }
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(processSpecVersion.getId(), item.getId(),"4");
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(processSpecVersion.getId(), item.getId(),DocAttributionTypeEnum.OPERATION.getCode().toString());
            if(stream == null) {
                stream = new PermissionStreamNew();
                stream.setDepartId(item.getId());
                stream.setBusinessId(processSpecVersion.getId());
                stream.setBusinessType("4");
                stream.setBusinessType(DocAttributionTypeEnum.OPERATION.getCode().toString());
                permissionStreamList.add(stream);
            }
        });
@@ -430,4 +464,82 @@
        return true;
    }
    /**
     * 根据工艺规程id查询,下级工序工步数量
     * @param processSpecId
     * @return
     */
    @Override
    public Result<?> getProcessSpecVersionCount(String processSpecId){
        List<ProcessStream> list = processStreamService.findBypsvId(processSpecId);
        List<WorkStep> workStepList=workStepService.list(new LambdaQueryWrapper<WorkStep>().eq(WorkStep::getPsvId,processSpecId));
        return null;
    }
    /**
     * 通过零件号、材质等查询对应电子样板
     * @param treeInfoRequest
     * @return
     */
    @Override
    public List<DocInfo> getByProcessSpecVersion(TreeInfoRequest treeInfoRequest){
        LambdaQueryWrapper<ProcessSpecVersion> 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 (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.OPERATION.getCode())){
            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<ProcessSpecVersion> list = super.list(queryWrapper);
        List<DocInfo> docInfos;
        if (list == null || list.isEmpty() || StrUtil.isNotBlank(treeInfoRequest.getStructureType())){
            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(DocAttributionTypeEnum.OPERATION.getCode());
            docInfos=docInfoService.findListByDocQuery(docQuery);
            if (Objects.equals(treeInfoRequest.getAttributionType(), DocAttributionTypeEnum.OPERATION.getCode())){
                List<String> id =new ArrayList<>();
                id.add(treeInfoRequest.getAttributionId());
                treeInfoRequest.setPsvIds(id);
                //工序
                List<DocInfo> processStreams = processStreamService.getByProcessStreamOtherFile(treeInfoRequest);
                docInfos.addAll(processStreams);
                //工步
                List<DocInfo> workSteps = workStepService.getByWorkStepOtherFile(treeInfoRequest);
                docInfos.addAll(workSteps);
            }
        }
        return docInfos;
    }
    @Override
    public boolean assignPermission(Object entity, Collection<SysUser> userList, boolean isAdd){
        if (isAdd) {
            return assignAddUser((ProcessSpecVersion) entity, userList);
        } else {
            return assignRemoveUser((ProcessSpecVersion) entity, userList);
        }
    }
    @Override
    public boolean assignDepartPermission(Object entity, Collection<MdcProduction> departments, boolean isAdd) {
        if (isAdd) {
            return assignAddDepart((ProcessSpecVersion) entity, departments);
        } else {
            return assignRemoveDepart((ProcessSpecVersion) entity, departments);
        }
    }
}