SaveCommunityCmd.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.community;
  17. import com.alibaba.fastjson.JSONArray;
  18. import com.alibaba.fastjson.JSONObject;
  19. import com.java110.community.bmo.community.ICommunityBMO;
  20. import com.java110.core.annotation.Java110Cmd;
  21. import com.java110.core.annotation.Java110Transactional;
  22. import com.java110.core.context.ICmdDataFlowContext;
  23. import com.java110.core.event.cmd.AbstractServiceCmdListener;
  24. import com.java110.core.event.cmd.CmdEvent;
  25. import com.java110.core.factory.GenerateCodeFactory;
  26. import com.java110.dto.workflow.WorkflowDto;
  27. import com.java110.intf.common.IWorkflowV1InnerServiceSMO;
  28. import com.java110.intf.community.ICommunityV1InnerServiceSMO;
  29. import com.java110.po.workflow.WorkflowPo;
  30. import com.java110.utils.constant.BusinessTypeConstant;
  31. import com.java110.utils.exception.CmdException;
  32. import com.java110.utils.util.Assert;
  33. import com.java110.vo.ResultVo;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. /**
  38. * 类表述:保存
  39. * 服务编码:community.saveCommunity
  40. * 请求路劲:/app/community.SaveCommunity
  41. * add by 吴学文 at 2021-09-18 12:54:57 mail: 928255095@qq.com
  42. * open source address: https://gitee.com/wuxw7/MicroCommunity
  43. * 官网:http://www.homecommunity.cn
  44. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  45. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  46. */
  47. @Java110Cmd(serviceCode = "community.saveCommunity")
  48. public class SaveCommunityCmd extends AbstractServiceCmdListener {
  49. private static Logger logger = LoggerFactory.getLogger(SaveCommunityCmd.class);
  50. public static final String CODE_PREFIX_ID = "10";
  51. @Autowired
  52. private ICommunityBMO communityBMOImpl;
  53. @Autowired
  54. private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
  55. @Autowired
  56. private IWorkflowV1InnerServiceSMO workflowV1InnerServiceSMOImpl;
  57. @Override
  58. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  59. Assert.hasKeyAndValue(reqJson, "name", "必填,请填写小区名称");
  60. Assert.hasKeyAndValue(reqJson, "address", "必填,请填写小区地址");
  61. Assert.hasKeyAndValue(reqJson, "cityCode", "请求报文中未包含cityCode");
  62. Assert.hasKeyAndValue(reqJson, "payFeeMonth", "请求报文中未包含payFeeMonth");
  63. Assert.hasKeyAndValue(reqJson, "feePrice", "请求报文中未包含feePrice");
  64. //属性校验
  65. Assert.judgeAttrValue(reqJson);
  66. }
  67. @Override
  68. @Java110Transactional
  69. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  70. communityBMOImpl.addCommunity(reqJson, cmdDataFlowContext);
  71. communityBMOImpl.addCommunityMembers(reqJson, cmdDataFlowContext);
  72. //产生物业费配置信息
  73. communityBMOImpl.addFeeConfigProperty(reqJson, cmdDataFlowContext);
  74. communityBMOImpl.addFeeConfigRepair(reqJson, cmdDataFlowContext); // 报修费用
  75. communityBMOImpl.addFeeConfigParkingSpaceTemp(reqJson, cmdDataFlowContext);//地下出租
  76. dealAttr(reqJson, cmdDataFlowContext);
  77. WorkflowPo workflowPo = null;
  78. workflowPo = new WorkflowPo();
  79. workflowPo.setCommunityId(reqJson.getString("communityId"));
  80. workflowPo.setFlowId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_flowId));
  81. workflowPo.setFlowName("投诉建议流程");
  82. workflowPo.setFlowType(WorkflowDto.FLOW_TYPE_COMPLAINT);
  83. workflowPo.setSkipLevel(WorkflowDto.DEFAULT_SKIP_LEVEL);
  84. workflowPo.setStoreId(reqJson.getString("storeId"));
  85. int flag = workflowV1InnerServiceSMOImpl.saveWorkflow(workflowPo);
  86. if (flag < 1) {
  87. throw new IllegalArgumentException("添加流程失败");
  88. }
  89. WorkflowPo workflowPo1 = null;
  90. workflowPo1 = new WorkflowPo();
  91. workflowPo1.setCommunityId(reqJson.getString("communityId"));
  92. workflowPo1.setFlowId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_flowId));
  93. workflowPo1.setFlowName("物品领用");
  94. workflowPo1.setFlowType(WorkflowDto.FLOW_TYPE_COLLECTION);
  95. workflowPo1.setSkipLevel(WorkflowDto.DEFAULT_SKIP_LEVEL);
  96. workflowPo1.setStoreId(reqJson.getString("storeId"));
  97. flag = workflowV1InnerServiceSMOImpl.saveWorkflow(workflowPo1);
  98. if (flag < 1) {
  99. throw new IllegalArgumentException("添加流程失败");
  100. }
  101. WorkflowPo workflowPo2 = new WorkflowPo();
  102. workflowPo2.setCommunityId(reqJson.getString("communityId")); //被调拨小区
  103. workflowPo2.setFlowId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_flowId));
  104. workflowPo2.setFlowName("物品被调拨");
  105. workflowPo2.setFlowType(WorkflowDto.FLOW_TYPE_ALLOCATION_STOREHOUSE_GO);
  106. workflowPo2.setSkipLevel(WorkflowDto.DEFAULT_SKIP_LEVEL);
  107. workflowPo2.setStoreId(reqJson.getString("storeId"));
  108. flag = workflowV1InnerServiceSMOImpl.saveWorkflow(workflowPo2);
  109. if (flag < 1) {
  110. throw new IllegalArgumentException("添加流程失败");
  111. }
  112. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  113. }
  114. private void dealAttr(JSONObject paramObj, ICmdDataFlowContext context) {
  115. if (!paramObj.containsKey("attrs")) {
  116. return;
  117. }
  118. JSONArray attrs = paramObj.getJSONArray("attrs");
  119. if (attrs.size() < 1) {
  120. return;
  121. }
  122. JSONObject attr = null;
  123. for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
  124. attr = attrs.getJSONObject(attrIndex);
  125. attr.put("communityId", paramObj.getString("communityId"));
  126. communityBMOImpl.addAttr(attr, context);
  127. }
  128. }
  129. }