Commit 8f4650e1 by zhanghj

V1.4.1--技工订货单与供应链系统的对接代码提交

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@23904 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 0865771f
......@@ -127,7 +127,6 @@ public class HttpUtils {
* @throws ParseException
* @throws IOException
*/
@SuppressWarnings({ "deprecation", "resource" })
public String postJson(String url,String json) throws Exception{
String retVal = "";
DefaultHttpClient httpClient =null;
......
......@@ -127,4 +127,21 @@ public interface BizConstants {
public static final String SYS_ORDER_SERVICE_ITEM_GPS_WIRELESS = "sys_order_service_item_gps_wireless";
public static final String SYS_ORDER_SERVICE_ITEM_GPS_GT700F = "sys_order_service_item_gps_GT700F";
/**
* 供应链系统域名
*/
public static final String SUP_DOMAIN = "sup.domain";
/**
* 供应链同步订货单uri
*/
public static final String SUP_INDENT_ORDER_URI = "sup.indent.order.uri";
/**
* 供应链系统调用签名
*/
public static final String SUP_SIGN = "sup.sign";
/**
* 技工订货单默认商户编号
*/
public static final String SUP_MERCHANT_NO = "sup.merchant.no";
}
......@@ -48,6 +48,7 @@ import com.glsx.ordercenter.service.IndentLogisticsService;
import com.glsx.ordercenter.service.IndentService;
import com.glsx.ordercenter.service.LogisticsService;
import com.glsx.ordercenter.service.ReceiveAddressService;
import com.glsx.ordercenter.utils.IndentUtil;
@Service
public class IndentServiceImpl implements IndentService {
......@@ -91,6 +92,8 @@ public class IndentServiceImpl implements IndentService {
@SuppressWarnings("rawtypes")
@Autowired
private RedisCacheUtil redisCacheUtil;
@Autowired
private IndentUtil indentUtil;
@Override
@Transactional
......@@ -150,6 +153,12 @@ public class IndentServiceImpl implements IndentService {
int num = indentDao.insertSelective(indent);
if (num >0) {
/*
* 添加操作日志
*/
Integer id = indent.getId();
String remark = "新增订货单";
addIndentLog(id, null, remark);
/*
* 若是技工端,并且是给服务商发的订货单,发送短信
*/
if (Constants.USER_TYPE_MECHANIC == terminalType) {
......@@ -162,13 +171,10 @@ public class IndentServiceImpl implements IndentService {
logger.error("技工端增加订货单,发送短信给服务商失败", e);
}
}
//同步订货单状态到供应链系统
indentUtil.syncIndentToSUP(indent);
}
/*
* 添加操作日志
*/
Integer id = indent.getId();
String remark = "新增订货单";
addIndentLog(id, null, remark);
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
......@@ -450,6 +456,14 @@ public class IndentServiceImpl implements IndentService {
} catch (Exception e) {
logger.error("PC端取消发送取消订货短信通知失败", e);
}
} else if (Constants.USER_TYPE_MECHANIC == terminalType) {
//同步订货单状态到供应链系统
SysIndent sIndent = indent;
sIndent.setUpdateTime(sysIndent.getUpdateTime());
sIndent.setIndentStatus(IndentStatusEnum.INDENT_CANCEL.getIndentStatus());
sIndent.setRemark(remark);
indentUtil.syncIndentToSUP(sIndent);
}
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
......@@ -637,6 +651,15 @@ public class IndentServiceImpl implements IndentService {
*/
String remark = "确认收货";
addIndentLog(id, null, remark);
//同步订货单状态到供应链系统
if(userType == Constants.USER_TYPE_MECHANIC){
SysIndent sIndent = indent;
sIndent.setUpdateTime(sysIndent.getUpdateTime());
sIndent.setIndentStatus(IndentStatusEnum.INDENT_COMPLETE.getIndentStatus());
sIndent.setRemark(remark);
indentUtil.syncIndentToSUP(sIndent);
}
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
......
package com.glsx.ordercenter.utils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.IndentStatusEnum;
import com.glsx.ordercenter.pojo.SysIndent;
import com.glsx.ordercenter.service.IAreaService;
/**
*
* @Title IndentUtil.java
* @Package com.glsx.ordercenter.utils
* @Description TODO 订货单相关工具类
* @author zhanghj
* @date 2019年9月11日 下午4:28:37
* @version 1.0.0
*/
@Component
public class IndentUtil {
private Logger logger = LoggerFactory.getLogger(IndentUtil.class);
@Autowired
private IAreaService areaService;
/**
*
* @author zhanghj
* @Title: syncIndentToSUP
* @Description: TODO 业务系统订货单以及订货单状态同步到供应链系统
* @param indent
* void
*
*/
public void syncIndentToSUP(SysIndent indent) {
// TODO Auto-generated method stub
try {
logger.info("订货单同步到供应链系统参数" + indent.toString());
String domain = PropertiesUtil.getProperty(BizConstants.SUP_DOMAIN);
String uri = PropertiesUtil.getProperty(BizConstants.SUP_INDENT_ORDER_URI);
String sign = PropertiesUtil.getProperty(BizConstants.SUP_SIGN);
String toMerchantNo = PropertiesUtil.getProperty(BizConstants.SUP_MERCHANT_NO);
String params = "?function=syncOrderinfos&tosysflag=SUP&fromsysflag=FMS&issign=false&sign=";
//String uri = "http://sc.test.glsx.com.cn/web-supplychain/synchro/extern_system?function=syncOrderinfos&tosysflag=SUP&fromsysflag=FMS&issign=false&sign=a19bd1622d5bb9e2b9205599055636f6";
String url = domain + uri + params + sign;
String deviceType = indent.getDeviceType();
if (!BizConstants.SYS_ORDER_SERVICE_ITEM_GPS.equals(deviceType) && !BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_WIRELESS.equals(deviceType)
&& !BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_GT700F.equals(deviceType)) {
return;
}
String indentNo = indent.getIndentNo();
Date createTime = indent.getCreateTime();
Long createTimeMill = null;
if (createTime != null) {
createTimeMill = createTime.getTime();
} else {
createTimeMill = System.currentTimeMillis();
}
Date expectedTime = DateUtil.getOffsetDayDate(createTime, 3);
long expectedTimestamp = expectedTime.getTime();
List<String> productList = transProductNoToSUP(deviceType);
String productNo = productList.get(0);
String productName = productList.get(1);
int deviceAmount = indent.getDeviceAmount();
Integer districtCode = indent.getDistrictCode();
String address = indent.getAddress();
String districtAddress = "";
if (districtCode != null && !districtCode.equals(0)) {
districtAddress = areaService.getFullAreaByDistrictId(districtCode);
}
String fullAddress = districtAddress + address;
String receiverName = indent.getReceiverName();
String phone = indent.getPhone();
Date updateTime = indent.getUpdateTime();
Long updateTimeMill = null;
if (updateTime != null) {
updateTimeMill = updateTime.getTime();
} else {
updateTimeMill = createTimeMill;
}
Integer indentStatus = indent.getIndentStatus();
String orderStatus = transIndentStatusToSUP(indentStatus);
String remark = indent.getRemark();
JSONObject data = new JSONObject();
JSONArray orderInfos = new JSONArray();
JSONObject orderInfo = new JSONObject();
orderInfo.put("orderno", indentNo);
orderInfo.put("ordertimestamp", createTimeMill);
orderInfo.put("tomerchantno", toMerchantNo);
orderInfo.put("productno", productNo);
orderInfo.put("productname", productName);
orderInfo.put("productquantity", deviceAmount);
orderInfo.put("contactname", receiverName);
orderInfo.put("contactphone", phone);
orderInfo.put("contactaddress",fullAddress);
orderInfo.put("expectedtimestamp", expectedTimestamp);
orderInfo.put("updatetime",updateTimeMill);
orderInfo.put("orderstatu", orderStatus);
orderInfo.put("remark", remark);
orderInfos.add(orderInfo);
data.put("total", 1);
data.put("orderinfos", orderInfos);
String bodyData = JSONObject.toJSONString(data);
logger.info("货单同步到供应链系统body数据=" + bodyData);
HttpUtils httpUtils = new HttpUtils();
String result = httpUtils.postJson(url, bodyData);
logger.info("订货单同步到供应链系统结果=" + result);
} catch (Exception e) {
logger.info("订货单同步到供应链系统异常" + e);
}
}
/**
*
* @author zhanghj
* @Title: transProductNoToSUP
* @Description: TODO 转换包活干设备类型到供应链系统对应的产品编号
* @param deviceType
* @return
* Map<String,String>
*
*/
private List<String> transProductNoToSUP(String deviceType) {
// TODO Auto-generated method stub
List<String> list = new ArrayList<String>();
if (BizConstants.SYS_ORDER_SERVICE_ITEM_GPS.equals(deviceType)) {
list.add("GPS016");
list.add("有源GPS设备(GT800B)");
return list;
} else if (BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_WIRELESS.equals(deviceType)) {
list.add("GPS015");
list.add("无源GPS设备(GT803)");
return list;
} else {
list.add("GPS017");
list.add("有源GPS设备(GT800F)");
return list;
}
}
/**
*
* @author zhanghj
* @Title: transIndentStatusToSUP
* @Description: TODO 把包活干的订单状态转换成供应链系统的订单状态
* 供应链订单状态:(0:已驳回,1:待审核,2:待发货,3:待签收,4:部分签收,5:已完成,6:已开票,7:已作废)
*
* @param indentStatus
* @return
* String
*
*/
private String transIndentStatusToSUP(Integer indentStatus) {
// TODO Auto-generated method stub
if (IndentStatusEnum.INDENT_UNCHECKED.getIndentStatus() == indentStatus) {
return "1";
} else if (IndentStatusEnum.INDENT_COMPLETE.getIndentStatus() == indentStatus) {
return "5";
} else if (IndentStatusEnum.INDENT_CANCEL.getIndentStatus() == indentStatus) {
return "7";
}
return null;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!