|
|
@@ -1,502 +0,0 @@
|
|
|
-package service;
|
|
|
-
|
|
|
-import beans.accountbalance.Accountbalance;
|
|
|
-import beans.accountbalance.CashbillEntity;
|
|
|
-import beans.datacontrllog.DataContrlLog;
|
|
|
-import beans.itemclass.ItemClass;
|
|
|
-import beans.order.Order;
|
|
|
-import beans.parameter.Parameter;
|
|
|
-import beans.remind.Remind;
|
|
|
-import beans.uploaderpdata.UploadDataToERP_HY;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import common.Controller;
|
|
|
-import common.ServiceController;
|
|
|
-import common.YosException;
|
|
|
-import common.data.*;
|
|
|
-import common.parameter.properties;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.log4j.Logger;
|
|
|
-import restcontroller.webmanage.executorService.Executor;
|
|
|
-import restcontroller.webmanage.sale.order.OrderItemsHelper;
|
|
|
-import utility.ERPDocking;
|
|
|
-import utility.tools.WebRequest;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Properties;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * 发货单自动关闭任务
|
|
|
- */
|
|
|
-public class DispatchAutoCloseService extends ServiceController {
|
|
|
-
|
|
|
- private static Logger logger = Logger.getLogger(DispatchAutoCloseService.class);
|
|
|
- String[] siteids = {"CCYOSG", "DLB"};
|
|
|
-
|
|
|
- @Override
|
|
|
-
|
|
|
- public void serviceRun() throws YosException {
|
|
|
- for (String siteid : siteids) {
|
|
|
- if (dbConnect.runSqlQuery("SELECT 1 from sys_site WHERE siteid='" + siteid + "'").isEmpty()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
-// Properties yosProperties = properties.getYosProperties();
|
|
|
-// if (yosProperties.getProperty("system.runmode.debug").equalsIgnoreCase("false")) {
|
|
|
- if(false){
|
|
|
- Rows rows = dbConnect.runSqlQuery("select * from sa_dispatch where status='复核' and siteid='" + siteid + "'");
|
|
|
- Rows rowsdetail = dbConnect.runSqlQuery("select t1.* 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='复核' and t1.siteid='" + siteid + "'");
|
|
|
- RowsMap rowsMap = rowsdetail.toRowsMap("sa_dispatchid");
|
|
|
- RowsMap rowsMap1 = rowsdetail.toRowsMap("billno");
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- ERPDocking erpDocking = new ERPDocking(siteid);
|
|
|
- JSONArray ErpSainvoices = erpDocking.queryErpSainvoices(10000, 1, new JSONArray(), "", "", "", false, false, true);
|
|
|
- JSONArray dispatchids = new JSONArray();
|
|
|
- JSONArray unclosedispatchids = new JSONArray();
|
|
|
- if (!ErpSainvoices.isEmpty()) {
|
|
|
- for (Object ErpSainvoice : ErpSainvoices) {
|
|
|
- JSONObject erpSainvoice = (JSONObject) ErpSainvoice;
|
|
|
- String billno = erpSainvoice.getString("finvonum");
|
|
|
- long sa_dispatchid = 0;
|
|
|
- if (rowsMap1.containsKey(billno)) {
|
|
|
- if (rowsMap1.get(billno).isNotEmpty()) {
|
|
|
- sa_dispatchid = rowsMap1.get(billno).get(0).getLong("sa_dispatchid");
|
|
|
- dispatchids.add(sa_dispatchid);
|
|
|
- } else {
|
|
|
- logger.info("发货单【" + billno + "】不存在:");
|
|
|
- continue;
|
|
|
- }
|
|
|
- } else {
|
|
|
- logger.info("发货单【" + billno + "】不存在:");
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONArray jsonArray = erpDocking.queryErpSainvoice(billno);
|
|
|
-
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- JSONObject objectdetail = new JSONObject();
|
|
|
- object.put("access_token", "basicDrp");
|
|
|
- object.put("classname", "Sainvoice");
|
|
|
- object.put("method", "closeSainvoice");
|
|
|
- objectdetail.put("finvonum", billno);
|
|
|
- objectdetail.put("isManual", false);
|
|
|
- object.put("content", objectdetail);
|
|
|
-
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("content-Type", "application/json");
|
|
|
- String result = new WebRequest().doPost(object.toString(), erpDocking.getUrl(), map);
|
|
|
- JSONObject resultobject = JSONObject.parseObject(result);
|
|
|
-
|
|
|
- try {
|
|
|
- Rows erpupdatelogRows = dbConnect.runSqlQuery(
|
|
|
- "select * from sys_erpupdatelog where ownertable='sa_dispatch' and type='关闭发货单' and ownerid=" + sa_dispatchid);
|
|
|
- SQLFactory sqlFactory;
|
|
|
- if (!erpupdatelogRows.isEmpty()) {
|
|
|
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
|
|
|
- sqlFactory.addParameter("sys_erpupdatelogid", erpupdatelogRows.get(0).getLong("sys_erpupdatelogid"));
|
|
|
- } else {
|
|
|
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
|
|
|
- sqlFactory.addParameter("sys_erpupdatelogid", createTableID("sys_erpupdatelog"));
|
|
|
- }
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlFactory.addParameter("userid", 1);
|
|
|
- sqlFactory.addParameter("username", "admin");
|
|
|
- sqlFactory.addParameter("ownerid", sa_dispatchid);
|
|
|
- sqlFactory.addParameter("ownertable", "sa_dispatch");
|
|
|
- sqlFactory.addParameter("type", "关闭发货单");
|
|
|
- sqlFactory.addParameter("request", object.toString());
|
|
|
- sqlFactory.addParameter("response", resultobject.toJSONString());
|
|
|
-
|
|
|
- if ("0".equals(resultobject.getString("errcode"))) {
|
|
|
- sqlFactory.addParameter("erpbillno", billno);
|
|
|
- sqlFactory.addParameter("errmsg", "");
|
|
|
- } else {
|
|
|
- sqlFactory.addParameter("erpbillno", "");
|
|
|
- sqlFactory.addParameter("errmsg", resultobject.getString("errmsg"));
|
|
|
- }
|
|
|
- sqlFactory.addParameter("status", resultobject.getString("errcode"));
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- if (resultobject.getString("errcode").equals("0")) {
|
|
|
- sqlList.add("update sa_dispatch set status='关闭',closedate=current_time,closeby='admin' where sa_dispatchid='" + sa_dispatchid + "' and siteid='" + siteid + "'");
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "数据操作日志新增");
|
|
|
- sqlFactory.addParameter("sys_contrllogid", createTableID("sys_contrllog"));
|
|
|
- sqlFactory.addParameter("ownertable", "sa_dispatch");
|
|
|
- sqlFactory.addParameter("ownerid", sa_dispatchid);
|
|
|
- sqlFactory.addParameter("action", "自动关闭");
|
|
|
- sqlFactory.addParameter("remarks", "发货单自动关闭成功");
|
|
|
- sqlFactory.addParameter("actionuserid", "1");
|
|
|
- sqlFactory.addParameter("actionby", "admin");
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
- } else {
|
|
|
- unclosedispatchids.add(sa_dispatchid);
|
|
|
- logger.info("发货单自动关闭错误:" + resultobject.getString("errmsg") + "发货单id:" + sa_dispatchid);
|
|
|
- }
|
|
|
- if (!jsonArray.isEmpty()) {
|
|
|
- for (Object object1 : jsonArray) {
|
|
|
- JSONObject jsonObject = (JSONObject) object1;
|
|
|
- sqlList.add("update sa_dispatch_items set outwarehousedate=current_time,outwarehouseqty=" + jsonObject.getBigDecimal("fqty1") + " where rowno =" + jsonObject.getIntValue("frownum") + " and sa_dispatchid='" + sa_dispatchid + "' and siteid='" + siteid + "'");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- dbConnect.runSqlUpdate(sqlList);
|
|
|
-
|
|
|
-
|
|
|
- //判断当前单据是否已实际发完货,如果发完,则生把订单变为关闭状态
|
|
|
- Rows orderRows = new Rows();
|
|
|
- if (dispatchids.size() > 0) {
|
|
|
- String sql = "select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='" + siteid + "' and t2.sa_dispatchid in" + dispatchids.toJSONString();
|
|
|
- sql = sql.replace("[", "(").replace("]", ")");
|
|
|
- logger.info("sql:" + sql);
|
|
|
- orderRows = dbConnect.runSqlQuery(sql);
|
|
|
- }
|
|
|
- //总数量
|
|
|
- Rows totalRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems where siteid='" + siteid + "' group by sa_orderid");
|
|
|
- RowsMap totalRowsMap = totalRows.toRowsMap("sa_orderid");
|
|
|
- //已发完数量
|
|
|
- Rows deliRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems t1 inner join (SELECT t1.sa_orderitemsid,t1.siteid,SUM(ifnull(t1.outwarehouseqty,0)) outwarehouseqty FROM sa_dispatch_items t1 WHERE t1.siteid='" + siteid + "' group by t1.sa_orderitemsid,t1.siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.qty=t2.outwarehouseqty and t1.siteid='" + siteid + "' group by sa_orderid");
|
|
|
- RowsMap deliRowsMap = deliRows.toRowsMap("sa_orderid");
|
|
|
- if (orderRows.size() > 0) {
|
|
|
- for (Row row : orderRows) {
|
|
|
- logger.info("订单id:" + row.getString("sa_orderid"));
|
|
|
- if (totalRowsMap.containsKey(row.getString("sa_orderid")) && deliRowsMap.containsKey(row.getString("sa_orderid"))) {
|
|
|
- if (totalRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count") == deliRowsMap.get(row.getString("sa_orderid")).get(0).getLong("count")) {
|
|
|
- logger.info("订单关闭:update sa_order set status='关闭',closedate=current_time,closeby='admin' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='" + siteid + "'");
|
|
|
- dbConnect.runSqlUpdate("update sa_order set status='关闭',closedate=current_time,closeby='admin' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='" + siteid + "'");
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "数据操作日志新增");
|
|
|
- sqlFactory.addParameter("sys_contrllogid", createTableID("sys_contrllog"));
|
|
|
- sqlFactory.addParameter("ownertable", "sa_order");
|
|
|
- sqlFactory.addParameter("ownerid", row.getLong("sa_orderid"));
|
|
|
- sqlFactory.addParameter("action", "自动关闭");
|
|
|
- sqlFactory.addParameter("remarks", "订单数量发完自动关闭");
|
|
|
- sqlFactory.addParameter("actionuserid", "1");
|
|
|
- sqlFactory.addParameter("actionby", "admin");
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- dbConnect.runSqlUpdate(sqlFactory.getSQL());
|
|
|
-
|
|
|
- //是否自动返利结算
|
|
|
- executeAutoRebate(row.getLong("sa_orderid"), siteid);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(siteid.equalsIgnoreCase("CCYOSG")){
|
|
|
- //自动关闭erp发货单接口不成功,则手动关闭e订货的发货单(但状态为关闭)
|
|
|
- ArrayList<String> uncloseSqlList = new ArrayList<>();
|
|
|
- if (unclosedispatchids.size() > 0) {
|
|
|
- for (Object object : unclosedispatchids) {
|
|
|
- Long sa_dispatchid = Long.valueOf(object.toString());
|
|
|
- String billno = "";
|
|
|
- Rows dispatchRows = dbConnect.runSqlQuery("select * from sa_dispatch where sa_dispatchid=" + sa_dispatchid + " and siteid='" + siteid + "'");
|
|
|
- if (!dispatchRows.isEmpty()) {
|
|
|
- billno = dispatchRows.get(0).getString("billno");
|
|
|
- } else {
|
|
|
- logger.info("发货单" + sa_dispatchid + "不存在:");
|
|
|
- continue;
|
|
|
- }
|
|
|
- //手工关闭发货单
|
|
|
- JSONObject jsonobject = new JSONObject();
|
|
|
- JSONObject objectdetail = new JSONObject();
|
|
|
- jsonobject.put("access_token", "basicDrp");
|
|
|
- jsonobject.put("classname", "Sainvoice");
|
|
|
- jsonobject.put("method", "closeSainvoice");
|
|
|
- objectdetail.put("finvonum", billno);
|
|
|
- objectdetail.put("isManual", true);
|
|
|
- jsonobject.put("content", objectdetail);
|
|
|
-
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("content-Type", "application/json");
|
|
|
- String result = new WebRequest().doPost(jsonobject.toString(), erpDocking.getUrl(), map);
|
|
|
- JSONObject resultobject = JSONObject.parseObject(result);
|
|
|
- if (resultobject.getString("errcode").equals("0")) {
|
|
|
- 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 sa_dispatch_items where sa_dispatchid=" + sa_dispatchid + ")");
|
|
|
- RowsMap rowsOrderDetailMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
- Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,sum(t1.outwarehouseqty) outwarehouseqty,t1.sa_orderitemsid,t1.siteid from sa_dispatch_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where ifnull(t1.isclose,0)=0 and t1.sa_dispatchid=" + sa_dispatchid + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
- if (!rowsDispatchDetailGroup.isEmpty()) {
|
|
|
- for (Row row : rowsDispatchDetailGroup) {
|
|
|
- logger.info("测试bug:" + "update sa_orderitems set undeliqty=" + rowsOrderDetailMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + ",deliedqty=" + rowsOrderDetailMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
- uncloseSqlList.add("update sa_orderitems set undeliqty=" + rowsOrderDetailMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + ",deliedqty=" + rowsOrderDetailMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty").subtract(row.getBigDecimal("outwarehouseqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
- }
|
|
|
- }
|
|
|
-// Rows orderRows =dbConnect.runSqlQuery("select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='" + siteid + "' and t2.sa_dispatchid=" + sa_dispatchid);
|
|
|
-// for (Row row:orderRows) {
|
|
|
-// sqlList.add("update sa_order set status='审核' where sa_orderid=" + row.getLong("sa_orderid") + " and siteid='" + siteid + "'");
|
|
|
-// }
|
|
|
- uncloseSqlList.add("update sa_dispatch set status='关闭',closedate=current_time,closeby='admin' where sa_dispatchid='" + sa_dispatchid + "' and siteid='" + siteid + "'");
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "数据操作日志新增");
|
|
|
- sqlFactory.addParameter("sys_contrllogid", createTableID("sys_contrllog"));
|
|
|
- sqlFactory.addParameter("ownertable", "sa_dispatch");
|
|
|
- sqlFactory.addParameter("ownerid", sa_dispatchid);
|
|
|
- sqlFactory.addParameter("action", "自动关闭");
|
|
|
- sqlFactory.addParameter("remarks", "发货单自动关闭成功(未全部发完,未发完数量退回订单并自动关闭)");
|
|
|
- sqlFactory.addParameter("actionuserid", "1");
|
|
|
- sqlFactory.addParameter("actionby", "admin");
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- uncloseSqlList.add(sqlFactory.getSQL());
|
|
|
- } else {
|
|
|
- logger.info("发货单手工关闭错误:" + resultobject.getString("errmsg") + "发货单id:" + sa_dispatchid);
|
|
|
- Rows erpupdatelogRows = dbConnect.runSqlQuery(
|
|
|
- "select * from sys_erpupdatelog where ownertable='sa_dispatch' and type='手工关闭发货单' and ownerid=" + sa_dispatchid);
|
|
|
- SQLFactory sqlFactory;
|
|
|
- if (!erpupdatelogRows.isEmpty()) {
|
|
|
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
|
|
|
- sqlFactory.addParameter("sys_erpupdatelogid", erpupdatelogRows.get(0).getLong("sys_erpupdatelogid"));
|
|
|
- } else {
|
|
|
- sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
|
|
|
- sqlFactory.addParameter("sys_erpupdatelogid", createTableID("sys_erpupdatelog"));
|
|
|
- }
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlFactory.addParameter("userid", 1);
|
|
|
- sqlFactory.addParameter("username", "admin");
|
|
|
- sqlFactory.addParameter("ownerid", sa_dispatchid);
|
|
|
- sqlFactory.addParameter("ownertable", "sa_dispatch");
|
|
|
- sqlFactory.addParameter("type", "手工关闭发货单");
|
|
|
- sqlFactory.addParameter("request", object.toString());
|
|
|
- sqlFactory.addParameter("response", resultobject.toJSONString());
|
|
|
- sqlFactory.addParameter("erpbillno", "");
|
|
|
- sqlFactory.addParameter("errmsg", resultobject.getString("errmsg"));
|
|
|
- sqlFactory.addParameter("status", resultobject.getString("errcode"));
|
|
|
- uncloseSqlList.add(sqlFactory.getSQL());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- dbConnect.runSqlUpdate(uncloseSqlList);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (Object o : dispatchids) {
|
|
|
- Rows rows1 = dbConnect.runSqlQuery("select t2.userid from sa_dispatch t1 inner join sys_enterprise_hr t2 on t1.siteid=t2.siteid and t1.sys_enterpriseid=t2.sys_enterpriseid where sa_dispatchid=" + o);
|
|
|
- HashMap<String, Object> dataextra = new HashMap<>();
|
|
|
- dataextra.put("extraUseridList", rows1.toArrayList("userid"));
|
|
|
- Executor.sendEml(this, "dispatch_close", (Long) o, siteid, dataextra);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void executeAutoRebate(Long sa_orderid, String siteid) throws YosException {
|
|
|
-
|
|
|
- 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.getString(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);
|
|
|
- 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>());
|
|
|
-
|
|
|
- itemclsids.addAll(ItemClass.getSubItemClassIds(dbConnect, siteid, itemclsids));
|
|
|
- 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);
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- 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;
|
|
|
- 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 JSONObject createCashbillIncome(String siteid, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, boolean isupdatek3flag) throws YosException {
|
|
|
-
|
|
|
- long userid = 1;
|
|
|
- String username = "admin";
|
|
|
-
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- long sa_cashbillid = createTableID("sa_cashbill");
|
|
|
- String billcode = createBillCode(siteid, "cashbill");
|
|
|
- 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("period",new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
- sqlFactory.addParameter("class", cashbillEntity.getType());
|
|
|
- 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",
|
|
|
- createTableID("sa_accountbalance"));
|
|
|
- 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;
|
|
|
- }
|
|
|
-}
|