袁野 2 weeks ago
parent 9aac81d0e5
commit 339223b64f
  1. 23
      cweb/src/main/java/com/hfkj/controller/ElmController.java
  2. 32
      cweb/src/main/java/com/hfkj/controller/GoodsController.java
  3. 16
      schedule/src/main/java/com/hfkj/schedule/OrderSchedule.java
  4. 32
      service/src/main/java/com/hfkj/service/elm/ElmService.java
  5. 108
      service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java

@ -2,9 +2,12 @@ package com.hfkj.controller;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsUser;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.elm.ElmService;
import com.hfkj.service.user.BsUserService;
import com.taobao.api.response.AlibabaAlscUnionMediaZoneAddResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
@Controller
@RequestMapping(value="/elm")
@Api(value="饿了么")
@ -25,6 +30,9 @@ public class ElmController {
@Autowired
private UserCenter userCenter;
@Resource
private BsUserService bsUserService;
@RequestMapping(value="/officialactivity",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "本地联盟饿了么推广官方活动查询")
@ -34,7 +42,20 @@ public class ElmController {
// 用户session
UserSessionObject session = userCenter.getSessionModel(UserSessionObject.class);
return ResponseMsgUtil.success(ElmService.officialactivity(session.getUser().getId() , "10144"));
BsUser user = bsUserService.getUser(session.getUser().getId());
String pid = "alsc_28560886_9016007_22442020";
if(user != null){
if (user.getElmPid() == null) {
AlibabaAlscUnionMediaZoneAddResponse mediaZone = ElmService.mediaZone(user.getPhone());
pid = mediaZone.getResult().getPid();
user.setElmPid(pid);
bsUserService.editData(user);
} else {
pid = user.getElmPid();
}
}
return ResponseMsgUtil.success(ElmService.officialactivity(session.getUser().getId() , "10144" , pid));
} catch (Exception e) {
log.error("error!",e);

@ -16,6 +16,7 @@ import com.hfkj.service.order.BsOrderService;
import com.hfkj.service.pdd.PddService;
import com.hfkj.service.taobao.TaoBaoService;
import com.hfkj.service.user.BsUserService;
import com.taobao.api.response.AlibabaAlscUnionMediaZoneAddResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
@ -25,8 +26,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -44,6 +43,10 @@ public class GoodsController {
@Resource
private BsUserService bsUserService;
@Resource
private BsOrderService orderService;
@RequestMapping(value="/goodsList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询商品列表")
@ -164,6 +167,25 @@ public class GoodsController {
}
}
@RequestMapping(value="/mediaZone",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "饿了么创建推广位")
public ResponseData mediaZone() {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
AlibabaAlscUnionMediaZoneAddResponse object = ElmService.mediaZone( userSession.getUser().getPhone());
return ResponseMsgUtil.success(object.getResult().getPid());
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getPublisherInfo",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "淘宝客-公用-私域用户备案信息查询")
@ -194,11 +216,11 @@ public class GoodsController {
@RequestMapping(value="/getOrderList",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询订单")
public ResponseData getOrderList(@RequestParam(value = "code" , required = false) String code
) {
public ResponseData getOrderList() {
try {
return ResponseMsgUtil.success(ElmService.elmOrderList("2024-10-20 09:34:00" , "2024-11-04 12:34:00").getJSONArray("result"));
orderService.getOrderElmList("2024-10-20 09:34:00" , "2024-11-08 12:34:00");
return ResponseMsgUtil.success("nu");
} catch (Exception e) {
log.error("error!",e);

@ -66,5 +66,21 @@ public class OrderSchedule {
}
}
@Scheduled(cron = "0 0/15 * * * ?") // 每十五分钟 执行一次
public void getOrderElmList() {
try {
// 昨日时间
// create domain
LocalDateTime now = LocalDateTime.now();
LocalDateTime twentyMinutesBefore = now.minus(Duration.ofMinutes(19));
// 昨日时间
orderService.getOrderElmList(twentyMinutesBefore.format(DateTimeFormatter.ofPattern(DateUtil.Y_M_D_HMS)) , DateUtil.format(new Date(),DateUtil.Y_M_D_HMS));
} catch (Exception e) {
System.out.println("查询失败!!!");
}
}
}

@ -25,10 +25,9 @@ public class ElmService {
private static String appKey = "34818013";
private static String appsecret = "822a2df4166dbab7e0acfc42ba0aab75";
private static String url = "https://gw.api.taobao.com/router/rest";
private static String pid = "alsc_28560886_9016007_22442020";
// 本地联盟饿了么推广官方活动查询
public static JSONObject officialactivity(Long userId , String activityId) throws Exception {
public static JSONObject officialactivity(Long userId , String activityId , String pid) throws Exception {
// 打印日志,开始本地联盟饿了么推广官方活动查询
log.info("============ 本地联盟饿了么推广官方活动查询-START =============");
@ -64,7 +63,7 @@ public class ElmService {
}
public static JSONObject elmOrderList(String startTime , String endTime) throws Exception {
public static AlibabaAlscUnionKbcpxPositiveOrderGetResponse elmOrderList(String startTime , String endTime) throws Exception {
// 打印日志, 本地生活媒体推广位创建
log.info("============ 本地生活媒体推广位创建-START =============");
@ -78,7 +77,6 @@ public class ElmService {
req.setPageSize(50L);
req.setPageNumber(1L);
req.setStartDate(startTime);
req.setPid(pid);
req.setIncludeUsedStoreId(false);
AlibabaAlscUnionKbcpxPositiveOrderGetResponse rsp = client.execute(req);
@ -91,7 +89,31 @@ public class ElmService {
// 打印日志, 本地生活媒体推广位创建
log.info("============ 本地生活媒体推广位创建--END ==============");
// 返回响应参数
return JSONObject.parseObject(JSON.toJSONString(rsp));
return rsp;
}
public static AlibabaAlscUnionMediaZoneAddResponse mediaZone(String phone) throws Exception {
// 打印日志, 本地生活媒体推广位创建
log.info("============ 本地生活媒体推广位创建-START =============");
// 创建淘宝客户端
TaobaoClient client = new DefaultTaobaoClient(url, appKey, appsecret);
AlibabaAlscUnionMediaZoneAddRequest req = new AlibabaAlscUnionMediaZoneAddRequest();
req.setZoneName(phone);
AlibabaAlscUnionMediaZoneAddResponse rsp = client.execute(req);
// 打印日志,请求接口
log.info("请求接口:" + "officialactivity");
// 打印日志,请求参数
log.info("请求参数:" + JSONObject.toJSONString(req));
// 打印日志,响应参数
log.info("响应参数:" + rsp);
// 打印日志, 本地生活媒体推广位创建
log.info("============ 本地生活媒体推广位创建--END ==============");
// 返回响应参数
return rsp;
}
}

@ -16,6 +16,7 @@ import com.hfkj.entity.BsOrderExample;
import com.hfkj.entity.BsUser;
import com.hfkj.model.BsOrderModel;
import com.hfkj.model.UserTeamModel;
import com.hfkj.service.elm.ElmService;
import com.hfkj.service.meituan.MeiTuanService;
import com.hfkj.service.order.BsOrderService;
import com.hfkj.service.order.OrderBusinessService;
@ -29,6 +30,7 @@ import com.hfkj.service.user.BsUserService;
import com.hfkj.sysenum.partner.PartnerEnum;
import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkOrderListRangeGetResponse;
import com.taobao.api.response.AlibabaAlscUnionKbcpxPositiveOrderGetResponse;
import com.taobao.top.ability414.domain.TaobaoTbkOrderDetailsGetPublisherOrderDto;
import com.taobao.top.ability414.response.TaobaoTbkOrderDetailsGetResponse;
import org.apache.commons.collections4.MapUtils;
@ -184,7 +186,7 @@ public class BsOrderServiceImpl implements BsOrderService {
@Override
public void getOrderElmList(String startTime, String endTime) {
try {
meiTuanOrder(startTime , endTime);
elmOrder(startTime , endTime);
} catch (Exception e) {
System.out.println(e.getMessage());
}
@ -595,18 +597,106 @@ public class BsOrderServiceImpl implements BsOrderService {
} else {
// 否则,调用editData方法,更新订单信息
editData(bsOrder);
}
}
}
}
}
}
private void elmOrder(String startTime , String endTime) throws Exception {
AlibabaAlscUnionKbcpxPositiveOrderGetResponse elmOrderList = ElmService.elmOrderList(startTime ,endTime);
List<AlibabaAlscUnionKbcpxPositiveOrderGetResponse.OrderDetailReportDTO> elmOrderListResult = elmOrderList.getResult();
List<BsOrder> list = getOrderList(new HashMap<>());
List<BsUser> userList = userService.getList(new HashMap<>());
userList = userList.stream().filter(s->s.getElmPid() != null).collect(Collectors.toList());
if (elmOrderListResult != null && !elmOrderListResult.isEmpty()) {
for (AlibabaAlscUnionKbcpxPositiveOrderGetResponse.OrderDetailReportDTO elmOrder : elmOrderListResult) {
// 根据订单号,从本地订单列表中查找订单
BsOrder bsOrder = list.stream().filter(s->s.getOrderNo().equals(elmOrder.getBizOrderId().toString())).findFirst().orElse(null);
// 根据relationId,从用户列表中查找用户
BsUser bsUser = userList.stream().filter(s->s.getElmPid().equals(elmOrder.getPid())).findFirst().orElse(null);
// 如果本地订单列表中没有该订单,则创建一个新的订单
if (bsOrder == null) {
bsOrder = new BsOrder();
bsOrder.setOrderNo(elmOrder.getBizOrderId().toString());
if (bsUser != null) {
bsOrder.setUserId(bsUser.getId());
bsOrder.setUserPhone(bsUser.getPhone() == null ? "" : bsUser.getPhone());
}
bsOrder.setCreateTime(new Date());
bsOrder.setUpdateTime(new Date());
bsOrder.setStatus(elmStatus(elmOrder.getOrderState()));
bsOrder.setType(4);
bsOrder.setGoodsName(elmOrder.getTitle());
bsOrder.setGoodsCount(1);
bsOrder.setTotalPrice(new BigDecimal(elmOrder.getPayAmount()));
bsOrder.setPromotionAmount(new BigDecimal(elmOrder.getSettleAmount()));
if (elmOrder.getTkCreateTime() != null) {
bsOrder.setCreateTime(DateUtil.format(elmOrder.getTkCreateTime() , DateUtil.Y_M_D_HMS));
}
if (elmOrder.getPayTime() != null) {
bsOrder.setPayTime(DateUtil.format(elmOrder.getPayTime() , DateUtil.Y_M_D_HMS));
}
if (elmOrder.getSettleTime() != null) {
bsOrder.setFinishTime(DateUtil.format(elmOrder.getSettleTime() , DateUtil.Y_M_D_HMS));
}
// 调用create方法,将新订单保存到本地订单列表中
create(bsOrder);
} else {
// 如果本地订单列表中已有该订单,则更新订单信息
if (bsOrder.getStatus() == 2) {
bsOrder.setOrderNo(elmOrder.getBizOrderId().toString());
if (bsUser != null) {
bsOrder.setUserId(bsUser.getId());
bsOrder.setUserPhone(bsUser.getPhone() == null ? "" : bsUser.getPhone());
}
bsOrder.setCreateTime(new Date());
bsOrder.setUpdateTime(new Date());
bsOrder.setStatus(elmStatus(elmOrder.getOrderState()));
bsOrder.setType(4);
bsOrder.setGoodsName(elmOrder.getTitle());
bsOrder.setGoodsCount(1);
bsOrder.setTotalPrice(new BigDecimal(elmOrder.getPayAmount()));
bsOrder.setPromotionAmount(new BigDecimal(elmOrder.getSettleAmount()));
if (elmOrder.getTkCreateTime() != null) {
bsOrder.setCreateTime(DateUtil.format(elmOrder.getTkCreateTime() , DateUtil.Y_M_D_HMS));
}
if (elmOrder.getPayTime() != null) {
bsOrder.setPayTime(DateUtil.format(elmOrder.getPayTime() , DateUtil.Y_M_D_HMS));
}
if (elmOrder.getSettleTime() != null) {
bsOrder.setFinishTime(DateUtil.format(elmOrder.getSettleTime() , DateUtil.Y_M_D_HMS));
}
// 如果订单状态为5,则调用orderRebate方法
if (bsOrder.getStatus() == 2 && elmOrder.getOrderState() == 4){
orderRebate(bsOrder);
} else {
// 否则,调用editData方法,更新订单信息
editData(bsOrder);
}
}
}
}
}
}
private Integer pddStatus(Long status) {
int result = 4;
if (status == 0) {
@ -652,4 +742,18 @@ public class BsOrderServiceImpl implements BsOrderService {
}
return result;
}
private Integer elmStatus(Long status) {
int result = 4;
if (status == 1) {
result = 1;
} else if (status == 0) {
result = 4;
} else if (status == 2) {
result = 2;
} else if (status == 4) {
result = 2;
}
return result;
}
}

Loading…
Cancel
Save