wuxw7 лет назад: 7
Родитель
Сommit
7096abd64a
16 измененных файлов с 796 добавлено и 6 удалено
  1. 2 2
      ShopService/doc/savaShopCatalog.json
  2. 36 0
      ShopService/src/main/java/com/java110/shop/dao/IShopServiceDao.java
  3. 85 0
      ShopService/src/main/java/com/java110/shop/dao/impl/ShopServiceDaoImpl.java
  4. 37 0
      ShopService/src/main/java/com/java110/shop/listener/AbstractShopBusinessServiceDataFlowListener.java
  5. 148 0
      ShopService/src/main/java/com/java110/shop/listener/DeleteShopCatalogListener.java
  6. 1 1
      ShopService/src/main/java/com/java110/shop/listener/DeleteShopDescListener.java
  7. 1 1
      ShopService/src/main/java/com/java110/shop/listener/DeleteShopInfoListener.java
  8. 1 1
      ShopService/src/main/java/com/java110/shop/listener/DeleteShopPhotoListener.java
  9. 1 1
      ShopService/src/main/java/com/java110/shop/listener/DeleteShopPreferentialListener.java
  10. 68 0
      ShopService/src/main/java/com/java110/shop/listener/FlushShopCatalogIdListener.java
  11. 142 0
      ShopService/src/main/java/com/java110/shop/listener/SaveShopCatalogListener.java
  12. 156 0
      ShopService/src/main/java/com/java110/shop/listener/UpdateShopCatalogListener.java
  13. 17 0
      java110-common/src/main/java/com/java110/common/constant/ServiceCodeConstant.java
  14. 17 0
      java110-config/db/ShopService/create_table.sql
  15. 70 0
      java110-config/src/main/resources/mapper/shop/ShopServiceDaoImplMapper.xml
  16. 14 0
      java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java

+ 2 - 2
ShopService/doc/savaShopCatalog.json

@@ -17,13 +17,13 @@
     "serviceName": "保存商品目录",
     "remark": "备注",
     "datas": {
-      "businessShopCatalog":[{
+      "businessShopCatalog":{
         "catalogId":"-1",
         "storeId":"123",
         "name":"盖浇饭",
         "level":"1",
         "parentCatalogId":"-1"
-      }]
+      }
     },
     "attrs": [{
       "specCd": "配置的字段ID",

+ 36 - 0
ShopService/src/main/java/com/java110/shop/dao/IShopServiceDao.java

@@ -58,6 +58,13 @@ public interface IShopServiceDao {
      */
     public void saveBusinessShopDesc(Map businessShopDesc) throws DAOException;
 
+    /**
+     * 保存商品目录信息 add by wuxw 2018-09-08
+     * @param businessShopCatalog 商品目录
+     * @throws DAOException
+     */
+    public void saveBusinessShopCatalog(Map businessShopCatalog) throws DAOException;
+
     /**
      * 查询商品信息(business过程)
      * 根据bId 查询商品信息
@@ -110,6 +117,14 @@ public interface IShopServiceDao {
      */
     public Map getBusinessShopDesc(Map info) throws DAOException;
 
+    /**
+     * 查询商品目录信息
+     * @param info bId 信息
+     * @return 商品目录
+     * @throws DAOException
+     */
+    public Map getBusinessShopCatalog(Map info) throws DAOException;
+
     /**
      * 保存 商品信息 Business数据到 Instance中
      * @param info
@@ -154,6 +169,12 @@ public interface IShopServiceDao {
      */
     public void saveShopDescInstance(Map info) throws DAOException;
 
+    /**
+     * 保存 商品目录信息 Business数据到 Instance中
+     * @param info
+     * @throws DAOException
+     */
+    public void saveShopCatalogInstance(Map info) throws DAOException;
 
     /**
      * 查询商品信息(instance过程)
@@ -206,6 +227,14 @@ public interface IShopServiceDao {
      */
     public Map getShopDesc(Map info) throws DAOException;
 
+    /**
+     * 查询商品目录信息(instance 过程)
+     * @param info bId 信息
+     * @return 商品目录
+     * @throws DAOException
+     */
+    public Map getShopCatalog(Map info) throws DAOException;
+
     /**
      * 修改商品信息
      * @param info 修改信息
@@ -250,4 +279,11 @@ public interface IShopServiceDao {
      */
     public void updateShopDescInstance(Map info) throws DAOException;
 
+    /**
+     * 修改商品目录信息
+     * @param info 修改信息
+     * @throws DAOException
+     */
+    public void updateShopCatalogInstance(Map info) throws DAOException;
+
 }

+ 85 - 0
ShopService/src/main/java/com/java110/shop/dao/impl/ShopServiceDaoImpl.java

@@ -127,6 +127,23 @@ public class ShopServiceDaoImpl extends BaseServiceDao implements IShopServiceDa
         }
     }
 
