init
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.sl;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@EnableCaching
|
||||
@EnableFeignClients
|
||||
@SpringBootApplication
|
||||
public class TransportInfoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TransportInfoApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sl.transport.info.controller;
|
||||
|
||||
import com.sl.transport.common.exception.SLException;
|
||||
import com.sl.transport.common.util.BeanUtil;
|
||||
import com.sl.transport.common.util.ObjectUtil;
|
||||
import com.sl.transport.info.domain.TransportInfoDTO;
|
||||
import com.sl.transport.info.entity.TransportInfoEntity;
|
||||
import com.sl.transport.info.enums.ExceptionEnum;
|
||||
import com.sl.transport.info.service.TransportInfoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "物流信息")
|
||||
@RestController
|
||||
@RequestMapping("infos")
|
||||
public class TransportInfoController {
|
||||
|
||||
@Resource
|
||||
private TransportInfoService transportInfoService;
|
||||
|
||||
/**
|
||||
* 根据运单id查询运单信息
|
||||
*
|
||||
* @param transportOrderId 运单号
|
||||
* @return 运单信息
|
||||
*/
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "transportOrderId", value = "运单id")
|
||||
})
|
||||
@ApiOperation(value = "查询", notes = "根据运单id查询物流信息")
|
||||
@GetMapping("{transportOrderId}")
|
||||
public TransportInfoDTO queryByTransportOrderId(@PathVariable("transportOrderId") String transportOrderId) {
|
||||
TransportInfoEntity transportInfoEntity = transportInfoService.queryByTransportOrderId(transportOrderId);
|
||||
if (ObjectUtil.isNotEmpty(transportInfoEntity)) {
|
||||
return BeanUtil.toBean(transportInfoEntity, TransportInfoDTO.class);
|
||||
}
|
||||
throw new SLException(ExceptionEnum.NOT_FOUND);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sl.transport.info.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 物流信息详情
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TransportInfoDetail{
|
||||
|
||||
private Long created; //创建时间,时间戳
|
||||
private String info; //详细信息,例如:您的快件已到达【北京通州分拣中心】
|
||||
private String status; //状态,例如:运输中
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.sl.transport.info.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 运输物流信息
|
||||
*/
|
||||
@Data
|
||||
@Document("sl_transport_info")
|
||||
public class TransportInfoEntity {
|
||||
|
||||
@Id
|
||||
@JsonIgnore
|
||||
private ObjectId id;
|
||||
@Indexed
|
||||
private String transportOrderId; //运单id
|
||||
private List<TransportInfoDetail> infoList; //info信息列表
|
||||
private Long created; //创建时间
|
||||
private Long updated; //更新时间
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sl.transport.info.enums;
|
||||
|
||||
import com.sl.transport.common.enums.BaseExceptionEnum;
|
||||
|
||||
/**
|
||||
* 异常枚举
|
||||
*/
|
||||
public enum ExceptionEnum implements BaseExceptionEnum {
|
||||
|
||||
NOT_FOUND(1001, 404, "查询的运单不存在");
|
||||
|
||||
private Integer code;
|
||||
private Integer status;
|
||||
private String value;
|
||||
|
||||
ExceptionEnum(Integer code, String value) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
this.status = 500;
|
||||
}
|
||||
|
||||
ExceptionEnum(Integer code, Integer status, String value) {
|
||||
this.code = code;
|
||||
this.status = status;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.sl.transport.info.mq;
|
||||
|
||||
import com.sl.transport.common.constant.Constants;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 物流信息消息
|
||||
*/
|
||||
@Component
|
||||
public class TransportInfoMQListener {
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(name = Constants.MQ.Queues.TRANSPORT_INFO_APPEND),
|
||||
exchange = @Exchange(name = Constants.MQ.Exchanges.TRANSPORT_INFO, type = ExchangeTypes.TOPIC),
|
||||
key = Constants.MQ.RoutingKeys.TRANSPORT_INFO_APPEND
|
||||
))
|
||||
@Transactional
|
||||
public void listenTransportInfoMsg(String msg) {
|
||||
//{"info":"您的快件已到达【$organId】", "status":"运输中", "organId":90001, "transportOrderId":"SL920733749248" , "created":1653133234913}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sl.transport.info.service;
|
||||
|
||||
import com.sl.transport.info.domain.TransportInfoDTO;
|
||||
import com.sl.transport.info.entity.TransportInfoDetail;
|
||||
import com.sl.transport.info.entity.TransportInfoEntity;
|
||||
|
||||
/**
|
||||
* 物流信息服务
|
||||
*/
|
||||
public interface TransportInfoService {
|
||||
|
||||
|
||||
/**
|
||||
* 如果运单数据不存在,就新增,否则更新数据
|
||||
*
|
||||
* @param transportOrderId 运单id
|
||||
* @param infoDetail 信息详情
|
||||
* @return 运输信息数据
|
||||
*/
|
||||
TransportInfoEntity saveOrUpdate(String transportOrderId, TransportInfoDetail infoDetail);
|
||||
|
||||
/**
|
||||
* 根据运单id查询运输信息
|
||||
*
|
||||
* @param transportOrderId 运单id
|
||||
* @return 运输信息数据
|
||||
*/
|
||||
TransportInfoEntity queryByTransportOrderId(String transportOrderId);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user