下载资源前端资源详情
ManufacturerDatautility.zip
大小:1.99KB
价格:31积分
下载量:0
评分:
5.0
上传者:qq_59708493
更新日期:2025-09-22

ManufacturerDatautility.zip

资源文件列表(大概)

文件名
大小
ManufacturerDatautility.java
5.84KB

资源内容介绍

111
package ext.rwd.part.datautility;import java.io.File;import java.io.InputStream;import java.util.ArrayList;import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;import org.apache.poi.ss.usermodel.WorkbookFactory;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.ptc.core.components.beans.CreateAndEditWizBean;import com.ptc.core.components.descriptor.ModelContext;import com.ptc.core.components.factory.AbstractDataUtility;import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;import com.ptc.core.components.rendering.GuiComponent;import com.ptc.core.components.rendering.guicomponents.ComboBox;import com.ptc.core.meta.type.common.impl.DefaultTypeInstance;import com.ptc.core.ui.resources.ComponentMode;import com.ptc.netmarkets.util.beans.NmCommandBean;import ext.lang.PIExcelUtils;import ext.lang.PIStringUtils;import ext.pi.PIException;import ext.pi.core.PIAttributeHelper;import ext.pi.core.PIContentHelper;import ext.pi.core.PICoreHelper;import ext.pi.core.PIDocumentHelper;import wt.content.ApplicationData;import wt.content.ContentItem;import wt.content.ContentServerHelper;import wt.doc.WTDocument;import wt.fc.WTObject;import wt.part.WTPart;import wt.util.WTException;public class ManufacturerDatautility extends AbstractDataUtility {private static final String CLASSNAME = ManufacturerDatautility.class.getName();private static final Logger logger = LoggerFactory.getLogger(CLASSNAME);@Overridepublic Object getDataValue(String s, Object obj, ModelContext mc) throws WTException {NmCommandBean nmCommandBean = mc.getNmCommandBean();// 是否创建及编辑状态boolean bool = CreateAndEditWizBean.isCreateEditWizard(nmCommandBean);logger.debug(" >>>>>bool=" + bool);if (bool) {if (obj instanceof DefaultTypeInstance) {DefaultTypeInstance instance = (DefaultTypeInstance) obj;String oid = instance.getPersistenceIdentifier();logger.debug(">>>oid=" + oid);if (PIStringUtils.hasText(oid) && mc.getDescriptorMode().equals(ComponentMode.EDIT)) {WTObject wtobj = PICoreHelper.service.getWTObjectByOid(oid);if (wtobj != null && (wtobj instanceof WTPart)) {WTPart part = (WTPart) wtobj;String value = getValue(part, s);value = value == null ? "" : value;return getCom(s, obj, mc, value);}} else if (mc.getDescriptorMode().equals(ComponentMode.CREATE)) {return getCom(s, obj, mc, "");}}}return null;}/** * 构建文本框 * * @param s * @param obj * @param mc * @param value * @return * @throws WTException */private ArrayList<GuiComponent> getCom(String s, Object obj, ModelContext mc, String value) throws WTException {ArrayList<String> excelData = getExcelData();logger.debug(" >>>>excelData=" + excelData);ArrayList<GuiComponent> component = new ArrayList<GuiComponent>();if (excelData != null) {ArrayList<String> al = new ArrayList<>();al.add("");al.addAll(excelData);ComboBox combobox = new ComboBox();combobox.setId(s);// combobox.setName(s);combobox.setColumnName(AttributeDataUtilityHelper.getColumnName(s, obj, mc));combobox.setValues(al);combobox.setInternalValues(al);combobox.setSelected(value);combobox.setRequired(true);component.add(combobox);}return component;}/** * 获取属性值 * * @param p * @param compid * @return * @throws PIException */public static String getValue(WTPart p, String compid) throws PIException {return (String) PIAttributeHelper.service.getValue(p, compid);}/** * 获取Excel数据 * * @return * @throws Exception */public static ArrayList<String> getExcelData() throws WTException {ArrayList<String> list = new ArrayList<String>();try {WTDocument doc = PIDocumentHelper.service.findWTDocument("T000001");if (doc == null) {String templatePath = PICoreHelper.service.getCodebase()+ File.separator + "ext"+ File.separator + "rwd" + File.separator + "template" + File.separator + "生产厂家配置表.xlsx";File file = new File(templatePath);Workbook book = WorkbookFactory.create(file);Sheet sheet = book.getSheetAt(0);int lastRowNum = sheet.getLastRowNum();logger.debug(" >>>>lastRowNum=" + lastRowNum);for (int i = 0; i <= lastRowNum; i++) {Row row = PIExcelUtils.getRow(sheet, i + 1, true);Cell cell = PIExcelUtils.getCell(row, 0, true);String excelValue = PIExcelUtils.getCellValueAsString(cell, null);if (!PIStringUtils.hasText(excelValue)) {break;}list.add(excelValue);}if (book != null) {book.close();}} else {ContentItem content = PIContentHelper.service.findPrimaryContent(doc);if (content != null) {if (content instanceof ApplicationData) {ApplicationData data = (ApplicationData) content;InputStream is = ContentServerHelper.service.findContentStream(data);Workbook book = WorkbookFactory.create(is);Sheet sheet = book.getSheetAt(0);int lastRowNum = sheet.getLastRowNum();logger.debug(" >>>>lastRowNum=" + lastRowNum);for (int i = 0; i <= lastRowNum; i++) {Row row = PIExcelUtils.getRow(sheet, i + 1, true);Cell cell = PIExcelUtils.getCell(row, 0, true);String excelValue = PIExcelUtils.getCellValueAsString(cell, null);if (!PIStringUtils.hasText(excelValue)) {break;}list.add(excelValue);}if (book != null) {book.close();}}}}} catch (Exception e) {e.printStackTrace();}return list;}}

用户评论 (0)

发表评论

captcha