+    /**
+     * 保存商品目录
+     * @param businessShopCatalog 商品目录
+     * @throws DAOException
+     */
+    @Override
+    public void saveBusinessShopCatalog(Map businessShopCatalog) throws DAOException {
+        businessShopCatalog.put("month", DateUtil.getCurrentMonth());
+        logger.debug("保存商品目录信息 入参 businessShopCatalog : {}",businessShopCatalog);
+
+        int saveFlag = sqlSessionTemplate.insert("shopServiceDaoImpl.saveBusinessShopCatalog",businessShopCatalog);
+
+        if(saveFlag < 1){
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存商品目录数据失败:"+ JSONObject.toJSONString(businessShopCatalog));
+        }
+    }
+
     /**
      * 查询商品信息
      * @param info bId 信息
@@ -236,6 +253,26 @@ public class ShopServiceDaoImpl extends BaseServiceDao implements IShopServiceDa
         return businessShopDesces.get(0);
     }
 
+    /**
+     * 查询商品目录
+     * @param info bId 信息
+     * @return
+     * @throws DAOException
+     */
+    @Override
+    public Map getBusinessShopCatalog(Map info) throws DAOException {
+        logger.debug("查询商品证件信息 入参 info : {}",info);
+
+        List<Map> businessShopCatalogs = sqlSessionTemplate.selectList("shopServiceDaoImpl.getBusinessShopCatalog",info);
+        if(businessShopCatalogs == null){
+            return null;
+        }
+        if(businessShopCatalogs.size() >1){
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"根据条件查询有多条数据,数据异常,请检查:businessShopCatalogs,"+ JSONObject.toJSONString(info));
+        }
+
+        return businessShopCatalogs.get(0);
+    }
 
     /**
      * 保存商品信息 到 instance
@@ -313,6 +350,18 @@ public class ShopServiceDaoImpl extends BaseServiceDao implements IShopServiceDa
         }
     }
 
+    @Override
+    public void saveShopCatalogInstance(Map info) throws DAOException {
+        logger.debug("保存商品目录信息Instance 入参 info : {}",info);
+
+        int saveFlag = sqlSessionTemplate.insert("shopServiceDaoImpl.saveShopCatalogInstance",info);
+
+        if(saveFlag < 1){
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存商品目录信息Instance数据失败:"+ JSONObject.toJSONString(info));
+        }
+    }
+
+
     /**
      * 查询商品信息(instance)
      * @param info bId 信息
@@ -419,6 +468,26 @@ public class ShopServiceDaoImpl extends BaseServiceDao implements IShopServiceDa
         return shopDesces.get(0);
     }
 
+    /**
+     * 商品描述查询(instance)
+     * @param info bId 信息
+     * @return
+     * @throws DAOException
+     */
+    @Override
+    public Map getShopCatalog(Map info) throws DAOException {
+        logger.debug("查询商品证件信息 入参 info : {}",info);
+
+        List<Map> shopCatalogs = sqlSessionTemplate.selectList("shopServiceDaoImpl.getShopCatalog",info);
+        if(shopCatalogs == null || shopCatalogs.size() == 0){
+            return null;
+        }
+        if(shopCatalogs.size() >1){
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"根据条件查询有多条数据,数据异常,请检查:getShopCatalog,"+ JSONObject.toJSONString(info));
+        }
+        return shopCatalogs.get(0);
+    }
+
 
     /**
      * 修改商品信息
@@ -515,4 +584,20 @@ public class ShopServiceDaoImpl extends BaseServiceDao implements IShopServiceDa
             throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改商品描述信息Instance数据失败:"+ JSONObject.toJSONString(info));
         }
     }
+
+    /**
+     * 修改商品描述信息
+     * @param info 修改信息
+     * @throws DAOException
+     */
+    @Override
+    public void updateShopCatalogInstance(Map info) throws DAOException {
+        logger.debug("修改商品描述信息Instance 入参 info : {}",info);
+
+        int saveFlag = sqlSessionTemplate.update("shopServiceDaoImpl.updateShopCatalogInstance",info);
+
+        if(saveFlag < 1){
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改商品目录信息Instance数据失败:"+ JSONObject.toJSONString(info));
+        }
+    }
 }

+ 37 - 0
ShopService/src/main/java/com/java110/shop/listener/AbstractShopBusinessServiceDataFlowListener.java

@@ -116,6 +116,20 @@ public abstract class AbstractShopBusinessServiceDataFlowListener extends Abstra
         businessShopDesc.put("statusCd",statusCd);
     }
 
