123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- package restcontroller.webmanage.saletool.store;
- import beans.attachment.Attachment;
- import beans.parameter.Parameter;
- import beans.time.Time;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.data.*;
- import restcontroller.R;
- import java.util.ArrayList;
- /**
- * 门店小程序(经销商)
- */
- public class StoreAgent extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public StoreAgent(JSONObject content) throws YosException {
- super(content);
- }
- String sa_store = "sa_store";
- Controller controller = this;
- @API(title = "门店列表", apiversion = R.ID20240410095602.v1.class)
- public String list() 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 (");
- where.append("t1.storename like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("storetype") && !"".equals(whereObject.getString("storetype"))) {
- where.append(" and (");
- where.append("t1.storetype='").append(whereObject.getString("storetype")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and (");
- where.append("t1.status='").append(whereObject.getString("status")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("markettype") && !"".equals(whereObject.getString("markettype"))) {
- where.append(" and (");
- where.append("t1.markettype='").append(whereObject.getString("markettype")).append("' ");
- where.append(")");
- }
- }
- if (content.containsKey("sys_enterpriseid") && content.getLongValue("sys_enterpriseid") != 0) {
- sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- }
- QuerySQL listQuery = SQLFactory.createQuerySQL(controller, sa_store)
- .setTableAlias("t1");
- listQuery.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
- , "name", "phonenumber");
- listQuery.addJoinTable(JOINTYPE.left, "sys_users", "t3", "t3.userid=t2.userid "
- , "accountno");
- listQuery.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t1.sys_enterpriseid and t4.siteid=t1.siteid"
- , "enterprisename");
- listQuery.setWhere("sys_enterpriseid", sys_enterpriseid);
- listQuery.setWhere(where.toString());
- listQuery.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = listQuery.query();
- RowsMap attinfoRows = Attachment.get(controller, sa_store, rows.toArrayList("sa_storeid", new ArrayList<>()));
- for (Row row : rows) {
- row.put("attinfos", attinfoRows.getOrDefault(row.getString("sa_storeid"), new Rows()));
- row.put("detailaddress", row.getString("province") + row.getString("city") + row.getString("county") + row.getString("address"));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "门店新增或编辑", apiversion = R.ID20240410095302.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- if (sa_storeid <= 0) {
- sa_storeid = createTableID(sa_store);
- InsertSQL sqlFactory = SQLFactory.createInsertSQL(controller, sa_store);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setUniqueid(sa_storeid);
- sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.setValue("storename", content.getStringValue("storename"));
- sqlFactory.setValue("sale_phonenmber", content.getStringValue("sale_phonenmber"));
- sqlFactory.setValue("area", content.getStringValue("area"));
- sqlFactory.setValue("leader_hrid", content.getLongValue("leader_hrid"));
- sqlFactory.setValue("storetype", content.getStringValue("storetype"));
- sqlFactory.setValue("markettype", content.getStringValue("markettype"));
- sqlFactory.setValue("service_phonenmber", content.getStringValue("service_phonenmber"));
- sqlFactory.setValue("latitude", content.getStringValue("latitude"));
- sqlFactory.setValue("longitude", content.getStringValue("longitude"));
- sqlFactory.setValue("province", content.getStringValue("province"));
- sqlFactory.setValue("city", content.getStringValue("city"));
- sqlFactory.setValue("county", content.getStringValue("county"));
- sqlFactory.setValue("address", content.getStringValue("address"));
- sqlFactory.setValue("storeno", content.getStringValue("storeno"));
- sqlFactory.setValue("status", "新建");
- sqlFactory.insert();
- content.put("sa_storeid", sa_storeid);
- } else {
- UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(controller, sa_store);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setUniqueid(sa_storeid);
- sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.setValue("storename", content.getStringValue("storename"));
- sqlFactory.setValue("sale_phonenmber", content.getStringValue("sale_phonenmber"));
- sqlFactory.setValue("area", content.getStringValue("area"));
- sqlFactory.setValue("leader_hrid", content.getLongValue("leader_hrid"));
- sqlFactory.setValue("storetype", content.getStringValue("storetype"));
- sqlFactory.setValue("markettype", content.getStringValue("markettype"));
- sqlFactory.setValue("service_phonenmber", content.getStringValue("service_phonenmber"));
- sqlFactory.setValue("latitude", content.getStringValue("latitude"));
- sqlFactory.setValue("longitude", content.getStringValue("longitude"));
- sqlFactory.setValue("province", content.getStringValue("province"));
- sqlFactory.setValue("city", content.getStringValue("city"));
- sqlFactory.setValue("county", content.getStringValue("county"));
- sqlFactory.setValue("address", content.getStringValue("address"));
- sqlFactory.setValue("storeno", content.getStringValue("storeno"));
- sqlFactory.update();
- }
- InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sa_store_hr");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sa_store_hr"));
- insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
- insertSQL.setValue("sa_storeid", sa_storeid);
- insertSQL.setValue("sys_enterprise_hrid", content.getLongValue("leader_hrid"));
- insertSQL.setWhere("not exists(select 1 from sa_store_hr where sys_enterprise_hrid=" + content.getLongValue("leader_hrid") + " and sa_storeid=" + sa_storeid + " and siteid='" + siteid + "')");
- insertSQL.insert();
- return detail();
- }
- @API(title = "门店详情", apiversion = R.ID20240410095402.v1.class)
- public String detail() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- QuerySQL detailQuery = SQLFactory.createQuerySQL(controller, sa_store).setTableAlias("t1");
- detailQuery.addJoinTable(JOINTYPE.left, "sys_enterprise_hr", "t2", "t2.sys_enterprise_hrid=t1.leader_hrid and t2.siteid=t1.siteid"
- , "name");
- detailQuery.addJoinTable(JOINTYPE.left, "sys_users", "t3", "t3.userid=t2.userid "
- , "accountno");
- detailQuery.addJoinTable(JOINTYPE.left, "sys_enterprise", "t4", "t4.sys_enterpriseid=t1.sys_enterpriseid and t4.siteid=t1.siteid"
- , "enterprisename");
- detailQuery.addQueryFields("phonenumber", "ifnull(t2.phonenumber,t3.phonenumber)");
- detailQuery.setUniqueid(sa_storeid);
- Rows rows = detailQuery.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- detailRow.putIfAbsent("checkdate", "");
- detailRow.putIfAbsent("submitdate", "");
- Rows attinfoRows = Attachment.get(controller, sa_store, sa_storeid);
- detailRow.put("attinfos", attinfoRows);
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "门店删除", apiversion = R.ID20240410095502.v1.class)
- public String delete() throws YosException {
- JSONArray sa_storeids = content.getJSONArray("sa_storeids");
- QuerySQL querySQL = SQLFactory.createQuerySQL(controller, sa_store);
- querySQL.setSiteid(siteid);
- querySQL.setWhere("sa_storeid", sa_storeids);
- querySQL.setWhere("status!='新建'");
- Rows rows = querySQL.query();
- if (rows.isNotEmpty()) {
- return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
- }
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(controller, sa_store);
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("sa_storeid", sa_storeids);
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "门店提交", apiversion = R.ID20240410110302.v1.class)
- public String submit() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_store WHERE sa_storeid=" + sa_storeid + " and siteid='" + siteid + "' ");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("新建")) {
- return getErrReturnObject().setErrMsg("当前状态不允许提交").toString();
- }
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_store);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_storeid);
- updateSQL.setValue("status", "提交");
- updateSQL.setValue("submitby", username);
- updateSQL.setValue("submitdate", Time.getDateTime_Str());
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "门店撤回", apiversion = R.ID20240410110802.v1.class)
- public String unsubmit() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_store WHERE sa_storeid=" + sa_storeid + " and siteid='" + siteid + "' ");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("提交")) {
- return getErrReturnObject().setErrMsg("当前状态不允许撤回").toString();
- }
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_store);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_storeid);
- updateSQL.setValue("status", "新建");
- updateSQL.setValue("submitby", "null");
- updateSQL.setValue("submitdate", "null");
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "门店退回", apiversion = R.ID20240410135402.v1.class)
- public String returnBack() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_store WHERE sa_storeid=" + sa_storeid + " and siteid='" + siteid + "' ");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("提交")) {
- return getErrReturnObject().setErrMsg("当前状态不允许退回").toString();
- }
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_store);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_storeid);
- updateSQL.setValue("status", "新建");
- updateSQL.setValue("submitby", "null");
- updateSQL.setValue("submitdate", "null");
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "门店审核", apiversion = R.ID20240410141002.v1.class)
- public String check() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_store WHERE sa_storeid=" + sa_storeid + " and siteid='" + siteid + "' ");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("提交")) {
- return getErrReturnObject().setErrMsg("当前状态不允许审核").toString();
- }
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_store);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_storeid);
- updateSQL.setValue("status", "审核");
- updateSQL.setValue("checkby", username);
- updateSQL.setValue("checkdate", Time.getDateTime_Str());
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "门店反审核", apiversion = R.ID20240410141402.v1.class)
- public String uncheck() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- Rows rows = dbConnect.runSqlQuery("SELECT status from sa_store WHERE sa_storeid=" + sa_storeid + " and siteid='" + siteid + "' ");
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- if (!rows.get(0).getString("status").equals("审核")) {
- return getErrReturnObject().setErrMsg("当前状态不允许反审核").toString();
- }
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_store);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_storeid);
- updateSQL.setValue("status", "新建");
- updateSQL.setValue("checkby", "null");
- updateSQL.setValue("checkdate", "null");
- updateSQL.setValue("submitby", "null");
- updateSQL.setValue("submitdate", "null");
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "选择负责人(添加门店人员)", apiversion = R.ID20240410142002.v1.class)
- public String chooseLeader() 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 (");
- where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- String storerolename = Parameter.get("storerolename");
- if (whereObject.getString("status").equals("启用")) {
- where.append(" and (");
- where.append("t1.userid in (").append("SELECT t1.userid FROM sys_userrole t1 INNER JOIN sys_role t2 ON t1.roleid=t2.roleid AND t2.siteid=t1.siteid WHERE t2.rolename='" + storerolename + "'").append(") ");
- where.append(")");
- }
- if (whereObject.getString("status").equals("停用")) {
- where.append(" and (");
- where.append("t1.userid not in (").append("SELECT t1.userid FROM sys_userrole t1 INNER JOIN sys_role t2 ON t1.roleid=t2.roleid AND t2.siteid=t1.siteid WHERE t2.rolename='" + storerolename + "'").append(") ");
- where.append(")");
- }
- }
- }
- Long sa_storeid = content.getLongValue("sa_storeid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sys_enterprise_hr"
- , "sys_enterprise_hrid", "name", "position", "phonenumber", "isleader", "userid")
- .setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where);
- querySQL.setWhere("sys_enterpriseid", sys_enterpriseid);
- querySQL.setWhere(" not exists(select 1 from sa_store where leader_hrid=t1.sys_enterprise_hrid and sa_storeid=" + sa_storeid + " and siteid='" + siteid + "')");
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- //查询角色
- RowsMap roleRowsMap = StoreHelper.getRoleRowsMap(controller, rows.toArray("userid"));
- //查询门店
- RowsMap storeRowsMap = StoreHelper.getStoreRowsMap(controller, rows.toArray("sys_enterprise_hrid"));
- for (Row row : rows) {
- row.put("headpic", getHeadPic(row.getLong("userid")));
- Rows roleRows = roleRowsMap.getOrDefault(row.getString("userid"), new Rows());
- row.put("rolenames", String.join(",", roleRows.toArrayList("rolename")));
- Rows storeRows = storeRowsMap.getOrDefault(row.getString("sys_enterprise_hrid"), new Rows());
- row.put("storenames", String.join(",", storeRows.toArrayList("storename")));
- if (roleRows.toArrayList("rolename").contains(Parameter.get("storerolename"))) {
- row.put("status", "启用");
- } else {
- row.put("status", "停用");
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "门店人员", apiversion = R.ID20240410150702.v1.class)
- public String storeHrs() 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 (");
- where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_storeid = content.getLongValue("sa_storeid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sys_enterprise_hr"
- , "sys_enterprise_hrid", "name", "position", "phonenumber", "isleader", "userid", "createby", "createdate", "changeby", "changedate")
- .setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.inner, "sa_store_hr", "t2", "t2.sys_enterprise_hrid=t1.sys_enterprise_hrid and t2.siteid=t1.siteid"
- , "sa_store_hrid");
- querySQL.addJoinTable(JOINTYPE.left, "sys_users", "t3", "t3.userid=t1.userid "
- , "accountno");
- querySQL.addJoinTable(JOINTYPE.left, "sys_userrole", "t4", "t4.userid=t1.userid and t4.siteid=t1.siteid");
- querySQL.addJoinTable(JOINTYPE.left, "sys_role", "t5", "t5.roleid=t4.roleid and t5.siteid=t4.siteid and t5.rolename='" + Parameter.get("storerolename") + "'");
- querySQL.addQueryFields("status", "case when t5.roleid >0 then '启用' else '停用' end");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where.toString());
- querySQL.setWhere("t2.sa_storeid", sa_storeid);
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- //查询角色
- RowsMap roleRowsMap = StoreHelper.getRoleRowsMap(controller, rows.toArray("userid"));
- //查询门店
- RowsMap storeRowsMap = StoreHelper.getStoreRowsMap(controller, rows.toArray("sys_enterprise_hrid"));
- for (Row row : rows) {
- row.put("headpic", getHeadPic(row.getLong("userid")));
- Rows roleRows = roleRowsMap.getOrDefault(row.getString("userid"), new Rows());
- row.put("rolenames", String.join(",", roleRows.toArrayList("rolename")));
- Rows storeRows = storeRowsMap.getOrDefault(row.getString("sys_enterprise_hrid"), new Rows());
- row.put("storenames", String.join(",", storeRows.toArrayList("storename")));
- row.putIfAbsent("createdate", "");
- row.putIfAbsent("changedate", "");
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "添加门店人员", apiversion = R.ID20240410153502.v1.class)
- public String addstoreHrs() throws YosException {
- Long sa_storeid = content.getLongValue("sa_storeid");
- JSONArray sys_enterprise_hrids = content.getJSONArray("sys_enterprise_hrids");
- ArrayList<String> sqlList = new ArrayList<>();
- for (Object object : sys_enterprise_hrids) {
- InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sa_store_hr");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sa_store_hr"));
- insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
- insertSQL.setValue("sa_storeid", sa_storeid);
- insertSQL.setValue("sys_enterprise_hrid", object);
- insertSQL.setWhere("not exists(select 1 from sa_store_hr where sys_enterprise_hrid=" + object + " and sa_storeid=" + sa_storeid + " and siteid='" + siteid + "')");
- sqlList.add(insertSQL.getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "删除门店人员", apiversion = R.ID20240410153602.v1.class)
- public String deleteStoreHrs() throws YosException {
- JSONArray sa_store_hrids = content.getJSONArray("sa_store_hrids");
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(controller, "sa_store_hr");
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("sa_store_hrid", sa_store_hrids);
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- }
|