lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ComponentInfoSeServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
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;
@@ -20,6 +21,7 @@
import org.jeecg.modules.dnc.ucenter.Department;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.dnc.entity.ComponentInfo;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,7 +41,7 @@
    @Autowired
    public ProductInfoMapper productInfoMapper;
    @Autowired
    private IPermissionStreamService permissionStreamService;
    private IPermissionStreamNewService permissionStreamNewService;
    @Autowired
    private IComponentDepartmentService componentDepartmentService;
    @Autowired
@@ -50,7 +52,9 @@
    @Autowired
    private IDocInfoService docInfoService;
    @Autowired
    private INcLogInfoService iNcLogInfoService;
    private IDocRelativeService iDocRelativeService;
    @Autowired
    private IProductPermissionService productPermissionService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
@@ -70,8 +74,7 @@
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        List<PermissionStream> oldPermissionList;
        List<PermissionStreamNew> oldPermissionList;
        ProductInfo productInfo = productInfoMapper.selectById(componentInfo.getProductId());
        if(productInfo == null)
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_PRODUCT_NONE);
@@ -80,40 +83,31 @@
            if(en == null) {
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_PARENT_NOT_EXIST);
            }
            oldPermissionList = permissionStreamService.getByComponentId(en.getProductId(), en.getComponentId());
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(en.getComponentId(),"2","1");
            componentInfo.setRankLevel(en.getRankLevel() + 1);
        } else {
            oldPermissionList = permissionStreamService.getByProductId(productInfo.getProductId());
            oldPermissionList = permissionStreamNewService.loadPermissionStreamNewByBusinessId(productInfo.getProductId(),"1","1");
            componentInfo.setParentId(null);
            componentInfo.setRankLevel(1);
        }
        componentInfo.setComponentStatus(1);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(2);
        //日志内容
        ncLogInfo.setLogContent("部件名称:"+componentInfo.getComponentName()+",部件代号:"+componentInfo.getComponentCode());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = super.save(componentInfo);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //部门权限
        List<ComponentDepartment> componentDepartmentList = new ArrayList<>();
        List<PermissionStream> componentDepartPermList = new ArrayList<>();
        List<PermissionStreamNew> componentDepartPermList = new ArrayList<>();
        if(oldPermissionList != null && !oldPermissionList.isEmpty()) {
            oldPermissionList.forEach(item -> {
                ComponentDepartment componentDepartment = new ComponentDepartment();
                componentDepartment.setComponentId(componentInfo.getComponentId());
                componentDepartment.setDepartId(item.getDepartId());
                componentDepartmentList.add(componentDepartment);
                PermissionStream permissionStream = new PermissionStream();
                permissionStream.setProductId(componentInfo.getProductId());
                permissionStream.setComponentId(componentInfo.getComponentId());
                PermissionStreamNew permissionStream = new PermissionStreamNew();
                permissionStream.setBusinessId(componentInfo.getComponentId());
                permissionStream.setDepartId(item.getDepartId());
                permissionStream.setBusinessType("2");
                componentDepartPermList.add(permissionStream);
            });
        }
@@ -123,40 +117,21 @@
                ExceptionCast.cast(CommonCode.FAIL);
        }
        if(!componentDepartPermList.isEmpty()) {
            b = permissionStreamService.saveBatch(componentDepartPermList);
            b = permissionStreamNewService.saveBatch(componentDepartPermList);
            if(!b)
                ExceptionCast.cast(CommonCode.FAIL);
        }
        ComponentPermission permission = new ComponentPermission();
        permission.setComponentId(componentInfo.getComponentId());
        permission.setUserId(userId);
        b = componentPermissionService.save(permission);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = productPermissionService.add(componentInfo.getComponentId(), userId,"2");
        if (!b) {
            ExceptionCast.cast(ProductInfoCode.PRODUCT_SAVE_ERROR);
        }
        //去除默认新增工序,转为手动添加
        /*/添加默认工序
        ProcessStream processStream = new ProcessStream();
        processStream.setProductId(componentInfo.getProductId());
        processStream.setComponentId(componentInfo.getComponentId());
        processStream.setProcessCode("1");
        //添加日志
        NcLogInfo ncLogInfogx = new NcLogInfo();
        //模块
        ncLogInfogx.setModuleInfo("产品结构树");
        //类型
        ncLogInfogx.setOperateType(2);
        //日志内容
        ncLogInfogx.setLogContent("部件名称:"+componentInfo.getComponentName()+"生成默认工序,工序号:"+processStream.getProcessCode());
        iNcLogInfoService.saveLogNcInfos(ncLogInfogx);
        b = processStreamService.save(processStream);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);*/
        //添加权限
        PermissionStream stream = new PermissionStream();
        PermissionStreamNew stream = new PermissionStreamNew();
        stream.setUserId(userId);
        stream.setProductId(componentInfo.getProductId());
        stream.setComponentId(componentInfo.getComponentId());
        return permissionStreamService.save(stream);
        stream.setBusinessId(componentInfo.getComponentId());
        stream.setBusinessType("2");
        return permissionStreamNewService.save(stream);
    }
    @Override
@@ -178,17 +153,6 @@
        componentInfo.setComponentStatus(null);
        componentInfo.setRankLevel(null);
        componentInfo.setProductId(null);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(3);
        //日志内容
        ncLogInfo.setLogContent("修改部件名称:"+productInfoMapper.selectById(en.getProductId()).getProductName()+"子集部件");
        //修改保存备注
        ncLogInfo.setRemark(JSONObject.toJSONString(en));
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = super.updateById(componentInfo);
        if(!b)
            return false;