+    /**
+     * 刷新 businessShopCatalog 数据
+     * @param businessShopCatalog
+     * @param statusCd
+     */
+    protected void flushBusinessShopCatalog(Map businessShopCatalog ,String statusCd){
+        businessShopCatalog.put("catalogId",businessShopCatalog.get("catalog_id"));
+        businessShopCatalog.put("storeId",businessShopCatalog.get("store_id"));
+        businessShopCatalog.put("parentCatalogId",businessShopCatalog.get("parent_catalog_id"));
+        businessShopCatalog.put("newBId",businessShopCatalog.get("b_id"));
+        businessShopCatalog.put("statusCd",statusCd);
+    }
+
+
     /**
      * 当修改数据时,查询instance表中的数据 自动保存删除数据到business中
      * @param businessShop 商户信息
@@ -260,4 +274,27 @@ public abstract class AbstractShopBusinessServiceDataFlowListener extends Abstra
         currentShopDesc.put("operate",StatusConstant.OPERATE_DEL);
         getShopServiceDaoImpl().saveBusinessShopDesc(currentShopDesc);
     }
+
+    /**
+     * 商品目录 自动刷 DEL数据
+     * @param business
+     * @param businessShopCalalog
+     */
+    protected void autoSaveDelBusinessShopCatalog(Business business,JSONObject businessShopCalalog){
+        Map info = new HashMap();
+        info.put("catalogId",businessShopCalalog.getString("catalogId"));
+        info.put("storeId",businessShopCalalog.getString("storeId"));
+        info.put("statusCd",StatusConstant.STATUS_CD_VALID);
+        Map currentShopCatalog = getShopServiceDaoImpl().getShopCatalog(info);
+        if(currentShopCatalog == null || currentShopCatalog.isEmpty()){
+            throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR,"未找到需要修改数据信息,入参错误或数据有问题,请检查"+info);
+        }
+
+        currentShopCatalog.put("bId",business.getbId());
+        currentShopCatalog.put("catalogId",currentShopCatalog.get("catalog_id"));
+        currentShopCatalog.put("storeId",currentShopCatalog.get("store_id"));
+        currentShopCatalog.put("parentCatalogId",currentShopCatalog.get("parent_catalog_id"));
+        currentShopCatalog.put("operate",StatusConstant.OPERATE_DEL);
+        getShopServiceDaoImpl().saveBusinessShopCatalog(currentShopCatalog);
+    }
 }

+ 148 - 0
ShopService/src/main/java/com/java110/shop/listener/DeleteShopCatalogListener.java

@@ -0,0 +1,148 @@
+package com.java110.shop.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.constant.ServiceCodeConstant;
+import com.java110.common.constant.StatusConstant;
+import com.java110.common.exception.ListenerExecuteException;
+import com.java110.common.util.Assert;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.entity.center.Business;
+import com.java110.shop.dao.IShopServiceDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 删除商品目录 侦听
+ *
+ * 处理节点
+ * 1、businessShop:{} 商户基本信息节点
+ * 协议地址 :https://github.com/java110/MicroCommunity/wiki/%E5%88%A0%E9%99%A4%E5%95%86%E6%88%B7%E4%BF%A1%E6%81%AF-%E5%8D%8F%E8%AE%AE
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("deleteShopCatalogListener")
+@Transactional
+public class DeleteShopCatalogListener extends AbstractShopBusinessServiceDataFlowListener {
+
+    private final static Logger logger = LoggerFactory.getLogger(DeleteShopCatalogListener.class);
+    @Autowired
+    IShopServiceDao shopServiceDaoImpl;
+
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_DELETE_SHOP_CATALOG;
+    }
+
+    /**
+     * 根据删除信息 查出Instance表中数据 保存至business表 (状态写DEL) 方便撤单时直接更新回去
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) {
+        JSONObject data = business.getDatas();
+
+        Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
+
+        //处理 businessShop 节点 按理这里不应该处理,程序上支持,以防真有这种业务
+        if(data.containsKey("businessShopCatalog")){
+            JSONObject businessShopCatalog = data.getJSONObject("businessShopCatalog");
+            doBusinessShopCatalog(business,businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.getString("catalogId"));
+        }
+    }
+
+    /**
+     * 删除 instance数据
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doBusinessToInstance(DataFlowContext dataFlowContext, Business business) {
+        String bId = business.getbId();
+        //Assert.hasLength(bId,"请求报文中没有包含 bId");
+
+        //商户信息
+        Map info = new HashMap();
+        info.put("bId",business.getbId());
+        info.put("operate",StatusConstant.OPERATE_DEL);
+
+        //商品目录
+        Map businessShopCatalog = shopServiceDaoImpl.getBusinessShopCatalog(info);
+        if( businessShopCatalog != null && !businessShopCatalog.isEmpty()) {
+            flushBusinessShopCatalog(businessShopCatalog,StatusConstant.STATUS_CD_INVALID);
+            shopServiceDaoImpl.updateShopCatalogInstance(businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.get("catalog_id"));
+        }
+    }
+
+    /**
+     * 撤单
+     * 从business表中查询到DEL的数据 将instance中的数据更新回来
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doRecover(DataFlowContext dataFlowContext, Business business) {
+        String bId = business.getbId();
+        //Assert.hasLength(bId,"请求报文中没有包含 bId");
+        Map info = new HashMap();
+        info.put("bId",bId);
+        info.put("statusCd",StatusConstant.STATUS_CD_INVALID);
+
+        Map delInfo = new HashMap();
+        delInfo.put("bId",business.getbId());
+        delInfo.put("operate",StatusConstant.OPERATE_DEL);
+        //商户信息
+        Map shopCatalog = shopServiceDaoImpl.getShopCatalog(info);
+        if(shopCatalog != null && !shopCatalog.isEmpty()){
+
+            //商户信息
+            Map businessShopCatalog = shopServiceDaoImpl.getBusinessShopCatalog(delInfo);
+            //除非程序出错了,这里不会为空
+            if(businessShopCatalog == null || businessShopCatalog.isEmpty()){
+                throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_INNER_ERROR,"撤单失败(shop_catalog),程序内部异常,请检查! "+delInfo);
+            }
+
+            flushBusinessShopCatalog(businessShopCatalog,StatusConstant.STATUS_CD_VALID);
+            shopServiceDaoImpl.updateShopCatalogInstance(businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",shopCatalog.get("catalog_id"));
+        }
+    }
+
+
+    /**
+     * 处理 businessShop 节点
+     * @param business 总的数据节点
+     * @param businessShopCatalog 商品优惠节点
+     */
+    private void doBusinessShopCatalog(Business business,JSONObject businessShopCatalog){
+
+        Assert.jsonObjectHaveKey(businessShopCatalog,"catalogId","businessShopCatalog 节点下没有包含 catalogId 节点");
+
+        if(businessShopCatalog.getString("catalogId").startsWith("-")){
+            throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR,"catalogId 错误,不能自动生成(必须已经存在的catalogId)"+businessShopCatalog);
+        }
+        //自动插入DEL
+        autoSaveDelBusinessShopCatalog(business,businessShopCatalog);
+    }
+
+    public IShopServiceDao getShopServiceDaoImpl() {
+        return shopServiceDaoImpl;
+    }
+
+    public void setShopServiceDaoImpl(IShopServiceDao shopServiceDaoImpl) {
+        this.shopServiceDaoImpl = shopServiceDaoImpl;
+    }
+}

