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());
|
}
|
}
|
}
|