|
|
@@ -1,15 +1,24 @@
|
|
|
package com.java110.api.listener.machineTranslate;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.java110.core.annotation.Java110Listener;
|
|
|
import com.java110.core.context.DataFlowContext;
|
|
|
+import com.java110.core.factory.GenerateCodeFactory;
|
|
|
import com.java110.core.smo.hardwareAdapation.ICarBlackWhiteInnerServiceSMO;
|
|
|
+import com.java110.core.smo.hardwareAdapation.ICarInoutInnerServiceSMO;
|
|
|
import com.java110.core.smo.hardwareAdapation.IMachineInnerServiceSMO;
|
|
|
import com.java110.dto.hardwareAdapation.CarBlackWhiteDto;
|
|
|
+import com.java110.dto.hardwareAdapation.CarInoutDto;
|
|
|
import com.java110.dto.hardwareAdapation.MachineDto;
|
|
|
+import com.java110.entity.center.AppService;
|
|
|
import com.java110.event.service.api.ServiceDataFlowEvent;
|
|
|
+import com.java110.utils.constant.BusinessTypeConstant;
|
|
|
+import com.java110.utils.constant.CommonConstant;
|
|
|
import com.java110.utils.constant.ServiceCodeMachineTranslateConstant;
|
|
|
import com.java110.utils.util.Assert;
|
|
|
+import com.java110.utils.util.BeanConvertUtil;
|
|
|
+import com.java110.utils.util.DateUtil;
|
|
|
import com.java110.utils.util.StringUtil;
|
|
|
import com.java110.vo.api.machine.MachineResDataVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -18,6 +27,7 @@ import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -42,6 +52,9 @@ public class MachineRoadGateOpenListener extends BaseMachineListener {
|
|
|
@Autowired
|
|
|
private IMachineInnerServiceSMO machineInnerServiceSMOImpl;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICarInoutInnerServiceSMO carInoutInnerServiceSMOImpl;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ICarBlackWhiteInnerServiceSMO carBlackWhiteInnerServiceSMOImpl;
|
|
|
|
|
|
@@ -86,9 +99,110 @@ public class MachineRoadGateOpenListener extends BaseMachineListener {
|
|
|
|
|
|
//进入
|
|
|
if (MACHINE_DIRECTION_IN.equals(direction)) {
|
|
|
- dealCarIn(context, reqJson, machineDtos.get(0), communityId, machineCode);
|
|
|
+ dealCarIn(event, context, reqJson, machineDtos.get(0), communityId);
|
|
|
+ } else {
|
|
|
+ dealCarOut(event, context, reqJson, machineDtos.get(0), communityId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 车辆出场
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ * @param context
|
|
|
+ * @param reqJson
|
|
|
+ * @param machineDto
|
|
|
+ * @param communityId
|
|
|
+ */
|
|
|
+ private void dealCarOut(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson, MachineDto machineDto, String communityId) {
|
|
|
+
|
|
|
+ //首先查询是否车辆有进场
|
|
|
+ CarInoutDto carInoutDto = new CarInoutDto();
|
|
|
+ carInoutDto.setStates(new String[]{"100300", "100400", "100600"});
|
|
|
+ carInoutDto.setCommunityId(communityId);
|
|
|
+ carInoutDto.setCarNum(reqJson.getString("carNum"));
|
|
|
+ List<CarInoutDto> carInoutDtos = carInoutInnerServiceSMOImpl.queryCarInouts(carInoutDto);
|
|
|
+
|
|
|
+ if (carInoutDtos == null || carInoutDtos.size() < 1) {//数据有问题, 直接出场
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_SUCCESS, "数据有问题,未查到入场记录,直接放行"));
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ CarInoutDto tmpCarInoutDto = carInoutDtos.get(0);
|
|
|
+ reqJson.put("inoutId", tmpCarInoutDto.getInoutId());
|
|
|
+
|
|
|
+ if (!"100400".equals(tmpCarInoutDto.getState())) {
|
|
|
+
|
|
|
+ dealCarOutIncomplete(event, context, reqJson, tmpCarInoutDto, machineDto);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ modifyCarInoutInfo(event, context, reqJson, tmpCarInoutDto, machineDto);
|
|
|
+ ResponseEntity<String> responseEntity = context.getResponseEntity();
|
|
|
+
|
|
|
+ if (responseEntity.getStatusCode() != HttpStatus.OK) {
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_ERROR, "后台处理数据异常" + responseEntity.getBody()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_SUCCESS, "成功"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理车辆未完成支付出场处理
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ * @param context
|
|
|
+ * @param tmpCarInoutDto
|
|
|
+ * @param machineDto
|
|
|
+ */
|
|
|
+ private void dealCarOutIncomplete(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson, CarInoutDto tmpCarInoutDto, MachineDto machineDto) {
|
|
|
+ //判断车辆是否在白名单中
|
|
|
+ String carNum = reqJson.getString("carNum");
|
|
|
+ CarBlackWhiteDto carBlackWhiteDto = new CarBlackWhiteDto();
|
|
|
+ carBlackWhiteDto.setCommunityId(tmpCarInoutDto.getCommunityId());
|
|
|
+ carBlackWhiteDto.setCarNum(carNum);
|
|
|
+ carBlackWhiteDto.setBlackWhite(CAR_WHITE);
|
|
|
+ int count = carBlackWhiteInnerServiceSMOImpl.queryCarBlackWhitesCount(carBlackWhiteDto);
|
|
|
+ if (count > 0) {
|
|
|
+ modifyCarInoutInfo(event, context, reqJson, tmpCarInoutDto, machineDto);
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_SUCCESS, "白名单中直接放行"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断车辆出租和出售 时间是否到期
|
|
|
+
|
|
|
+
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_ERROR, "车辆未支付,请先支付"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void modifyCarInoutInfo(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson, CarInoutDto tmpCarInoutDto, MachineDto machineDto) {
|
|
|
+ HttpHeaders header = new HttpHeaders();
|
|
|
+ context.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD, "D");
|
|
|
+ JSONArray businesses = new JSONArray();
|
|
|
+ AppService service = event.getAppService();
|
|
|
+ //添加单元信息
|
|
|
+ businesses.add(modifyCarInout(reqJson, context, tmpCarInoutDto));
|
|
|
+ reqJson.put("inoutId", tmpCarInoutDto.getInoutId());
|
|
|
+ businesses.add(addCarInoutDetail(reqJson, context, tmpCarInoutDto.getCommunityId(), machineDto));
|
|
|
+ JSONObject paramInObj = super.restToCenterProtocol(businesses, context.getRequestCurrentHeaders());
|
|
|
+ //将 rest header 信息传递到下层服务中去
|
|
|
+ super.freshHttpHeader(header, context.getRequestCurrentHeaders());
|
|
|
+ ResponseEntity<String> responseEntity = this.callService(context, service.getServiceCode(), paramInObj);
|
|
|
+ context.setResponseEntity(responseEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object modifyCarInout(JSONObject reqJson, DataFlowContext context, CarInoutDto carInoutDto) {
|
|
|
+ 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", "100500");
|
|
|
+ businessCarInout.put("outTime", DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_A));
|
|
|
+ //计算 应收金额
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessCarInout", businessCarInout);
|
|
|
+ return business;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -97,9 +211,8 @@ public class MachineRoadGateOpenListener extends BaseMachineListener {
|
|
|
* @param reqJson
|
|
|
* @param machineDto
|
|
|
* @param communityId
|
|
|
- * @param machineCode
|
|
|
*/
|
|
|
- private void dealCarIn(DataFlowContext context, JSONObject reqJson, MachineDto machineDto, String communityId, String machineCode) {
|
|
|
+ private void dealCarIn(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson, MachineDto machineDto, String communityId) {
|
|
|
//车辆是否黑名单 车辆
|
|
|
String carNum = reqJson.getString("carNum");
|
|
|
CarBlackWhiteDto carBlackWhiteDto = new CarBlackWhiteDto();
|
|
|
@@ -112,8 +225,80 @@ public class MachineRoadGateOpenListener extends BaseMachineListener {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ HttpHeaders header = new HttpHeaders();
|
|
|
+ context.getRequestCurrentHeaders().put(CommonConstant.HTTP_ORDER_TYPE_CD, "D");
|
|
|
+ JSONArray businesses = new JSONArray();
|
|
|
+
|
|
|
+ AppService service = event.getAppService();
|
|
|
+
|
|
|
+ //添加单元信息
|
|
|
+ businesses.add(addCarInout(reqJson, context, communityId));
|
|
|
+ businesses.add(addCarInoutDetail(reqJson, context, communityId, machineDto));
|
|
|
+
|
|
|
+ JSONObject paramInObj = super.restToCenterProtocol(businesses, context.getRequestCurrentHeaders());
|
|
|
+
|
|
|
+ //将 rest header 信息传递到下层服务中去
|
|
|
+ super.freshHttpHeader(header, context.getRequestCurrentHeaders());
|
|
|
+
|
|
|
+ ResponseEntity<String> responseEntity = this.callService(context, service.getServiceCode(), paramInObj);
|
|
|
+ if (responseEntity.getStatusCode() != HttpStatus.OK) {
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_ERROR, responseEntity.getBody()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ context.setResponseEntity(MachineResDataVo.getResData(MachineResDataVo.CODE_SUCCESS, "成功"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加小区信息
|
|
|
+ *
|
|
|
+ * @param paramInJson 接口调用放传入入参
|
|
|
+ * @param dataFlowContext 数据上下文
|
|
|
+ * @return 订单服务能够接受的报文
|
|
|
+ */
|
|
|
+ private JSONObject addCarInout(JSONObject paramInJson, DataFlowContext dataFlowContext, String communityId) {
|
|
|
+
|
|
|
+ paramInJson.put("inoutId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_inoutId));
|
|
|
+ JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
|
|
|
+ business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_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.put("carNum", paramInJson.getString("carNum"));
|
|
|
+ businessCarInout.put("inoutId", paramInJson.getString("inoutId"));
|
|
|
+ businessCarInout.put("communityId", communityId);
|
|
|
+ businessCarInout.put("state", "100300");
|
|
|
+ businessCarInout.put("inTime", DateUtil.getFormatTimeString(new Date(), DateUtil.DATE_FORMATE_STRING_A));
|
|
|
+ //计算 应收金额
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessCarInout", businessCarInout);
|
|
|
+ return business;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加小区信息
|
|
|
+ *
|
|
|
+ * @param paramInJson 接口调用放传入入参
|
|
|
+ * @param dataFlowContext 数据上下文
|
|
|
+ * @return 订单服务能够接受的报文
|
|
|
+ */
|
|
|
+ private JSONObject addCarInoutDetail(JSONObject paramInJson, DataFlowContext dataFlowContext, String communityId, MachineDto machineDto) {
|
|
|
|
|
|
|
|
|
+ JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
|
|
|
+ business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_SAVE_CAR_INOUT);
|
|
|
+ business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
|
|
|
+ business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
|
|
|
+ JSONObject businessCarInoutDetail = new JSONObject();
|
|
|
+ businessCarInoutDetail.put("carNum", paramInJson.getString("carNum"));
|
|
|
+ businessCarInoutDetail.put("inoutId", paramInJson.getString("inoutId"));
|
|
|
+ businessCarInoutDetail.put("communityId", communityId);
|
|
|
+ businessCarInoutDetail.put("machineId", machineDto.getMachineId());
|
|
|
+ businessCarInoutDetail.put("machineCode", machineDto.getMachineCode());
|
|
|
+ businessCarInoutDetail.put("carInout", machineDto.getDirection());
|
|
|
+ businessCarInoutDetail.put("detailId", "-1");
|
|
|
+ //计算 应收金额
|
|
|
+ business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessCarInoutDetail", businessCarInoutDetail);
|
|
|
+ return business;
|
|
|
}
|
|
|
|
|
|
@Override
|