+ 1 - 1
ShopService/src/main/java/com/java110/shop/listener/DeleteShopDescListener.java

@@ -41,7 +41,7 @@ public class DeleteShopDescListener extends AbstractShopBusinessServiceDataFlowL
 
     @Override
     public String getServiceCode() {
-        return ServiceCodeConstant.SERVICE_CODE_DELETE_STORE_INFO;
+        return ServiceCodeConstant.SERVICE_CODE_DELETE_SHOP_INFO;
     }
 
     /**

+ 1 - 1
ShopService/src/main/java/com/java110/shop/listener/DeleteShopInfoListener.java

@@ -43,7 +43,7 @@ public class DeleteShopInfoListener extends AbstractShopBusinessServiceDataFlowL
 
     @Override
     public String getServiceCode() {
-        return ServiceCodeConstant.SERVICE_CODE_DELETE_STORE_INFO;
+        return ServiceCodeConstant.SERVICE_CODE_DELETE_SHOP_INFO;
     }
 
     /**

+ 1 - 1
ShopService/src/main/java/com/java110/shop/listener/DeleteShopPhotoListener.java

@@ -43,7 +43,7 @@ public class DeleteShopPhotoListener extends AbstractShopBusinessServiceDataFlow
 
     @Override
     public String getServiceCode() {
-        return ServiceCodeConstant.SERVICE_CODE_DELETE_STORE_INFO;
+        return ServiceCodeConstant.SERVICE_CODE_DELETE_SHOP_INFO;
     }
 
     /**

+ 1 - 1
ShopService/src/main/java/com/java110/shop/listener/DeleteShopPreferentialListener.java

@@ -41,7 +41,7 @@ public class DeleteShopPreferentialListener extends AbstractShopBusinessServiceD
 
     @Override
     public String getServiceCode() {
-        return ServiceCodeConstant.SERVICE_CODE_DELETE_STORE_INFO;
+        return ServiceCodeConstant.SERVICE_CODE_DELETE_SHOP_INFO;
     }
 
     /**

+ 68 - 0
ShopService/src/main/java/com/java110/shop/listener/FlushShopCatalogIdListener.java

@@ -0,0 +1,68 @@
+package com.java110.shop.listener;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.constant.ServiceCodeConstant;
+import com.java110.common.util.Assert;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.entity.center.Business;
+import com.java110.shop.dao.IShopServiceDao;
+
+/**
+ * 如果shopCatalogId填写的值为-1,则重新生成
+ * Created by wuxw on 2018/7/7.
+ */
+@Java110Listener(name="flushShopCatalogIdListener")
+public class FlushShopCatalogIdListener extends AbstractShopBusinessServiceDataFlowListener {
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_SAVE_SHOP_CATALOG;
+    }
+
+    @Override
+    public IShopServiceDao getShopServiceDaoImpl() {
+        return null;
+    }
+
+    @Override
+    protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) {
+        JSONObject data = business.getDatas();
+        Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
+        //刷新shopId
+        if(data.containsKey("businessShopCatalog")){
+            JSONObject businessShopCatalog = data.getJSONObject("businessShopCatalog");
+            if(!businessShopCatalog.containsKey("catalogId") || businessShopCatalog.getString("catalogId").startsWith("-")){
+                flushShopCatalogId(data);
+            }
+        }
+
+    }
+
+    @Override
+    protected void doBusinessToInstance(DataFlowContext dataFlowContext, Business business) {
+        // nothing to do
+    }
+
+    @Override
+    protected void doRecover(DataFlowContext dataFlowContext, Business business) {
+        // nothing to do
+    }
+
+    /**
+     * 刷新 商品目录ID
+     * @param data
+     */
+    private void flushShopCatalogId(JSONObject data) {
+
+        String catalogId = GenerateCodeFactory.getShopCatalogId();
+        JSONObject businessShopCatalog = data.getJSONObject("businessShopCatalog");
+        businessShopCatalog.put("catalogId",catalogId);
+    }
+}

