Client.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package com.ydd.third.waimai;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ydd.common.exception.BusinessException;
  4. import com.ydd.third.common.utils.HttpUtils;
  5. import com.ydd.third.common.utils.StringUtils;
  6. import com.ydd.third.common.vo.ResObject;
  7. import com.ydd.third.common.vo.waimai.*;
  8. import com.ydd.third.common.vo.waimai.meituan.RefundFoodItemVo;
  9. import com.ydd.third.waimai.eleRetai.EleRetaiClient;
  10. import com.ydd.third.waimai.eleme.ElemeClient;
  11. import com.ydd.third.waimai.meituan.MeituanClient;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.math.BigDecimal;
  16. import java.util.List;
  17. /**
  18. * @ClassName Client
  19. * @Deacription TODO
  20. * @Author peakren
  21. * @Date 2/4/21 10:20 PM
  22. * @Version 1.0
  23. **/
  24. @Slf4j
  25. @Service("waimaiClient")
  26. public class Client {
  27. @Autowired
  28. MeituanClient meituanClient;
  29. @Autowired
  30. ElemeClient elemeClient;
  31. @Autowired
  32. EleRetaiClient eleRetaiClient;
  33. /**
  34. * ok
  35. * 查询订单
  36. * @param queryOrderVo
  37. * @return
  38. */
  39. public ResObject queryOrderById(QueryOrderVo queryOrderVo) {
  40. String client = queryOrderVo.getLbClient();
  41. if (StringUtils.isBlank(client)) {
  42. throw new BusinessException("未指定lbClient参数");
  43. }
  44. if (client.equals("meituan")) {
  45. ResObject<MeituanOrderResultVo> res = meituanClient.queryOrderById(queryOrderVo);
  46. return res;
  47. } else if (client.equals("eleme")) {
  48. ResObject<ElemeOrderResultVo> res = elemeClient.getOrder(queryOrderVo);
  49. return res;
  50. } else {
  51. throw new BusinessException("lb_client参数不正确");
  52. }
  53. }
  54. /**
  55. * ok
  56. * 对订单进行确认
  57. * @param confirmOrderVo
  58. * @return
  59. */
  60. public ResObject confirmOrder(ConfirmOrderVo confirmOrderVo){
  61. // JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr);
  62. String client = confirmOrderVo.getLbClient(); //jsonParams.getString("lb_client");
  63. if (StringUtils.isBlank(client)) {
  64. throw new BusinessException("未指定lbClient参数");
  65. }
  66. ResObject res ;
  67. if (client.equals("meituan")) {
  68. res = meituanClient.confirmOrder(confirmOrderVo);
  69. } else if (client.equals("eleme")) {
  70. res = elemeClient.confirmOrder(confirmOrderVo);
  71. } else {
  72. throw new BusinessException("lbClient参数不正确");
  73. }
  74. return res;
  75. }
  76. /**
  77. * ok
  78. * 取消订单
  79. * @param cancelOrderVo
  80. * @return
  81. */
  82. public ResObject cancelOrder(CancelOrderVo cancelOrderVo) {
  83. // JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr);
  84. String client = cancelOrderVo.getLbClient();
  85. if (StringUtils.isBlank(client)) {
  86. throw new BusinessException("未指定lbClient参数");
  87. }
  88. ResObject res;
  89. if (client.equals("meituan")) {
  90. res = meituanClient.cancelOrder(cancelOrderVo);
  91. } else if (client.equals("eleme")) {
  92. res = elemeClient.cancelOrder(cancelOrderVo);
  93. } else if (client.equals("elemeretail")) {
  94. res = eleRetaiClient.cancelOrder(cancelOrderVo);
  95. } else {
  96. throw new BusinessException("lbClient参数不正确");
  97. }
  98. return res;
  99. }
  100. /**
  101. * ok
  102. * 自配订单同步配送信息
  103. * @param syncRiderPositionVo
  104. * @return
  105. */
  106. public ResObject syncRiderPositionStatus(SyncRiderPositionStatusVo syncRiderPositionVo) { ;
  107. String client = syncRiderPositionVo.getLbClient();
  108. if (StringUtils.isBlank(client)) {
  109. throw new BusinessException("未指定lbClient参数");
  110. }
  111. ResObject res= new ResObject();
  112. if (client.equals("meituan")) {
  113. res = meituanClient.syncRiderPosition(syncRiderPositionVo);
  114. } else if (client.equals("eleme")) {
  115. //同步位置
  116. if(syncRiderPositionVo.getLongitude()!=null&&syncRiderPositionVo.getLongitude().compareTo(BigDecimal.ZERO)>0
  117. &&("DELIVERY_START".equals(syncRiderPositionVo.getDeliverState().name()))){
  118. res = elemeClient.selfDeliveryLocationSync(syncRiderPositionVo);
  119. }
  120. //同步状态
  121. res = elemeClient.selfDeliveryStateSync(syncRiderPositionVo);
  122. }else if (client.equals("elemeretail")){
  123. if(syncRiderPositionVo.getLogisticsStatus()==16){
  124. res= eleRetaiClient.complete(syncRiderPositionVo.getOrderId(),syncRiderPositionVo.getCourierPhone());
  125. }else{
  126. if(syncRiderPositionVo.getLongitude()!=null&&syncRiderPositionVo.getLongitude().compareTo(BigDecimal.ZERO)>0){
  127. eleRetaiClient.syncRiderPosition(syncRiderPositionVo);
  128. }
  129. if(syncRiderPositionVo.getLogisticsStatus().intValue()!=-1){
  130. res= eleRetaiClient.syncRiderPositionStatus(syncRiderPositionVo);
  131. }
  132. }
  133. }else if (client.equals("shantang")){
  134. String json = syncRiderPositionVo.getShanTangdto();
  135. res = new ResObject();
  136. try {
  137. String resp = HttpUtils.sendJsonPost("https://business-api.hsst100.com/order/delivery/delivery/callback",json);
  138. res.setCode(0);
  139. res.setMsg("操作成功"+resp);
  140. } catch (Exception e) {
  141. e.printStackTrace();
  142. }
  143. }
  144. else {
  145. throw new BusinessException("lb_client参数不正确");
  146. }
  147. return res;
  148. }
  149. /**
  150. * ok
  151. * 订单同意退款
  152. * @param agreeOrderRefundVo
  153. * @return
  154. */
  155. public ResObject agreeOrderRefund(AgreeOrderRefundVo agreeOrderRefundVo) {
  156. String client = agreeOrderRefundVo.getLbClient();
  157. if (StringUtils.isBlank(client)) {
  158. throw new BusinessException("未指定lbClient参数");
  159. }
  160. ResObject res;
  161. if (client.equals("meituan")) {
  162. res = meituanClient.agreeOrderRefund(agreeOrderRefundVo);
  163. } else if (client.equals("eleme")) {
  164. res = elemeClient.agreeRefundOrder(agreeOrderRefundVo);
  165. } else {
  166. throw new BusinessException("lbClient参数不正确");
  167. }
  168. return res;
  169. }
  170. /**
  171. * ok
  172. * 订单拒绝退款
  173. * @param rejectOrderRefundVo
  174. * @return
  175. */
  176. public ResObject rejectOrderRefund(RejectOrderRefundVo rejectOrderRefundVo) {
  177. String client = rejectOrderRefundVo.getLbClient(); //jsonParams.getString("lb_client");
  178. if (StringUtils.isBlank(client)) {
  179. throw new BusinessException("未指定lbClient参数");
  180. }
  181. ResObject res;
  182. if (client.equals("meituan")) {
  183. res = meituanClient.rejectOrderRefund(rejectOrderRefundVo);
  184. } else if (client.equals("eleme")) {
  185. res = elemeClient.disagreeRefundOrder(rejectOrderRefundVo);
  186. } else {
  187. throw new BusinessException("lbClient参数不正确");
  188. }
  189. return res;
  190. }
  191. /**
  192. * ok
  193. * 部分退款-查询部分退款商品
  194. * @param queryPartRefundFoodsVo
  195. * @return
  196. */
  197. public ResObject<List<RefundFoodItemVo>> queryPartRefundFoods(QueryPartRefundFoodsVo queryPartRefundFoodsVo) {
  198. String client = queryPartRefundFoodsVo.getLbClient(); //jsonParams.getString("lb_client");
  199. if (StringUtils.isBlank(client)) {
  200. throw new BusinessException("未指定lbClient参数");
  201. }
  202. ResObject<List<RefundFoodItemVo>> res;
  203. if (client.equals("meituan")) {
  204. res = meituanClient.queryPartRefundFoods(queryPartRefundFoodsVo);
  205. } else if (client.equals("eleme")) {
  206. res = new ResObject<>();
  207. res.setMsg("饿了么没有相应的接口");
  208. } else {
  209. throw new BusinessException("lbClient参数不正确");
  210. }
  211. return res;
  212. }
  213. /**
  214. * ok
  215. * 部分退款-申请部分退款
  216. * @param applyPartRefundVo
  217. * @return
  218. */
  219. public ResObject applyPartRefund(ApplyPartRefundVo applyPartRefundVo) {
  220. //JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr);
  221. String client = applyPartRefundVo.getLbClient(); // .getLjsonParams.getString("lb_client");
  222. if (StringUtils.isBlank(client)) {
  223. throw new BusinessException("未指定lbClient参数");
  224. }
  225. ResObject res;
  226. if (client.equals("meituan")) {
  227. res = meituanClient.applyPartRefund(applyPartRefundVo);
  228. } else if (client.equals("eleme")) {
  229. res = elemeClient.refundParty(applyPartRefundVo); //商家部分退款
  230. } else {
  231. throw new BusinessException("lbClient参数不正确");
  232. }
  233. return res;
  234. }
  235. /**
  236. * ok
  237. * 催单回复
  238. * @param orderRemindReplyVo
  239. * @return
  240. */
  241. public ResObject orderRemindReply(OrderRemindReplyVo orderRemindReplyVo) {
  242. String client = orderRemindReplyVo.getLbClient(); //jsonParams.getString("lb_client");
  243. if (StringUtils.isBlank(client)) {
  244. throw new BusinessException("未指定lbClient参数");
  245. }
  246. ResObject res;
  247. if (client.equals("meituan")) {
  248. res = meituanClient.orderRemindReply(orderRemindReplyVo);
  249. } else if (client.equals("eleme")) {
  250. res = elemeClient.replyReminder(orderRemindReplyVo); //回复催单
  251. } else {
  252. throw new BusinessException("lbClient参数不正确");
  253. }
  254. return res;
  255. }
  256. /**
  257. * ok
  258. * 查询门店信息
  259. * @param jsonParamsStr
  260. * @return
  261. */
  262. public String queryShopInfo(String jsonParamsStr) {
  263. JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr);
  264. String client = jsonParams.getString("lb_client");
  265. if (StringUtils.isBlank(client)) {
  266. throw new BusinessException("未指定lb_client参数");
  267. }
  268. String res = "";
  269. if (client.equals("meituan")) {
  270. res = meituanClient.queryPoiInfo(jsonParamsStr);
  271. } else if (client.equals("eleme")) {
  272. res = elemeClient.getShop(jsonParamsStr); //回复催单
  273. } else {
  274. throw new BusinessException("lb_client参数不正确");
  275. }
  276. return res;
  277. }
  278. }