123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- package restcontroller.webmanage.saletool.fad;
- import beans.attachment.Attachment;
- import beans.datacontrllog.DataContrlLog;
- import beans.datatag.DataTag;
- import beans.salearea.SaleArea;
- 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 org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import restcontroller.system.dataauth.DataAuthHelper;
- import java.awt.geom.Area;
- import java.util.ArrayList;
- import java.util.LinkedHashSet;
- /**
- * 商品管理
- */
- public class FadGoods extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public FadGoods(JSONObject content) throws YosException {
- super(content);
- }
- String sa_fad = "sa_fad";
- @API(title = "商品新增或编辑", apiversion = R.ID20240428154102.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sa_fadid = content.getLongValue("sa_fadid");
- ArrayList<String> listSQL = new ArrayList<>();
- if (sa_fadid <= 0) {
- sa_fadid = createTableID(sa_fad);
- InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid);
- listSQL.add(sqlFactory.getSQL());
- content.put("sa_fadid", sa_fadid);
- } else {
- if (sys_enterpriseid == 0) {
- UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
- listSQL.add(sqlFactory.getSQL());
- } else {
- Rows rows = dbConnect.runSqlQuery("SELECT * from sa_fadadjust WHERE sys_enterpriseid=" + sys_enterpriseid + " and sa_fadid=" + sa_fadid + " and siteid='" + siteid + "'");
- if (rows.isEmpty()) {
- InsertSQL sqlFactory = FadHelper.getFadAdjustInsertSQL(this, sa_fadid);
- listSQL.add(sqlFactory.getSQL());
- } else {
- UpdateSQL sqlFactory = FadHelper.getFadAdjustUpdateSQL(this, sa_fadid);
- listSQL.add(sqlFactory.getSQL());
- }
- }
- }
- //上下架
- listSQL.add(FadHelper.getIsOnSalesUpdateSQL(this, sa_fadid).getSQL());
- dbConnect.runSqlUpdate(listSQL);
- return detail();
- }
- @API(title = "商品详情", apiversion = R.ID20240428154202.v1.class)
- public String detail() throws YosException {
- Long sa_fadid = content.getLongValue("sa_fadid");
- String ownertable = sa_fad;
- Rows fadrows = dbConnect.runSqlQuery("select * from sa_fad where sa_fadid=" + sa_fadid);
- if (fadrows.isNotEmpty()) {
- siteid = fadrows.get(0).getString("siteid");
- }
- dbConnect.runSqlUpdate("UPDATE sa_fad SET readcount=readcount+1 WHERE sa_fadid=" + sa_fadid);
- QuerySQL querySQ = SQLFactory.createQuerySQL(this, sa_fad)
- .setTableAlias("t1");
- querySQ.addJoinTable(JOINTYPE.left, "sys_datacollect", "t2", "t2.siteid=t1.siteid and t2.ownertable='sa_fad' and t2.type=1 and t2.ownerid=t1.sa_fadid and t2.userid='" + userid + "'");
- querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END");
- querySQ.setSiteid(siteid);
- querySQ.setWhere("sa_fadid", sa_fadid);
- Rows rows = querySQ.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- Rows attRows = getAttachmentUrl(sa_fad, sa_fadid);
- attRows.sortby("sequence", "linksid");
- detailRow.put("attinfos", attRows);
- detailRow.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadGoodsUrl") + sa_fadid);
- QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
- attachmentQuery.setSiteid(detailRow.getString("siteid"));
- attachmentQuery.setWhere("ownertable", ownertable);
- attachmentQuery.setWhere("ownerid", sa_fadid);
- attachmentQuery.setWhere("usetype", ownertable);
- attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
- Rows attachmentRows = attachmentQuery.query();
- ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
- RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- for (Row row : attachmentRows) {
- Rows attPicRows = new Rows();
- Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
- for (Row tempAttRow : tempAttRows) {
- if (tempAttRow.getString("usetype").equals(ownertable)) {
- attPicRows.add(tempAttRow);
- }
- }
- row.put("attinfos", attPicRows);
- }
- detailRow.put("attinfos_pic", attachmentRows);
- detailRow.putIfAbsent("onsaledate", "");
- detailRow.putIfAbsent("classnames", StringUtils.join(detailRow.getJSONArray("class"), ","));
- Row officalrow = new Row();
- officalrow.put("pricetype", detailRow.getString("pricetype"));
- officalrow.put("price", detailRow.getBigDecimal("price"));
- officalrow.put("price_store", detailRow.getBigDecimal("price_store"));
- officalrow.put("price_rebate", detailRow.getBigDecimal("price_rebate"));
- officalrow.put("price_deposit", detailRow.getBigDecimal("price_deposit"));
- officalrow.put("price_original", detailRow.getBigDecimal("price_original"));
- officalrow.put("tag", detailRow.getString("tag"));
- detailRow.put("officialinfo", officalrow);
- if (sys_enterpriseid > 0) {
- Rows adjustrows = dbConnect.runSqlQuery("SELECT pricetype, isonsale,price,price_store,price_rebate,price_deposit,price_original,tag from sa_fadadjust WHERE siteid='" + siteid + "' and sa_fadid=" + sa_fadid + " and sys_enterpriseid=" + sys_enterpriseid);
- if (adjustrows.isNotEmpty()) {
- detailRow.putAll(adjustrows.get(0));
- }
- }
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "商品删除", apiversion = R.ID20240428154302.v1.class)
- public String delete() throws YosException {
- JSONArray sa_fadids = content.getJSONArray("sa_fadids");
- if (sa_fadids.size() == 0) {
- return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
- }
- DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sa_fad);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("sa_fadid", sa_fadids.toArray());
- sqlFactory.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "商品上下架", apiversion = R.ID20240428154402.v1.class)
- public String isonsale() throws YosException {
- JSONArray sa_fadids = content.getJSONArray("sa_fadids");
- int isonsale = content.getIntValue("isonsale");
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
- updateSQL.setSiteid(siteid);
- updateSQL.setWhere("sa_fadid", sa_fadids);
- updateSQL.setValue("isonsale", isonsale);
- updateSQL.setValue("onsaledate", isonsale == 0 ? "null" : Time.getDateTime_Str());
- updateSQL.setValue("onsaleby", isonsale == 0 ? "null" : username);
- updateSQL.update();
- //操作记录
- for (Object object : sa_fadids) {
- long sa_fadid = Long.parseLong(object.toString());
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + sa_fadid);
- if (isonsale == 0) {
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "下架", "下架 " + row.getString("name")).insert();
- } else {
- DataContrlLog.createLog(this, "sa_fad", sa_fadid, "上架", "上架 " + row.getString("name")).insert();
- }
- }
- return getSucReturnObject().toString();
- }
- @API(title = "商品列表", apiversion = R.ID20240428154002.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.name like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
- where.append(" and (");
- where.append("t1.isonsale ='").append(whereObject.getString("isonsale")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("canadjust") && !"".equals(whereObject.getString("canadjust"))) {
- where.append(" and (");
- where.append("t1.canadjust ='").append(whereObject.getString("canadjust")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
- where.append(" and (");
- where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
- where.append(" and (");
- where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_onsale") && !"".equals(whereObject.getString("begindate_onsale"))) {
- where.append(" and (");
- where.append("t1.onsaledate >='").append(whereObject.getString("begindate_onsale")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_onsale") && !"".equals(whereObject.getString("enddate_onsale"))) {
- where.append(" and (");
- where.append("t1.onsaledate <='").append(whereObject.getString("enddate_onsale")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
- where.append(")");
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "isonsale", "canadjust", "model", "pricetype", "sequence", "createby", "createdate", "onsaledate", "class", "tag")
- .setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("classid", 2);
- querySQL.setWhere(where.toString());
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
- // 附件
- RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
- for (Row row : rows) {
- Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
- attRows.sortby("sequence", "linksid");
- row.put("attinfos", attRows);
- row.put("appleturl", userInfo.getWechatAppPage("marketingtool", "FadGoodsUrl") + row.getString("sa_fadid"));
- row.putIfAbsent("onsaledate", "");
- row.putIfAbsent("classnames", StringUtils.join(row.getJSONArray("class"), ","));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "获取门店商品列表", apiversion = R.ID20240430094102.v1.class)
- public String getStoreList() 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.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("isnew") && !"".equals(whereObject.getString("isnew"))) {
- where.append(" and (");
- where.append("t1.isnew ='").append(whereObject.getString("isnew")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
- where.append(")");
- }
- if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) {
- if (whereObject.getString("iscollect").equals("1")) {
- where.append(" and (");
- where.append(" t1.sa_fadid in (SELECT ownerid from sys_datacollect WHERE ownertable='sa_fad' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")");
- where.append(")");
- }
- }
- }
- Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- if (sys_enterpriseid < 0) {
- return getSucReturnObject().setData(new Rows()).toString();
- }
- LinkedHashSet<Long> saleareaidsPath = userInfo.getSaleareaidsPath(this, sys_enterpriseid);
- String wheresql = "t1.sa_fadid in (SELECT ownerid from sys_dataauths WHERE ownertable='sa_fad' and (sys_enterpriseid =" + sys_enterpriseid + " or sa_saleareaid in " + saleareaidsPath + "))";
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "unitname")
- .setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "sa_fadadjust", "t2", "t2.sa_fadid=t1.sa_fadid and t2.siteid=t1.siteid and t2.sys_enterpriseid=" + sys_enterpriseid);
- querySQL.addQueryFields("pricetype", "case when t2.sa_fadadjustid>0 then t2.pricetype else t1.pricetype end");
- querySQL.addQueryFields("price", "case when t2.sa_fadadjustid>0 then t2.price else t1.price end");
- querySQL.addQueryFields("price_deposit", "case when t2.sa_fadadjustid>0 then t2.price_deposit else t1.price_deposit end");
- querySQL.addQueryFields("tag", "case when t2.sa_fadadjustid>0 then t2.tag else t1.tag end");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(wheresql.replace("[", "(").replace("]", ")"));
- querySQL.setWhere("classid", 2);
- querySQL.setWhere("t1.isonsale=1 and (t2.isonsale=1 or t2.isonsale is null)");
- querySQL.setWhere(where.toString());
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
- // 附件
- RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
- for (Row row : rows) {
- Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
- attRows.sortby("sequence", "linksid");
- row.put("attinfos", attRows);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "获取门店调整商品列表", apiversion = R.ID20240515153202.v1.class)
- public String getAdjustStoreList() 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.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.tag like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
- where.append(")");
- }
- }
- if (sys_enterpriseid < 0) {
- return getSucReturnObject().setData(new Rows()).toString();
- }
- LinkedHashSet<Long> saleareaidsPath = userInfo.getSaleareaidsPath(this, sys_enterpriseid);
- String wheresql = "t1.sa_fadid in (SELECT ownerid from sys_dataauths WHERE ownertable='sa_fad' and (sys_enterpriseid =" + sys_enterpriseid + " or sa_saleareaid in " + saleareaidsPath + "))";
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "unitname")
- .setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "sa_fadadjust", "t2", "t2.sa_fadid=t1.sa_fadid and t2.siteid=t1.siteid and t2.sys_enterpriseid=" + sys_enterpriseid);
- querySQL.addQueryFields("pricetype", "case when t2.sa_fadadjustid>0 then t2.pricetype else t1.pricetype end");
- querySQL.addQueryFields("price", "case when t2.sa_fadadjustid>0 then t2.price else t1.price end");
- querySQL.addQueryFields("price_deposit", "case when t2.sa_fadadjustid>0 then t2.price_deposit else t1.price_deposit end");
- querySQL.addQueryFields("tag", "case when t2.sa_fadadjustid>0 then t2.tag else t1.tag end");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(wheresql.replace("[", "(").replace("]", ")"));
- querySQL.setWhere("classid", 2);
- querySQL.setWhere("t1.isonsale=1 and (t2.isonsale=1 or t2.isonsale is null)");
- querySQL.setWhere("canadjust", 1);
- querySQL.setWhere(where.toString());
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
- // 附件
- RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
- for (Row row : rows) {
- Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
- attRows.sortby("sequence", "linksid");
- row.put("attinfos", attRows);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|