+ 142 - 0
ShopService/src/main/java/com/java110/shop/listener/SaveShopCatalogListener.java

@@ -0,0 +1,142 @@
+package com.java110.shop.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.constant.ServiceCodeConstant;
+import com.java110.common.constant.StatusConstant;
+import com.java110.common.exception.ListenerExecuteException;
+import com.java110.common.util.Assert;
+import com.java110.common.util.DateUtil;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.entity.center.Business;
+import com.java110.shop.dao.IShopServiceDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 保存 商品信息 侦听
+ * 处理 businessShop 节点
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("saveShopCatalogListener")
+@Transactional
+public class SaveShopCatalogListener extends AbstractShopBusinessServiceDataFlowListener {
+
+    private final static Logger logger = LoggerFactory.getLogger(SaveShopCatalogListener.class);
+
+    @Autowired
+    IShopServiceDao shopServiceDaoImpl;
+
+    @Override
+    public int getOrder() {
+        return 2;
+    }
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_SAVE_SHOP_CATALOG;
+    }
+
+    /**
+     * 保存商户信息 business 表中
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) {
+        JSONObject data = business.getDatas();
+        Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
+
+        //处理 businessShop 节点
+        if(data.containsKey("businessShopCatalog")){
+            JSONObject businessShopCatalog = data.getJSONObject("businessShopCatalog");
+            doBusinessShopCatalog(business,businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.getString("catalogId"));
+        }
+
+    }
+
+    /**
+     * business 数据转移到 instance
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doBusinessToInstance(DataFlowContext dataFlowContext, Business business) {
+        JSONObject data = business.getDatas();
+
+        Map info = new HashMap();
+        info.put("bId",business.getbId());
+        info.put("operate",StatusConstant.OPERATE_ADD);
+
+        //商户信息
+        Map businessShopCatalog = shopServiceDaoImpl.getBusinessShopCatalog(info);
+        if( businessShopCatalog != null && !businessShopCatalog.isEmpty()) {
+            shopServiceDaoImpl.saveShopCatalogInstance(info);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.get("catalog_id"));
+        }
+
+    }
+
+    /**
+     * 撤单
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doRecover(DataFlowContext dataFlowContext, Business business) {
+        String bId = business.getbId();
+        //Assert.hasLength(bId,"请求报文中没有包含 bId");
+        Map info = new HashMap();
+        info.put("bId",bId);
+        info.put("statusCd",StatusConstant.STATUS_CD_VALID);
+        Map paramIn = new HashMap();
+        paramIn.put("bId",bId);
+        paramIn.put("statusCd",StatusConstant.STATUS_CD_INVALID);
+        //商户信息
+        Map storeCatalog = shopServiceDaoImpl.getShopCatalog(info);
+        if(storeCatalog != null && !storeCatalog.isEmpty()){
+            paramIn.put("storeId",storeCatalog.get("store_id").toString());
+            shopServiceDaoImpl.updateShopCatalogInstance(paramIn);
+            dataFlowContext.addParamOut("catalogId",storeCatalog.get("catalog_id"));
+        }
+    }
+
+
+
+    /**
+     * 处理 businessShop 节点
+     * @param business 总的数据节点
+     * @param businessShopCatalog 商品节点
+     */
+    private void doBusinessShopCatalog(Business business,JSONObject businessShopCatalog){
+
+        Assert.jsonObjectHaveKey(businessShopCatalog,"shopId","businessShopCatalog 节点下没有包含 shopId 节点");
+
+        businessShopCatalog.put("bId",business.getbId());
+        businessShopCatalog.put("operate", StatusConstant.OPERATE_ADD);
+
+        //保存商户信息
+        shopServiceDaoImpl.saveBusinessShopCatalog(businessShopCatalog);
+
+    }
+
+
+
+    @Override
+    public IShopServiceDao getShopServiceDaoImpl() {
+        return shopServiceDaoImpl;
+    }
+
+    public void setShopServiceDaoImpl(IShopServiceDao shopServiceDaoImpl) {
+        this.shopServiceDaoImpl = shopServiceDaoImpl;
+    }
+}

