|
| 1 | +package com.java110.store.listener; |
| 2 | + |
| 3 | +import com.alibaba.fastjson.JSONArray; |
| 4 | +import com.alibaba.fastjson.JSONObject; |
| 5 | +import com.java110.common.constant.ResponseConstant; |
| 6 | +import com.java110.common.constant.ServiceCodeConstant; |
| 7 | +import com.java110.common.constant.StatusConstant; |
| 8 | +import com.java110.common.log.LoggerEngine; |
| 9 | +import com.java110.common.util.Assert; |
| 10 | +import com.java110.core.annotation.Java110Listener; |
| 11 | +import com.java110.core.context.DataFlowContext; |
| 12 | +import com.java110.core.factory.DataTransactionFactory; |
| 13 | +import com.java110.core.factory.GenerateCodeFactory; |
| 14 | +import com.java110.entity.center.Business; |
| 15 | +import com.java110.event.service.BusinessServiceDataFlowEvent; |
| 16 | +import com.java110.event.service.BusinessServiceDataFlowListener; |
| 17 | +import com.java110.store.dao.IStoreServiceDao; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.transaction.annotation.Transactional; |
| 20 | + |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +/** |
| 26 | + * 保存 用户信息 侦听 |
| 27 | + * Created by wuxw on 2018/5/18. |
| 28 | + */ |
| 29 | +@Java110Listener("saveStoreInfoListener") |
| 30 | +@Transactional |
| 31 | +public class SaveStoreInfoListener extends LoggerEngine implements BusinessServiceDataFlowListener{ |
| 32 | + |
| 33 | + @Autowired |
| 34 | + IStoreServiceDao storeServiceDaoImpl; |
| 35 | + |
| 36 | + @Override |
| 37 | + public int getOrder() { |
| 38 | + return 0; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public String getServiceCode() { |
| 43 | + return ServiceCodeConstant.SERVICE_CODE_SAVE_STORE_INFO; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void soService(BusinessServiceDataFlowEvent event) { |
| 48 | + //这里处理业务逻辑数据 |
| 49 | + DataFlowContext dataFlowContext = event.getDataFlowContext(); |
| 50 | + doSaveUserInfo(dataFlowContext); |
| 51 | + } |
| 52 | + |
| 53 | + private void doSaveUserInfo(DataFlowContext dataFlowContext){ |
| 54 | + String businessType = dataFlowContext.getOrder().getBusinessType(); |
| 55 | + Business business = dataFlowContext.getCurrentBusiness(); |
| 56 | + //Assert.hasLength(business.getbId(),"bId 不能为空"); |
| 57 | + // Instance 过程 |
| 58 | + if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(businessType)){ |
| 59 | + //doComplateUserInfo(business); |
| 60 | + doSaveInstanceUserInfo(dataFlowContext,business); |
| 61 | + }else if(StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(businessType)){ // Business过程 |
| 62 | + doSaveBusinessUserInfo(dataFlowContext,business); |
| 63 | + }else if(StatusConstant.REQUEST_BUSINESS_TYPE_DELETE.equals(businessType)){ //撤单过程 |
| 64 | + doDeleteInstanceUserInfo(dataFlowContext,business); |
| 65 | + } |
| 66 | + |
| 67 | + dataFlowContext.setResJson(DataTransactionFactory.createBusinessResponseJson(dataFlowContext,ResponseConstant.RESULT_CODE_SUCCESS,"成功", |
| 68 | + dataFlowContext.getParamOut())); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * 撤单 |
| 73 | + * @param business |
| 74 | + */ |
| 75 | + private void doDeleteInstanceUserInfo(DataFlowContext dataFlowContext,Business business) { |
| 76 | + |
| 77 | + /*String bId = business.getbId(); |
| 78 | + //Assert.hasLength(bId,"请求报文中没有包含 bId"); |
| 79 | + Map info = new HashMap(); |
| 80 | + info.put("bId",bId); |
| 81 | + Map userInfo = storeServiceDaoImpl.queryUserInfo(info); |
| 82 | + if(userInfo != null && !userInfo.isEmpty()){ |
| 83 | + info.put("bId",bId); |
| 84 | + info.put("userId",userInfo.get("user_id").toString()); |
| 85 | + info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| 86 | + storeServiceDaoImpl.updateUserInfoInstance(userInfo); |
| 87 | + dataFlowContext.addParamOut("userId",userInfo.get("user_id")); |
| 88 | + } |
| 89 | +
|
| 90 | + info.clear(); |
| 91 | + info.put("bId",bId); |
| 92 | +
|
| 93 | + List<Map> userAttrs = storeServiceDaoImpl.queryUserInfoAttrs(info); |
| 94 | +
|
| 95 | + if(userAttrs != null && userAttrs.size() >0){ |
| 96 | + info.put("bId",bId); |
| 97 | + //info.put("userId",userInfo.get("user_id").toString()); |
| 98 | + info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| 99 | + storeServiceDaoImpl.updateUserAttrInstance(info); |
| 100 | + } |
| 101 | +*/ |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * instance过程 |
| 107 | + * @param business |
| 108 | + */ |
| 109 | + private void doSaveInstanceUserInfo(DataFlowContext dataFlowContext,Business business) { |
| 110 | + |
| 111 | + JSONObject data = business.getDatas(); |
| 112 | + |
| 113 | + //Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| 114 | + |
| 115 | + //Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点"); |
| 116 | + |
| 117 | + //JSONObject businessUser = data.getJSONObject("businessUser"); |
| 118 | + /* Map info = new HashMap(); |
| 119 | + info.put("bId",business.getbId()); |
| 120 | + info.put("operate",StatusConstant.OPERATE_ADD); |
| 121 | + Map businessUser = storeServiceDaoImpl.queryBusinessUserInfo(info); |
| 122 | + if( businessUser != null && !businessUser.isEmpty()) { |
| 123 | + storeServiceDaoImpl.saveUserInfoInstance(businessUser); |
| 124 | + dataFlowContext.addParamOut("userId",businessUser.get("user_id")); |
| 125 | + } |
| 126 | + List<Map> businessUserAttrs = storeServiceDaoImpl.queryBusinessUserInfoAttrs(info); |
| 127 | + if(businessUserAttrs != null && businessUserAttrs.size() > 0) { |
| 128 | + storeServiceDaoImpl.saveUserAttrInstance(businessUser); |
| 129 | + }*/ |
| 130 | + |
| 131 | + |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * 保存数据至u_user 表中 |
| 136 | + * @param business |
| 137 | + */ |
| 138 | + private void doComplateUserInfo(DataFlowContext dataFlowContext,Business business) { |
| 139 | + /*String bId = business.getbId(); |
| 140 | + Map paramIn = new HashMap(); |
| 141 | + paramIn.put("bId",bId); |
| 142 | + paramIn.put("statusCd",StatusConstant.STATUS_CD_VALID); |
| 143 | + storeServiceDaoImpl.updateUserInfoInstance(paramIn); |
| 144 | + storeServiceDaoImpl.updateUserAttrInstance(paramIn);*/ |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * 处理用户信息 |
| 149 | + * @param business |
| 150 | + */ |
| 151 | + private void doSaveBusinessUserInfo(DataFlowContext dataFlowContext,Business business) { |
| 152 | + |
| 153 | + /*JSONObject data = business.getDatas(); |
| 154 | +
|
| 155 | + Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| 156 | +
|
| 157 | + Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点"); |
| 158 | +
|
| 159 | + JSONObject businessUser = data.getJSONObject("businessUser"); |
| 160 | +
|
| 161 | + Assert.jsonObjectHaveKey(businessUser,"userId","businessUser 节点下没有包含 userId 节点"); |
| 162 | +
|
| 163 | + if(businessUser.getInteger("userId") < 0){ |
| 164 | + //生成userId |
| 165 | + String userId = GenerateCodeFactory.getUserId(); |
| 166 | + businessUser.put("userId",userId); |
| 167 | + } |
| 168 | + dataFlowContext.addParamOut("userId",businessUser.getString("userId")); |
| 169 | + businessUser.put("bId",business.getbId()); |
| 170 | + businessUser.put("operate", StatusConstant.OPERATE_ADD); |
| 171 | + //保存用户信息 |
| 172 | + storeServiceDaoImpl.saveBusinessUserInfo(businessUser); |
| 173 | +
|
| 174 | + if(businessUser.containsKey("businessUserAttr")){ |
| 175 | + doSaveUserAttrs(business); |
| 176 | + }*/ |
| 177 | + |
| 178 | + //storeServiceDaoImpl.saveUserInfoInstance(businessUser); |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + } |
| 183 | + |
| 184 | + private void doSaveUserAttrs(Business business){ |
| 185 | + /*JSONObject data = business.getDatas(); |
| 186 | + JSONObject businessUser = data.getJSONObject("businessUser"); |
| 187 | + JSONArray businessUserAttrs = businessUser.getJSONArray("businessUserAttr"); |
| 188 | + for(int userAttrIndex = 0 ; userAttrIndex < businessUserAttrs.size();userAttrIndex ++){ |
| 189 | + JSONObject userAttr = businessUserAttrs.getJSONObject(userAttrIndex); |
| 190 | + Assert.jsonObjectHaveKey(userAttr,"attrId","businessUserAttr 节点下没有包含 attrId 节点"); |
| 191 | +
|
| 192 | + if(userAttr.getInteger("attrId") < 0){ |
| 193 | + String attrId = GenerateCodeFactory.getAttrId(); |
| 194 | + userAttr.put("attrId",attrId); |
| 195 | + } |
| 196 | +
|
| 197 | + userAttr.put("bId",business.getbId()); |
| 198 | + userAttr.put("userId",businessUser.getString("userId")); |
| 199 | + userAttr.put("operate", StatusConstant.OPERATE_ADD); |
| 200 | +
|
| 201 | + storeServiceDaoImpl.saveBusinessUserAttr(userAttr); |
| 202 | + }*/ |
| 203 | + |
| 204 | + /*JSONObject attrInstance = new JSONObject(); |
| 205 | + attrInstance.put("bId",business.getbId()); |
| 206 | + storeServiceDaoImpl.saveUserAttrInstance(attrInstance);*/ |
| 207 | + } |
| 208 | + |
| 209 | + public IStoreServiceDao getStoreServiceDaoImpl() { |
| 210 | + return storeServiceDaoImpl; |
| 211 | + } |
| 212 | + |
| 213 | + public void setStoreServiceDaoImpl(IStoreServiceDao storeServiceDaoImpl) { |
| 214 | + this.storeServiceDaoImpl = storeServiceDaoImpl; |
| 215 | + } |
| 216 | +} |
0 commit comments