package restcontroller.webmanage.sale.paybill; import beans.accountbalance.Accountbalance; import beans.accountbalance.CashbillEntity; import beans.data.BatchDeleteErr; import beans.datacontrllog.DataContrlLog; import beans.remind.Remind; 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.SQLFactory; import restcontroller.R; import java.util.ArrayList; @API(title = "打款凭证") public class Paybill extends Controller { /** * 构造函数 * * @param content */ public Paybill(JSONObject content) throws YosException { super(content); } @API(title = "列表", apiversion = R.ID20221226152904.v1.class) @CACHEING public String query() 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 (t1.billno like '%").append(whereObject.getString("condition")).append("%'"); where.append("or t2.agentnum like '%").append(whereObject.getString("condition")).append("%'"); where.append("or t3.enterprisename like '%").append(whereObject.getString("condition")).append("%')"); } if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) { where.append("and t1.status = '").append(whereObject.getString("status")).append("'"); } if (whereObject.containsKey("startdate") && !"".equals(whereObject.getString("startdate"))) { where.append(" and("); where.append("t1.createdate >='").append(whereObject.getString("startdate")).append("' "); where.append(")"); } if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) { where.append(" and("); where.append("t1.createdate <='").append(whereObject.getString("enddate")).append("' "); where.append(")"); } } if (usertype == 21 || usertype == 22) { where.append(" and t1.sys_enterpriseid=").append(sys_enterpriseid); } else { where.append(" and t1.status!='新建'"); } SQLFactory sqlFactory = new SQLFactory(this, "打款凭证列表", pageSize, pageNumber, pageSorting); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_SQL("where", where); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); return getSucReturnObject().setData(rows).toString(); } @API(title = "新增或更新", apiversion = R.ID20221226153004.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20230202100104.v1.class}) public String insertOrUpdate() throws YosException { ArrayList sqlList = new ArrayList<>(); Long sa_paybillid = content.getLong("sa_paybillid"); if (content.containsKey("sys_enterpriseid")) { sys_enterpriseid = content.getLong("sys_enterpriseid"); } String payer = content.getString("payer"); String paydate = content.getString("paydate"); String amount = content.getString("amount"); String remarks = content.getString("remarks"); String bank = content.getString("bank"); String bankcardno = content.getString("bankcardno"); String inbank = content.getString("inbank"); String inbankcardno = content.getString("inbankcardno"); Rows rows = dbConnect.runSqlQuery("select status from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); SQLFactory sqlFactory = new SQLFactory(this, "打款凭证新增"); if (sa_paybillid <= 0 || rows.isEmpty()) { sa_paybillid = createTableID("sa_paybill"); String billno = createBillCode("paybill"); sqlFactory.addParameter("billno", billno); //sqlFactory.addParameter("billno", sa_paybillid); sqlList.add(DataContrlLog.createLog(this, "sa_paybill", sa_paybillid, "新增", "打款凭证新增").getSQL()); } else { if (!rows.get(0).getString("status").equals("新建")) { return getErrReturnObject().setErrMsg("非新建状态不能更改").toString(); } sqlFactory = new SQLFactory(this, "打款凭证更新"); sqlList.add(DataContrlLog.createLog(this, "sa_paybill", sa_paybillid, "更新", "打款凭证更新").getSQL()); } sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_paybillid", sa_paybillid); sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid); sqlFactory.addParameter("payer", payer); sqlFactory.addParameter("paydate", paydate); sqlFactory.addParameter("amount", amount); sqlFactory.addParameter("remarks", remarks); sqlFactory.addParameter("bank", bank); sqlFactory.addParameter("bankcardno", bankcardno); sqlFactory.addParameter("inbank", inbank); sqlFactory.addParameter("inbankcardno", inbankcardno); sqlFactory.addParameter("userid", userid); sqlFactory.addParameter("username", username); sqlList.add(sqlFactory.getSQL()); dbConnect.runSqlUpdate(sqlList); content.put("sa_paybillid", sa_paybillid); return queryById(); } @API(title = "删除", apiversion = R.ID20221226153104.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20230202100104.v1.class}) public String delete() throws YosException { ArrayList sqlList = new ArrayList<>(); JSONArray sa_paybillids = content.getJSONArray("sa_paybillids"); BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_paybillids.size()); for (Object o : sa_paybillids) { long sa_paybillid = Long.parseLong(o.toString()); Rows rows = dbConnect.runSqlQuery("select status from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); if (!rows.get(0).getString("status").equals("新建")) { batchDeleteErr.addErr(sa_paybillid, "非新建状态下无法删除"); continue; } sqlList.add("delete from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); sqlList.add("delete from sa_paybilldetail where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); sqlList.add(DataContrlLog.createLog(this, "sa_paybill", sa_paybillid, "删除", "打款凭证删除").getSQL()); } dbConnect.runSqlUpdate(sqlList); return batchDeleteErr.getReturnObject().toString(); } @API(title = "提交", apiversion = R.ID20221226153204.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20230202100104.v1.class}) public String submit() throws YosException { ArrayList sqlList = new ArrayList<>(); Long sa_paybillid = content.getLong("sa_paybillid"); Rows rows = dbConnect.runSqlQuery("select status,amount from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); Rows accountsumamount = dbConnect.runSqlQuery("select sum(amount) amount from sa_paybilldetail where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("未选择打款凭证").toString(); } if (!"新建".equals(rows.get(0).getString("status"))) { return getErrReturnObject().setErrMsg("非新建状态无法提交").toString(); } if (rows.get(0).getBigDecimal("amount").compareTo(accountsumamount.get(0).getBigDecimal("amount")) == -1) { return getErrReturnObject().setErrMsg("账户打款金额总值超出打款总金额").toString(); } if (rows.get(0).getBigDecimal("amount").compareTo(accountsumamount.get(0).getBigDecimal("amount")) == 1) { return getErrReturnObject().setErrMsg("打款总金额余" + rows.get(0).getBigDecimal("amount").subtract(accountsumamount.get(0).getBigDecimal("amount")) + "未分配").toString(); } SQLFactory sqlFactory = new SQLFactory(this, "打款凭证提交"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("username", username); sqlFactory.addParameter("sa_paybillid", sa_paybillid); sqlList.add(sqlFactory.getSQL()); sqlList.add(DataContrlLog.createLog(this, "sa_paybill", sa_paybillid, "提交", "打款凭证提交").getSQL()); dbConnect.runSqlUpdate(sqlList); return getSucReturnObject().toString(); } @API(title = "审核", apiversion = R.ID20221226153304.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20221010102903.v1.class, R.ID20230111103403.v1.class, R.ID20230202100104.v1.class}) public String check() throws YosException { ArrayList sqlList = new ArrayList<>(); Long sa_paybillid = content.getLong("sa_paybillid"); Rows rows = dbConnect.runSqlQuery("select sys_enterpriseid,status,billno,remarks from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); Rows accountclassRows = dbConnect.runSqlQuery("select sa_accountclassid,amount from sa_paybilldetail where siteid='" + siteid + "' and amount>0 and sa_paybillid=" + sa_paybillid); if (rows.isEmpty()) { return getErrReturnObject().setErrMsg("未选择打款凭证").toString(); } if (!"提交".equals(rows.get(0).getString("status"))) { return getErrReturnObject().setErrMsg("非提交状态无法审核").toString(); } if (content.containsKey("period") && !"".equals(content.getString("period"))) { sqlList.add("update sa_paybill set period='" + content.getString("period") + "' where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid); } else { return getErrReturnObject().setErrMsg("未填写会计日期").toString(); } SQLFactory sqlFactory = new SQLFactory(this, "打款凭证审核"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_paybillid", sa_paybillid); sqlFactory.addParameter("username", username); sqlList.add(sqlFactory.getSQL()); sqlList.add(DataContrlLog.createLog(this, "sa_paybill", sa_paybillid, "审核", "打款凭证审核").getSQL()); long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid"); String billno = rows.get(0).getString("billno"); CashbillEntity cashbillEntity = new CashbillEntity(); cashbillEntity.setOwnerid(sa_paybillid); cashbillEntity.setOwnertable("sa_paybill"); cashbillEntity.setSource("打款凭证"); cashbillEntity.setSourcenote(billno); cashbillEntity.setRemarks(rows.get(0).getString("remarks")); for (Row row : accountclassRows) { cashbillEntity.setAmount(row.getBigDecimal("amount")); sqlList.addAll(Accountbalance.createCashbillIncome(this, sys_enterpriseid, row.getLong("sa_accountclassid"), cashbillEntity, false)); } dbConnect.runSqlUpdate(sqlList); String message="打款单审核:“您的打款单"+billno+"关联的收入凭证已审核,款已打入您的账户,请及时查收!”"; sendMsg(message, sa_paybillid, sys_enterpriseid); return getSucReturnObject().toString(); } public void sendMsg(String content, Long sa_paybillid, 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_paybillid); remind.setObjectname("sa_paybill"); remind.setTouserid(userList); remind.sendByDialogMsg().createSys_message(); } @API(title = "详情", apiversion = R.ID20221226153404.v1.class) public String queryById() throws YosException { Long sa_paybillid = content.getLong("sa_paybillid"); SQLFactory sqlFactory = new SQLFactory(this, "打款凭证详情"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_paybillid", sa_paybillid); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); if (rows.isNotEmpty()) { rows.get(0).put("attinfos", getAttachmentUrl("sa_paybill", sa_paybillid)); } return getSucReturnObject().setData(rows.get(0)).toString(); } @API(title = "退回", apiversion = R.ID20221227110104.v1.class) @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20230202100104.v1.class}) public String reback() throws YosException { Long sa_paybillid = content.getLong("sa_paybillid"); SQLFactory sqlFactory = new SQLFactory(this, "打款凭证退回"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter("sa_paybillid", sa_paybillid); dbConnect.runSqlUpdate(sqlFactory.getSQL()); return getSucReturnObject().toString(); } @API(title = "查询营销账户类型", apiversion = R.ID20221228085004.v1.class) public String queryAccountclass() throws YosException { Long sa_paybillid = content.getLong("sa_paybillid"); 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(accountname like'%").append(whereObject.getString("condition")).append("%'"); where.append(" or accountno like '%").append(whereObject.getString("condition")).append("%')"); } } SQLFactory sqlFactory = new SQLFactory(this, "营销账户类型列表查询"); sqlFactory.addParameter("siteid", siteid); sqlFactory.addParameter_SQL("where", where); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); return getSucReturnObject().setData(rows).toString(); } }