parent
10e99ce87b
commit
96eac805ed
@ -1,8 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
@ -0,0 +1,347 @@
|
||||
package com.connor.chint.sap2.dy.createElectricalBOM;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.chint.plm.common.context.ApiContext;
|
||||
import com.chint.plm.common.util.ArrayUtils;
|
||||
import com.chint.plm.common.util.HttpUtils;
|
||||
import com.chint.plm.common.util.LoggerUtils;
|
||||
import com.chint.plm.common.util.StringUtils;
|
||||
import com.connor.chint.sap2.dy.createElectricalBOM.bean.CcemEb;
|
||||
import com.connor.chint.sap2.util.KUtil;
|
||||
import com.connor.chint.sap2.util.MyProgressBarCompent;
|
||||
import com.connor.chint.sap2.util.POIUtil;
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFOperation;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentContextList;
|
||||
import com.teamcenter.rac.kernel.TCComponentFolder;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemType;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
import com.teamcenter.services.rac.cad.StructureManagementService;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.AttributesInfo;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.CreateOrUpdateRelativeStructureInfo;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.CreateOrUpdateRelativeStructurePref;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.CreateOrUpdateRelativeStructureResponse;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.RelOccInfo;
|
||||
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.RelativeStructureChildInfo;
|
||||
|
||||
/**
|
||||
* 提取深化电气BOM
|
||||
*
|
||||
*/
|
||||
public class DYSHCreateElectricalBOMOperationV2 extends AbstractAIFOperation {
|
||||
|
||||
private AbstractAIFApplication app;
|
||||
|
||||
public DYSHCreateElectricalBOMOperationV2(AbstractAIFApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOperation() throws Exception {
|
||||
MyProgressBarCompent my = null;
|
||||
try {
|
||||
TCComponent project = null;
|
||||
TCComponent folder = null;
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
InterfaceAIFComponent target = app.getTargetComponent();
|
||||
if (target == null || !(target instanceof TCComponent)) {
|
||||
return;
|
||||
}
|
||||
String type = target.getType();
|
||||
if (type.equals("ZT2_ProjectItem")) {
|
||||
project = (TCComponent) target;
|
||||
String zt2_WBSNo = project.getProperty("zt2_WBSNo");
|
||||
}
|
||||
if (project == null) {
|
||||
MessageBox.post("请选择项目对象", "", 2);
|
||||
return;
|
||||
}
|
||||
TCComponentFolder xxzx_folder = KUtil.getXMZXFolderFromProject(project);
|
||||
if (xxzx_folder == null) {
|
||||
MessageBox.post("未找到项目执行文件夹,请检查项目数据 ", "", 2);
|
||||
return;
|
||||
}
|
||||
AIFComponentContext[] childs = xxzx_folder.getChildren();
|
||||
for (int i = 0, len = childs.length; i < len; i++) {
|
||||
folder = (TCComponent) childs[i].getComponent();
|
||||
if (folder.getProperty("object_name").contains("电气设计") && folder instanceof TCComponentFolder) {
|
||||
break;
|
||||
}
|
||||
folder = null;
|
||||
}
|
||||
if (folder == null) {
|
||||
MessageBox.post("未找到电气设计文件夹,请检查项目数据 ", "", 2);
|
||||
return;
|
||||
}
|
||||
my = new MyProgressBarCompent("", "正在提取项目BOM信息......");
|
||||
String projectId = project.getProperty("item_id");
|
||||
String zt2_WBSNo = project.getProperty("zt2_WBSNo");
|
||||
// 发起提取BOM请求
|
||||
String cadUrl = ApiContext.getApiUrl(session, "CHINT_EX_CADTOOL_URL");
|
||||
String urlString = cadUrl + "/api/PLM/PullProject";
|
||||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
paramMap.put("plmId", projectId);
|
||||
String resp = HttpUtils.get(urlString, paramMap);
|
||||
try {
|
||||
JSONObject respObject = JSONObject.parseObject(resp);
|
||||
if (respObject.containsKey("isOK") && respObject.getBoolean("isOK")) {
|
||||
JSONObject dataObject = respObject.getJSONObject("data");
|
||||
JSONArray products = dataObject.getJSONArray("products");
|
||||
if (products != null && products.size() > 0) {
|
||||
TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent("Part");
|
||||
for (int i = 0; i < products.size(); i++) {
|
||||
JSONObject product = products.getJSONObject(i);
|
||||
String factoryId = product.getString("factoryId");
|
||||
// String flowNo = product.getString("flowNo");
|
||||
JSONArray items = product.getJSONArray("items");
|
||||
if (items != null && items.size() > 0) {
|
||||
// 在 项目执行/电气设计 下,创建固定单元
|
||||
String objectName = "固定单元";
|
||||
int index = getTypeNumber(session, "9900000135", zt2_WBSNo);
|
||||
// 出厂编号
|
||||
List<TCComponent> factoryNoComps = new ArrayList<>();
|
||||
List<String> factoryNos = getFactoryNos(factoryId);
|
||||
for (String factoryNo : factoryNos) {
|
||||
Map<String, String> queryCondition = new HashMap<>();
|
||||
queryCondition.put("fid", factoryNo);
|
||||
// 查询出厂编号
|
||||
TCComponentContextList contextList = KUtil.query(session, "chint_query_FactoryNo", queryCondition);
|
||||
if (contextList.getListCount() > 0) {
|
||||
TCComponent comp = (TCComponent) contextList.get(0).getComponent();
|
||||
if (comp instanceof TCComponentItem) {
|
||||
TCComponentItem item = (TCComponentItem) comp;
|
||||
factoryNoComps.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
// BOM
|
||||
CcemEb parent = new CcemEb();
|
||||
List<CcemEb> bomChilds = new ArrayList<CcemEb>();
|
||||
Map<String, TCComponentItemRevision> partItemRevMaps = new LinkedHashMap<String, TCComponentItemRevision>();
|
||||
for (int j = 0; j < items.size(); j++) {
|
||||
JSONObject item = items.getJSONObject(j);
|
||||
String code = item.getString("code");
|
||||
BigDecimal quantity = item.getBigDecimal("quantity").setScale(2, RoundingMode.HALF_UP);
|
||||
Map<String, String> queryCondition = new HashMap<>();
|
||||
queryCondition.put("ID", code);
|
||||
// 查询零件
|
||||
TCComponentContextList contextList = KUtil.query(session, "chint_query_item", queryCondition);
|
||||
if (contextList.getListCount() > 0) {
|
||||
TCComponent comp = (TCComponent) contextList.get(0).getComponent();
|
||||
if (comp instanceof TCComponentItemRevision) {
|
||||
TCComponentItemRevision partItemRev = (TCComponentItemRevision) comp;
|
||||
System.out.print(partItemRev);
|
||||
partItemRevMaps.put(code, partItemRev);
|
||||
}
|
||||
}
|
||||
CcemEb ccemEb = new CcemEb();
|
||||
ccemEb.setZt2_MaterialNo(code);
|
||||
ccemEb.setEbQty(quantity.toString());
|
||||
ccemEb.setBl_sequence_no("");
|
||||
ccemEb.setBl_ref_designator("");
|
||||
bomChilds.add(ccemEb);
|
||||
}
|
||||
parent.setChilds(bomChilds);
|
||||
// 创建固定单元
|
||||
String zt2_MaterialNo = "9900000135-";
|
||||
// 物料分类码
|
||||
String pmpcCode = "990101002";
|
||||
TCComponentItemRevision partItmeRevision = createPart(session, folder, factoryNoComps, itemType,
|
||||
objectName, zt2_WBSNo, zt2_MaterialNo + String.format("%05d", index), pmpcCode);
|
||||
// 创建固定单元下的视图BOM
|
||||
int p_size = 1;
|
||||
createBOM(session, parent, partItmeRevision, partItemRevMaps, p_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
my.setVisible(false);
|
||||
MessageBox.post("(深化)电气提取BOM成功", "", 2);
|
||||
} else {
|
||||
my.setVisible(false);
|
||||
MessageBox.post("调用接口响应:" + respObject.getString("message"), "", 2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
my.setVisible(false);
|
||||
MessageBox.post("处理异常:" + e.getMessage() + "接口响应:" + resp, "", 2);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
KUtil.closeMyProgressBar(my);
|
||||
e.printStackTrace();
|
||||
MessageBox.post("异常:" + e.getMessage(), "", 2);
|
||||
}
|
||||
}
|
||||
|
||||
public TCComponentItemRevision createPart(TCSession session, TCComponent folder, List<TCComponent> factoryNos, TCComponentItemType itemType,
|
||||
String object_name, String zt2_WBSNo, String zt2_MaterialNo, String pmpcCode) throws Exception {
|
||||
// 创建零件
|
||||
String item_id = itemType.getNewID();
|
||||
TCComponentItem item = itemType.create(item_id, "A", "Part", object_name, null, null);
|
||||
item.setProperty("zt2_unit", "TAI");
|
||||
// 添加内容
|
||||
folder.add("contents", item);
|
||||
// 物料编码
|
||||
item.getLatestItemRevision().setProperty("zt2_MaterialNo", zt2_MaterialNo);
|
||||
// WBS号
|
||||
item.getLatestItemRevision().setProperty("zt2_WBSNo", zt2_WBSNo);
|
||||
// 基本数量
|
||||
item.getLatestItemRevision().setProperty("zt2_Quantity", "1");
|
||||
// item.getLatestItemRevision().setProperty("zt2_unit", "TAI");
|
||||
// 物料分类码
|
||||
item.getLatestItemRevision().setProperty("zt2_ClassificationCode", pmpcCode);
|
||||
TCComponentItemRevision rev = item.getLatestItemRevision();
|
||||
// 添加出厂编码
|
||||
if (factoryNos.size() > 0) {
|
||||
rev.add("ZT2_FactoryNumber", factoryNos);
|
||||
}
|
||||
return rev;
|
||||
}
|
||||
|
||||
private void createBOM(TCSession session, CcemEb parent, TCComponentItemRevision rev, Map<String, TCComponentItemRevision> partItemRevMaps, int p_size) {
|
||||
List<CcemEb> childs = parent.getChilds();
|
||||
if (childs.size() == 0)
|
||||
return;
|
||||
// 排序
|
||||
Collections.sort(childs, new Comparator<CcemEb>() {
|
||||
@Override
|
||||
public int compare(CcemEb o1, CcemEb o2) {
|
||||
return POIUtil.getIntValue(o1.getBl_sequence_no()) - POIUtil.getIntValue(o2.getBl_sequence_no());
|
||||
}
|
||||
});
|
||||
// 创建结构子集
|
||||
List<RelativeStructureChildInfo> childInfos = new ArrayList<>();
|
||||
AttributesInfo attr, attr1, attr2;
|
||||
for (int i = 0, len = childs.size(); i < len; i++) {
|
||||
// 子集信息
|
||||
RelativeStructureChildInfo childInfo = new RelativeStructureChildInfo();
|
||||
RelOccInfo occInfo = new RelOccInfo();
|
||||
// 数量
|
||||
attr = new AttributesInfo();
|
||||
attr.name = "bl_quantity";
|
||||
attr.value = POIUtil.getIntValue(childs.get(i).getEbQty()) * p_size + "";
|
||||
// 查找编号
|
||||
attr1 = new AttributesInfo();
|
||||
attr1.name = "bl_sequence_no";
|
||||
attr1.value = (i + 1) * 10 + "";
|
||||
// 代号
|
||||
attr2 = new AttributesInfo();
|
||||
attr2.name = "bl_ref_designator";
|
||||
attr2.value = childs.get(i).getBl_ref_designator();
|
||||
occInfo.attrsToSet = new AttributesInfo[] { attr, attr1, attr2 };
|
||||
childInfo.child = partItemRevMaps.get(childs.get(i).getZt2_MaterialNo());
|
||||
childInfo.occInfo = occInfo;
|
||||
childInfos.add(childInfo);
|
||||
}
|
||||
// 保存相关的结构
|
||||
saveRelativeStructure(session, rev, childInfos);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void saveRelativeStructure(TCSession session, TCComponentItemRevision parent, List<RelativeStructureChildInfo> childInfos) {
|
||||
StructureManagementService service = StructureManagementService.getService(session);
|
||||
// 创建或修改相关的结构
|
||||
CreateOrUpdateRelativeStructurePref structurePref = new CreateOrUpdateRelativeStructurePref();
|
||||
CreateOrUpdateRelativeStructureInfo structureInfo = new CreateOrUpdateRelativeStructureInfo();
|
||||
structureInfo.childInfo = childInfos.toArray(new RelativeStructureChildInfo[] {});
|
||||
structureInfo.parent = parent;
|
||||
structureInfo.precise = false;
|
||||
CreateOrUpdateRelativeStructureResponse resp;
|
||||
try {
|
||||
resp = service.createOrUpdateRelativeStructure(new CreateOrUpdateRelativeStructureInfo[] { structureInfo }, "view", true, structurePref);
|
||||
KUtil.throwServiceDataError(resp.serviceData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LoggerUtils.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static int getTypeNumber(TCSession session, String type, String zt2_WBSNo) throws Exception {
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
fields.put("WBS号", zt2_WBSNo);
|
||||
fields.put("物料编码", type + "-*");
|
||||
TCComponentContextList querys = KUtil.query(session, "查询物料", fields);
|
||||
List<InterfaceAIFComponent> list = querys.toComponentVector();
|
||||
int size = list.size();
|
||||
Collections.sort(list, new Comparator<InterfaceAIFComponent>() {
|
||||
@Override
|
||||
public int compare(InterfaceAIFComponent o1, InterfaceAIFComponent o2) {
|
||||
try {
|
||||
return o2.getProperty("zt2_MaterialNo").compareTo(o1.getProperty("zt2_MaterialNo"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
if (size > 0) {
|
||||
String zt2_MaterialNo = list.get(0).getProperty("zt2_MaterialNo");
|
||||
int index = zt2_MaterialNo.indexOf("-");
|
||||
if (index != -1) {
|
||||
int value = POIUtil.getIntValue(zt2_MaterialNo.substring(index + 1));
|
||||
return value == 0 ? 1 : value + 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static List<String> getFactoryNos(String factoryId) {
|
||||
List<String> factoryNos = new ArrayList<>(64);
|
||||
if (StringUtils.isNotBlank(factoryId)) {
|
||||
String[] noStrs = factoryId.split(",");
|
||||
if (ArrayUtils.isNotEmpty(noStrs)) {
|
||||
for (String str : noStrs) {
|
||||
String[] nos = str.split("~");
|
||||
if (ArrayUtils.isNotEmpty(nos)) {
|
||||
if (nos.length == 1) {
|
||||
factoryNos.add(nos[0]);
|
||||
} else if (nos.length == 2) {
|
||||
String one = nos[0];
|
||||
String two = nos[1];
|
||||
String prefix = one.substring(0, one.length() - 8);
|
||||
String serial = one.substring(one.length() - 8, one.length());
|
||||
int serialNum = Integer.parseInt(serial);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
String next = prefix + (serialNum + i);
|
||||
factoryNos.add(next);
|
||||
if (next.equals(two)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("出厂编号格式不催:" + factoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return factoryNos;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> nos = getFactoryNos("DX323041400");
|
||||
System.out.println(nos.size());
|
||||
nos = getFactoryNos("DX323041400~DX323041432");
|
||||
System.out.println(nos.size());
|
||||
nos = getFactoryNos("DX323041400~DX323041432,DX323041388~DX323041399");
|
||||
System.out.println(nos.size());
|
||||
}
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package com.connor.chint.sap2.electrical_task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.chint.plm.common.context.ApiContext;
|
||||
import com.chint.plm.common.util.HttpUtils;
|
||||
import com.connor.chint.sap2.util.KUtil;
|
||||
import com.connor.chint.sap2.util.MyProgressBarCompent;
|
||||
import com.connor.chint.sap2.util.ZYFactoryUtil;
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFOperation;
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentFolder;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
/**
|
||||
* 深化 电气任务下发
|
||||
* @since 2024-05-10
|
||||
*/
|
||||
public class DYSHElectricalTasksOperationV2 extends AbstractAIFOperation {
|
||||
|
||||
private AbstractAIFApplication app;
|
||||
|
||||
public DYSHElectricalTasksOperationV2(AbstractAIFApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeOperation() throws Exception {
|
||||
MyProgressBarCompent my = null;
|
||||
try {
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
InterfaceAIFComponent target = app.getTargetComponent();
|
||||
if (target == null || !target.getType().equals("ZT2_ProjectItem")) {
|
||||
MessageBox.post("请选择项目对象", "", 2);
|
||||
return;
|
||||
}
|
||||
my = new MyProgressBarCompent("任务下发", "(深化)电气任务传递中......");
|
||||
// 项目对象
|
||||
TCComponent project = (TCComponent) target;
|
||||
// 产成品文件夹
|
||||
TCComponentFolder ccpFolder = KUtil.getCCPFolderFromProject(project);
|
||||
if (ccpFolder == null) {
|
||||
MessageBox.post("未找到产成品信息,请检查项目数据", "", 2);
|
||||
return;
|
||||
}
|
||||
// 项目基本信息
|
||||
String itemId = project.getProperty("item_id");
|
||||
String projectCode = project.getProperty("zt2_ProjectNo");
|
||||
String projectName = project.getProperty("object_name");
|
||||
// 同一前缀产成品
|
||||
Map<String, String> ccp_types = new HashMap<>(16);
|
||||
// 产成品和出厂编号关系
|
||||
Map<String, List<String>> ccp_factoryNos = new HashMap<>(16);
|
||||
// 产成品名称
|
||||
Map<String, String> ccp_names = new HashMap<>(16);
|
||||
// 出厂编号:物料编码
|
||||
Map<String, String> map_factory_ccp = new HashMap<>(32);
|
||||
// 产成品文件夹子集
|
||||
AIFComponentContext[] ccpChilds = ccpFolder.getChildren();
|
||||
for (int i = 0, len = ccpChilds.length; i < len; i++) {
|
||||
if (ccpChilds[i].getComponent().getType().equals("Part")) {
|
||||
// 版本对象
|
||||
TCComponentItemRevision rev = ((TCComponentItem) ccpChilds[i].getComponent()).getLatestItemRevision();
|
||||
String zt2_MaterialNo = rev.getProperty("zt2_MaterialNo");
|
||||
int index = zt2_MaterialNo.indexOf("-");
|
||||
// 主物料编码
|
||||
String type = index > -1 ? zt2_MaterialNo.substring(0, index) : zt2_MaterialNo;
|
||||
// 出厂编码
|
||||
TCComponent[] meops = rev.getRelatedComponents("ZT2_FactoryNumber");
|
||||
// 产成品名称
|
||||
String object_name = rev.getProperty("object_name");
|
||||
ccp_names.put(zt2_MaterialNo, object_name);
|
||||
if (ccp_types.containsKey(type)) {
|
||||
String value = ccp_types.get(type);
|
||||
if (zt2_MaterialNo.compareTo(value) < 0) {
|
||||
ccp_types.put(type, zt2_MaterialNo);
|
||||
}
|
||||
List<String> factoryNos = ccp_factoryNos.get(type);
|
||||
for (int j = 0; j < meops.length; j++) {
|
||||
String factoryID = meops[j].getProperty("item_id");
|
||||
map_factory_ccp.put(factoryID, zt2_MaterialNo);
|
||||
if (!factoryNos.contains(factoryID)) {
|
||||
factoryNos.add(factoryID);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ccp_types.put(type, zt2_MaterialNo);
|
||||
List<String> factoryNos = new ArrayList<>();
|
||||
for (int j = 0; j < meops.length; j++) {
|
||||
String factoryID = meops[j].getProperty("item_id");
|
||||
factoryNos.add(factoryID);
|
||||
map_factory_ccp.put(factoryID, zt2_MaterialNo);
|
||||
}
|
||||
ccp_factoryNos.put(type, factoryNos);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按物料排序
|
||||
List<String> keys = new java.util.ArrayList<>(ccp_types.keySet());
|
||||
Collections.sort(keys);
|
||||
if (ccp_types.size() > 0) {
|
||||
// 组织请求参数
|
||||
JSONObject param = new JSONObject();
|
||||
JSONArray products = new JSONArray();
|
||||
param.put("PLMId", itemId);
|
||||
param.put("Code", projectCode);
|
||||
param.put("Name", projectName);
|
||||
for (Map.Entry<String, String> entry : ccp_types.entrySet()) {
|
||||
String materialCode = entry.getKey();
|
||||
String materialCodePart = entry.getValue();
|
||||
List<String> factoryNos = ccp_factoryNos.get(materialCode);
|
||||
String factoryId = "";
|
||||
if (factoryNos.size() > 0) {
|
||||
Collections.sort(factoryNos);
|
||||
if (factoryNos.size() == 1) {
|
||||
factoryId = factoryNos.get(0);
|
||||
} else {
|
||||
factoryId = ZYFactoryUtil.getFactory2(factoryNos, 4, "~");
|
||||
}
|
||||
}
|
||||
JSONObject product = new JSONObject();
|
||||
product.put("PartId", materialCode);
|
||||
product.put("PartName", ccp_names.get(materialCodePart));
|
||||
product.put("FactoryId", factoryId);
|
||||
product.put("Status", "0");
|
||||
product.put("FlowNo", "-00001");
|
||||
products.add(product);
|
||||
}
|
||||
param.put("Products", products);
|
||||
// 发起任务下发请求
|
||||
String cadUrl = ApiContext.getApiUrl(session, "CHINT_EX_CADTOOL_URL");
|
||||
String urlString = cadUrl + "/api/PLM/ReceiveProject";
|
||||
String resp = HttpUtils.post(urlString, param.toString());
|
||||
try {
|
||||
JSONObject respObject = JSONObject.parseObject(resp);
|
||||
if (respObject.containsKey("isOK") && respObject.getBoolean("isOK")) {
|
||||
my.setVisible(false);
|
||||
MessageBox.post("(深化)电气任务下发成功", "", 2);
|
||||
} else {
|
||||
my.setVisible(false);
|
||||
MessageBox.post("调用接口响应:" + respObject.getString("message"), "", 2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
my.setVisible(false);
|
||||
MessageBox.post("调用接口响应:" + resp, "", 2);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
my.setVisible(false);
|
||||
MessageBox.post("未找到产成品信息,请检查项目数据", "", 2);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
KUtil.closeMyProgressBar(my);
|
||||
e.printStackTrace();
|
||||
MessageBox.post("异常:" + e.getMessage(), "", 2);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.connor.chint.sap2.gylxgs;
|
||||
|
||||
public class GylxGsBatchImportBean {
|
||||
|
||||
// 序号
|
||||
private int no;
|
||||
|
||||
// 图样代号
|
||||
private String tydh;
|
||||
|
||||
// 工艺号
|
||||
private String gyh;
|
||||
|
||||
// 工序号
|
||||
private String gxh;
|
||||
|
||||
// 人工时间
|
||||
private Double rgTime;
|
||||
|
||||
// 机器时间
|
||||
private Double jqTime;
|
||||
|
||||
// 准备时间
|
||||
private Double zbTime;
|
||||
|
||||
public int getNo() {
|
||||
return no;
|
||||
}
|
||||
|
||||
public void setNo(int no) {
|
||||
this.no = no;
|
||||
}
|
||||
|
||||
public String getTydh() {
|
||||
return tydh;
|
||||
}
|
||||
|
||||
public void setTydh(String tydh) {
|
||||
this.tydh = tydh;
|
||||
}
|
||||
|
||||
public String getGyh() {
|
||||
return gyh;
|
||||
}
|
||||
|
||||
public void setGyh(String gyh) {
|
||||
this.gyh = gyh;
|
||||
}
|
||||
|
||||
public String getGxh() {
|
||||
return gxh;
|
||||
}
|
||||
|
||||
public void setGxh(String gxh) {
|
||||
this.gxh = gxh;
|
||||
}
|
||||
|
||||
public Double getRgTime() {
|
||||
return rgTime;
|
||||
}
|
||||
|
||||
public void setRgTime(Double rgTime) {
|
||||
this.rgTime = rgTime;
|
||||
}
|
||||
|
||||
public Double getJqTime() {
|
||||
return jqTime;
|
||||
}
|
||||
|
||||
public void setJqTime(Double jqTime) {
|
||||
this.jqTime = jqTime;
|
||||
}
|
||||
|
||||
public Double getZbTime() {
|
||||
return zbTime;
|
||||
}
|
||||
|
||||
public void setZbTime(Double zbTime) {
|
||||
this.zbTime = zbTime;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.connor.chint.sap2.gylxgs;
|
||||
|
||||
import com.connor.chint.sap2.KCommand;
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
|
||||
/**
|
||||
* 批量导入工艺路线与工时
|
||||
*
|
||||
*/
|
||||
public class GylxGsBatchImportCommand extends KCommand {
|
||||
|
||||
public GylxGsBatchImportCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
|
||||
super(app, commandId, actionInfo);
|
||||
this.setRunnable(new GylxGsBatchImportDialog(app));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.connor.chint.sap2.stylesheet;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
public class ComboBoxColumnRender extends DefaultTableCellRenderer {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JComboBox<String> comboBox;
|
||||
|
||||
public ComboBoxColumnRender(Object[] values) {
|
||||
super();
|
||||
|
||||
comboBox = new JComboBox<>();
|
||||
comboBox.addItem("");
|
||||
for(Object s : values)
|
||||
comboBox.addItem("" + s);
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
|
||||
comboBox.setSelectedItem(value == null ? "" : value.toString());
|
||||
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.connor.chint.sap2.util;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import com.chint.plm.common.util.StringUtils;
|
||||
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
||||
|
||||
public class ConfirmDialogDateUtil extends AbstractAIFDialog {
|
||||
|
||||
JTextField date;
|
||||
String dateText;
|
||||
|
||||
boolean flag = false;
|
||||
private JButton b_ok;
|
||||
private JButton b_ch;
|
||||
private String text;
|
||||
private String title;
|
||||
private String retult = "-1";
|
||||
|
||||
public ConfirmDialogDateUtil(AbstractAIFDialog parent, String title, String text, int initUI2) {
|
||||
super(parent, true);
|
||||
this.text = text;
|
||||
this.title = title;
|
||||
initUI2(null);
|
||||
addListener();
|
||||
showDialog();
|
||||
}
|
||||
|
||||
public ConfirmDialogDateUtil(AbstractAIFDialog parent, String title, String text) {
|
||||
super(parent, true);
|
||||
this.text = text;
|
||||
this.title = title;
|
||||
initUI(null);
|
||||
addListener();
|
||||
showDialog();
|
||||
}
|
||||
|
||||
public ConfirmDialogDateUtil(String title, String text, Dimension dim) {
|
||||
super(true);
|
||||
this.text = text;
|
||||
this.title = title;
|
||||
initUI(dim);
|
||||
addListener();
|
||||
showDialog();
|
||||
}
|
||||
|
||||
public ConfirmDialogDateUtil(AbstractAIFDialog parent, String title, String text, Dimension dim, String dateText) {
|
||||
super(true);
|
||||
this.text = text;
|
||||
this.title = title;
|
||||
this.dateText = dateText;
|
||||
initUI(dim);
|
||||
addListener();
|
||||
showDialog();
|
||||
}
|
||||
|
||||
private void initUI(Dimension dim) {
|
||||
this.setTitle(title);
|
||||
if (dim == null) {
|
||||
this.setPreferredSize(new Dimension(250, 200));
|
||||
} else {
|
||||
this.setPreferredSize(dim);
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
|
||||
JLabel label = new JLabel(text);
|
||||
panel.add(label);
|
||||
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 20));
|
||||
date = new JTextField();
|
||||
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date time = new Date();
|
||||
String nowDate = sdfDate.format(time);
|
||||
if (StringUtils.isBlank(dateText)) {
|
||||
date.setText(nowDate);
|
||||
} else {
|
||||
date.setText(dateText);
|
||||
}
|
||||
date.setEditable(false);
|
||||
DateChooser dateChooser = DateChooser.getInstance("yyyy-MM-dd");
|
||||
dateChooser.register(date);
|
||||
panel1.add(date);
|
||||
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20));
|
||||
b_ok = new JButton("ÊÇ");
|
||||
b_ch = new JButton("·ñ");
|
||||
panel2.add(b_ok);
|
||||
panel2.add(b_ch);
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(BorderLayout.NORTH, panel);
|
||||
this.add(BorderLayout.CENTER, panel1);
|
||||
this.add(BorderLayout.SOUTH, panel2);
|
||||
}
|
||||
|
||||
private void initUI2(Dimension dim) {
|
||||
this.setTitle(title);
|
||||
if (dim == null) {
|
||||
this.setPreferredSize(new Dimension(400, 150));
|
||||
} else {
|
||||
this.setPreferredSize(dim);
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 20));
|
||||
JLabel label = new JLabel(text);
|
||||
panel.add(label);
|
||||
this.setLayout(new BorderLayout());
|
||||
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 20));
|
||||
b_ok = new JButton("È·¶¨");
|
||||
b_ch = new JButton("·ñ");
|
||||
panel2.add(b_ok);
|
||||
this.add(BorderLayout.CENTER, panel);
|
||||
this.add(BorderLayout.SOUTH, panel2);
|
||||
}
|
||||
|
||||
private void addListener() {
|
||||
b_ok.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
flag = true;
|
||||
retult = "1";
|
||||
disposeDialog();
|
||||
}
|
||||
});
|
||||
b_ch.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
flag = false;
|
||||
retult = "0";
|
||||
disposeDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getDateText() {
|
||||
return date.getText();
|
||||
}
|
||||
|
||||
public boolean getResult() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public String getRetult2() {
|
||||
return retult;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,698 @@
|
||||
package com.connor.chint.sap2.util;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.PopupFactory;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.AncestorEvent;
|
||||
import javax.swing.event.AncestorListener;
|
||||
|
||||
public class DateChooser extends JPanel {
|
||||
private static final long serialVersionUID = 4529266044762990227L;
|
||||
private Date initDate;
|
||||
private Calendar now;
|
||||
private Calendar select;
|
||||
private JPanel monthPanel;
|
||||
private DateChooser.JP1 jp1;
|
||||
private DateChooser.JP2 jp2;
|
||||
private DateChooser.JP3 jp3;
|
||||
private DateChooser.JP4 jp4;
|
||||
private Font font;
|
||||
private final DateChooser.LabelManager lm;
|
||||
private SimpleDateFormat sdf;
|
||||
private boolean isShow;
|
||||
private Popup pop;
|
||||
private JComponent showDate;
|
||||
|
||||
public static DateChooser getInstance() {
|
||||
return new DateChooser();
|
||||
}
|
||||
|
||||
public static DateChooser getInstance(Date date) {
|
||||
return new DateChooser(date);
|
||||
}
|
||||
|
||||
public static DateChooser getInstance(String format) {
|
||||
return new DateChooser(format);
|
||||
}
|
||||
|
||||
public static DateChooser getInstance(Date date, String format) {
|
||||
return new DateChooser(date, format);
|
||||
}
|
||||
|
||||
private DateChooser() {
|
||||
this(new Date());
|
||||
}
|
||||
|
||||
private DateChooser(Date date) {
|
||||
this(date, "yyyy年MM月dd日");
|
||||
}
|
||||
|
||||
private DateChooser(String format) {
|
||||
this(new Date(), format);
|
||||
}
|
||||
|
||||
private DateChooser(Date date, String format) {
|
||||
this.now = Calendar.getInstance();
|
||||
this.font = new Font("宋体", 0, 12);
|
||||
this.lm = new DateChooser.LabelManager();
|
||||
this.isShow = false;
|
||||
this.initDate = date;
|
||||
this.sdf = new SimpleDateFormat(format);
|
||||
this.select = Calendar.getInstance();
|
||||
this.select.setTime(this.initDate);
|
||||
this.initPanel();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean b) {
|
||||
super.setEnabled(b);
|
||||
this.showDate.setEnabled(b);
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.select.getTime();
|
||||
}
|
||||
|
||||
public String getStrDate() {
|
||||
return this.sdf.format(this.select.getTime());
|
||||
}
|
||||
|
||||
public String getStrDate(String format) {
|
||||
this.sdf = new SimpleDateFormat(format);
|
||||
return this.sdf.format(this.select.getTime());
|
||||
}
|
||||
|
||||
private void initPanel() {
|
||||
this.monthPanel = new JPanel(new BorderLayout());
|
||||
this.monthPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE));
|
||||
JPanel up = new JPanel(new BorderLayout());
|
||||
up.add(this.jp1 = new DateChooser.JP1(), "North");
|
||||
up.add(this.jp2 = new DateChooser.JP2(), "Center");
|
||||
this.monthPanel.add(this.jp3 = new DateChooser.JP3(), "Center");
|
||||
this.monthPanel.add(up, "North");
|
||||
this.monthPanel.add(this.jp4 = new DateChooser.JP4(), "South");
|
||||
this.addAncestorListener(new AncestorListener() {
|
||||
public void ancestorAdded(AncestorEvent event) {
|
||||
}
|
||||
|
||||
public void ancestorRemoved(AncestorEvent event) {
|
||||
}
|
||||
|
||||
public void ancestorMoved(AncestorEvent event) {
|
||||
DateChooser.this.hidePanel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void register(final JComponent showDate) {
|
||||
this.showDate = showDate;
|
||||
showDate.setRequestFocusEnabled(true);
|
||||
showDate.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent me) {
|
||||
showDate.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
this.setBackground(Color.WHITE);
|
||||
this.add(showDate, "Center");
|
||||
this.setPreferredSize(new Dimension(90, 25));
|
||||
this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||
showDate.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
if (showDate.isEnabled()) {
|
||||
showDate.setCursor(new Cursor(12));
|
||||
showDate.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
if (showDate.isEnabled()) {
|
||||
showDate.setCursor(new Cursor(0));
|
||||
showDate.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
if (showDate.isEnabled()) {
|
||||
showDate.setForeground(Color.CYAN);
|
||||
if (DateChooser.this.isShow) {
|
||||
DateChooser.this.hidePanel();
|
||||
} else {
|
||||
DateChooser.this.showPanel(showDate);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
if (showDate.isEnabled()) {
|
||||
showDate.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
showDate.addFocusListener(new FocusListener() {
|
||||
public void focusLost(FocusEvent e) {
|
||||
DateChooser.this.hidePanel();
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
this.jp1.updateDate();
|
||||
this.jp2.updateDate();
|
||||
this.jp3.updateDate();
|
||||
this.jp4.updateDate();
|
||||
SwingUtilities.updateComponentTreeUI(this);
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
if (this.showDate instanceof JTextField) {
|
||||
((JTextField) this.showDate).setText(this.sdf.format(this.select.getTime()));
|
||||
} else if (this.showDate instanceof JLabel) {
|
||||
((JLabel) this.showDate).setText(this.sdf.format(this.select.getTime()));
|
||||
}
|
||||
|
||||
this.hidePanel();
|
||||
}
|
||||
|
||||
private void hidePanel() {
|
||||
if (this.pop != null) {
|
||||
this.isShow = false;
|
||||
this.pop.hide();
|
||||
this.pop = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showPanel(Component owner) {
|
||||
if (this.pop != null) {
|
||||
this.pop.hide();
|
||||
}
|
||||
|
||||
Point show = new Point(0, this.showDate.getHeight());
|
||||
SwingUtilities.convertPointToScreen(show, this.showDate);
|
||||
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int x = show.x;
|
||||
int y = show.y;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (x > size.width - 295) {
|
||||
x = size.width - 295;
|
||||
}
|
||||
|
||||
if (y >= size.height - 170) {
|
||||
y -= 188;
|
||||
}
|
||||
|
||||
this.pop = PopupFactory.getSharedInstance().getPopup(owner, this.monthPanel, x, y);
|
||||
this.pop.show();
|
||||
this.isShow = true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
DateChooser dateChooser1 = getInstance("yyyy-MM-dd HH:mm");
|
||||
DateChooser dateChooser2 = getInstance("yyyy-MM-dd");
|
||||
JTextField showDate1 = new JTextField("单击选择日期");
|
||||
JLabel showDate2 = new JLabel("单击选择日期");
|
||||
dateChooser1.register(showDate1);
|
||||
dateChooser2.register(showDate2);
|
||||
JFrame jf = new JFrame("测试日期选择器");
|
||||
jf.add(showDate1, "North");
|
||||
jf.add(showDate2, "South");
|
||||
jf.pack();
|
||||
jf.setLocationRelativeTo((Component) null);
|
||||
jf.setVisible(true);
|
||||
jf.setDefaultCloseOperation(3);
|
||||
}
|
||||
|
||||
private class JP1 extends JPanel {
|
||||
private static final long serialVersionUID = -5638853772805561174L;
|
||||
JLabel yearleft;
|
||||
JLabel yearright;
|
||||
JLabel monthleft;
|
||||
JLabel monthright;
|
||||
JLabel center;
|
||||
JLabel centercontainer;
|
||||
|
||||
public JP1() {
|
||||
super(new BorderLayout());
|
||||
this.setBackground(new Color(160, 185, 215));
|
||||
this.initJP1();
|
||||
}
|
||||
|
||||
private void initJP1() {
|
||||
this.yearleft = new JLabel(" <<", 0);
|
||||
this.yearleft.setToolTipText("上一年");
|
||||
this.yearright = new JLabel(">> ", 0);
|
||||
this.yearright.setToolTipText("下一年");
|
||||
this.yearleft.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
||||
this.yearright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
||||
this.monthleft = new JLabel(" <", 4);
|
||||
this.monthleft.setToolTipText("上一月");
|
||||
this.monthright = new JLabel("> ", 2);
|
||||
this.monthright.setToolTipText("下一月");
|
||||
this.monthleft.setBorder(BorderFactory.createEmptyBorder(2, 30, 0, 0));
|
||||
this.monthright.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30));
|
||||
this.centercontainer = new JLabel("", 0);
|
||||
this.centercontainer.setLayout(new BorderLayout());
|
||||
this.center = new JLabel("", 0);
|
||||
this.centercontainer.add(this.monthleft, "West");
|
||||
this.centercontainer.add(this.center, "Center");
|
||||
this.centercontainer.add(this.monthright, "East");
|
||||
this.add(this.yearleft, "West");
|
||||
this.add(this.centercontainer, "Center");
|
||||
this.add(this.yearright, "East");
|
||||
this.setPreferredSize(new Dimension(295, 25));
|
||||
this.updateDate();
|
||||
this.yearleft.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
JP1.this.yearleft.setCursor(new Cursor(12));
|
||||
JP1.this.yearleft.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
JP1.this.yearleft.setCursor(new Cursor(0));
|
||||
JP1.this.yearleft.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
DateChooser.this.select.add(1, -1);
|
||||
JP1.this.yearleft.setForeground(Color.WHITE);
|
||||
DateChooser.this.refresh();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
JP1.this.yearleft.setForeground(Color.BLACK);
|
||||
}
|
||||
});
|
||||
this.yearright.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
JP1.this.yearright.setCursor(new Cursor(12));
|
||||
JP1.this.yearright.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
JP1.this.yearright.setCursor(new Cursor(0));
|
||||
JP1.this.yearright.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
DateChooser.this.select.add(1, 1);
|
||||
JP1.this.yearright.setForeground(Color.WHITE);
|
||||
DateChooser.this.refresh();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
JP1.this.yearright.setForeground(Color.BLACK);
|
||||
}
|
||||
});
|
||||
this.monthleft.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
JP1.this.monthleft.setCursor(new Cursor(12));
|
||||
JP1.this.monthleft.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
JP1.this.monthleft.setCursor(new Cursor(0));
|
||||
JP1.this.monthleft.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
DateChooser.this.select.add(2, -1);
|
||||
JP1.this.monthleft.setForeground(Color.WHITE);
|
||||
DateChooser.this.refresh();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
JP1.this.monthleft.setForeground(Color.BLACK);
|
||||
}
|
||||
});
|
||||
this.monthright.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
JP1.this.monthright.setCursor(new Cursor(12));
|
||||
JP1.this.monthright.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
JP1.this.monthright.setCursor(new Cursor(0));
|
||||
JP1.this.monthright.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
DateChooser.this.select.add(2, 1);
|
||||
JP1.this.monthright.setForeground(Color.WHITE);
|
||||
DateChooser.this.refresh();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
JP1.this.monthright.setForeground(Color.BLACK);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateDate() {
|
||||
this.center.setText(DateChooser.this.select.get(1) + "年" + (DateChooser.this.select.get(2) + 1) + "月");
|
||||
}
|
||||
}
|
||||
|
||||
private class JP2 extends JPanel {
|
||||
private static final long serialVersionUID = -8176264838786175724L;
|
||||
|
||||
public JP2() {
|
||||
this.setPreferredSize(new Dimension(295, 20));
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g) {
|
||||
g.setFont(DateChooser.this.font);
|
||||
g.drawString("星期日 星期一 星期二 星期三 星期四 星期五 星期六", 5, 10);
|
||||
g.drawLine(0, 15, this.getWidth(), 15);
|
||||
}
|
||||
|
||||
private void updateDate() {
|
||||
}
|
||||
}
|
||||
|
||||
private class JP3 extends JPanel {
|
||||
private static final long serialVersionUID = 43157272447522985L;
|
||||
|
||||
public JP3() {
|
||||
super(new GridLayout(6, 7));
|
||||
this.setPreferredSize(new Dimension(295, 100));
|
||||
this.initJP3();
|
||||
}
|
||||
|
||||
private void initJP3() {
|
||||
this.updateDate();
|
||||
}
|
||||
|
||||
public void updateDate() {
|
||||
this.removeAll();
|
||||
DateChooser.this.lm.clear();
|
||||
Date temp = DateChooser.this.select.getTime();
|
||||
Calendar select = Calendar.getInstance();
|
||||
select.setTime(temp);
|
||||
select.set(5, 1);
|
||||
int index = select.get(7);
|
||||
int sum = index == 1 ? 8 : index;
|
||||
select.add(5, 0 - sum);
|
||||
|
||||
for (int i = 0; i < 42; ++i) {
|
||||
select.add(5, 1);
|
||||
DateChooser.this.lm.addLabel(DateChooser.this.new MyLabel(select.get(1), select.get(2), select.get(5)));
|
||||
}
|
||||
|
||||
Iterator var6 = DateChooser.this.lm.getLabels().iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
DateChooser.MyLabel my = (DateChooser.MyLabel) var6.next();
|
||||
this.add(my);
|
||||
}
|
||||
|
||||
select.setTime(temp);
|
||||
}
|
||||
}
|
||||
|
||||
private class JP4 extends JPanel {
|
||||
private static final long serialVersionUID = -6391305687575714469L;
|
||||
|
||||
public JP4() {
|
||||
super(new BorderLayout());
|
||||
this.setPreferredSize(new Dimension(295, 20));
|
||||
this.setBackground(new Color(160, 185, 215));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
final JLabel jl = new JLabel("今天: " + sdf.format(new Date()));
|
||||
jl.setToolTipText("点击选择今天日期");
|
||||
this.add(jl, "Center");
|
||||
jl.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent me) {
|
||||
jl.setCursor(new Cursor(12));
|
||||
jl.setForeground(Color.RED);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent me) {
|
||||
jl.setCursor(new Cursor(0));
|
||||
jl.setForeground(Color.BLACK);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent me) {
|
||||
jl.setForeground(Color.WHITE);
|
||||
DateChooser.this.select.setTime(new Date());
|
||||
DateChooser.this.refresh();
|
||||
DateChooser.this.commit();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent me) {
|
||||
jl.setForeground(Color.BLACK);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateDate() {
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelManager {
|
||||
private List<DateChooser.MyLabel> list = new ArrayList();
|
||||
|
||||
public LabelManager() {
|
||||
}
|
||||
|
||||
public List<DateChooser.MyLabel> getLabels() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public void addLabel(DateChooser.MyLabel my) {
|
||||
this.list.add(my);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.list.clear();
|
||||
}
|
||||
|
||||
public void setSelect(DateChooser.MyLabel my, boolean b) {
|
||||
Iterator var4 = this.list.iterator();
|
||||
|
||||
while (var4.hasNext()) {
|
||||
DateChooser.MyLabel m = (DateChooser.MyLabel) var4.next();
|
||||
if (m.equals(my)) {
|
||||
m.setSelected(true, b);
|
||||
} else {
|
||||
m.setSelected(false, b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setSelect(Point p, boolean b) {
|
||||
if (b) {
|
||||
boolean findPrevious = false;
|
||||
boolean findNext = false;
|
||||
Iterator var6 = this.list.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
DateChooser.MyLabel mx = (DateChooser.MyLabel) var6.next();
|
||||
if (mx.contains(p)) {
|
||||
findNext = true;
|
||||
if (mx.getIsSelected()) {
|
||||
findPrevious = true;
|
||||
} else {
|
||||
mx.setSelected(true, b);
|
||||
}
|
||||
} else if (mx.getIsSelected()) {
|
||||
findPrevious = true;
|
||||
mx.setSelected(false, b);
|
||||
}
|
||||
|
||||
if (findPrevious && findNext) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DateChooser.MyLabel temp = null;
|
||||
Iterator var9 = this.list.iterator();
|
||||
|
||||
while (var9.hasNext()) {
|
||||
DateChooser.MyLabel m = (DateChooser.MyLabel) var9.next();
|
||||
if (m.contains(p)) {
|
||||
temp = m;
|
||||
} else if (m.getIsSelected()) {
|
||||
m.setSelected(false, b);
|
||||
}
|
||||
}
|
||||
|
||||
if (temp != null) {
|
||||
temp.setSelected(true, b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class MyLabel extends JLabel
|
||||
implements Comparator<DateChooser.MyLabel>, MouseListener, MouseMotionListener {
|
||||
private static final long serialVersionUID = 3668734399227577214L;
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private boolean isSelected;
|
||||
|
||||
public MyLabel(int year, int month, int day) {
|
||||
super("" + day, 0);
|
||||
this.year = year;
|
||||
this.day = day;
|
||||
this.month = month;
|
||||
this.addMouseListener(this);
|
||||
this.addMouseMotionListener(this);
|
||||
this.setFont(DateChooser.this.font);
|
||||
if (month == DateChooser.this.select.get(2)) {
|
||||
this.setForeground(Color.BLACK);
|
||||
} else {
|
||||
this.setForeground(Color.LIGHT_GRAY);
|
||||
}
|
||||
|
||||
if (day == DateChooser.this.select.get(5)) {
|
||||
this.setBackground(new Color(160, 185, 215));
|
||||
} else {
|
||||
this.setBackground(Color.WHITE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean getIsSelected() {
|
||||
return this.isSelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean b, boolean isDrag) {
|
||||
this.isSelected = b;
|
||||
if (b && !isDrag) {
|
||||
int temp = DateChooser.this.select.get(2);
|
||||
DateChooser.this.select.set(this.year, this.month, this.day);
|
||||
if (temp == this.month) {
|
||||
SwingUtilities.updateComponentTreeUI(DateChooser.this.jp3);
|
||||
} else {
|
||||
DateChooser.this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g) {
|
||||
if (this.day == DateChooser.this.select.get(5) && this.month == DateChooser.this.select.get(2)) {
|
||||
g.setColor(new Color(160, 185, 215));
|
||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
if (this.year == DateChooser.this.now.get(1) && this.month == DateChooser.this.now.get(2)
|
||||
&& this.day == DateChooser.this.now.get(5)) {
|
||||
Graphics2D gdx = (Graphics2D) g;
|
||||
gdx.setColor(Color.RED);
|
||||
Polygon p = new Polygon();
|
||||
p.addPoint(0, 0);
|
||||
p.addPoint(this.getWidth() - 1, 0);
|
||||
p.addPoint(this.getWidth() - 1, this.getHeight() - 1);
|
||||
p.addPoint(0, this.getHeight() - 1);
|
||||
gdx.drawPolygon(p);
|
||||
}
|
||||
|
||||
if (this.isSelected) {
|
||||
Stroke s = new BasicStroke(1.0F, 2, 2, 1.0F, new float[] { 2.0F, 2.0F }, 1.0F);
|
||||
Graphics2D gd = (Graphics2D) g;
|
||||
gd.setStroke(s);
|
||||
gd.setColor(Color.BLACK);
|
||||
Polygon px = new Polygon();
|
||||
px.addPoint(0, 0);
|
||||
px.addPoint(this.getWidth() - 1, 0);
|
||||
px.addPoint(this.getWidth() - 1, this.getHeight() - 1);
|
||||
px.addPoint(0, this.getHeight() - 1);
|
||||
gd.drawPolygon(px);
|
||||
}
|
||||
|
||||
super.paintComponent(g);
|
||||
}
|
||||
|
||||
public boolean contains(Point p) {
|
||||
return this.getBounds().contains(p);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
this.isSelected = true;
|
||||
this.update();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3);
|
||||
DateChooser.this.lm.setSelect(p, false);
|
||||
DateChooser.this.commit();
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
Point p = SwingUtilities.convertPoint(this, e.getPoint(), DateChooser.this.jp3);
|
||||
DateChooser.this.lm.setSelect(p, true);
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
}
|
||||
|
||||
public int compare(DateChooser.MyLabel o1, DateChooser.MyLabel o2) {
|
||||
Calendar c1 = Calendar.getInstance();
|
||||
c1.set(o1.year, o2.month, o1.day);
|
||||
Calendar c2 = Calendar.getInstance();
|
||||
c2.set(o2.year, o2.month, o2.day);
|
||||
return c1.compareTo(c2);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue