1ba87f72 刘嘉

菠萝派接口-发货接口

1 个父辈 2f6a3a63
package com.sibu.orderHelper.integral.dao;
import com.sibu.orderHelper.integral.model.*;
import com.sibu.orderHelper.integral.pineapple.model.Orders;
import com.sibu.orderHelper.integral.pineapple.model.OrdersProduct;
import com.sibu.orderHelper.integral.pineapple.model.Product;
import com.sibu.orderHelper.integral.pineapple.model.*;
import com.sibu.orderHelper.integral.reponse.CheckRefundStatusResponse;
import com.sibu.orderHelper.integral.reponse.DoingOrderDetailResponse;
import com.sibu.orderHelper.integral.reponse.SkuApiResponse;
......@@ -86,4 +84,28 @@ public interface PineappleDao {
List<OrdersProduct> getOrdersProductList(@Param("orderSn")String orderSn);
/**
* 根据条件查询省市级信息
* @param params
* @return
*/
Regions getRegionsByMap(Map<String,Object> params);
/**
* 根据id查询省市级信息
* @param id
* @return
*/
Regions getRegionsById(@Param("id") Integer id);
/**
* 根据条件查询物流公司
* @return
*/
List<CourierCompany> getCourierCompanyByName(Map<String,Object> params);
}
......
......@@ -68,9 +68,6 @@
<if test="addressInfo !=null and addressInfo !=''">
address_info = #{addressInfo},
</if>
<if test="deliverTime !=null and deliverTime !=''">
deliver_time = #{deliverTime},
</if>
<if test="logisticsNumber !=null and logisticsNumber !=''">
logistics_number = #{logisticsNumber},
</if>
......@@ -123,9 +120,12 @@
<if test="productId !=null and productId !=''">
AND (p.id = #{productId} or p.product_code = #{productId}
</if>
<if test="state !=null and state !=''">
<if test="state !=null and state !='' and state != -1">
AND p.state = #{state}
</if>
<if test="state !=null and state !='' and state == -1">
AND p.state IN ('6','7')
</if>
<if test="productName !=null and productName !=''">
AND p.state = #{productName}
</if>
......@@ -223,4 +223,53 @@
SELECT product_sku,id,product_name,spec_info,number,money_price,money_act_single FROM orders_product
WHERE orders_sn = #{ordersSn}
</select>
<!-- 地址实体类-->
<resultMap id="regionsResult" type="com.sibu.orderHelper.integral.pineapple.model.Regions">
<result property="id" column="id" />
<result property="parentId" column="parentId" />
<result property="regionName" column="regionName" />
<result property="parentPath" column="parentPath" />
<result property="firstLetter" column="firstLetter" />
<result property="regionType" column="regionType" />
<result property="agencyId" column="agencyId" />
<result property="shippingId" column="shippingId" />
<result property="visible" column="visible" />
<result property="rowId" column="rowId" />
</resultMap>
<!-- 根据条件查询省市级信息-->
<select id="getRegionsByMap" parameterType="java.util.Map" resultMap="regionsResult">
SELECT * FROM regions WHERE regionName LIKE concat('%',#{name},'%') AND regionType = #{regionType}
</select>
<!-- 根据id查询省市级信息-->
<select id="getRegionsById" parameterType="java.lang.Integer" resultMap="regionsResult">
select
*
from `regions`
where `id` = #{id}
</select>
<!-- 物流公司实体-->
<resultMap id="courierCompanyResult" type="com.sibu.orderHelper.integral.pineapple.model.CourierCompany">
<result property="id" column="id" />
<result property="createTime" column="create_time" />
<result property="state" column="state" />
<result property="companyMark" column="company_mark" />
<result property="companyName" column="company_name" />
<result property="seq" column="seq" />
<result property="sellerId" column="seller_id" />
<result property="companyType" column="company_type" />
<result property="imagePath" column="image_path" />
<result property="content" column="content" />
</resultMap>
<!-- 根据条件查询物流公司-->
<select id="getCourierCompanyByName" parameterType="java.util.Map" resultMap="courierCompanyResult">
select
*
from `courier_company`
where company_name LIKE concat('%',#{name},'%') AND seller_id =#{sellerId}
</select>
</mapper>
\ No newline at end of file
......
package com.sibu.orderHelper.integral.pineapple.enums;
import com.alibaba.druid.util.StringUtils;
import com.sibu.orderHelper.enums.PayOrderStatus;
import com.sibu.orderHelper.integral.pineapple.constant.PineAppleConst;
import org.apache.commons.lang3.EnumUtils;
import java.util.List;
/**
* @author LauKa
* @contact a062431@vip.qq.com
* @date 2018/05/15
* @description 新系统丁订单状态
*/
public enum EJavaShopOrderStateEnum {
WaitPay(1, "待支付"), WaitConfirmed(2, "待确认"), WaitShip(3, "待发货"),
HasReceived(4, "已发货"), RefundFail(6, "交易关闭"),Finished(5, "交易完成");
private int code; // 错误代码
private String msg; // 错误消息
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
EJavaShopOrderStateEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public static EJavaShopOrderStateEnum valueOf(int code) { // 手写的从int到enum的转换函数
List<EJavaShopOrderStateEnum> enums = EnumUtils.getEnumList(EJavaShopOrderStateEnum.class);
EJavaShopOrderStateEnum result = enums.stream()
.filter(p -> p.getCode() == code)
.findFirst()
.orElse(EJavaShopOrderStateEnum.RefundFail);
return result;
}
public static EJavaShopOrderStateEnum resolve(String code) {
List<EJavaShopOrderStateEnum> enums = EnumUtils.getEnumList(EJavaShopOrderStateEnum.class);
EJavaShopOrderStateEnum result = enums.stream()
.filter(p -> StringUtils.equalsIgnoreCase(String.valueOf(p.getCode()), code))
.findFirst()
.orElse(EJavaShopOrderStateEnum.RefundFail);
return result;
}
}
package com.sibu.orderHelper.integral.pineapple.model;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
@Data
@ToString
public class CourierCompany implements Serializable{
private Integer id;
private java.util.Date createTime;
private Integer state;
private String companyMark;
private String companyName;
private Integer seq;
private String companyType;
private Integer sellerId;
}
package com.sibu.orderHelper.integral.pineapple.model;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
@Data
@ToString
public class Regions implements Serializable{
private Integer id;
private Integer parentId;
private String regionName;
private String parentPath;
private String firstLetter;
private Integer regionType;
private Integer agencyId;
private Integer shippingId;
private Integer visible;
private String rowId;
}
......@@ -9,8 +9,11 @@ import com.sibu.orderHelper.enums.PineappleEnum;
import com.sibu.orderHelper.enums.PineappleMethodsEnum;
import com.sibu.orderHelper.integral.dao.PineappleDao;
import com.sibu.orderHelper.integral.model.IMDoingOrderBean;
import com.sibu.orderHelper.integral.pineapple.enums.EJavaShopOrderStateEnum;
import com.sibu.orderHelper.integral.pineapple.exception.BizException;
import com.sibu.orderHelper.integral.pineapple.model.CourierCompany;
import com.sibu.orderHelper.integral.pineapple.model.Orders;
import com.sibu.orderHelper.integral.pineapple.model.Regions;
import com.sibu.orderHelper.integral.pineapple.request.CallRequest;
import com.sibu.orderHelper.integral.pineapple.response.BaseResponse;
import com.sibu.orderHelper.integral.request.PineappleSendRequest;
......@@ -18,9 +21,7 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
@Service
public class PineappleSendBizServiceImpl extends AbstractBizService<PineappleSendRequest> {
......@@ -35,19 +36,34 @@ public class PineappleSendBizServiceImpl extends AbstractBizService<PineappleSen
Map<String,Object> params = new HashMap<>();
params.put("orderSn",callRequest.getBizModel().getPlatOrderNo());
params.put("sellerId",callRequest.getSupplier().getId());
//只有订单状态为3 4 5 才允许修改地址,快递单号,其中状态为3还可以修改ERP状态与时间,发货时间,订单状态,其他订单状态直接报业务异常
Orders orders = pineappleDao.getOrdersByMap(params);
if(StringUtil.isNull(orders)){
log.error("获取订单数据业务异常:"+callRequest.getBizModel().getPlatOrderNo());
throw new BizException("获取订单数据业务异常:"+callRequest.getBizModel().getPlatOrderNo());
log.error(String.format("订单发货,获取订单数据业务异常:[%s]",callRequest.getBizModel().getPlatOrderNo()));
throw new BizException(String.format("订单发货,获取订单数据业务异常:[%s]",callRequest.getBizModel().getPlatOrderNo()));
}
//只有订单状态为12345可以允许修改快递单号,其中状态为123可以修改地址,发货时间,订单状态,其他订单状态直接报业务异常
if(orders.getOrderState().intValue() != EJavaShopOrderStateEnum.RefundFail.getCode()){
if(orders.getOrderState().intValue() == EJavaShopOrderStateEnum.WaitPay.getCode()
|| orders.getOrderState().intValue() == EJavaShopOrderStateEnum.WaitConfirmed.getCode()
|| orders.getOrderState().intValue() == EJavaShopOrderStateEnum.WaitShip.getCode()){
//订单状态
params.put("state",EJavaShopOrderStateEnum.HasReceived.getCode());
//收货人名字
if(!StringUtil.isNull(callRequest.getBizModel().getSenderName())){
params.put("name",callRequest.getBizModel().getSenderName());
}
//电话
if(!StringUtil.isNull(callRequest.getBizModel().getSenderTel())){
params.put("mobile",callRequest.getBizModel().getSenderTel());
}
//地址、快递信息
this.gainInfo(params,callRequest,orders);
if(orders.getOrderState().intValue() == PayOrderStatus.HasReceived.getCode() || orders.getOrderState().intValue() == PayOrderStatus.HasDelive.getCode()
|| orders.getOrderState().intValue() == PayOrderStatus.WaitShip.getCode()){
if(orders.getOrderState().intValue() == PayOrderStatus.WaitShip.getCode()){
params.put("orderState",PayOrderStatus.HasReceived.getCode());
params.put("deliverTime",new Date());
}
//判断该快递订单号是否存在,已存在就不允许把该快递订单号添加进去
int num = pineappleDao.checkLogisticsNumber(params);
if(num == 0){
......@@ -59,48 +75,76 @@ public class PineappleSendBizServiceImpl extends AbstractBizService<PineappleSen
}
}
}
//收货人名字
if(!StringUtil.isNull(callRequest.getBizModel().getSenderName())){
params.put("name",callRequest.getBizModel().getSenderName());
}else{
log.error(String.format("订单发货接口,该订单状态不允许进行发货操作,订单号:[%s]",callRequest.getBizModel().getPlatOrderNo()));
throw new BizException(String.format("订单发货接口,该订单状态不允许进行发货操作,订单号:[%s]",callRequest.getBizModel().getPlatOrderNo()));
}
//电话
if(!StringUtil.isNull(callRequest.getBizModel().getSenderTel())){
params.put("mobile",callRequest.getBizModel().getSenderTel());
//修改订单信息
pineappleDao.updateOrdersState(params);
baseResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
baseResponse.setCode(PineappleEnum.SUCCESS.getCode());
return baseResponse;
}
//地址 良品不需要更改地址
/* if(!StringUtil.isNull(callRequest.getBizModel().getSenderAddress())){
private void gainInfo(Map<String,Object> params,CallRequest<PineappleSendRequest> callRequest,Orders orders){
//地址
if(!StringUtil.isNull(callRequest.getBizModel().getSenderAddress())){
String [] str = callRequest.getBizModel().getSenderAddress().split(" ");
if(!StringUtil.isNull(str) && str.length >3){
params.put("province",str[0]);
params.put("city", str[1]);
params.put("area",str[2]);
StringBuffer address = new StringBuffer();
for(int i = 3;i<str.length;i++){
address.append(str[i]);
}
params.put("addressAll",str[0]+"-"+str[1]+"-"+str[2]);
params.put("addressInfo",str[0]+"-"+str[1]+"-"+str[2]+"-"+address);
//查询省市级ID 先寻找最低级 然后查询上去
Map<String,Object> map = new HashMap<>();
map.put("regionType",3);
map.put("name",str[2]);
Regions regions = pineappleDao.getRegionsByMap(map);
if(StringUtil.isNull(regions)){
params.put("provinceId","99999990");
params.put("cityId", "99999989");
params.put("areaId","99999988");
}else{
params.put("area",regions.getId());
Regions city = pineappleDao.getRegionsById(regions.getId());
Regions province = null;
if(!StringUtil.isNull(city)){
province = pineappleDao.getRegionsById(city.getId());
}
if(!StringUtil.isNull(city) && !StringUtil.isNull(province)){
params.put("provinceId", province.getId());
params.put("cityId", city.getId());
}else{
params.put("provinceId","99999990");
params.put("cityId", "99999989");
params.put("areaId","99999988");
}
}
}else{
log.error(String.format("订单号:%s,地址不符合要求:%s,请求method:%s,appket:%s",callRequest.getBizModel().getPlatOrderNo(),callRequest.getBizModel().getSenderAddress(),callRequest.getRequest().getMethod(),callRequest.getRequest().getAppkey()));
throw new BizException(String.format("订单号:%s,地址不符合要求:%s,请求method:%s,appket:%s",callRequest.getBizModel().getPlatOrderNo(),callRequest.getBizModel().getSenderAddress(),callRequest.getRequest().getMethod(),callRequest.getRequest().getAppkey()));
}
}*/
}
//物流公司名字
if(StringUtil.isNull(orders.getLogisticsName())){
params.put("expressName",callRequest.getBizModel().getLogisticName());
}
Map<String,Object> m = new HashMap<>();
m.put("name","orders.getLogisticsName()");
m.put("sellerId",callRequest.getSupplier().getId());
List<CourierCompany> courierCompanyByName = pineappleDao.getCourierCompanyByName(m);
if(!StringUtil.isNull(courierCompanyByName) && !courierCompanyByName.isEmpty()){
Optional<CourierCompany> first = courierCompanyByName.stream().findFirst();
params.put("logisticsName",callRequest.getBizModel().getLogisticName());
params.put("logisticsId", first.get().getId());
}else{
log.error("订单发货接口,该订单状态不允许进行发货操作,订单号:"+callRequest.getBizModel().getPlatOrderNo());
throw new BizException("订单发货接口,该订单状态不允许进行发货操作,订单号:"+callRequest.getBizModel().getPlatOrderNo());
params.put("logisticsName","其他");
params.put("logisticsId","999999990");
}
}
//修改订单信息
pineappleDao.updateOrdersState(params);
baseResponse.setMessage(PineappleEnum.SUCCESS.getMsg());
baseResponse.setCode(PineappleEnum.SUCCESS.getCode());
return baseResponse;
}
@Override
public String getHandleMethodName() {
return PineappleMethodsEnum.Send.getMethod();
......