| | |
| | | "postalCode": "810504", |
| | | "isDefault": "0" |
| | | } |
| | | }, |
| | | "attrs": [{ |
| | | "specCd": "配置的字段ID", |
| | | "value": "具体值" |
| | | }] |
| | | } |
| | | }] |
| | | } |
| | |
| | | public void saveBusinessUserAttr(Map userAttr) throws DAOException; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public void saveUserInfoInstance(Map businessUser); |
| | | |
| | | public void saveUserAttrInstance(Map attrInstance); |
| | |
| | | * @throws DAOException |
| | | */ |
| | | public List<Map> queryUserInfoAttrs(Map info) throws DAOException; |
| | | |
| | | |
| | | /** |
| | | * 保存用户地址信息 |
| | | * Business 过程 |
| | | * @param userAddress 用户地址信息 |
| | | * @throws DAOException |
| | | */ |
| | | public void saveBusinessUserAddress(Map userAddress) throws DAOException; |
| | | |
| | | |
| | | /** |
| | | * 查询用户地址信息 |
| | | * business 过程 |
| | | * @param info b_id |
| | | * @return 查询到的用户地址信息 |
| | | * @throws DAOException |
| | | */ |
| | | public Map queryBusinessUserAddress(Map info) throws DAOException; |
| | | |
| | | /** |
| | | * 保存Business 数据到 Instance |
| | | * @param businessUserAddress 从business 中查出的数据 |
| | | * @throws DAOException 数据处理异常 |
| | | */ |
| | | public void saveUserAddressInstance(Map businessUserAddress) throws DAOException; |
| | | |
| | | |
| | | /** |
| | | * 作废用户信息数据 |
| | | * @param businessUserAddress 用户地址信息 b_id |
| | | * @throws DAOException 数据处理异常 |
| | | */ |
| | | public void updateUserAddressInstance(Map businessUserAddress) throws DAOException; |
| | | } |
| | |
| | | @Override |
| | | public void updateUserInfoInstance(Map businessUser) { |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.updateUserInfoInstance】保存数据入参 : " + JSONObject.toJSONString(businessUser)); |
| | | int saveFlag = sqlSessionTemplate.insert("userServiceDAOImpl.updateUserInfoInstance",businessUser); |
| | | int saveFlag = sqlSessionTemplate.update("userServiceDAOImpl.updateUserInfoInstance",businessUser); |
| | | |
| | | if(saveFlag < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改用户Instance数据失败:"+JSONObject.toJSONString(businessUser)); |
| | |
| | | @Override |
| | | public void updateUserAttrInstance(Map attrInstance) { |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.updateUserAttrInstance】保存数据入参 : " + JSONObject.toJSONString(attrInstance)); |
| | | int saveFlag = sqlSessionTemplate.insert("userServiceDAOImpl.updateUserAttrInstance",attrInstance); |
| | | int saveFlag = sqlSessionTemplate.update("userServiceDAOImpl.updateUserAttrInstance",attrInstance); |
| | | |
| | | if(saveFlag < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改用户Instance数据失败:"+JSONObject.toJSONString(attrInstance)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存用户地址信息 |
| | | * Business 过程 |
| | | * @param userAddress 用户地址信息 |
| | | * @throws DAOException |
| | | */ |
| | | public void saveBusinessUserAddress(Map userAddress) throws DAOException{ |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.saveBusinessUserAddress】保存数据入参 : " + JSONObject.toJSONString(userAddress)); |
| | | int saveFlag = sqlSessionTemplate.insert("userServiceDAOImpl.saveBusinessUserAddress",userAddress); |
| | | |
| | | if(saveFlag < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存用户地址数据失败:"+JSONObject.toJSONString(userAddress)); |
| | | } |
| | | } |
| | | |
| | |
| | | List<Map> userAttrs = sqlSessionTemplate.selectList("userServiceDAOImpl.queryUserInfoAttrs",info); |
| | | return userAttrs; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询用户地址信息 |
| | | * business 过程 |
| | | * @param info b_id |
| | | * @return 查询到的用户地址信息 |
| | | * @throws DAOException |
| | | */ |
| | | public Map queryBusinessUserAddress(Map info) throws DAOException{ |
| | | Assert.notNull(info,"queryBusinessUserAddress 的参数不能为空"); |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.queryBusinessUserAddress】保存数据入参 : " + JSONObject.toJSONString(info)); |
| | | List<Map> users = sqlSessionTemplate.selectList("userServiceDAOImpl.queryBusinessUserAddress",info); |
| | | if(users == null || users.size() == 0){ |
| | | return null; |
| | | } |
| | | return users.get(0); |
| | | } |
| | | |
| | | /** |
| | | * 保存用户地址 Business 数据到 Instance |
| | | * @param businessUserAddress 从business 中查出的数据 |
| | | * @throws DAOException 数据处理异常 |
| | | */ |
| | | public void saveUserAddressInstance(Map businessUserAddress) throws DAOException{ |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.saveUserAddressInstance】保存数据入参 : " + JSONObject.toJSONString(businessUserAddress)); |
| | | int saveFlag = sqlSessionTemplate.insert("userServiceDAOImpl.saveUserAddressInstance",businessUserAddress); |
| | | |
| | | if(saveFlag < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存用户地址Instance数据失败:"+JSONObject.toJSONString(businessUserAddress)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 作废用户地址信息数据 |
| | | * @param businessUserAddress 用户地址信息 b_id |
| | | * @throws DAOException 数据处理异常 |
| | | */ |
| | | public void updateUserAddressInstance(Map businessUserAddress) throws DAOException{ |
| | | LoggerEngine.debug("----【UserServiceDAOImpl.updateUserAddressInstance】保存数据入参 : " + JSONObject.toJSONString(businessUserAddress)); |
| | | int saveFlag = sqlSessionTemplate.update("userServiceDAOImpl.updateUserAddressInstance",businessUserAddress); |
| | | |
| | | if(saveFlag < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改用户Instance数据失败:"+JSONObject.toJSONString(businessUserAddress)); |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.user.listener; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | 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.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.entity.center.Business; |
| | | import com.java110.event.service.BusinessServiceDataFlowEvent; |
| | | import com.java110.event.service.BusinessServiceDataFlowListener; |
| | | import com.java110.user.dao.IUserServiceDao; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 保存 用户信息 侦听 |
| | | * Created by wuxw on 2018/5/18. |
| | | */ |
| | | @Service("saveUserAddress") |
| | | @Transactional |
| | | public class SaveUserAddressListener implements BusinessServiceDataFlowListener{ |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(SaveUserAddressListener.class); |
| | | |
| | | @Autowired |
| | | IUserServiceDao userServiceDaoImpl; |
| | | |
| | | @Override |
| | | public int getOrder() { |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceCode() { |
| | | return ServiceCodeConstant.SERVICE_CODE_SAVE_USER_ADDRESS; |
| | | } |
| | | |
| | | @Override |
| | | public void soService(BusinessServiceDataFlowEvent event) { |
| | | //这里处理业务逻辑数据 |
| | | DataFlowContext dataFlowContext = event.getDataFlowContext(); |
| | | doSaveUserAddress(dataFlowContext); |
| | | } |
| | | |
| | | private void doSaveUserAddress(DataFlowContext dataFlowContext){ |
| | | String businessType = dataFlowContext.getOrder().getBusinessType(); |
| | | Business business = dataFlowContext.getCurrentBusiness(); |
| | | //Assert.hasLength(business.getbId(),"bId 不能为空"); |
| | | // Instance 过程 |
| | | if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(businessType)){ |
| | | //doComplateUserInfo(business); |
| | | doSaveInstanceUserAddress(dataFlowContext,business); |
| | | }else if(StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(businessType)){ // Business过程 |
| | | doSaveBusinessUserAddress(dataFlowContext,business); |
| | | }else if(StatusConstant.REQUEST_BUSINESS_TYPE_DELETE.equals(businessType)){ //撤单过程 |
| | | doDeleteInstanceUserAddress(dataFlowContext,business); |
| | | } |
| | | |
| | | dataFlowContext.setResJson(DataTransactionFactory.createBusinessResponseJson(dataFlowContext,ResponseConstant.RESULT_CODE_SUCCESS,"成功", |
| | | dataFlowContext.getParamOut())); |
| | | } |
| | | |
| | | /** |
| | | * 撤单 |
| | | * @param business |
| | | */ |
| | | private void doDeleteInstanceUserAddress(DataFlowContext dataFlowContext, Business business) { |
| | | |
| | | String bId = business.getbId(); |
| | | //Assert.hasLength(bId,"请求报文中没有包含 bId"); |
| | | Map info = new HashMap(); |
| | | info.put("bId",bId); |
| | | Map userAddress = userServiceDaoImpl.queryBusinessUserAddress(info); |
| | | if(userAddress != null && !userAddress.isEmpty()){ |
| | | info.put("bId",bId); |
| | | info.put("userId",userAddress.get("user_id").toString()); |
| | | info.put("addressId",userAddress.get("address_id").toString()); |
| | | info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| | | userServiceDaoImpl.updateUserAddressInstance(userAddress); |
| | | dataFlowContext.addParamOut("userId",userAddress.get("user_id")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * instance过程 |
| | | * @param business |
| | | */ |
| | | private void doSaveInstanceUserAddress(DataFlowContext dataFlowContext, Business business) { |
| | | |
| | | JSONObject data = business.getDatas(); |
| | | |
| | | Map info = new HashMap(); |
| | | info.put("bId",business.getbId()); |
| | | info.put("operate",StatusConstant.OPERATE_ADD); |
| | | Map businessUserAddress = userServiceDaoImpl.queryBusinessUserAddress(info); |
| | | if( businessUserAddress != null && !businessUserAddress.isEmpty()) { |
| | | userServiceDaoImpl.saveUserAddressInstance(businessUserAddress); |
| | | dataFlowContext.addParamOut("userId",businessUserAddress.get("user_id")); |
| | | return ; |
| | | } |
| | | |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR,"当前数据未找到business 数据"+info); |
| | | } |
| | | |
| | | /** |
| | | * 处理用户地址信息 |
| | | * @param business 业务信息 |
| | | */ |
| | | private void doSaveBusinessUserAddress(DataFlowContext dataFlowContext, Business business) { |
| | | |
| | | JSONObject data = business.getDatas(); |
| | | |
| | | Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| | | |
| | | Assert.jsonObjectHaveKey(data,"businessUserAddress","datas 节点下没有包含 businessUser 节点"); |
| | | |
| | | JSONObject businessUser = data.getJSONObject("businessUserAddress"); |
| | | |
| | | Assert.jsonObjectHaveKey(businessUser,"userId","businessUser 节点下没有包含 userId 节点"); |
| | | |
| | | if(businessUser.getLong("userId") <= 0){ |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR,"用户地址(saveUserAddress)保存失败,userId 不正确"+businessUser.getInteger("userId")); |
| | | } |
| | | dataFlowContext.addParamOut("userId",businessUser.getString("userId")); |
| | | businessUser.put("bId",business.getbId()); |
| | | businessUser.put("operate", StatusConstant.OPERATE_ADD); |
| | | //保存用户信息 |
| | | userServiceDaoImpl.saveBusinessUserAddress(businessUser); |
| | | |
| | | } |
| | | |
| | | public IUserServiceDao getUserServiceDaoImpl() { |
| | | return userServiceDaoImpl; |
| | | } |
| | | |
| | | public void setUserServiceDaoImpl(IUserServiceDao userServiceDaoImpl) { |
| | | this.userServiceDaoImpl = userServiceDaoImpl; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.user.listener; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | 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.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.entity.center.Business; |
| | | import com.java110.event.service.BusinessServiceDataFlowEvent; |
| | | import com.java110.event.service.BusinessServiceDataFlowListener; |
| | | import com.java110.user.dao.IUserServiceDao; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 保存 用户信息 侦听 |
| | | * Created by wuxw on 2018/5/18. |
| | | */ |
| | | @Service("saveUserInfo") |
| | | @Transactional |
| | | public class SaveUserTagListener extends LoggerEngine implements BusinessServiceDataFlowListener{ |
| | | |
| | | @Autowired |
| | | IUserServiceDao userServiceDaoImpl; |
| | | |
| | | @Override |
| | | public int getOrder() { |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceCode() { |
| | | return ServiceCodeConstant.SERVICE_CODE_SAVE_USER_INFO; |
| | | } |
| | | |
| | | @Override |
| | | public void soService(BusinessServiceDataFlowEvent event) { |
| | | //这里处理业务逻辑数据 |
| | | DataFlowContext dataFlowContext = event.getDataFlowContext(); |
| | | doSaveUserInfo(dataFlowContext); |
| | | } |
| | | |
| | | private void doSaveUserInfo(DataFlowContext dataFlowContext){ |
| | | String businessType = dataFlowContext.getOrder().getBusinessType(); |
| | | Business business = dataFlowContext.getCurrentBusiness(); |
| | | //Assert.hasLength(business.getbId(),"bId 不能为空"); |
| | | // Instance 过程 |
| | | if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(businessType)){ |
| | | //doComplateUserInfo(business); |
| | | doSaveInstanceUserInfo(dataFlowContext,business); |
| | | }else if(StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(businessType)){ // Business过程 |
| | | doSaveBusinessUserInfo(dataFlowContext,business); |
| | | }else if(StatusConstant.REQUEST_BUSINESS_TYPE_DELETE.equals(businessType)){ //撤单过程 |
| | | doDeleteInstanceUserInfo(dataFlowContext,business); |
| | | } |
| | | |
| | | dataFlowContext.setResJson(DataTransactionFactory.createBusinessResponseJson(dataFlowContext,ResponseConstant.RESULT_CODE_SUCCESS,"成功", |
| | | dataFlowContext.getParamOut())); |
| | | } |
| | | |
| | | /** |
| | | * 撤单 |
| | | * @param business |
| | | */ |
| | | private void doDeleteInstanceUserInfo(DataFlowContext dataFlowContext,Business business) { |
| | | |
| | | String bId = business.getbId(); |
| | | //Assert.hasLength(bId,"请求报文中没有包含 bId"); |
| | | Map info = new HashMap(); |
| | | info.put("bId",bId); |
| | | Map userInfo = userServiceDaoImpl.queryUserInfo(info); |
| | | if(userInfo != null && !userInfo.isEmpty()){ |
| | | info.put("bId",bId); |
| | | info.put("userId",userInfo.get("user_id").toString()); |
| | | info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| | | userServiceDaoImpl.updateUserInfoInstance(userInfo); |
| | | dataFlowContext.addParamOut("userId",userInfo.get("user_id")); |
| | | } |
| | | |
| | | info.clear(); |
| | | info.put("bId",bId); |
| | | |
| | | List<Map> userAttrs = userServiceDaoImpl.queryUserInfoAttrs(info); |
| | | |
| | | if(userAttrs != null && userAttrs.size() >0){ |
| | | info.put("bId",bId); |
| | | //info.put("userId",userInfo.get("user_id").toString()); |
| | | info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| | | userServiceDaoImpl.updateUserAttrInstance(info); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * instance过程 |
| | | * @param business |
| | | */ |
| | | private void doSaveInstanceUserInfo(DataFlowContext dataFlowContext,Business business) { |
| | | |
| | | JSONObject data = business.getDatas(); |
| | | |
| | | //Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| | | |
| | | //Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点"); |
| | | |
| | | //JSONObject businessUser = data.getJSONObject("businessUser"); |
| | | Map info = new HashMap(); |
| | | info.put("bId",business.getbId()); |
| | | info.put("operate",StatusConstant.OPERATE_ADD); |
| | | Map businessUser = userServiceDaoImpl.queryBusinessUserInfo(info); |
| | | if( businessUser != null && !businessUser.isEmpty()) { |
| | | userServiceDaoImpl.saveUserInfoInstance(businessUser); |
| | | dataFlowContext.addParamOut("userId",businessUser.get("user_id")); |
| | | } |
| | | List<Map> businessUserAttrs = userServiceDaoImpl.queryBusinessUserInfoAttrs(info); |
| | | if(businessUserAttrs != null && businessUserAttrs.size() > 0) { |
| | | userServiceDaoImpl.saveUserAttrInstance(businessUser); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 保存数据至u_user 表中 |
| | | * @param business |
| | | */ |
| | | private void doComplateUserInfo(DataFlowContext dataFlowContext,Business business) { |
| | | String bId = business.getbId(); |
| | | Map paramIn = new HashMap(); |
| | | paramIn.put("bId",bId); |
| | | paramIn.put("statusCd",StatusConstant.STATUS_CD_VALID); |
| | | userServiceDaoImpl.updateUserInfoInstance(paramIn); |
| | | userServiceDaoImpl.updateUserAttrInstance(paramIn); |
| | | } |
| | | |
| | | /** |
| | | * 处理用户信息 |
| | | * @param business |
| | | */ |
| | | private void doSaveBusinessUserInfo(DataFlowContext dataFlowContext,Business business) { |
| | | |
| | | JSONObject data = business.getDatas(); |
| | | |
| | | Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| | | |
| | | Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点"); |
| | | |
| | | JSONObject businessUser = data.getJSONObject("businessUser"); |
| | | |
| | | Assert.jsonObjectHaveKey(businessUser,"userId","businessUser 节点下没有包含 userId 节点"); |
| | | |
| | | if(businessUser.getInteger("userId") < 0){ |
| | | //生成userId |
| | | String userId = GenerateCodeFactory.getUserId(); |
| | | businessUser.put("userId",userId); |
| | | } |
| | | dataFlowContext.addParamOut("userId",businessUser.getString("userId")); |
| | | businessUser.put("bId",business.getbId()); |
| | | businessUser.put("operate", StatusConstant.OPERATE_ADD); |
| | | //保存用户信息 |
| | | userServiceDaoImpl.saveBusinessUserInfo(businessUser); |
| | | |
| | | if(businessUser.containsKey("businessUserAttr")){ |
| | | doSaveUserAttrs(business); |
| | | } |
| | | |
| | | //userServiceDaoImpl.saveUserInfoInstance(businessUser); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void doSaveUserAttrs(Business business){ |
| | | JSONObject data = business.getDatas(); |
| | | JSONObject businessUser = data.getJSONObject("businessUser"); |
| | | JSONArray businessUserAttrs = businessUser.getJSONArray("businessUserAttr"); |
| | | for(int userAttrIndex = 0 ; userAttrIndex < businessUserAttrs.size();userAttrIndex ++){ |
| | | JSONObject userAttr = businessUserAttrs.getJSONObject(userAttrIndex); |
| | | Assert.jsonObjectHaveKey(userAttr,"attrId","businessUserAttr 节点下没有包含 attrId 节点"); |
| | | |
| | | if(userAttr.getInteger("attrId") < 0){ |
| | | String attrId = GenerateCodeFactory.getAttrId(); |
| | | userAttr.put("attrId",attrId); |
| | | } |
| | | |
| | | userAttr.put("bId",business.getbId()); |
| | | userAttr.put("userId",businessUser.getString("userId")); |
| | | userAttr.put("operate", StatusConstant.OPERATE_ADD); |
| | | |
| | | userServiceDaoImpl.saveBusinessUserAttr(userAttr); |
| | | } |
| | | |
| | | /*JSONObject attrInstance = new JSONObject(); |
| | | attrInstance.put("bId",business.getbId()); |
| | | userServiceDaoImpl.saveUserAttrInstance(attrInstance);*/ |
| | | } |
| | | |
| | | public IUserServiceDao getUserServiceDaoImpl() { |
| | | return userServiceDaoImpl; |
| | | } |
| | | |
| | | public void setUserServiceDaoImpl(IUserServiceDao userServiceDaoImpl) { |
| | | this.userServiceDaoImpl = userServiceDaoImpl; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public static final String SERVICE_CODE_SAVE_USER_INFO = "save.user.info"; |
| | | |
| | | /** |
| | | * 保存用户地址信息 |
| | | */ |
| | | public static final String SERVICE_CODE_SAVE_USER_ADDRESS = "save.user.address"; |
| | | |
| | | /** |
| | | * 用户打标 |
| | | */ |
| | | public static final String SERVICE_CODE_SAVE_USER_TAG = "save.user.tag"; |
| | | |
| | | |
| | | |
| | | |
| New file |
| | |
| | | package com.java110.common.exception; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | import java.io.PrintStream; |
| | | import java.io.PrintWriter; |
| | | |
| | | /** |
| | | * 侦听执行异常 |
| | | * Created by wuxw on 2018/4/14. |
| | | */ |
| | | public class ListenerExecuteException extends RuntimeException { |
| | | |
| | | |
| | | private Result result; |
| | | private Throwable cause = this; |
| | | |
| | | public ListenerExecuteException(){} |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param result 返回值 |
| | | * @param cause 异常堆栈 |
| | | */ |
| | | public ListenerExecuteException(Result result, Throwable cause) { |
| | | super(result.getMsg(), cause); |
| | | this.result = result; |
| | | } |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param code 返回码 |
| | | * @param msg 错误消息 |
| | | */ |
| | | public ListenerExecuteException(int code, String msg) { |
| | | super(msg); |
| | | this.result = new Result(code, msg); |
| | | } |
| | | |
| | | public ListenerExecuteException(String code, String msg) { |
| | | super(msg); |
| | | this.result = new Result(code, msg); |
| | | } |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param result 返回值 |
| | | * @param detail 具体的返回消息 |
| | | */ |
| | | public ListenerExecuteException(Result result, String detail) { |
| | | super(result.getMsg() + "," + detail); |
| | | this.result = new Result(result.getCode(), result.getMsg() + "," + detail); |
| | | } |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param result 返回值 |
| | | * @param detail 具体的返回消息 |
| | | * @param cause 异常堆栈 |
| | | */ |
| | | public ListenerExecuteException(Result result, String detail, Throwable cause) { |
| | | super(result.getMsg() + "," + detail, cause); |
| | | this.result = new Result(result.getCode(), result.getMsg() + "," + detail); |
| | | } |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param code 返回码 |
| | | * @param msg 返回消息 |
| | | * @param cause 异常堆栈 |
| | | */ |
| | | public ListenerExecuteException(int code, String msg, Throwable cause) { |
| | | super(msg, cause); |
| | | |
| | | if(cause != null) { |
| | | if(cause.getCause() != null) { |
| | | msg += " cause:" + ExceptionUtils.populateExecption(cause.getCause(), 500); |
| | | } |
| | | msg += " StackTrace:"+ExceptionUtils.populateExecption(cause, 500); |
| | | } |
| | | this.result = new Result(code, msg); |
| | | } |
| | | |
| | | /** |
| | | * 构造方法 |
| | | * @param code 返回码 |
| | | * @param cause 异常堆栈 |
| | | */ |
| | | public ListenerExecuteException(int code, Throwable cause) { |
| | | super(cause); |
| | | String msg = ""; |
| | | |
| | | if(cause != null) { |
| | | if(cause.getCause() != null) { |
| | | msg += " cause:" + ExceptionUtils.populateExecption(cause.getCause(), 500); |
| | | } |
| | | msg += " StackTrace:"+ExceptionUtils.populateExecption(cause, 500); |
| | | } |
| | | this.result = new Result(code, msg); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * TODO 简单描述该方法的实现功能(可选). |
| | | * @see Throwable#getCause() |
| | | */ |
| | | public synchronized Throwable getCause() { |
| | | return (cause==this ? super.getCause() : cause); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 返回异常消息 |
| | | * @return 异常消息 |
| | | */ |
| | | @Override |
| | | public String getMessage() { |
| | | return ExceptionUtils.buildMessage(super.getMessage(), getCause()); |
| | | } |
| | | |
| | | /** |
| | | * 异常 |
| | | * @return |
| | | */ |
| | | public String toJsonString() { |
| | | JSONObject exceptionJson = JSONObject.parseObject("{\"exception\":{}"); |
| | | JSONObject exceptionJsonObj = exceptionJson.getJSONObject("exception"); |
| | | |
| | | if (getResult() != null) |
| | | exceptionJsonObj.putAll(JSONObject.parseObject(result.toString())); |
| | | |
| | | exceptionJsonObj.put("exceptionTrace",getMessage()); |
| | | |
| | | return exceptionJsonObj.toString(); |
| | | } |
| | | @Override |
| | | public void printStackTrace(PrintStream ps) { |
| | | ps.print("<exception>"); |
| | | if (getResult() != null) { |
| | | ps.print(result.toString()); |
| | | } |
| | | ps.append("<exceptionTrace>"); |
| | | |
| | | Throwable cause = getCause(); |
| | | if (cause == null) { |
| | | super.printStackTrace(ps); |
| | | } else { |
| | | ps.println(this); |
| | | ps.print("Caused by: "); |
| | | cause.printStackTrace(ps); |
| | | } |
| | | ps.append("</exceptionTrace>"); |
| | | ps.println("</exception>"); |
| | | } |
| | | |
| | | @Override |
| | | public void printStackTrace(PrintWriter pw) { |
| | | pw.print("<exception>"); |
| | | if (getResult() != null) { |
| | | pw.print(result.toString()); |
| | | } |
| | | pw.append("<exceptionTrace>"); |
| | | |
| | | Throwable cause = getCause(); |
| | | if (cause == null) { |
| | | super.printStackTrace(pw); |
| | | } else { |
| | | pw.println(this); |
| | | pw.print("Caused by: "); |
| | | cause.printStackTrace(pw); |
| | | } |
| | | pw.append("</exceptionTrace>"); |
| | | pw.println("</exception>"); |
| | | } |
| | | |
| | | /** |
| | | * 返回异常值 |
| | | * @return 异常值对象 |
| | | */ |
| | | public Result getResult() { |
| | | return result; |
| | | } |
| | | |
| | | public void setResult(Result result) { |
| | | this.result = result; |
| | | } |
| | | |
| | | } |
| | |
| | | java110.UserService.listeners=\ |
| | | saveUserInfo,\ |
| | | deleteUserInfo,\ |
| | | updateUserInfo |
| | | updateUserInfo,\ |
| | | saveUserAddress,\ |
| | | saveUserTag |
| | |
| | | </if> |
| | | </update> |
| | | |
| | | |
| | | |
| | | <!-- 查询用户信息 Business --> |
| | | <select id="queryBusinessUserInfo" parameterType="map" resultType="map"> |
| | | select u.user_id,u.name,u.email,u.address,u.password,u.location_cd, |
| | |
| | | </select> |
| | | |
| | | |
| | | <!--保存用户地址信息 add by wuxw 2018-06-29 --> |
| | | <insert id="saveBusinessUserAddress" parameterType="map"> |
| | | insert into business_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,operate) |
| | | values(#{addressId},#{b_id},#{userId},#{tel},#{postalCode},#{address},#{isDefault},#{operate}) |
| | | </insert> |
| | | |
| | | |
| | | <!-- 查询用户地址信息 add by wuxw 2018-06-29--> |
| | | <select id="queryBusinessUserAddress" parameterType="map" resultType="map"> |
| | | select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,ua.operate |
| | | from business_user_address ua where 1 = 1 |
| | | <if test="operate != null and operate != ''"> |
| | | and ua.operate = #{operate} |
| | | </if> |
| | | <if test="bId != null and bId !=''"> |
| | | and ua.b_id = #{bId} |
| | | </if> |
| | | <if test="userId != null and userId != ''"> |
| | | and ua.user_id = #{userId} |
| | | </if> |
| | | </select> |
| | | |
| | | <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 --> |
| | | <insert id="saveUserAddressInstance" parameterType="map"> |
| | | insert into u_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,status_cd) |
| | | select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,'0' |
| | | from business_user_address ua where 1 = 1 |
| | | ua.operate = 'ADD' and ua.b_id=#{b_id} |
| | | </insert> |
| | | |
| | | <!-- 作废用户地址信息数据 add by wuxw 2018-06-29--> |
| | | <update id="updateUserAddressInstance" parameterType="map"> |
| | | update u_user_address ua set ua.status_cd = #{statusCd} where 1 = 1 |
| | | <if test="bId != null and bId != ''"> |
| | | and ua.b_id = #{bId} |
| | | </if> |
| | | <if test="userId != null and userId !=''"> |
| | | and ua.user_id = #{userId} |
| | | </if> |
| | | <if test="addressId != null and addressId != ''"> |
| | | and ua.address_id = #{addressId} |
| | | </if> |
| | | </update> |
| | | </mapper> |