package com.java110.api.listener.owner; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.java110.api.listener.AbstractServiceApiDataFlowListener; import com.java110.core.smo.file.IFileInnerServiceSMO; import com.java110.dto.file.FileDto; import com.java110.utils.cache.MappingCache; import com.java110.utils.constant.*; import com.java110.utils.exception.ListenerExecuteException; import com.java110.utils.util.Assert; import com.java110.utils.util.DateUtil; import com.java110.core.annotation.Java110Listener; import com.java110.core.context.DataFlowContext; import com.java110.core.factory.GenerateCodeFactory; import com.java110.entity.center.AppService; import com.java110.event.service.api.ServiceDataFlowEvent; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import javax.activation.FileDataSource; import javax.xml.ws.soap.Addressing; /** * @ClassName SaveOwnerListener * @Description 保存小区楼信息 * @Author wuxw * @Date 2019/4/26 14:51 * @Version 1.0 * add by wuxw 2019/4/26 **/ @Java110Listener("saveOwnerListener") public class SaveOwnerListener extends AbstractServiceApiDataFlowListener { private static final int DEFAULT_SEQ_COMMUNITY_MEMBER = 2; @Autowired private IFileInnerServiceSMO fileInnerServiceSMOImpl; private static Logger logger = LoggerFactory.getLogger(SaveOwnerListener.class); @Override public String getServiceCode() { return ServiceCodeConstant.SERVICE_CODE_SAVE_OWNER; } @Override public HttpMethod getHttpMethod() { return HttpMethod.POST; } @Override public void soService(ServiceDataFlowEvent event) { logger.debug("ServiceDataFlowEvent : {}", event); DataFlowContext dataFlowContext = event.getDataFlowContext(); AppService service = event.getAppService(); String paramIn = dataFlowContext.getReqData(); //校验数据 validate(paramIn); JSONObject paramObj = JSONObject.parseObject(paramIn); HttpHeaders header = new HttpHeaders(); dataFlowContext.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD, "D"); JSONArray businesses = new JSONArray(); //生成memberId generateMemberId(paramObj); //添加小区楼 businesses.add(addOwner(paramObj)); if ("1001".equals(paramObj.getString("ownerTypeCd"))) { //小区楼添加到小区中 businesses.add(addCommunityMember(paramObj)); } //有房屋信息,则直接绑定房屋和 业主的关系 if (paramObj.containsKey("roomId")) { //添加单元信息 businesses.add(sellRoom(paramObj, dataFlowContext)); //添加物业费用信息 businesses.add(addPropertyFee(paramObj, dataFlowContext)); } if (paramObj.containsKey("ownerPhoto") && !StringUtils.isEmpty(paramObj.getString("ownerPhoto"))) { FileDto fileDto = new FileDto(); fileDto.setFileId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id)); fileDto.setFileName(fileDto.getFileId()); fileDto.setContext(paramObj.getString("ownerPhoto")); fileDto.setSuffix("jpeg"); fileDto.setCommunityId(paramObj.getString("communityId")); if (fileInnerServiceSMOImpl.saveFile(fileDto) < 1) { throw new ListenerExecuteException(ResponseConstant.RESULT_PARAM_ERROR, "保存文件出错"); } paramObj.put("ownerPhotoId", fileDto.getFileId()); businesses.add(addOwnerPhoto(paramObj, dataFlowContext)); } /*if ("ON".equals(MappingCache.getValue("SAVE_MACHINE_TRANSLATE_FLAG"))) { addMachineTranslate(paramObj, dataFlowContext); }*/ JSONObject paramInObj = super.restToCenterProtocol(businesses, dataFlowContext.getRequestCurrentHeaders()); //将 rest header 信息传递到下层服务中去 super.freshHttpHeader(header, dataFlowContext.getRequestCurrentHeaders()); ResponseEntity responseEntity = this.callService(dataFlowContext, service.getServiceCode(), paramInObj); dataFlowContext.setResponseEntity(responseEntity); } /** * 生成小区楼ID * * @param paramObj 请求入参数据 */ private void generateMemberId(JSONObject paramObj) { String memberId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_ownerId); paramObj.put("memberId", memberId); if (!paramObj.containsKey("ownerId") || "1001".equals(paramObj.getString("ownerTypeCd"))) { paramObj.put("ownerId", memberId); } } /** * 添加小区楼信息 *

* * name:'', * * age:'', * * link:'', * * sex:'', * * remark:'' * * @param paramInJson 接口调用放传入入参 * @return 订单服务能够接受的报文 */ private JSONObject addOwner(JSONObject paramInJson) { JSONObject business = JSONObject.parseObject("{\"datas\":{}}"); business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_OWNER_INFO); business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ); business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S); JSONObject businessOwner = new JSONObject(); businessOwner.putAll(paramInJson); business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessOwner", businessOwner); return business; } /** * 添加小区成员 * * @param paramInJson 组装 楼小区关系 * @return 小区成员信息 */ private JSONObject addCommunityMember(JSONObject paramInJson) { JSONObject business = JSONObject.parseObject("{\"datas\":{}}"); business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_MEMBER_JOINED_COMMUNITY); business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ_COMMUNITY_MEMBER); business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S); JSONObject businessCommunityMember = new JSONObject(); businessCommunityMember.put("communityMemberId", "-1"); businessCommunityMember.put("communityId", paramInJson.getString("communityId")); businessCommunityMember.put("memberId", paramInJson.getString("ownerId")); businessCommunityMember.put("memberTypeCd", CommunityMemberTypeConstant.OWNER); businessCommunityMember.put("auditStatusCd", StateConstant.AGREE_AUDIT); business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessCommunityMember", businessCommunityMember); return business; } /** * 售卖房屋信息 * * @param paramInJson 接口调用放传入入参 * @param dataFlowContext 数据上下文 * @return 订单服务能够接受的报文 */ private JSONObject sellRoom(JSONObject paramInJson, DataFlowContext dataFlowContext) { JSONObject business = JSONObject.parseObject("{\"datas\":{}}"); business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_OWNER_ROOM_REL); business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ); business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S); JSONObject businessUnit = new JSONObject(); businessUnit.putAll(paramInJson); businessUnit.put("relId", "-1"); businessUnit.put("userId", dataFlowContext.getRequestCurrentHeaders().get(CommonConstant.HTTP_USER_ID)); business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessOwnerRoomRel", businessUnit); return business; } /** * 添加物业费用 * * @param paramInJson 接口调用放传入入参 * @param dataFlowContext 数据上下文 * @return 订单服务能够接受的报文 */ private JSONObject addPropertyFee(JSONObject paramInJson, DataFlowContext dataFlowContext) { JSONObject business = JSONObject.parseObject("{\"datas\":{}}"); business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_FEE_INFO); business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ + 1); business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S); JSONObject businessUnit = new JSONObject(); businessUnit.put("feeId", "-1"); businessUnit.put("feeTypeCd", FeeTypeConstant.FEE_TYPE_PROPERTY); businessUnit.put("incomeObjId", paramInJson.getString("storeId")); businessUnit.put("amount", "-1.00"); businessUnit.put("startTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A)); businessUnit.put("endTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A)); businessUnit.put("communityId", paramInJson.getString("communityId")); businessUnit.put("payerObjId", paramInJson.getString("roomId")); businessUnit.put("userId", dataFlowContext.getRequestCurrentHeaders().get(CommonConstant.HTTP_USER_ID)); business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessFee", businessUnit); return business; } /** * 添加物业费用 * * @param paramInJson 接口调用放传入入参 * @param dataFlowContext 数据上下文 * @return 订单服务能够接受的报文 */ private JSONObject addOwnerPhoto(JSONObject paramInJson, DataFlowContext dataFlowContext) { JSONObject business = JSONObject.parseObject("{\"datas\":{}}"); business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_FILE_REL); business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ + 2); business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S); JSONObject businessUnit = new JSONObject(); businessUnit.put("fileRelId", "-1"); businessUnit.put("relTypeCd", "10000"); businessUnit.put("saveWay", "table"); businessUnit.put("objId", paramInJson.getString("memberId")); businessUnit.put("fileRealName", paramInJson.getString("ownerPhotoId")); businessUnit.put("fileSaveName", paramInJson.getString("ownerPhotoId")); business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessFileRel", businessUnit); return business; } /** * 数据校验 *

