浏览代码

返利方案增加参与返利商品

hu 1 年之前
父节点
当前提交
5fe1a8eab2

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

@@ -5568,6 +5568,28 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID20240722145303 {
+        public static class v1 {
+        }
+    }
+    public static class ID20240722145403 {
+        public static class v1 {
+        }
+    }
+    public static class ID20240722145503 {
+        public static class v1 {
+        }
+    }
+    public static class ID20240722145603 {
+        public static class v1 {
+        }
+    }
+    public static class ID20240722145703 {
+        public static class v1 {
+        }
+    }
+
 }
 
 

+ 7 - 1
src/custom/restcontroller/webmanage/sale/order/OrderItemsHelper.java

@@ -103,6 +103,7 @@ public class OrderItemsHelper extends BaseClass {
 
         Rows rebatecategorys = dbConnect.runSqlQuery("select itemclassid from sa_rebatecategory where siteid='" + controller.siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
         Rows rebateunproducts = dbConnect.runSqlQuery("select itemid from sa_rebateunproducts where siteid='" + controller.siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
+        Rows rebateunjoinproducts = dbConnect.runSqlQuery("select * from sa_rebateunjoinproducts where siteid='" +  controller.siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
 
         ArrayList<Long> itemclsids = rebatecategorys.toArrayList("itemclassid", new ArrayList<Long>());
 
@@ -110,13 +111,18 @@ public class OrderItemsHelper extends BaseClass {
         itemclsids.add(0l);
         ArrayList<Long> itemids = rebateunproducts.toArrayList("itemid", new ArrayList<Long>());
         itemids.add(0l);
-
+        ArrayList<Long> joinitemids = rebateunjoinproducts.toArrayList("itemid", new ArrayList<Long>());
+        String where =" 1=1 ";
+        if(!joinitemids.isEmpty()){
+            where=where+" and t1.itemid in"+joinitemids;
+        }
         SQLFactory sqlFactory = new SQLFactory(controller, "查询返利数据");
         sqlFactory.addParameter("sa_orderid", sa_orderid);
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter("siteid", controller.siteid);
         sqlFactory.addParameter_in("itemclassid", itemclsids);
         sqlFactory.addParameter_in("itemid", itemids);
+        sqlFactory.addParameter_SQL("where", where);
 
         Rows rows = controller.dbConnect.runSqlQuery(sqlFactory);
         BigDecimal saorderamount = BigDecimal.ZERO;

+ 2 - 1
src/custom/restcontroller/webmanage/sale/order/SQL/查询返利数据.sql

@@ -9,4 +9,5 @@ WHERE t2.sa_orderid = $sa_orderid$
   and t1.outwarehouseqty > 0
   and (t3.decorationrebateflag = 0 or t3.decorationrebateflag is null)
   and t1.itemid in (select itemid from sa_itemsaleclass where itemclassid in $itemclassid$)
-  and t1.itemid not in $itemid$
+  and t1.itemid not in $itemid$
+  and $where$

+ 27 - 13
src/custom/restcontroller/webmanage/sale/rebateaccount/rebateaccounthead.java

@@ -17,7 +17,6 @@ import common.data.Row;
 import common.data.Rows;
 import common.data.RowsMap;
 import common.data.SQLFactory;
-import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
 import java.io.IOException;
@@ -265,18 +264,21 @@ public class rebateaccounthead extends Controller {
             }
             Rows rebatecategorys = dbConnect.runSqlQuery("select * from sa_rebatecategory where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
             Rows rebateunproducts = dbConnect.runSqlQuery("select * from sa_rebateunproducts where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
+            Rows rebateunjoinproducts = dbConnect.runSqlQuery("select * from sa_rebateunjoinproducts where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
             Rows agentdecorationtrebates = dbConnect.runSqlQuery("select * from sa_agentdecorationtrebate where siteid='" + siteid + "'");
             Rows agentrebatecategorys = dbConnect.runSqlQuery("select * from sa_agentrebatecategory where siteid='" + siteid + "'");
             RowsMap agentdecorationtrebatesRowsMap = agentdecorationtrebates.toRowsMap("sys_enterpriseid");
             RowsMap agentrebatecategorysRowsMap = agentrebatecategorys.toRowsMap("sys_enterpriseid");
             String itemids = rebateunproducts.toJsonArray("itemid").toString();
+            String joinitemids = rebateunjoinproducts.toJsonArray("itemid").toString();
             itemids = itemids.replace("[", "(").replace("]", ")");
+            joinitemids = joinitemids.replace("[", "(").replace("]", ")");
 
             ArrayList<Long> itemclsids = rebatecategorys.toArrayList("itemclassid", new ArrayList<Long>());
 
-            RowsMap amountRowsMap = CalculateAmount(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids);
-            RowsMap ordersRowsMap = QuerySaorderNum(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids);
-            RowsMap orderDetailIdRowsMap = QuerySaorderDetailId(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids);
+            RowsMap amountRowsMap = CalculateAmount(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids,joinitemids);
+            RowsMap ordersRowsMap = QuerySaorderNum(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids,joinitemids);
+            RowsMap orderDetailIdRowsMap = QuerySaorderDetailId(itemclsids, rebateaccounts.toArrayList("sys_enterpriseid", new ArrayList<Long>()), itemids,joinitemids);
 
             for (Row row : rebateaccounts) {
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -573,19 +575,23 @@ public class rebateaccounthead extends Controller {
 
 
     public RowsMap CalculateAmount(ArrayList<Long> itemclsids, ArrayList<Long> sys_enterpriseids,
-                                   String itemids) throws YosException {
+                                   String itemids,String joinitemids) throws YosException {
         Rows rows = null;
         itemclsids.addAll(ItemClass.getSubItemClassIds(this, itemclsids));
         itemclsids.add(0l);
+        String where =" and 1=1 ";
+        if(!joinitemids.equals("()")){
+            where=where+" and t1.itemid in" + joinitemids + " ";
+        }
         if (itemids.equals("()")) {
             rows = dbConnect.runSqlQuery("select t2.closedate,t2.sys_enterpriseid,sum(if(t1.isclose,t1.amount,t1.price*(t1.qty-t1.undeliqty))) amount from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " ) and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭')  "+where+" and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " ) and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate");
 
         } else {
             rows = dbConnect.runSqlQuery("select  t2.closedate,t2.sys_enterpriseid,sum(if(t1.isclose,t1.amount,t1.price*(t1.qty-t1.undeliqty))) amount from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )   and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') "+where+" and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )   and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate");
 
         }
         return rows.toRowsMap("sys_enterpriseid");
@@ -594,19 +600,23 @@ public class rebateaccounthead extends Controller {
     }
 
     public RowsMap QuerySaorderNum(ArrayList<Long> itemclsids, ArrayList<Long> sys_enterpriseids,
-                                   String itemids) throws YosException {
+                                   String itemids,String joinitemids) throws YosException {
         Rows rows = null;
         itemclsids.addAll(ItemClass.getSubItemClassIds(this, itemclsids));
         itemclsids.add(0l);
+        String where =" and 1=1 ";
+        if(!joinitemids.equals("()")){
+            where=where+" and t1.itemid in" + joinitemids + " ";
+        }
         if (itemids.equals("()")) {
             rows = dbConnect.runSqlQuery("select t2.closedate,t2.sys_enterpriseid,t2.sa_orderid,SUM(if(t1.isclose,t1.amount,t1.price*(t1.qty-t1.undeliqty))) amount from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sa_orderid,t2.sys_enterpriseid,t2.closedate");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') "+where+" and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sa_orderid,t2.sys_enterpriseid,t2.closedate");
 
         } else {
             rows = dbConnect.runSqlQuery("select t2.closedate,t2.sys_enterpriseid,t2.sa_orderid,SUM(if(t1.isclose,t1.amount,t1.price*(t1.qty-t1.undeliqty))) amount from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sa_orderid,t2.sys_enterpriseid,t2.closedate");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') "+where+" and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sa_orderid,t2.sys_enterpriseid,t2.closedate");
 
 
         }
@@ -615,19 +625,23 @@ public class rebateaccounthead extends Controller {
     }
 
     public RowsMap QuerySaorderDetailId(ArrayList<Long> itemclsids, ArrayList<Long> sys_enterpriseids,
-                                        String itemids) throws YosException {
+                                        String itemids,String joinitemids) throws YosException {
         Rows rows = null;
         itemclsids.addAll(ItemClass.getSubItemClassIds(this, itemclsids));
         itemclsids.add(0l);
+        String where =" and 1=1 ";
+        if(!joinitemids.equals("()")){
+            where=where+" and t1.itemid in" + joinitemids + " ";
+        }
         if (itemids.equals("()")) {
             rows = dbConnect.runSqlQuery("select t2.closedate,t2.sys_enterpriseid,t1.sa_orderitemsid  from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate,t1.sa_orderitemsid");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') "+where+" and t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " )  and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate,t1.sa_orderitemsid");
 
         } else {
             rows = dbConnect.runSqlQuery("select t2.closedate,t2.sys_enterpriseid,t1.sa_orderitemsid from sa_orderitems t1 \n" +
                     "inner join sa_order t2 on  t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid\n" +
-                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " ) and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate,t1.sa_orderitemsid");
+                    "inner join plm_item t3 on  t1.itemid=t3.itemid and t1.siteid=t3.siteid where t2.type !='促销订单' and ifnull( t2.closedate,'')!='' and t2.sa_accountclassid!=0 and t2.sys_enterpriseid in" + sys_enterpriseids.toString().replace("[", "(").replace("]", ")") + "  and t2.status in('关闭') "+where+" and t1.itemid not in" + itemids + " and  t1.itemid in(select itemid from sa_itemsaleclass where itemclassid in" + itemclsids.toString().replace("[", "(").replace("]", ")") + " ) and t1.DECORATIONREBATEFLAG=0 and t1.siteid='" + siteid + "' group by t2.sys_enterpriseid,t2.closedate,t1.sa_orderitemsid");
 
 
         }

+ 4 - 4
src/custom/restcontroller/webmanage/sale/rebatescheme/ExportExcel.java

@@ -156,14 +156,14 @@ public class ExportExcel {
         row = sheet.createRow(0);
         cell = row.createCell(0);// ID
         cell.setCellStyle(cellStyle4);
-        cell.setCellValue("不返利商品导入");
+        cell.setCellValue("商品导入");
         /*第二行*/
         //sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 0));
         /*第二行塞值*/
         row = sheet.createRow(1);
         cell = row.createCell(0);// ID
         cell.setCellStyle(cellStyle1);
-        cell.setCellValue("注意:①请按照以下示例填写商品;②调价商品最多不超过5000行;③导入前,请记得删除示例行!");
+        cell.setCellValue("注意:①请按照以下示例填写商品;②商品最多不超过5000行;③导入前,请记得删除示例行!");
         /*第三行塞值*/
         row = sheet.createRow(2);
 
@@ -215,14 +215,14 @@ public class ExportExcel {
         row = sheet.createRow(0);
         cell = row.createCell(0);// ID
         cell.setCellStyle(cellStyle3);
-        cell.setCellValue("不返利商品导入");
+        cell.setCellValue("商品导入");
         /*第二行*/
         sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1));
         /*第二行塞值*/
         row = sheet.createRow(1);
         cell = row.createCell(0);// ID
         cell.setCellStyle(cellStyle1);
-        cell.setCellValue("注意:①请按照以下示例填写商品;②调价商品最多不超过5000行;③调价单导入前,请记得删除示例行!");
+        cell.setCellValue("注意:①请按照以下示例填写商品;②商品最多不超过5000行;③调价单导入前,请记得删除示例行!");
         /*第三行塞值*/
         row = sheet.createRow(2);
 

+ 47 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/SQL/参与返利商品查询.sql

@@ -0,0 +1,47 @@
+SELECT t1.itemid,
+       t1.itemno,
+       t1.itemname,
+       t1.model,
+       t1.spec,
+       t2.unitname,
+       t1.unitid,
+       t1.createdate,
+       t1.isonsale,
+       t1.status,
+       t1.orderaddqty,
+       t1.orderminqty,
+       t1.remarks,
+       t1.barcode,
+       t1.skucontrol,
+       t1.batchcontrol,
+       t1.standards,
+       t1.grossweight,
+       t1.weight,
+       t1.height,
+       t1.width,
+       t1.length,
+       t1.delivery,
+       t1.istool,
+       t1.marketprice,
+       t6.auxunitid,
+       t6.unitgroupname,
+       t7.unitname axunitname,
+       t8.caliber,
+       t8.pressure,
+       t8.material,
+       t8.device,
+       t8.prodline, 
+       t8.erpitemname,
+       t8.erpitemno,
+       t8.specalnote
+FROM plm_item t1
+         LEFT JOIN plm_unit t2 ON t2.unitid = t1.unitid AND t2.siteid = t1.siteid
+         LEFT JOIN plm_unitgroup t6 ON t6.unitgroupid = t1.unitgroupid
+         LEFT JOIN plm_unit t7 ON t7.unitid = t6.unitid AND t7.siteid = t6.siteid
+         LEFT JOIN plm_itemextend t8 ON t8.itemid = t1.itemid AND t8.siteid = t1.siteid
+WHERE
+  t1.`status` = '审核'
+  and t1.isonsale=1
+  and $where$
+  and t1.siteid = $siteid$
+  and t1.itemid not in(select itemid from sa_rebateunjoinproducts where sa_rebateschemeid=$sa_rebateschemeid$)

+ 7 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/SQL/装修返利方案参与返利商品列表查询.sql

@@ -0,0 +1,7 @@
+SELECT
+    t1.*,
+    t2.itemno,
+    t2.itemname
+FROM  sa_rebateunjoinproducts t1
+    left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid
+where $where$ and t1.siteid=$siteid$ and t1.sa_rebateschemeid=$sa_rebateschemeid$

+ 2 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/SQL/装修返利方案参与返利商品新增.sql

@@ -0,0 +1,2 @@
+insert into sa_rebateunjoinproducts (siteid, sa_rebateunjoinproductsid,sa_rebateschemeid,itemid)
+values ($siteid$, $sa_rebateunjoinproductsid$,$sa_rebateschemeid$,$itemid$);

+ 4 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/SQL/装修返利方案参与返利商品更新.sql

@@ -0,0 +1,4 @@
+UPDATE sa_rebateunjoinproducts
+SET
+    itemid=$itemid$
+WHERE sa_rebateunjoinproductsid = $sa_rebateunjoinproductsid$

+ 309 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/rebateunjoinproducts.java

@@ -0,0 +1,309 @@
+package restcontroller.webmanage.sale.rebatescheme;
+
+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 org.apache.commons.lang.StringUtils;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.xssf.usermodel.*;
+import restcontroller.R;
+import restcontroller.system.attachment.Attachment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class rebateunjoinproducts extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public rebateunjoinproducts(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "装修返利方案参与返利商品查询", apiversion = R.ID20240722145303.v1.class)
+    @CACHEING
+    public String queryItemList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        Long sa_rebateschemeid = content.getLong("sa_rebateschemeid");
+        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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "参与返利商品查询", pageSize, pageNumber, pageSorting);
+
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
+    @API(title = "装修返利方案参与返利商品新增更新", apiversion = R.ID20240722145403.v1.class)
+    @CACHEING_CLEAN(apiClass = {rebateunjoinproducts.class})
+    public String insertormodify_rebateunproducts() throws YosException {
+        Long sa_rebateschemeid = content.getLong("sa_rebateschemeid");
+        JSONArray iteminfos = content.getJSONArray("iteminfos");
+        ArrayList<String> sqlList = new ArrayList<>();
+        int i = 0;
+        long[] rebateunjoinproductsid = createTableID("sa_rebateunjoinproducts", iteminfos.size());
+        for (Object obj : iteminfos) {
+            JSONObject iteminfo = (JSONObject) obj;
+
+            if (iteminfo.getLong("sa_rebateunjoinproductsid") <= 0 || dbConnect
+                    .runSqlQuery("select sa_rebateunjoinproductsid from sa_rebateunjoinproducts where sa_rebateunjoinproductsid="
+                            + iteminfo.getLong("sa_rebateunjoinproductsid"))
+                    .isEmpty()) {
+                SQLFactory saleFactory = new SQLFactory(this, "装修返利方案参与返利商品新增");
+                saleFactory.addParameter("siteid", siteid);
+                saleFactory.addParameter("sa_rebateunjoinproductsid", rebateunjoinproductsid[i]);
+                saleFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
+                saleFactory.addParameter("itemid", iteminfo.getLong("itemid"));
+                sqlList.add(saleFactory.getSQL());
+                sqlList.add("delete from  sa_rebateunproducts where sa_rebateschemeid="+sa_rebateschemeid+" and itemid="+ iteminfo.getLong("itemid")+" and siteid='"+siteid+"'");
+                i++;
+            } else {
+                SQLFactory saleFactory = new SQLFactory(this, "装修返利方案参与返利商品更新");
+                saleFactory.addParameter("siteid", siteid);
+                saleFactory.addParameter("sa_rebateunjoinproductsid", iteminfo.getLong("sa_rebateunjoinproductsid"));
+                saleFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
+                saleFactory.addParameter("itemid", iteminfo.getLong("itemid"));
+                sqlList.add(saleFactory.getSQL());
+                sqlList.add("delete from sa_rebateunproducts where sa_rebateschemeid="+sa_rebateschemeid+" and itemid="+ iteminfo.getLong("itemid")+" and siteid='"+siteid+"'");
+            }
+
+        }
+        dbConnect.runSqlUpdate(sqlList);
+
+        return queryrebateunproductsList();
+    }
+
+
+    @API(title = "查询装修返利方案参与返利商品列表", apiversion = R.ID20240722145503.v1.class)
+    @CACHEING
+    public String queryrebateunproductsList() throws YosException {
+
+        Long sa_rebateschemeid = content.getLong("sa_rebateschemeid");
+
+        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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "装修返利方案参与返利商品列表查询", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
+        sqlFactory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除", apiversion = R.ID20240722145603.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20230627111003.v1.class},apiClass = {rebateunjoinproducts.class})
+    public String delete() throws YosException {
+
+        JSONArray sa_rebateunjoinproductsids = content.getJSONArray("sa_rebateunjoinproductsids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_rebateunjoinproductsids.size());
+        for (Object o : sa_rebateunjoinproductsids) {
+            long sa_rebateunjoinproductsid = Long.parseLong(o.toString());
+            dbConnect.runSqlUpdate("delete from sa_rebateunjoinproducts where siteid='" + siteid + "' and sa_rebateunjoinproductsid="
+                    + sa_rebateunjoinproductsid);
+        }
+        return batchDeleteErr.getReturnObject().toString();
+
+    }
+
+    @API(title = "导入参与返利商品", apiversion = R.ID20240722145703.v1.class)
+    @CACHEING_CLEAN(apiClass = {rebateunjoinproducts.class})
+    public String importItem() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        JSONArray jsonArray = new JSONArray();
+        jsonArray.add(content.getLong("attachmentid"));
+
+        content.put("ownertable", "sa_rebatescheme");
+        content.put("ownerid", content.getLongValue("sa_rebateschemeid"));
+        content.put("usetype", "default");
+        content.put("attachmentids", jsonArray);
+        Attachment attachment = new Attachment(content);
+        attachment.createFileLink();
+
+        ExcelFactory e;
+        try {
+
+            // 华为云
+            e = getPostExcelFactory(content.getLong("attachmentid"));
+            // 本地
+            //e = getPostExcelFactory();
+
+            ArrayList<String> keys = new ArrayList<>();
+            ArrayList<String> sqllist = new ArrayList<>();
+            keys.add("itemno");
+            HashMap<String, CellType> cellMap = new HashMap<>();
+            cellMap.put("itemno", CellType.STRING);
+            Rows rows = e.getSheetRows(0, keys, cellMap, 3);
+
+            ArrayList<String> itemnoList = rows.toArrayList("itemno",false);
+            itemnoList.add("-1");
+
+            boolean iserr = false;
+            Rows rowserr = new Rows();
+            Rows rowssuc = new Rows();
+            QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item", "itemid", "itemno", "marketprice");
+            querySQL.setSiteid(siteid);
+            querySQL.setWhere("itemno", itemnoList);
+            RowsMap itemnoRowsMap = querySQL.query().toRowsMap("itemno");
+            for (Row row : rows) {
+                if (StringUtils.isEmpty(row.getString("itemno"))) {
+                    iserr = true;
+                    row.put("msg", "错误信息:商品编号不能为空");
+                    rowserr.add(row);
+                    continue;
+                } else {
+                    String itemno = row.getString("itemno");
+                    System.out.println(itemno);
+                    System.out.println(itemnoList.indexOf(itemno));
+                    System.out.println( itemnoList.lastIndexOf(itemno));
+
+                    if (itemnoList.indexOf(itemno) != itemnoList.lastIndexOf(itemno)) {
+                        iserr = true;
+                        row.put("msg", "错误信息:导入文件存在相同编码的商品");
+                        rowserr.add(row);
+                        continue;
+                    }
+                    if (itemnoRowsMap.containsKey(itemno)) {
+                        row.put("itemid", itemnoRowsMap.get(itemno).get(0).getLong("itemid"));
+                    } else {
+                        iserr = true;
+                        row.put("msg", "错误信息:不存在商品编号为" + itemno + "的商品");
+                        rowserr.add(row);
+                        continue;
+                    }
+
+                }
+                rowssuc.add(row);
+
+            }
+
+            if (!rowssuc.isEmpty()) {
+                for (Row row : rowssuc) {
+                    Long sa_rebateunjoinproductsid = createTableID("sa_rebateunjoinproducts");
+                    SQLFactory sqlFactoryupload = new SQLFactory(this, "装修返利方案参与返利商品新增");
+                    sqlFactoryupload.addParameter("sa_rebateunjoinproductsid", sa_rebateunjoinproductsid);
+                    sqlFactoryupload.addParameter("sa_rebateschemeid", content.getLongValue("sa_rebateschemeid"));
+                    sqlFactoryupload.addParameter("siteid", siteid);
+                    sqlFactoryupload.addParameter("itemid", row.getString("itemid"));
+                    sqllist.add(sqlFactoryupload.getSQL());
+                    sqlList.add("delete from sa_rebateunproducts where sa_rebateschemeid="+content.getLongValue("sa_rebateschemeid")+" and itemid="+ row.getString("itemid")+" and siteid='"+siteid+"'");
+                }
+            }
+            if (!sqllist.isEmpty()) {
+                String sql = DataContrlLog.createLog(this, "sa_rebatescheme",  content.getLongValue("sa_rebateschemeid"), "新增", "装修返利方案参与返利商品导入:" + content.getLongValue("sa_rebateschemeid")).getSQL();
+                sqlList.add(sql);
+                dbConnect.runSqlUpdate(sqllist);
+            } else {
+                dbConnect.runSqlUpdate("delete from sa_rebateunjoinproducts where sa_rebateschemeid=" + content.getLongValue("sa_rebateschemeid"));
+            }
+
+            if (iserr) {
+                ExcelFactory excelFactory = new ExcelFactory("参与返利商品导入错误信息");
+                HashMap<String, String> map = new HashMap<String, String>();
+                map.put("itemno", "商品编号");
+                map.put("msg", "错误信息");
+                ArrayList<String> colNameList = new ArrayList<String>();
+                HashMap<String, Class> keytypemap = new HashMap<String, Class>();
+                colNameList.add("itemno");
+                colNameList.add("msg");
+                keytypemap.put("itemno", String.class);
+                keytypemap.put("msg", String.class);
+                rowserr.setFieldList(colNameList);
+                rowserr.setFieldTypeMap(keytypemap);
+                addSheet(excelFactory, "Sheet1", rowserr, map);
+
+                Rows aa = uploadExcelToObs(excelFactory);
+                String url = "";
+                if (!aa.isEmpty()) {
+                    url = aa.get(0).getString("url");
+                }
+                return getErrReturnObject().setErrMsg(url).toString();
+            }
+        } catch (Exception e1) {
+            dbConnect.runSqlUpdate("delete from sa_rebateunjoinproducts where sa_rebateschemeid=" + content.getLongValue("sa_rebateschemeid"));
+            e1.printStackTrace();
+            return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
+        }
+        return getSucReturnObject().toString();
+    }
+
+    public XSSFSheet addSheet(ExcelFactory excelFactory, String sheetname, Rows datarows,
+                              HashMap<String, String> titlemap) {
+        ArrayList<String> keylist = datarows.getFieldList();
+        XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
+        XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
+
+        XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
+        XSSFFont font = xssfFWorkbook.createFont();
+
+        font.setColor((short) 0xa);
+        font.setFontHeightInPoints((short) 12);
+        font.setBold(true);
+        xssfCellStyle1.setFont(font);
+
+        ExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
+        XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle3 = ExportExcel.createTitleCellStyle3(xssfFWorkbook);
+        ExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
+
+        for (int n = 0; n < datarows.size(); n++) {
+            Row row = datarows.get(n);
+            XSSFRow datarow = sheet.createRow(n + 3);
+            for (int i1 = 0; i1 < keylist.size(); i1++) {
+                Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
+                if (fieldclazztype == Integer.class) {
+                    datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)).intValue());
+                } else if (fieldclazztype == Long.class) {
+                    datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
+                } else if (fieldclazztype == Float.class) {
+                    datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
+                } else if (fieldclazztype == Double.class) {
+                    datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
+                } else {
+                    datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
+                }
+                if (i1 == 1) {
+                    datarow.getCell(i1).setCellStyle(xssfCellStyle1);
+                }
+            }
+        }
+        return sheet;
+    }
+
+
+}

+ 3 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/rebateunproducts.java

@@ -80,6 +80,7 @@ public class rebateunproducts extends Controller {
                 saleFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
                 saleFactory.addParameter("itemid", iteminfo.getLong("itemid"));
                 sqlList.add(saleFactory.getSQL());
+                sqlList.add("delete from sa_rebateunjoinproducts where sa_rebateschemeid="+sa_rebateschemeid+" and itemid="+ iteminfo.getLong("itemid")+" and siteid='"+siteid+"'");
                 i++;
             } else {
                 SQLFactory saleFactory = new SQLFactory(this, "装修返利方案不参与返利商品更新");
@@ -88,6 +89,7 @@ public class rebateunproducts extends Controller {
                 saleFactory.addParameter("sa_rebateschemeid", sa_rebateschemeid);
                 saleFactory.addParameter("itemid", iteminfo.getLong("itemid"));
                 sqlList.add(saleFactory.getSQL());
+                sqlList.add("delete from sa_rebateunjoinproducts where sa_rebateschemeid="+sa_rebateschemeid+" and itemid="+ iteminfo.getLong("itemid")+" and siteid='"+siteid+"'");
             }
 
         }
@@ -219,6 +221,7 @@ public class rebateunproducts extends Controller {
                     sqlFactoryupload.addParameter("siteid", siteid);
                     sqlFactoryupload.addParameter("itemid", row.getString("itemid"));
                     sqllist.add(sqlFactoryupload.getSQL());
+                    sqlList.add("delete from  sa_rebateunjoinproducts where sa_rebateschemeid="+ content.getLongValue("sa_rebateschemeid")+" and itemid="+row.getString("itemid")+" and siteid='"+siteid+"'");
                 }
             }
             if (!sqllist.isEmpty()) {

+ 7 - 0
src/custom/service/DispatchAutoCloseService.java

@@ -320,6 +320,7 @@ public class DispatchAutoCloseService extends ServiceController {
 
         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);
+        Rows rebateunjoinproducts = dbConnect.runSqlQuery("select itemid from sa_rebateunjoinproducts where siteid='" + siteid + "' and sa_rebateschemeid=" + sa_rebateschemeid);
 
         ArrayList<Long> itemclsids = rebatecategorys.toArrayList("itemclassid", new ArrayList<Long>());
 
@@ -327,6 +328,11 @@ public class DispatchAutoCloseService extends ServiceController {
         itemclsids.add(0l);
         ArrayList<Long> itemids = rebateunproducts.toArrayList("itemid", new ArrayList<Long>());
         itemids.add(0l);
+        ArrayList<Long> joinitemids = rebateunjoinproducts.toArrayList("itemid", new ArrayList<Long>());
+        String where =" 1=1 ";
+        if(!joinitemids.isEmpty()){
+            where=where+" and t1.itemid in"+joinitemids;
+        }
 
         SQLFactory sqlFactory = new SQLFactory(new DispatchAutoCloseService(), "查询返利数据");
         sqlFactory.addParameter("sa_orderid", sa_orderid);
@@ -334,6 +340,7 @@ public class DispatchAutoCloseService extends ServiceController {
         sqlFactory.addParameter("siteid", siteid);
         sqlFactory.addParameter_in("itemclassid", itemclsids);
         sqlFactory.addParameter_in("itemid", itemids);
+        sqlFactory.addParameter_SQL("where", where);
 
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
         BigDecimal saorderamount = BigDecimal.ZERO;

+ 2 - 1
src/custom/service/SQL/查询返利数据.sql

@@ -9,4 +9,5 @@ WHERE t2.sa_orderid = $sa_orderid$
   and t1.outwarehouseqty > 0
   and (t3.decorationrebateflag = 0 or t3.decorationrebateflag is null)
   and t1.itemid in (select itemid from sa_itemsaleclass where itemclassid in $itemclassid$)
-  and t1.itemid not in $itemid$
+  and t1.itemid not in $itemid$
+  and $where$