CustomCarInOutCmd.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.common.cmd.machine;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.java110.common.bmo.machine.IMachineOpenDoorBMO;
  19. import com.java110.common.dao.ICarInoutV1ServiceDao;
  20. import com.java110.core.annotation.Java110Cmd;
  21. import com.java110.core.context.ICmdDataFlowContext;
  22. import com.java110.core.event.cmd.Cmd;
  23. import com.java110.core.event.cmd.CmdEvent;
  24. import com.java110.core.factory.GenerateCodeFactory;
  25. import com.java110.dto.machine.CarInoutDto;
  26. import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
  27. import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
  28. import com.java110.intf.common.ICarInoutV1InnerServiceSMO;
  29. import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
  30. import com.java110.intf.job.IDataBusInnerServiceSMO;
  31. import com.java110.utils.exception.CmdException;
  32. import com.java110.utils.util.Assert;
  33. import com.java110.utils.util.DateUtil;
  34. import com.java110.utils.util.StringUtil;
  35. import com.java110.vo.ResultVo;
  36. import org.slf4j.Logger;
  37. import com.java110.core.log.LoggerFactory;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.http.ResponseEntity;
  40. import java.util.List;
  41. /**
  42. * 类表述:保存
  43. * 服务编码:machine.customCarInOutCmd
  44. * 请求路劲:/app/machine.customCarInOutCmd
  45. * add by 吴学文 at 2021-09-18 13:35:13 mail: 928255095@qq.com
  46. * open source address: https://gitee.com/wuxw7/MicroCommunity
  47. * 官网:http://www.homecommunity.cn
  48. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  49. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  50. */
  51. @Java110Cmd(serviceCode = "machine.customCarInOutCmd")
  52. public class CustomCarInOutCmd extends Cmd {
  53. private static Logger logger = LoggerFactory.getLogger(CustomCarInOutCmd.class);
  54. public static final String CODE_PREFIX_ID = "10";
  55. @Autowired
  56. private IMachineOpenDoorBMO machineOpenDoorBMOImpl;
  57. @Autowired
  58. private IDataBusInnerServiceSMO dataBusInnerServiceSMOImpl;
  59. @Autowired
  60. private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaV1InnerServiceSMOImpl;
  61. @Autowired
  62. private ICarInoutV1InnerServiceSMO carInoutV1InnerServiceSMOImpl;
  63. @Override
  64. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  65. Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息");
  66. Assert.hasKeyAndValue(reqJson, "machineId", "请求报文中未包含设备信息");
  67. Assert.hasKeyAndValue(reqJson, "carNum", "请求报文中未包含车牌号");
  68. Assert.hasKeyAndValue(reqJson, "type", "请求报文中未包含类型");
  69. if("1101".equals(reqJson.getString("type"))) {
  70. return;
  71. }
  72. CarInoutDto carInoutDto = new CarInoutDto();
  73. carInoutDto.setCarNum(reqJson.getString("carNum"));
  74. carInoutDto.setStates(new String[]{
  75. CarInoutDto.STATE_IN,
  76. CarInoutDto.STATE_REPAY
  77. });
  78. int count = carInoutV1InnerServiceSMOImpl.queryCarInoutsCount(carInoutDto);
  79. if(count < 1){
  80. throw new CmdException("车辆未入场");
  81. }
  82. }
  83. @Override
  84. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  85. //出场时 先 补充费用信息
  86. if(!"1101".equals(reqJson.getString("type"))) {
  87. ParkingBoxAreaDto parkingBoxAreaDto = new ParkingBoxAreaDto();
  88. parkingBoxAreaDto.setBoxId(reqJson.getString("boxId"));
  89. parkingBoxAreaDto.setDefaultArea(ParkingBoxAreaDto.DEFAULT_AREA_TRUE);
  90. List<ParkingBoxAreaDto> parkingBoxAreaDtos = parkingBoxAreaV1InnerServiceSMOImpl.queryParkingBoxAreas(parkingBoxAreaDto);
  91. if(parkingBoxAreaDtos == null || parkingBoxAreaDtos.size()< 1){
  92. throw new CmdException("未包含停车场信息");
  93. }
  94. TempCarPayOrderDto tempCarPayOrderDto = new TempCarPayOrderDto();
  95. tempCarPayOrderDto.setCarNum(reqJson.getString("carNum"));
  96. tempCarPayOrderDto.setPaId(parkingBoxAreaDtos.get(0).getPaId());
  97. tempCarPayOrderDto.setOrderId(reqJson.getString("inoutId"));
  98. tempCarPayOrderDto.setAmount(Double.parseDouble(reqJson.getString("payCharge")));
  99. tempCarPayOrderDto.setPayType(reqJson.getString("payType"));
  100. //tempCarPayOrderDto.setMachineId(reqJson.getString("machineId"));
  101. ResultVo resultVo = dataBusInnerServiceSMOImpl.notifyTempCarFeeOrder(tempCarPayOrderDto);
  102. }
  103. ResponseEntity<String> responseEntity = machineOpenDoorBMOImpl.customCarInOut(reqJson);
  104. cmdDataFlowContext.setResponseEntity(responseEntity);
  105. }
  106. }