zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package com.shlanbao.tzsc.plugin.service.impl;
 
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.shlanbao.tzsc.base.mapping.MdEquipment;
import com.shlanbao.tzsc.base.mapping.SchCalendar;
import com.shlanbao.tzsc.pms.sch.calendar.service.CalendarServiceI;
import com.shlanbao.tzsc.utils.tools.ConfigUtil;
import com.shlanbao.tzsc.utils.tools.RedisUtil;
import com.shlanbao.tzsc.utils.tools.XmlUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.shlanbao.tzsc.base.model.Combobox;
import com.shlanbao.tzsc.base.service.BaseService;
import com.shlanbao.tzsc.init.BaseParams;
import com.shlanbao.tzsc.plugin.service.LoadComboboxServiceI;
import com.shlanbao.tzsc.pms.md.eqp.beans.EquipmentsBean;
import com.shlanbao.tzsc.pms.md.eqp.service.EquipmentsServiceI;
import com.shlanbao.tzsc.pms.md.eqpcategory.beans.MdEqpCategoryBean;
import com.shlanbao.tzsc.pms.md.eqpcategory.service.MdEqpCategoryServiceI;
import com.shlanbao.tzsc.pms.md.eqptype.beans.MdEqpTypeBean;
import com.shlanbao.tzsc.pms.md.eqptype.service.MdEqpTypeServiceI;
import com.shlanbao.tzsc.pms.md.fixCode.service.FixCodeServiceI;
import com.shlanbao.tzsc.pms.md.mat.beans.MatBean;
import com.shlanbao.tzsc.pms.md.mat.service.MatServiceI;
import com.shlanbao.tzsc.pms.md.matgrp.beans.MatGrpBean;
import com.shlanbao.tzsc.pms.md.matgrp.service.MatGrpServiceI;
import com.shlanbao.tzsc.pms.md.mattype.beans.MatTypeBean;
import com.shlanbao.tzsc.pms.md.mattype.service.MatTypeServiceI;
import com.shlanbao.tzsc.pms.md.shift.beans.ShiftBean;
import com.shlanbao.tzsc.pms.md.shift.service.ShiftServiceI;
import com.shlanbao.tzsc.pms.md.team.beans.TeamBean;
import com.shlanbao.tzsc.pms.md.team.service.TeamServiceI;
import com.shlanbao.tzsc.pms.md.unit.beans.UnitBean;
import com.shlanbao.tzsc.pms.md.unit.service.UnitServiceI;
import com.shlanbao.tzsc.pms.md.workshop.beans.WorkShopBean;
import com.shlanbao.tzsc.pms.md.workshop.service.WorkShopServiceI;
import com.shlanbao.tzsc.pms.sys.role.beans.RoleBean;
import com.shlanbao.tzsc.pms.sys.role.service.RoleServiceI;
import com.shlanbao.tzsc.utils.params.ComboboxType;
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
 
 
@Service
public class LoadComboboxServiceImpl extends BaseService implements LoadComboboxServiceI {
 
