123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- package restcontroller.webmanage.sale.accountclass;
- import beans.data.BatchDeleteErr;
- 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.annotation.cm;
- import common.data.Row;
- import common.data.Rows;
- import common.data.SQLFactory;
- import restcontroller.R;
- import restcontroller.sale.creditbill.creditbill;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- @API(title = "营销账户类型")
- public class accountclass extends Controller {
- public accountclass(JSONObject content) throws YosException {
- super(content);
- // TODO Auto-generated constructor stub
- }
- /**
- * 新增修改营销账户类型
- *
- * @return
- */
- @API(title = "营销账户类型新增修改", apiversion = R.ID20221008134703.v1.class)
- @CACHEING_CLEAN(cms = {@cm(clazz = accountclass.class, method = {"queryAccountclass"}), @cm(clazz = creditbill.class, method = {"queryAccountclassList"})})
- public String insertormodify_accountclass() throws YosException {
- long sa_accountclassid = content.getLong("sa_accountclassid");
- String accountno = content.getString("accountno");
- String accountname = content.getString("accountname");
- boolean isorder = content.getBoolean("isorder");
- boolean isrebate = content.getBooleanValue("isrebate");
- JSONArray bindingcategories = content.getJSONArray("bindingcategories");
- BigDecimal maximumdiscount = content.getBigDecimalValue("maximumdiscount");
- if (dbConnect.runSqlQuery("SELECT * from sa_accountclass WHERE accountname='" + accountname + "' and siteid='" + siteid + "' and sa_accountclassid!=" + sa_accountclassid).isNotEmpty()) {
- return getErrReturnObject().setErrMsg("账户名称已存在").toString();
- }
- ArrayList<String> sqllist = new ArrayList<>();
- if (sa_accountclassid <= 0 || dbConnect
- .runSqlQuery(
- "select sa_accountclassid from sa_accountclass where sa_accountclassid=" + sa_accountclassid)
- .isEmpty()) {
- Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_accountclass WHERE accountno = '"
- + accountno + "' and siteid='" + siteid + "'");
- if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
- return getErrReturnObject().setErrMsg("营销账户类型已存在").toString();
- }
- SQLFactory sqlAddFactory = new SQLFactory(this, "营销账户类型新增");
- sa_accountclassid = createTableID("sa_accountclass");
- sqlAddFactory.addParameter("sa_accountclassid", sa_accountclassid);
- sqlAddFactory.addParameter("siteid", siteid);
- sqlAddFactory.addParameter("accountno", accountno);
- sqlAddFactory.addParameter("accountname", accountname);
- sqlAddFactory.addParameter("isorder", isorder);
- sqlAddFactory.addParameter("isrebate", isrebate);
- sqlAddFactory.addParameter("maximumdiscount", maximumdiscount);
- sqlAddFactory.addParameter("bindingcategories", bindingcategories);
- content.put("sa_accountclassid", sa_accountclassid);
- sqllist.add(sqlAddFactory.getSQL());
- } else {
- Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_accountclass WHERE sa_accountclassid!="
- + content.getLong("sa_accountclassid") + " and accountno = '" + accountno + "' and siteid='"
- + siteid + "'");
- if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
- return getErrReturnObject().setErrMsg("营销账户类型已存在").toString();
- }
- Rows isuserdRows = dbConnect
- .runSqlQuery(
- "select isused,accountno,accountname,isorder from sa_accountclass where sa_accountclassid=" + sa_accountclassid);
- SQLFactory sqlUpdateFactory = new SQLFactory(this, "营销账户类型更新");
- sqlUpdateFactory.addParameter("sa_accountclassid", content.getLong("sa_accountclassid"));
- sqlUpdateFactory.addParameter("siteid", siteid);
- if (isuserdRows.get(0).getBoolean("isused")) {
- if (!content.getBoolean("isused")) {
- Rows rowscashbill = dbConnect.runSqlQuery("select sa_cashbillid from sa_cashbill where sa_accountclassid="
- + sa_accountclassid + " and status='审核'");
- Rows rowsaccountbalance = dbConnect.runSqlQuery(
- "select sa_accountbalanceid from sa_accountbalance where sa_accountclassid=" + sa_accountclassid);
- if (!rowscashbill.isEmpty() || !rowsaccountbalance.isEmpty()) {
- return getErrReturnObject().setErrMsg("此营销账户类型已被使用,无法反启用").toString();
- }
- }
- sqlUpdateFactory.addParameter("accountno", accountno);
- sqlUpdateFactory.addParameter("accountname", accountname);
- sqlUpdateFactory.addParameter("isorder", isorder);
- sqlUpdateFactory.addParameter("isused", content.getInteger("isused"));
- sqlUpdateFactory.addParameter("isrebate", isuserdRows.get(0).getInteger("isrebate"));
- sqlUpdateFactory.addParameter("maximumdiscount", maximumdiscount);
- sqlUpdateFactory.addParameter("bindingcategories", bindingcategories);
- } else {
- if (content.getInteger("isused") == 1 && isrebate) {
- sqllist.add("update sa_accountclass set isrebate=0 where sa_accountclassid !=" + sa_accountclassid);
- }
- sqlUpdateFactory.addParameter("accountno", accountno);
- sqlUpdateFactory.addParameter("accountname", accountname);
- sqlUpdateFactory.addParameter("isorder", isorder);
- sqlUpdateFactory.addParameter("isused", content.getInteger("isused"));
- sqlUpdateFactory.addParameter("isrebate", isrebate);
- sqlUpdateFactory.addParameter("maximumdiscount", maximumdiscount);
- sqlUpdateFactory.addParameter("bindingcategories", bindingcategories);
- }
- sqllist.add(sqlUpdateFactory.getSQL());
- }
- dbConnect.runSqlUpdate(sqllist);
- return queryAccountclass();
- }
- /**
- * 查询营销大类
- *
- * @return
- */
- @API(title = "查询营销大类", apiversion = R.ID20230711135303.v1.class)
- @CACHEING
- public String queryitemclassTop() throws YosException {
- /*
- * SQL通告板块查询参数设置并查询
- */
- SQLFactory factory = new SQLFactory(this, "营销大类列表查询");
- factory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(factory.getSQL());
- return getSucReturnObject().setData(rows).toString();
- }
- /**
- * 查询营销账户类型
- *
- * @return
- */
- @API(title = "查询营销账户类型", apiversion = R.ID20221008134803.v1.class)
- public String queryAccountclass() 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(accountname like'%" + whereObject.getString("condition")
- + "%' or accountno like '%" + whereObject.getString("condition") + "%')";
- }
- if (whereObject.containsKey("isused") && !"".equals(whereObject.getString("isused"))) {
- where = where + " and t1.isused=" + whereObject.getLong("isused");
- }
- if (whereObject.containsKey("isorder") && !"".equals(whereObject.getString("isorder"))) {
- where = where + " and t1.isorder=" + whereObject.getLong("isorder");
- }
- if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
- where = where + " and t1.isrebate=" + whereObject.getLong("isrebate");
- }
- if (whereObject.containsKey("isnotspecialfund") && !"".equals(whereObject.getString("isnotspecialfund"))) {
- where = where + " and (JSON_TYPE(t1.bindingcategories) = 'NULL' || JSON_LENGTH(t1.bindingcategories) = 0) and t1.accountname !='保证金账户' ";
- }
- }
- if (content.containsKey("sys_enterpriseid")) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- if (usertype == 21 || usertype == 22) {
- where = where + " and t1.accountname !='活动账户'";
- }
- }
- /*
- * SQL通告板块查询参数设置并查询
- */
- SQLFactory factory = new SQLFactory(this, "营销账户类型列表查询");
- factory.addParameter("siteid", siteid);
- factory.addParameter("sys_enterpriseid", sys_enterpriseid);
- factory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(factory.getSQL());
- // for (Row row:rows) {
- // JSONArray bindingcategories= row.getJSONArray("bindingcategories");
- // if(bindingcategories.size()>0){
- // Rows itemclassRows = dbConnect.runSqlQuery("select * from plm_itemclass where siteid='"+siteid+"' and classtype='营销' and itemclassid in"+bindingcategories.toJSONString().replace("[", "(").replace("]", ")"));
- // row.put("bindingcategories",itemclassRows.toJsonArray("itemclassname"));
- // }else{
- // row.put("bindingcategories",new JSONArray());
- // }
- // }
- return getSucReturnObject().setData(rows).toString();
- }
- /**
- * 查询营销账户余额
- *
- * @return
- */
- @API(title = "查询营销账户余额", apiversion = R.ID20221008145903.v1.class)
- @CACHEING
- public String queryAccountbalance() throws YosException {
- long type = content.getLongValue("type");
- /*
- 过滤条件设置
- */
- String where = " 1=1 ";
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("sys_enterpriseid") && !"".equals(whereObject.getString("sys_enterpriseid"))) {
- where = where + " and t1.sys_enterpriseid='" + whereObject.getString("sys_enterpriseid") + "' ";
- }
- if (whereObject.containsKey("enterprisename") && !"".equals(whereObject.getString("enterprisename"))) {
- where = where + " and t3.enterprisename='" + whereObject.getString("enterprisename") + "' ";
- }
- if (whereObject.containsKey("accountno") && !"".equals(whereObject.getString("accountno"))) {
- where = where + " and t2.accountno='" + whereObject.getString("accountno") + "' ";
- }
- if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
- where = where + " and t2.accountname='" + whereObject.getString("accountname") + "' ";
- }
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where = where + " and (t2.accountname like'%" + whereObject.getString("condition") + "%' " +
- "or t3.enterprisename like'%" + whereObject.getString("condition") + "%' " +
- "or t4.agentnum like'%" + whereObject.getString("condition") + "%' " +
- ") ";
- }
- }
- if (type == 1) {
- where = where + " and t1.sys_enterpriseid='" + sys_enterpriseid + "' ";
- }
- /*
- * SQL通告板块查询参数设置并查询
- */
- SQLFactory factory = new SQLFactory(this, "营销账户余额查询", pageSize, pageNumber, pageSorting);
- factory.addParameter("siteid", siteid);
- factory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(factory.getSQL());
- if (!rows.isEmpty()) {
- for (Row row : rows) {
- row.put("balance", row.getBigDecimal("balance"));
- row.put("creditquota", row.getBigDecimal("creditquota"));
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "删除", apiversion = R.ID20221008134903.v1.class)
- @CACHEING_CLEAN(cms = {@cm(clazz = accountclass.class, method = {"queryAccountclass"}), @cm(clazz = creditbill.class, method = {"queryAccountclassList"})})
- public String delete() throws YosException {
- JSONArray sa_accountclassids = content.getJSONArray("sa_accountclassids");
- BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_accountclassids.size());
- for (Object o : sa_accountclassids) {
- long sa_accountclassid = Long.parseLong(o.toString());
- Rows RowsStatus = dbConnect.runSqlQuery("select sa_accountclassid,isused from sa_accountclass where siteid='"
- + siteid + "' and sa_accountclassid='" + sa_accountclassid + "'");
- if (RowsStatus.isNotEmpty()) {
- if (RowsStatus.get(0).getBoolean("isused")) {
- batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已启用,无法删除");
- continue;
- }
- // 判断账户类型是否被使用(存在收支凭证或存在企业营销账户余额表中)
- Rows rowscashbill = dbConnect.runSqlQuery("select sa_cashbillid from sa_cashbill where sa_accountclassid="
- + sa_accountclassid + " and status='审核'");
- Rows rowsaccountbalance = dbConnect.runSqlQuery(
- "select sa_accountbalanceid from sa_accountbalance where sa_accountclassid=" + sa_accountclassid);
- if (!rowscashbill.isEmpty() || !rowsaccountbalance.isEmpty()) {
- batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已被使用,无法删除");
- continue;
- }
- }
- ArrayList<String> list = new ArrayList<>();
- SQLFactory deletesql = new SQLFactory("sql:delete from sa_accountclass where siteid='" + siteid
- + "' and sa_accountclassid=" + sa_accountclassid);
- list.add(deletesql.getSQL());
- dbConnect.runSqlUpdate(list);
- }
- return batchDeleteErr.getReturnObject().toString();
- }
- }
|