123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /**
- *
- * Copyright (c) behosoft Co.,Ltd.
- * All Rights Reserved.
- *
- * This software is the confidential and proprietary information of behosoft.
- * (Social Security Department). You shall not disclose such
- * Confidential Information and shall use it only in accordance with
- * the terms of the license agreement you entered into with behosoft.
- *
- * Distributable under GNU LGPL license by gnu.org
- */
- package com.behosoft.lis.common.subscriber;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import org.apache.commons.collections.CollectionUtils;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import com.behosoft.lis.crm.customer.service.CustomerService;
- import com.behosoft.lis.model.bo.AccountConfig;
- import com.behosoft.lis.model.bo.OmsPickInbound;
- import com.behosoft.lis.model.bo.ShelvesTask;
- import com.behosoft.lis.model.bo.SnInLocation;
- import com.behosoft.lis.model.vo.CustomerVO;
- import com.behosoft.lis.oms.pickinbound.service.OmsPickInboundService;
- import com.behosoft.lis.sys.accountconfig.service.AccountConfigService;
- import com.behosoft.lis.wms.shelves.service.ShelvesTaskService;
- import com.behosoft.lis.wms.sninlocation.service.SnInLocationService;
- import com.behosoft.util.HttpUtils;
- import com.wondersgroup.saas.message.common.SerializableMessage;
- import com.wondersgroup.saas.message.common.WrappedMessage;
- import com.wondersgroup.saas.message.subscribe.AbstractDataSubscriber;
- import com.wondersgroup.saas.util.JSONUtil;
- /**
- * <p>
- * Title: 百弘电商物流标准版_[]_[模块名]
- * </p>
- * <p>
- * Description: [百胜采购订单反馈]
- * </p>
- *
- * @author chenxinglong
- * @version 1.0 2019-01-31
- * @author (lastest modification by )
- * @since 1.0
- */
- public class BsOmsPickInboundFeedbackSubscriber extends AbstractDataSubscriber<WrappedMessage> {
- private final Log logger = LogFactory.getLog(this.getClass());
- @Autowired
- private AccountConfigService accountConfigService;
-
- @Autowired
- private CustomerService customerService;
-
- @Autowired
- private ShelvesTaskService shelvesTaskService;
-
- @Autowired
- private SnInLocationService snInLocationService;
-
- @Autowired
- private OmsPickInboundService omsPickInboundService;
-
- @Override
- public void receive(WrappedMessage param) {
- List<Serializable> serializables = ((SerializableMessage) param).getFilteredObjects();
- Date date = (Date) serializables.get(0);
- logger.info("enter BsOmsPickInboundFeedbackSubscriber get date is:" + date);
-
- List<AccountConfig> accountConfigList = accountConfigService.getValueByKey("BS_CUSTOMER_CODE");
-
- if (CollectionUtils.isEmpty(accountConfigList)) {
- logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:BS_CUSTOMER_CODE");
- return;
- }
-
- //查询JSBS货主
- List<CustomerVO> customerList = customerService.findCustomerByCustomerCode(accountConfigList.get(0).getAttributeValue());
-
- if (CollectionUtils.isEmpty(customerList)) {
- logger.info("百胜采购订单反馈,未配置货主:江苏百胜");
- return;
- }
- CustomerVO customer = customerList.get(0);
-
- JSONObject jsonObject = accountConfigService.getMapByKey3("BS_OMSPICKINBOUND_FEEDBACK");
-
- if(jsonObject != null){
- if(!jsonObject.containsKey("URL") || jsonObject.get("URL") == null){
- logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:URL");
- return;
- }
- //获取百胜ERP服务端信息
- String url = jsonObject.getString("URL");
- //组装请求报文,并发送请求
- packingRequestData(customer, url);
- }
- else{
- logger.info("百胜采购订单反馈,账户配置表(sys_account_config)未配置:BS_OMSPICKINBOUND_FEEDBACK");
- return;
- }
- logger.info("exit BsOmsPickInboundFeedbackSubscriber");
- }
-
- /**
- * 组装请求报文
- */
- private void packingRequestData(CustomerVO customer, String url){
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("url", url);
- //采购订单状态集合
- List<String> pickInboundStatusList = new ArrayList<String>();
- //入储单状态集合
- List<String> shelvesStatusList = new ArrayList<String>();
- //采购订单号集合
- List<String> pickInboundIdList = new ArrayList<String>();
- //已完成收货
- pickInboundStatusList.add("4704");
- //已入储
- shelvesStatusList.add("6402");
- //查询符合反馈条件的入储单
- List<ShelvesTask> shelvesTaskList =
- shelvesTaskService.queryByPickInboundId(customer.getAccountId(), customer.getCustomerId(), pickInboundStatusList, shelvesStatusList);
-
- if (CollectionUtils.isNotEmpty(shelvesTaskList)) {
- //收集符合条件的采购订单号
- for (ShelvesTask shelvesTask : shelvesTaskList) {
- pickInboundIdList.add(shelvesTask.getPickInboundId());
- }
- //map:采购订单号
- Map<String, List<SnInLocation>> inboundIdMap = new HashMap<String, List<SnInLocation>>();
- //查询所有符合条件的sn入库记录
- List<SnInLocation> allSnInLocationList = snInLocationService.queryByPickInboundId(pickInboundIdList);
-
- if (CollectionUtils.isNotEmpty(allSnInLocationList)) {
- //根据采购订单号分组
- for (SnInLocation snInLocation : allSnInLocationList) {
- if (!inboundIdMap.containsKey(snInLocation.getInboundId())) {
- List<SnInLocation> temp = new ArrayList<SnInLocation>();
- temp.add(snInLocation);
-
- inboundIdMap.put(snInLocation.getInboundId(), temp);
- }
- else{
- List<SnInLocation> temp = inboundIdMap.get(snInLocation.getInboundId());
- temp.add(snInLocation);
-
- inboundIdMap.put(snInLocation.getInboundId(), temp);
- }
- }
- //map:商品id
- Map<String, List<SnInLocation>> itemIdMap = new HashMap<String, List<SnInLocation>>();
- for (String inboundId : inboundIdMap.keySet()) {
- //同一采购订单下的sn入库记录
- List<SnInLocation> snInLocationList = inboundIdMap.get(inboundId);
- //根据商品id分组
- for (SnInLocation snInLocation : snInLocationList) {
- if (!itemIdMap.containsKey(snInLocation.getItemId())) {
- List<SnInLocation> temp = new ArrayList<SnInLocation>();
- temp.add(snInLocation);
-
- itemIdMap.put(snInLocation.getItemId(), temp);
- }
- else{
- List<SnInLocation> temp = itemIdMap.get(snInLocation.getItemId());
- temp.add(snInLocation);
-
- itemIdMap.put(snInLocation.getItemId(), temp);
- }
- }
- //查询采购订单
- OmsPickInbound omsPickInbound = omsPickInboundService.getEntityById(inboundId, OmsPickInbound.class);
- //组装请求报文
- if (null != omsPickInbound) {
- JSONObject request = new JSONObject();
- request.put("customerRefferenceId", omsPickInbound.getCustomerRefferenceId());
- request.put("warehouseCode", omsPickInbound.getWarehouseName());
- request.put("senderCode", omsPickInbound.getSenderCode());
-
- JSONArray itemListJsonArray = new JSONArray();
- //组装itemList节点报文
- for (String itemId : itemIdMap.keySet()) {
- List<SnInLocation> itemList = itemIdMap.get(itemId);
- StringBuffer snListSb = new StringBuffer();
-
- for (int i = 0; i < itemList.size(); i++) {
- if (i == (itemList.size() - 1)) {
- snListSb.append(itemList.get(i).getSn());
- }
- else{
- snListSb.append(itemList.get(i).getSn()).append(",");
- }
- }
- JSONObject itemJsonObject = new JSONObject();
- itemJsonObject.put("itemCode", itemList.get(0).getItemCode());
- itemJsonObject.put("snList", snListSb.toString());
- itemListJsonArray.add(itemJsonObject);
- }
- request.put("itemList", itemListJsonArray);
-
- params.put("requestData", request.toString());
- }
- //发送请求,并获取响应
- Map<String, String> result = HttpUtils.httpPost(params);
-
- if (result.containsKey("response") && result.get("response") != null) {
- JSONObject json = JSONObject.fromObject(result.get("response"), JSONUtil.getJsonConfig());
-
- //如果响应成功,更新采购单是否反馈标识为是
- if (json.containsKey("resultCode") && json.get("resultCode") != null && "0".equals(json.get("resultCode").toString())) {
- omsPickInbound.setIsFeedback(1);
-
- omsPickInboundService.updateEntity(omsPickInbound);
- }
- }
- }
- }
- }
- }
- }
|