Selaa lähdekoodia

工单BOM删除处理

koul 3 vuotta sitten
vanhempi
commit
b9a71aff83

+ 10 - 14
src/main/java/com/uas/eis/service/Impl/MESServiceImpl.java

@@ -693,6 +693,7 @@ public class MESServiceImpl implements MESService {
         String code="";
         int tlid=0;
         String tlcode = "";
+        String macode="";
         String ma_tasktype=null;
         int maid=0;
         String tlpiclass = "生产退料单", tlcaller = "ProdInOut!Make!Return", bcpiclass = "拨出单", bccaller = "ProdInOut!AppropriationOut";
@@ -700,7 +701,7 @@ public class MESServiceImpl implements MESService {
         int frob=99;
         JSONArray array = data.get("detail");
         if(array!=null&&array.size()>0){
-            String macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "")).get("FICMOBillNo"));
+            macode = StringUtil.valueOf(JSON.parseObject(StringUtil.nvl(array.get(0), "")).get("FICMOBillNo"));
             Object[] data1 = baseDao.getFieldsDataByCondition("Make", "ma_tasktype,ma_id", "ma_code in ('" + macode + "')");
             if (data1!=null&&data1.length>0) {
                 ma_tasktype = StringUtil.nvl(data1[0], "");
@@ -781,19 +782,14 @@ public class MESServiceImpl implements MESService {
             sqls.add("insert into prodiodetail (pd_id,pd_piid,pd_inoutno,pd_piclass,pd_pdno,pd_prodcode,pd_outqty,pd_whcode,pd_whname,pd_inwhcode,pd_inwhname,pd_macode,pd_madetno) values (PRODIODETAIL_SEQ.nextval,"+id+",'"+code+"','"+bcpiclass+"',"+detno+",'"+itemNo+"',"+qty+",'"+warehouses[0]+"','"+warehouses[1]+"','"+warehouses2[0]+"','"+warehouses2[1]+"','"+ficmoBillNo+"',"+objs[2]+")");
             if (frob==0) {
                 Object prid = baseDao.getFieldDataByCondition("Product", "pr_id", "pr_code='" + itemNo + "'");
-                SqlRowList rs = baseDao.queryForRowSet("select nvl(mm_totaluseqty,0)+nvl(mm_havegetqty,0)-nvl(ma_tomadeqty,0)*nvl(mm_oneuseqty,0) mmqty,nvl(mm_havegetqty,0)-nvl(ma_tomadeqty,0)*nvl(mm_oneuseqty,0) useqty,mm_totaluseqty from MakeMaterial left join Make on ma_id=mm_maid where mm_id=" + objs[0]);
-                Double mmqty=0.0;
-                if (rs.next()){
-                    //最多可退数量
-                    mmqty = rs.getDouble("mmqty");
-                    //未使用数量
-                    Double useqty = rs.getDouble("useqty");
-                    //已转领料数
-                    Double mmTotaluseqty = rs.getDouble("mm_totaluseqty");
-                }
-                qty = qty.compareTo(mmqty) > 0 ? mmqty : qty;
-                sqls.add("INSERT INTO ProdIODetail(pd_id, pd_piid, pd_inoutno, pd_piclass, pd_pdno, pd_status,pd_auditstatuscode,pd_auditstatus,pd_prodcode,pd_ordercode, pd_orderdetno,pd_macode,pd_madetno,pd_plancode, pd_wccode, pd_orderid, pd_prodid,pd_whcode,pd_whname,pd_inqty,pd_description) VALUES (PRODIODETAIL_SEQ.nextval,"+tlid+",'"+tlcode+"','"+tlpiclass+"',"+det+ ",0,'ENTERING','在录入','"+itemNo+"','"+ficmoBillNo+"',"+objs[2]+",'"+ficmoBillNo+"',"+objs[2]+ ",'"+objs[3]+"','"+objs[5]+"',"+lineId+","+prid+",'"+warehouses[0]+"','"+warehouses[1]+"',"+qty+ ",'良品退仓')");
-                det++;
+                Double remain = baseDao.getSummaryByField("batch", "ba_remain", "ba_prodcode='" + itemNo + "' and ba_macode='" + macode + "' and ba_whcode='" + warehouses[0] + "'");
+                /*Object[] data1 = baseDao.getFieldsDataByCondition("MakeMaterial left join Make on ma_id=mm_maid",
+                        "mm_totaluseqty,mm_havegetqty,ma_tomadeqty,mm_oneuseqty,ma_qty", "mm_id=" + objs[0]);*/
+                if (qty.compareTo(remain) > 0){
+                    double sub = DoubleUtils.sub(qty, remain);
+                    sqls.add("INSERT INTO ProdIODetail(pd_id, pd_piid, pd_inoutno, pd_piclass, pd_pdno, pd_status,pd_auditstatuscode,pd_auditstatus,pd_prodcode,pd_ordercode, pd_orderdetno,pd_macode,pd_madetno,pd_plancode, pd_wccode, pd_orderid, pd_prodid,pd_whcode,pd_whname,pd_inqty,pd_description) VALUES (PRODIODETAIL_SEQ.nextval,"+tlid+",'"+tlcode+"','"+tlpiclass+"',"+det+ ",0,'ENTERING','在录入','"+itemNo+"','"+ficmoBillNo+"',"+objs[2]+",'"+ficmoBillNo+"',"+objs[2]+ ",'"+objs[3]+"','"+objs[5]+"',"+lineId+","+prid+",'"+warehouses[0]+"','"+warehouses[1]+"',"+sub+ ",'良品退仓')");
+                    det++;
+                }
             }
             detno++;
         }

+ 2 - 2
src/main/java/com/uas/eis/service/Impl/ScheduleTaskServiceImpl.java

@@ -100,7 +100,7 @@ public class ScheduleTaskServiceImpl implements ScheduleTaskService {
     public void syncMakeBaseDetails() {
         SqlRowList rs = baseDao.queryForRowSet("select id,mm_code,mm_detno from mes_makematerial where status='W' order by id");
         while (rs.next()) {
-            int count = baseDao.getCount("select count(1) from mes_make where status='D' and action<>'D' and ma_code='" + rs.getGeneralString("mm_code") + "'");
+            int count = baseDao.getCount("select count(1) from mes_make where status='D' and ma_code='" + rs.getGeneralString("mm_code") + "'");
             if (count > 0) {
                 MakeMaterial makeMaterial = baseDao.getJdbcTemplate().queryForObject("select mm_code,erpid,mm_prodcode,pr_detail,replace(PR_SPEC,'''','''''') pr_spec,pr_unit,mm_oneuseqty qty,mm_qty,mm_oneuseqty,'main' type,bo_recorder,to_char(bo_date,'yyyy-MM-dd HH24:mi:ss') bo_date,nvl(bo_version,0) bo_version,nvl(bo_cop,'BYT') bo_cop,mm_prodcode mm_repprodcode,mm_balance,(select nvl(cu_mescode,'BYT') from Product left join customer on pr_kh_user=cu_shortname where pr_code=ma_prodcode) ma_custcode,to_char(mc_indate,'yyyy-MM-dd HH24:mi:ss') mc_indate,mc_recorder,flag,0 rpid from mes_makematerial left join make on ma_id=mm_maid left join Product on mm_prodcode=pr_code left join bom on bo_id=mm_bomid left join (select max(mc_indate) mc_indate,max(mc_recorder) mc_recorder,max(md_mmdetno) md_mmdetno,max(md_makecode) md_makecode from MakeMaterialChangeDet left join MakeMaterialChange on mc_id=md_mcid) on md_makecode=ma_code and md_mmdetno=mm_detno where id=? order by mm_detno", new BeanPropertyRowMapper<MakeMaterial>(MakeMaterial.class), rs.getInt("id"));
                 makeMaterial.setMesUser(tokenConfig.get("mesUser"));
@@ -140,7 +140,7 @@ public class ScheduleTaskServiceImpl implements ScheduleTaskService {
             SqlRowList rs = baseDao.queryForRowSet("select id,mp_mmcode, mp_mmdetno,mp_mmid from mes_makematerialreplace where status='W' order by id");
             while (rs.next()) {
             int count =
-                    baseDao.getCount("select count(1) from mes_makematerial where status='D' and action<>'D' and " + "erpid=" + rs.getInt("mp_mmid"));
+                    baseDao.getCount("select count(1) from mes_makematerial where status='D' and " + "erpid=" + rs.getInt("mp_mmid"));
             if (count > 0) {
                     MakeMaterial makeMaterial = baseDao.getJdbcTemplate().queryForObject("select mm.mm_code,mm.erpid,mr.mp_prodcode mm_prodcode,pr_detail,replace(PR_SPEC,'''','''''') pr_spec,pr_unit,mm.mm_oneuseqty qty,mr.mp_canuseqty mm_qty,mm.mm_oneuseqty,'alternative' type,bo_recorder,to_char(bo_date,'yyyy-MM-dd HH24:mi:ss') bo_date,nvl(bo_version,0) bo_version,nvl(bo_cop,'BYT') bo_cop,mm.mm_prodcode mm_repprodcode,mm.mm_balance,(select nvl(cu_mescode,'BYT') from Product left join customer on pr_kh_user=cu_shortname where pr_code=ma_prodcode) ma_custcode,to_char(mc_indate,'yyyy-MM-dd HH24:mi:ss') mc_indate,mc_recorder,mr.flag,mr.erpid rpid from mes_makematerialreplace mr left join mes_makematerial mm on mr.mp_mmid=mm.erpid left join make on mm.mm_maid=ma_id left join Product on mr.mp_prodcode=pr_code left join bom on bo_id=mm.mm_bomid left join (select max(mc_indate) mc_indate,max(mc_recorder) mc_recorder,max(md_mmdetno) md_mmdetno,max(md_makecode) md_makecode from MakeMaterialChangeDet left join MakeMaterialChange on mc_id=md_mcid) on md_makecode=ma_code and md_mmdetno=mm.mm_detno where mr.id=?",
                             new BeanPropertyRowMapper<MakeMaterial>(MakeMaterial.class), rs.getInt("id"));

+ 93 - 0
src/main/java/com/uas/eis/utils/DoubleUtils.java

@@ -0,0 +1,93 @@
+package com.uas.eis.utils;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2022-01-10 16:48
+ */
+public class DoubleUtils implements Serializable {
+    private static final long serialVersionUID = -3345205828566485102L;
+    // 默认除法运算精度
+    private static final Integer DEF_DIV_SCALE = 6;
+    /**
+     * 提供精确的加法运算。
+     *
+     * @param value1 被加数
+     * @param value2 加数
+     * @return 两个参数的和
+     */
+    public static Double add(Double value1, Double value2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(value1));
+        BigDecimal b2 = new BigDecimal(Double.toString(value2));
+        return b1.add(b2).doubleValue();
+    }
+    /**
+     * 提供精确的减法运算。
+     *
+     * @param value1 被减数
+     * @param value2 减数
+     * @return 两个参数的差
+     */
+    public static double sub(Double value1, Double value2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(value1));
+        BigDecimal b2 = new BigDecimal(Double.toString(value2));
+        return b1.subtract(b2).doubleValue();
+    }
+    /**
+     * 提供精确的乘法运算。
+     *
+     * @param value1 被乘数
+     * @param value2 乘数
+     * @return 两个参数的积
+     */
+    public static Double mul(Double value1, Double value2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(value1));
+        BigDecimal b2 = new BigDecimal(Double.toString(value2));
+        return b1.multiply(b2).doubleValue();
+    }
+    /**
+     * 提供(相对)精确的除法运算,当发生除不尽的情况时, 精确到小数点以后10位,以后的数字四舍五入。
+     *
+     * @param dividend 被除数
+     * @param divisor 除数
+     * @return 两个参数的商
+     */
+    public static Double divide(Double dividend, Double divisor) {
+        return divide(dividend, divisor, DEF_DIV_SCALE);
+    }
+    /**
+     * 提供(相对)精确的除法运算。 当发生除不尽的情况时,由scale参数指定精度,以后的数字四舍五入。
+     *
+     * @param dividend 被除数
+     * @param divisor 除数
+     * @param scale  表示表示需要精确到小数点以后几位。
+     * @return 两个参数的商
+     */
+    public static Double divide(Double dividend, Double divisor, Integer scale) {
+        if (scale < 0) {
+            throw new IllegalArgumentException("The scale must be a positive integer or zero");
+        }
+        BigDecimal b1 = new BigDecimal(Double.toString(dividend));
+        BigDecimal b2 = new BigDecimal(Double.toString(divisor));
+        return b1.divide(b2, scale, RoundingMode.HALF_UP).doubleValue();
+    }
+    /**
+     * 提供指定数值的(精确)小数位四舍五入处理。
+     *
+     * @param value 需要四舍五入的数字
+     * @param scale 小数点后保留几位
+     * @return 四舍五入后的结果
+     */
+    public static double round(double value,int scale){
+        if(scale<0){
+            throw new IllegalArgumentException("The scale must be a positive integer or zero");
+        }
+        BigDecimal b = new BigDecimal(Double.toString(value));
+        BigDecimal one = new BigDecimal("1");
+        return b.divide(one,scale, RoundingMode.HALF_UP).doubleValue();
+    }
+}