@@ -201,13 +165,13 @@
            if(!b)
                return false;
        }
        PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(en.getProductId(), id, userId);
        PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndUserId(id, userId,"2");
        if(stream == null) {
            stream = new PermissionStream();
            stream = new PermissionStreamNew();
            stream.setUserId(userId);
            stream.setProductId(en.getProductId());
            stream.setComponentId(id);
            return permissionStreamService.save(stream);
            stream.setBusinessId(id);
            stream.setBusinessType("2");
            return permissionStreamNewService.save(stream);
        }
        return b;
    }
@@ -262,10 +226,10 @@
            b = componentDepartmentService.deleteByComponentId(item.getComponentId());
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamService.deleteUserPermsByComponentId(item.getProductId(), item.getComponentId());
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),"2","0");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = permissionStreamService.deleteDepartPermsByComponentId(item.getProductId(), item.getComponentId());
            b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(item.getComponentId(),"2","1");
            if(!b)
                ExceptionCast.cast(ComponentInfoCode.COMPONENT_DELETE_PERM_NONE);
            b = super.removeById(item.getComponentId());
@@ -296,28 +260,22 @@
        if(processStreamList != null && !processStreamList.isEmpty()) {
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_PROCESS_EXIST);
        }
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(4);
        //日志内容
        ncLogInfo.setLogContent("部件名称:"+componentInfo.getComponentName());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        boolean b = docInfoService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        boolean b;
        //验证是否存在文档
        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type","2").eq("attribution_id",id));
        if (!docRelativeList.isEmpty()){
            ExceptionCast.cast(ComponentInfoCode.COMPONENT_DOC_EXIST);
        }
        b = componentPermissionService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = componentDepartmentService.deleteByComponentId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamService.deleteUserPermsByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),"2","0");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = permissionStreamService.deleteDepartPermsByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
        b = permissionStreamNewService.deletePermissionStreamNewByBusinessId(componentInfo.getComponentId(),"2","1");
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        return super.removeById(id);
@@ -341,7 +299,7 @@
        if(componentInfo == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentPermission> permissionList = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            ComponentPermission en = componentPermissionService.getByComponentIdAndUserId(componentInfo.getComponentId(), item.getId());
            if(en == null) {
@@ -350,12 +308,12 @@
                en.setComponentId(componentInfo.getComponentId());
                permissionList.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(), "2 ");
            if(stream == null) {
                stream = new PermissionStream();
                stream = new PermissionStreamNew();
                stream.setUserId(item.getId());
                stream.setProductId(componentInfo.getProductId());
                stream.setComponentId(componentInfo.getComponentId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType("2");
                permissionStreamList.add(stream);
            }
        });
@@ -366,7 +324,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.saveBatch(permissionStreamList);
            boolean b = permissionStreamNewService.saveBatch(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -380,13 +338,13 @@
        if(componentInfo == null || userList == null || userList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentPermission> permissionList = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        userList.forEach(item -> {
            ComponentPermission en = componentPermissionService.getByComponentIdAndUserId(componentInfo.getComponentId(), item.getId());
            if(en != null) {
                permissionList.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(), "2 ");
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -402,7 +360,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.removeByCollection(permissionStreamList);
            boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -412,25 +370,25 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean assignAddDepart(ComponentInfo componentInfo, Collection<Department> departmentList) {
    public boolean assignAddDepart(ComponentInfo componentInfo, Collection<MdcProduction> departmentList) {
        if(componentInfo == null || departmentList == null || departmentList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentDepartment> componentDepartments = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        departmentList.forEach(item -> {
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getDepartId());
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getId());
            if(en == null) {
                en = new ComponentDepartment();
                en.setDepartId(item.getDepartId());
                en.setDepartId(item.getId());
                en.setComponentId(componentInfo.getComponentId());
                componentDepartments.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndDepartId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getDepartId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),"2");
            if(stream == null) {
                stream = new PermissionStream();
                stream.setDepartId(item.getDepartId());
                stream.setProductId(componentInfo.getProductId());
                stream.setComponentId(componentInfo.getComponentId());
                stream = new PermissionStreamNew();
                stream.setDepartId(item.getId());
                stream.setBusinessId(componentInfo.getComponentId());
                stream.setBusinessType("2");
                permissionStreamList.add(stream);
            }
        });
@@ -441,7 +399,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.saveBatch(permissionStreamList);
            boolean b = permissionStreamNewService.saveBatch(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }
@@ -451,17 +409,17 @@
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean assignRemoveDepart(ComponentInfo componentInfo, Collection<Department> departmentList) {
    public boolean assignRemoveDepart(ComponentInfo componentInfo, Collection<MdcProduction> departmentList) {
        if(componentInfo == null || departmentList == null || departmentList.isEmpty())
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        List<ComponentDepartment> componentDepartments = new ArrayList<>();
        List<PermissionStream> permissionStreamList = new ArrayList<>();
        List<PermissionStreamNew> permissionStreamList = new ArrayList<>();
        departmentList.forEach(item -> {
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getDepartId());
            ComponentDepartment en = componentDepartmentService.getByComponentIdAndDepartId(componentInfo.getComponentId(), item.getId());
            if(en != null) {
                componentDepartments.add(en);
            }
            PermissionStream stream = permissionStreamService.getByComponentIdAndDepartId(componentInfo.getProductId(), componentInfo.getComponentId(), item.getDepartId());
            PermissionStreamNew stream = permissionStreamNewService.loadPermissionStreamNewByBusinessIdAndDepartId(componentInfo.getComponentId(), item.getId(),"2");
            if(stream != null) {
                permissionStreamList.add(stream);
            }
@@ -473,7 +431,7 @@
            }
        }
        if(!permissionStreamList.isEmpty()) {
            boolean b = permissionStreamService.removeByCollection(permissionStreamList);
            boolean b = permissionStreamNewService.deletePermissionStreamNewByList(permissionStreamList);
            if(!b) {
                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
            }