zhangherong
2025-07-09 c800257cb6c8b45e7edc20e2e9018cd90b230806
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package org.jeecg.modules.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.mapper.BaseFactoryUserMapper;
import org.jeecg.modules.system.model.EamBaseFactoryIdModel;
import org.jeecg.modules.system.model.EamBaseFactoryIdModel;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description: 设备车间管理与用户
 * @Author: jeecg-boot
 * @Date:   2025-06-30
 * @Version: V1.0
 */
@Service
public class BaseFactoryUserServiceImpl extends ServiceImpl<BaseFactoryUserMapper, BaseFactoryUser> implements IBaseFactoryUserService {
    @Autowired
    private IBaseFactoryService iBaseFactoryService;
 
    /**
     * 根据指定用户id查询产线信息
     */
    @Override
    public List<EamBaseFactoryIdModel> queryEamBaseFactoryIdsOfUser(String userId){
        LambdaQueryWrapper<BaseFactoryUser> queryUserRepDep = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<BaseFactory> queryRepDep = new LambdaQueryWrapper<>();
        try {
            queryUserRepDep.eq(BaseFactoryUser::getUserId, userId);
            List<String> repRepDepIdList = new ArrayList<>();
            List<EamBaseFactoryIdModel> repDepIdModelList = new ArrayList<>();
            List<BaseFactoryUser> userRepDepList = this.list(queryUserRepDep);
            if (userRepDepList != null && !userRepDepList.isEmpty()) {
                for (BaseFactoryUser BaseFactoryUser : userRepDepList) {
                    repRepDepIdList.add(BaseFactoryUser.getFactoryId());
                }
                queryRepDep.in(BaseFactory::getId, repRepDepIdList);
                List<BaseFactory> repDepList = iBaseFactoryService.list(queryRepDep);
                if (repDepList != null && !repDepList.isEmpty()) {
                    for (BaseFactory BaseFactory : repDepList) {
                        repDepIdModelList.add(new EamBaseFactoryIdModel().convertByUserProduction(BaseFactory));
                    }
                }
                return repDepIdModelList;
            }
        } catch (Exception e) {
            e.fillInStackTrace();
        }
        return null;
    }
 
    /**
     * 根据指定用户id查询EAM中心信息
     */
    @Override
    public List<String> queryEamCenterIdsByUserId(String userId){
        LambdaQueryWrapper<BaseFactoryUser> factoryUserLambdaQueryWrapper=new LambdaQueryWrapper<>();
        factoryUserLambdaQueryWrapper.eq(BaseFactoryUser::getUserId, userId);
        factoryUserLambdaQueryWrapper.exists("select 1 from eam_base_factory b where b.id=eam_base_factory_user.factory_id and b.del_flag=0");
        List<BaseFactoryUser> baseFactoryUsers=this.list(factoryUserLambdaQueryWrapper);
        List<String> eamCenterIds=new ArrayList<>();
        if(baseFactoryUsers!=null&& !baseFactoryUsers.isEmpty()) {
            for (BaseFactoryUser baseFactoryUser : baseFactoryUsers) {
                eamCenterIds.add(baseFactoryUser.getFactoryId());
            }
        }
        return eamCenterIds;
    }
 
    /**
     * 添加单个用户与一组中心
     * @param userId
     * @param factoryIds
     */
    @Override
    public void addUserFactory(String userId, String factoryIds){
        if (factoryIds.contains(",")){
            //先查询
            List<String> eamCenterIds=this.queryEamCenterIdsByUserId(userId);
            if (eamCenterIds != null && !eamCenterIds.isEmpty()) {
                for (String eamCenterId : eamCenterIds) {
                    this.remove(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, userId).eq(BaseFactoryUser::getFactoryId, eamCenterId));
                }
            }
            String [] factoryIdArray=factoryIds.split(",");
            for(String factoryId:factoryIdArray){
                BaseFactoryUser baseFactoryUser=new BaseFactoryUser();
                baseFactoryUser.setUserId(userId);
                baseFactoryUser.setFactoryId(factoryId);
                this.save(baseFactoryUser);
            }
        }
    }
}