SaveItemReleaseCmd.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.itemRelease;
  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.itemRelease.ItemReleaseDto;
  27. import com.java110.dto.itemReleaseType.ItemReleaseTypeDto;
  28. import com.java110.dto.oaWorkflow.OaWorkflowDto;
  29. import com.java110.dto.user.UserDto;
  30. import com.java110.intf.common.IItemReleaseResV1InnerServiceSMO;
  31. import com.java110.intf.common.IItemReleaseTypeV1InnerServiceSMO;
  32. import com.java110.intf.common.IItemReleaseV1InnerServiceSMO;
  33. import com.java110.intf.common.IOaWorkflowActivitiInnerServiceSMO;
  34. import com.java110.intf.oa.IOaWorkflowInnerServiceSMO;
  35. import com.java110.intf.user.IUserInnerServiceSMO;
  36. import com.java110.po.itemRelease.ItemReleasePo;
  37. import com.java110.po.itemReleaseRes.ItemReleaseResPo;
  38. import com.java110.utils.exception.CmdException;
  39. import com.java110.utils.util.Assert;
  40. import com.java110.utils.util.BeanConvertUtil;
  41. import com.java110.utils.util.StringUtil;
  42. import com.java110.vo.ResultVo;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.slf4j.Logger;
  45. import org.slf4j.LoggerFactory;
  46. import java.util.ArrayList;
  47. import java.util.List;
  48. @Java110CmdDoc(title = "申请物品放行",
  49. description = "申请物品放行",
  50. httpMethod = "post",
  51. url = "http://{ip}:{port}/app/itemRelease.saveItemRelease",
  52. resource = "commonDoc",
  53. author = "吴学文",
  54. serviceCode = "itemRelease.saveItemRelease"
  55. )
  56. @Java110ParamsDoc(params = {
  57. @Java110ParamDoc(name = "typeId", length = 30, remark = "放行ID"),
  58. @Java110ParamDoc(name = "communityId", length = 30, remark = "放行小区"),
  59. @Java110ParamDoc(name = "applyCompany", length = 30, remark = "申请单位"),
  60. @Java110ParamDoc(name = "applyPerson", length = 30, remark = "申请人"),
  61. @Java110ParamDoc(name = "idCard", length = 30, remark = "身份证"),
  62. @Java110ParamDoc(name = "applyTel", length = 30, remark = "申请电话"),
  63. @Java110ParamDoc(name = "passTime", length = 30, remark = "通信时间"),
  64. @Java110ParamDoc(name = "amount", length = 30, remark = "数量"),
  65. })
  66. @Java110ResponseDoc(
  67. params = {
  68. @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "返回编号,0 成功 其他失败"),
  69. @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "成功", remark = "描述"),
  70. }
  71. )
  72. @Java110ExampleDoc(
  73. reqBody="{\n" +
  74. "\t\"irId\": \"\",\n" +
  75. "\t\"typeId\": \"102023011264340006\",\n" +
  76. "\t\"applyCompany\": \"123123\",\n" +
  77. "\t\"applyPerson\": \"12312\",\n" +
  78. "\t\"idCard\": \"12312\",\n" +
  79. "\t\"applyTel\": \"18909711443\",\n" +
  80. "\t\"passTime\": \"2023-01-13 11:55:00\",\n" +
  81. "\t\"resNames\": [{\n" +
  82. "\t\t\"resName\": \"123\",\n" +
  83. "\t\t\"amount\": \"123\"\n" +
  84. "\t}],\n" +
  85. "\t\"state\": \"\",\n" +
  86. "\t\"carNum\": \"123123\",\n" +
  87. "\t\"remark\": \"123\",\n" +
  88. "\t\"audit\": {\n" +
  89. "\t\t\"assignee\": \"-2\",\n" +
  90. "\t\t\"staffId\": \"\",\n" +
  91. "\t\t\"staffName\": \"\",\n" +
  92. "\t\t\"taskId\": \"\"\n" +
  93. "\t},\n" +
  94. "\t\"communityId\": \"2022120695590004\"\n" +
  95. "}",
  96. resBody="{'code':0,'msg':'成功'}"
  97. )
  98. /**
  99. * 类表述:保存
  100. * 服务编码:itemRelease.saveItemRelease
  101. * 请求路劲:/app/itemRelease.SaveItemRelease
  102. * add by 吴学文 at 2023-01-11 15:40:01 mail: 928255095@qq.com
  103. * open source address: https://gitee.com/wuxw7/MicroCommunity
  104. * 官网:http://www.homecommunity.cn
  105. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  106. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  107. */
  108. @Java110Cmd(serviceCode = "itemRelease.saveItemRelease")
  109. public class SaveItemReleaseCmd extends Cmd {
  110. private static Logger logger = LoggerFactory.getLogger(SaveItemReleaseCmd.class);
  111. public static final String CODE_PREFIX_ID = "10";
  112. @Autowired
  113. private IItemReleaseV1InnerServiceSMO itemReleaseV1InnerServiceSMOImpl;
  114. @Autowired
  115. private IItemReleaseResV1InnerServiceSMO itemReleaseResV1InnerServiceSMOImpl;
  116. @Autowired
  117. private IItemReleaseTypeV1InnerServiceSMO itemReleaseTypeV1InnerServiceSMOImpl;
  118. @Autowired
  119. private IOaWorkflowInnerServiceSMO oaWorkflowInnerServiceSMOImpl;
  120. @Autowired
  121. private IUserInnerServiceSMO userInnerServiceSMOImpl;
  122. @Autowired
  123. private IOaWorkflowActivitiInnerServiceSMO oaWorkflowActivitiInnerServiceSMOImpl;
  124. @Override
  125. public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
  126. Assert.hasKeyAndValue(reqJson, "typeId", "请求报文中未包含typeId");
  127. Assert.hasKeyAndValue(reqJson, "applyCompany", "请求报文中未包含applyCompany");
  128. Assert.hasKeyAndValue(reqJson, "applyPerson", "请求报文中未包含applyPerson");
  129. Assert.hasKeyAndValue(reqJson, "idCard", "请求报文中未包含idCard");
  130. Assert.hasKeyAndValue(reqJson, "applyTel", "请求报文中未包含applyTel");
  131. Assert.hasKeyAndValue(reqJson, "passTime", "请求报文中未包含passTime");
  132. Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
  133. //校验物品是否存在
  134. if(!reqJson.containsKey("resNames")){
  135. throw new CmdException("未包含物品");
  136. }
  137. JSONArray resNames = reqJson.getJSONArray("resNames");
  138. if(resNames == null || resNames.size() < 1){
  139. throw new CmdException("未包含物品");
  140. }
  141. }
  142. @Override
  143. @Java110Transactional
  144. public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
  145. String userId = cmdDataFlowContext.getReqHeaders().get("user-id");
  146. ItemReleaseTypeDto itemReleaseTypeDto = new ItemReleaseTypeDto();
  147. itemReleaseTypeDto.setTypeId(reqJson.getString("typeId"));
  148. itemReleaseTypeDto.setCommunityId(reqJson.getString("communityId"));
  149. List<ItemReleaseTypeDto> itemReleaseTypeDtos = itemReleaseTypeV1InnerServiceSMOImpl.queryItemReleaseTypes(itemReleaseTypeDto);
  150. Assert.listOnlyOne(itemReleaseTypeDtos,"未包含放行类型");
  151. OaWorkflowDto oaWorkflowDto = new OaWorkflowDto();
  152. oaWorkflowDto.setStoreId(itemReleaseTypeDtos.get(0).getStoreId());
  153. oaWorkflowDto.setFlowId(itemReleaseTypeDtos.get(0).getFlowId());
  154. List<OaWorkflowDto> oaWorkflowDtos = oaWorkflowInnerServiceSMOImpl.queryOaWorkflows(oaWorkflowDto);
  155. Assert.listOnlyOne(oaWorkflowDtos, "流程不存在");
  156. if (!OaWorkflowDto.STATE_COMPLAINT.equals(oaWorkflowDtos.get(0).getState())) {
  157. throw new IllegalArgumentException(oaWorkflowDtos.get(0).getFlowName() + "流程未部署");
  158. }
  159. if (StringUtil.isEmpty(oaWorkflowDtos.get(0).getProcessDefinitionKey())) {
  160. throw new IllegalArgumentException(oaWorkflowDtos.get(0).getFlowName() + "流程未部署");
  161. }
  162. //查询用户名称
  163. UserDto userDto = new UserDto();
  164. userDto.setUserId(userId);
  165. List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
  166. Assert.listOnlyOne(userDtos, "用户不存在");
  167. ItemReleasePo itemReleasePo = BeanConvertUtil.covertBean(reqJson, ItemReleasePo.class);
  168. itemReleasePo.setIrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
  169. itemReleasePo.setState(ItemReleaseDto.STATE_WAIT);
  170. itemReleasePo.setCreateUserId(userId);
  171. int flag = itemReleaseV1InnerServiceSMOImpl.saveItemRelease(itemReleasePo);
  172. if (flag < 1) {
  173. throw new CmdException("保存数据失败");
  174. }
  175. JSONArray resNames = reqJson.getJSONArray("resNames");
  176. JSONObject resNameObj = null;
  177. ItemReleaseResPo itemReleaseResPo = null;
  178. List<ItemReleaseResPo> itemReleaseResPos = new ArrayList<>();
  179. for(int resNameIndex = 0; resNameIndex< resNames.size(); resNameIndex++){
  180. resNameObj = resNames.getJSONObject(resNameIndex);
  181. itemReleaseResPo = new ItemReleaseResPo();
  182. itemReleaseResPo.setAmount(resNameObj.getString("amount"));
  183. itemReleaseResPo.setResName(resNameObj.getString("resName"));
  184. itemReleaseResPo.setResId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
  185. itemReleaseResPo.setIrId(itemReleasePo.getIrId());
  186. itemReleaseResPo.setCommunityId(itemReleasePo.getCommunityId());
  187. itemReleaseResPos.add(itemReleaseResPo);
  188. }
  189. flag = itemReleaseResV1InnerServiceSMOImpl.saveItemReleaseReses(itemReleaseResPos);
  190. if (flag < 1) {
  191. throw new CmdException("保存数据失败");
  192. }
  193. //启动任务
  194. JSONObject flowJson = new JSONObject();
  195. flowJson.put("processDefinitionKey", oaWorkflowDtos.get(0).getProcessDefinitionKey());
  196. flowJson.put("createUserId",userId);
  197. flowJson.put("flowId",oaWorkflowDtos.get(0).getFlowId());
  198. flowJson.put("id",itemReleasePo.getIrId());
  199. flowJson.put("auditMessage","提交审核");
  200. flowJson.put("storeId",itemReleaseTypeDtos.get(0).getStoreId());
  201. reqJson.put("processDefinitionKey", oaWorkflowDtos.get(0).getProcessDefinitionKey());
  202. JSONObject result = oaWorkflowActivitiInnerServiceSMOImpl.startProcess(flowJson);
  203. //提交者提交
  204. flowJson = new JSONObject();
  205. flowJson.put("processInstanceId",result.getString("processInstanceId"));
  206. flowJson.put("createUserId",userId);
  207. flowJson.put("nextUserId",reqJson.getJSONObject("audit").getString("staffId"));
  208. flowJson.put("storeId",itemReleaseTypeDtos.get(0).getStoreId());
  209. flowJson.put("id",itemReleasePo.getIrId());
  210. flowJson.put("flowId",oaWorkflowDtos.get(0).getFlowId());
  211. oaWorkflowActivitiInnerServiceSMOImpl.autoFinishFirstTask(flowJson);
  212. cmdDataFlowContext.setResponseEntity(ResultVo.success());
  213. }
  214. }