|
|
@@ -0,0 +1,297 @@
|
|
|
+package com.java110.api.listener.fee;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.java110.api.listener.AbstractServiceApiDataFlowListener;
|
|
|
+import com.java110.core.annotation.Java110Listener;
|
|
|
+import com.java110.core.context.DataFlowContext;
|
|
|
+import com.java110.core.smo.fee.IFeeConfigInnerServiceSMO;
|
|
|
+import com.java110.core.smo.fee.IFeeInnerServiceSMO;
|
|
|
+import com.java110.core.smo.hardwareAdapation.ICarInoutInnerServiceSMO;
|
|
|
+import com.java110.core.smo.room.IRoomInnerServiceSMO;
|
|
|
+import com.java110.dto.FeeConfigDto;
|
|
|
+import com.java110.dto.FeeDto;
|
|
|
+import com.java110.dto.RoomDto;
|
|
|
+import com.java110.dto.hardwareAdapation.CarInoutDto;
|
|
|
+import com.java110.entity.center.AppService;
|
|
|
+import com.java110.entity.order.Orders;
|
|
|
+import com.java110.event.service.api.ServiceDataFlowEvent;
|
|
|
+import com.java110.utils.constant.BusinessTypeConstant;
|
|
|
+import com.java110.utils.constant.CommonConstant;
|
|
|
+import com.java110.utils.constant.FeeTypeConstant;
|
|
|
+import com.java110.utils.constant.ResponseConstant;
|
|
|
+import com.java110.utils.constant.ServiceCodeConstant;
|
|
|
+import com.java110.utils.exception.ListenerExecuteException;
|
|
|
+import com.java110.utils.util.Assert;
|
|
|
+import com.java110.utils.util.BeanConvertUtil;
|
|
|
+import com.java110.utils.util.DateUtil;
|
|
|
+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.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName PayFeeListener
|
|
|
+ * @Description TODO 预交费(临时停车费)侦听
|
|
|
+ * @Author wuxw
|
|
|
+ * @Date 2019/6/3 13:46
|
|
|
+ * @Version 1.0
|
|
|
+ * add by wuxw 2019/6/3
|
|
|
+ **/
|
|
|
+@Java110Listener("payFeePreTempCarInoutListener")
|
|
|
+public class PayFeePreTempCarInoutListener extends AbstractServiceApiDataFlowListener {
|
|
|
+
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(PayFeePreTempCarInoutListener.class);
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFeeInnerServiceSMO feeInnerServiceSMOImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICarInoutInnerServiceSMO carInoutInnerServiceSMOImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getServiceCode() {
|
|
|
+ return ServiceCodeConstant.SERVICE_CODE_PAY_FEE_PRE_TEMP_CAR_INOUT;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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();
|
|
|
+
|
|
|
+ //添加单元信息
|
|
|
+ businesses.add(addFeeDetail(paramObj, dataFlowContext));
|
|
|
+ businesses.add(modifyFee(paramObj, dataFlowContext));
|
|
|
+ businesses.add(modifyCarInout(paramObj, dataFlowContext));
|
|
|
+
|
|
|
+ JSONObject paramInObj = super.restToCenterProtocol(businesses, dataFlowContext.getRequestCurrentHeaders());
|
|
|
+
|
|
|
+ //将 rest header 信息传递到下层服务中去
|
|
|
+ super.freshHttpHeader(header, dataFlowContext.getRequestCurrentHeaders());
|
|
|
+
|
|
|
+ ResponseEntity<String> responseEntity = this.callService(dataFlowContext, service.getServiceCode(), paramInObj);
|
|
|
+ if (responseEntity.getStatusCode() != HttpStatus.OK) {
|
|
|
+ dataFlowContext.setResponseEntity(responseEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ paramOut.put("receivableAmount", paramObj.getString("receivableAmount"));
|
|
|
+
|
|
|
+ responseEntity = new ResponseEntity<>(paramOut.toJSONString(), HttpStatus.OK);
|
|
|
+ dataFlowContext.setResponseEntity(responseEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject modifyCarInout(JSONObject reqJson, DataFlowContext context) {
|
|
|
+
|
|
|
+ FeeDto feeDto = (FeeDto) reqJson.get("feeInfo");
|
|
|
+ CarInoutDto tempCarInoutDto = new CarInoutDto();
|
|
|
+ tempCarInoutDto.setCommunityId(reqJson.getString("communityId"));
|
|
|
+ tempCarInoutDto.setInoutId(feeDto.getPayerObjId());
|
|
|
+ List<CarInoutDto> carInoutDtos = carInoutInnerServiceSMOImpl.queryCarInouts(tempCarInoutDto);
|
|
|
+
|
|
|
+ Assert.listOnlyOne(carInoutDtos, "根据费用信息反差车辆进场记录未查到 或查到多条");
|
|
|
+
|
|
|
+ CarInoutDto carInoutDto = carInoutDtos.get(0);
|
|
|
+ JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
|
|
|
+ business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_UPDATE_CAR_INOUT);
|
|
|
+ business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
|
|
|
+ business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
|
|
|
+ JSONObject businessCarInout = new JSONObject();
|
|
|
+ businessCarInout.putAll(BeanConvertUtil.beanCovertMap(carInoutDto));
|
|
|
+ businessCarInout.put("state", "100400");
|
|
|
+ //计算 应收金额
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessCarInout", businessCarInout);
|
|
|
+ return business;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷入order信息
|
|
|
+ *
|
|
|
+ * @param orders 订单信息
|
|
|
+ * @param headers 头部信息
|
|
|
+ */
|
|
|
+ protected void freshOrderProtocol(JSONObject orders, Map<String, String> headers) {
|
|
|
+ super.freshOrderProtocol(orders, headers);
|
|
|
+ orders.put("orderProcess", Orders.ORDER_PROCESS_ORDER_PRE_SUBMIT);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加费用明细信息
|
|
|
+ *
|
|
|
+ * @param paramInJson 接口调用放传入入参
|
|
|
+ * @param dataFlowContext 数据上下文
|
|
|
+ * @return 订单服务能够接受的报文
|
|
|
+ */
|
|
|
+ private JSONObject addFeeDetail(JSONObject paramInJson, DataFlowContext dataFlowContext) {
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
|
|
|
+ business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_FEE_DETAIL);
|
|
|
+ business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
|
|
|
+ business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
|
|
|
+ JSONObject businessFeeDetail = new JSONObject();
|
|
|
+ businessFeeDetail.putAll(paramInJson);
|
|
|
+ businessFeeDetail.put("detailId", "-1");
|
|
|
+ businessFeeDetail.put("primeRate", "1.00");
|
|
|
+ //计算 应收金额
|
|
|
+ FeeDto feeDto = new FeeDto();
|
|
|
+ feeDto.setFeeId(paramInJson.getString("feeId"));
|
|
|
+ feeDto.setCommunityId(paramInJson.getString("communityId"));
|
|
|
+ List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto);
|
|
|
+ if (feeDtos == null || feeDtos.size() != 1) {
|
|
|
+ throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "查询费用信息失败,未查到数据或查到多条数据");
|
|
|
+ }
|
|
|
+ feeDto = feeDtos.get(0);
|
|
|
+ paramInJson.put("feeInfo", feeDto);
|
|
|
+ FeeConfigDto feeConfigDto = new FeeConfigDto();
|
|
|
+ feeConfigDto.setFeeTypeCd(feeDto.getFeeTypeCd());
|
|
|
+ feeConfigDto.setCommunityId(feeDto.getCommunityId());
|
|
|
+ List<FeeConfigDto> feeConfigDtos = feeConfigInnerServiceSMOImpl.queryFeeConfigs(feeConfigDto);
|
|
|
+ if (feeConfigDtos == null || feeConfigDtos.size() != 1) {
|
|
|
+ throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "未查到费用配置信息,查询多条数据");
|
|
|
+ }
|
|
|
+ feeConfigDto = feeConfigDtos.get(0);
|
|
|
+ Date nowTime = new Date();
|
|
|
+
|
|
|
+ long diff = nowTime.getTime() - feeDto.getStartTime().getTime();
|
|
|
+ long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
|
|
|
+ long nh = 1000 * 60 * 60;// 一小时的毫秒数
|
|
|
+ long nm = 1000 * 60;// 一分钟的毫秒数
|
|
|
+ double day = 0;
|
|
|
+ double hour = 0;
|
|
|
+ double min = 0;
|
|
|
+ day = diff / nd;// 计算差多少天
|
|
|
+ hour = diff % nd / nh + day * 24;// 计算差多少小时
|
|
|
+ min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟
|
|
|
+ double money = 0.00;
|
|
|
+ double newHour = hour;
|
|
|
+ if (min > 0) { //一小时超过
|
|
|
+ newHour += 1;
|
|
|
+ }
|
|
|
+ if (newHour <= 2) {
|
|
|
+ money = Double.parseDouble(feeConfigDto.getAdditionalAmount());
|
|
|
+ } else {
|
|
|
+ double lastHour = newHour - 2;
|
|
|
+ money = lastHour * Double.parseDouble(feeConfigDto.getSquarePrice()) + Double.parseDouble(feeConfigDto.getAdditionalAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ double receivableAmount = money;
|
|
|
+
|
|
|
+ businessFeeDetail.put("receivableAmount", receivableAmount);
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessFeeDetail", businessFeeDetail);
|
|
|
+ paramInJson.put("receivableAmount", receivableAmount);
|
|
|
+ return business;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改费用信息
|
|
|
+ *
|
|
|
+ * @param paramInJson 接口调用放传入入参
|
|
|
+ * @param dataFlowContext 数据上下文
|
|
|
+ * @return 订单服务能够接受的报文
|
|
|
+ */
|
|
|
+ private JSONObject modifyFee(JSONObject paramInJson, DataFlowContext dataFlowContext) {
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
|
|
|
+ business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_UPDATE_FEE_INFO);
|
|
|
+ business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ + 1);
|
|
|
+ business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
|
|
|
+ JSONObject businessFee = new JSONObject();
|
|
|
+ FeeDto feeInfo = (FeeDto) paramInJson.get("feeInfo");
|
|
|
+ Map feeMap = BeanConvertUtil.beanCovertMap(feeInfo);
|
|
|
+ feeMap.put("startTime", DateUtil.getFormatTimeString(feeInfo.getStartTime(), DateUtil.DATE_FORMATE_STRING_A));
|
|
|
+ feeMap.put("endTime", DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_A));
|
|
|
+ feeMap.put("total", paramInJson.getString("receivableAmount"));
|
|
|
+ businessFee.putAll(feeMap);
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessFee", businessFee);
|
|
|
+
|
|
|
+ return business;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据校验
|
|
|
+ *
|
|
|
+ * @param paramIn "communityId": "7020181217000001",
|
|
|
+ * "memberId": "3456789",
|
|
|
+ * "memberTypeCd": "390001200001"
|
|
|
+ */
|
|
|
+ private void validate(String paramIn) {
|
|
|
+ Assert.jsonObjectHaveKey(paramIn, "communityId", "请求报文中未包含communityId节点");
|
|
|
+ Assert.jsonObjectHaveKey(paramIn, "receivedAmount", "请求报文中未包含receivedAmount节点");
|
|
|
+ Assert.jsonObjectHaveKey(paramIn, "feeId", "请求报文中未包含feeId节点");
|
|
|
+
|
|
|
+ JSONObject paramInObj = JSONObject.parseObject(paramIn);
|
|
|
+ Assert.hasLength(paramInObj.getString("communityId"), "小区ID不能为空");
|
|
|
+ Assert.hasLength(paramInObj.getString("receivedAmount"), "实收金额不能为空");
|
|
|
+ Assert.hasLength(paramInObj.getString("feeId"), "费用ID不能为空");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getOrder() {
|
|
|
+ return DEFAULT_ORDER;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public IFeeInnerServiceSMO getFeeInnerServiceSMOImpl() {
|
|
|
+ return feeInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFeeInnerServiceSMOImpl(IFeeInnerServiceSMO feeInnerServiceSMOImpl) {
|
|
|
+ this.feeInnerServiceSMOImpl = feeInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IFeeConfigInnerServiceSMO getFeeConfigInnerServiceSMOImpl() {
|
|
|
+ return feeConfigInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFeeConfigInnerServiceSMOImpl(IFeeConfigInnerServiceSMO feeConfigInnerServiceSMOImpl) {
|
|
|
+ this.feeConfigInnerServiceSMOImpl = feeConfigInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IRoomInnerServiceSMO getRoomInnerServiceSMOImpl() {
|
|
|
+ return roomInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRoomInnerServiceSMOImpl(IRoomInnerServiceSMO roomInnerServiceSMOImpl) {
|
|
|
+ this.roomInnerServiceSMOImpl = roomInnerServiceSMOImpl;
|
|
|
+ }
|
|
|
+}
|