+ 156 - 0
ShopService/src/main/java/com/java110/shop/listener/UpdateShopCatalogListener.java

@@ -0,0 +1,156 @@
+package com.java110.shop.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.constant.ServiceCodeConstant;
+import com.java110.common.constant.StatusConstant;
+import com.java110.common.exception.ListenerExecuteException;
+import com.java110.common.util.Assert;
+import com.java110.core.annotation.Java110Listener;
+import com.java110.core.context.DataFlowContext;
+import com.java110.entity.center.Business;
+import com.java110.shop.dao.IShopServiceDao;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 修改商品目录 侦听
+ *
+ * 处理节点
+ * 1、businessShopCatalog:{} 商品优惠信息节点
+ * 协议地址 :https://github.com/java110/MicroCommunity/wiki/%E4%BF%AE%E6%94%B9%E5%95%86%E5%93%81%E4%BF%A1%E6%81%AF-%E5%8D%8F%E8%AE%AE
+ * Created by wuxw on 2018/5/18.
+ */
+@Java110Listener("updateShopCatalogListener")
+@Transactional
+public class UpdateShopCatalogListener extends AbstractShopBusinessServiceDataFlowListener {
+
+    private final static Logger logger = LoggerFactory.getLogger(UpdateShopCatalogListener.class);
+    @Autowired
+    IShopServiceDao shopServiceDaoImpl;
+
+    @Override
+    public int getOrder() {
+        return 1;
+    }
+
+    @Override
+    public String getServiceCode() {
+        return ServiceCodeConstant.SERVICE_CODE_UPDATE_SHOP_CATALOG;
+    }
+
+    /**
+     * business过程
+     * @param dataFlowContext
+     * @param business
+     */
+    @Override
+    protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) {
+
+        JSONObject data = business.getDatas();
+
+        Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
+
+        //处理 businessShopCatalog 节点
+        if(data.containsKey("businessShopCatalog")){
+            JSONObject businessShopCatalog = data.getJSONObject("businessShopCatalog");
+            doBusinessShopCatalog(business,businessShopCatalog);
+        }
+    }
+
+
+    /**
+     * business to instance 过程
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doBusinessToInstance(DataFlowContext dataFlowContext, Business business) {
+
+        //JSONObject data = business.getDatas();
+
+        Map info = new HashMap();
+        info.put("bId",business.getbId());
+        info.put("operate",StatusConstant.OPERATE_ADD);
+
+        //商户优惠信息
+        Map businessShopCatalog = shopServiceDaoImpl.getBusinessShopCatalog(info);
+        if( businessShopCatalog != null && !businessShopCatalog.isEmpty()) {
+            flushBusinessShopCatalog(businessShopCatalog,StatusConstant.STATUS_CD_VALID);
+            shopServiceDaoImpl.updateShopCatalogInstance(businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.get("catalog_id"));
+        }
+    }
+
+    /**
+     * 撤单
+     * @param dataFlowContext 数据对象
+     * @param business 当前业务对象
+     */
+    @Override
+    protected void doRecover(DataFlowContext dataFlowContext, Business business) {
+
+        String bId = business.getbId();
+        //Assert.hasLength(bId,"请求报文中没有包含 bId");
+        Map info = new HashMap();
+        info.put("bId",bId);
+        info.put("statusCd",StatusConstant.STATUS_CD_VALID);
+        Map delInfo = new HashMap();
+        delInfo.put("bId",business.getbId());
+        delInfo.put("operate",StatusConstant.OPERATE_DEL);
+        //商户信息
+        Map shopCatalog = shopServiceDaoImpl.getShopCatalog(info);
+        if(shopCatalog != null && !shopCatalog.isEmpty()){
+
+            //商户信息
+            Map businessShopCatalog = shopServiceDaoImpl.getBusinessShopCatalog(delInfo);
+            //除非程序出错了,这里不会为空
+            if(businessShopCatalog == null || businessShopCatalog.isEmpty()){
+                throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_INNER_ERROR,"撤单失败(shop_catalog),程序内部异常,请检查! "+delInfo);
+            }
+
+            flushBusinessShopCatalog(businessShopCatalog,StatusConstant.STATUS_CD_VALID);
+            shopServiceDaoImpl.updateShopCatalogInstance(businessShopCatalog);
+            dataFlowContext.addParamOut("catalogId",businessShopCatalog.get("catalog_id"));
+        }
+
+    }
+
+
+
+    /**
+     * 处理 businessShopCatalog 节点
+     * @param business 总的数据节点
+     * @param businessShopCatalog 商户节点
+     */
+    private void doBusinessShopCatalog(Business business,JSONObject businessShopCatalog){
+
+        Assert.jsonObjectHaveKey(businessShopCatalog,"catalogId","businessShop 节点下没有包含 catalogId 节点");
+
+        if(businessShopCatalog.getString("catalogId").startsWith("-")){
+            throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR,"catalogId 错误,不能自动生成(必须已经存在的catalogId)"+businessShopCatalog);
+        }
+        //自动保存DEL
+        autoSaveDelBusinessShopCatalog(business,businessShopCatalog);
+
+        businessShopCatalog.put("bId",business.getbId());
+        businessShopCatalog.put("operate", StatusConstant.OPERATE_ADD);
+        //保存商户信息
+        shopServiceDaoImpl.saveBusinessShopCatalog(businessShopCatalog);
+
+    }
+
+    @Override
+    public IShopServiceDao getShopServiceDaoImpl() {
+        return shopServiceDaoImpl;
+    }
+
+    public void setShopServiceDaoImpl(IShopServiceDao shopServiceDaoImpl) {
+        this.shopServiceDaoImpl = shopServiceDaoImpl;
+    }
+}

