危化品全生命周期管理后端
“djh”
2025-04-21 437f8e2b89a18363a1073fdbb3ab99bcd840a757
hazmat-system/src/main/java/com/gkhy/hazmat/system/service/impl/HzHazmatFlowServiceImpl.java
@@ -1,5 +1,7 @@
package com.gkhy.hazmat.system.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.hazmat.common.api.CommonPage;
import com.gkhy.hazmat.common.config.IdTableNameHandler;
@@ -17,8 +19,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * <p>
@@ -37,9 +41,14 @@
    public CommonPage selectHazmatFlowList(HzHazmatFlow hazmatFlow) {
        SysUser currentUser = SecurityUtils.getLoginUser().getUser();
        checkUserAllowed(null,currentUser);
        hazmatFlow.setCompanyId(currentUser.getCompanyId());
        //设置分表id
        IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
            IdTableNameHandler.setCurrentId(hazmatFlow.getCompanyId());
        }else {
            hazmatFlow.setCompanyId(currentUser.getCompanyId());
            //设置分表id
            //todo
            IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        }
        PageUtils.startPage();
        List<HzHazmatFlow> flowList = baseMapper.selectHazmatFlowList(hazmatFlow);
        IdTableNameHandler.removeCurrentId();
@@ -109,15 +118,19 @@
    }
    @Override
    public List<HzHazmatFlow> selectAllHazmatFlowByCode(String code) {
    public List<HzHazmatFlow> selectAllHazmatFlowByCode(String code,Long companyId) {
        SysUser currentUser=SecurityUtils.getLoginUser().getUser();
        checkUserAllowed(null,currentUser);
        if(!code.startsWith(CodePrexEnum.MATERIAL.getCode())){
            throw new ApiException("条码格式不正确");
        }
        //设置分表id
        IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        HzHazmat hazmat=hazmatMapper.selectHazmatByCode(code,currentUser.getCompanyId());
        if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
            IdTableNameHandler.setCurrentId(companyId);
        }else {
            //设置分表id
            IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        }
        HzHazmat hazmat=hazmatMapper.selectHazmatByCode(code,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())?companyId:currentUser.getCompanyId());
        if(hazmat==null){
            throw new ApiException("危化品条码数据不存在");
        }
@@ -142,11 +155,15 @@
    }
    @Override
    public List<HzHazmatFlow> getAllHazmatFlowByHazmatId(Long hazmatId) {
    public List<HzHazmatFlow> getAllHazmatFlowByHazmatId(Long hazmatId,Long companyId) {
        SysUser currentUser=SecurityUtils.getLoginUser().getUser();
        checkUserAllowed(null,currentUser);
        //设置分表id
        IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
            IdTableNameHandler.setCurrentId(companyId);
        }else {
            //设置分表id
            IdTableNameHandler.setCurrentId(currentUser.getCompanyId());
        }
        HzHazmat hazmat=hazmatMapper.selectById(hazmatId);
        if(hazmat==null){
            throw new ApiException("危化品数据不存在");
@@ -162,8 +179,10 @@
            throw new ApiException("管理员不能操作");
        }
        if(hazmatFlow!=null){
            if(!Objects.equals(user.getCompanyId(), hazmatFlow.getCompanyId())){
                throw new ApiException("无权限操作其他企业数据");
            if (!user.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
                if(!Objects.equals(user.getCompanyId(), hazmatFlow.getCompanyId())){
                    throw new ApiException("无权限操作其他企业数据");
                }
            }
        }
    }