123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- package restcontroller.webmanage.sale.paybill;
- import beans.accountbalance.Accountbalance;
- import beans.accountbalance.AccountbalanceEntity;
- 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.QuerySQL;
- import common.data.Row;
- import common.data.Rows;
- import common.data.SQLFactory;
- import restcontroller.R;
- import restcontroller.webmanage.executorService.Executor;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- @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, IOException {
- boolean isExport = content.getBooleanValue("isExport");
- 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("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and(");
- where.append("t1.paydate >='").append(whereObject.getString("begindate")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and(");
- where.append("t1.paydate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
- 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());
- if (pageSorting.equals("''")) {
- pageSorting = "t1.status desc, t1.createdate desc";
- }
- QuerySQL querySQL = query(where.toString());
- querySQL.setOrderBy(pageSorting);
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- // if (isExport) {
- // //去除不需要导出项
- // rows.getFieldList().remove("sa_paybillid");
- // rows.getFieldList().remove("sys_enterpriseid");
- // rows.getFieldList().remove("checkby");
- // rows.getFieldList().remove("checkdate");
- // rows.getFieldList().remove("remarks");
- // rows.getFieldList().remove("enterprisename");
- // rows.getFieldList().remove("createby");
- // rows.getFieldList().remove("createdate");
- //
- // rows.getFieldList().remove("sa_paybillid");
- // rows.getFieldList().remove("changeuserid");
- // rows.getFieldList().remove("changeby");
- // rows.getFieldList().remove("changedate");
- // rows.getFieldList().remove("bank");
- // rows.getFieldList().remove("bankcardno");
- // rows.getFieldList().remove("submitdate");
- // rows.getFieldList().remove("submitby");
- // rows.getFieldList().remove("inbank");
- // rows.getFieldList().remove("inbankcardno");
- //
- // Rows uploadRows = uploadExcelToObs("cashBill", "打款凭证列表", rows, getTitleMap());
- // return getSucReturnObject().setData(uploadRows).toString();
- // }
- return getSucReturnObject().setData(rows).toString();
- }
- //返回导出的标题
- public HashMap<String, String> getTitleMap() {
- HashMap<String, String> titleMap = new HashMap<>();
- titleMap.put("billno", "凭证编号");
- titleMap.put("status", "单据状态");
- titleMap.put("agentnum", "经销商编号");
- titleMap.put("abbreviation", "经销商简称");
- titleMap.put("payer", "付款人");
- titleMap.put("paydate", "付款时间");
- titleMap.put("period", "回款归属月份");
- titleMap.put("amount", "打款金额");
- return titleMap;
- }
- public QuerySQL query(String where) throws YosException {
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_paybill");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid"
- , "agentnum");
- querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t3.sys_enterpriseid"
- , "enterprisename", "abbreviation");
- querySQL.setWhere(where);
- querySQL.setWhere("t1.siteid", siteid);
- return querySQL;
- }
- @API(title = "新增或更新", apiversion = R.ID20221226153004.v1.class, intervaltime = 200)
- @CACHEING_CLEAN(apiversions = {R.ID20221226152904.v1.class, R.ID20230202100104.v1.class})
- public String insertOrUpdate() throws YosException {
- ArrayList<String> 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<String> 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<String> 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.ID20221009102903.v1.class, R.ID20230111103403.v1.class, R.ID20230202100104.v1.class})
- public String check() throws YosException {
- ArrayList<String> 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 t1.sa_accountclassid,t1.amount,t2.accountname from sa_paybilldetail t1 left join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t1.siteid='" + siteid + "' and t1.amount>0 and t1.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();
- }
- if (dbConnect.runSqlQuery("SELECT 1 from sa_paybilldetail WHERE sa_paybillid=" + sa_paybillid).isEmpty()) {
- 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");
- String remarks = rows.get(0).getString("remarks");
- dbConnect.runSqlUpdate(sqlList);
- for (Row row : accountclassRows) {
- BigDecimal amount = row.getBigDecimal("amount");
- CashbillEntity cashbillEntity = new CashbillEntity(amount, remarks, "打款凭证", billno, "sa_paybill", sa_paybillid, "货款", "");
- JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, row.getLong("sa_accountclassid"), cashbillEntity, false, true);
- sqlList = new ArrayList<>(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
- Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
- dbConnect.runSqlUpdate(sqlList);
- Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
- String message = "您的打款凭证已审核通过,【" + row.getString("accountname") + "】账户已成功充值【" + amount + "】元";
- // sendMsg(message, sa_paybillid, sys_enterpriseid);
- }
- return getSucReturnObject().toString();
- }
- public void sendMsg(String content, Long sa_paybillid, Long sys_enterpriseid) throws YosException {
- ArrayList<Long> 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());
- Rows rows = dbConnect.runSqlQuery("select * from sa_paybill where siteid='" + siteid + "' and sa_paybillid=" + sa_paybillid);
- if (!rows.isEmpty()) {
- String message = "您的打款凭证【" + rows.get(0).getString("billno") + "】已退回!";
- sendMsg(message, sa_paybillid, sys_enterpriseid);
- }
- 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("sa_paybillid", sa_paybillid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- return getSucReturnObject().setData(rows).toString();
- }
- }
|