package restcontroller.sale.stockbill; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.data.QuerySQL; import common.data.Rows; import common.data.SQLFactory; import common.data.UpdateSQL; import restcontroller.R; import common.annotation.CACHEING; @API(title = "经销商到货确认单") public class stockbill extends Controller { public stockbill(JSONObject content) throws YosException { super(content); } @API(title = "经销商到货确认单查询", apiversion = R.ID2025061311114103.v1.class) @CACHEING public String queryStockbillList() 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.outplace like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t3.agentnum like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t6.depname like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } if (whereObject.containsKey("rb") && !"".equals(whereObject.getString("rb"))) { where.append(" and t1.rb ='").append(whereObject.getString("rb")).append("' "); } if (whereObject.containsKey("isreceiver") && !"".equals(whereObject.getString("isreceiver"))) { where.append(" and t1.isreceiver ='").append(whereObject.getString("isreceiver")).append("' "); } if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) { where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' "); } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' "); } if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) { where.append("and t1.remarks like'%").append(whereObject.getString("remarks")).append("%' "); } } // SQLFactory sqlFactory = new SQLFactory(this, "出入库单列表查询", pageSize, pageNumber, pageSorting); // sqlFactory.addParameter("siteid", siteid); // sqlFactory.addParameter_SQL("where", where); // Rows rows = dbConnect.runSqlQuery(sqlFactory); QuerySQL querySQL = queryStockbillList(where.toString()); querySQL.setPage(pageSize, pageNumber); querySQL.setOrderBy(pageSorting); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } public QuerySQL queryStockbillList(String where) throws YosException { QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill","*"); querySQL.setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid", "enterprisename", "abbreviation"); querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid", "agentnum"); querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_contacts", "t4", "t1.rec_contactsid=t4.contactsid and t1.siteid = t4.siteid"); querySQL.addJoinTable(JOINTYPE.left, "sa_accountbalance", "t5", "t5.sys_enterpriseid=t1.sys_enterpriseid and t1.siteid = t5.siteid and t5.sa_accountclassid =(select t1.sa_accountclassid from sa_accountclass t1 where t1.siteid='"+siteid+"' and t1.accountname='现金账户')", "discountamount"); querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t6", "t1.departmentid=t6.departmentid and t1.siteid = t6.siteid", "depno","depname"); querySQL.addQueryFields("recname", "t4.name"); querySQL.addQueryFields("recphonenumber", "t4.phonenumber"); querySQL.addQueryFields("recaddress", "t4.address"); querySQL.setWhere("t1.siteid", siteid); querySQL.setWhere("t1.status='审核' and t1.type in ('销售出库','返修出库')"); querySQL.setWhere("t1.sys_enterpriseid", sys_enterpriseid); querySQL.setWhere(where); return querySQL; } @API(title = "收货确认", apiversion = R.ID2025061311223103.v1.class) public String newApiMethod() throws YosException { Long st_stockbillid = content.getLong("st_stockbillid"); boolean isreceiver = content.getBooleanValue("isreceiver"); Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='" + st_stockbillid + "' and siteid='" + siteid + "'"); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("该出入库单不存在") .toString(); } else { if (!rows.get(0).getString("status").equals("审核")) { return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非审核状态,无法进行收货确认") .toString(); } } UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_stockbill"); updateSQL.setUniqueid(st_stockbillid); updateSQL.setSiteid(siteid); updateSQL.setValue("isreceiver", isreceiver); updateSQL.setValue("receiverby", username); updateSQL.setDateValue("receiverdate"); dbConnect.runSqlUpdate(updateSQL.getSQL()); return getSucReturnObject().toString(); } }