SaveCommunitySpacePersonCmd.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.community.cmd.communitySpace;
  17. import com.alibaba.fastjson.JSONArray;
  18. import com.alibaba.fastjson.JSONObject;
  19. import com.java110.core.annotation.Java110Cmd;
  20. import com.java110.core.annotation.Java110Transactional;
  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.doc.annotation.*;
  26. import com.java110.dto.communitySpacePerson.CommunitySpacePersonDto;
  27. import com.java110.dto.communitySpacePersonTime.CommunitySpacePersonTimeDto;
  28. import com.java110.intf.community.ICommunitySpacePersonTimeV1InnerServiceSMO;
  29. import com.java110.intf.community.ICommunitySpacePersonV1InnerServiceSMO;
  30. import com.java110.po.communitySpacePerson.CommunitySpacePersonPo;
  31. import com.java110.po.communitySpacePersonTime.CommunitySpacePersonTimePo;
  32. import com.java110.utils.exception.CmdException;
  33. import com.java110.utils.util.Assert;
  34. import com.java110.utils.util.BeanConvertUtil;
  35. import com.java110.utils.util.StringUtil;
  36. import com.java110.vo.ResultVo;
  37. import org.slf4j.Logger;
  38. import org.slf4j.LoggerFactory;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. @Java110CmdDoc(title = "预约场地",
  41. description = "系统中的预约场地",
  42. httpMethod = "post",
  43. url = "http://{ip}:{port}/app/communitySpace.saveCommunitySpacePerson",
  44. resource = "communityDoc",
  45. author = "吴学文",
  46. serviceCode = "communitySpace.saveCommunitySpacePerson"
  47. )
  48. @Java110ParamsDoc(params = {
  49. @Java110ParamDoc(name = "page",type = "int",length = 11, remark = "分页页数"),
  50. @Java110ParamDoc(name = "row",type = "int", length = 11, remark = "分页行数"),
  51. @Java110ParamDoc(name = "communityId", length = 30, remark = "小区ID"),
  52. @Java110ParamDoc(name = "appointmentDate", length = 30, remark = "预约日期 YYYY-MM-DD"),
  53. @Java110ParamDoc(name = "appointmentTime", length = 30, remark = "预约时间 HH24:MI"),
  54. @Java110ParamDoc(name = "payWay", length = 12, remark = "支付方式"),
  55. @Java110ParamDoc(name = "personName", length = 64, remark = "预约人"),
  56. @Java110ParamDoc(name = "personTel", length = 30, remark = "预约人电话"),
  57. @Java110ParamDoc(name = "receivableAmount", length = 30, remark = "应收金额"),
  58. @Java110ParamDoc(name = "receivedAmount", length = 30, remark = "实收金额"),
  59. @Java110ParamDoc(name = "spaceId", length = 30, remark = "场地ID"),
  60. })
  61. @Java110ResponseDoc(
  62. params = {
  63. @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 其他失败"),
  64. @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
  65. }
  66. )
  67. @Java110ExampleDoc(
  68. reqBody="{\"spaceId\":\"102022093043260007\",\"personName\":\"wuxw\",\"personTel\":\"18909711443\",\"appointmentTime\":\"01:00\",\"receivableAmount\":\"10\",\"receivedAmount\":\"10\",\"payWay\":\"2\",\"state\":\"S\",\"remark\":\"123\",\"appointmentDate\":\"2022-09-01\",\"communityId\":\"2022081539020475\"}",
  69. resBody="{\"code\":0,\"msg\":\"成功\"}"
  70. )
  71. /**
  72. * 类表述:保存
  73. * 服务编码:communitySpacePerson.saveCommunitySpacePerson
  74. * 请求路劲:/app/communitySpacePerson.SaveCommunitySpacePerson
  75. * add by 吴学文 at 2022-09-30 11:36:52 mail: 928255095@qq.com
  76. * open source address: https://gitee.com/wuxw7/MicroCommunity
  77. * 官网:http://www.homecommunity.cn
  78. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  79. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  80. */
  81. @Java110Cmd(serviceCode = "communitySpace.saveCommunitySpacePerson")
  82. public class SaveCommunitySpacePersonCmd extends Cmd {
  83. private static Logger logger = LoggerFactory.getLogger(SaveCommunitySpacePersonCmd.class);
  84. public static final String CODE_PREFIX_ID = "10";
  85. @Autowired
  86. private ICommunitySpacePersonV1InnerServiceSMO communitySpacePersonV1InnerServiceSMOImpl;
  87. @Autowired
  88. private ICommunitySpacePersonTimeV1InnerServiceSMO communitySpacePersonTimeV1InnerServiceSMOImpl;
  89. @Override
  90. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  91. Assert.hasKeyAndValue(reqJson, "spaceId", "请求报文中未包含spaceId");
  92. Assert.hasKeyAndValue(reqJson, "personName", "请求报文中未包含personName");
  93. Assert.hasKeyAndValue(reqJson, "personTel", "请求报文中未包含personTel");
  94. Assert.hasKeyAndValue(reqJson, "appointmentTime", "请求报文中未包含appointmentTime");
  95. Assert.hasKeyAndValue(reqJson, "receivableAmount", "请求报文中未包含receivableAmount");
  96. Assert.hasKeyAndValue(reqJson, "receivedAmount", "请求报文中未包含receivedAmount");
  97. Assert.hasKeyAndValue(reqJson, "payWay", "请求报文中未包含payWay");
  98. Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
  99. if(!reqJson.containsKey("openTimes")){
  100. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  101. return ;
  102. }
  103. JSONArray openTimes = reqJson.getJSONArray("openTimes");
  104. if(openTimes == null || openTimes.size() <1){
  105. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  106. return ;
  107. }
  108. CommunitySpacePersonTimeDto communitySpacePersonTimeDto = null;
  109. int flag = 0;
  110. for(int timeIndex = 0 ;timeIndex < openTimes.size(); timeIndex++) {
  111. if("N".equals(openTimes.getJSONObject(timeIndex).getString("isOpen"))){
  112. continue;
  113. }
  114. communitySpacePersonTimeDto = new CommunitySpacePersonTimeDto();
  115. communitySpacePersonTimeDto.setCommunityId(reqJson.getString("communityId"));
  116. communitySpacePersonTimeDto.setAppointmentTime(reqJson.getString("appointmentTime"));
  117. communitySpacePersonTimeDto.setHours(openTimes.getJSONObject(timeIndex).getString("hours"));
  118. communitySpacePersonTimeDto.setSpaceId(reqJson.getString("spaceId"));
  119. flag = communitySpacePersonTimeV1InnerServiceSMOImpl.queryCommunitySpacePersonTimesCount(communitySpacePersonTimeDto);
  120. if(flag > 0){
  121. throw new CmdException(reqJson.getString("appointmentTime")+","+openTimes.getJSONObject(timeIndex).getString("hours")+"已经被预约");
  122. }
  123. }
  124. }
  125. @Override
  126. @Java110Transactional
  127. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  128. CommunitySpacePersonPo communitySpacePersonPo = BeanConvertUtil.covertBean(reqJson, CommunitySpacePersonPo.class);
  129. communitySpacePersonPo.setCspId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
  130. if(StringUtil.isEmpty(communitySpacePersonPo.getState())){
  131. communitySpacePersonPo.setState(CommunitySpacePersonDto.STATE_W);
  132. }
  133. int flag = communitySpacePersonV1InnerServiceSMOImpl.saveCommunitySpacePerson(communitySpacePersonPo);
  134. if (flag < 1) {
  135. throw new CmdException("保存数据失败");
  136. }
  137. if(!reqJson.containsKey("openTimes")){
  138. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  139. return ;
  140. }
  141. JSONArray openTimes = reqJson.getJSONArray("openTimes");
  142. if(openTimes == null || openTimes.size() <1){
  143. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  144. return ;
  145. }
  146. CommunitySpacePersonTimePo communitySpacePersonTimePo = null;
  147. for(int timeIndex = 0 ;timeIndex < openTimes.size(); timeIndex++) {
  148. if("N".equals(openTimes.getJSONObject(timeIndex).getString("isOpen"))){
  149. continue;
  150. }
  151. communitySpacePersonTimePo = new CommunitySpacePersonTimePo();
  152. communitySpacePersonTimePo.setCommunityId(communitySpacePersonPo.getCommunityId());
  153. communitySpacePersonTimePo.setCspId(communitySpacePersonPo.getCspId());
  154. communitySpacePersonTimePo.setHours(openTimes.getJSONObject(timeIndex).getString("hours"));
  155. communitySpacePersonTimePo.setSpaceId(communitySpacePersonPo.getSpaceId());
  156. communitySpacePersonTimePo.setTimeId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
  157. communitySpacePersonTimeV1InnerServiceSMOImpl.saveCommunitySpacePersonTime(communitySpacePersonTimePo);
  158. }
  159. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  160. }
  161. }