|
|
@@ -0,0 +1,232 @@
|
|
|
+package restcontroller.webmanage.sale.stockbill;
|
|
|
+
|
|
|
+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 restcontroller.R;
|
|
|
+
|
|
|
+import javax.swing.text.StyledEditorKit;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 出入库单
|
|
|
+ */
|
|
|
+@API(title = "出入库单")
|
|
|
+public class stockbill extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public stockbill(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "出入库单详情", apiversion = R.ID20230719153803.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryStockbillMain() throws YosException {
|
|
|
+ Long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "出入库单详情");
|
|
|
+ sqlFactory.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(row).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "查询出入库单列表", apiversion = R.ID20230719153903.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.remarks like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
|
|
|
+ where.append(" and t1.status ='").append(whereObject.getString("status")).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("%' ");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("param") && !"".equals(whereObject.getString("param"))) {
|
|
|
+ Rows rowsStockbillid = dbConnect.runSqlQuery("select t1.st_stockbillid from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
|
|
|
+ " where t1.siteid='" + siteid + "' and (t2.itemname like '%" + whereObject.getString("param") + "%' or t2.itemno like '%" + whereObject.getString("param") + "%')");
|
|
|
+
|
|
|
+ if (rowsStockbillid.toJsonArray("st_stockbillid").isEmpty()) {
|
|
|
+ where.append(" and t1.st_stockbillid in (0)");
|
|
|
+ } else {
|
|
|
+ String str = rowsStockbillid.toJsonArray("st_stockbillid").toJSONString();
|
|
|
+ str = str.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(" and t1.st_stockbillid in").append(str);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+// 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.addQueryFields("enterprisephonenumber", "t2.phonenumber");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ return querySQL;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID20230719154003.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {stockbill.class})
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray st_stockbillids = content.getJSONArray("st_stockbillids");
|
|
|
+ BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_stockbillids.size());
|
|
|
+ for (Object o : st_stockbillids) {
|
|
|
+ long st_stockbillid = Long.parseLong(o.toString());
|
|
|
+ Rows RowsStatus = dbConnect.runSqlQuery("select st_stockbillid,status from st_stockbill where siteid='"
|
|
|
+ + siteid + "' and st_stockbillid='" + st_stockbillid + "'");
|
|
|
+
|
|
|
+ if (RowsStatus.isNotEmpty()) {
|
|
|
+ if (!RowsStatus.get(0).getString("status").equals("新建")) {
|
|
|
+ batchDeleteErr.addErr(st_stockbillid, "非新建状态的出入库单无法删除");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(
|
|
|
+ "delete from st_stockbill where siteid='" + siteid + "' and st_stockbillid=" + st_stockbillid);
|
|
|
+ }
|
|
|
+ return batchDeleteErr.getReturnObject().toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "审核", apiversion = R.ID20230719154103.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {stockbill.class})
|
|
|
+ public String check() throws YosException {
|
|
|
+
|
|
|
+ Long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select st_stockbillid,status,billno 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ SQLFactory sqlFactoryupdate = new SQLFactory(this, "出入库单审核");
|
|
|
+ sqlFactoryupdate.addParameter("siteid", siteid);
|
|
|
+ sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactoryupdate.addParameter("checkby", username);
|
|
|
+ sqlList.add(sqlFactoryupdate.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "审核", "出入库单审核成功").getSQL());
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "反审核", apiversion = R.ID20230719154203.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {stockbill.class})
|
|
|
+ public String uncheck() throws YosException {
|
|
|
+ Long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select st_stockbillid,status,billno 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ SQLFactory sqlFactoryupdate = new SQLFactory(this, "出入库单反审核");
|
|
|
+ sqlFactoryupdate.addParameter("siteid", siteid);
|
|
|
+ sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactoryupdate.addParameter("checkby", username);
|
|
|
+ sqlList.add(sqlFactoryupdate.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "反审核", "出入库单反审核成功").getSQL());
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "出入库单明细列表", apiversion = R.ID20230719154303.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String querStcokbillItemsList() 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("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long st_stockbillid = content.getLong("st_stockbillid");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "出入库单明细列表查询", pageSize, pageNumber, pageSorting);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ sqlFactory.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|