    @Autowired
    public FixCodeServiceI fixCodeService;
    @Autowired
    public RoleServiceI roleService;
    @Autowired
    public ShiftServiceI shiftService;
    @Autowired
    public TeamServiceI teamService;
    @Autowired
    public WorkShopServiceI workShopService;
    @Autowired
    public MatServiceI matService;
    @Autowired
    public MatTypeServiceI matTypeService;
    @Autowired
    public MatGrpServiceI matGrpService;
    @Autowired
    public UnitServiceI unitService;
    @Autowired
    public EquipmentsServiceI equipmentsService;
    @Autowired
    public MdEqpTypeServiceI eqpTypeServiceI;
    @Autowired
    public MdEqpCategoryServiceI categoryServiceI;
    @Autowired
    public CalendarServiceI calendarServiceI;
    @Override
    public void initCombobox(String scope) {
        try {
            //角色表
            if(scope.equalsIgnoreCase(ComboboxType.ALL)){
                RedisUtil.addMap("baseParams","ROLES", JSONArray.fromObject(roleService.getAllRoles(new RoleBean())).toString());
 
            }
            //查询所有基础数据
            if(scope.equalsIgnoreCase(ComboboxType.ALL)){
                RedisUtil.addMap("baseParams","FIXCODES",JSONArray.fromObject(fixCodeService.queryFixCode(null)).toString());
            }
            //班次下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.SHIFT)){
                List<ShiftBean> list=shiftService.queryAllShiftsForComboBox();
                Map<String,String> shiftMap = new HashMap<>();
                for (ShiftBean shiftBean : list){
                    shiftMap.put(shiftBean.getId(),shiftBean.getName());
                }
                RedisUtil.addMap("baseParams","SHIFT",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","SHIFTMAP",JSONObject.fromObject(shiftMap).toString());
                RedisUtil.addMap("baseParams","SHIFTCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //班组下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.TEAM)){
                List<TeamBean> list=teamService.queryAllTeamsForComboBox();
                Map<String,String> teamMap = new HashMap<>();
                for (TeamBean teamBean : list){
                    teamMap.put(teamBean.getId(),teamBean.getName());
                }
                RedisUtil.addMap("baseParams","TEAM",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","TEAMMAP",JSONObject.fromObject(teamMap).toString());
                RedisUtil.addMap("baseParams","TEAMCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //车间下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.WORKSHOP)){
                List<WorkShopBean> list=workShopService.queryAllWorkShopsForComboBox();
                BaseParams.setWorkShopCombobox(BeanConvertor.copyList(list, Combobox.class));
                BaseParams.setWorkShopLt(list);
            }
            //产品下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.MATPROD)){
                List<MatBean> list=matService.queryAllProdMat();
                RedisUtil.addMap("baseParams","MATPROD",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","MATPRODCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //滤棒成品下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.MATFILTER)){
                @SuppressWarnings("unchecked")
                List<MatBean> list=matService.getMatFiller();
                RedisUtil.addMap("baseParams","MATFILTER",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","MATFILTERCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //辅料滤棒下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.FLFILTER)){
                @SuppressWarnings("unchecked")
                List<MatBean> list=matService.getFlFiller();
                RedisUtil.addMap("baseParams","FLFILTER",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","FLFILTERCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
 
 
            //物料组下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.MATGRP)){
                List<MatGrpBean> list=matGrpService.queryAllMatGrpsForComboBox();
                RedisUtil.addMap("baseParams","MATGRP",JSONArray.fromObject(JSONArray.fromObject(list)).toString());
                RedisUtil.addMap("baseParams","MATGRPCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //物料类型下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.MATTYPE)){
                List<MatTypeBean> list=matTypeService.queryAllMatTypesForComboBox();
                RedisUtil.addMap("baseParams","MATTYPE",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","MATTYPECOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //物料单位下拉框
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.UNIT)){
                List<UnitBean> list=unitService.queryAllUnitsForComboBox();
                Map<String,String> unitMap = new HashMap<>();
                for (UnitBean unitBean : list){
                    unitMap.put(unitBean.getId(),unitBean.getName());
                }
                RedisUtil.addMap("baseParams","UNIT", JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","UNITMAP",JSONObject.fromObject(unitMap).toString());
                RedisUtil.addMap("baseParams","UNITCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //设备类型
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.EQPCATEGORY)){
                List<MdEqpCategoryBean> list=categoryServiceI.queryMdCategory();
                RedisUtil.addMap("baseParams","EQPCATEGORY",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","EQPCATEGORYCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //设备型号
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.EQPTYPE)){
                List<MdEqpTypeBean> eqptypelist = eqpTypeServiceI.queryMdType(null);
                RedisUtil.addMap("baseParams","EQPTYPE",JSONArray.fromObject(eqptypelist).toString());
                RedisUtil.addMap("baseParams","EQPTYPECOMBO",JSONArray.fromObject(BeanConvertor.copyList(eqptypelist, Combobox.class)).toString());
            }
            //所有设备
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLEQPS)){
                List<EquipmentsBean> eqplist = equipmentsService.queryAllEqpsForComboBox();
                RedisUtil.addMap("baseParams","ALLEQPS",JSONArray.fromObject(eqplist).toString());
                RedisUtil.addMap("baseParams","ALLEQPSCOMBO",JSONArray.fromObject(BeanConvertor.copyList(eqplist, Combobox.class)).toString());
            }
            //所有卷烟机
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLROLLERS)){
                List<EquipmentsBean> list=equipmentsService.queryAllPackersForComboBox(1);
                RedisUtil.addMap("baseParams","ROLLERS",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","ROLLERSCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //所有包装机
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLPACKERS)){
                List<EquipmentsBean> list=equipmentsService.queryAllPackersForComboBox(2);
                RedisUtil.addMap("baseParams","PACKERS",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","PACKERSCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //所有封箱机
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLBOXERS)){
                List<EquipmentsBean> list=equipmentsService.queryAllPackersForComboBox(3);
                RedisUtil.addMap("baseParams","BOXERS",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","BOXERSCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //所有成型机
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLFILTERS)){
                List<EquipmentsBean> list=equipmentsService.queryAllPackersForComboBox(4);
                RedisUtil.addMap("baseParams","FILTERS",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","FILTERSCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //所有发射机
            if(scope.equalsIgnoreCase(ComboboxType.ALL)||scope.equalsIgnoreCase(ComboboxType.ALLTRANSM)){
                List<EquipmentsBean> list=equipmentsService.queryAllPackersForComboBox(5);
                RedisUtil.addMap("baseParams","TRANSM",JSONArray.fromObject(list).toString());
                RedisUtil.addMap("baseParams","TRANSMCOMBO",JSONArray.fromObject(BeanConvertor.copyList(list, Combobox.class)).toString());
            }
            //获取wct下登录名对应的设备
            if(scope.equalsIgnoreCase(ComboboxType.ALL)){
                Map<String, List<MdEquipment>> userEqu = getUserEqu();
                if(userEqu!=null){
                    BaseParams.setWctEquMap(userEqu);
                }
            }
 
 
        } catch (Exception e) {
            log.error("初始数据系统基础数据异常", e);
        }
    }
 
 
    /**
     * 登录用户为键,用户下设备为值
     * @return
     */
    private Map<String, List<MdEquipment>> getUserEqu() {
        String xmlPath =ConfigUtil.class.getClassLoader().getResource("equipment_wct.xml").getPath();
        NodeList nodeList = XmlUtil.getRootNodes(xmlPath, "equipment");
        Map<String, List<MdEquipment>> map = new HashMap<>();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            MdEquipment equipment = new MdEquipment();
            equipment.setEquipmentCode(XmlUtil.getValueByNodeName(node, "code"));
            equipment.setWinUname(XmlUtil.getValueByNodeName(node, "winUname"));
            equipment.setEquipmentName(XmlUtil.getValueByNodeName(node, "name"));
            if(!map.containsKey(equipment.getWinUname())){
                List<MdEquipment>  list = new ArrayList<>();
                list.add(equipment);
                map.put(equipment.getWinUname(),list);
            }else {
                List<MdEquipment> list = map.get(equipment.getWinUname());
                list.add(equipment);
                map.put(equipment.getWinUname(),list);
            }
 
        }
        return map;
 
    }
 
 
 
    @Override
    public void getAllMatParams(){
        //保存缓存
        BaseParams.setAllMdMatParam(equipmentsService.getAllMdMatParamData());
    }
 
 
    @Override
    public void initShiftTeam() {
        List<SchCalendar> calendars = calendarServiceI.getNowCalendars();
        if (calendars!=null && calendars.size()>0){
            SchCalendar calendar = calendars.get(0);
            RedisUtil.addMap("shift","ID",calendar.getMdShift().getId());
            RedisUtil.addMap("shift","team",calendar.getMdTeam().getId());
        }
    }
}