diff --git a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBean.java b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBean.java index d1305e6..bc62aa4 100644 --- a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBean.java +++ b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBean.java @@ -1,24 +1,26 @@ package com.chint.plm.createGGBom; +import java.math.BigDecimal; + public class GGBean { private String pk; - private String weight; - public GGBean(String pk, String weight) { + private BigDecimal weight; + public GGBean(String pk, BigDecimal weight) { super(); this.pk = pk; this.weight = weight; } - public String getPk() { + protected String getPk() { return pk; } - public void setPk(String pk) { + protected void setPk(String pk) { this.pk = pk; } - public String getWeight() { + protected BigDecimal getWeight() { return weight; } - public void setWeight(String weight) { + protected void setWeight(BigDecimal weight) { this.weight = weight; } @Override diff --git a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBomController.java b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBomController.java index 78e1b52..326fa72 100644 --- a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBomController.java +++ b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/GGBomController.java @@ -75,16 +75,16 @@ public class GGBomController { // private TCComponent project; // private String wbsNo = ""; // private String projectDh = ""; - public Map> phMap = new HashMap>(); + protected Map> phMap = new HashMap>(); private TCComponentItemType itemType; - public List pkList = new ArrayList(); - public List typeList = new ArrayList(); + protected List pkList = new ArrayList(); + protected List typeList = new ArrayList(); private String groupID; private String now; private String userID; private TCComponentUser dcproxy; private TCComponentFolder newStuffFolder; - public static String INSERT_SQL = "insert into chint_material(\"Code\",\"PUID\",\"PmpcCode\",\"GoodsCode\",\"GoodsName\",\"UnitCode\",\"CompanyCode\",\"BpNo\",\"Spec\",\"TeRe\",\"State\",\"User\",\"Time\",\"Condition\",\"Info\")" + protected static String INSERT_SQL = "insert into chint_material(\"Code\",\"PUID\",\"PmpcCode\",\"GoodsCode\",\"GoodsName\",\"UnitCode\",\"CompanyCode\",\"BpNo\",\"Spec\",\"TeRe\",\"State\",\"User\",\"Time\",\"Condition\",\"Info\")" + " values(?,?,?,?,?,?,?,?,?,?,?,?,to_date(?,'yyyy-mm-dd HH24:mi:ss'),?,?)"; Map idBeanMap = new HashMap(); public GGBomController(AbstractAIFApplication app) { @@ -105,7 +105,7 @@ public class GGBomController { e.printStackTrace(); } } - public void readSql() throws TCException { + protected void readSql() throws Exception { String sql1 = "SELECT * FROM \"CHINT_SILLICONSTEELSHEET\" order by NO"; String[] prefs = session.getPreferenceService().getStringValues("database_tc"); @@ -150,11 +150,11 @@ public class GGBomController { SqlUtil.freeAll(); } } - public Map> ruleMap = new HashMap<>(); - public boolean getGGRule(String ruleName,StringBuffer msg) { + private Map> ruleMap = new HashMap<>(); + protected boolean getGGRule(String ruleName,StringBuffer msg) { //获取硅钢条料规则 //SELECT * FROM CHINT_SILLICONSTEELSHEET_RULE where "TYPE" = '三相五柱' - String sql3 = "SELECT WIDTHMIN,WIDTHMAX,MODEL,QUANTITY,USAGE,ISMAKEUP FROM CHINT_SILLICONSTEELSHEET_RULE where \"TYPE\" = ?"; + String sql3 = "SELECT WIDTHMIN,WIDTHMAX,MODEL,QUANTITY,USAGE,ISMAKEUP,REMARK FROM CHINT_SILLICONSTEELSHEET_RULE where \"TYPE\" = ?"; String[] prefs = session.getPreferenceService().getStringValues("database_tc"); SqlUtil.getTCDataConnection(prefs); ruleMap.clear(); @@ -169,9 +169,12 @@ public class GGBomController { int qty = read.getInt(4); String usage = read.getString(5); String makeup = read.getString(6); + String remark = read.getString(7); + if(remark == null) + remark = ""; String[] split = model.split(";"); - for(String ggp:split) { - RuleBean ruleBean = new RuleBean(minWidth,maxWidth,qty,Double.valueOf(usage),makeup.equals("是")); + for(String ggp : split) { + RuleBean ruleBean = new RuleBean(minWidth, maxWidth, qty, Double.valueOf(usage), makeup.equals("是"), remark); if(ruleMap.containsKey(ggp)) { ruleMap.get(ggp).add(ruleBean); }else { @@ -194,7 +197,7 @@ public class GGBomController { msg.append("以下为合法数据:").append(types.toString()); } - } catch (SQLException e) { + } catch (Exception e) { // Auto-generated catch block e.printStackTrace(); }finally { @@ -202,14 +205,14 @@ public class GGBomController { } return flagSj; } - public List prds = new ArrayList(); - public String Sql2 = "select t.PrhName,t.PrdLine,t.PrdNo,t.PrdFeatureCode,t.FeatureName,t.PrdCanInput,t.PrdSign from CcemVW_Prd t where t.prhcode = ? order by t.PrdNo"; - public PMPC pmpc; - public String Sql1 = "select t.PmpcPrhCode, t.PmpcPType,t.PmpcMType from CcemVW_Pmpc t where t.PmpcCode=?"; + private List prds = new ArrayList(); + private String Sql2 = "select t.PrhName,t.PrdLine,t.PrdNo,t.PrdFeatureCode,t.FeatureName,t.PrdCanInput,t.PrdSign from CcemVW_Prd t where t.prhcode = ? order by t.PrdNo"; + private PMPC pmpc; + private String Sql1 = "select t.PmpcPrhCode, t.PmpcPType,t.PmpcMType from CcemVW_Pmpc t where t.PmpcCode=?"; private String s_code = "400101016"; - public List self_lists = new ArrayList(); - public Vector drequests = new Vector(); - public void send(String ph,String pk) throws SQLException { + protected List self_lists = new ArrayList(); + protected Vector drequests = new Vector(); + protected void send(String ph,String pk) throws SQLException { String pmpcCode = pmpc == null ? "" : pmpc.getCode(); String prhCode = pmpc == null ? "" : pmpc.getPrhCode(); @@ -285,7 +288,7 @@ public class GGBomController { self_lists.add(new SelfMPartBean(code, params, null, "")); } - public CreateIn createMaterialYH(SelfMPartBean bean,String desc) throws TCException, ServiceException { + protected CreateIn createMaterialYH(SelfMPartBean bean,String desc) throws TCException, ServiceException { // Object[] result = new Object[2]; // TCComponentItem item = null; @@ -328,7 +331,7 @@ public class GGBomController { return cI; } - public List changeOwner(CreateOut[] cOs){ + protected List changeOwner(CreateOut[] cOs){ //String pa9 = ownUser.get_person().get_PA9(); List revList = new ArrayList(); try{ @@ -364,7 +367,7 @@ public class GGBomController { } return revList; } - public void applyChilds2() throws SQLException { + protected void applyChilds2() throws Exception { // Object obj1[] = new Object[] { s_code }; @@ -395,7 +398,7 @@ public class GGBomController { return; } - public void applyChilds1() throws SQLException { + protected void applyChilds1() throws Exception { if (SqlUtil.getConnection() == null) { MessageBox.post("ERROR", "连接模板数据库时失败,请检查连接!", MessageBox.ERROR); @@ -426,7 +429,7 @@ public class GGBomController { return; } - public String getMergedRegionValue(XSSFSheet sheet, int row, int column) { + protected String getMergedRegionValue(XSSFSheet sheet, int row, int column) { int sheetMergeCount = sheet.getNumMergedRegions(); for (int i = 0; i < sheetMergeCount; i++) { CellRangeAddress ca = sheet.getMergedRegion(i); @@ -443,59 +446,75 @@ public class GGBomController { return null; } private List ggBeanList = new ArrayList<>(); - public Double getRule(String type,int pk,double weight) { + + private Double getRule(String type, int pk, double weight, boolean first) { // Map pkMap = new LinkedHashMap<>(); - if(pk==0 || weight==0) { + if(pk == 0 || weight == 0) { return 0.0; } double resultVal = 0.0; if(ruleMap.containsKey(type)) { List list = ruleMap.get(type); - for(RuleBean bean : list) { - //偏宽在范围之中 - if(bean.inPath(pk)) { - //需要拼片 拼片逻辑 偏宽/2+-30 - if(bean.isPpFlag()) { - int pk1 = pk/2-30; - int pk2 = pk/2+30; - double dpk1 = (double)pk1/(pk1+pk2); - double dpk2 = (double)pk2/(pk1+pk2); - resultVal = weight*bean.getQty(); -// for(RuleBean beanCf : list) { - { - double d = weight*bean.getQty()*dpk1/bean.getUsage(); - BigDecimal b = new BigDecimal(d); - String f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).toString(); - ggBeanList.add(new GGBean(String.valueOf(pk1), f1)); - } - { - double d = weight*bean.getQty()*dpk2/bean.getUsage(); - BigDecimal b = new BigDecimal(d); - String f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).toString(); - ggBeanList.add(new GGBean(String.valueOf(pk2), f1)); - } -// } - }else { - //不需要 - double d = weight*bean.getQty()/bean.getUsage(); - BigDecimal b = new BigDecimal(d); - String f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).toString(); - ggBeanList.add(new GGBean(String.valueOf(pk), f1)); - resultVal = weight*bean.getQty(); - } - } - } + boolean find = true; + if(first) { + //TODO lidy20240426新增逻辑:excel中同类型首行优先匹配REMAKRK列=主柱末级片的规则 + for(RuleBean bean : list) { + if(bean.getRemark().equals("主柱末级片") && bean.inPath(pk)){ + find = false; + double d = weight * bean.getQty() / bean.getUsage(); + BigDecimal b = new BigDecimal(d); + //String f1 = b.toString();//.setScale(0, BigDecimal.ROUND_UP).toString(); + ggBeanList.add(new GGBean(String.valueOf(pk), b)); + resultVal = weight * bean.getQty(); + } + } + } + if(!first || find) { + for(RuleBean bean : list) { + if(bean.inPath(pk)) {//偏宽在范围之中 + //需要拼片 拼片逻辑 偏宽/2+-30 + if(bean.isPpFlag()) { + int pk1 = pk / 2 - 30; + int pk2 = pk / 2 + 30; + double dpk1 = (double)pk1 / (pk1 + pk2); + double dpk2 = (double)pk2 / (pk1 + pk2); + resultVal = weight * bean.getQty(); +// for(RuleBean beanCf : list) { + { + double d = weight * bean.getQty() * dpk1 / bean.getUsage(); + BigDecimal b = new BigDecimal(d); + //String f1 = b.toString();//.setScale(0, BigDecimal.ROUND_UP).toString(); + ggBeanList.add(new GGBean(String.valueOf(pk1), b)); + } + { + double d = weight * bean.getQty() * dpk2 / bean.getUsage(); + BigDecimal b = new BigDecimal(d); + //String f1 = b.toString();//.setScale(0, BigDecimal.ROUND_UP).toString(); + ggBeanList.add(new GGBean(String.valueOf(pk2), b)); + } +// } + }else { + //不需要 + double d = weight * bean.getQty() / bean.getUsage(); + BigDecimal b = new BigDecimal(d); + //String f1 = b.toString();//.setScale(0, BigDecimal.ROUND_UP).toString(); + ggBeanList.add(new GGBean(String.valueOf(pk), b)); + resultVal = weight * bean.getQty(); + } + } + } + } }else { BigDecimal b = new BigDecimal(weight); resultVal = b.doubleValue(); - String f1 = b.setScale(0, BigDecimal.ROUND_HALF_UP).toString(); - ggBeanList.add(new GGBean(String.valueOf(pk), f1)); + //String f1 = b.toString();//.setScale(0, BigDecimal.ROUND_UP).toString(); + ggBeanList.add(new GGBean(String.valueOf(pk), b)); } return resultVal; } private BigDecimal totalDecimal;//numTotal // private Map pkMap = new LinkedHashMap<>(); - public void readExcel(File tmpFile) throws Exception { + protected void readExcel(File tmpFile) throws Exception { FileInputStream in = new FileInputStream(tmpFile); XSSFWorkbook wb = new XSSFWorkbook(in); @@ -504,30 +523,31 @@ public class GGBomController { int cnt = sheetAt.getPhysicalNumberOfRows(); BigDecimal b = new BigDecimal("0"); - for(int i=5;i "+cellValue1); - double cellVal = getRule(cellValue1,Integer.valueOf(cellValue2),Double.valueOf(cellValue3)); + double cellVal = getRule(cellValue1, Integer.valueOf(cellValue2), Double.valueOf(cellValue3), !type0.equals(cellValue1)); b = b.add(new BigDecimal(cellVal)); // pkMap.put(cellValue1, cellValue2); } + type0 = cellValue1; } totalDecimal = b; System.out.println(ggBeanList.toString()); } - public void createBomExcel(String ph,TCComponentItemRevision parentRev,MyProgressBarCompent my,GGBomDialog dialog,String ruleName) throws Exception { + protected void createBomExcel(String ph,TCComponentItemRevision parentRev,MyProgressBarCompent my,GGBomDialog dialog,String ruleName) throws Exception { // List nums = new ArrayList(); // List childs = new ArrayList(); - Map childMap = new LinkedHashMap<>(); + Map childMap = new LinkedHashMap<>(); StringBuffer errBuffer = new StringBuffer(""); int num = 0; int count = ggBeanList.size(); Collections.sort(ggBeanList, new Comparator() { - @Override public int compare(GGBean o1, GGBean o2) { return o1.getPk().compareTo(o2.getPk()); @@ -535,44 +555,43 @@ public class GGBomController { }); boolean hasSq = false; BigDecimal numTotal = new BigDecimal("0"); - Map matnrMap = new HashMap<>(); - for(GGBean ggbean:ggBeanList) { - num = num+1; + Map matnrMap = new HashMap<>(); + for(GGBean ggbean : ggBeanList) { + num = num + 1; my.setShowLabel("正在获取第 " + num + "/" + count + " 个硅钢条料"); Map fields = new LinkedHashMap(); fields.put("物料分类码", "400101016"); //*牌号*片宽* - String desc = "*"+ph+"/"+ggbean.getPk(); + String desc = "*" + ph + "/" + ggbean.getPk(); System.out.println("desc==>"+desc); fields.put("描述", desc); - numTotal = numTotal.add(new BigDecimal(ggbean.getWeight())); + numTotal = numTotal.add(ggbean.getWeight()); if(matnrMap.containsKey(desc)) { // childs.add(matnrMap.get(desc)); // nums.add(ggbean.getWeight()); if(childMap.containsKey(matnrMap.get(desc))) { - String string = childMap.get(matnrMap.get(desc)); - BigDecimal b = new BigDecimal(string); - BigDecimal a = new BigDecimal(ggbean.getWeight()); + BigDecimal b = childMap.get(matnrMap.get(desc)); + BigDecimal a = ggbean.getWeight(); BigDecimal add = b.add(a); - childMap.put(matnrMap.get(desc), add.toString()); + childMap.put(matnrMap.get(desc), add); }else { childMap.put(matnrMap.get(desc), ggbean.getWeight()); } continue; } TCComponentContextList materials = KUtil.query(session, "chint_search_siliconsteelsheet", fields); - if(materials.getListCount()==1) { + if(materials.getListCount() == 1) { TCComponent component = (TCComponent) materials.get(0).getComponent(); - System.out.println("component==>"+component); + System.out.println("component==>" + component); // childs.add((TCComponentItemRevision)component); // nums.add(ggbean.getWeight()); - TCComponentItemRevision rev =(TCComponentItemRevision)component; + TCComponentItemRevision rev = (TCComponentItemRevision)component; if(childMap.containsKey(rev)) { - String string = childMap.get(rev); - BigDecimal b = new BigDecimal(string); - BigDecimal a = new BigDecimal(ggbean.getWeight()); + //String string = childMap.get(rev); + BigDecimal b = childMap.get(rev); + BigDecimal a = ggbean.getWeight(); BigDecimal add = b.add(a); - childMap.put(rev, add.toString()); + childMap.put(rev, add); }else { childMap.put(rev, ggbean.getWeight()); } @@ -585,15 +604,15 @@ public class GGBomController { SqlUtil.getTCDataConnection(prefs); self_lists.clear(); drequests.clear(); - send(ph,ggbean.getPk()); - System.out.println("申请物料"+drequests.toString()); + send(ph, ggbean.getPk()); + System.out.println("申请物料" + drequests.toString()); List cIList = new ArrayList<>(); for (int i = 0; i < self_lists.size(); i++) { int t = i+1; - System.out.println("正在创建第"+t+"个物料!"); + System.out.println("正在创建第" + t + "个物料!"); SelfMPartBean bean = self_lists.get(i); - CreateIn createMaterialYH = createMaterialYH(bean,ph+"/"+ggbean.getPk()); //groupID bean.getSpec(); m_code - if(createMaterialYH!=null) { + CreateIn createMaterialYH = createMaterialYH(bean,ph + "/" + ggbean.getPk()); //groupID bean.getSpec(); m_code + if(createMaterialYH != null) { cIList.add(createMaterialYH); } } @@ -603,11 +622,11 @@ public class GGBomController { CreateOut[] cOs = resp.output; List changeOwner = changeOwner(cOs); if(childMap.containsKey(changeOwner.get(0))) { - String string = childMap.get(changeOwner.get(0)); - BigDecimal b = new BigDecimal(string); - BigDecimal a = new BigDecimal(ggbean.getWeight()); + //String string = childMap.get(changeOwner.get(0)); + BigDecimal b = childMap.get(changeOwner.get(0)); + BigDecimal a = ggbean.getWeight(); BigDecimal add = b.add(a); - childMap.put(changeOwner.get(0), add.toString()); + childMap.put(changeOwner.get(0), add); }else { childMap.put(changeOwner.get(0), ggbean.getWeight()); } @@ -657,7 +676,7 @@ public class GGBomController { return; }else { my.setShowLabel("正在获取搭建硅钢条料BOM"); - createBomChild(parentRev,childMap); + createBomChild(parentRev, childMap); my.setVisible(false); // numTotal; String[] prefs = session.getPreferenceService().getStringValues("database_tc"); @@ -669,7 +688,7 @@ public class GGBomController { if(read2.next()) { String min = read2.getString(1); String max = read2.getString(2); - Double val = totalDecimal.divide(numTotal,BigDecimal.ROUND_CEILING).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + Double val = totalDecimal.divide(numTotal,BigDecimal.ROUND_CEILING).setScale(2, BigDecimal.ROUND_UP).doubleValue(); build.append("当前铁心平均利用率为");//当前铁心平均利用率为0.95,允许的利用率为0.9~0.95,符合要求 build.append(val).append(",允许的利用率为").append(min).append("-").append(max); @@ -696,7 +715,7 @@ public class GGBomController { } - public void sendMsg(String mess, String userID) throws IOException { + protected void sendMsg(String mess, String userID) throws IOException { try { // TXTUtil.writeTXT(logPath, "开始AM消息推送"); // TXTUtil.writeTXT(logPath, "用户:" + userID + ";信息:" + mess); @@ -711,7 +730,7 @@ public class GGBomController { // TXTUtil.writeTXT(logPath, "AM消息推送结束"); } @SuppressWarnings("deprecation") - public void createBomChild(TCComponentItemRevision parentRev,Map childMap ) { + protected void createBomChild(TCComponentItemRevision parentRev, Map childMap ) { try { ICCTReservationService reservationService = new ICCTReservationService(session.getSoaConnection()); TCComponent[] strustRevs = parentRev.getReferenceListProperty("structure_revisions"); @@ -726,12 +745,13 @@ public class GGBomController { AttributesInfo attr; List childInfos = new ArrayList<>(); RelativeStructureChildInfo childInfo; - for(TCComponentItemRevision rev:childMap.keySet()) { + for(TCComponentItemRevision rev : childMap.keySet()) { childInfo = new RelativeStructureChildInfo(); occInfo = new RelOccInfo(); attr = new AttributesInfo(); attr.name = "bl_quantity"; - attr.value = childMap.get(rev); + //attr.value = childMap.get(rev); + attr.value = childMap.get(rev).setScale(0, BigDecimal.ROUND_UP).toString(); // AttributesInfo attr1 = new AttributesInfo(); // attr1.name = "bl_sequence_no"; @@ -782,7 +802,7 @@ public class GGBomController { } } @SuppressWarnings("deprecation") - public void createBomChild(TCComponentItemRevision parentRev,List childs,List nums) { + protected void createBomChild(TCComponentItemRevision parentRev,List childs,List nums) { ICCTReservationService reservationService = new ICCTReservationService( session.getSoaConnection()); try { diff --git a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/RuleBean.java b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/RuleBean.java index ca488cf..77d6e4b 100644 --- a/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/RuleBean.java +++ b/com.connor.chint.wuhan/src/com/chint/plm/createGGBom/RuleBean.java @@ -8,17 +8,19 @@ public class RuleBean { private int qty; private double usage; private boolean ppFlag = false;//是否需要拼片 + private String remark; - public RuleBean(int minWidth, int maxWidth, int qty, double usage, boolean ppFlag) { + public RuleBean(int minWidth, int maxWidth, int qty, double usage, boolean ppFlag, String remark) { super(); this.minWidth = minWidth; this.maxWidth = maxWidth; this.qty = qty; this.usage = usage; this.ppFlag = ppFlag; + this.remark = remark; } - public boolean inPath(int len) { + protected boolean inPath(int len) { if(len>=minWidth && len<=maxWidth) { return true; @@ -26,44 +28,52 @@ public class RuleBean { return false; } - public int getMinWidth() { + protected int getMinWidth() { return minWidth; } - public void setMinWidth(int minWidth) { + protected void setMinWidth(int minWidth) { this.minWidth = minWidth; } - public int getMaxWidth() { + protected int getMaxWidth() { return maxWidth; } - public void setMaxWidth(int maxWidth) { + protected void setMaxWidth(int maxWidth) { this.maxWidth = maxWidth; } - public int getQty() { + protected int getQty() { return qty; } - public void setQty(int qty) { + protected void setQty(int qty) { this.qty = qty; } - public double getUsage() { + protected double getUsage() { return usage; } - public void setUsage(double usage) { + protected void setUsage(double usage) { this.usage = usage; } - public boolean isPpFlag() { + protected boolean isPpFlag() { return ppFlag; } - public void setPpFlag(boolean ppFlag) { + protected void setPpFlag(boolean ppFlag) { this.ppFlag = ppFlag; } + protected String getRemark() { + return remark; + } + + protected void setRemark(String remark) { + this.remark = remark; + } + } diff --git a/com.connor.chint.wuhan/src/com/connor/plm/process/ProcessCheckDialog.java b/com.connor.chint.wuhan/src/com/connor/plm/process/ProcessCheckDialog.java index cca15f3..70294c2 100644 --- a/com.connor.chint.wuhan/src/com/connor/plm/process/ProcessCheckDialog.java +++ b/com.connor.chint.wuhan/src/com/connor/plm/process/ProcessCheckDialog.java @@ -171,8 +171,10 @@ public class ProcessCheckDialog extends AbstractAIFDialog { bomSet.add(cuid); TCComponentBOMLine line = data.bomLine; //只获取其中包含首选项定义的物料名称的物料版本(精确匹配) - if(TCUtil.contains(names, line.getProperty("bl_item_object_name"))) + if(!TCUtil.contains(names, line.getProperty("bl_item_object_name"))) { + recycleBOM(bomLineTree, line.getUid()); continue; + } AIFComponentContext[] meops = rev.whereReferencedByTypeRelation(new String[] { "MEProcessRevision" }, new String[] { "IMAN_METarget" }); Object[] value = new Object[4];