* name:'', * age:'', * link:'', * sex:'', * remark:'' * * @param paramIn "communityId": "7020181217000001", * "memberId": "3456789", * "memberTypeCd": "390001200001" */ private void validate(String paramIn) { Assert.jsonObjectHaveKey(paramIn, "name", "请求报文中未包含name"); Assert.jsonObjectHaveKey(paramIn, "userId", "请求报文中未包含userId"); Assert.jsonObjectHaveKey(paramIn, "age", "请求报文中未包含age"); Assert.jsonObjectHaveKey(paramIn, "link", "请求报文中未包含link"); Assert.jsonObjectHaveKey(paramIn, "sex", "请求报文中未包含sex"); Assert.jsonObjectHaveKey(paramIn, "ownerTypeCd", "请求报文中未包含sex"); Assert.jsonObjectHaveKey(paramIn, "communityId", "请求报文中未包含communityId"); Assert.jsonObjectHaveKey(paramIn, "idCard", "请求报文中未包含身份证号"); JSONObject paramObj = JSONObject.parseObject(paramIn); if (paramObj.containsKey("roomId")) { Assert.jsonObjectHaveKey(paramObj, "state", "请求报文中未包含state节点"); Assert.jsonObjectHaveKey(paramObj, "storeId", "请求报文中未包含storeId节点"); Assert.hasLength(paramObj.getString("roomId"), "roomId不能为空"); Assert.hasLength(paramObj.getString("state"), "state不能为空"); Assert.hasLength(paramObj.getString("storeId"), "storeId不能为空"); } } @Override public int getOrder() { return 0; } public IFileInnerServiceSMO getFileInnerServiceSMOImpl() { return fileInnerServiceSMOImpl; } public void setFileInnerServiceSMOImpl(IFileInnerServiceSMO fileInnerServiceSMOImpl) { this.fileInnerServiceSMOImpl = fileInnerServiceSMOImpl; } }