| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package restcontroller.sale.creditbill;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import beans.datacontrllog.DataContrlLog;
- 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 java.math.BigDecimal;
- import java.util.ArrayList;
- @API(title = "信用额度调整单")
- public class creditbill extends Controller {
- public creditbill(JSONObject content) throws YosException {
- super(content);
- // TODO Auto-generated constructor stub
- }
- @API(title = "新建更新信用额度调整单", apiversion = R.ID20221008155003.v1.class, intervaltime = 200)
- @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class})
- public String insertormodify_creditbill() throws YosException {
- Long sa_creditbillid = content.getLong("sa_creditbillid");
- // Long sys_enterpriseid = content.getLong("sys_enterpriseid");
- // Long sa_accountclassid = content.getLong("sa_accountclassid");
- String billcode = createBillCode("creditbill");
- // String billcode = "123456789";
- // BigDecimal creditquota = content.getBigDecimal("creditquota");
- String remarks = content.getString("remarks");
- ArrayList<String> sqlList = new ArrayList<>();
- if (sa_creditbillid <= 0 || dbConnect
- .runSqlQuery("select sa_creditbillid from sa_creditbill where sa_creditbillid=" + sa_creditbillid)
- .isEmpty()) {
- sa_creditbillid = createTableID("sa_creditbill");
- SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单新增");
- sqlFactory.addParameter("billno", billcode);
- // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("remarks", remarks);
- // sqlFactory.addParameter("creditquota", creditquota);
- sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- content.put("sa_creditbillid", sa_creditbillid);
- sqlList.add(sqlFactory.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "新增", "信用额度调整单新增成功").getSQL());
- } else {
- Rows rowscount = dbConnect
- .runSqlQuery("select status from sa_creditbill where sa_creditbillid=" + sa_creditbillid);
- if (rowscount.isNotEmpty()) {
- if (!rowscount.get(0).getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("非新建状态的信用额度调整单无法更新").toString();
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单更新");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("remarks", remarks);
- // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- // sqlFactory.addParameter("creditquota", creditquota);
- sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- sqlList.add(sqlFactory.getSQL());
- sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "更新", "信用额度调整单更新成功").getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- return queryCreditbillMain();
- }
- @API(title = "合作企业档案列表", apiversion = R.ID20221008164103.v1.class)
- @CACHEING
- public String queryEnterpriseList() throws YosException {
- /*
- * 过滤条件设置
- */
- String where = " 1=1 ";
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + " and(t1.enterprisename like'%" + whereObject.getString("condition")
- + "%' or t1.phonenumber like '%" + whereObject.getString("condition") + "%' " +
- "or t2.erpagentnum like '%" + whereObject.getString("condition") + "%')";
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "合作企业档案列表查询", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "营销账户类别列表", apiversion = R.ID20221008164203.v1.class)
- @CACHEING
- public String queryAccountclassList() throws YosException {
- long sys_enterpriseid = content.getLong("sys_enterpriseid");
- long sa_creditbillid = content.getLong("sa_creditbillid");
- SQLFactory sqlFactory = new SQLFactory(this, "营销账户类别列表查询");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "信用额度调整单列表", apiversion = R.ID20221008155103.v1.class)
- @CACHEING
- public String queryCreditbillList() throws YosException {
- /*
- * 过滤条件设置
- */
- String where = " 1=1 ";
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + " and (t1.billno like'%" + whereObject.getString("condition")
- + "%' or t1.remarks like '%" + whereObject.getString("condition")
- + "%')";
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
- }
- if (whereObject.containsKey("enterprisename") && !"".equals(whereObject.getString("enterprisename"))) {
- where = where + " and t5.enterprisename like '%" + whereObject.getString("enterprisename") + "%' ";
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单列表查询", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "信用额度调整单详情", apiversion = R.ID20221008155203.v1.class)
- public String queryCreditbillMain() throws YosException {
- Long sa_creditbillid = content.getLong("sa_creditbillid");
- SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单详情查询");
- sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
- }
- /**
- * 信用额度调整单审核
- *
- * @return
- */
- @API(title = "信用额度调整单审核", apiversion = R.ID20221008155303.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class,
- R.ID20221008164203.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class})
- public String release() throws YosException {
- long sa_creditbillid = content.getLong("sa_creditbillid");
- // List<String> list = sa_creditbillids.toJavaList(String.class);
- // String[] stringArray = list.toArray(new String[0]);
- // SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
- // sqlFactoryquery.addParameter("siteid", siteid);
- // sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
- Rows rows = dbConnect
- .runSqlQuery("select sa_creditbillid,status,billno from sa_creditbill where sa_creditbillid ='"
- + sa_creditbillid + "' and siteid='" + siteid + "'");
- Rows rowsdetail = dbConnect.runSqlQuery(
- "select sa_creditbillid,sys_enterpriseid,sa_accountclassid,creditquota from sa_creditbilldetail where sa_creditbillid ='"
- + sa_creditbillid + "' and siteid='" + siteid + "'");
- for (Row row : rows) {
- if (row.getString("status").equals("审核")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的信用额度调整单已审核,无法再次审核")
- .toString();
- }
- if (!row.getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的信用额度调整单为非新建状态,无法审核")
- .toString();
- }
- }
- ArrayList<String> sqlList = new ArrayList<>();
- Rows rowsaccountbalance = dbConnect.runSqlQuery(
- "select sa_accountclassid,sys_enterpriseid from sa_accountbalance where siteid='" + siteid + "'");
- RowsMap rowsMaAaccountbalance = rowsaccountbalance.toRowsMap("sys_enterpriseid");
- SQLFactory sqlFactoryupdate = new SQLFactory(this, "信用额度调整单审核");
- sqlFactoryupdate.addParameter("siteid", siteid);
- sqlFactoryupdate.addParameter_in("sa_creditbillid", sa_creditbillid);
- sqlFactoryupdate.addParameter("checkby", username);
- sqlList.add(sqlFactoryupdate.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rowsdetail) {
- long sys_enterpriseid = row.getLong("sys_enterpriseid");
- long sa_accountclassid = row.getLong("sa_accountclassid");
- BigDecimal creditquota = row.getBigDecimal("creditquota");
- if (rowsMaAaccountbalance.get(sys_enterpriseid).isEmpty()) {
- SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
- sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("creditquota", creditquota);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- // content.put("sa_creditbillid", sa_creditbillid);
- sqlList.add(sqlFactory.getSQL());
- } else {
- if (rowsMaAaccountbalance.get(sys_enterpriseid).toRowsMap("sa_accountclassid")
- .get(sa_accountclassid).isEmpty()) {
- SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
- sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("creditquota", creditquota);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("username", username);
- // content.put("sa_creditbillid", sa_creditbillid);
- sqlList.add(sqlFactory.getSQL());
- } else {
- sqlList.add("update sa_accountbalance set creditquota=creditquota+" + creditquota
- + ",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid
- + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='"
- + sa_accountclassid + "' and siteid='" + siteid + "'");
- }
- }
- }
- }
- sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "审核", "信用额度调整单审核成功").getSQL());
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "删除", apiversion = R.ID20221008155403.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class})
- public String delete() throws YosException {
- JSONArray sa_creditbillids = content.getJSONArray("sa_creditbillids");
- StringBuffer err = new StringBuffer();
- ArrayList<String> list = new ArrayList<>();
- for (Object o : sa_creditbillids) {
- Rows RowsStatus = dbConnect.runSqlQuery(
- "select billno,status from sa_creditbill where siteid='" + siteid + "' and sa_creditbillid=" + o);
- if (RowsStatus.isNotEmpty() && !RowsStatus.get(0).getString("status").equals("新建")) {
- err.append("编号").append(RowsStatus.get(0).getString("billno")).append("为非新建状态的信用额度调整单无法删除;");
- continue;
- }
- SQLFactory deletesql = new SQLFactory(
- "sql:delete from sa_creditbill where siteid='" + siteid + "' and sa_creditbillid=" + o);
- list.add(deletesql.getSQL());
- }
- dbConnect.runSqlUpdate(list);
- if (err.length() != 0) {
- return getErrReturnObject().setErrMsg(err.toString()).toString();
- } else {
- return getSucReturnObject().toString();
- }
- }
- }
|