creditbill.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package restcontroller.sale.creditbill;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import beans.datacontrllog.DataContrlLog;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.data.Row;
  11. import common.data.Rows;
  12. import common.data.RowsMap;
  13. import common.data.SQLFactory;
  14. import restcontroller.R;
  15. import java.math.BigDecimal;
  16. import java.util.ArrayList;
  17. @API(title = "信用额度调整单")
  18. public class creditbill extends Controller {
  19. public creditbill(JSONObject content) throws YosException {
  20. super(content);
  21. // TODO Auto-generated constructor stub
  22. }
  23. @API(title = "新建更新信用额度调整单", apiversion = R.ID20221008155003.v1.class, intervaltime = 200)
  24. @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class})
  25. public String insertormodify_creditbill() throws YosException {
  26. Long sa_creditbillid = content.getLong("sa_creditbillid");
  27. // Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  28. // Long sa_accountclassid = content.getLong("sa_accountclassid");
  29. String billcode = createBillCode("creditbill");
  30. // String billcode = "123456789";
  31. // BigDecimal creditquota = content.getBigDecimal("creditquota");
  32. String remarks = content.getString("remarks");
  33. ArrayList<String> sqlList = new ArrayList<>();
  34. if (sa_creditbillid <= 0 || dbConnect
  35. .runSqlQuery("select sa_creditbillid from sa_creditbill where sa_creditbillid=" + sa_creditbillid)
  36. .isEmpty()) {
  37. sa_creditbillid = createTableID("sa_creditbill");
  38. SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单新增");
  39. sqlFactory.addParameter("billno", billcode);
  40. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  41. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  42. sqlFactory.addParameter("siteid", siteid);
  43. sqlFactory.addParameter("remarks", remarks);
  44. // sqlFactory.addParameter("creditquota", creditquota);
  45. sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
  46. sqlFactory.addParameter("userid", userid);
  47. sqlFactory.addParameter("username", username);
  48. content.put("sa_creditbillid", sa_creditbillid);
  49. sqlList.add(sqlFactory.getSQL());
  50. sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "新增", "信用额度调整单新增成功").getSQL());
  51. } else {
  52. Rows rowscount = dbConnect
  53. .runSqlQuery("select status from sa_creditbill where sa_creditbillid=" + sa_creditbillid);
  54. if (rowscount.isNotEmpty()) {
  55. if (!rowscount.get(0).getString("status").equals("新建")) {
  56. return getErrReturnObject().setErrMsg("非新建状态的信用额度调整单无法更新").toString();
  57. }
  58. }
  59. SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单更新");
  60. sqlFactory.addParameter("siteid", siteid);
  61. sqlFactory.addParameter("remarks", remarks);
  62. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  63. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  64. // sqlFactory.addParameter("creditquota", creditquota);
  65. sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
  66. sqlFactory.addParameter("userid", userid);
  67. sqlFactory.addParameter("username", username);
  68. sqlList.add(sqlFactory.getSQL());
  69. sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "更新", "信用额度调整单更新成功").getSQL());
  70. }
  71. dbConnect.runSqlUpdate(sqlList);
  72. return queryCreditbillMain();
  73. }
  74. @API(title = "合作企业档案列表", apiversion = R.ID20221008164103.v1.class)
  75. @CACHEING
  76. public String queryEnterpriseList() throws YosException {
  77. /*
  78. * 过滤条件设置
  79. */
  80. String where = " 1=1 ";
  81. if (content.containsKey("where")) {
  82. JSONObject whereObject = content.getJSONObject("where");
  83. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  84. where = where + " and(t1.enterprisename like'%" + whereObject.getString("condition")
  85. + "%' or t1.phonenumber like '%" + whereObject.getString("condition") + "%' " +
  86. "or t2.erpagentnum like '%" + whereObject.getString("condition") + "%')";
  87. }
  88. }
  89. SQLFactory sqlFactory = new SQLFactory(this, "合作企业档案列表查询", pageSize, pageNumber, pageSorting);
  90. sqlFactory.addParameter_SQL("where", where);
  91. sqlFactory.addParameter("siteid", siteid);
  92. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  93. return getSucReturnObject().setData(rows).toString();
  94. }
  95. @API(title = "营销账户类别列表", apiversion = R.ID20221008164203.v1.class)
  96. @CACHEING
  97. public String queryAccountclassList() throws YosException {
  98. long sys_enterpriseid = content.getLong("sys_enterpriseid");
  99. long sa_creditbillid = content.getLong("sa_creditbillid");
  100. SQLFactory sqlFactory = new SQLFactory(this, "营销账户类别列表查询");
  101. sqlFactory.addParameter("siteid", siteid);
  102. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  103. sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
  104. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  105. return getSucReturnObject().setData(rows).toString();
  106. }
  107. @API(title = "信用额度调整单列表", apiversion = R.ID20221008155103.v1.class)
  108. @CACHEING
  109. public String queryCreditbillList() throws YosException {
  110. /*
  111. * 过滤条件设置
  112. */
  113. String where = " 1=1 ";
  114. if (content.containsKey("where")) {
  115. JSONObject whereObject = content.getJSONObject("where");
  116. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  117. where = where + " and (t1.billno like'%" + whereObject.getString("condition")
  118. + "%' or t1.remarks like '%" + whereObject.getString("condition")
  119. + "%')";
  120. }
  121. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  122. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  123. }
  124. if (whereObject.containsKey("enterprisename") && !"".equals(whereObject.getString("enterprisename"))) {
  125. where = where + " and t5.enterprisename like '%" + whereObject.getString("enterprisename") + "%' ";
  126. }
  127. }
  128. SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单列表查询", pageSize, pageNumber, pageSorting);
  129. sqlFactory.addParameter_SQL("where", where);
  130. sqlFactory.addParameter("siteid", siteid);
  131. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  132. return getSucReturnObject().setData(rows).toString();
  133. }
  134. @API(title = "信用额度调整单详情", apiversion = R.ID20221008155203.v1.class)
  135. public String queryCreditbillMain() throws YosException {
  136. Long sa_creditbillid = content.getLong("sa_creditbillid");
  137. SQLFactory sqlFactory = new SQLFactory(this, "信用额度调整单详情查询");
  138. sqlFactory.addParameter("sa_creditbillid", sa_creditbillid);
  139. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  140. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  141. }
  142. /**
  143. * 信用额度调整单审核
  144. *
  145. * @return
  146. */
  147. @API(title = "信用额度调整单审核", apiversion = R.ID20221008155303.v1.class)
  148. @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class,
  149. R.ID20221008164203.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class})
  150. public String release() throws YosException {
  151. long sa_creditbillid = content.getLong("sa_creditbillid");
  152. // List<String> list = sa_creditbillids.toJavaList(String.class);
  153. // String[] stringArray = list.toArray(new String[0]);
  154. // SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  155. // sqlFactoryquery.addParameter("siteid", siteid);
  156. // sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  157. Rows rows = dbConnect
  158. .runSqlQuery("select sa_creditbillid,status,billno from sa_creditbill where sa_creditbillid ='"
  159. + sa_creditbillid + "' and siteid='" + siteid + "'");
  160. Rows rowsdetail = dbConnect.runSqlQuery(
  161. "select sa_creditbillid,sys_enterpriseid,sa_accountclassid,creditquota from sa_creditbilldetail where sa_creditbillid ='"
  162. + sa_creditbillid + "' and siteid='" + siteid + "'");
  163. for (Row row : rows) {
  164. if (row.getString("status").equals("审核")) {
  165. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的信用额度调整单已审核,无法再次审核")
  166. .toString();
  167. }
  168. if (!row.getString("status").equals("新建")) {
  169. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的信用额度调整单为非新建状态,无法审核")
  170. .toString();
  171. }
  172. }
  173. ArrayList<String> sqlList = new ArrayList<>();
  174. Rows rowsaccountbalance = dbConnect.runSqlQuery(
  175. "select sa_accountclassid,sys_enterpriseid from sa_accountbalance where siteid='" + siteid + "'");
  176. RowsMap rowsMaAaccountbalance = rowsaccountbalance.toRowsMap("sys_enterpriseid");
  177. SQLFactory sqlFactoryupdate = new SQLFactory(this, "信用额度调整单审核");
  178. sqlFactoryupdate.addParameter("siteid", siteid);
  179. sqlFactoryupdate.addParameter_in("sa_creditbillid", sa_creditbillid);
  180. sqlFactoryupdate.addParameter("checkby", username);
  181. sqlList.add(sqlFactoryupdate.getSQL());
  182. if (!rows.isEmpty()) {
  183. for (Row row : rowsdetail) {
  184. long sys_enterpriseid = row.getLong("sys_enterpriseid");
  185. long sa_accountclassid = row.getLong("sa_accountclassid");
  186. BigDecimal creditquota = row.getBigDecimal("creditquota");
  187. if (rowsMaAaccountbalance.get(sys_enterpriseid).isEmpty()) {
  188. SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  189. sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  190. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  191. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  192. sqlFactory.addParameter("siteid", siteid);
  193. sqlFactory.addParameter("creditquota", creditquota);
  194. sqlFactory.addParameter("userid", userid);
  195. sqlFactory.addParameter("username", username);
  196. // content.put("sa_creditbillid", sa_creditbillid);
  197. sqlList.add(sqlFactory.getSQL());
  198. } else {
  199. if (rowsMaAaccountbalance.get(sys_enterpriseid).toRowsMap("sa_accountclassid")
  200. .get(sa_accountclassid).isEmpty()) {
  201. SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  202. sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  203. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  204. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  205. sqlFactory.addParameter("siteid", siteid);
  206. sqlFactory.addParameter("creditquota", creditquota);
  207. sqlFactory.addParameter("userid", userid);
  208. sqlFactory.addParameter("username", username);
  209. // content.put("sa_creditbillid", sa_creditbillid);
  210. sqlList.add(sqlFactory.getSQL());
  211. } else {
  212. sqlList.add("update sa_accountbalance set creditquota=creditquota+" + creditquota
  213. + ",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid
  214. + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='"
  215. + sa_accountclassid + "' and siteid='" + siteid + "'");
  216. }
  217. }
  218. }
  219. }
  220. sqlList.add(DataContrlLog.createLog(this, "sa_creditbill", sa_creditbillid, "审核", "信用额度调整单审核成功").getSQL());
  221. dbConnect.runSqlUpdate(sqlList);
  222. return getSucReturnObject().toString();
  223. }
  224. @API(title = "删除", apiversion = R.ID20221008155403.v1.class)
  225. @CACHEING_CLEAN(apiversions = {R.ID20221008155103.v1.class, R.ID20221008155203.v1.class})
  226. public String delete() throws YosException {
  227. JSONArray sa_creditbillids = content.getJSONArray("sa_creditbillids");
  228. StringBuffer err = new StringBuffer();
  229. ArrayList<String> list = new ArrayList<>();
  230. for (Object o : sa_creditbillids) {
  231. Rows RowsStatus = dbConnect.runSqlQuery(
  232. "select billno,status from sa_creditbill where siteid='" + siteid + "' and sa_creditbillid=" + o);
  233. if (RowsStatus.isNotEmpty() && !RowsStatus.get(0).getString("status").equals("新建")) {
  234. err.append("编号").append(RowsStatus.get(0).getString("billno")).append("为非新建状态的信用额度调整单无法删除;");
  235. continue;
  236. }
  237. SQLFactory deletesql = new SQLFactory(
  238. "sql:delete from sa_creditbill where siteid='" + siteid + "' and sa_creditbillid=" + o);
  239. list.add(deletesql.getSQL());
  240. }
  241. dbConnect.runSqlUpdate(list);
  242. if (err.length() != 0) {
  243. return getErrReturnObject().setErrMsg(err.toString()).toString();
  244. } else {
  245. return getSucReturnObject().toString();
  246. }
  247. }
  248. }