GetCarMachineQrCodeUrl.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.core.annotation.Java110Cmd;
  20. import com.java110.core.context.ICmdDataFlowContext;
  21. import com.java110.core.event.cmd.Cmd;
  22. import com.java110.core.event.cmd.CmdEvent;
  23. import com.java110.core.factory.CommunitySettingFactory;
  24. import com.java110.core.log.LoggerFactory;
  25. import com.java110.dto.communitySetting.CommunitySettingDto;
  26. import com.java110.dto.parkingBoxArea.ParkingBoxAreaDto;
  27. import com.java110.dto.smallWeChat.SmallWeChatDto;
  28. import com.java110.intf.community.IParkingBoxAreaV1InnerServiceSMO;
  29. import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
  30. import com.java110.utils.cache.MappingCache;
  31. import com.java110.utils.exception.CmdException;
  32. import com.java110.utils.util.Assert;
  33. import com.java110.utils.util.StringUtil;
  34. import com.java110.vo.ResultVo;
  35. import org.slf4j.Logger;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import java.util.List;
  38. /**
  39. * 类表述:保存
  40. * 服务编码:machine.getCarMachineQrCodeUrl
  41. * 请求路劲:/app/machine.getCarMachineQrCodeUrl
  42. * add by 吴学文 at 2021-09-18 13:35:13 mail: 928255095@qq.com
  43. * open source address: https://gitee.com/wuxw7/MicroCommunity
  44. * 官网:http://www.homecommunity.cn
  45. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  46. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  47. */
  48. @Java110Cmd(serviceCode = "machine.getCarMachineQrCodeUrl")
  49. public class GetCarMachineQrCodeUrl extends Cmd {
  50. private static Logger logger = LoggerFactory.getLogger(GetCarMachineQrCodeUrl.class);
  51. public static final String CODE_PREFIX_ID = "10";
  52. @Autowired
  53. private IMachineOpenDoorBMO machineOpenDoorBMOImpl;
  54. @Autowired
  55. private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
  56. @Autowired
  57. private IParkingBoxAreaV1InnerServiceSMO parkingBoxAreaV1InnerServiceSMOImpl;
  58. @Override
  59. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  60. Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息");
  61. Assert.hasKeyAndValue(reqJson, "boxId", "请求报文中未包含岗亭");
  62. }
  63. @Override
  64. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  65. SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
  66. smallWeChatDto.setObjId(reqJson.getString("communityId"));
  67. smallWeChatDto.setWeChatType(SmallWeChatDto.WECHAT_TYPE_PUBLIC);
  68. List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
  69. String ownerUrl = MappingCache.getValue("OWNER_WECHAT_URL");
  70. ownerUrl += ("/#/pages/tempParkingFee/tempParkingFee?paId=" + getPaIds(reqJson)+"&communityId="+reqJson.getString("communityId"));
  71. if (smallWeChatDtos != null && smallWeChatDtos.size() > 0) {
  72. ownerUrl += ("&appId=" + smallWeChatDtos.get(0).getAppId());
  73. }
  74. if (reqJson.containsKey("machineId") && !"-1".equals(reqJson.getString("machineId"))) {
  75. ownerUrl += ("&machineId=" + reqJson.getString("machineId"));
  76. }
  77. String aliAppId = CommunitySettingFactory.getValue(reqJson.getString("communityId"),"APP_ID");
  78. if( !StringUtil.isEmpty(aliAppId)){
  79. ownerUrl += ("&aliAppId=" + aliAppId);
  80. }
  81. reqJson.put("url", ownerUrl);
  82. cmdDataFlowContext.setResponseEntity(ResultVo.createResponseEntity(reqJson));
  83. }
  84. private String getPaIds(JSONObject reqJson) {
  85. if (reqJson.containsKey("boxId") && !StringUtil.isEmpty(reqJson.getString("boxId"))) {
  86. ParkingBoxAreaDto parkingBoxAreaDto = new ParkingBoxAreaDto();
  87. parkingBoxAreaDto.setBoxId(reqJson.getString("boxId"));
  88. parkingBoxAreaDto.setCommunityId(reqJson.getString("communityId"));
  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. return parkingBoxAreaDtos.get(0).getPaId();
  95. }
  96. return "";
  97. }
  98. }