|
| 1 | +package com.java110.property.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.exception.ListenerExecuteException; |
| 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.entity.center.Business; |
| 13 | +import com.java110.property.dao.IPropertyServiceDao; |
| 14 | +import org.slf4j.Logger; |
| 15 | +import org.slf4j.LoggerFactory; |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; |
| 17 | +import org.springframework.transaction.annotation.Transactional; |
| 18 | + |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +/** |
| 24 | + * 删除物业信息 侦听 |
| 25 | + * |
| 26 | + * 处理节点 |
| 27 | + * 1、businessPropertyHouse:{} 物业住户信息节点 |
| 28 | + * 2、businessPropertyAttr:[{}] 物业属性信息节点 |
| 29 | + * Created by wuxw on 2018/5/18. |
| 30 | + */ |
| 31 | +@Java110Listener("deletePropertyAttrListener") |
| 32 | +@Transactional |
| 33 | +public class DeletePropertyAttrListener extends AbstractPropertyBusinessServiceDataFlowListener { |
| 34 | + |
| 35 | + private final static Logger logger = LoggerFactory.getLogger(DeletePropertyAttrListener.class); |
| 36 | + @Autowired |
| 37 | + IPropertyServiceDao propertyServiceDaoImpl; |
| 38 | + |
| 39 | + @Override |
| 40 | + public int getOrder() { |
| 41 | + return 3; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public String getServiceCode() { |
| 46 | + return ServiceCodeConstant.SERVICE_CODE_DELETE_PROPERTY_ATTR; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * 根据删除信息 查出Instance表中数据 保存至business表 (状态写DEL) 方便撤单时直接更新回去 |
| 51 | + * @param dataFlowContext 数据对象 |
| 52 | + * @param business 当前业务对象 |
| 53 | + */ |
| 54 | + @Override |
| 55 | + protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) { |
| 56 | + JSONObject data = business.getDatas(); |
| 57 | + |
| 58 | + Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); |
| 59 | + |
| 60 | + if(data.containsKey("businessPropertyAttr")){ |
| 61 | + JSONArray businessPropertyAttrs = data.getJSONArray("businessPropertyAttr"); |
| 62 | + doSaveBusinessPropertyAttrs(business,businessPropertyAttrs); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * 删除 instance数据 |
| 68 | + * @param dataFlowContext 数据对象 |
| 69 | + * @param business 当前业务对象 |
| 70 | + */ |
| 71 | + @Override |
| 72 | + protected void doBusinessToInstance(DataFlowContext dataFlowContext, Business business) { |
| 73 | + String bId = business.getbId(); |
| 74 | + //Assert.hasLength(bId,"请求报文中没有包含 bId"); |
| 75 | + |
| 76 | + //物业信息 |
| 77 | + Map info = new HashMap(); |
| 78 | + info.put("bId",business.getbId()); |
| 79 | + info.put("operate",StatusConstant.OPERATE_DEL); |
| 80 | + |
| 81 | + //物业属性 |
| 82 | + List<Map> businessPropertyAttrs = propertyServiceDaoImpl.getBusinessPropertyAttrs(info); |
| 83 | + if(businessPropertyAttrs != null && businessPropertyAttrs.size() > 0) { |
| 84 | + for(Map businessPropertyAttr : businessPropertyAttrs) { |
| 85 | + flushBusinessPropertyAttr(businessPropertyAttr,StatusConstant.STATUS_CD_INVALID); |
| 86 | + propertyServiceDaoImpl.updatePropertyAttrInstance(businessPropertyAttr); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * 撤单 |
| 93 | + * 从business表中查询到DEL的数据 将instance中的数据更新回来 |
| 94 | + * @param dataFlowContext 数据对象 |
| 95 | + * @param business 当前业务对象 |
| 96 | + */ |
| 97 | + @Override |
| 98 | + protected void doRecover(DataFlowContext dataFlowContext, Business business) { |
| 99 | + String bId = business.getbId(); |
| 100 | + //Assert.hasLength(bId,"请求报文中没有包含 bId"); |
| 101 | + Map info = new HashMap(); |
| 102 | + info.put("bId",bId); |
| 103 | + info.put("statusCd",StatusConstant.STATUS_CD_INVALID); |
| 104 | + |
| 105 | + Map delInfo = new HashMap(); |
| 106 | + delInfo.put("bId",business.getbId()); |
| 107 | + delInfo.put("operate",StatusConstant.OPERATE_DEL); |
| 108 | + |
| 109 | + //物业属性 |
| 110 | + List<Map> propertyAttrs = propertyServiceDaoImpl.getPropertyAttrs(info); |
| 111 | + if(propertyAttrs != null && propertyAttrs.size()>0){ |
| 112 | + |
| 113 | + List<Map> businessPropertyAttrs = propertyServiceDaoImpl.getBusinessPropertyAttrs(delInfo); |
| 114 | + //除非程序出错了,这里不会为空 |
| 115 | + if(businessPropertyAttrs == null || businessPropertyAttrs.size() ==0 ){ |
| 116 | + throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_INNER_ERROR,"撤单失败(property_attr),程序内部异常,请检查! "+delInfo); |
| 117 | + } |
| 118 | + for(Map businessPropertyAttr : businessPropertyAttrs) { |
| 119 | + flushBusinessPropertyAttr(businessPropertyAttr,StatusConstant.STATUS_CD_VALID); |
| 120 | + propertyServiceDaoImpl.updatePropertyAttrInstance(businessPropertyAttr); |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + /** |
| 128 | + * 保存物业属性信息 |
| 129 | + * @param business 当前业务 |
| 130 | + * @param businessPropertyAttrs 物业属性 |
| 131 | + */ |
| 132 | + private void doSaveBusinessPropertyAttrs(Business business,JSONArray businessPropertyAttrs){ |
| 133 | + JSONObject data = business.getDatas(); |
| 134 | + |
| 135 | + for(int propertyAttrIndex = 0 ; propertyAttrIndex < businessPropertyAttrs.size();propertyAttrIndex ++){ |
| 136 | + JSONObject propertyAttr = businessPropertyAttrs.getJSONObject(propertyAttrIndex); |
| 137 | + Assert.jsonObjectHaveKey(propertyAttr,"attrId","businessPropertyAttr 节点下没有包含 attrId 节点"); |
| 138 | + if(propertyAttr.getString("attrId").startsWith("-")){ |
| 139 | + throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR,"attrId 错误,不能自动生成(必须已经存在的attrId)"+propertyAttr); |
| 140 | + } |
| 141 | + |
| 142 | + autoSaveDelBusinessPropertyAttr(business,propertyAttr); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + public IPropertyServiceDao getPropertyServiceDaoImpl() { |
| 147 | + return propertyServiceDaoImpl; |
| 148 | + } |
| 149 | + |
| 150 | + public void setPropertyServiceDaoImpl(IPropertyServiceDao propertyServiceDaoImpl) { |
| 151 | + this.propertyServiceDaoImpl = propertyServiceDaoImpl; |
| 152 | + } |
| 153 | +} |
0 commit comments