package restcontroller.webmanage.sale.toolbill; import beans.accountbalance.Accountbalance; import beans.accountbalance.CashbillEntity; import beans.datacontrllog.DataContrlLog; import beans.dataextend.DataExtend; import beans.datateam.DataTeam; import beans.hr.Hr; import beans.parameter.Parameter; import beans.remind.Remind; import beans.uploaderpdata.UploadDataToERP; 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.Row; import common.data.Rows; import common.data.RowsMap; import common.data.SQLFactory; import restcontroller.R; import restcontroller.webmanage.sale.order.Order; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import static beans.order.Order.getOrderRows; /** * 工具借用单 */ public class ToolBill extends Controller { /** * 构造函数 * * @param content */ public ToolBill(JSONObject content) throws YosException { super(content); } @API(title = "查询企业的工具合同", apiversion = R.ID20230114092502.v1.class) public String queryEnterpriseToolContract() 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.billno like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.title like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } } if (content.containsKey("sys_enterpriseid")) { sys_enterpriseid = content.getLongValue("sys_enterpriseid"); } SQLFactory sqlFactory = new SQLFactory(this, "查询企业的工具合同", pageSize, pageNumber, pageSorting); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_SQL("where", where); sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid); Rows rows = dbConnect.runSqlQuery(sqlFactory); return getSucReturnObject().setData(rows).toString(); } @API(title = "新增或更新", apiversion = R.ID20230116092702.v1.class,intervaltime = 200) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String insertOrUpdate() throws YosException { //表名 String tableName = "sa_order"; Long sa_orderid = content.getLong("sa_orderid"); if (content.getLongValue("sys_enterpriseid") > 0) { sys_enterpriseid = content.getLongValue("sys_enterpriseid"); } Long sa_brandid = content.getLongValue("sa_brandid"); Long sa_contractid = content.getLongValue("sa_contractid"); Long sa_projectid = content.getLongValue("sa_projectid"); boolean isAdd; SQLFactory sqlFactory = new SQLFactory(this, "工具借用单新增"); if (sa_orderid <= 0) { isAdd = true; sa_orderid = createTableID(tableName); //默认当前用户为负责人 DataTeam.createTeam(this, "sa_order", sa_orderid, userid); dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "新增", "工具借用单新增成功").getSQL()); } else { Rows rows = dbConnect.runSqlQuery("SELECT status from sa_order WHERE sa_orderid = " + sa_orderid); if (rows.isNotEmpty()) { sqlFactory = new SQLFactory(this, "工具借用单更新"); isAdd = false; dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "更新", "订单更新成功").getSQL()); } else { return getErrReturnObject().setErrMsg("未找到数据").toString(); } } sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); //订单编号 sqlFactory.addParameter("sonum", createBillCode("orderbill")); //订单类型 sqlFactory.addParameter("type", "工具借用单"); //明细分类 sqlFactory.addParameter("typemx", content.getStringValue("typemx")); //订货企业id sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid); //营销账户类型ID sqlFactory.addParameter("sa_accountclassid", beans.order.Order.getDefaultAccount(siteid, "工具借用单")); //品牌ID sqlFactory.addParameter("sa_brandid", sa_brandid); //合同ID sqlFactory.addParameter("sa_contractid", sa_contractid); //工程项目表ID sqlFactory.addParameter("sa_projectid", sa_projectid); //合作企业财务信息ID(开票信息) Long sys_enterprise_financeid = content.getLongValue("sys_enterprise_financeid"); if (sys_enterprise_financeid <= 0 && isAdd) { sys_enterprise_financeid = new Order(content).getDefaultEnterpriseFinanceid(sys_enterpriseid); } sqlFactory.addParameter("sys_enterprise_financeid", sys_enterprise_financeid); //物流公司档案ID //sqlFactory.addParameter("sa_logiscompid", content.getLongValue("sa_logiscompid")); //合作企业联系人表ID(收货信息) //合作企业联系人表ID(收货信息),设置默认 Long rec_contactsid = content.getLongValue("rec_contactsid"); if (rec_contactsid <= 0 && isAdd) { rec_contactsid = new Order(content).getDefaultContactsid(sys_enterpriseid); } sqlFactory.addParameter("rec_contactsid", rec_contactsid); //备注说明 sqlFactory.addParameter("remarks", content.getStringValue("remarks")); //销售人员hrid,业务员hrid if (content.containsKey("saler_hrid")) { hrid = content.getLongValue("saler_hrid"); } if (isAdd) { hrid = new Order(content).getSaleHrid(sys_enterpriseid); } sqlFactory.addParameter("saler_hrid", hrid); //制单方 1表示工厂方,0表示客户方 if (usertype == 21 || usertype == 22) { sqlFactory.addParameter("createflag", 0); } else { sqlFactory.addParameter("createflag", 1); } // 领域 sqlFactory.addParameter("tradefield", content.getStringValue("tradefield")); //结算单位 Long pay_enterpriseid = content.getLongValue("pay_enterpriseid"); if (isAdd) { pay_enterpriseid = sys_enterpriseid; } sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid); //单据日期 String billdate = content.getStringValue("billdate"); //订单新增时 if (isAdd) { if (billdate.equals("")) { sqlFactory.addParameter_SQL("billdate", "current_time"); } else { sqlFactory.addParameter("billdate", billdate); } } else { //订单更新时 if (billdate.equals("")) { sqlFactory.addParameter_SQL("billdate", "createdate"); } else { sqlFactory.addParameter("billdate", billdate); } } sqlFactory.addParameter("rebate_used", content.getBooleanValue("rebate_used")); sqlFactory.addParameter("signbacknum", content.getStringValue("signbacknum")); sqlFactory.addParameter("tradefieldmx", content.getStringValue("tradefieldmx")); sqlFactory.addParameter("sa_promotionid", "null"); sqlFactory.addParameter("freightstatus", content.getStringValue("freightstatus")); //套 Long toolcount = content.getLongValue("toolcount", 1L); sqlFactory.addParameter("toolcount", toolcount); String sql = sqlFactory.getSQL(); dbConnect.runSqlUpdate(sql); content.put("sa_orderid", sa_orderid); return selectDetail(); } @API(title = "更改套数", apiversion = R.ID20230202135502.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String changeToolCount() throws YosException { //表名 Long sa_orderid = content.getLong("sa_orderid"); Long toolcount = content.getLongValue("toolcount", 1L); SQLFactory sqlFactory = new SQLFactory(this, "工具借用单更新套数"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlFactory.addParameter("toolcount", toolcount); String sql = sqlFactory.getSQL(); dbConnect.runSqlUpdate(sql); content.put("sa_orderid", sa_orderid); return selectDetail(); } @API(title = "工具借用单列表", apiversion = R.ID20230114105002.v1.class) @CACHEING public String queryToolList() throws YosException, IOException { 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.sonum like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t5.agentnum like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } //状态 if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) { where.append(" and("); where.append("t1.status like'%").append(whereObject.getString("status")).append("%' "); where.append(")"); } if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) { where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("' "); } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where.append(" and t1.billdate <='").append(whereObject.getString("enddate")).append("' "); } } //是否管理端 Long isManage = content.getLongValue("isManage", 2L); //经销商 if (isManage == 1 && (usertype == 21 || usertype == 22)) { where.append(" and t1.sys_enterpriseid = " + sys_enterpriseid + " "); } //业务员 if (isManage == 0 && usertype == 1) { ArrayList sys_enterpriseids = new ArrayList<>(); sys_enterpriseids.addAll(Hr.getAgents(this, hrid)); sys_enterpriseids.addAll(Hr.getCustomers(this, hrid)); String sql = " and t1.sys_enterpriseid IN " + sys_enterpriseids; sql = sql.replace("[", "(").replace("]", ")"); where.append(sql); } boolean isExport = content.getBooleanValue("isExport"); SQLFactory sqlFactory = new SQLFactory(this, "工具借用单列表", pageSize, pageNumber, pageSorting); if (isExport) { sqlFactory = new SQLFactory(this, "工具借用单列表"); } sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_SQL("where", where); String sql = sqlFactory.getSQL(); Rows rows = dbConnect.runSqlQuery(sql); //查询数据:amount,defaultamount,qty ArrayList sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>()); sqlFactory = new SQLFactory(this, "查询工具数据"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_in("sa_orderid", sa_orderids); RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid"); for (Row row : rows) { Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows()); if (dataRows.isNotEmpty()) { row.putAll(dataRows.get(0)); } else { row.put("amount", 0); row.put("qty", 0); } } // if (isExport) { // Rows uploadRows = uploadExcelToObs("order", "工具借用单列表", rows, new HashMap<>()); // return getSucReturnObject().setData(uploadRows).toString(); // } return getSucReturnObject().setData(rows).toString(); } @API(title = "工具借用单详情", apiversion = R.ID20230114140402.v1.class) @CACHEING public String selectDetail() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); //查询详情 SQLFactory sqlFactory = new SQLFactory(this, "工具借用单详情"); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlFactory.addParameter("siteid", siteid); Rows rows = dbConnect.runSqlQuery(sqlFactory); //查询数据 ArrayList sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>()); sqlFactory = new SQLFactory(this, "查询工具数据"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_in("sa_orderid", sa_orderids); RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid"); ArrayList sys_enterpriseids = rows.toArrayList("pay_enterpriseid", new ArrayList<>()); //查询开票信息 sqlFactory = new SQLFactory(this, "查询经销商默认开票信息"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseids); RowsMap financeRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sys_enterpriseid"); for (Row row : rows) { row.put("pay_finance", financeRowsMap.getOrDefault(row.getString("sys_enterpriseid"), new Rows())); Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows()); if (dataRows.isNotEmpty()) { row.putAll(dataRows.get(0)); } else { row.put("amount", 0); row.put("qty", 0); } } Row row = rows.isNotEmpty() ? rows.get(0) : new Row(); Long pay_enterpriseid = row.getLong("pay_enterpriseid"); Long sa_accountclassid = row.getLong("sa_accountclassid"); //开票信息 sqlFactory = new SQLFactory(this, "工具_开票信息"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_orderid", sa_orderid); Rows financeRows = dbConnect.runSqlQuery(sqlFactory); row.put("finance", financeRows.isNotEmpty() ? financeRows.get(0) : new Row()); //物流 // sqlFactory = new SQLFactory(this, "工具-查询物流信息"); // sqlFactory.addParameter("siteid", siteid); // sqlFactory.addParameter("sa_orderid", sa_orderid); // Rows logiscompRows = dbConnect.runSqlQuery(sqlFactory); // row.put("logiscomp", logiscompRows.isNotEmpty() ? logiscompRows.get(0) : new Row()); //营销账户类型 sqlFactory = new SQLFactory(this, "工具-查询营销账号"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid); sqlFactory.addParameter("sa_accountclassid", sa_accountclassid); String sql = sqlFactory.getSQL(); Rows accountclassRows = dbConnect.runSqlQuery(sql); if (accountclassRows.isNotEmpty()) { accountclassRows.get(0).put("amount", row.getBigDecimal("amount")); accountclassRows.get(0).put("rebate_used", row.getBigDecimal("rebate_used")); accountclassRows.get(0).put("rebate_userate", row.getBigDecimal("rebate_userate")); accountclassRows.get(0).put("rebate_amount", row.getBigDecimal("amount").multiply(row.getBigDecimal("rebate_userate"))); } row.put("accountclass", accountclassRows.isNotEmpty() ? accountclassRows.get(0) : new Row()); //收货信息 row.put("contacts", beans.order.Order.getContactsRow(this, row.getLong("rec_contactsid"))); Rows deliveryRows = dbConnect.runSqlQuery("SELECT count(0) count from plm_item WHERE itemid in (SELECT itemid from sa_orderitems WHERE sa_orderid = " + sa_orderid + " and siteid = '" + siteid + "') and delivery >0 and siteid = '" + siteid + "'"); if (deliveryRows.get(0).getLong("count") > 0) { row.put("isdelivery", 1); } else { row.put("isdelivery", 0); } Rows contractrow = dbConnect.runSqlQuery("SELECT * from sa_contract WHERE sa_contractid in (SELECT sa_contractid FROM sa_order WHERE sa_orderid=" + sa_orderid + ")"); if (contractrow.isNotEmpty()) { row.put("contract", contractrow.get(0)); } else { row.put("contract", new Row()); } row.put("rebatebalance", Accountbalance.getRebateBalance(this, pay_enterpriseid)); return getSucReturnObject().setData(row).toString(); } @API(title = "删除", apiversion = R.ID20230116100002.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String delete() throws YosException { JSONArray sa_orderids = content.getJSONArray("sa_orderids"); if (sa_orderids.size() <= 0) { return getErrReturnObject().setErrMsg("请选择要执行删除操作的数据。").toString(); } String sql = "SELECT 1 from sa_order WHERE sa_orderid in " + sa_orderids + " and `status` !='新建' and siteid = '" + siteid + "'"; sql = sql.replace("[", "(").replace("]", ")"); if (dbConnect.runSqlQuery(sql).isNotEmpty()) { return getErrReturnObject().setErrMsg("存在非新建状态数据,无法执行删除操作。").toString(); } ArrayList sqlList = new ArrayList<>(); SQLFactory sqlFactory = new SQLFactory(this, "删除"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_in("sa_orderid", sa_orderids.toArray()); sqlList.add(sqlFactory.getSQL()); //订单删除原因 DataExtend.createDeleteReasonSql(this, "sa_order", sa_orderids.toJavaList(Long.class), content.getStringValue("deletereason")); //操作记录 for (Object obj : sa_orderids) { Long sa_orderid = Long.valueOf(obj.toString()); sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "删除", "工具借用单删除").getSQL()); } dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "交期回复", apiversion = R.ID20230114152602.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String delivery() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } // if (!rows.get(0).getString("status").equals("新建")) { // return getErrReturnObject().setErrMsg("非新建状态无法交期回复").toString(); // } ArrayList sqlList = new ArrayList<>(); SQLFactory sqlFactory = new SQLFactory(this, "交期回复"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期回复", "工具借用单:交期回复" + sa_orderid).getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "确认交期,操作交期待确认的", apiversion = R.ID20230129154102.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String confirmDeliveryDate() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("订单不存在").toString(); } //交期待确认 String status = rows.get(0).getString("status"); if (!status.equals("交期待确认")) { return getErrReturnObject().setErrMsg("只能操作交期待确认的订单").toString(); } ArrayList sqlList = new ArrayList<>(); SQLFactory sqlFactory = new SQLFactory(this, "确认交期"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期确认", "工具借用单交期确认").getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "撤回交期回复", apiversion = R.ID20230114152702.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String unDelivery() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); ArrayList sqlList = new ArrayList<>(); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } if (!rows.get(0).getString("status").equals("交期回复")) { return getErrReturnObject().setErrMsg("非交期回复状态无法撤回").toString(); } SQLFactory sqlFactory = new SQLFactory(this, "撤回交期回复"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "撤回交期回复", "工具借用单:撤回交期回复" + sa_orderid).getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "提交", apiversion = R.ID20230114160002.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String submit() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); ArrayList sqlList = new ArrayList<>(); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } Row row = rows.get(0); BigDecimal amount = getAmount(sa_orderid); Rows freefreightamountRows = dbConnect.runSqlQuery("SELECT ifnull(freefreightamount,0) freefreightamount from sys_enterprise WHERE sys_enterpriseid= 1 and siteid ='yostest2'"); BigDecimal freefreightamount = freefreightamountRows.get(0).getBigDecimal("freefreightamount"); String freightstatus = row.getString("freightstatus"); if (freightstatus.isEmpty()) { if (freefreightamount.compareTo(BigDecimal.ZERO) == -1) { freightstatus = "到付"; } if (freefreightamount.compareTo(BigDecimal.ZERO) == 0) { freightstatus = "预付"; } if (freefreightamount.compareTo(BigDecimal.ZERO) == 1) { if (amount.compareTo(freefreightamount) == 1) { freightstatus = "预付"; } else { freightstatus = "到付"; } } } SQLFactory sqlFactory = new SQLFactory(this, "提交"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("freightstatus", freightstatus); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "提交", "工具借用单:提交" + sa_orderid).getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "审核", apiversion = R.ID20230114161402.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String check() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); String reviewtype = content.getString("reviewtype"); Rows rows = getOrderRows(this, sa_orderid); ArrayList sqlList = new ArrayList<>(); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } if (!rows.get(0).getString("status").equals("提交") && !rows.get(0).getString("status").equals("交期确认")) { return getErrReturnObject().setErrMsg("非提交,交期确认状态无法审核").toString(); } Row row = rows.get(0); Long sa_accountclassid = row.getLong("sa_accountclassid"); if (sa_accountclassid <= 0) { return getErrReturnObject().setErrMsg("请选择支付账号").toString(); } //验证结算企业 Long pay_enterpriseid = row.getLong("pay_enterpriseid"); if (pay_enterpriseid <= 0) { return getErrReturnObject().setErrMsg("请选择结算企业").toString(); } String sonum = row.getString("sonum"); SQLFactory sqlFactory = new SQLFactory(this, "审核"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("reviewtype", reviewtype); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); BigDecimal amount = getAmount(sa_orderid); CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "押金收入凭证", "由" + sonum + "工具借用单审核时自动产生"); sqlList.addAll(Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true,false)); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "审核", "工具借用单:审核" + sa_orderid).getSQL()); dbConnect.runSqlUpdate(sqlList); if (Parameter.get("system.erp_dockswitch").equalsIgnoreCase("true")) { UploadDataToERP uploadDataToERP = new UploadDataToERP(this, sa_orderid, ""); boolean issuccess = uploadDataToERP.upload(); if (!issuccess) { unCheck(); return getErrReturnObject().setErrMsg("上传ERP失败,当前单据将自动反审核,请检查!").toString(); } else { Long sys_enterpriseid = row.getLong("sys_enterpriseid"); sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid); sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid); } } else { Long sys_enterpriseid = row.getLong("sys_enterpriseid"); sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid); sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid); } return getSucReturnObject().toString(); } public void sendMsg(String content, Long sa_orderid, Long sys_enterpriseid) throws YosException { ArrayList userList = getEnterpriseHrs(sys_enterpriseid).toArrayList("userid", new ArrayList<>()); Remind remind = new Remind(this); remind.setTitle("工具借用单"); remind.setContent(content); remind.setType("应用"); remind.setObjectid(sa_orderid); remind.setObjectname("sa_order"); remind.setTouserid(userList); remind.createSys_message(); } @API(title = "反审核", apiversion = R.ID20230114161502.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String unCheck() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); ArrayList sqlList = new ArrayList<>(); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } if (!rows.get(0).getString("status").equals("审核")) { return getErrReturnObject().setErrMsg("非审核状态无法反审核").toString(); } Row row = rows.get(0); Long sa_accountclassid = row.getLong("sa_accountclassid"); if (sa_accountclassid <= 0) { return getErrReturnObject().setErrMsg("请选择支付账号").toString(); } //验证结算企业 Long pay_enterpriseid = row.getLong("pay_enterpriseid"); if (pay_enterpriseid <= 0) { return getErrReturnObject().setErrMsg("请选择结算企业").toString(); } String sonum = row.getString("sonum"); SQLFactory sqlFactory = new SQLFactory(this, "反审核"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); BigDecimal amount = getAmount(sa_orderid); CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, "押金收入凭证", "由" + sonum + "工具借用反单审核时自动产生"); sqlList.addAll(Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true,false)); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反审核", "工具借用单:反审核" + sa_orderid).getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "退回", apiversion = R.ID20230116085902.v1.class) @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class}) public String back() throws YosException { Long sa_orderid = content.getLong("sa_orderid"); Rows rows = getOrderRows(this, sa_orderid); ArrayList sqlList = new ArrayList<>(); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("数据不存在").toString(); } SQLFactory sqlFactory = new SQLFactory(this, "退回"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_orderid", sa_orderid); sqlList.add(sqlFactory.getSQL()); //操作记录 sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "退回", "工具借用单:退回" + sa_orderid).getSQL()); //订单退回原因 ArrayList sa_orderids = new ArrayList<>(); sa_orderids.add(sa_orderid); DataExtend.createBackReasonSql(this, "sa_order", sa_orderids, content.getStringValue("backreason")); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } public CashbillEntity getCashbillEntity(BigDecimal amount, Long ownerid, String source, String remarks) throws YosException { CashbillEntity entity = new CashbillEntity(); entity.setAmount(amount); entity.setOwnerid(ownerid); entity.setOwnertable("sa_order"); entity.setSource(source); entity.setRemarks(remarks); return entity; } /** * 获取价格(折扣) * * @param sa_orderid * @return * @throws YosException */ public BigDecimal getAmount(Long sa_orderid) throws YosException { Rows rows = dbConnect.runSqlQuery("SELECT ifnull(sum(amount),0) amount from sa_orderitems WHERE sa_orderid=" + sa_orderid + " AND siteid = '" + siteid + "'"); return rows.get(0).getBigDecimal("amount"); } }