+ 17 - 0
java110-common/src/main/java/com/java110/common/constant/ServiceCodeConstant.java

@@ -122,6 +122,23 @@ public class ServiceCodeConstant {
      */
     public static final String SERVICE_CODE_BUY_SHOP_INFO = "buy.shop.info";
 
+    /**
+     * 保存商品目录
+     */
+    public static final String SERVICE_CODE_SAVE_SHOP_CATALOG = "save.shop.catalog";
+
+    /**
+     * 修改商品目录
+     */
+    public static final String SERVICE_CODE_UPDATE_SHOP_CATALOG = "update.shop.catalog";
+
+
+    /**
+     * 修改商品目录
+     */
+    public static final String SERVICE_CODE_DELETE_SHOP_CATALOG = "delete.shop.catalog";
+
+
 
 
 

+ 17 - 0
java110-config/db/ShopService/create_table.sql

@@ -62,6 +62,7 @@ CREATE INDEX idx_business_shop_attr_b_id ON business_shop_attr(b_id);
 -- 商品 目录
 create table business_shop_catalog(
     catalog_id varchar(30) not null comment '目录ID',
+    b_id VARCHAR(30) NOT NULL COMMENT '业务Id',
     store_id VARCHAR(30) NOT NULL COMMENT '商店ID',
     `name` varchar(100) not null comment '目录名称',
     level varchar(2) not null comment '目录等级',
@@ -296,6 +297,22 @@ CREATE INDEX idx_shop_photo_b_id ON s_store_photo(b_id);
 CREATE INDEX idx_shop_photo_shop_id ON s_store_photo(shop_id);
 CREATE INDEX idx_shop_photo_shop_photo_id ON s_store_photo(shop_photo_id);
 
+create table s_shop_catalog(
+    catalog_id varchar(30) not null comment '目录ID',
+    b_id VARCHAR(30) NOT NULL COMMENT '业务Id',
+    store_id VARCHAR(30) NOT NULL COMMENT '商店ID',
+    `name` varchar(100) not null comment '目录名称',
+    level varchar(2) not null comment '目录等级',
+    parent_catalog_id varchar(30) not null default '-1' comment '父目录ID,一级目录则写-1',
+    `month` INT NOT NULL COMMENT '月份',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    status_cd VARCHAR(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,S 保存,0, 在用 1失效',
+     UNIQUE KEY (catalog_id)
+);
+CREATE INDEX idx_shop_catalog_b_id ON s_shop_catalog(b_id);
+CREATE INDEX idx_shop_catalog_store_id ON s_shop_catalog(store_id);
+CREATE INDEX idx_shop_catalog_catalog_id ON s_shop_catalog(catalog_id);
+
 -- 商品购买记录
 
 create table s_buy_shop(

+ 70 - 0
java110-config/src/main/resources/mapper/shop/ShopServiceDaoImplMapper.xml

@@ -35,6 +35,11 @@
         insert into business_shop_desc(shop_desc_id,shop_id,b_id,shop_describe,month,operate)
         values(#{shopDescId},#{shopId},#{bId},#{shopDescribe},#{month},#{operate})
     </insert>
+    <!-- 商品目录 add by wuxw 2018-07-08 -->
+    <insert id="saveBusinessShopCatalog" parameterType="Map">
+        insert into business_shop_catalog(catalog_id,b_id,store_id,name,level,parent_catalog_id,month,operate)
+        values(#{catalogId},#{bId},#{storeId},#{name},#{level},#{parentCatalogId},#{month},#{operate})
+    </insert>
 
     <!-- 查询商品信息(Business) add by wuxw 2018-07-03 -->
     <select id="getBusinessShopInfo" parameterType="Map" resultType="Map">
@@ -133,6 +138,21 @@
         </if>
     </select>
 
+    <!-- 查询商品目录(business) add by wuxw 2018-07-03 -->
+    <select id="getBusinessShopCatalog" parameterType="Map" resultType="Map">
+        select sc.catalog_id,sc.b_id,sc.store_id,sc.name,sc.level,sc.parent_catalog_id,sc.operate
+        from business_shop_catalog sc where 1=1
+        <if test="bId != null and bId !=''">
+            and sc.b_id = #{bId}
+        </if>
+        <if test="operate != null and operate != ''">
+            and sc.operate = #{operate}
+        </if>
+        <if test="shopId != null and shopId != ''">
+            and sc.store_id = #{storeId}
+        </if>
+    </select>
+
     <!-- 保存商品信息至 instance表中 add by wuxw 2018-07-03 -->
     <insert id="saveShopInfoInstance" parameterType="Map">
         insert into s_shop(shop_id,b_id,catalog_id,store_id,name,hot_buy,sale_price,open_shop_count,shop_count,start_date,end_date,status_cd)
@@ -180,6 +200,14 @@
         where sd.operate = 'ADD' and sd.b_id=#{bId}
     </insert>
 
+    <!-- 保存 商品目录 信息 instance add by wuxw 2018-07-08 -->
+    <insert id="saveShopCatalogInstance" parameterType="Map">
+        insert into s_shop_catalog(catalog_id,b_id,store_id,name,level,parent_catalog_id,status_cd)
+        select sc.catalog_id,sc.b_id,sc.store_id,sc.name,sc.level,sc.parent_catalog_id,'0'
+        from business_shop_catalog sc
+        where sc.operate = 'ADD' and sc.b_id=#{bId}
+    </insert>
+
     <!-- 查询商品信息 add by wuxw 2018-07-03 -->
     <select id="getShopInfo" parameterType="Map" resultType="Map">
         select s.shop_id,s.b_id,s.catalog_id,s.store_id,s.name,s.hot_buy,s.sale_price,s.open_shop_count,s.shop_count,s.start_date,s.end_date,s.status_cd
@@ -285,6 +313,21 @@
         </if>
     </select>
 
+    <!-- 查询商品目录 instance add by wuxw 2018-07-08 -->
+    <select id="getShopCatalog" parameterType="Map" resultType="Map">
+        select sc.catalog_id,sc.b_id,sc.store_id,sc.name,sc.level,sc.parent_catalog_id,sc.status_cd
+        from s_shop_catalog sc
+        where 1=1
+        <if test="statusCd != null and statusCd != ''">
+            and sd.status_cd = #{statusCd}
+        </if>
+        <if test="bId != null and bId !=''">
+            and sd.b_id = #{bId}
+        </if>
+        <if test="catalogId != null and catalogId !=''">
+            and sd.catalog_id = #{catalogId}
+        </if>
+    </select>
 
 
     <!-- 修改商品信息 add by wuxw 2018-07-03 -->
@@ -454,4 +497,31 @@
             and sd.shop_desc_id = #{shopDescId}
         </if>
     </update>
+
+    <!-- 修改 商品目录信息 add by wuxw 2018-07-08 -->
+    <update id="updateShopCatalogInstance" parameterType="Map">
+        update s_shop_catalog sc set sc.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,sc.b_id = #{newBId}
+        </if>
+        <if test="name != null and name != ''">
+            ,sc.name = #{name}
+        </if>
+        <if test="level != null and level != ''">
+            ,sc.level = #{level}
+        </if>
+        <if test="parentCatalogId != null and parentCatalogId != ''">
+            ,sc.parent_catalog_id = #{parentCatalogId}
+        </if>
+        where 1=1
+        <if test="bId != null and bId !=''">
+            and sc.b_id = #{bId}
+        </if>
+        <if test="storeId != null and storeId !=''">
+            and sc.store_id = #{storeId}
+        </if>
+        <if test="catalogId != null and catalogId !=''">
+            and sc.catalog_id = #{catalogId}
+        </if>
+    </update>
 </mapper>

+ 14 - 0
java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java

@@ -60,6 +60,7 @@ public class GenerateCodeFactory {
         prefixMap.put("shopAttrParamId","53");
         prefixMap.put("shopPreferentialId","54");
         prefixMap.put("shopDescId","55");
+        prefixMap.put("shopCatalogId","56");
     }
 
     private static String PLATFORM_CODE = "0001";
@@ -302,6 +303,19 @@ public class GenerateCodeFactory {
         //调用服务
         return getCode(prefixMap.get("shopDescId"));
     }
+
+    /**
+     * 商品目录ID生成
+     * @return
+     * @throws GenerateCodeException
+     */
+    public static String getShopCatalogId()  throws GenerateCodeException{
+        if(!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))){
+            return prefixMap.get("shopCatalogId") +DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H)+ nextId("%06d");
+        }
+        //调用服务
+        return getCode(prefixMap.get("shopCatalogId"));
+    }
     /**
      * 获取restTemplate
      * @return