Browse Source

销售出库单

hu 6 tháng trước cách đây
mục cha
commit
ba7697a413

+ 19 - 9
src/custom/beans/accountbalance/Accountbalance.java

@@ -33,7 +33,8 @@ public class Accountbalance extends BaseClass {
         if (!rows.isEmpty()) {
             accountbalanceEntity.setBalance(rows.get(0).getBigDecimal("balance"));
             accountbalanceEntity.setCreditquota(rows.get(0).getBigDecimal("creditquota"));
-            accountbalanceEntity.setCanuseamount(rows.get(0).getBigDecimal("balance").add(rows.get(0).getBigDecimal("creditquota")));
+            accountbalanceEntity.setDiscountamount(rows.get(0).getBigDecimal("discountamount"));
+            accountbalanceEntity.setCanuseamount(rows.get(0).getBigDecimal("balance").add(rows.get(0).getBigDecimal("creditquota")).add(rows.get(0).getBigDecimal("discountamount")));
         }
         return accountbalanceEntity;
     }
@@ -111,6 +112,7 @@ public class Accountbalance extends BaseClass {
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
         sqlFactory.addParameter("amount", cashbillEntity.getAmount());
+        sqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
         sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
         sqlFactory.addParameter("userid", controller.userid);
         sqlFactory.addParameter("username", controller.username);
@@ -135,7 +137,7 @@ public class Accountbalance extends BaseClass {
 
             // 审核逻辑判断
             Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
+                    "select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='"
                             + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
                             + controller.siteid + "'");
 
@@ -147,14 +149,16 @@ public class Accountbalance extends BaseClass {
                 accountbalanceaddSqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
                 accountbalanceaddSqlFactory.addParameter("siteid", controller.siteid);
                 accountbalanceaddSqlFactory.addParameter("balance", cashbillEntity.getAmount());
+                accountbalanceaddSqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
                 accountbalanceaddSqlFactory.addParameter("userid", controller.userid);
                 accountbalanceaddSqlFactory.addParameter("username", controller.username);
                 balance = cashbillEntity.getAmount();
                 sqlList.add(accountbalanceaddSqlFactory.getSQL());
             } else {
                 BigDecimal newbalance = cashbillEntity.getAmount().add(rowsaccountbalance.get(0).getBigDecimal("balance"));
+                BigDecimal newdiscountamount = cashbillEntity.getDiscountamountamount().add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
                 sqlList.add("update sa_accountbalance set balance='" + newbalance
-                        + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='"
+                        + "',newdiscountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='"
                         + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid
                         + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid
                         + "'");
@@ -205,6 +209,7 @@ public class Accountbalance extends BaseClass {
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
         sqlFactory.addParameter("amount", cashbillEntity.getAmount());
+        sqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
         sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
         sqlFactory.addParameter("userid", controller.userid);
         sqlFactory.addParameter("username", controller.username);
@@ -225,7 +230,7 @@ public class Accountbalance extends BaseClass {
 
             // 审核逻辑判断
             Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
+                    "select sa_accountbalanceid,balance,creditquota,discountamount from sa_accountbalance where sys_enterpriseid ='"
                             + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
                             + controller.siteid + "'");
             if (rowsaccountbalance.isEmpty()) {
@@ -240,12 +245,13 @@ public class Accountbalance extends BaseClass {
 //				sqlList.add(sqlFactory.getSQL());
                 throw new YosException(false, "该营销账户不存在,支出凭证无法审核");
             } else {
-                BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1) {
+                BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance")).add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
+                if ((cashbillEntity.getAmount().add(cashbillEntity.getDiscountamountamount())).compareTo(canuseamount) == 1) {
                     throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
@@ -282,6 +288,7 @@ public class Accountbalance extends BaseClass {
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
         sqlFactory.addParameter("amount", cashbillEntity.getAmount());
+        sqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
         sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
         sqlFactory.addParameter("userid", controller.userid);
         sqlFactory.addParameter("username", controller.username);
@@ -322,7 +329,8 @@ public class Accountbalance extends BaseClass {
 //                    throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
 //                }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);
@@ -360,6 +368,7 @@ public class Accountbalance extends BaseClass {
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
         sqlFactory.addParameter("amount", cashbillEntity.getAmount());
+        sqlFactory.addParameter("discountamount", cashbillEntity.getDiscountamountamount());
         sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
         sqlFactory.addParameter("userid", controller.userid);
         sqlFactory.addParameter("username", controller.username);
@@ -390,7 +399,8 @@ public class Accountbalance extends BaseClass {
                     throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
-                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                BigDecimal newdiscountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(cashbillEntity.getDiscountamountamount());
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount='"+newdiscountamount+"',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
                 balance = newbalance;
             }
             sqlFactory.addParameter("balance", balance);

+ 10 - 2
src/custom/beans/accountbalance/AccountbalanceEntity.java

@@ -7,8 +7,16 @@ public class AccountbalanceEntity {
 	private BigDecimal creditquota;
 	private BigDecimal balance;
 	private BigDecimal canuseamount;
-	
-	
+	private BigDecimal discountamount;
+
+	public BigDecimal getDiscountamount() {
+		return discountamount;
+	}
+
+	public void setDiscountamount(BigDecimal discountamount) {
+		this.discountamount = discountamount;
+	}
+
 	public BigDecimal getCreditquota() {
 		return creditquota;
 	}

+ 11 - 1
src/custom/beans/accountbalance/CashbillEntity.java

@@ -8,6 +8,7 @@ import java.math.BigDecimal;
 public class CashbillEntity {
 
     private BigDecimal amount;
+    private BigDecimal discountamountamount;
     private String remarks;
     private String source;
     private String sourcenote;
@@ -24,8 +25,9 @@ public class CashbillEntity {
     public CashbillEntity() {
     }
 
-    public CashbillEntity(BigDecimal amount, String remarks, String source, String sourcenote, String ownertable, long ownerid, String type, String typemx) {
+    public CashbillEntity(BigDecimal amount,BigDecimal discountamountamount, String remarks, String source, String sourcenote, String ownertable, long ownerid, String type, String typemx) {
         this.amount = amount;
+        this.discountamountamount = discountamountamount;
         this.remarks = remarks;
         this.source = source;
         this.sourcenote = sourcenote;
@@ -77,6 +79,14 @@ public class CashbillEntity {
         this.amount = amount;
     }
 
+    public BigDecimal getDiscountamountamount() {
+        return discountamountamount;
+    }
+
+    public void setDiscountamountamount(BigDecimal discountamountamount) {
+        this.discountamountamount = discountamountamount;
+    }
+
     public String getRemarks() {
         return remarks;
     }

+ 2 - 2
src/custom/beans/accountbalance/SQL/收支凭证新增.sql

@@ -1,8 +1,8 @@
 insert into sa_cashbill (siteid, sa_cashbillid, createuserid, createby, createdate, billno, changeuserid, changeby,
-                         changedate, checkby, checkdate, sys_enterpriseid, sa_accountclassid, type, remarks, amount,
+                         changedate, checkby, checkdate, sys_enterpriseid, sa_accountclassid, type, remarks, amount,discountamount,
                          status, source, sourcenote, ownertable, ownerid, balance, sa_cashbillid_rebate, class,
                          subclass, period, updatek3flag)
 values ($siteid$, $sa_cashbillid$, $userid$, $username$, CURRENT_TIME, $billno$, $userid$, $username$, CURRENT_TIME,
         $checkby$, $checkdate$, $sys_enterpriseid$, $sa_accountclassid$, $type$, $remarks$,
-        $amount$, $status$, $source$, $sourcenote$, $ownertable$, $ownerid$, $balance$, $sa_cashbillid_rebate$, $class$,
+        $amount$,$discountamount$,$status$, $source$, $sourcenote$, $ownertable$, $ownerid$, $balance$, $sa_cashbillid_rebate$, $class$,
         $subclass$, $period$, $updatek3flag$);

+ 2 - 1
src/custom/beans/accountbalance/SQL/营销账户余额新增.sql

@@ -1,4 +1,4 @@
-insert into sa_accountbalance (siteid, sa_accountbalanceid, sys_enterpriseid, sa_accountclassid, balance, creditquota,
+insert into sa_accountbalance (siteid, sa_accountbalanceid, sys_enterpriseid, sa_accountclassid, balance, creditquota,discountamount,
                                changeuserid, changeby, changedate)
 select $siteid$,
        $sa_accountbalanceid$,
@@ -6,6 +6,7 @@ select $siteid$,
        $sa_accountclassid$,
        $balance$,
        0,
+       $discountamount$,
        $userid$,
        $username$,
        CURRENT_TIME where not exists(select *from sa_accountbalance where siteid=$siteid$ and sys_enterpriseid=$sys_enterpriseid$ and sa_accountclassid=$sa_accountclassid$)

+ 1 - 0
src/custom/beans/accountbalance/SQL/账户余额查询.sql

@@ -2,6 +2,7 @@ SELECT t1.accountno,
        t1.accountname,
        ifnull(t2.balance, 0)     balance,
        ifnull(t2.creditquota, 0) creditquota,
+       ifnull(t2.discountamount, 0) discountamount,
        t2.changeuserid,
        t2.changeby,
        t2.changedate

+ 2 - 1
src/custom/beans/remind/Remind.java

@@ -577,11 +577,12 @@ public class Remind {
             insertSQL.setSiteid(siteid);
             insertSQL.setValue("title", title);
             insertSQL.setValue("type", type);
-            insertSQL.setValue("content", content);
             insertSQL.setValue("userid", userid);
+            insertSQL.setValue("message", content);
             insertSQL.setValue("systemappids", systemappids);
             insertSQL.setValue("objectid", objectid == 0 ? "null" : objectid);
             insertSQL.setValue("objectname", objectname);
+            insertSQL.setValue("isread",0);
             insertSQL.insert();
         }
     }

+ 25 - 0
src/custom/restcontroller/R.java

@@ -5762,6 +5762,31 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025043010105603 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025050614284803 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025050614510403 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025050614581203 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025050709505703 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 1 - 1
src/custom/restcontroller/webmanage/sale/paybill/Paybill.java

@@ -270,7 +270,7 @@ public class Paybill extends Controller {
         dbConnect.runSqlUpdate(sqlList);
         for (Row row : accountclassRows) {
             BigDecimal amount = row.getBigDecimal("amount");
-            CashbillEntity cashbillEntity = new CashbillEntity(amount, remarks, "打款凭证", billno, "sa_paybill", sa_paybillid, "货款", "");
+            CashbillEntity cashbillEntity = new CashbillEntity(amount,BigDecimal.ZERO, remarks, "打款凭证", billno, "sa_paybill", sa_paybillid, "货款", "");
             JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, row.getLong("sa_accountclassid"), cashbillEntity, false, true);
             sqlList = new ArrayList<>(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
 

+ 1 - 2
src/custom/restcontroller/webmanage/sale/stockbill/SQL/出入库单明细列表查询.sql

@@ -9,8 +9,7 @@ FROM st_stockbill_items t1
          left join plm_item t2 on t1.itemid = t2.itemid and t1.siteid = t2.siteid
          LEFT JOIN plm_unit t3 ON t3.unitid = t2.unitid AND t3.siteid = t2.siteid
          LEFT JOIN st_stockbill t4 ON t4.st_stockbillid = t1.st_stockbillid AND t4.siteid = t1.siteid
-         left join sa_dispatch_items t5 on t1.sa_dispatch_itemsid=t5.sa_dispatch_itemsid and t1.siteid=t5.siteid
-         left join sa_orderitems t6 on t6.sa_orderitemsid=t5.sa_orderitemsid and t6.siteid=t5.siteid
+         left join sa_orderitems t6 on t6.sa_orderitemsid=t1.sa_orderitemsid and t6.siteid=t1.siteid
          left join sa_order t7 on t6.sa_orderid=t7.sa_orderid and t6.siteid=t7.siteid
 where $where$
   and t1.siteid = $siteid$

+ 12 - 3
src/custom/restcontroller/webmanage/sale/stockbill/SQL/出入库单详情.sql

@@ -2,8 +2,17 @@ SELECT t1.*,
        t2.enterprisename,
        t2.abbreviation,
        t2.phonenumber enterprisephonenumber,
-       t3.agentnum
+       t3.agentnum,
+       t4.name recname,
+       t4.phonenumber recphonenumber,
+       t4.address recaddress,
+       t5.discountamount,
+       t6.depno,
+       t6.depname
 FROM st_stockbill t1
          LEFT JOIN sys_enterprise t2 ON t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid
-        LEFT JOIN sa_agents t3 ON t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid
-      where t1.siteid=$siteid$ and t1.st_stockbillid=$st_stockbillid$
+         LEFT JOIN sa_agents t3 ON t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid
+         left join sys_enterprise_contacts t4 on t1.rec_contactsid=t4.contactsid and t1.siteid = t4.siteid
+         left join sa_accountbalance t5 on t5.sys_enterpriseid=t1.sys_enterpriseid and t1.siteid = t5.siteid and t5.sa_accountclassid =(select sa_accountclassid from sa_accountclass where siteid=$siteid$ and accountname='现金账户')
+         left join sys_department t6 on t1.departmentid=t6.departmentid and t1.siteid = t6.siteid
+           where t1.siteid=$siteid$ and t1.st_stockbillid=$st_stockbillid$

+ 361 - 107
src/custom/restcontroller/webmanage/sale/stockbill/stockbill.java

@@ -4,6 +4,7 @@ import beans.accountbalance.Accountbalance;
 import beans.accountbalance.CashbillEntity;
 import beans.data.BatchDeleteErr;
 import beans.datacontrllog.DataContrlLog;
+import beans.dispatch.Dispatch;
 import beans.parameter.Parameter;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -13,13 +14,19 @@ import common.annotation.API;
 import common.annotation.CACHEING;
 import common.annotation.CACHEING_CLEAN;
 import common.data.*;
+import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
+import restcontroller.webmanage.sale.order.Order;
+import restcontroller.webmanage.sale.order.OrderItems;
 
 import javax.swing.text.StyledEditorKit;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
+
+import static java.time.LocalDate.now;
 
 /**
  * 出入库单
@@ -35,6 +42,116 @@ public class stockbill extends Controller {
         super(content);
     }
 
+    @API(title = "新增销售出库单", apiversion = R.ID2025043010105603.v1.class)
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
+    public String insertormodify_stockbill() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        // 表名
+
+        String tableName = "st_stockbill";
+        Long st_stockbillid = content.getLong("st_stockbillid");
+        Long sys_enterpriseid = content.getLong("sys_enterpriseid");
+        Rows contactrows =dbConnect.runSqlQuery("select * from sys_enterprise_contacts where sys_enterpriseid="+sys_enterpriseid+" and ifnull(deleted,0)=0");
+        Long rec_contactsid=content.getLongValue("rec_contactsid");
+        if(contactrows.isNotEmpty()){
+            rec_contactsid = contactrows.get(0).getLong("contactsid");
+        }
+        Long departmentid = content.getLongValue("departmentid");
+        String type = content.getStringValue("type");
+        String remarks = content.getStringValue("remarks");
+        String billdate = content.getStringValue("billdate");
+        String outplace = content.getStringValue("outplace");
+        String delivery = content.getStringValue("delivery");
+        Rows invoicerows =dbConnect.runSqlQuery("select * from sys_enterprise_finance where sys_enterpriseid="+sys_enterpriseid+" order by isdefault desc");
+        String invoice_enterprisename = content.getStringValue("invoice_enterprisename");
+        String invoice_address = content.getStringValue("invoice_address");
+        String invoice_taxno = content.getStringValue("invoice_taxno");
+        if(invoicerows.isNotEmpty()){
+            invoice_enterprisename=invoicerows.get(0).getString("enterprisename");
+            invoice_address=invoicerows.get(0).getString("address");
+            invoice_taxno=invoicerows.get(0).getString("taxno");
+        }
+        String tracknumber = content.getStringValue("tracknumber");
+
+        boolean isconfirm = content.getBooleanValue("isconfirm");
+        SQLFactory sqlFactory = new SQLFactory(this, "发货单新增");
+
+        if (st_stockbillid <= 0) {
+
+            st_stockbillid = createTableID(tableName);
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
+            insertSQL.setUniqueid(st_stockbillid);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
+            insertSQL.setValue("rec_contactsid", rec_contactsid);
+            insertSQL.setValue("departmentid", departmentid);
+            insertSQL.setValue("type", type);
+            insertSQL.setValue("remarks", remarks);
+            insertSQL.setValue("billdate", billdate);
+            insertSQL.setValue("billno", createBillCode("stockbill"));
+            insertSQL.setValue("outplace", outplace);
+            insertSQL.setValue("delivery", delivery);
+            insertSQL.setValue("invoice_enterprisename", invoice_enterprisename);
+            insertSQL.setValue("invoice_address", invoice_address);
+            insertSQL.setValue("invoice_taxno", invoice_taxno);
+            insertSQL.setValue("tracknumber", tracknumber);
+            insertSQL.setValue("isconfirm", isconfirm);
+
+            insertSQL.setValue("createby", username);
+            insertSQL.setDateValue("createdate");
+            insertSQL.setValue("changeby", username);
+            insertSQL.setDateValue("changedate");
+            insertSQL.setValue("status", "新建");
+            insertSQL.setValue("payamount", 0);
+            insertSQL.setValue("paydiscountamount", 0);
+            sqlList.add(insertSQL.getSQL());
+
+            sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "新增", "销售出库单新增成功").getSQL());
+        } else {
+            Rows rows = dbConnect.runSqlQuery(
+                    "SELECT status,sys_enterpriseid from st_stockbill WHERE st_stockbillid = "
+                            + st_stockbillid);
+            if (rows.isNotEmpty()) {
+                if (rows.get(0).getString("status").equals("新建")) {
+
+                    UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
+                    updateSQL.setUniqueid(st_stockbillid);
+                    updateSQL.setSiteid(siteid);
+                    updateSQL.setValue("sys_enterpriseid", sys_enterpriseid);
+                    updateSQL.setValue("rec_contactsid", rec_contactsid);
+                    updateSQL.setValue("departmentid", departmentid);
+                    updateSQL.setValue("remarks", remarks);
+                    updateSQL.setValue("billdate", billdate);
+                    updateSQL.setValue("outplace", outplace);
+                    updateSQL.setValue("delivery", delivery);
+                    updateSQL.setValue("invoice_enterprisename", content.getStringValue("invoice_enterprisename"));
+                    updateSQL.setValue("invoice_address", content.getStringValue("invoice_address"));
+                    updateSQL.setValue("invoice_taxno", content.getStringValue("invoice_taxno"));
+                    updateSQL.setValue("tracknumber", tracknumber);
+                    updateSQL.setValue("isconfirm", isconfirm);
+                    updateSQL.setValue("payamount", content.getBigDecimal("payamount"));
+                    updateSQL.setValue("paydiscountamount", content.getBigDecimal("paydiscountamount"));
+
+                    updateSQL.setValue("changeby", username);
+                    updateSQL.setDateValue("changedate");
+                    sqlList.add(updateSQL.getSQL());
+
+                    sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "更新", "销售出库单更新成功").getSQL());
+                } else {
+                    return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                }
+
+            } else {
+                return getErrReturnObject().setErrMsg("该销售出库单不存在").toString();
+            }
+
+        }
+        dbConnect.runSqlUpdate(sqlList);
+        content.put("st_stockbillid", st_stockbillid);
+
+        return queryStockbillMain();
+    }
+
     @API(title = "出入库单详情", apiversion = R.ID20230719153803.v1.class)
     @CACHEING
     public String queryStockbillMain() throws YosException {
@@ -44,6 +161,8 @@ public class stockbill extends Controller {
         sqlFactory.addParameter("siteid", siteid);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
         Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
+        Rows rowsdetail = dbConnect.runSqlQuery("select amount from st_stockbill_items where st_stockbillid="+st_stockbillid);
+        row.put("receivableamount",rowsdetail.sum("amount"));
 
         return getSucReturnObject().setData(row).toString();
     }
@@ -57,9 +176,10 @@ public class stockbill extends Controller {
             if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
                 where.append(" and(");
                 where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.outplace like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t3.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t6.depname like'%").append(whereObject.getString("condition")).append("%' ");
                 where.append(")");
             }
             if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
@@ -78,6 +198,38 @@ public class stockbill extends Controller {
                 where.append("and t1.remarks like'%").append(whereObject.getString("remarks")).append("%' ");
             }
 
+
+            if (whereObject.containsKey("past15days") && !"".equals(whereObject.getString("past15days"))) {
+                if(whereObject.getBooleanValue("past15days")){
+                    where.append("and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >=DATE_SUB(CURDATE(), INTERVAL 15 DAY)");
+                }
+
+            }
+            if (whereObject.containsKey("past30days") && !"".equals(whereObject.getString("past30days"))) {
+                if(whereObject.getBooleanValue("past30days")){
+                    where.append("and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >=DATE_SUB(CURDATE(), INTERVAL 30 DAY)");
+                }
+            }
+            if (whereObject.containsKey("today") && !"".equals(whereObject.getString("today"))) {
+                if(whereObject.getBooleanValue("today")){
+                    where.append("and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >=CURDATE()");
+                }
+            }
+            if (whereObject.containsKey("checknoprint") && !"".equals(whereObject.getString("checknoprint"))) {
+                if(whereObject.getBooleanValue("checknoprint")){
+                    where.append("and t1.status ='审核' and isreport=0");
+                }
+            }
+            if (whereObject.containsKey("nowaybillgenerated") && !"".equals(whereObject.getString("nowaybillgenerated"))) {
+                if(whereObject.getBooleanValue("checknoprint")){
+                    where.append("and t1.isreceiver=0 and ifnull(txlogisticid,'')='' ");
+                }
+            }
+//            if (whereObject.containsKey("paynocheck") && !"".equals(whereObject.getString("paynocheck"))) {
+//                where.append("and t1.remarks like'%").append(whereObject.getString("remarks")).append("%' ");
+//            }
+
+
             if (whereObject.containsKey("param") && !"".equals(whereObject.getString("param"))) {
                 Rows rowsStockbillid = dbConnect.runSqlQuery("select t1.st_stockbillid from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
                         " where t1.siteid='" + siteid + "' and (t2.itemname like '%" + whereObject.getString("param") + "%' or t2.itemno like '%" + whereObject.getString("param") + "%')");
@@ -89,8 +241,6 @@ public class stockbill extends Controller {
                     str = str.replace("[", "(").replace("]", ")");
                     where.append(" and t1.st_stockbillid  in").append(str);
                 }
-
-
             }
         }
 //        SQLFactory sqlFactory = new SQLFactory(this, "出入库单列表查询", pageSize, pageNumber, pageSorting);
@@ -107,13 +257,20 @@ public class stockbill extends Controller {
 
     //查询出入库单列表
     public QuerySQL queryStockbillList(String where) throws YosException {
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill");
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill","*");
         querySQL.setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid",
                 "enterprisename", "abbreviation");
         querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid",
                 "agentnum");
-        querySQL.addQueryFields("enterprisephonenumber", "t2.phonenumber");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_contacts", "t4", "t1.rec_contactsid=t4.contactsid and t1.siteid = t4.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_accountbalance", "t5", "t5.sys_enterpriseid=t1.sys_enterpriseid and t1.siteid = t5.siteid and t5.sa_accountclassid =(select t1.sa_accountclassid from sa_accountclass t1 where t1.siteid='"+siteid+"' and t1.accountname='现金账户')",
+                "discountamount");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t6", "t1.departmentid=t6.departmentid and t1.siteid = t6.siteid",
+                "depno","depname");
+        querySQL.addQueryFields("recname", "t4.name");
+        querySQL.addQueryFields("recphonenumber", "t4.phonenumber");
+        querySQL.addQueryFields("recaddress", "t4.address");
         querySQL.setWhere("t1.siteid", siteid);
         querySQL.setWhere(where);
         return querySQL;
@@ -121,7 +278,7 @@ public class stockbill extends Controller {
 
 
     @API(title = "删除", apiversion = R.ID20230719154003.v1.class)
-    @CACHEING_CLEAN(apiClass = {stockbill.class})
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
     public String delete() throws YosException {
 
         JSONArray st_stockbillids = content.getJSONArray("st_stockbillids");
@@ -146,12 +303,17 @@ public class stockbill extends Controller {
     }
 
     @API(title = "审核", apiversion = R.ID20230719154103.v1.class)
-    @CACHEING_CLEAN(apiClass = {stockbill.class})
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class, Order.class, OrderItems.class})
     public String check() throws YosException {
 
         Long st_stockbillid = content.getLong("st_stockbillid");
-        Rows rows = dbConnect.runSqlQuery("select st_stockbillid,status,billno,sys_enterpriseid from st_stockbill where st_stockbillid ='"
+
+        Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
                 + st_stockbillid + "' and  siteid='" + siteid + "'");
+        Rows rowsdetail = dbConnect.runSqlQuery("select * from st_stockbill_items where st_stockbillid ='"
+                + st_stockbillid + "' and  siteid='" + siteid + "'");
+        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
+
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该出入库单不存在")
                     .toString();
@@ -161,34 +323,86 @@ public class stockbill extends Controller {
                         .toString();
             }
         }
+        for(Row row : rowsdetail){
+            if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
+                return getErrReturnObject().setErrMsg("表体数量不能小于0").toString();
+            }
+        }
+        if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
+            return getErrReturnObject().setErrMsg("扣款金额需大于0").toString();
+        }
+        if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
+            return getErrReturnObject().setErrMsg("发货地不可为空").toString();
+        }
+        if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
+            return getErrReturnObject().setErrMsg("扣款金额与应扣金额不符,不能审核").toString();
+        }
+        Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
+        if (accountbalancerows.isNotEmpty()) {
+            BigDecimal discountamount = accountbalancerows.get(0).getBigDecimal("discountamount");
+            if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(discountamount)>0) {
+                return getErrReturnObject().setErrMsg("优惠金额不能大于可用优惠金额").toString();
+            }
+        }else{
+            return getErrReturnObject().setErrMsg("账户不存在").toString();
+        }
         ArrayList<String> sqlList = new ArrayList<>();
-
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-
-        BigDecimal billamount = BigDecimal.ZERO;
-        Rows stockbilldetails = dbConnect.runSqlQuery("select * from st_stockbill_items where st_stockbillid ='"
-                + st_stockbillid + "' and  siteid='" + siteid + "'");
-        for (Row row : stockbilldetails) {
-            billamount = billamount.add(row.getBigDecimal("amount").abs());
+        Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
+        RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
+
+        String order_paymentnode = Parameter.get(siteid, "order_paymentnode");
+        if(rows.get(0).getBoolean("rb")){
+            if(rows.get(0).getString("type").equals("销售出库")){
+                if (order_paymentnode.equals("3")) {
+                    if (Accountbalance.judgeBalance(this, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount"))) {
+                        CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount"),rows.get(0).getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "审核时生成");
+                        JSONObject createCashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
+                        sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                    } else {
+                        return getErrReturnObject().setErrMsg("账户余额不足,还差" + Accountbalance.InsufficientBalance(this, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!").toString();
+                    }
+                }
+                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
+                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
+                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
+                Rows rowsjudge =dbConnect.runSqlQuery("select * from (select sa_orderitemsid,sum(qty) qty from st_stockbill_items where st_stockbillid ='"+st_stockbillid+"' group by sa_orderitemsid) t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid where t1.qty>t2.undeliqty");
+                if(rowsjudge.isNotEmpty()){
+                    return getErrReturnObject().setErrMsg("存在商品已完全出库,无法审核").toString();
+                }
+                for (Row row : rowsDispatchDetailGroup) {
+                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").subtract(row.getBigDecimal("qty")) + ",deliedqty=" + (row.getBigDecimal("qty").add(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
+                }
+            }
+            for(Row row :rowsdetail){
+                String itemid= row.getString("itemid");
+                long stockid=row.getLong("stockid");
+                if(stockRowsMap.containsKey(itemid)){
+                    for(Row row1 :stockRowsMap.get(itemid)){
+                        if(row1.getLong("stockid")==stockid){
+                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
+                        }
+                    }
+                }
+                // String batchno = row.getString("batchno");
+            }
+        }else{
+            for(Row row :rowsdetail){
+                String itemid= row.getString("itemid");
+                long stockid=row.getLong("stockid");
+                if(stockRowsMap.containsKey(itemid)){
+                    for(Row row1 :stockRowsMap.get(itemid)){
+                        if(row1.getLong("stockid")==stockid){
+                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
+                        }
+                    }
+                }
+                // String batchno = row.getString("batchno");
+            }
         }
+//            Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
+//            Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
+//            RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
 
-        //返利比例
-        String icstockbillrebateaccount = Parameter.get(siteid, "icstockbillrebateaccount"); //经销商销售出库单返利账户
-        long res = Long.valueOf(icstockbillrebateaccount).longValue();
-        String icstockbillrebaterate1 = Parameter.get(siteid, "icstockbillrebaterate"); //销售出库单返利比例
-        BigDecimal icstockbillrebaterate = new BigDecimal(icstockbillrebaterate1);
-        //经销商返利
-        BigDecimal rebateamount = icstockbillrebaterate.multiply(billamount);
-
-        CashbillEntity entity = new CashbillEntity();
-        entity.setAmount(rebateamount);
-        entity.setOwnerid(st_stockbillid);
-        entity.setOwnertable("st_stockbill");
-        entity.setSource("");
-        entity.setRemarks("销售出库单" + rows.get(0).getString("billno") + "返利");
-        JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, Long.valueOf(icstockbillrebateaccount).longValue(), entity, true, false);
-        sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
-        Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
 
         SQLFactory sqlFactoryupdate = new SQLFactory(this, "出入库单审核");
         sqlFactoryupdate.addParameter("siteid", siteid);
@@ -198,18 +412,23 @@ public class stockbill extends Controller {
         sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "审核", "出入库单审核成功").getSQL());
         dbConnect.runSqlUpdate(sqlList);
 
-        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
+//        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
         return getSucReturnObject().toString();
 
     }
 
 
     @API(title = "反审核", apiversion = R.ID20230719154203.v1.class)
-    @CACHEING_CLEAN(apiClass = {stockbill.class})
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class, Order.class, OrderItems.class})
     public String uncheck() throws YosException {
         Long st_stockbillid = content.getLong("st_stockbillid");
-        Rows rows = dbConnect.runSqlQuery("select st_stockbillid,status,billno from st_stockbill where st_stockbillid ='"
+
+        Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
+                + st_stockbillid + "' and  siteid='" + siteid + "'");
+        Rows rowsdetail = dbConnect.runSqlQuery("select * from st_stockbill_items where st_stockbillid ='"
                 + st_stockbillid + "' and  siteid='" + siteid + "'");
+        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
+
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该出入库单不存在")
                     .toString();
@@ -219,38 +438,83 @@ public class stockbill extends Controller {
                         .toString();
             }
         }
-
+        for(Row row : rowsdetail){
+            if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
+                return getErrReturnObject().setErrMsg("表体数量不能小于0").toString();
+            }
+        }
+        if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(BigDecimal.ZERO)<0) {
+            return getErrReturnObject().setErrMsg("优惠金额不能小于0").toString();
+        }
+        if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
+            return getErrReturnObject().setErrMsg("扣款金额需大于0").toString();
+        }
+        if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
+            return getErrReturnObject().setErrMsg("发货地不可为空").toString();
+        }
+        if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
+            return getErrReturnObject().setErrMsg("扣款金额与应扣金额不符,不能反审核").toString();
+        }
+        Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
+        if (accountbalancerows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("账户不存在").toString();
+        }
+        if (rows.get(0).getString("type").equals("销售出库") && rows.get(0).getBoolean("isreceiver")) {
+            return getErrReturnObject().setErrMsg("经销商已经确认收货,不可进行反审核").toString();
+        }
         ArrayList<String> sqlList = new ArrayList<>();
-
-        long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
-
-        BigDecimal billamount = BigDecimal.ZERO;
-        Rows stockbilldetails = dbConnect.runSqlQuery("select * from st_stockbill_items where st_stockbillid ='"
-                + st_stockbillid + "' and  siteid='" + siteid + "'");
-        for (Row row : stockbilldetails) {
-            billamount = billamount.add(row.getBigDecimal("amount").abs().negate());
+        Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
+        RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
+
+        String order_paymentnode = Parameter.get(siteid, "order_paymentnode");
+        if(rows.get(0).getBoolean("rb")){
+            if(rows.get(0).getString("type").equals("销售出库")){
+                if (order_paymentnode.equals("3")) {
+                    if (Accountbalance.judgeBalance(this, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount").negate())) {
+                        CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount").negate(),rows.get(0).getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单反审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "反审核时生成");
+                        JSONObject createCashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
+                        sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                    } else {
+                        return getErrReturnObject().setErrMsg("账户余额不足,还差" + Accountbalance.InsufficientBalance(this, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!").toString();
+                    }
+                }
+                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
+                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
+                Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1  where  t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
+                for (Row row : rowsDispatchDetailGroup) {
+                    sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
+                }
+            }
+            for(Row row :rowsdetail){
+                String itemid= row.getString("itemid");
+                long stockid=row.getLong("stockid");
+                if(stockRowsMap.containsKey(itemid)){
+                    for(Row row1 :stockRowsMap.get(itemid)){
+                        if(row1.getLong("stockid")==stockid){
+                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
+                        }
+                    }
+                }
+                // String batchno = row.getString("batchno");
+            }
+        }else{
+            for(Row row :rowsdetail){
+                String itemid= row.getString("itemid");
+                long stockid=row.getLong("stockid");
+                if(stockRowsMap.containsKey(itemid)){
+                    for(Row row1 :stockRowsMap.get(itemid)){
+                        if(row1.getLong("stockid")==stockid){
+                            sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
+                        }
+                    }
+                }
+                // String batchno = row.getString("batchno");
+            }
         }
+//            Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
+//            Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
+//            RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
 
-        //返利比例
-        String icstockbillrebateaccount = Parameter.get(siteid, "icstockbillrebateaccount"); //经销商销售出库单返利账户
-        long res = Long.valueOf(icstockbillrebateaccount).longValue();
-        String icstockbillrebaterate1 = Parameter.get(siteid, "icstockbillrebaterate"); //销售出库单返利比例
-        BigDecimal icstockbillrebaterate = new BigDecimal(icstockbillrebaterate1);
-        //经销商返利
-        BigDecimal rebateamount = icstockbillrebaterate.multiply(billamount);
-
-        CashbillEntity entity = new CashbillEntity();
-        entity.setAmount(rebateamount);
-        entity.setOwnerid(st_stockbillid);
-        entity.setOwnertable("st_stockbill");
-        entity.setSource("");
-        entity.setRemarks("销售出库单" + rows.get(0).getString("billno") + "返利");
-        if (!Accountbalance.judgeBalance(this, sys_enterpriseid, Long.valueOf(icstockbillrebateaccount).longValue(), rebateamount)) {
-            return getErrReturnObject().setErrMsg("账户余额不足,还差" + Accountbalance.InsufficientBalance(this, sys_enterpriseid, Long.valueOf(icstockbillrebateaccount).longValue(), rebateamount) + "元!").toString();
-        }
-        JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, Long.valueOf(icstockbillrebateaccount).longValue(), entity, true, false);
-        sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
-        Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
 
         SQLFactory sqlFactoryupdate = new SQLFactory(this, "出入库单反审核");
         sqlFactoryupdate.addParameter("siteid", siteid);
@@ -260,57 +524,36 @@ public class stockbill extends Controller {
         sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "反审核", "出入库单反审核成功").getSQL());
         dbConnect.runSqlUpdate(sqlList);
 
-        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
+//        Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
         return getSucReturnObject().toString();
     }
 
-
-    @API(title = "出入库单明细列表", apiversion = R.ID20230719154303.v1.class)
-    @CACHEING
-    public String querStcokbillItemsList() throws YosException {
-        /*
-         * 过滤条件设置
-         */
-        StringBuffer where = new StringBuffer(" 1=1 ");
-        if (content.containsKey("where")) {
-            JSONObject whereObject = content.getJSONObject("where");
-            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
-                where.append(" and(");
-                where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append(")");
-            }
-        }
+    @API(title = "仓库确认", apiversion = R.ID2025050709505703.v1.class)
+    public String confirm() throws YosException {
         Long st_stockbillid = content.getLong("st_stockbillid");
-        Rows stockbillrows = dbConnect.runSqlQuery("select st_stockbillid,status,billno,rb from st_stockbill where st_stockbillid ='"
+        boolean isconfirm = content.getBooleanValue("isconfirm");
+        Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
                 + st_stockbillid + "' and  siteid='" + siteid + "'");
-        boolean rb = false;
-        if (stockbillrows.isNotEmpty()) {
-            rb = stockbillrows.get(0).getBoolean("rb");
-        }
-        SQLFactory sqlFactory;
-        if (rb) {
-            sqlFactory = new SQLFactory(this, "出入库单明细列表查询");
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("该出入库单不存在")
+                    .toString();
         } else {
-            sqlFactory = new SQLFactory(this, "出入库单明细列表查询(红)");
+            if (!rows.get(0).getString("status").equals("审核")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非审核状态,无法进行仓库确认")
+                        .toString();
+            }
         }
-
-        sqlFactory.addParameter_SQL("where", where);
-        sqlFactory.addParameter("st_stockbillid", st_stockbillid);
-        sqlFactory.addParameter("siteid", siteid);
-//        Rows rows = dbConnect.runSqlQuery(sqlFactory);
-        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_site_parameter",  "sys_site_parameterid");
-        querySQL.setTableAlias("t0");
-        querySQL.addJoinTable(JOINTYPE.right, sqlFactory, "t1", "t0.siteid='111'","*");
-        querySQL.setPage(pageSize, pageNumber);
-        querySQL.setOrderBy(pageSorting);
-        Rows rows = querySQL.query();
-
-        return getSucReturnObject().setData(rows).toString();
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_stockbill");
+        updateSQL.setUniqueid(st_stockbillid);
+        updateSQL.setSiteid(siteid);
+        updateSQL.setValue("isconfirm", isconfirm);
+        updateSQL.setValue("changeby", username);
+        updateSQL.setDateValue("changedate");
+        dbConnect.runSqlUpdate(updateSQL.getSQL());
+        return getSucReturnObject().toString();
     }
 
+
     @API(title = "更新站点信息详情详情", apiversion = R.ID20230720143503.v1.class)
     public String updateParameterSiteInfo() throws YosException {
         BigDecimal icstockbillrebaterate = content.getBigDecimal("icstockbillrebaterate");
@@ -329,5 +572,16 @@ public class stockbill extends Controller {
         return getSucReturnObject().setData(row).toString();
     }
 
+    public CashbillEntity getCashbillEntity(BigDecimal amount,BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks) throws YosException {
+        CashbillEntity entity = new CashbillEntity();
+        entity.setAmount(amount);
+        entity.setDiscountamountamount(discountamount);
+        entity.setOwnerid(ownerid);
+        entity.setOwnertable("st_stockbill");
+        entity.setSource(source);
+        entity.setRemarks(remarks);
+        entity.setSourcenote(sourcenotes);
+        return entity;
 
+    }
 }

+ 262 - 0
src/custom/restcontroller/webmanage/sale/stockbill/stockbillitems.java

@@ -0,0 +1,262 @@
+package restcontroller.webmanage.sale.stockbill;
+
+import beans.data.BatchDeleteErr;
+import beans.datacontrllog.DataContrlLog;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.annotation.CACHEING;
+import common.annotation.CACHEING_CLEAN;
+import common.data.*;
+import restcontroller.R;
+import restcontroller.webmanage.sale.order.Order;
+import restcontroller.webmanage.sale.order.OrderItems;
+
+import java.util.ArrayList;
+
+public class stockbillitems extends Controller {
+    public stockbillitems(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "出库商品列表查询", apiversion = R.ID2025050614581203.v1.class)
+    @CACHEING
+    public String queryOrderItemgList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.unit like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.sonum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.typemx like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("sa_orderid") && !"".equals(whereObject.getString("sa_orderid"))) {
+                Long sa_orderid = whereObject.getLongValue("sa_orderid");
+                if (sa_orderid > 0) {
+                    where.append("  and t1.sa_orderid ='").append(sa_orderid).append("' ");
+                }
+            }
+            if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
+                where.append(" and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
+            }
+            if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
+                where.append(" and DATE_FORMAT(t3.checkdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
+            }
+        }
+//        SQLFactory sqlFactory = new SQLFactory(this, "发货商品列表查询", pageSize, pageNumber, pageSorting);
+//        sqlFactory.addParameter_SQL("where", where);
+//        sqlFactory.addParameter("sys_enterpriseid", content.getLongValue("sys_enterpriseid"));
+//        sqlFactory.addParameter("sa_dispatchid", content.getLongValue("sa_dispatchid"));
+//        sqlFactory.addParameter("siteid", siteid);
+//
+//        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_orderitems", "sa_orderitemsid", "sa_orderid",
+                "itemid","unit","undeliqty","remarks","rowno","customproperties","price","defaultprice");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.siteid = t2.siteid and t1.itemid = t2.itemid","itemno","itemname","model","spec","batchcontrol");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_order", "t3", "t1.siteid=t3.siteid and t1.sa_orderid=t3.sa_orderid","sonum","billdate","createdate","submitdate","checkdate","typemx","abstract");
+        querySQL.addQueryFields("orderremarks","t3.remarks");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t3.STATUS = '审核' and ifnull(t1.undeliqty, 0) !=0 and ifnull(t1.isfreeze, 0) =0 AND ifnull( t1.isclose, 0 )= 0");
+        querySQL.setWhere("t3.sys_enterpriseid",content.getLongValue("sys_enterpriseid"));
+        querySQL.setWhere("if(ifnull(t2.batchcontrol,0)!=0,1=1,t1.sa_orderitemsid not in (select sa_orderitemsid from st_stockbill_items where st_stockbillid='"+content.getLongValue("st_stockbillid")+"'))");
+        //querySQL.setWhere("t1.sa_orderitemsid not in(select t1.sa_orderitemsid from (select t1.sa_orderitemsid,t1.siteid,SUM(t1.qty) qty from sa_dispatch_items t1 inner join sa_dispatch t2 on t1.sa_dispatchid=t2.sa_dispatchid and t1.siteid=t2.siteid where t2.status in('新建','提交') group by t1.sa_orderitemsid,t1.siteid) t1 inner join  sa_orderitems t3 on t1.sa_orderitemsid=t3.sa_orderitemsid and t1.siteid=t3.siteid where t3.undeliqty=t1.qty)");
+        querySQL.setWhere(where.toString());
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "出入库单明细新增更新", apiversion = R.ID2025050614284803.v1.class)
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
+    public String insertormodify_stcokbillItems() throws YosException {
+        Long st_stockbillid = content.getLong("st_stockbillid");
+        JSONArray iteminfos = content.getJSONArray("iteminfos");
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows rowscount = dbConnect.runSqlQuery("select billno,status from st_stockbill where st_stockbillid=" + st_stockbillid);
+        if (!rowscount.isEmpty()) {
+            if (!rowscount.get(0).getString("status").equals("新建")) {
+                return getErrReturnObject().setErrMsg("非新建状态的出库单无法新增修改").toString();
+            }
+        }
+        int i = 0;
+        long maxid = 0;
+        long[] st_stockbill_itemsid = createTableID("st_stockbill_items", iteminfos.size());
+        Rows maxidRows = dbConnect
+                .runSqlQuery("select MAX(rowno) rowno from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+        if (!maxidRows.isEmpty()) {
+            maxid = maxidRows.get(0).getLong("rowno");
+        }
+        for (Object obj : iteminfos) {
+            JSONObject iteminfo = (JSONObject) obj;
+            if (iteminfo.getLong("st_stockbill_itemsid") <= 0 || dbConnect
+                    .runSqlQuery("select st_stockbill_itemsid from st_stockbill_items where st_stockbill_itemsid="
+                            + iteminfo.getLong("st_stockbill_itemsid"))
+                    .isEmpty()) {
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
+                insertSQL.setUniqueid(st_stockbill_itemsid[i]);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("rowno", maxid + i + 1);
+                insertSQL.setValue("st_stockbillid", st_stockbillid);
+                insertSQL.setValue("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
+                insertSQL.setValue("itemid", iteminfo.getStringValue("itemid"));
+                insertSQL.setValue("sa_orderid", iteminfo.getStringValue("sa_orderid"));
+                insertSQL.setValue("qty", iteminfo.getStringValue("qty"));
+                insertSQL.setValue("discountrate", iteminfo.getBigDecimal("discountrate"));
+                insertSQL.setValue("sa_dispatch_itemsid", 0);
+                insertSQL.setValue("defaultprice", iteminfo.getStringValue("defaultprice"));
+                insertSQL.setValue("remarks", iteminfo.getStringValue("remarks"));
+                insertSQL.setValue("itemno", iteminfo.getStringValue("itemno"));
+                insertSQL.setValue("itemname", iteminfo.getStringValue("itemname"));
+                insertSQL.setValue("model", iteminfo.getStringValue("model"));
+                insertSQL.setValue("price", iteminfo.getStringValue("price"));
+                insertSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
+                i++;
+                sqlList.add(insertSQL.getSQL());
+            } else {
+                Rows rows = dbConnect.runSqlQuery(
+                        "SELECT status from st_stockbill WHERE st_stockbillid = "
+                                + st_stockbillid);
+                if (rows.isNotEmpty()) {
+                    if (rows.get(0).getString("status").equals("新建")) {
+
+                        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_stockbill_items");
+                        updateSQL.setUniqueid(iteminfo.getLong("st_stockbill_itemsid"));
+                        updateSQL.setSiteid(siteid);
+                        updateSQL.setValue("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
+                        updateSQL.setValue("itemid", iteminfo.getString("itemid"));
+                        updateSQL.setValue("sa_orderid", iteminfo.getString("sa_orderid"));
+                        updateSQL.setValue("qty", iteminfo.getString("qty"));
+                        updateSQL.setValue("discountrate", iteminfo.getString("discountrate"));
+                        updateSQL.setValue("defaultprice", iteminfo.getString("defaultprice"));
+                        updateSQL.setValue("remarks", iteminfo.getString("remarks"));
+                        updateSQL.setValue("itemno", iteminfo.getString("itemno"));
+                        updateSQL.setValue("itemname", iteminfo.getString("itemname"));
+                        updateSQL.setValue("model", iteminfo.getString("model"));
+                        updateSQL.setValue("price", iteminfo.getString("price"));
+                        updateSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
+                        updateSQL.setValue("batchno", iteminfo.getString("batchno"));
+                        updateSQL.setValue("stockid", iteminfo.getString("stockid"));
+                        sqlList.add(updateSQL.getSQL());
+                    } else {
+                        return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                    }
+
+                } else {
+                    return getErrReturnObject().setErrMsg("该销售出库单不存在").toString();
+                }
+            }
+
+        }
+
+        dbConnect.runSqlUpdate(sqlList);
+        return querStcokbillItemsList();
+    }
+
+
+    @API(title = "出入库单明细列表", apiversion = R.ID20230719154303.v1.class)
+    @CACHEING
+    public String querStcokbillItemsList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        Long st_stockbillid = content.getLong("st_stockbillid");
+        Rows stockbillrows = dbConnect.runSqlQuery("select st_stockbillid,status,billno,rb,type from st_stockbill where st_stockbillid ='"
+                + st_stockbillid + "' and  siteid='" + siteid + "'");
+        String type = "销售出库";
+        if (stockbillrows.isNotEmpty()) {
+            type = stockbillrows.get(0).getString("type");
+        }
+        SQLFactory sqlFactory;
+        if (type.equals("销售出库")) {
+            sqlFactory = new SQLFactory(this, "出入库单明细列表查询");
+        } else {
+            sqlFactory = new SQLFactory(this, "出入库单明细列表查询(红)");
+        }
+
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("st_stockbillid", st_stockbillid);
+        sqlFactory.addParameter("siteid", siteid);
+//        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_site_parameter",  "sys_site_parameterid");
+        querySQL.setTableAlias("t0");
+        querySQL.addJoinTable(JOINTYPE.right, sqlFactory, "t1", "t0.siteid='111'","*");
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除明细", apiversion = R.ID2025050614510403.v1.class)
+    @CACHEING_CLEAN(apiClass = {stockbill.class, stockbillitems.class})
+    public String deletemx() throws YosException {
+
+
+        JSONArray st_stockbill_itemsids = content.getJSONArray("st_stockbill_itemsids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_stockbill_itemsids.size());
+        long st_stockbillid = 0;
+        for (Object o : st_stockbill_itemsids) {
+            long st_stockbill_itemsid = Long.parseLong(o.toString());
+            Rows RowsStatus = dbConnect.runSqlQuery("select t1.st_stockbill_itemsid,t2.status,t1.st_stockbillid from st_stockbill_items t1 left join st_stockbill t2 on t1.st_stockbillid=t2.st_stockbillid and t1.siteid=t2.siteid where t1.siteid='"
+                    + siteid + "' and t1.st_stockbill_itemsid='" + st_stockbill_itemsid + "'");
+
+            if (RowsStatus.isNotEmpty()) {
+                st_stockbillid = RowsStatus.get(0).getLong("st_stockbillid");
+                if (!RowsStatus.get(0).getString("status").equals("新建")) {
+                    batchDeleteErr.addErr(st_stockbill_itemsid, "非新建状态的出库单明细无法删除");
+                    continue;
+                }
+            }
+            ArrayList<String> list = new ArrayList<>();
+            list.add("delete from st_stockbill_items where siteid='" + siteid
+                    + "' and st_stockbill_itemsid=" + st_stockbill_itemsid);
+
+            dbConnect.runSqlUpdate(list);
+        }
+        //重新排序
+        updateRowNo(st_stockbillid);
+        return batchDeleteErr.getReturnObject().toString();
+    }
+    /**
+     * 重新对发货单行进行排序
+     *
+     * @param
+     * @throws YosException
+     */
+    public void updateRowNo(Long st_stockbillid) throws YosException {
+        String sql = "SELECT st_stockbill_itemsid from st_stockbill_items WHERE st_stockbillid= " + st_stockbillid + " and siteid = '" + siteid + "' ORDER  BY st_stockbill_itemsid asc ";
+        ArrayList<Long> st_stockbill_itemsids = dbConnect.runSqlQuery(sql).toArrayList("st_stockbill_itemsid", new ArrayList<>());
+        ArrayList<String> sqlList = new ArrayList<>();
+        int rowno = 1;
+        for (Long id : st_stockbill_itemsids) {
+            sqlList.add("UPDATE st_stockbill_items SET rowno=" + rowno + " WHERE st_stockbill_itemsid = " + id);
+            rowno++;
+        }
+        dbConnect.runSqlUpdate(sqlList);
+    }
+
+}

+ 1 - 1
src/custom/restcontroller/webmanage/sale/transferbill/Transferbill.java

@@ -127,7 +127,7 @@ public class Transferbill extends Controller {
         ArrayList<Long> sa_cashbillidList = new ArrayList<>();
         sqlList.add("update sa_transferbill set checkby='" + username + "',checkdate=current_date,status='审核' where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
 
-        CashbillEntity cashbillEntity = new CashbillEntity(amount.negate(), "", "转账单", rows.get(0).getString("billno"), "sa_transferbill", sa_transferbillid, "货款", "");
+        CashbillEntity cashbillEntity = new CashbillEntity(amount.negate(),BigDecimal.ZERO, "", "转账单", rows.get(0).getString("billno"), "sa_transferbill", sa_transferbillid, "货款", "");
         cashbillEntity.setPeriod(rows.get(0).getString("billno"));
 
         JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, sa_accountclassid, cashbillEntity, true, false);

+ 85 - 352
src/custom/utility/test.java

@@ -1,361 +1,94 @@
 package utility;
 
-import beans.accountbalance.Accountbalance;
-import beans.accountbalance.CashbillEntity;
-import beans.itemclass.ItemClass;
-import beans.itemprice.ItemPrice;
-import beans.parameter.Parameter;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import common.Controller;
-import common.ServiceController;
-import common.YosException;
-import common.data.*;
-import common.data.db.DBConnect;
-import org.apache.commons.collections4.bag.SynchronizedSortedBag;
-import org.apache.commons.lang.StringUtils;
-import org.sqlite.SQLiteConfig;
-import restcontroller.sale.itemgroup.itemgroup;
-import restcontroller.webmanage.sale.dispatch.dispatch;
-import restcontroller.webmanage.sale.itemclass.SortByNum;
-import restcontroller.webmanage.sale.order.OrderImport;
-import service.DispatchAutoCloseService;
-import utility.tools.WebRequest;
-
-import java.io.*;
-import java.math.BigDecimal;
-import java.net.ConnectException;
-import java.net.URL;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.Date;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import static beans.accountbalance.Accountbalance.createCashbillIncome;
-
+import java.util.Arrays;
+import java.lang.System;
+import com.alibaba.dashscope.aigc.generation.Generation;
+import com.alibaba.dashscope.aigc.generation.GenerationParam;
+import com.alibaba.dashscope.aigc.generation.GenerationResult;
+import com.alibaba.dashscope.common.Message;
+import com.alibaba.dashscope.common.Role;
+import com.alibaba.dashscope.exception.ApiException;
+import com.alibaba.dashscope.exception.InputRequiredException;
+import com.alibaba.dashscope.exception.NoApiKeyException;
+import com.alibaba.dashscope.tools.FunctionDefinition;
+import com.alibaba.dashscope.tools.ToolFunction;
+import com.alibaba.dashscope.utils.JsonUtils;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.github.victools.jsonschema.generator.*;
 
 public class test  {
-    public static void main(String[] args) throws YosException, UnsupportedEncodingException {
-        try {
-            System.out.println(WzwlDocking.digest_MD5_Base64("",""));
-
-            // 需要转换的字符串
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("companyCode","202409241033166130229eade94bece");
-            jsonObject.put("orderNo","LSA2020926");
-            System.out.println(jsonObject.toString().replace("\"","'"));
-            String inputString="{'companyCode':'202409241033166130229eade94bece','orderNo':'LO202410220013'}mIAZwKEaUOpp";
-            String inputStrin5="{'companyCode':'202409241033166130229eade94bece','consigner':{'address':'浙江省嘉兴市秀洲区王店镇瑞博大道968号','province':'浙江省','phone':'18967389665','city':'嘉兴市','district':'秀洲区','name':'孙卫刚','mobile':'18967389665','company':'来斯奥集成家居股份有限公司'},'custOrderNo':'LO202410110003','submitTime':1728635263701,'consignee':{'address':'智慧产业创新园','province':'浙江省','phone':'15888888888','city':'嘉兴市','district':'嘉善县','name':'哈哈哈','mobile':'15888888888','company':''},'isPickup':'false','remark':'备注6','logisticCompanyID':'WZ','cargo':[{'num':10.0000,'name':'卡利尔'},{'num':2.0000,'name':'A1薄悦多功能机'}],'settleType':1,'deliverType':1}mIAZwKEaUOpp";
-            System.out.println(inputString);
-            System.out.println(inputString.equals(inputStrin5));
-            for (int i = 0; i < inputString.length() && i < inputStrin5.length(); i++) {
-                if (inputString.charAt(i) != inputStrin5.charAt(i)) {
-                    System.out.println("Strings are different at index " + i+inputString.charAt(i));
-                }
-            }
-            // 创建MD5摘要
-            MessageDigest md = MessageDigest.getInstance("MD5");
-            md.update(inputString.getBytes());
-            byte[] digest = md.digest();
-
-            // 将摘要转换为Base64字符串
-            String base64Digest = Base64.getEncoder().encodeToString(digest);
-
-            // 输出Base64转换后的摘要
-            System.out.println("Base64 Encoded MD5 Digest: " + base64Digest);
-        } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public static void executeAutoRebate(Long sa_orderid, String siteid) throws YosException {
-        DBConnect dbConnect= new DBConnect();
-        Rows orderRows = dbConnect.runSqlQuery("SELECT * from sa_order WHERE sa_orderid = " + sa_orderid + " and siteid = '" + siteid + "'");
-        if (orderRows.get(0).getString("type").equals("促销订单")) {
-            return;
-        }
-        Long sys_enterpriseid = orderRows.get(0).getLong("sys_enterpriseid");
-
-
-        //是否自动返利结算
-        String isrebate = Parameter.get(siteid, "isrebate");
-        if (!isrebate.equals("1")) {
-            return;
-        }
-        //查询有效期内,余额大于0 的经销商装修补贴返利
-        String sql = "select * from sa_agentdecorationtrebate WHERE sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "' and begindate <= current_date and enddate>=current_date and balance>0";
-        Rows agentdecorationtrebatRows = dbConnect.runSqlQuery(sql);
-        if (agentdecorationtrebatRows.isEmpty()) {
-            return;
-        }
-        //查询装修返利方案
-        Rows rebateschemeRows = dbConnect.runSqlQuery("select * from sa_rebatescheme where siteid='" + siteid + "'");
-        if (rebateschemeRows.isEmpty()) {
-            return;
-        }
-        ArrayList<String> sqlList = new ArrayList<>();
-        Long sa_rebateschemeid = rebateschemeRows.get(0).getLong("sa_rebateschemeid");
-        Long sa_accountclassid = rebateschemeRows.get(0).getLong("sa_accountclassid");
-
-        Rows rebatecategorys = dbConnect.runSqlQuery("select itemclassid from sa_rebatecategory where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
-        Rows rebateunproducts = dbConnect.runSqlQuery("select itemid from sa_rebateunproducts where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
-
-        ArrayList<Long> itemclsids = rebatecategorys.toArrayList("itemclassid", new ArrayList<Long>());
-
-        itemclsids.addAll(ItemClass.getSubItemClassIds(dbConnect, siteid, itemclsids));
-        itemclsids.add(0l);
-        ArrayList<Long> itemids = rebateunproducts.toArrayList("itemid", new ArrayList<Long>());
-        itemids.add(0l);
-
-        SQLFactory sqlFactory = new SQLFactory(new DispatchAutoCloseService(), "查询返利数据");
-        sqlFactory.addParameter("sa_orderid", sa_orderid);
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter_in("itemclassid", itemclsids);
-        sqlFactory.addParameter_in("itemid", itemids);
-
-        Rows rows = dbConnect.runSqlQuery(sqlFactory);
-        BigDecimal saorderamount = BigDecimal.ZERO;
-        for (Row row : rows) {
-            saorderamount = saorderamount.add(row.getBigDecimal("amount"));
-        }
-        //查询定制费用
-        sql = "SELECT ifnull(sum(costamount),0) costamount from sa_order_cost WHERE sa_orderid=" + sa_orderid;
-        BigDecimal costamount = dbConnect.runSqlQuery(0, sql).getBigDecimal("costamount");
-        saorderamount = saorderamount.add(costamount);
-
-
-        BigDecimal balance = agentdecorationtrebatRows.get(0).getBigDecimal("balance");
-        BigDecimal brate = agentdecorationtrebatRows.get(0).getBigDecimal("brate");
-
-
-        BigDecimal approvedamount = BigDecimal.ZERO;
-        if (balance.compareTo(saorderamount.multiply(brate)) >= 0) {
-            approvedamount = saorderamount.multiply(brate);
-        } else if (balance.compareTo(BigDecimal.ZERO) > 0) {
-            approvedamount = balance;
-        }
-        System.out.println(saorderamount);
-        System.out.println(approvedamount);
-
-        if (approvedamount.compareTo(BigDecimal.ZERO) > 0) {
-            ArrayList<Long> sa_orderitemsids = rows.toArrayList("sa_orderitemsid", new ArrayList<>());
-            sa_orderitemsids.add(0l);
-
-            //更新订单明细的装修返利标志
-            UpdateSQL updateSQL = SQLFactory.createUpdateSQL(dbConnect, "sa_orderitems");
-            updateSQL.setWhere("sa_orderitemsid", sa_orderitemsids);
-            updateSQL.setValue("decorationrebateflag", "1");
-            sqlList.add(updateSQL.getSQL());
-
-            //更新sa_agentdecorationtrebate
-            updateSQL = SQLFactory.createUpdateSQL(dbConnect, "sa_agentdecorationtrebate");
-            updateSQL.setWhere("sys_enterpriseid", sys_enterpriseid);
-            updateSQL.setSiteid(siteid);
-            updateSQL.setValue("balance", balance.subtract(approvedamount));
-            sqlList.add(updateSQL.getSQL());
-
-            //生成收入凭证
-            CashbillEntity entity = new CashbillEntity();
-            entity.setAmount(approvedamount);
-            entity.setOwnerid(sa_orderid);
-            entity.setOwnertable("sa_order");
-            entity.setSource("订单自动返利");
-            entity.setType("公司支持");
-            entity.setTypemx("装修返利");
-            entity.setSourcenote(orderRows.get(0).getString("sonum"));
-            entity.setRemarks(orderRows.get(0).getString("sonum") + "订单自动返利");
-            JSONObject cashbillIncome = createCashbillIncome(siteid, sys_enterpriseid, sa_accountclassid, entity, true, true);
-            sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
-
-            System.err.println(sqlList);
-            dbConnect.runSqlUpdate(sqlList);
-        }
-    }
-    /**
-     * 创建收入凭证(返回SQL)
-     *
-     * @param siteid
-     * @param sys_enterpriseid  企业id
-     * @param sa_accountclassid 账户id
-     * @param cashbillEntity    收支凭证实体
-     * @param ischeck           是否审核
-     * @return
-     * @throws YosException
-     */
-    public static JSONObject createCashbillIncome(String siteid, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, boolean isupdatek3flag) throws YosException {
-        DBConnect dbConnect= new DBConnect();
-        long userid = 1;
-        String username = "admin";
-
-        ArrayList<String> sqlList = new ArrayList<>();
-        long sa_cashbillid = 11;
-        String billcode = "111111";
-        SQLFactory sqlFactory = new SQLFactory(new Accountbalance(), "收支凭证新增");
-        sqlFactory.addParameter("billno", billcode);
-        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
-        sqlFactory.addParameter("type", 1);
-        sqlFactory.addParameter("siteid", siteid);
-        sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
-        sqlFactory.addParameter("amount", cashbillEntity.getAmount());
-        sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
-        sqlFactory.addParameter("userid", userid);
-        sqlFactory.addParameter("username", username);
-        sqlFactory.addParameter("ownertable", cashbillEntity.getOwnertable());
-        sqlFactory.addParameter("ownerid", cashbillEntity.getOwnerid());
-        sqlFactory.addParameter("source", cashbillEntity.getSource());
-        sqlFactory.addParameter("sourcenote", cashbillEntity.getSourcenote());
-        sqlFactory.addParameter("sa_cashbillid_rebate", "null");
-        sqlFactory.addParameter("class", cashbillEntity.getType());
-        sqlFactory.addParameter("period",new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
-        sqlFactory.addParameter("subclass", cashbillEntity.getTypemx());
-        if (ischeck) {
-            BigDecimal balance = BigDecimal.ZERO;  //当前账户余额
-            sqlFactory.addParameter("status", "审核");
-            if (isupdatek3flag) {
-                sqlFactory.addParameter("updatek3flag", "0");
-            } else {
-                sqlFactory.addParameter("updatek3flag", "");
-            }
-            sqlFactory.addParameter("checkby", username);
-            sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
-
-            // 审核逻辑判断
-            Rows rowsaccountbalance = dbConnect.runSqlQuery(
-                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
-                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
-                            + siteid + "'");
-
-            if (rowsaccountbalance.isEmpty()) {
-                SQLFactory accountbalanceaddSqlFactory = new SQLFactory(new Accountbalance(), "营销账户余额新增");
-                accountbalanceaddSqlFactory.addParameter("sa_accountbalanceid",
-                        "999999999");
-                accountbalanceaddSqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-                accountbalanceaddSqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
-                accountbalanceaddSqlFactory.addParameter("siteid", siteid);
-                accountbalanceaddSqlFactory.addParameter("balance", cashbillEntity.getAmount());
-                accountbalanceaddSqlFactory.addParameter("userid", userid);
-                accountbalanceaddSqlFactory.addParameter("username", username);
-                balance = cashbillEntity.getAmount();
-                sqlList.add(accountbalanceaddSqlFactory.getSQL());
-            } else {
-                BigDecimal newbalance = cashbillEntity.getAmount().add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                sqlList.add("update sa_accountbalance set balance='" + newbalance
-                        + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='"
-                        + userid + "' where sys_enterpriseid ='" + sys_enterpriseid
-                        + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid
-                        + "'");
-                balance = newbalance;
-            }
-            sqlFactory.addParameter("balance", balance);
-            Rows accountclassrows = dbConnect.runSqlQuery("select * from sa_accountclass where siteid='" + siteid + "' and  sa_accountclassid=" + sa_accountclassid);
-            if (!accountclassrows.isEmpty()) {
-                String content = "您的" + accountclassrows.get(0).getString("accountname") + "已收入【" + cashbillEntity.getAmount() + "】元";
-                new Accountbalance().sendMsg(siteid, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
-            }
-
-        } else {
-            sqlFactory.addParameter("status", "新建");
-            sqlFactory.addParameter("checkby", "null");
-            sqlFactory.addParameter("checkdate", "null");
-            sqlFactory.addParameter("updatek3flag", "");
-            sqlFactory.addParameter("balance", 0);
-        }
-        sqlList.add(sqlFactory.getSQL());
-
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("sa_cashbillid", sa_cashbillid);
-        jsonObject.put("sqlList", sqlList);
-        return jsonObject;
-    }
-
-    public static boolean isNumeric(String strNum) {
-        if (strNum == null) {
-            return false;
-        }
-        return strNum.matches("-?\\d+(\\.\\d+)?");
-    }
-    private static class TrustAnyTrustManager implements X509TrustManager {
-        @Override
-        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-        }
-        @Override
-        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-        }
-        @Override
-        public X509Certificate[] getAcceptedIssuers() {
-            return null;
-        }
-    }
-    private static class TrustAnyHostnameVerifier implements HostnameVerifier {
-        public boolean verify(String hostname, SSLSession session) {
-            return true;
-        }
-    }
-    public static String sendHttps(String url) throws Exception {
-        InputStream in = null;
-        OutputStream out = null;
-        String returnValue = "";
-        try {
-            SSLContext sc = SSLContext.getInstance("SSL");
-//            System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
-//            SSLContext sc = SSLContext.getInstance("TLS", "SunJSSE");
-            //SSLContext sc = SSLContext.getInstance("TLS");
-            sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
-            URL console = new URL(url);
-            HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
-            conn.setSSLSocketFactory(sc.getSocketFactory());
-//            conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
-            conn.setRequestMethod("POST");
-            conn.connect();
-            InputStream is = conn.getInputStream();
-            DataInputStream indata = new DataInputStream(is);
-            returnValue = indata.readLine();
-            conn.disconnect();
-        } catch (ConnectException e) {
-            e.printStackTrace();
-            throw e;
-        } catch (IOException e) {
-            e.printStackTrace();
-            throw e;
-        } finally {
-            try {
-                in.close();
-            } catch (Exception e) {  }
-            try {
-                out.close();
-            } catch (Exception e) { }
-        }
-        return returnValue;
-    }
-    public static boolean isJSONArray(String jsonStr) {
-        try {
-            Object object = JSON.parse(jsonStr);
-            return object instanceof JSONArray;
-        } catch (Exception e) {
-            return false;
-        }
+    public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
+        Generation gen = new Generation();
+
+        // 创建SchemaGeneratorConfigBuilder实例,指定使用JSON格式的模式版本
+        SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON);
+
+        // 构建SchemaGeneratorConfig配置,包含额外的OpenAPI格式值,但不使用枚举的toString方法进行展平
+        SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
+                .without(Option.FLATTENED_ENUMS_FROM_TOSTRING)
+                .build();
+
+        // 根据配置创建SchemaGenerator实例,用于生成模式
+        SchemaGenerator generator = new SchemaGenerator(config);
+
+
+        // 生成GetWhetherTool类的JSON Schema
+        ObjectNode jsonSchema_order = generator.generateSchema(GetOrderTool.class);
+
+        // 构建获取预订单信息的函数定义
+        FunctionDefinition fd_order = FunctionDefinition.builder()
+                .name("get_current_Order") // 设置函数名称
+                .description("获取指定预订单的信息") // 设置函数描述
+                .parameters(JsonUtils.parseString(jsonSchema_order.toString()).getAsJsonObject()) // 设置函数参数
+                .build();
+
+
+        Message systemMsg = Message.builder()
+                .role(Role.SYSTEM.getValue())
+                .content("你是e订单的客服,请以愉快,友好的方式回复,你正在通过在线聊天系统与客户互动,在提到有关预订或解除预订的时候,必须从用户处获取预定号及姓名,获取预定号后使用工具,请讲中文")
+                .build();
+        Message userMsg = Message.builder()
+                .role(Role.USER.getValue())
+                .content("我是胡鑫晖")
+                .build();
+        Message userMsg1 = Message.builder()
+                .role(Role.ASSISTANT.getValue())
+                .content("你好,胡鑫晖先生/女士!很高兴为您服务。今天是2024年2月25日,有什么可以帮助您的吗?无论是查询订单状态、修改信息还是其他任何问题,我都会尽力协助您。😊")
+                .build();
+        Message userMsg2 = Message.builder()
+                .role(Role.USER.getValue())
+                .content("取消预订")
+                .build();
+        Message userMsg3 = Message.builder()
+                .role(Role.ASSISTANT.getValue())
+                .content("您好,胡鑫晖先生/女士!为了帮您取消预订,我需要您提供一下预订号以及具体的预订信息。请您方便告知一下预订号和姓名吗?这样我可以更快地为您处理取消事宜。\n" +
+                        "\n" +
+                        "如果您有任何其他问题或需要进一步的帮助,随时告诉我哦!\uD83D\uDE0A")
+                .build();
+        Message userMsg4 = Message.builder()
+                .role(Role.USER.getValue())
+                .content("20180104000054 胡鑫晖")
+                .build();
+        GenerationParam param = GenerationParam.builder()
+                // 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
+                .apiKey("sk-ded3e089f27a426d87e050bb20c4869a")
+                // 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
+                .model("qwen-plus")
+                .messages(Arrays.asList(systemMsg,userMsg,userMsg1,userMsg2,userMsg3,userMsg4))
+                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
+                .tools(Arrays.asList(
+                        ToolFunction.builder().function(fd_order).build()))
+                .build();
+        return gen.call(param);
     }
-    public static boolean isJSONObject(String jsonStr) {
+    public static void main(String[] args) {
         try {
-            Object object = JSON.parse(jsonStr);
-            return object instanceof JSONObject;
-        } catch (Exception e) {
-            return false;
+            GenerationResult result = callWithMessage();
+            System.out.println(JsonUtils.toJson(result));
+        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
+            System.err.println("错误信息:"+e.getMessage());
+            System.out.println("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code");
         }
+        System.exit(0);
     }
 }