|
|
@@ -1,10 +1,12 @@
|
|
|
package restcontroller.webmanage.sale.enterprisesaleclass;
|
|
|
|
|
|
+import beans.itemclass.ItemClass;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
import common.YosException;
|
|
|
import common.annotation.API;
|
|
|
+import common.data.Row;
|
|
|
import common.data.Rows;
|
|
|
import common.data.SQLFactory;
|
|
|
import restcontroller.R;
|
|
|
@@ -56,10 +58,30 @@ public class EnterpriseSaleClass extends Controller {
|
|
|
public String delete() throws YosException {
|
|
|
JSONArray jsonArray = content.getJSONArray("sys_enterprise_saleclassids");
|
|
|
|
|
|
+ SQLFactory sqlFactoryquery = new SQLFactory(this, "合作企业营销类别查询");
|
|
|
+ sqlFactoryquery.addParameter_in("sys_enterprise_saleclassid", jsonArray.toArray());
|
|
|
+ sqlFactoryquery.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactoryquery);
|
|
|
+
|
|
|
+ ArrayList<Long> itemclassids = rows.toArrayList("itemclassid", new ArrayList<>());
|
|
|
+ ArrayList<Long> needitemclassids= ItemClass.getSubItemClassIds(this, itemclassids);
|
|
|
+ needitemclassids.addAll(itemclassids);
|
|
|
+ long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "合作企业营销类别删除");
|
|
|
- sqlFactory.addParameter_in("sys_enterprise_saleclassid", jsonArray.toArray());
|
|
|
+ sqlFactory.addParameter_in("itemclassid", needitemclassids);
|
|
|
+ sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseid);
|
|
|
sqlFactory.addParameter("siteid", siteid);
|
|
|
dbConnect.runSqlUpdate(sqlFactory);
|
|
|
+
|
|
|
+
|
|
|
+ String sql = " SELECT ifnull(t1.parentid ,0) parentid from plm_itemclass t1 WHERE t1.itemclassid in " + itemclassids + " and t1.siteid ='"
|
|
|
+ + siteid + "'";
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ Rows rows1 = dbConnect.runSqlQuery(sql);
|
|
|
+ for (Row row:rows1) {
|
|
|
+ DeleteItemclass(row.getLong("parentid"),sys_enterpriseid);
|
|
|
+ }
|
|
|
+
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
@@ -76,4 +98,24 @@ public class EnterpriseSaleClass extends Controller {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private void DeleteItemclass( long parentid,long sys_enterpriseid)
|
|
|
+ throws YosException {
|
|
|
+ if (parentid > 0) {
|
|
|
+ Rows rows = dbConnect.runSqlQuery(
|
|
|
+ "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='"+sys_enterpriseid+"' and t1.siteid='"+siteid+"' and t1.itemclassid= '"
|
|
|
+ + parentid + "'");
|
|
|
+ if (!rows.isEmpty()) {
|
|
|
+ if(dbConnect.runSqlQuery(
|
|
|
+ "select t1.itemclassid,ifnull(t2.parentid,0) as parentid from sys_enterprise_saleclass t1 inner join plm_itemclass t2 on t1.itemclassid=t2.itemclassid and t1.siteid=t2.siteid where t1.sys_enterpriseid='"+sys_enterpriseid+"' and t1.siteid='"+siteid+"' and t2.parentid= '"
|
|
|
+ + rows.get(0).getLong("itemclassid") + "'").isEmpty()){
|
|
|
+ dbConnect.runSqlUpdate("delete from sys_enterprise_saleclass where itemclassid= '" + rows.get(0).getLong("itemclassid") + "' and sys_enterpriseid='"+sys_enterpriseid+"' and siteid='"+siteid+"'");
|
|
|
+ DeleteItemclass( rows.get(0).getLong("parentid"),sys_enterpriseid);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|