BsOmsPickInboundFeedbackSubscriber.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. *
  3. * Copyright (c) behosoft Co.,Ltd.
  4. * All Rights Reserved.
  5. *
  6. * This software is the confidential and proprietary information of behosoft.
  7. * (Social Security Department). You shall not disclose such
  8. * Confidential Information and shall use it only in accordance with
  9. * the terms of the license agreement you entered into with behosoft.
  10. *
  11. * Distributable under GNU LGPL license by gnu.org
  12. */
  13. package com.behosoft.lis.common.subscriber;
  14. import java.io.Serializable;
  15. import java.util.ArrayList;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import net.sf.json.JSONArray;
  21. import net.sf.json.JSONObject;
  22. import org.apache.commons.collections.CollectionUtils;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import com.behosoft.lis.crm.customer.service.CustomerService;
  27. import com.behosoft.lis.model.bo.AccountConfig;
  28. import com.behosoft.lis.model.bo.OmsPickInbound;
  29. import com.behosoft.lis.model.bo.ShelvesTask;
  30. import com.behosoft.lis.model.bo.SnInLocation;
  31. import com.behosoft.lis.model.vo.CustomerVO;
  32. import com.behosoft.lis.oms.pickinbound.service.OmsPickInboundService;
  33. import com.behosoft.lis.sys.accountconfig.service.AccountConfigService;
  34. import com.behosoft.lis.wms.shelves.service.ShelvesTaskService;
  35. import com.behosoft.lis.wms.sninlocation.service.SnInLocationService;
  36. import com.behosoft.util.HttpUtils;
  37. import com.wondersgroup.saas.message.common.SerializableMessage;
  38. import com.wondersgroup.saas.message.common.WrappedMessage;
  39. import com.wondersgroup.saas.message.subscribe.AbstractDataSubscriber;
  40. import com.wondersgroup.saas.util.JSONUtil;
  41. /**
  42. * <p>
  43. * Title: 百弘电商物流标准版_[]_[模块名]
  44. * </p>
  45. * <p>
  46. * Description: [百胜采购订单反馈]
  47. * </p>
  48. *
  49. * @author chenxinglong
  50. * @version 1.0 2019-01-31
  51. * @author (lastest modification by )
  52. * @since 1.0
  53. */
  54. public class BsOmsPickInboundFeedbackSubscriber extends AbstractDataSubscriber<WrappedMessage> {
  55. private final Log logger = LogFactory.getLog(this.getClass());
  56. @Autowired
  57. private AccountConfigService accountConfigService;
  58. @Autowired
  59. private CustomerService customerService;
  60. @Autowired
  61. private ShelvesTaskService shelvesTaskService;
  62. @Autowired
  63. private SnInLocationService snInLocationService;
  64. @Autowired
  65. private OmsPickInboundService omsPickInboundService;
  66. @Override
  67. public void receive(WrappedMessage param) {
  68. List<Serializable> serializables = ((SerializableMessage) param).getFilteredObjects();
  69. Date date = (Date) serializables.get(0);
  70. logger.info("enter BsOmsPickInboundFeedbackSubscriber get date is:" + date);
  71. List<AccountConfig> accountConfigList = accountConfigService.getValueByKey("BS_CUSTOMER_CODE");
  72. if (CollectionUtils.isEmpty(accountConfigList)) {
  73. logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:BS_CUSTOMER_CODE");
  74. return;
  75. }
  76. //查询JSBS货主
  77. List<CustomerVO> customerList = customerService.findCustomerByCustomerCode(accountConfigList.get(0).getAttributeValue());
  78. if (CollectionUtils.isEmpty(customerList)) {
  79. logger.info("百胜采购订单反馈,未配置货主:江苏百胜");
  80. return;
  81. }
  82. CustomerVO customer = customerList.get(0);
  83. JSONObject jsonObject = accountConfigService.getMapByKey3("BS_OMSPICKINBOUND_FEEDBACK");
  84. if(jsonObject != null){
  85. if(!jsonObject.containsKey("URL") || jsonObject.get("URL") == null){
  86. logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:URL");
  87. return;
  88. }
  89. //获取百胜ERP服务端信息
  90. String url = jsonObject.getString("URL");
  91. //组装请求报文,并发送请求
  92. packingRequestData(customer, url);
  93. }
  94. else{
  95. logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:BS_OMSPICKINBOUND_FEEDBACK");
  96. return;
  97. }
  98. logger.info("exit BsOmsPickInboundFeedbackSubscriber");
  99. }
  100. /**
  101. * 组装请求报文
  102. */
  103. private void packingRequestData(CustomerVO customer, String url){
  104. Map<String, Object> params = new HashMap<String, Object>();
  105. params.put("url", url);
  106. //采购订单状态集合
  107. List<String> pickInboundStatusList = new ArrayList<String>();
  108. //入储单状态集合
  109. List<String> shelvesStatusList = new ArrayList<String>();
  110. //采购订单号集合
  111. List<String> pickInboundIdList = new ArrayList<String>();
  112. //已完成收货
  113. pickInboundStatusList.add("4704");
  114. //已入储
  115. shelvesStatusList.add("6402");
  116. //查询符合反馈条件的入储单
  117. List<ShelvesTask> shelvesTaskList =
  118. shelvesTaskService.queryByPickInboundId(customer.getAccountId(), customer.getCustomerId(), pickInboundStatusList, shelvesStatusList);
  119. if (CollectionUtils.isNotEmpty(shelvesTaskList)) {
  120. //收集符合条件的采购订单号
  121. for (ShelvesTask shelvesTask : shelvesTaskList) {
  122. pickInboundIdList.add(shelvesTask.getPickInboundId());
  123. }
  124. //map:采购订单号
  125. Map<String, List<SnInLocation>> inboundIdMap = new HashMap<String, List<SnInLocation>>();
  126. //查询所有符合条件的sn入库记录
  127. List<SnInLocation> allSnInLocationList = snInLocationService.queryByPickInboundId(pickInboundIdList);
  128. if (CollectionUtils.isNotEmpty(allSnInLocationList)) {
  129. //根据采购订单号分组
  130. for (SnInLocation snInLocation : allSnInLocationList) {
  131. if (!inboundIdMap.containsKey(snInLocation.getInboundId())) {
  132. List<SnInLocation> temp = new ArrayList<SnInLocation>();
  133. temp.add(snInLocation);
  134. inboundIdMap.put(snInLocation.getInboundId(), temp);
  135. }
  136. else{
  137. List<SnInLocation> temp = inboundIdMap.get(snInLocation.getInboundId());
  138. temp.add(snInLocation);
  139. inboundIdMap.put(snInLocation.getInboundId(), temp);
  140. }
  141. }
  142. //map:商品id
  143. Map<String, List<SnInLocation>> itemIdMap = new HashMap<String, List<SnInLocation>>();
  144. for (String inboundId : inboundIdMap.keySet()) {
  145. //同一采购订单下的sn入库记录
  146. List<SnInLocation> snInLocationList = inboundIdMap.get(inboundId);
  147. //根据商品id分组
  148. for (SnInLocation snInLocation : snInLocationList) {
  149. if (!itemIdMap.containsKey(snInLocation.getItemId())) {
  150. List<SnInLocation> temp = new ArrayList<SnInLocation>();
  151. temp.add(snInLocation);
  152. itemIdMap.put(snInLocation.getItemId(), temp);
  153. }
  154. else{
  155. List<SnInLocation> temp = itemIdMap.get(snInLocation.getItemId());
  156. temp.add(snInLocation);
  157. itemIdMap.put(snInLocation.getItemId(), temp);
  158. }
  159. }
  160. //查询采购订单
  161. OmsPickInbound omsPickInbound = omsPickInboundService.getEntityById(inboundId, OmsPickInbound.class);
  162. //组装请求报文
  163. if (null != omsPickInbound) {
  164. JSONObject request = new JSONObject();
  165. request.put("customerRefferenceId", omsPickInbound.getCustomerRefferenceId());
  166. request.put("warehouseCode", omsPickInbound.getWarehouseName());
  167. request.put("senderCode", omsPickInbound.getSenderCode());
  168. JSONArray itemListJsonArray = new JSONArray();
  169. //组装itemList节点报文
  170. for (String itemId : itemIdMap.keySet()) {
  171. List<SnInLocation> itemList = itemIdMap.get(itemId);
  172. StringBuffer snListSb = new StringBuffer();
  173. for (int i = 0; i < itemList.size(); i++) {
  174. if (i == (itemList.size() - 1)) {
  175. snListSb.append(itemList.get(i).getSn());
  176. }
  177. else{
  178. snListSb.append(itemList.get(i).getSn()).append(",");
  179. }
  180. }
  181. JSONObject itemJsonObject = new JSONObject();
  182. itemJsonObject.put("itemCode", itemList.get(0).getItemCode());
  183. itemJsonObject.put("snList", snListSb.toString());
  184. itemListJsonArray.add(itemJsonObject);
  185. }
  186. request.put("itemList", itemListJsonArray);
  187. params.put("requestData", request.toString());
  188. }
  189. //发送请求,并获取响应
  190. Map<String, String> result = HttpUtils.httpPost(params);
  191. if (result.containsKey("response") && result.get("response") != null) {
  192. JSONObject json = JSONObject.fromObject(result.get("response"), JSONUtil.getJsonConfig());
  193. //如果响应成功,更新采购单是否反馈标识为是
  194. if (json.containsKey("resultCode") && json.get("resultCode") != null && "0".equals(json.get("resultCode").toString())) {
  195. omsPickInbound.setIsFeedback(1);
  196. omsPickInboundService.updateEntity(omsPickInbound);
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }